AuthorizeOrder.php
5 years ago
CaptureOrder.php
5 years ago
CreateOrder.php
5 years ago
RunAll.php
5 years ago
RunAll.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | require __DIR__ . '/../../vendor/autoload.php'; |
| 4 | |
| 5 | use Sample\AuthorizeIntentExamples\CreateOrder; |
| 6 | use Sample\AuthorizeIntentExamples\AuthorizeOrder; |
| 7 | use Sample\AuthorizeIntentExamples\CaptureOrder; |
| 8 | use Sample\RefundOrder; |
| 9 | |
| 10 | $order = CreateOrder::createOrder(); |
| 11 | |
| 12 | print "Creating Order...\n"; |
| 13 | $orderId = ""; |
| 14 | if ($order->statusCode == 201) |
| 15 | { |
| 16 | $orderId = $order->result->id; |
| 17 | print "Links:\n"; |
| 18 | for ($i = 0; $i < count($order->result->links); ++$i) |
| 19 | { |
| 20 | $link = $order->result->links[$i]; |
| 21 | print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; |
| 22 | } |
| 23 | print "Created Successfully\n"; |
| 24 | print "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n"; |
| 25 | } |
| 26 | else { |
| 27 | exit(1); |
| 28 | } |
| 29 | |
| 30 | $handle = fopen ("php://stdin","r"); |
| 31 | $line = fgets($handle); |
| 32 | fclose($handle); |
| 33 | |
| 34 | print "Authorizing Order...\n"; |
| 35 | $response = AuthorizeOrder::authorizeOrder($orderId); |
| 36 | $authId = ""; |
| 37 | |
| 38 | if ($response->statusCode == 201) |
| 39 | { |
| 40 | print "Authorized Successfully\n"; |
| 41 | $authId = $response->result->purchase_units[0]->payments->authorizations[0]->id; |
| 42 | } |
| 43 | else { |
| 44 | exit(1); |
| 45 | } |
| 46 | |
| 47 | print "\nCapturing Order...\n"; |
| 48 | $response = CaptureOrder::captureOrder($authId); |
| 49 | if ($response->statusCode == 201) |
| 50 | { |
| 51 | print "Captured Successfully\n"; |
| 52 | print "Status Code: {$response->statusCode}\n"; |
| 53 | print "Status: {$response->result->status}\n"; |
| 54 | $captureId = $response->result->id; |
| 55 | print "Capture ID: {$captureId}\n"; |
| 56 | print "Links:\n"; |
| 57 | for ($i = 0; $i < count($response->result->links); ++$i){ |
| 58 | $link = $response->result->links[$i]; |
| 59 | print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; |
| 60 | } |
| 61 | } |
| 62 | else { |
| 63 | exit(1); |
| 64 | } |
| 65 | |
| 66 | print "\nRefunding Order...\n"; |
| 67 | $response = RefundOrder::refundOrder($captureId); |
| 68 | if ($response->statusCode == 201) |
| 69 | { |
| 70 | print "Refunded Successfully\n"; |
| 71 | print "Status Code: {$response->statusCode}\n"; |
| 72 | print "Status: {$response->result->status}\n"; |
| 73 | print "Refund ID: {$response->result->id}\n"; |
| 74 | print "Links:\n"; |
| 75 | for ($i = 0; $i < count($response->result->links); ++$i){ |
| 76 | $link = $response->result->links[$i]; |
| 77 | print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; |
| 78 | } |
| 79 | } |
| 80 | else { |
| 81 | exit(1); |
| 82 | } |
| 83 |