40 lines
5.9 KiB
HTML
40 lines
5.9 KiB
HTML
|
<!DOCTYPE html><html lang="en"><head><title>ExecutePayment</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="ExecutePayment"><meta name="groc-project-path" content="ExecutePayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="execute-payment-sample">Execute Payment Sample</h1>
|
||
|
|
||
|
<p>This sample shows how you can complete
|
||
|
a payment that has been approved by
|
||
|
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="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||
|
<span class="k">use</span> <span class="nx">PayPal\Api\ExecutePayment</span><span class="p">;</span>
|
||
|
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||
|
<span class="k">use</span> <span class="nx">PayPal\Api\PaymentExecution</span><span class="p">;</span>
|
||
|
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||
|
<span class="nb">session_start</span><span class="p">();</span>
|
||
|
|
||
|
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">])</span> <span class="o">&&</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'true'</span><span class="p">)</span> <span class="p">{</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||
|
|
||
|
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||
|
the call and to send a unique request id
|
||
|
(that ensures idempotency). The SDK generates
|
||
|
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"> <span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||
|
</div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><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="nv">$paymentId</span> <span class="o">=</span> <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">];</span>
|
||
|
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">);</span>
|
||
|
</div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||
|
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="nv">$execution</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PaymentExecution</span><span class="p">();</span>
|
||
|
<span class="nv">$execution</span><span class="o">-></span><span class="na">setPayer_id</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'PayerID'</span><span class="p">]);</span>
|
||
|
|
||
|
<span class="c1">//Execute the payment</span>
|
||
|
<span class="nv">$payment</span><span class="o">-></span><span class="na">execute</span><span class="p">(</span><span class="nv">$execution</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||
|
|
||
|
<span class="k">echo</span> <span class="s2">"<html><body><pre>"</span><span class="p">;</span>
|
||
|
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span>
|
||
|
<span class="k">echo</span> <span class="s2">"</pre><a href='../index.html'>Back</a></body></html>"</span><span class="p">;</span>
|
||
|
|
||
|
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||
|
<span class="k">echo</span> <span class="s2">"User cancelled payment."</span><span class="p">;</span>
|
||
|
<span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|