AuthorizeIntentExamples
5 years ago
CaptureIntentExamples
5 years ago
ErrorSample.php
5 years ago
GetOrder.php
5 years ago
PatchOrder.php
5 years ago
PayPalClient.php
5 years ago
RefundOrder.php
5 years ago
GetOrder.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Sample; |
| 4 | |
| 5 | require __DIR__ . '/../vendor/autoload.php'; |
| 6 | |
| 7 | use Sample\PayPalClient; |
| 8 | use PayPalCheckoutSdk\Orders\OrdersGetRequest; |
| 9 | use Sample\CaptureIntentExamples\CreateOrder; |
| 10 | |
| 11 | class GetOrder |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * This function can be used to retrieve an order by passing order Id as argument. |
| 16 | */ |
| 17 | public static function getOrder($orderId) |
| 18 | { |
| 19 | |
| 20 | $client = PayPalClient::client(); |
| 21 | $response = $client->execute(new OrdersGetRequest($orderId)); |
| 22 | /** |
| 23 | * Enable below line to print complete response as JSON. |
| 24 | */ |
| 25 | //print json_encode($response->result); |
| 26 | print "Status Code: {$response->statusCode}\n"; |
| 27 | print "Status: {$response->result->status}\n"; |
| 28 | print "Order ID: {$response->result->id}\n"; |
| 29 | print "Intent: {$response->result->intent}\n"; |
| 30 | print "Links:\n"; |
| 31 | foreach($response->result->links as $link) |
| 32 | { |
| 33 | print "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n"; |
| 34 | } |
| 35 | |
| 36 | print "Gross Amount: {$response->result->purchase_units[0]->amount->currency_code} {$response->result->purchase_units[0]->amount->value}\n"; |
| 37 | |
| 38 | // To toggle printing the whole response body comment/uncomment below line |
| 39 | echo json_encode($response->result, JSON_PRETTY_PRINT), "\n"; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * This is the driver function which invokes the getOrder function to retrieve |
| 45 | * an sample order. |
| 46 | * |
| 47 | * To get the correct Order id, we are using the createOrder to create new order |
| 48 | * and then we are using the newly created order id. |
| 49 | */ |
| 50 | if (!count(debug_backtrace())) |
| 51 | { |
| 52 | $createdOrder = CreateOrder::createOrder()->result; |
| 53 | GetOrder::getOrder($createdOrder ->id); |
| 54 | } |