-
Notifications
You must be signed in to change notification settings - Fork 26
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 #99 from world4youcom/add_retry_mechanism_via_requ…
…est_header Add retry mechanism via request header
- Loading branch information
Showing
5 changed files
with
156 additions
and
6 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,70 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Ticketpark\SaferpayJson\Request\Exception\SaferpayErrorException; | ||
use Ticketpark\SaferpayJson\Request\RequestConfig; | ||
use Ticketpark\SaferpayJson\Request\Transaction\AuthorizeRequest; | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
require_once __DIR__ . '/../credentials.php'; | ||
|
||
// A token you received after initializing a transaction (see example-initialize.php) | ||
|
||
$token = 'xxx'; | ||
|
||
// The request ID which is generated by our merchant-system to retry the authorize request | ||
// after the first attempt returned a Behavior of RETRY or RETRY_LATER | ||
|
||
$requestId = 'your_request_id'; | ||
|
||
// retryIndicator is set to 1 or more to indicate that this is a retry (see SaferpayJson/Request/RequestConfig.php) | ||
|
||
$retryIndicator = 1; | ||
|
||
// ----------------------------- | ||
// Step 1: | ||
// Prepare the authorize request | ||
// See https://saferpay.github.io/jsonapi/#Payment_v1_Transaction_Authorize | ||
|
||
$requestConfig = new RequestConfig( | ||
$apiKey, | ||
$apiSecret, | ||
$customerId, | ||
true | ||
); | ||
|
||
// Note: The RequestConfig contains the optional fields requestId and retryIndicator to indicate that this is a retry | ||
// or for debugging purposes | ||
// (see https://docs.saferpay.com/home/integration-guide/licences-and-interfaces/error-handling#the-requestid-and-retryindicator) | ||
|
||
$requestConfig->setRequestId($requestId); | ||
$requestConfig->setRetryIndicator($retryIndicator); | ||
|
||
// ----------------------------- | ||
// Step 2: | ||
// Create the request with required data | ||
|
||
$authorizeRequest = new AuthorizeRequest( | ||
$requestConfig, | ||
$token, | ||
); | ||
|
||
// Note: More data can be provided to InitializeRequest with setters, | ||
// for example: $authorizeRequest->setCondition() | ||
// See Saferpay documentation for available options. | ||
|
||
// ----------------------------- | ||
// Step 3: | ||
// Execute and check for successful response | ||
|
||
try { | ||
$response = $authorizeRequest->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: 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
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 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 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