Order API Support

- Added Order API Support
- Updated Sample Code to demonstrate
- Updated Sample Docs
- Fixes #237
This commit is contained in:
japatel
2015-02-04 15:54:30 -06:00
parent 217a54f0a6
commit 47cd78172c
22 changed files with 2045 additions and 306 deletions

View File

@@ -0,0 +1,40 @@
<?php
// #Void Order Sample
// Use this call to void an existing order.
// Note: An order cannot be voided if payment has already been partially or fully captured.
// API used: POST /v1/payments/orders/<Order-Id>/do-void
/** @var \PayPal\Api\Payment $payment */
$payment = require __DIR__ . '/ExecutePayment.php';
use PayPal\Api\Capture;
use PayPal\Api\Amount;
// ### Approval Status
// Determine if the user approved the payment or not
if (isset($_GET['success']) && $_GET['success'] == 'true') {
// ### Retrieve the order
// OrderId could be retrieved by parsing the object inside related_resources.
$transactions = $payment->getTransactions();
$transaction = $transactions[0];
$relatedResources = $transaction->getRelatedResources();
$relatedResource = $relatedResources[0];
$order = $relatedResource->getOrder();
try {
// ### Void Order
// Call void method on order object. You will get an Order Object back
$result = $order->void($apiContext);
ResultPrinter::printResult("Voided Order", "Order", $result->getId(), null, $result);
} catch (Exception $ex) {
ResultPrinter::printError("Voided Order", "Order", null, null, $ex);
exit(1);
}
return $result;
} else {
ResultPrinter::printResult("User Cancelled the Approval", null);
exit;
}