forked from LiveCarta/PayPal-PHP-SDK
Updates to Samples
- Added Sample to update payment amount just before execute - Minor Docs Updates
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -6,11 +6,6 @@
|
||||
<span class="hljs-variable">$tokenInfo</span> = <span class="hljs-keyword">new</span> OpenIdTokeninfo();
|
||||
<span class="hljs-variable">$tokenInfo</span> = <span class="hljs-variable">$tokenInfo</span>->createFromRefreshToken(<span class="hljs-keyword">array</span>(<span class="hljs-string">'refresh_token'</span> => <span class="hljs-variable">$refreshToken</span>), <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printError(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
ResultPrinter::printResult(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-variable">$tokenInfo</span>->getAccessToken(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$tokenInfo</span>);</div></div></div></div></body></html>
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Obtained Access Token From Refresh Token"</span>, <span class="hljs-string">"Access Token"</span>, <span class="hljs-variable">$tokenInfo</span>->getAccessToken(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$tokenInfo</span>);</div></div></div></div></body></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/<payment-id>/execute'.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ExecutePayment</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentExecution</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="approval-status">Approval Status</h3>
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentExecution</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="approval-status">Approval Status</h3>
|
||||
<p>Determine if the user approved the payment or not</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">if</span> (<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
payment id was previously stored in session in
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$paymentId</span> = <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'paymentId'</span>];
|
||||
@@ -19,7 +22,22 @@ CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrappe
|
||||
to execute a PayPal account payment.
|
||||
The payer_id is added to the request query parameters
|
||||
when the user is redirected from paypal back to your site</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$execution</span> = <span class="hljs-keyword">new</span> PaymentExecution();
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="optional-changes-to-amount">Optional Changes to Amount</h3>
|
||||
<p>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 <code>amount</code> field in it.
|
||||
Here is the example on how we changed the shipping to $1 more than before.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
|
||||
<span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
|
||||
|
||||
<span class="hljs-variable">$details</span>->setShipping(<span class="hljs-number">2.2</span>)
|
||||
->setTax(<span class="hljs-number">1.3</span>)
|
||||
->setSubtotal(<span class="hljs-number">17.50</span>);
|
||||
|
||||
<span class="hljs-variable">$amount</span>->setCurrency(<span class="hljs-string">'USD'</span>);
|
||||
<span class="hljs-variable">$amount</span>->setTotal(<span class="hljs-number">21</span>);
|
||||
<span class="hljs-variable">$amount</span>->setDetails(<span class="hljs-variable">$details</span>);
|
||||
<span class="hljs-variable">$transaction</span>->setAmount(<span class="hljs-variable">$amount</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add the above transaction object inside our Execution object.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$execution</span>->addTransaction(<span class="hljs-variable">$transaction</span>);
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Execute the payment
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$result</span> = <span class="hljs-variable">$payment</span>->execute(<span class="hljs-variable">$execution</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Executed Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>->getId(), <span class="hljs-variable">$execution</span>, <span class="hljs-variable">$result</span>);
|
||||
|
||||
@@ -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`)
|
||||
|
||||
Reference in New Issue
Block a user