![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mcoil.corals.io/vendor/paypal/rest-api-sdk-php/sample/doc/vault/ |
<!DOCTYPE html><html lang="en"><head><title>vault/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="vault/CreateCreditCard"><meta name="groc-project-path" content="vault/CreateCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">vault/CreateCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-credit-card-sample">Create Credit Card Sample</h1> <p>You can store credit card details securely with PayPal. You can then use the returned Credit card id to process future payments. API used: POST /v1/vault/credit-card</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">CreditCard</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="creditcard">CreditCard</h3> <p>A resource representing a credit card that is to be stored with PayPal.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> CreditCard(); <span class="hljs-variable">$card</span>->setType(<span class="hljs-string">"visa"</span>) ->setNumber(<span class="hljs-string">"4917912523797702"</span>) ->setExpireMonth(<span class="hljs-string">"11"</span>) ->setExpireYear(<span class="hljs-string">"2019"</span>) ->setCvv2(<span class="hljs-string">"012"</span>) ->setFirstName(<span class="hljs-string">"Joe"</span>) ->setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-information">Additional Information</h3> <p>Now you can also store the information that could help you connect your users with the stored credit cards. All these three fields could be used for storing any information that could help merchant to point the card. However, Ideally, MerchantId could be used to categorize stores, apps, websites, etc. ExternalCardId could be used for uniquely identifying the card per MerchantId. So, combination of "MerchantId" and "ExternalCardId" should be unique. ExternalCustomerId could be userId, user email, etc to group multiple cards per user.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span>->setMerchantId(<span class="hljs-string">"MyStore1"</span>); <span class="hljs-variable">$card</span>->setExternalCardId(<span class="hljs-string">"CardNumber123"</span> . uniqid()); <span class="hljs-variable">$card</span>->setExternalCustomerId(<span class="hljs-string">"[email protected]"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$card</span>;</div></div></div><div class="segment"><div class="comments "><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 future payments. (See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> { <span class="hljs-variable">$card</span>->create(<span class="hljs-variable">$apiContext</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">"Create Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</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">"Create Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>->getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$card</span>); <span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>