| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sample; |
| 4 |
|
| 5 |
require __DIR__ . '/../vendor/autoload.php'; |
| 6 |
|
| 7 |
use PayPalCheckoutSdk\Orders\OrdersPatchRequest; |
| 8 |
use PayPalCheckoutSdk\Orders\OrdersGetRequest; |
| 9 |
use Sample\AuthorizeIntentExamples\CreateOrder; |
| 10 |
|
| 11 |
class PatchOrder |
| 12 |
{ |
| 13 |
private static function buildRequestBody() |
| 14 |
{ |
| 15 |
return array ( |
| 16 |
0 => |
| 17 |
array ( |
| 18 |
'op' => 'replace', |
| 19 |
'path' => '/intent', |
| 20 |
'value' => 'CAPTURE', |
| 21 |
), |
| 22 |
1 => |
| 23 |
array ( |
| 24 |
'op' => 'replace', |
| 25 |
'path' => '/purchase_units/@reference_id==\'PUHF\'/amount', |
| 26 |
'value' => |
| 27 |
array ( |
| 28 |
'currency_code' => 'USD', |
| 29 |
'value' => '200.00', |
| 30 |
'breakdown' => |
| 31 |
array ( |
| 32 |
'item_total' => |
| 33 |
array ( |
| 34 |
'currency_code' => 'USD', |
| 35 |
'value' => '180.00', |
| 36 |
), |
| 37 |
'tax_total' => |
| 38 |
array ( |
| 39 |
'currency_code' => 'USD', |
| 40 |
'value' => '20.00', |
| 41 |
), |
| 42 |
), |
| 43 |
), |
| 44 |
), |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
public static function patchOrder($orderId) |
| 49 |
{ |
| 50 |
|
| 51 |
$client = PayPalClient::client(); |
| 52 |
|
| 53 |
$request = new OrdersPatchRequest($orderId); |
| 54 |
$request->body = PatchOrder::buildRequestBody(); |
| 55 |
$client->execute($request); |
| 56 |
|
| 57 |
$response = $client->execute(new OrdersGetRequest($orderId)); |
| 58 |
|
| 59 |
print "Status Code: {$response->statusCode}\n"; |
| 60 |
print "Status: {$response->result->status}\n"; |
| 61 |
print "Order ID: {$response->result->id}\n"; |
| 62 |
print "Intent: {$response->result->intent}\n"; |
| 63 |
print "Links:\n"; |
| 64 |
foreach($response->result->links as $link) |
| 65 |
{ |
| 66 |
print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; |
| 67 |
} |
| 68 |
|
| 69 |
print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n"; |
| 70 |
|
| 71 |
// To toggle printing the whole response body comment/uncomment below line |
| 72 |
echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
if (!count(debug_backtrace())) |
| 77 |
{ |
| 78 |
print "Before PATCH:\n"; |
| 79 |
$createdOrder = CreateOrder::createOrder(true)->result; |
| 80 |
print "\nAfter PATCH (Changed Intent and Amount):\n"; |
| 81 |
PatchOrder::patchOrder($createdOrder->id); |
| 82 |
} |