forked from LiveCarta/PayPal-PHP-SDK
Removing Dependency from SDK Core Project
- Copied files required for Rest API SDK - Removed PPApiContext and directly connected APIContext with PPConfigManager - Removed duplicate data storage of configuration and credentials. - Code Style Fixes - Remove build.xml file as it is not required anymore - Updated the samples - Updated the documentations
This commit is contained in:
39
sample/doc/payments/AuthorizationCapture.html
Normal file
39
sample/doc/payments/AuthorizationCapture.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/AuthorizationCapture</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/AuthorizationCapture"><meta name="groc-project-path" content="sample/payments/AuthorizationCapture.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">sample/payments/AuthorizationCapture.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="authorizationcapture">AuthorizationCapture</h1>
|
||||
<p>This sample code demonstrates how you can capture
|
||||
a previously authorized payment.
|
||||
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">Capture</span>;
|
||||
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="capture-payment">Capture Payment</h3>
|
||||
<p>You can capture and process a previously created authorization
|
||||
by invoking the $authorization->capture method
|
||||
with a valid ApiContext (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"><p>Create a new authorization to get authorization Id
|
||||
createAuthorization defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
|
||||
<span class="hljs-comment">### Capture</span>
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$capture</span>->setId(<span class="hljs-variable">$authId</span>)
|
||||
->setAmount(<span class="hljs-variable">$amt</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Perform a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$getCapture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$capture</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Capturing an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Captured payment <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$getCapture</span>->getParentPayment(); <span class="hljs-preprocessor">?></span>. Capture Id:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$getCapture</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$getCapture</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
97
sample/doc/payments/CreatePayment.html
Normal file
97
sample/doc/payments/CreatePayment.html
Normal file
@@ -0,0 +1,97 @@
|
||||
<!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="sample/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">sample/payments/CreatePayment.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">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">CreditCard</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">FundingInstrument</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="creditcard">CreditCard</h3>
|
||||
<p>A resource representing a credit card that can be
|
||||
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> CreditCard();
|
||||
<span class="hljs-variable">$card</span>->setType(<span class="hljs-string">"visa"</span>)
|
||||
->setNumber(<span class="hljs-string">"4417119669820331"</span>)
|
||||
->setExpireMonth(<span class="hljs-string">"11"</span>)
|
||||
->setExpireYear(<span class="hljs-string">"2019"</span>)
|
||||
->setCvv2(<span class="hljs-string">"012"</span>)
|
||||
->setFirstName(<span class="hljs-string">"Joe"</span>)
|
||||
->setLastName(<span class="hljs-string">"Shopper"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="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>->setCreditCard(<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-string">'0.30'</span>)
|
||||
->setPrice(<span class="hljs-string">'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-string">'0.20'</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</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-string">'1.20'</span>)
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</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-string">"20.00"</span>)
|
||||
->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>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>);</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"><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> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
90
sample/doc/payments/CreatePaymentUsingPayPal.html
Normal file
90
sample/doc/payments/CreatePaymentUsingPayPal.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/CreatePaymentUsingPayPal</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/CreatePaymentUsingPayPal"><meta name="groc-project-path" content="sample/payments/CreatePaymentUsingPayPal.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">sample/payments/CreatePaymentUsingPayPal.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-payment-using-paypal-as-payment-method">Create Payment using PayPal as payment method</h1>
|
||||
<p>This sample code demonstrates how you can process a
|
||||
PayPal Account based Payment.
|
||||
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">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">RedirectUrls</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>;
|
||||
session_start();</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 paypal account payments, set payment method
|
||||
to 'paypal'.</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">"paypal"</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>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setPrice(<span class="hljs-string">'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>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</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-string">'1.20'</span>)
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</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-string">"20.00"</span>)
|
||||
->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>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
|
||||
<p>Set the urls that the buyer must be redirected to after
|
||||
payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$baseUrl</span> = getBaseUrl();
|
||||
<span class="hljs-variable">$redirectUrls</span> = <span class="hljs-keyword">new</span> RedirectUrls();
|
||||
<span class="hljs-variable">$redirectUrls</span>->setReturnUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=true"</span>)
|
||||
->setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);</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'</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>)
|
||||
->setRedirectUrls(<span class="hljs-variable">$redirectUrls</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"><h3 id="create-payment">Create Payment</h3>
|
||||
<p>Create a payment by calling the 'create' method
|
||||
passing it a valid apiContext.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the state and the
|
||||
url to which the buyer must be redirected to
|
||||
for payment approval</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> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="get-redirect-url">Get redirect url</h3>
|
||||
<p>The API response provides the url that you must redirect
|
||||
the buyer to. Retrieve the url from the $payment->getLinks()
|
||||
method</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$payment</span>->getLinks() <span class="hljs-keyword">as</span> <span class="hljs-variable">$link</span>) {
|
||||
<span class="hljs-keyword">if</span>(<span class="hljs-variable">$link</span>->getRel() == <span class="hljs-string">'approval_url'</span>) {
|
||||
<span class="hljs-variable">$redirectUrl</span> = <span class="hljs-variable">$link</span>->getHref();
|
||||
<span class="hljs-keyword">break</span>;
|
||||
}
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="redirect-buyer-to-paypal-website">Redirect buyer to PayPal website</h3>
|
||||
<p>Save the payment id so that you can 'complete' the payment
|
||||
once the buyer approves the payment and is redirected
|
||||
back to your website.
|
||||
It is not a great idea to store the payment id
|
||||
in the session. In a real world app, you may want to
|
||||
store the payment id in a database.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$_SESSION</span>[<span class="hljs-string">'paymentId'</span>] = <span class="hljs-variable">$payment</span>->getId();
|
||||
<span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$redirectUrl</span>)) {
|
||||
header(<span class="hljs-string">"Location: $redirectUrl"</span>);
|
||||
<span class="hljs-keyword">exit</span>;
|
||||
}</div></div></div></div></body></html>
|
||||
86
sample/doc/payments/CreatePaymentUsingSavedCard.html
Normal file
86
sample/doc/payments/CreatePaymentUsingSavedCard.html
Normal file
@@ -0,0 +1,86 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/CreatePaymentUsingSavedCard</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/CreatePaymentUsingSavedCard"><meta name="groc-project-path" content="sample/payments/CreatePaymentUsingSavedCard.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">sample/payments/CreatePaymentUsingSavedCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor"><?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-payment-using-a-saved-credit-card">Create payment using a saved credit card</h1>
|
||||
<p>This sample code demonstrates how you can process a
|
||||
Payment using a previously stored credit card token.
|
||||
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">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">CreditCardToken</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">FundingInstrument</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="credit-card-token">Credit card token</h3>
|
||||
<p>Saved credit card id from a previous call to
|
||||
CreateCreditCard.php</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$creditCardToken</span> = <span class="hljs-keyword">new</span> CreditCardToken();
|
||||
<span class="hljs-variable">$creditCardToken</span>->setCreditCardId(<span class="hljs-string">'CARD-29H07236G1554552FKINPBHQ'</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 stored credit card payments, set the CreditCardToken
|
||||
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>->setCreditCardToken(<span class="hljs-variable">$creditCardToken</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 stored credit card payments, set payment method
|
||||
to 'credit_card'.</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>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">1</span>)
|
||||
->setPrice(<span class="hljs-string">'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>)
|
||||
->setCurrency(<span class="hljs-string">'USD'</span>)
|
||||
->setQuantity(<span class="hljs-number">5</span>)
|
||||
->setPrice(<span class="hljs-string">'2.00'</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-string">'1.20'</span>)
|
||||
->setTax(<span class="hljs-string">'1.30'</span>)
|
||||
->setSubtotal(<span class="hljs-string">'17.50'</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-string">"20.00"</span>)
|
||||
->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>->setAmount(<span class="hljs-variable">$amount</span>)
|
||||
->setItemList(<span class="hljs-variable">$itemList</span>)
|
||||
->setDescription(<span class="hljs-string">"Payment description"</span>);</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'</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"><h3 id="create-payment">Create Payment</h3>
|
||||
<p>Create a payment by calling the 'create' method
|
||||
passing it 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> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Saved Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
31
sample/doc/payments/ExecutePayment.html
Normal file
31
sample/doc/payments/ExecutePayment.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/ExecutePayment</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="payments/ExecutePayment"><meta name="groc-project-path" content="sample/payments/ExecutePayment.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">sample/payments/ExecutePayment.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="execute-payment-sample">Execute Payment Sample</h1>
|
||||
<p>This sample shows how you can complete
|
||||
a payment that has been approved by
|
||||
the buyer by logging into paypal site.
|
||||
You can optionally update transaction
|
||||
information by passing in one or more transactions.
|
||||
API used: POST '/v1/payments/payment/<payment-id>/execute'.</p></div></div><div class="code"><div class="wrapper"><span class="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">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>;
|
||||
session_start();
|
||||
<span class="hljs-keyword">if</span>(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>]) && <span class="hljs-variable">$_GET</span>[<span class="hljs-string">'success'</span>] == <span class="hljs-string">'true'</span>) {
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
payment id was previously stored in session in
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$paymentId</span> = <span class="hljs-variable">$_SESSION</span>[<span class="hljs-string">'paymentId'</span>];
|
||||
<span class="hljs-variable">$payment</span> = Payment::get(<span class="hljs-variable">$paymentId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||
to execute a PayPal account payment.
|
||||
The payer_id is added to the request query parameters
|
||||
when the user is redirected from paypal back to your site</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$execution</span> = <span class="hljs-keyword">new</span> PaymentExecution();
|
||||
<span class="hljs-variable">$execution</span>->setPayerId(<span class="hljs-variable">$_GET</span>[<span class="hljs-string">'PayerID'</span>]);
|
||||
|
||||
<span class="hljs-comment">//Execute the payment</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-variable">$result</span> = <span class="hljs-variable">$payment</span>->execute(<span class="hljs-variable">$execution</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"<html><body><pre>"</span>;
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-variable">$result</span>->toJSON(JSON_PRETTY_PRINT);
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"</pre><a href='../index.html'>Back</a></body></html>"</span>;
|
||||
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"User cancelled payment."</span>;
|
||||
}</div></div></div></div></body></html>
|
||||
31
sample/doc/payments/GetAuthorization.html
Normal file
31
sample/doc/payments/GetAuthorization.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/GetAuthorization</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/GetAuthorization"><meta name="groc-project-path" content="sample/payments/GetAuthorization.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">sample/payments/GetAuthorization.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="getauthorization">GetAuthorization</h1>
|
||||
<p>This sample code demonstrates how you can get details
|
||||
of an authorized payment.
|
||||
API used: /v1/payments/authorization/<$authorizationId></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">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="getauthorization">GetAuthorization</h3>
|
||||
<p>You can retrieve info about an Authorization
|
||||
by invoking the Authorization::get method
|
||||
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the authorization state.</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"><p>create a authorization to get authorization Id
|
||||
createAuthorization is defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieve the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Retrieved Authorization:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$authorization</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$authorization</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
47
sample/doc/payments/GetCapture.html
Normal file
47
sample/doc/payments/GetCapture.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/GetCapture</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/GetCapture"><meta name="groc-project-path" content="sample/payments/GetCapture.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">sample/payments/GetCapture.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="getcapture">GetCapture</h1>
|
||||
<p>This sample code demonstrates how you can lookup the details
|
||||
of a captured payment.
|
||||
API used: /v1/payments/capture/<$captureId></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">Capture</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">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-a-mock-capture">Create a mock Capture</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>create a mock authorization to get authorization Id
|
||||
createAuthorization is defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<span class="hljs-comment">### Capture</span>
|
||||
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$captureInfo</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$captureInfo</span>->setId(<span class="hljs-variable">$authId</span>)
|
||||
->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$captureInfo</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-capture-details">Retrieve Capture details</h3>
|
||||
<p>You can look up a capture by invoking the Capture::get method
|
||||
with a valid ApiContext (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">$capture</span> = Capture::get(<span class="hljs-variable">$capture</span>->getId(), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a capture</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Capture Id:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$capture</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$capture</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
33
sample/doc/payments/GetPayment.html
Normal file
33
sample/doc/payments/GetPayment.html
Normal file
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/GetPayment</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/GetPayment"><meta name="groc-project-path" content="sample/payments/GetPayment.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">sample/payments/GetPayment.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="getpaymentsample">GetPaymentSample</h1>
|
||||
<p>This sample code demonstrate how you can
|
||||
retrieve a list of all Payment resources
|
||||
you'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-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-variable">$paymentId</span> = <span class="hljs-string">"PAY-0XL713371A312273YKE2GCNI"</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-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$paymentId</span>;<span class="hljs-preprocessor">?></span></div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payment</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
32
sample/doc/payments/ListPayments.html
Normal file
32
sample/doc/payments/ListPayments.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/ListPayments</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/ListPayments"><meta name="groc-project-path" content="sample/payments/ListPayments.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">sample/payments/ListPayments.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="getpaymentlist">GetPaymentList</h1>
|
||||
<p>This sample code demonstrate how you can
|
||||
retrieve a list of all Payment resources
|
||||
you'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-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>;</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,
|
||||
and pass a Map object that contains
|
||||
query parameters for paginations and filtering.
|
||||
Refer the method doc for valid values for keys
|
||||
(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">$payments</span> = Payment::all(<span class="hljs-keyword">array</span>(<span class="hljs-string">'count'</span> => <span class="hljs-number">10</span>, <span class="hljs-string">'start_index'</span> => <span class="hljs-number">5</span>), <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception:"</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup payment history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got <span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payments</span>->getCount(); <span class="hljs-preprocessor">?></span> matching payments </div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$payments</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
37
sample/doc/payments/Reauthorization.html
Normal file
37
sample/doc/payments/Reauthorization.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/Reauthorization</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/Reauthorization"><meta name="groc-project-path" content="sample/payments/Reauthorization.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">sample/payments/Reauthorization.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"><h2 id="reauthorization-sample">Reauthorization Sample</h2>
|
||||
<p>This sample code demonstrates how you can reauthorize a PayPal
|
||||
account payment.
|
||||
API used: v1/payments/authorization/{authorization_id}/reauthorize</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">Authorization</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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="reauthorization">Reauthorization</h3>
|
||||
<p>Reauthorization is available only for PayPal account payments
|
||||
and not for credit card payments.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>You can reauthorize a payment only once 4 to 29
|
||||
days after the 3-day honor period for the original authorization
|
||||
has expired.</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="lookup-authorization-using-the-authorization-id">Lookup authorization using the authorization id</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-string">'7GH53639GA425732B'</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
<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>);
|
||||
<span class="hljs-variable">$amount</span>->setTotal(<span class="hljs-string">"1.00"</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="reauthorize-with-amount-being-reauthorized">Reauthorize with amount being reauthorized</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span>->setAmount(<span class="hljs-variable">$amount</span>);
|
||||
<span class="hljs-variable">$reauthorization</span> = <span class="hljs-variable">$authorization</span>->reauthorize(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Reauthorize a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Reauthorization Id:
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$reauthorization</span>->getId();<span class="hljs-preprocessor">?></span>
|
||||
</div>
|
||||
<pre>
|
||||
<span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$reauthorization</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span>
|
||||
</pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
52
sample/doc/payments/RefundCapture.html
Normal file
52
sample/doc/payments/RefundCapture.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/RefundCapture</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/RefundCapture"><meta name="groc-project-path" content="sample/payments/RefundCapture.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">sample/payments/RefundCapture.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="refund-capture-sample">Refund Capture Sample</h1>
|
||||
<p>This sample code demonstrates how you can
|
||||
process a refund on a Captured transaction.
|
||||
API used: /v1/payments/capture/{<captureID>}/refund</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">Authorization</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>;
|
||||
<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">Rest</span>\<span class="hljs-title">ApiContext</span>;
|
||||
|
||||
|
||||
<span class="hljs-keyword">try</span> {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a mock authorization to get authorization Id</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="capture">Capture</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper">
|
||||
<span class="hljs-variable">$amt</span> = <span class="hljs-keyword">new</span> Amount();
|
||||
<span class="hljs-variable">$amt</span>->setCurrency(<span class="hljs-string">"USD"</span>)
|
||||
->setTotal(<span class="hljs-string">"1.00"</span>);
|
||||
</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a capture</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$captureInfo</span> = <span class="hljs-keyword">new</span> Capture();
|
||||
<span class="hljs-variable">$captureInfo</span>->setAmount(<span class="hljs-variable">$amt</span>);
|
||||
|
||||
<span class="hljs-variable">$capture</span> = <span class="hljs-variable">$authorization</span>->capture(<span class="hljs-variable">$captureInfo</span>, <span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</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>);
|
||||
|
||||
<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">$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> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a captured payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refund Capture:</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$captureRefund</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
28
sample/doc/payments/VoidAuthorization.html
Normal file
28
sample/doc/payments/VoidAuthorization.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>payments/VoidAuthorization</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/VoidAuthorization"><meta name="groc-project-path" content="sample/payments/VoidAuthorization.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">sample/payments/VoidAuthorization.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="voidauthorization">VoidAuthorization</h1>
|
||||
<p>This sample code demonstrates how you can
|
||||
void an authorized payment.
|
||||
API used: /v1/payments/authorization/<{authorizationid}>/void"</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">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="voidauthorization">VoidAuthorization</h3>
|
||||
<p>You can void a previously authorized payment
|
||||
by invoking the $authorization->void method
|
||||
with a valid ApiContext (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"><p>create an authorization to get authorization Id
|
||||
createAuthorization is defined in common.php</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authId</span> = createAuthorization(<span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Lookup the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Void the authorization </p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$voidedAuth</span> = <span class="hljs-variable">$authorization</span>->void(<span class="hljs-variable">$apiContext</span>);
|
||||
} <span class="hljs-keyword">catch</span> (PayPal\<span class="hljs-keyword">Exception</span>\PPConnectionException <span class="hljs-variable">$ex</span>) {
|
||||
<span class="hljs-keyword">echo</span> <span class="hljs-string">"Exception: "</span> . <span class="hljs-variable">$ex</span>->getMessage() . PHP_EOL;
|
||||
var_dump(<span class="hljs-variable">$ex</span>->getData());
|
||||
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
|
||||
}
|
||||
<span class="hljs-preprocessor">?></span>
|
||||
<html>
|
||||
<head>
|
||||
<title>Void an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Voided authorization
|
||||
</div>
|
||||
<pre><span class="hljs-preprocessor"><?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-variable">$voidedAuth</span>->toJSON(JSON_PRETTY_PRINT);<span class="hljs-preprocessor">?></span></pre>
|
||||
<a href=<span class="hljs-string">'../index.html'</span>>Back</a>
|
||||
</body>
|
||||
</html></div></div></div></div></body></html>
|
||||
Reference in New Issue
Block a user