Updated samples and its documentation

This commit is contained in:
brluk and japatel
2017-10-24 12:05:49 -05:00
parent ddc8b6d482
commit 0303e2c0c9
98 changed files with 3063 additions and 1068 deletions

View File

@@ -5,10 +5,11 @@
// This sample code demonstrate how you can get a billing agreement, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement
// API used: /v1/payments/billing-agreements/<Agreement-Id>
require __DIR__ . '/../bootstrap.php';
// Retrieving the Agreement object from Create Agreement From Credit Card Sample
/** @var Agreement $createdAgreement */
$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php';
$createdAgreement = "your billing agreement id";
use PayPal\Api\Agreement;

View File

@@ -7,8 +7,7 @@
// API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend
// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
/** @var Agreement $createdAgreement */
$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php';
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Agreement;
use PayPal\Api\AgreementStateDescriptor;
@@ -17,6 +16,10 @@ use PayPal\Api\AgreementStateDescriptor;
$agreementStateDescriptor = new AgreementStateDescriptor();
$agreementStateDescriptor->setNote("Suspending the agreement");
// Fetch the agreement object
/** @var Agreement $createdAgreement */
$createdAgreement = null; // Replace this with your fetched agreement object
try {
$createdAgreement->suspend($agreementStateDescriptor, $apiContext);

View File

@@ -6,9 +6,11 @@
// https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement
// API used: /v1/payments/billing-agreements/<Agreement-Id>
require __DIR__ . '/../bootstrap.php';
// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
/** @var Agreement $createdAgreement */
$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php';
$createdAgreement = 'your agreement id';
use PayPal\Api\Agreement;
use PayPal\Api\Patch;

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
<!DOCTYPE html><html lang="en"><head><title>billing/GetBillingAgreement</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="billing/GetBillingAgreement"><meta name="groc-project-path" content="billing/GetBillingAgreement.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">billing/GetBillingAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-billing-agreement-sample">Get Billing Agreement Sample</h1>
<p>This sample code demonstrate how you can get a billing agreement, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement</a>
API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement From Credit Card Sample</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBillingAgreementWithCreditCard.php'</span>;
API used: /v1/payments/billing-agreements/<Agreement-Id></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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement From Credit Card Sample</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-string">"your billing agreement id"</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;

View File

@@ -1,15 +1,15 @@
<!DOCTYPE html><html lang="en"><head><title>billing/SuspendBillingAgreement</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="billing/SuspendBillingAgreement"><meta name="groc-project-path" content="billing/SuspendBillingAgreement.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">billing/SuspendBillingAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="suspend-an-agreement">Suspend an agreement</h1>
<p>This sample code demonstrate how you can suspend a billing agreement, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement</a>
API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBillingAgreementWithCreditCard.php'</span>;
API used: /v1/payments/billing-agreements/<Agreement-Id>/suspend</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</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">Agreement</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">AgreementStateDescriptor</span>;
<span class="hljs-comment">//Create an Agreement State Descriptor, explaining the reason to suspend.</span>
<span class="hljs-variable">$agreementStateDescriptor</span> = <span class="hljs-keyword">new</span> AgreementStateDescriptor();
<span class="hljs-variable">$agreementStateDescriptor</span>-&gt;setNote(<span class="hljs-string">"Suspending the agreement"</span>);
<span class="hljs-variable">$agreementStateDescriptor</span>-&gt;setNote(<span class="hljs-string">"Suspending the agreement"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Fetch the agreement object</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">null</span>; <span class="hljs-comment">// Replace this with your fetched agreement object</span>
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$createdAgreement</span>-&gt;suspend(<span class="hljs-variable">$agreementStateDescriptor</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lets get the updated Agreement Object</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = Agreement::get(<span class="hljs-variable">$createdAgreement</span>-&gt;getId(), <span class="hljs-variable">$apiContext</span>);

View File

@@ -1,8 +1,8 @@
<!DOCTYPE html><html lang="en"><head><title>billing/UpdateBillingAgreement</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="billing/UpdateBillingAgreement"><meta name="groc-project-path" content="billing/UpdateBillingAgreement.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">billing/UpdateBillingAgreement.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="update-an-agreement">Update an agreement</h1>
<p>This sample code demonstrate how you can update a billing agreement, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement</a>
API used: /v1/payments/billing-agreements/<Agreement-Id></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBillingAgreementWithCreditCard.php'</span>;
API used: /v1/payments/billing-agreements/<Agreement-Id></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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Agreement object from Create Agreement Sample to demonstrate the List</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Agreement $createdAgreement */</span>
<span class="hljs-variable">$createdAgreement</span> = <span class="hljs-string">'your agreement id'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</span>;

View File

@@ -52,9 +52,7 @@ To resolve that, we need to use alternative, which makes a call to PayPal&#39;s
<span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionSig(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-TRANSMISSION-SIG'</span>]);
<span class="hljs-variable">$signatureVerification</span>-&gt;setTransmissionTime(<span class="hljs-variable">$headers</span>[<span class="hljs-string">'PAYPAL-TRANSMISSION-TIME'</span>]);
<span class="hljs-variable">$webhookEvent</span> = <span class="hljs-keyword">new</span> WebhookEvent();
<span class="hljs-variable">$webhookEvent</span>-&gt;fromJson(<span class="hljs-variable">$requestBody</span>);
<span class="hljs-variable">$signatureVerification</span>-&gt;setWebhookEvent(<span class="hljs-variable">$webhookEvent</span>);
<span class="hljs-variable">$signatureVerification</span>-&gt;setRequestBody(<span class="hljs-variable">$requestBody</span>);
<span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$signatureVerification</span>;
<span class="hljs-keyword">try</span> {

View File

@@ -1,85 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>payments/CreatePayment</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="payments/CreatePayment"><meta name="groc-project-path" content="payments/CreatePayment.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">payments/CreatePayment.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="createpaymentsample">CreatePaymentSample</h1>
<p>This sample code demonstrate how you can process
a direct credit card payment. Please note that direct
credit card payment and related features using the
REST API is restricted in some countries.
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">Details</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FundingInstrument</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ItemList</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">Payment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PaymentCard</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="paymentcard">PaymentCard</h3>
<p>A resource representing a payment card that can be
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> PaymentCard();
<span class="hljs-variable">$card</span>-&gt;setType(<span class="hljs-string">"visa"</span>)
-&gt;setNumber(<span class="hljs-string">"4669424246660779"</span>)
-&gt;setExpireMonth(<span class="hljs-string">"11"</span>)
-&gt;setExpireYear(<span class="hljs-string">"2019"</span>)
-&gt;setCvv2(<span class="hljs-string">"012"</span>)
-&gt;setFirstName(<span class="hljs-string">"Joe"</span>)
-&gt;setBillingCountry(<span class="hljs-string">"US"</span>)
-&gt;setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
<p>A resource representing a Payer&#39;s funding instrument.
For direct credit card payments, set the CreditCard
field on this object.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument();
<span class="hljs-variable">$fi</span>-&gt;setPaymentCard(<span class="hljs-variable">$card</span>);</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
For direct credit card payments, set payment method
to &#39;credit_card&#39; and add an array of funding instruments.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
-&gt;setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="itemized-information">Itemized information</h3>
<p>(Optional) Lets you specify item wise
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item1</span>-&gt;setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
-&gt;setDescription(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">1</span>)
-&gt;setTax(<span class="hljs-number">0.3</span>)
-&gt;setPrice(<span class="hljs-number">7.50</span>);
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item2</span>-&gt;setName(<span class="hljs-string">'Granola bars'</span>)
-&gt;setDescription(<span class="hljs-string">'Granola Bars with Peanuts'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">5</span>)
-&gt;setTax(<span class="hljs-number">0.2</span>)
-&gt;setPrice(<span class="hljs-number">2</span>);
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
<span class="hljs-variable">$itemList</span>-&gt;setItems(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$item1</span>, <span class="hljs-variable">$item2</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-payment-details">Additional payment details</h3>
<p>Use this optional field to set additional
payment information such as tax, shipping
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
<span class="hljs-variable">$details</span>-&gt;setShipping(<span class="hljs-number">1.2</span>)
-&gt;setTax(<span class="hljs-number">1.3</span>)
-&gt;setSubtotal(<span class="hljs-number">17.5</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Lets you specify a payment amount.
You can also specify additional details
such as shipping, tax.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
-&gt;setTotal(<span class="hljs-number">20</span>)
-&gt;setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a
payment - what is the payment for and who
is fulfilling it. </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">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>)
-&gt;setItemList(<span class="hljs-variable">$itemList</span>)
-&gt;setDescription(<span class="hljs-string">"Payment description"</span>)
-&gt;setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using
the above types and intent set to sale &#39;sale&#39;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"sale"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</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"><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">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by calling the payment-&gt;create() method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
The return object contains the state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$payment</span>-&gt;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 Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using &lt;a href="https://www.paypal-knowledge.com/infocenter/index?page=content&amp;widgetview=true&amp;id=FAQ1413"&gt;Step 4, on this link&lt;/a&gt;, and using it.'</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">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 Payment Using Credit Card'</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>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>

View File

@@ -10,7 +10,6 @@ information by passing in one or more transactions.
API used: POST &#39;/v1/payments/payment/<payment-id>/execute&#39;.</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>;
<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>

View File

@@ -5,15 +5,16 @@ you&#39;ve created using the Payments API.
Note various query parameters that you can
use to filter, and paginate through the
payments list.
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Payment $createdPayment */</span>
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$createdPayment</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/CreatePaymentUsingPayPal.php'</span>;
<span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Payment $createdPayment */</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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $paymentId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$paymentId</span> = <span class="hljs-string">"&lt;your paymentid here&gt;"</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<p>Retrieve the payment object by calling the
static <code>get</code> method
on the Payment class by passing a valid
Payment ID
(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">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$createdPayment</span>-&gt;getId(), <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">"Get Payment"</span>, <span class="hljs-string">"Payment"</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>);
}</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">"Get Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$payment</span>);

View File

@@ -5,7 +5,7 @@ you&#39;ve created using the Payments API.
Note various query parameters that you can
use to filter, and paginate through the
payments list.
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePayment.php'</span>;
API used: GET /v1/payments/payments</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">'/CreatePaymentUsingPayPal.php'</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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<p>Retrieve the PaymentHistory object by calling the
static <code>get</code> method on the Payment class,

View File

@@ -2,14 +2,9 @@
<p>Sale transactions are nothing but completed payments.
This sample code demonstrates how you can retrieve
details of completed Sale Transaction.
API used: /v1/payments/sale/{sale-id}</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Payment $payment */</span>
<span class="hljs-variable">$payment</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../payments/CreatePayment.php'</span>;
API used: /v1/payments/sale/{sale-id}</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">Payment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Sale</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-sale-from-created-payment">Get Sale From Created Payment</h3>
<p>You can retrieve the sale Id from Related Resources for each transactions.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transactions</span> = <span class="hljs-variable">$payment</span>-&gt;getTransactions();
<span class="hljs-variable">$relatedResources</span> = <span class="hljs-variable">$transactions</span>[<span class="hljs-number">0</span>]-&gt;getRelatedResources();
<span class="hljs-variable">$sale</span> = <span class="hljs-variable">$relatedResources</span>[<span class="hljs-number">0</span>]-&gt;getSale();
<span class="hljs-variable">$saleId</span> = <span class="hljs-variable">$sale</span>-&gt;getId();
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Sale</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>You can retrieve the sale Id from Related Resources for each transactions.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$saleId</span> = <span class="hljs-string">"enter your sale id"</span>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
<p>Pass the ID of the sale

View File

@@ -1,65 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/CreateBankAccount</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/CreateBankAccount"><meta name="groc-project-path" content="vault/CreateBankAccount.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/CreateBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-bank-account-sample">Create Bank Account Sample</h1>
<p>You can store credit card details securely
with PayPal. You can then use the returned
Bank Account id to process future payments.
API used: POST /v1/vault/bank-accounts</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">BankAccount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="bank-account">Bank Account</h3>
<p>A resource representing a bank account that is
to be stored with PayPal.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/*
{
"account_number": "4417119669820331",
"account_number_type": "IBAN",
"account_type": "SAVINGS",
"account_name": "Ramraj",
"check_type": "PERSONAL",
"auth_type": "WEB",
"bank_name": "CITI",
"country_code": "US",
"first_name": "Ramraj",
"last_name": "K",
"birth_date": "1987-08-13",
"billing_address": {
"line1": "52 N Main ST",
"city": "Johnstown",
"country_code": "US",
"postal_code": "43210",
"state": "OH",
"phone": "408-334-8890"
},
"external_customer_id": "external_id"
}
*/</span>
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">new</span> BankAccount();
<span class="hljs-variable">$bankAccount</span>-&gt;setAccountNumber(<span class="hljs-string">"4417119669820331"</span>)
-&gt;setAccountNumberType(<span class="hljs-string">"IBAN"</span>)
-&gt;setAccountType(<span class="hljs-string">"SAVINGS"</span>)
-&gt;setAccountName(<span class="hljs-string">"Ramraj"</span>)
-&gt;setCheckType(<span class="hljs-string">"PERSONAL"</span>)
-&gt;setAuthType(<span class="hljs-string">"WEB"</span>)
-&gt;setBankName(<span class="hljs-string">"CITI"</span>)
-&gt;setCountryCode(<span class="hljs-string">"US"</span>)
-&gt;setFirstName(<span class="hljs-string">"Ramraj"</span>)
-&gt;setLastName(<span class="hljs-string">"K"</span>)
-&gt;setBirthDate(<span class="hljs-string">"1987-08-13"</span>)
-&gt;setExternalCustomerId(uniqid());
<span class="hljs-variable">$billingAddress</span> = <span class="hljs-keyword">new</span> \PayPal\Api\Address();
<span class="hljs-variable">$billingAddress</span>-&gt;setLine1(<span class="hljs-string">"52 N Main St"</span>)
-&gt;setCity(<span class="hljs-string">"Johnstown"</span>)
-&gt;setState(<span class="hljs-string">"OH"</span>)
-&gt;setCountryCode(<span class="hljs-string">"US"</span>)
-&gt;setPostalCode(<span class="hljs-string">"43210"</span>)
-&gt;setPhone(<span class="hljs-string">"408-334-8890"</span>);
<span class="hljs-variable">$bankAccount</span>-&gt;setBillingAddress(<span class="hljs-variable">$billingAddress</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">$bankAccount</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="save-bank-account">Save bank account</h3>
<p>Creates the bank account as a resource
in the PayPal vault. The response contains
an &#39;id&#39; 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">$bankAccount</span>-&gt;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 Bank Account"</span>, <span class="hljs-string">"Bank Account"</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 Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$bankAccount</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div></div></body></html>

View File

@@ -1,34 +0,0 @@
<!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">&lt;?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>-&gt;setType(<span class="hljs-string">"visa"</span>)
-&gt;setNumber(<span class="hljs-string">"4917912523797702"</span>)
-&gt;setExpireMonth(<span class="hljs-string">"11"</span>)
-&gt;setExpireYear(<span class="hljs-string">"2019"</span>)
-&gt;setCvv2(<span class="hljs-string">"012"</span>)
-&gt;setFirstName(<span class="hljs-string">"Joe"</span>)
-&gt;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 &quot;MerchantId&quot; and &quot;ExternalCardId&quot; 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>-&gt;setMerchantId(<span class="hljs-string">"MyStore1"</span>);
<span class="hljs-variable">$card</span>-&gt;setExternalCardId(<span class="hljs-string">"CardNumber123"</span> . uniqid());
<span class="hljs-variable">$card</span>-&gt;setExternalCustomerId(<span class="hljs-string">"123123-myUser1@something.com"</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 &#39;id&#39; 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>-&gt;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>-&gt;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>

View File

@@ -1,13 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/DeleteBankAccount</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/DeleteBankAccount"><meta name="groc-project-path" content="vault/DeleteBankAccount.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/DeleteBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="delete-bank-account-sample">Delete Bank Account Sample</h1>
<p>This sample code demonstrate how you can
delete a saved bank account
API used: /v1/vault/bank-accounts/{<bankAccountId>}
NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> \PayPal\Api\BankAccount $card */</span>
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBankAccount.php'</span>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-card">Delete Card</h3>
<p>Lookup and delete a saved credit card.
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$bankAccount</span>-&gt;delete(<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">"Delete Bank Account"</span>, <span class="hljs-string">"Bank Account"</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>);
}</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">"Delete Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>

View File

@@ -1,14 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/DeleteCreditCard</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/DeleteCreditCard"><meta name="groc-project-path" content="vault/DeleteCreditCard.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/DeleteCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="delete-creditcard-sample">Delete CreditCard Sample</h1>
<p>This sample code demonstrate how you can
delete a saved credit card.
API used: /v1/vault/credit-card/{<creditCardId>}
NOTE: HTTP method used here is DELETE</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> CreditCard $card */</span>
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.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>;
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="delete-card">Delete Card</h3>
<p>Lookup and delete a saved credit card.
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$card</span>-&gt;delete(<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">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</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>);
}</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">"Delete Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>);</div></div></div></div></body></html>

View File

@@ -1,14 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/GetBankAccount</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/GetBankAccount"><meta name="groc-project-path" content="vault/GetBankAccount.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/GetBankAccount.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-bank-account-sample">Get Bank Account Sample</h1>
<p>The Bank Account resource allows you to
retrieve previously saved Bank Accounts.
API called: &#39;/v1/vault/bank-accounts&#39;</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>The following code takes you through
the process of retrieving a saved Bank Account</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> \PayPal\Api\BankAccount $bankAccount */</span>
<span class="hljs-variable">$bankAccount</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateBankAccount.php'</span>;
<span class="hljs-comment">/// ### Retrieve Bank Account</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(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">$bankAccount</span> = \PayPal\Api\BankAccount::get(<span class="hljs-variable">$bankAccount</span>-&gt;getId(), <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">"Get Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>-&gt;getId(), <span class="hljs-keyword">null</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">"Get Bank Account"</span>, <span class="hljs-string">"Bank Account"</span>, <span class="hljs-variable">$bankAccount</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$bankAccount</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$bankAccount</span>;</div></div></div></div></body></html>

View File

@@ -1,18 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/GetCreditCard</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/GetCreditCard"><meta name="groc-project-path" content="vault/GetCreditCard.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/GetCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="get-credit-card-sample">Get Credit Card Sample</h1>
<p>The CreditCard resource allows you to
retrieve previously saved CreditCards.
API called: &#39;/v1/vault/credit-card&#39;
The following code takes you through
the process of retrieving a saved CreditCard</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> CreditCard $card */</span>
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.php'</span>;
<span class="hljs-variable">$id</span> = <span class="hljs-variable">$card</span>-&gt;getId();
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;
<span class="hljs-comment">/// ### Retrieve card</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(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> = CreditCard::get(<span class="hljs-variable">$card</span>-&gt;getId(), <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">"Get Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-keyword">null</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">"Get Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-keyword">null</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>

View File

@@ -1,21 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/ListCreditCards</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/ListCreditCards"><meta name="groc-project-path" content="vault/ListCreditCards.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/ListCreditCards.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="list-credit-card-sample">List Credit Card Sample</h1>
<p>The CreditCard resource allows you to
retrieve all previously saved CreditCards.
API called: &#39;/v1/vault/credit-cards&#39;
Documentation: <a href="https://developer.paypal.com/webapps/developer/docs/api/#list-credit-card-resources">https://developer.paypal.com/webapps/developer/docs/api/#list-credit-card-resources</a></p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Creating a Credit Card just in case</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> CreditCard $card */</span>
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.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>;
<span class="hljs-comment">/// ### List All Credit Cards</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="parameters-to-filter">Parameters to Filter</h3>
<p>There are many possible filters that you could apply to it. For complete list, please refere to developer docs at above link.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$params</span> = <span class="hljs-keyword">array</span>(
<span class="hljs-string">"sort_by"</span> =&gt; <span class="hljs-string">"create_time"</span>,
<span class="hljs-string">"sort_order"</span> =&gt; <span class="hljs-string">"desc"</span>,
<span class="hljs-string">"merchant_id"</span> =&gt; <span class="hljs-string">"MyStore1"</span> <span class="hljs-comment">// Filtering by MerchantId set during CreateCreditCard.</span>
);
<span class="hljs-variable">$cards</span> = CreditCard::all(<span class="hljs-variable">$params</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>) {</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">"List All Credit Cards"</span>, <span class="hljs-string">"CreditCardList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</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">"List All Credit Cards"</span>, <span class="hljs-string">"CreditCardList"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$params</span>, <span class="hljs-variable">$cards</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>

View File

@@ -1,36 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>vault/UpdateCreditCard</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/UpdateCreditCard"><meta name="groc-project-path" content="vault/UpdateCreditCard.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/UpdateCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="update-credit-card-sample">Update Credit Card Sample</h1>
<p>The CreditCard resource allows you to
update previously saved CreditCards.
API called: PATCH /v1/vault/credit-cards/<Credit-Card-Id>
The following code takes you through
the process of updating a saved CreditCard</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> CreditCard $card */</span>
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreateCreditCard.php'</span>;
<span class="hljs-variable">$id</span> = <span class="hljs-variable">$card</span>-&gt;getId();
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Patch</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="patch-object">Patch Object</h3>
<p>You could update a credit card by sending patch requests. Each path object would have a specific detail in the object to be updated.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$pathOperation</span> = <span class="hljs-keyword">new</span> Patch();
<span class="hljs-variable">$pathOperation</span>-&gt;setOp(<span class="hljs-string">"replace"</span>)
-&gt;setPath(<span class="hljs-string">'/expire_month'</span>)
-&gt;setValue(<span class="hljs-string">"12"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="another-patch-object">Another Patch Object</h3>
<p>You could set more than one patch while updating a credit card.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$pathOperation2</span> = <span class="hljs-keyword">new</span> Patch();
<span class="hljs-variable">$pathOperation2</span>-&gt;setOp(<span class="hljs-string">'add'</span>)
-&gt;setPath(<span class="hljs-string">'/billing_address'</span>)
-&gt;setValue(json_decode(<span class="hljs-string">'{
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"state": "CA",
"postal_code": "95070"
}'</span>));
<span class="hljs-variable">$pathRequest</span> = <span class="hljs-keyword">new</span> \PayPal\Api\PatchRequest();
<span class="hljs-variable">$pathRequest</span>-&gt;addPatch(<span class="hljs-variable">$pathOperation</span>)
-&gt;addPatch(<span class="hljs-variable">$pathOperation2</span>);
<span class="hljs-comment">/// ### Update Credit Card</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>(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> = <span class="hljs-variable">$card</span>-&gt;update(<span class="hljs-variable">$pathRequest</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>) {</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">"Updated Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-variable">$pathRequest</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">"Updated Credit Card"</span>, <span class="hljs-string">"Credit Card"</span>, <span class="hljs-variable">$card</span>-&gt;getId(), <span class="hljs-variable">$pathRequest</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>

View File

@@ -221,7 +221,6 @@ if (PHP_SAPI == 'cli') {
<li><a href="#sale">Sale</a></li>
<li><a href="#order">Order</a></li>
<li><a href="#billing">Billing Plan & Agreements</a></li>
<li><a href="#vault">Vault</a></li>
<li><a href="#experience">Payment Experience</a></li>
<li><a href="#notifications">Notifications</a></li>
<li><a href="#invoice">Invoice</a></li>
@@ -827,72 +826,6 @@ if (PHP_SAPI == 'cli') {
</li>
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="vault" class="panel-title"><a href="https://developer.paypal.com/webapps/developer/docs/api/#vault"
target="_blank">Vault</a></h3>
</div>
<!-- List group -->
<ul class="list-group">
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - Save</h5></div>
<div class="col-md-4">
<a href="vault/CreateCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/vault/CreateCreditCard.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - Retrieve</h5></div>
<div class="col-md-4">
<a href="vault/GetCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/vault/GetCreditCard.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - List All</h5></div>
<div class="col-md-4">
<a href="vault/ListCreditCards.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/vault/ListCreditCards.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - Update</h5></div>
<div class="col-md-4">
<a href="vault/UpdateCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/vault/UpdateCreditCard.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Credit Card - Delete</h5></div>
<div class="col-md-4">
<a href="vault/DeleteCreditCard.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/vault/DeleteCreditCard.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="experience" class="panel-title"><a

View File

@@ -8,13 +8,12 @@
// payments list.
// API used: GET /v1/payments/payments
$createdPayment = require __DIR__ . '/CreatePaymentUsingPayPal.php';
/** @var Payment $createdPayment */
use PayPal\Api\Payment;
// Replace $paymentId with any static Id you might already have.
$paymentId = "<your paymentid here>";
// ### Retrieve payment
// Retrieve the payment object by calling the
// static `get` method
@@ -22,7 +21,7 @@ $paymentId = "<your paymentid here>";
// Payment ID
// (See bootstrap.php for more on `ApiContext`)
try {
$payment = Payment::get($paymentId, $apiContext);
$payment = Payment::get($createdPayment->getId(), $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);

View File

@@ -9,7 +9,7 @@
// payments list.
// API used: GET /v1/payments/payments
require 'CreatePayment.php';
require __DIR__ . '/CreatePaymentUsingPayPal.php';
use PayPal\Api\Payment;
// ### Retrieve payment

View File

@@ -6,17 +6,12 @@
// details of completed Sale Transaction.
// API used: /v1/payments/sale/{sale-id}
/** @var Payment $payment */
$payment = require __DIR__ . '/../payments/CreatePayment.php';
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Payment;
use PayPal\Api\Sale;
// ### Get Sale From Created Payment
// You can retrieve the sale Id from Related Resources for each transactions.
$transactions = $payment->getTransactions();
$relatedResources = $transactions[0]->getRelatedResources();
$sale = $relatedResources[0]->getSale();
$saleId = $sale->getId();
$saleId = "enter your sale id";
try {
// ### Retrieve the sale object

View File

@@ -1,56 +0,0 @@
<?php
// # Create Credit Card Sample
// 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
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard;
// ### CreditCard
// A resource representing a credit card that is
// to be stored with PayPal.
$card = new CreditCard();
$card->setType("visa")
->setNumber("4917912523797702")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
// ### Additional Information
// 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.
$card->setMerchantId("MyStore1");
$card->setExternalCardId("CardNumber123" . uniqid());
$card->setExternalCustomerId("123123-myUser1@something.com");
// For Sample Purposes Only.
$request = clone $card;
// ### Save card
// 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 `ApiContext`)
try {
$card->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card);
return $card;

View File

@@ -1,24 +0,0 @@
<?php
// # Delete CreditCard Sample
// This sample code demonstrate how you can
// delete a saved credit card.
// API used: /v1/vault/credit-card/{<creditCardId>}
// NOTE: HTTP method used here is DELETE
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
use PayPal\Api\CreditCard;
try {
// ### Delete Card
// Lookup and delete a saved credit card.
// (See bootstrap.php for more on `ApiContext`)
$card->delete($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Delete Credit Card", "Credit Card", null, null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Delete Credit Card", "Credit Card", $card->getId(), null, null);

View File

@@ -1,28 +0,0 @@
<?php
// # Get Credit Card Sample
// The CreditCard resource allows you to
// retrieve previously saved CreditCards.
// API called: '/v1/vault/credit-card'
// The following code takes you through
// the process of retrieving a saved CreditCard
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
$id = $card->getId();
use PayPal\Api\CreditCard;
/// ### Retrieve card
// (See bootstrap.php for more on `ApiContext`)
try {
$card = CreditCard::get($card->getId(), $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Credit Card", "Credit Card", $card->getId(), null, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Get Credit Card", "Credit Card", $card->getId(), null, $card);
return $card;

View File

@@ -1,36 +0,0 @@
<?php
// # List Credit Card Sample
// The CreditCard resource allows you to
// retrieve all previously saved CreditCards.
// API called: '/v1/vault/credit-cards'
// Documentation: https://developer.paypal.com/webapps/developer/docs/api/#list-credit-card-resources
// Creating a Credit Card just in case
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
use PayPal\Api\CreditCard;
/// ### List All Credit Cards
// (See bootstrap.php for more on `ApiContext`)
try {
// ### Parameters to Filter
// There are many possible filters that you could apply to it. For complete list, please refere to developer docs at above link.
$params = array(
"sort_by" => "create_time",
"sort_order" => "desc",
"merchant_id" => "MyStore1" // Filtering by MerchantId set during CreateCreditCard.
);
$cards = CreditCard::all($params, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("List All Credit Cards", "CreditCardList", null, $params, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("List All Credit Cards", "CreditCardList", null, $params, $cards);
return $card;

View File

@@ -1,53 +0,0 @@
<?php
// # Update Credit Card Sample
// The CreditCard resource allows you to
// update previously saved CreditCards.
// API called: PATCH /v1/vault/credit-cards/<Credit-Card-Id>
// The following code takes you through
// the process of updating a saved CreditCard
/** @var CreditCard $card */
$card = require 'CreateCreditCard.php';
$id = $card->getId();
use PayPal\Api\CreditCard;
use PayPal\Api\Patch;
// ### Patch Object
// You could update a credit card by sending patch requests. Each path object would have a specific detail in the object to be updated.
$pathOperation = new Patch();
$pathOperation->setOp("replace")
->setPath('/expire_month')
->setValue("12");
// ### Another Patch Object
// You could set more than one patch while updating a credit card.
$pathOperation2 = new Patch();
$pathOperation2->setOp('add')
->setPath('/billing_address')
->setValue(json_decode('{
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"state": "CA",
"postal_code": "95070"
}'));
$pathRequest = new \PayPal\Api\PatchRequest();
$pathRequest->addPatch($pathOperation)
->addPatch($pathOperation2);
/// ### Update Credit Card
// (See bootstrap.php for more on `ApiContext`)
try {
$card = $card->update($pathRequest, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Updated Credit Card", "Credit Card", $card->getId(), $pathRequest, $card);
return $card;