Fixing Future Payment Sample

This commit is contained in:
Jay Patel
2015-07-21 11:23:41 -05:00
parent 9caf75ee82
commit 36f0dd7de9
3 changed files with 79 additions and 54 deletions

View File

@@ -490,53 +490,7 @@ 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": "invoice/UpdateInvoice", "pageTitle": "invoice/UpdateInvoice",
"title": "UpdateInvoice" "title": "UpdateInvoice"
}, },
"depth": 2, "depth": 2
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Update Invoice Sample",
"slug": "update-invoice-sample"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Update Invoice",
"slug": "update-invoice"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "NOTE: These are the work-around added to the",
"slug": "note-these-are-the-work-around-added-to-the"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Update Invoice",
"slug": "update-invoice"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Retrieve Invoice",
"slug": "retrieve-invoice"
},
"depth": 3
}
]
}
]
} }
] ]
}, { }, {
@@ -1008,7 +962,77 @@ 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": "payments/CreateFuturePayment", "pageTitle": "payments/CreateFuturePayment",
"title": "CreateFuturePayment" "title": "CreateFuturePayment"
}, },
"depth": 2 "depth": 2,
"outline": [
{
"type": "heading",
"data": {
"level": 1,
"title": "Create Payment using PayPal as payment method",
"slug": "create-payment-using-paypal-as-payment-method"
},
"depth": 1,
"children": [
{
"type": "heading",
"data": {
"level": 3,
"title": "Payer",
"slug": "payer"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Amount",
"slug": "amount"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Transaction",
"slug": "transaction"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Redirect urls",
"slug": "redirect-urls"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Payment",
"slug": "payment"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Get Refresh Token",
"slug": "get-refresh-token"
},
"depth": 3
}, {
"type": "heading",
"data": {
"level": 3,
"title": "Create Future Payment",
"slug": "create-future-payment"
},
"depth": 3
}
]
}
]
}, { }, {
"type": "file", "type": "file",
"data": { "data": {

View File

@@ -3,10 +3,11 @@
PayPal Account based Payment. PayPal Account based Payment.
API used: /v1/payments/payment</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>; API used: /v1/payments/payment</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">Amount</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FuturePayment</span>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FuturePayment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RedirectUrls</span>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RedirectUrls</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>; <span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;
session_start();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payer">Payer</h3> session_start();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payer">Payer</h3>
<p>A resource representing a Payer that funds a payment <p>A resource representing a Payer that funds a payment
For paypal account payments, set payment method For paypal account payments, set payment method
@@ -33,7 +34,7 @@ the above types and intent set to &#39;sale&#39;</p></div></div><div class="code
-&gt;setPayer(<span class="hljs-variable">$payer</span>) -&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>) -&gt;setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-refresh-token">Get Refresh Token</h3> -&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-refresh-token">Get Refresh Token</h3>
<p>You need to get a permanent refresh token from the authorization code, retrieved from the mobile sdk.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>authorization code from mobile sdk</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationCode</span> = <span class="hljs-string">'EJfRuAqXEE95pdVMmOym_mftTbeJD03RBX-Zjg9pLCAhdLqLeRR6YSKTNsrbQGX7lFoZ3SxwFyxADEZbBOxpn023W9SA0JzSQAy-9eLdON5eDPAyMyKlHyNVS2DqBR2iWVfQGfudbd9MDoRxMEjIZbY'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Client Metadata id from mobile sdk <p>You need to get a permanent refresh token from the authorization code, retrieved from the mobile sdk.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>authorization code from mobile sdk</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationCode</span> = <span class="hljs-string">'EK7_MAKlB4QxW1dWKnvnr_CEdLKnpH3vnGAf155Eg8yO8e_7VaQonsqIbTK9CR7tUsoIN2eCc5raOfaGbZDCT0j6k_BDE8GkyLgk8ulcQyR_3S-fgBzjMzBwNqpj3AALgCVR03zw1iT8HTsxZXp3s2U'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Client Metadata id from mobile sdk
For more information look for PayPal-Client-Metadata-Id in <a href="https://developer.paypal.com/docs/api/#authentication--headers">https://developer.paypal.com/docs/api/#authentication--headers</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$clientMetadataId</span> = <span class="hljs-string">'123123456'</span>; For more information look for PayPal-Client-Metadata-Id in <a href="https://developer.paypal.com/docs/api/#authentication--headers">https://developer.paypal.com/docs/api/#authentication--headers</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$clientMetadataId</span> = <span class="hljs-string">'123123456'</span>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Exchange authorization_code for long living refresh token. You should store <span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Exchange authorization_code for long living refresh token. You should store
@@ -46,7 +47,7 @@ url to which the buyer must be redirected to
for payment approval for payment approval
Please note that currently future payments works only with PayPal as a funding instrument.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$payment</span>-&gt;create(<span class="hljs-variable">$apiContext</span>, <span class="hljs-variable">$clientMetadataId</span>); Please note that currently future payments works only with PayPal as a funding instrument.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$payment</span>-&gt;create(<span class="hljs-variable">$apiContext</span>, <span class="hljs-variable">$clientMetadataId</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">"Future Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</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">"Future Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$payment</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>); <span class="hljs-keyword">exit</span>(<span class="hljs-number">1</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">"Future Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</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">"Future Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);

View File

@@ -67,10 +67,10 @@ $clientMetadataId = '123123456';
try { try {
// Exchange authorization_code for long living refresh token. You should store // Exchange authorization_code for long living refresh token. You should store
// it in a database for later use // it in a database for later use
//$refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext); $refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext);
echo $refreshToken;
// Update the access token in apiContext // Update the access token in apiContext
$payment->updateAccessToken('NvtsgQLDxJXfFTOpYRS5Ad9S1kOd_QWCk4vkdPuBe9qDfKDBbKyioSMXeMwSaLKr4Lz_zoFEpZBiHrce4X4IcAfabH0', $apiContext); $payment->updateAccessToken($refreshToken, $apiContext);
// For Sample Purposes Only. // For Sample Purposes Only.
$request = clone $payment; $request = clone $payment;