forked from LiveCarta/PayPal-PHP-SDK
Update samples for 3rd Party Payments
This commit is contained in:
@@ -21,8 +21,8 @@ used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><s
|
||||
->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>)
|
||||
->setBillingCountry(<span class="hljs-string">"US"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||
->setBillingCountry(<span class="hljs-string">"US"</span>)
|
||||
->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'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();
|
||||
|
||||
90
sample/doc/payments/CreateThirdPartyPayment.html
Normal file
90
sample/doc/payments/CreateThirdPartyPayment.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/CreateThirdPartyPayment</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/CreateThirdPartyPayment"><meta name="groc-project-path" content="payments/CreateThirdPartyPayment.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/CreateThirdPartyPayment.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="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">Payee</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>->setType(<span class="hljs-string">"visa"</span>)
|
||||
->setNumber(<span class="hljs-string">"4669424246660779"</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>)
|
||||
->setBillingCountry(<span class="hljs-string">"US"</span>)
|
||||
->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'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>->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 'credit_card' 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>->setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
|
||||
->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>->setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
|
||||
->setDescription(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setTax(<span class="hljs-number">0.3</span>)
|
||||
->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>->setName(<span class="hljs-string">'Granola bars'</span>)
|
||||
->setDescription(<span class="hljs-string">'Granola Bars with Peanuts'</span>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setTax(<span class="hljs-number">0.2</span>)
|
||||
->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>->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>->setShipping(<span class="hljs-number">1.2</span>)
|
||||
->setTax(<span class="hljs-number">1.3</span>)
|
||||
->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>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-number">20</span>)
|
||||
->setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payee">Payee</h3>
|
||||
<p>Specify a payee with that user's email or merchant id
|
||||
Merchant Id can be found at <a href="https://www.paypal.com/businessprofile/settings/">https://www.paypal.com/businessprofile/settings/</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payee</span> = <span class="hljs-keyword">new</span> Payee();
|
||||
<span class="hljs-variable">$payee</span>->setEmail(<span class="hljs-string">"stevendcoffey-facilitator@gmail.com"</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>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>)
|
||||
->setPayee(<span class="hljs-variable">$payee</span>)
|
||||
->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 'sale'</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>->setIntent(<span class="hljs-string">"sale"</span>)
|
||||
->setPayer(<span class="hljs-variable">$payer</span>)
|
||||
->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->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>->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 <a href="https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1413">Step 4, on this link</a>, 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>->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>
|
||||
@@ -5,15 +5,16 @@ API used: /v1/payments/capture/{<captureID>}/refund</p></div></div><div class="c
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizationCapture.php'</span>;
|
||||
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Refund</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RefundRequest</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
<p>Create a refund object indicating
|
||||
refund amount and call the refund method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$refund</span> = <span class="hljs-keyword">new</span> Refund();
|
||||
<span class="hljs-variable">$refund</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
refund amount and call the refund method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$refundRequest</span> = <span class="hljs-keyword">new</span> RefundRequest();
|
||||
<span class="hljs-variable">$refundRequest</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a new apiContext object so we send a new
|
||||
PayPal-Request-Id (idempotency) header for this resource</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$apiContext</span> = getApiContext(<span class="hljs-variable">$clientId</span>, <span class="hljs-variable">$clientSecret</span>);
|
||||
|
||||
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>->refund(<span class="hljs-variable">$refund</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">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$ex</span>);
|
||||
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>->refundCapturedPayment(<span class="hljs-variable">$refundRequest</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">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$refundRequest</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">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$captureRefund</span>->getId(), <span class="hljs-variable">$refund</span>, <span class="hljs-variable">$captureRefund</span>);</div></div></div></div></body></html>
|
||||
}</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">"Refund Capture"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$captureRefund</span>->getId(), <span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$captureRefund</span>);</div></div></div></div></body></html>
|
||||
|
||||
Reference in New Issue
Block a user