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