forked from paypal/Checkout-PHP-SDK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RunAll.php
65 lines (58 loc) · 2.04 KB
/
RunAll.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require __DIR__.'/../../vendor/autoload.php';
use Sample\CaptureIntentExamples\CaptureOrder;
use Sample\CaptureIntentExamples\CreateOrder;
use Sample\RefundOrder;
$order = CreateOrder::createOrder();
print "Creating Order...\n";
$orderId = "";
if ($order->statusCode == 201) {
$orderId = $order->result->id;
print "Links:\n";
for ($i = 0; $i < count($order->result->links); ++$i) {
$link = $order->result->links[$i];
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
}
print "Created Successfully\n";
print "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter...\n";
} else {
exit(1);
}
$handle = fopen("php://stdin", "r");
$line = fgets($handle);
fclose($handle);
print "Capturing Order...\n";
$response = CaptureOrder::captureOrder($orderId);
if ($response->statusCode == 201) {
print "Captured Successfully\n";
print "Status Code: {$response->statusCode}\n";
print "Status: {$response->result->status}\n";
print "Order ID: {$response->result->id}\n";
print "Links:\n";
for ($i = 0; $i < count($response->result->links); ++$i) {
$link = $response->result->links[$i];
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
}
foreach ($response->result->purchase_units as $purchase_unit) {
foreach ($purchase_unit->payments->captures as $capture) {
$captureId = $capture->id;
}
}
} else {
exit(1);
}
print "\nRefunding Order...\n";
$response = RefundOrder::refundOrder($captureId);
if ($response->statusCode == 201) {
print "Refunded Successfully\n";
print "Status Code: {$response->statusCode}\n";
print "Status: {$response->result->status}\n";
print "Refund ID: {$response->result->id}\n";
print "Links:\n";
for ($i = 0; $i < count($response->result->links); ++$i) {
$link = $response->result->links[$i];
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
}
} else {
exit(1);
}