PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / paypal / paypal-checkout-sdk / samples / PatchOrder.php

PatchOrder.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/paypal/paypal-checkout-sdk/samples/PatchOrder.php

82 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }