48 lines
No EOL
6.7 KiB
HTML
48 lines
No EOL
6.7 KiB
HTML
<!DOCTYPE html><html lang="en"><head><title>CreateCreditCard</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="CreateCreditCard"><meta name="groc-project-path" content="CreateCreditCard.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="create-credit-card-sample">Create Credit Card Sample</h1>
|
|
|
|
<p>Using the 'vault' API, you can store a
|
|
Credit Card securely on PayPal. You can
|
|
use a saved Credit Card to process
|
|
a payment in the future.
|
|
The following code demonstrates how
|
|
can save a Credit Card on PayPal using
|
|
the Vault API.
|
|
API used: POST /v1/vault/credit-card</p></div></div><div class="code"><div class="wrapper"><span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
|
|
|
<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\CreditCard</span><span class="p">;</span>
|
|
<span class="k">use</span> <span class="nx">PayPal\Api\Address</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="creditcard">CreditCard</h3>
|
|
|
|
<p>A resource representing a credit card that can be
|
|
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setType</span><span class="p">(</span><span class="s2">"visa"</span><span class="p">);</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setNumber</span><span class="p">(</span><span class="s2">"4417119669820331"</span><span class="p">);</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">"11"</span><span class="p">);</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">"2019"</span><span class="p">);</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">"012"</span><span class="p">);</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">"Joe"</span><span class="p">);</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</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"><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> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</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"><h3 id="save-card">Save card</h3>
|
|
|
|
<p>Creates the credit card as a resource
|
|
in the PayPal vault. The response contains
|
|
an 'id' that you can use to refer to it
|
|
in the future payments.</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
|
<span class="nv">$card</span><span class="o">-></span><span class="na">create</span><span class="p">();</span>
|
|
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
|
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
|
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
|
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
|
<span class="p">}</span>
|
|
<span class="cp">?></span><span class="x"></span>
|
|
<span class="x"><html></span>
|
|
<span class="x"><body></span>
|
|
<span class="x"> <div>Saved a new credit card with id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$card</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span><span class="cp">?></span><span class="x"></div></span>
|
|
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
|
<span class="x"> <a href='../index.html'>Back</a></span>
|
|
<span class="x"></body></span>
|
|
<span class="x"></html></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> |