AuthorizeOrder.php
5 years ago
CaptureOrder.php
5 years ago
CreateOrder.php
5 years ago
RunAll.php
5 years ago
CaptureOrder.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Sample\AuthorizeIntentExamples; |
| 4 | |
| 5 | require __DIR__ . '/../../vendor/autoload.php'; |
| 6 | use PayPalCheckoutSdk\Payments\AuthorizationsCaptureRequest; |
| 7 | use Sample\PayPalClient; |
| 8 | |
| 9 | class CaptureOrder |
| 10 | { |
| 11 | /** |
| 12 | * Below method can be used to build the capture request body. |
| 13 | * This request can be updated with required fields as per need. |
| 14 | * Please refer API specs for more info. |
| 15 | */ |
| 16 | public static function buildRequestBody() |
| 17 | { |
| 18 | return "{}"; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Below function can be used to capture order. |
| 23 | * Valid Authorization id should be passed as an argument. |
| 24 | */ |
| 25 | public static function captureOrder($authorizationId, $debug=false) |
| 26 | { |
| 27 | $request = new AuthorizationsCaptureRequest($authorizationId); |
| 28 | $request->body = self::buildRequestBody(); |
| 29 | $client = PayPalClient::client(); |
| 30 | $response = $client->execute($request); |
| 31 | |
| 32 | if ($debug) |
| 33 | { |
| 34 | print "Status Code: {$response->statusCode}\n"; |
| 35 | print "Status: {$response->result->status}\n"; |
| 36 | print "Capture ID: {$response->result->id}\n"; |
| 37 | print "Links:\n"; |
| 38 | foreach($response->result->links as $link) |
| 39 | { |
| 40 | print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; |
| 41 | } |
| 42 | // To toggle printing the whole response body comment/uncomment below line |
| 43 | echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; |
| 44 | } |
| 45 | return $response; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Driver function for invoking the capture flow. |
| 51 | */ |
| 52 | if (!count(debug_backtrace())) |
| 53 | { |
| 54 | CaptureOrder::captureOrder('18A38324BV5456924', true); |
| 55 | } |