Updates to Samples

- Added Sample to update payment amount just before execute
- Minor Docs Updates
This commit is contained in:
Jay Patel
2015-08-12 16:36:39 -05:00
parent 63fbe50138
commit 32db0af731
4 changed files with 70 additions and 11 deletions

View File

@@ -11,9 +11,12 @@
// API used: POST '/v1/payments/payment/<payment-id>/execute'.
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\ExecutePayment;
use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution;
use PayPal\Api\Transaction;
// ### Approval Status
// Determine if the user approved the payment or not
@@ -33,6 +36,27 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
$execution = new PaymentExecution();
$execution->setPayerId($_GET['PayerID']);
// ### Optional Changes to Amount
// If you wish to update the amount that you wish to charge the customer,
// based on the shipping address or any other reason, you could
// do that by passing the transaction object with just `amount` field in it.
// Here is the example on how we changed the shipping to $1 more than before.
$transaction = new Transaction();
$amount = new Amount();
$details = new Details();
$details->setShipping(2.2)
->setTax(1.3)
->setSubtotal(17.50);
$amount->setCurrency('USD');
$amount->setTotal(21);
$amount->setDetails($details);
$transaction->setAmount($amount);
// Add the above transaction object inside our Execution object.
$execution->addTransaction($transaction);
try {
// Execute the payment
// (See bootstrap.php for more on `ApiContext`)