From 32db0af73130d0a94fcccdf823ecf91f26ee0d68 Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Wed, 12 Aug 2015 16:36:39 -0500 Subject: [PATCH] Updates to Samples - Added Sample to update payment amount just before execute - Minor Docs Updates --- sample/doc/assets/behavior.js | 26 +++++++++++++++++-- .../GenerateAccessTokenFromRefreshToken.html | 9 ++----- sample/doc/payments/ExecutePayment.html | 22 ++++++++++++++-- sample/payments/ExecutePayment.php | 24 +++++++++++++++++ 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 9b43888..0f35e6a 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -518,7 +518,18 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "lipp/GenerateAccessTokenFromRefreshToken", "title": "GenerateAccessTokenFromRefreshToken" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Obtain Access Token From Refresh Token", + "slug": "obtain-access-token-from-refresh-token" + }, + "depth": 3 + } + ] }, { "type": "file", "data": { @@ -536,7 +547,18 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "pageTitle": "lipp/GetUserInfo", "title": "GetUserInfo" }, - "depth": 2 + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Obtain Access Token From Refresh Token", + "slug": "obtain-access-token-from-refresh-token" + }, + "depth": 3 + } + ] }, { "type": "file", "data": { diff --git a/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html b/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html index fc7bba9..a00e32c 100644 --- a/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html +++ b/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html @@ -6,11 +6,6 @@ $tokenInfo = new OpenIdTokeninfo(); $tokenInfo = $tokenInfo->createFromRefreshToken(array('refresh_token' => $refreshToken), $apiContext); -} catch (Exception $ex) { - // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printError("Obtained Access Token From Refresh Token", "Access Token", null, null, $ex); +} catch (Exception $ex) {

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printError("Obtained Access Token From Refresh Token", "Access Token", null, null, $ex); exit(1); -} - -// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY - ResultPrinter::printResult("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), null, $tokenInfo);
+}

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), null, $tokenInfo);
\ No newline at end of file diff --git a/sample/doc/payments/ExecutePayment.html b/sample/doc/payments/ExecutePayment.html index 0a2907f..f1fc85f 100644 --- a/sample/doc/payments/ExecutePayment.html +++ b/sample/doc/payments/ExecutePayment.html @@ -8,9 +8,12 @@ the buyer by logging into paypal site. You can optionally update transaction information by passing in one or more transactions. API used: POST '/v1/payments/payment//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;

Approval Status

+use PayPal\Api\PaymentExecution; +use PayPal\Api\Transaction;

Approval Status

Determine if the user approved the payment or not

if (isset($_GET['success']) && $_GET['success'] == 'true') {

Get the payment Object by passing paymentId payment id was previously stored in session in CreatePaymentUsingPayPal.php

$paymentId = $_GET['paymentId']; @@ -19,7 +22,22 @@ CreatePaymentUsingPayPal.php

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)

$result = $payment->execute($execution, $apiContext);

NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY

ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result); diff --git a/sample/payments/ExecutePayment.php b/sample/payments/ExecutePayment.php index 539becd..c1fb9e5 100644 --- a/sample/payments/ExecutePayment.php +++ b/sample/payments/ExecutePayment.php @@ -11,9 +11,12 @@ // API used: POST '/v1/payments/payment//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`)