-
Notifications
You must be signed in to change notification settings - Fork 26
/
example-capture.php
51 lines (38 loc) · 1.38 KB
/
example-capture.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php declare(strict_types=1);
use Ticketpark\SaferpayJson\Request\Exception\SaferpayErrorException;
use Ticketpark\SaferpayJson\Request\Container;
use Ticketpark\SaferpayJson\Request\RequestConfig;
use Ticketpark\SaferpayJson\Request\Transaction\CaptureRequest;
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../credentials.php';
// A transaction id you received with a successful assert request (see ../PaymentPage/example-assert.php)
$transactionId = 'xxx';
// -----------------------------
// Step 1:
// Prepare the capture request
// https://saferpay.github.io/jsonapi/#Payment_v1_Transaction_Capture
$requestConfig = new RequestConfig(
$apiKey,
$apiSecret,
$customerId,
true
);
$transactionReference = (new Container\TransactionReference())
->setTransactionId($transactionId);
// -----------------------------
// Step 2:
// Create the request with required data
$captureRequest = new CaptureRequest(
$requestConfig,
$transactionReference
);
// -----------------------------
// Step 3:
// Execute and check for successful response
try {
$response = $captureRequest->execute();
} catch (SaferpayErrorException $e) {
die ($e->getErrorResponse()->getErrorMessage());
}
echo 'The transaction has successfully been captured! Capture-Id: ' . $response->getCaptureId()."\n";
// You have now fully completed a successful payment :)