1 | <?php declare(strict_types=1); |
||
2 | |||
3 | use \Ticketpark\SaferpayJson\Container; |
||
4 | use \Ticketpark\SaferpayJson\Response\ErrorResponse; |
||
5 | use \Ticketpark\SaferpayJson\Request\Transaction\RefundRequest; |
||
6 | |||
7 | require_once __DIR__ . '/../../vendor/autoload.php'; |
||
8 | require_once __DIR__ . '/../credentials.php'; |
||
9 | |||
10 | // A transaction id you received with a successful assert request (see ../PaymentPage/2-example-assert.php) |
||
11 | |||
12 | $transactionId = 'xxx'; |
||
13 | |||
14 | // Step 1: |
||
15 | // Prepare the refund request |
||
16 | // https://saferpay.github.io/jsonapi/1.2/#Payment_v1_Transaction_Refund |
||
17 | |||
18 | $requestHeader = (new Container\RequestHeader()) |
||
19 | ->setCustomerId($customerId) |
||
20 | ->setRequestId(uniqid()); |
||
21 | |||
22 | $transactionReference = (new Container\TransactionReference()) |
||
23 | ->setTransactionId($transactionId); |
||
24 | |||
25 | $amount = (new Container\Amount()) |
||
26 | ->setCurrencyCode('CHF') |
||
27 | ->setValue(5000); // amount in cents |
||
28 | |||
29 | $refund = (new Container\Refund()) |
||
30 | ->setAmount($amount); |
||
31 | |||
32 | $response = (new RefundRequest($apiKey, $apiSecret)) |
||
33 | ->setRequestHeader($requestHeader) |
||
34 | ->setTransactionReference($transactionReference) |
||
35 | ->setRefund($refund) |
||
36 | ->execute(); |
||
37 | |||
38 | // Step 2: |
||
39 | // Check for successful response |
||
40 | |||
41 | /** @var \Ticketpark\SaferpayJson\Transaction\RefundResponse */ |
||
42 | if ($response instanceof ErrorResponse) { |
||
43 | die($response->getErrorMessage()); |
||
44 | } |
||
45 | |||
46 | echo 'The transaction has successfully been refunded! Transaction-ID: ' . $response->getTransaction()->getId(); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
47 |