Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Ticketpark/v3-wip
v3
- Loading branch information
Showing
165 changed files
with
6,125 additions
and
3,117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Contributing to this library | ||
|
||
🎉 Thanks for being interested in contributing to this library! | ||
|
||
## Basics | ||
|
||
* Follow [Symfony coding standards](http://symfony.com/doc/current/contributing/code/standards.html) | ||
* Write useful commit messages | ||
* Be nice and respect others | ||
|
||
## Technical guidelines | ||
|
||
### Request containers | ||
|
||
* Put mandatory properties into the constructor | ||
* No setters for data which is set in constructor | ||
|
||
Note that some data seems to be mandatory, but is not marked as such in the Saferpay docs. We strictly follow the | ||
information in the Saferpay docs and keep all data optional unless Saferpay explicity marks | ||
it as mandatory. | ||
|
||
### Response containers | ||
|
||
* No constructors | ||
* No setters | ||
* All properties are optional | ||
|
||
Even though in the Saferpay doc some data is marked as mandatory in responses, we keep them all optional in this | ||
library because it is not in our control whether this data will actually be provided or not. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Ticketpark\SaferpayJson\Request\Exception\SaferpayErrorException; | ||
use Ticketpark\SaferpayJson\Request\RequestConfig; | ||
use Ticketpark\SaferpayJson\Request\PaymentPage\AssertRequest; | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
require_once __DIR__ . '/../credentials.php'; | ||
|
||
// A token you received after initializing a payment page (see example-assert.php) | ||
|
||
$token = 'xxx'; | ||
|
||
// ----------------------------- | ||
// Step 1: | ||
// Prepare the assert request | ||
// See http://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Assert | ||
|
||
$requestConfig = new RequestConfig( | ||
$apiKey, | ||
$apiSecret, | ||
$customerId, | ||
true | ||
); | ||
|
||
// ----------------------------- | ||
// Step 2: | ||
// Create the request with required data | ||
|
||
$assertRequest = new AssertRequest( | ||
$requestConfig, | ||
$token, | ||
); | ||
|
||
// ----------------------------- | ||
// Step 3: | ||
// Execute and check for successful response | ||
|
||
try { | ||
$response = $assertRequest->execute(); | ||
} catch (SaferpayErrorException $e) { | ||
die ($e->getErrorResponse()->getErrorMessage()); | ||
} | ||
|
||
echo 'The transaction has been successful! Transaction id: ' . $response->getTransaction()->getId()."\n"; | ||
|
||
// ----------------------------- | ||
// Step 4: | ||
// Capture the transaction to get the cash flowing. | ||
// See ../Transaction/example-capture.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Ticketpark\SaferpayJson\Request\Exception\SaferpayErrorException; | ||
use Ticketpark\SaferpayJson\Request\PaymentPage\InitializeRequest; | ||
use Ticketpark\SaferpayJson\Request\RequestConfig; | ||
use Ticketpark\SaferpayJson\Request\Container; | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
require_once __DIR__ . '/../credentials.php'; | ||
|
||
// ----------------------------- | ||
// Step 1: | ||
// Initialize the required payment page data | ||
// See https://saferpay.github.io/jsonapi/#Payment_v1_PaymentPage_Initialize | ||
|
||
$requestConfig = new RequestConfig( | ||
$apiKey, | ||
$apiSecret, | ||
$customerId, | ||
true | ||
); | ||
|
||
$amount = new Container\Amount( | ||
5000, // amount in cents | ||
'CHF' | ||
); | ||
|
||
$payment = new Container\Payment($amount); | ||
$payment->setDescription('Order No. 12839'); | ||
|
||
$returnUrls = new Container\ReturnUrls( | ||
'http://www.mysite.ch/success?orderId=12839', | ||
'http://www.mysite.ch/fail' | ||
); | ||
|
||
// ----------------------------- | ||
// Step 2: | ||
// Create the request with required data | ||
|
||
$initializeRequest = new InitializeRequest( | ||
$requestConfig, | ||
$terminalId, | ||
$payment, | ||
$returnUrls | ||
); | ||
|
||
// Note: More data can be provided to InitializeRequest with setters, | ||
// for example: $initializeRequest->setPayer() | ||
// See Saferpay documentation for available options. | ||
|
||
// ----------------------------- | ||
// Step 3: | ||
// Execute and check for successful response | ||
|
||
try { | ||
$response = $initializeRequest->execute(); | ||
} catch (SaferpayErrorException $e) { | ||
die ($e->getErrorResponse()->getErrorMessage()); | ||
} | ||
|
||
// ----------------------------- | ||
// Step 4: | ||
// Save the response token, you will need it later to verify the payment (see step 7) | ||
echo 'Payment token: ' . $response->getToken() . "<br>\n"; | ||
|
||
// ----------------------------- | ||
// Step 5: | ||
// Redirect to the payment page | ||
echo 'Redirect to: ' . $response->getRedirectUrl() ."<br>\n"; | ||
|
||
// ----------------------------- | ||
// Step 6: | ||
// Fill in test payment page. For dummy credit card numbers see | ||
// https://saferpay.github.io/sndbx/paymentmeans.html | ||
|
||
// ----------------------------- | ||
// Step 7: | ||
// On success page and notification url, assert that the payment has been successful. | ||
// -> see example-assert.php |
Oops, something went wrong.