Remove credit card samples (#896)

* removed credit card payment samples
* update docs to reflect sample changes
* update readme to recommend braintree for direct card payments
This commit is contained in:
Randy
2017-08-03 10:32:26 -05:00
committed by GitHub
parent e3aadb48c2
commit 14e814d74b
23 changed files with 81 additions and 756 deletions

View File

@@ -1,111 +0,0 @@
<?php
// # Create Billing Agreement with Credit Card as Payment Source
//
// This sample code demonstrate how you can create a billing agreement, as documented here at:
// https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement
// API used: /v1/payments/billing-agreements
// Retrieving the Plan from the Create Update Sample. This would be used to
// define Plan information to create an agreement. Make sure the plan you are using is in active state.
/** @var Plan $createdPlan */
$createdPlan = require 'UpdatePlan.php';
use PayPal\Api\Agreement;
use PayPal\Api\CreditCard;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Api\PayerInfo;
use PayPal\Api\Plan;
use PayPal\Api\ShippingAddress;
/* Create a new instance of Agreement object
{
"name": "DPRP",
"description": "Payment with credit Card ",
"start_date": "2015-06-17T9:45:04Z",
"plan": {
"id": "P-1WJ68935LL406420PUTENA2I"
},
"shipping_address": {
"line1": "111 First Street",
"city": "Saratoga",
"state": "CA",
"postal_code": "95070",
"country_code": "US"
},
"payer": {
"payment_method": "credit_card",
"payer_info": {
"email": "jaypatel512-facilitator@hotmail.com"
},
"funding_instruments": [
{
"credit_card": {
"type": "visa",
"number": "4417119669820331",
"expire_month": "12",
"expire_year": "2017",
"cvv2": "128"
}
}
]
}
}*/
$agreement = new Agreement();
$agreement->setName('DPRP')
->setDescription('Payment with credit Card')
->setStartDate('2019-06-17T9:45:04Z');
// Add Plan ID
// Please note that the plan Id should be only set in this case.
$plan = new Plan();
$plan->setId($createdPlan->getId());
$agreement->setPlan($plan);
// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('credit_card')
->setPayerInfo(new PayerInfo(array('email' => 'jaypatel512-facilitator@hotmail.com')));
// Add Credit Card to Funding Instruments
$card = new CreditCard();
$card->setType('visa')
->setNumber('4491759698858890')
->setExpireMonth('12')
->setExpireYear('2017')
->setCvv2('128');
$fundingInstrument = new FundingInstrument();
$fundingInstrument->setCreditCard($card);
$payer->setFundingInstruments(array($fundingInstrument));
//Add Payer to Agreement
$agreement->setPayer($payer);
// Add Shipping Address
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')
->setCity('Saratoga')
->setState('CA')
->setPostalCode('95070')
->setCountryCode('US');
$agreement->setShippingAddress($shippingAddress);
// For Sample Purposes Only.
$request = clone $agreement;
// ### Create Agreement
try {
// Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
$agreement = $agreement->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $agreement);
return $agreement;

View File

@@ -1,81 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>billing/CreateBillingAgreementWithCreditCard</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="billing/CreateBillingAgreementWithCreditCard"><meta name="groc-project-path" content="billing/CreateBillingAgreementWithCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">billing/CreateBillingAgreementWithCreditCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-billing-agreement-with-credit-card-as-payment-source">Create Billing Agreement with Credit Card as Payment Source</h1>
<p>This sample code demonstrate how you can create a billing agreement, as documented here at:
<a href="https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement">https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement</a>
API used: /v1/payments/billing-agreements</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Retrieving the Plan from the Create Update Sample. This would be used to
define Plan information to create an agreement. Make sure the plan you are using is in active state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Plan $createdPlan */</span>
<span class="hljs-variable">$createdPlan</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'UpdatePlan.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Agreement</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">CreditCard</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">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">PayerInfo</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">Plan</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ShippingAddress</span>;
<span class="hljs-comment">/* Create a new instance of Agreement object
{
"name": "DPRP",
"description": "Payment with credit Card ",
"start_date": "2015-06-17T9:45:04Z",
"plan": {
"id": "P-1WJ68935LL406420PUTENA2I"
},
"shipping_address": {
"line1": "111 First Street",
"city": "Saratoga",
"state": "CA",
"postal_code": "95070",
"country_code": "US"
},
"payer": {
"payment_method": "credit_card",
"payer_info": {
"email": "jaypatel512-facilitator<span class="hljs-doctag">@hotmail</span>.com"
},
"funding_instruments": [
{
"credit_card": {
"type": "visa",
"number": "4417119669820331",
"expire_month": "12",
"expire_year": "2017",
"cvv2": "128"
}
}
]
}
}*/</span>
<span class="hljs-variable">$agreement</span> = <span class="hljs-keyword">new</span> Agreement();
<span class="hljs-variable">$agreement</span>-&gt;setName(<span class="hljs-string">'DPRP'</span>)
-&gt;setDescription(<span class="hljs-string">'Payment with credit Card'</span>)
-&gt;setStartDate(<span class="hljs-string">'2019-06-17T9:45:04Z'</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Plan ID
Please note that the plan Id should be only set in this case.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$plan</span> = <span class="hljs-keyword">new</span> Plan();
<span class="hljs-variable">$plan</span>-&gt;setId(<span class="hljs-variable">$createdPlan</span>-&gt;getId());
<span class="hljs-variable">$agreement</span>-&gt;setPlan(<span class="hljs-variable">$plan</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Payer</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">'credit_card'</span>)
-&gt;setPayerInfo(<span class="hljs-keyword">new</span> PayerInfo(<span class="hljs-keyword">array</span>(<span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'jaypatel512-facilitator@hotmail.com'</span>)));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Credit Card to Funding Instruments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$card</span> = <span class="hljs-keyword">new</span> CreditCard();
<span class="hljs-variable">$card</span>-&gt;setType(<span class="hljs-string">'visa'</span>)
-&gt;setNumber(<span class="hljs-string">'4491759698858890'</span>)
-&gt;setExpireMonth(<span class="hljs-string">'12'</span>)
-&gt;setExpireYear(<span class="hljs-string">'2017'</span>)
-&gt;setCvv2(<span class="hljs-string">'128'</span>);
<span class="hljs-variable">$fundingInstrument</span> = <span class="hljs-keyword">new</span> FundingInstrument();
<span class="hljs-variable">$fundingInstrument</span>-&gt;setCreditCard(<span class="hljs-variable">$card</span>);
<span class="hljs-variable">$payer</span>-&gt;setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fundingInstrument</span>));
<span class="hljs-comment">//Add Payer to Agreement</span>
<span class="hljs-variable">$agreement</span>-&gt;setPayer(<span class="hljs-variable">$payer</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Add Shipping Address</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$shippingAddress</span> = <span class="hljs-keyword">new</span> ShippingAddress();
<span class="hljs-variable">$shippingAddress</span>-&gt;setLine1(<span class="hljs-string">'111 First Street'</span>)
-&gt;setCity(<span class="hljs-string">'Saratoga'</span>)
-&gt;setState(<span class="hljs-string">'CA'</span>)
-&gt;setPostalCode(<span class="hljs-string">'95070'</span>)
-&gt;setCountryCode(<span class="hljs-string">'US'</span>);
<span class="hljs-variable">$agreement</span>-&gt;setShippingAddress(<span class="hljs-variable">$shippingAddress</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">$agreement</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-agreement">Create Agreement</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>Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$agreement</span> = <span class="hljs-variable">$agreement</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Created Billing Agreement."</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>-&gt;getId(), <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">"Created Billing Agreement."</span>, <span class="hljs-string">"Agreement"</span>, <span class="hljs-variable">$agreement</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$agreement</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$agreement</span>;</div></div></div></div></body></html>

View File

@@ -2,15 +2,12 @@
<p>This sample code demonstrates how you can capture
a previously authorized payment.
API used: /v1/payments/payment
<a href="https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization">https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Authorization $authorization */</span>
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'GetAuthorization.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>;
<a href="https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization">https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization</a></p></div></div><div class="code"><div class="wrapper"><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>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="capture-payment">Capture Payment</h3>
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $authorizationId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">"&lt;your authorization id here&gt;"</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-&gt;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> {
<span class="hljs-variable">$authId</span> = <span class="hljs-variable">$authorization</span>-&gt;getId();
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>Retrieve the authorization</p></div></div><div class="code"><div class="wrapper"> <span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authorizationId</span>, <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>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
@@ -23,4 +20,4 @@ with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)<
<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">"Capture Payment"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$getCapture</span>-&gt;getId(), <span class="hljs-variable">$capture</span>, <span class="hljs-variable">$getCapture</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$getCapture</span>;</div></div></div></div></body></html>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$getCapture</span>;</div></div></div></div></body></html>

View File

@@ -1,64 +0,0 @@
<!DOCTYPE html><html lang="en"><head><title>payments/AuthorizePayment</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/AuthorizePayment"><meta name="groc-project-path" content="payments/AuthorizePayment.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/AuthorizePayment.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="authorize-payment">Authorize Payment</h1>
<p>This sample code demonstrates how you can authorize a payment.
API used: /v1/payments/authorization
<a href="https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment">https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment</a></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">Address</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">FundingInstrument</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"><p>The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment
to correct setting. In this case, it would be &#39;authorize&#39;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$addr</span> = <span class="hljs-keyword">new</span> Address();
<span class="hljs-variable">$addr</span>-&gt;setLine1(<span class="hljs-string">"3909 Witmer Road"</span>)
-&gt;setLine2(<span class="hljs-string">"Niagara Falls"</span>)
-&gt;setCity(<span class="hljs-string">"Niagara Falls"</span>)
-&gt;setState(<span class="hljs-string">"NY"</span>)
-&gt;setPostalCode(<span class="hljs-string">"14305"</span>)
-&gt;setCountryCode(<span class="hljs-string">"US"</span>)
-&gt;setPhone(<span class="hljs-string">"716-298-1822"</span>);
<span class="hljs-variable">$paymentCard</span> = <span class="hljs-keyword">new</span> PaymentCard();
<span class="hljs-variable">$paymentCard</span>-&gt;setType(<span class="hljs-string">"visa"</span>)
-&gt;setNumber(<span class="hljs-string">"4417119669820331"</span>)
-&gt;setExpireMonth(<span class="hljs-string">"11"</span>)
-&gt;setExpireYear(<span class="hljs-string">"2019"</span>)
-&gt;setCvv2(<span class="hljs-string">"012"</span>)
-&gt;setFirstName(<span class="hljs-string">"Joe"</span>)
-&gt;setLastName(<span class="hljs-string">"Shopper"</span>)
-&gt;setBillingCountry(<span class="hljs-string">"US"</span>)
-&gt;setBillingAddress(<span class="hljs-variable">$addr</span>);
<span class="hljs-variable">$fi</span> = <span class="hljs-keyword">new</span> FundingInstrument();
<span class="hljs-variable">$fi</span>-&gt;setPaymentCard(<span class="hljs-variable">$paymentCard</span>);
<span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
-&gt;setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));
<span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
-&gt;setTotal(<span class="hljs-number">1</span>);
<span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
<span class="hljs-variable">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>)
-&gt;setDescription(<span class="hljs-string">"Payment description."</span>);
<span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Setting intent to authorize creates a payment
authorization. Setting it to sale creates actual payment</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"authorize"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by calling the payment-&gt;create() method
with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
The return object contains the state.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">try</span> {
<span class="hljs-variable">$payment</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">'Authorize a Payment'</span>, <span class="hljs-string">'Authorized Payment'</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <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">'Authorize a Payment'</span>, <span class="hljs-string">'Authorized Payment'</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
<span class="hljs-variable">$transactions</span> = <span class="hljs-variable">$payment</span>-&gt;getTransactions();
<span class="hljs-variable">$relatedResources</span> = <span class="hljs-variable">$transactions</span>[<span class="hljs-number">0</span>]-&gt;getRelatedResources();
<span class="hljs-variable">$authorization</span> = <span class="hljs-variable">$relatedResources</span>[<span class="hljs-number">0</span>]-&gt;getAuthorization();
<span class="hljs-keyword">return</span> <span class="hljs-variable">$authorization</span>;</div></div></div></div></body></html>

View File

@@ -1,75 +0,0 @@
<!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="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">payments/CreatePaymentUsingSavedCard.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-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-comment">/** <span class="hljs-doctag">@var</span> CreditCard $card */</span>
<span class="hljs-variable">$card</span> = <span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../vault/CreateCreditCard.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</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">CreditCardToken</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">FundingInstrument</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ItemList</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">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>-&gt;setCreditCardId(<span class="hljs-variable">$card</span>-&gt;getId());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
<p>A resource representing a Payer&#39;s funding instrument.
For 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>-&gt;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 &#39;credit_card&#39;.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">"credit_card"</span>)
-&gt;setFundingInstruments(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$fi</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="itemized-information">Itemized information</h3>
<p>(Optional) Lets you specify item wise
information</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$item1</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item1</span>-&gt;setName(<span class="hljs-string">'Ground Coffee 40 oz'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">1</span>)
-&gt;setPrice(<span class="hljs-number">7.5</span>);
<span class="hljs-variable">$item2</span> = <span class="hljs-keyword">new</span> Item();
<span class="hljs-variable">$item2</span>-&gt;setName(<span class="hljs-string">'Granola bars'</span>)
-&gt;setCurrency(<span class="hljs-string">'USD'</span>)
-&gt;setQuantity(<span class="hljs-number">5</span>)
-&gt;setPrice(<span class="hljs-number">2</span>);
<span class="hljs-variable">$itemList</span> = <span class="hljs-keyword">new</span> ItemList();
<span class="hljs-variable">$itemList</span>-&gt;setItems(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$item1</span>, <span class="hljs-variable">$item2</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="additional-payment-details">Additional payment details</h3>
<p>Use this optional field to set additional
payment information such as tax, shipping
charges etc.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$details</span> = <span class="hljs-keyword">new</span> Details();
<span class="hljs-variable">$details</span>-&gt;setShipping(<span class="hljs-number">1.2</span>)
-&gt;setTax(<span class="hljs-number">1.3</span>)
-&gt;setSubtotal(<span class="hljs-number">17.5</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Lets you specify a payment amount.
You can also specify additional details
such as shipping, tax.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
-&gt;setTotal(<span class="hljs-number">20</span>)
-&gt;setDetails(<span class="hljs-variable">$details</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a
payment - what is the payment for and who
is fulfilling it. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
<span class="hljs-variable">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>)
-&gt;setItemList(<span class="hljs-variable">$itemList</span>)
-&gt;setDescription(<span class="hljs-string">"Payment description"</span>)
-&gt;setInvoiceNumber(uniqid());</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using
the above types and intent set to &#39;sale&#39;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"sale"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by calling the &#39;create&#39; 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>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Create Payment using Saved Card"</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 Saved Card"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-variable">$request</span>, <span class="hljs-variable">$payment</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$card</span>;</div></div></div></div></body></html>

View File

@@ -1,10 +1,7 @@
<!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="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">payments/GetAuthorization.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="getauthorization">GetAuthorization</h1>
<p>This sample code demonstrates how you can get details
of an authorized payment.
API used: /v1/payments/authorization/&lt;$authorizationId&gt;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Authorization $authorization */</span>
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;
<span class="hljs-variable">$authorizationId</span> = <span class="hljs-variable">$authorization</span>-&gt;getId();
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Authorization</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="getauthorization">GetAuthorization</h3>
API used: /v1/payments/authorization/&lt;$authorizationId&gt;</p></div></div><div class="code"><div class="wrapper"><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"><p>Replace $authorizationId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">"&lt;your authorization id here&gt;"</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>)
@@ -13,4 +10,4 @@ The return object contains the authorization state.</p></div></div><div class="c
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Get Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$authorizationId</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$result</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$result</span>;</div></div></div></div></body></html>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$result</span>;</div></div></div></div></body></html>

View File

@@ -1,13 +1,10 @@
<!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="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">payments/GetCapture.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="getcapture">GetCapture</h1>
<p>This sample code demonstrates how you can lookup the details
of a captured payment.
API used: /v1/payments/capture/&lt;$captureId&gt;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Capture $request */</span>
<span class="hljs-variable">$request</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>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-capture-details">Retrieve Capture details</h3>
API used: /v1/payments/capture/&lt;$captureId&gt;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Capture</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $captureId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$captureId</span> = <span class="hljs-string">"&lt;your authorization id here&gt;"</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">$request</span>-&gt;getId(), <span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"Get Captured Payment"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$request</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-variable">$capture</span> = Capture::get(<span class="hljs-variable">$captureId</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">"Get Captured Payment"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$captureId</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Get Captured Payment"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$capture</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$capture</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">"Get Captured Payment"</span>, <span class="hljs-string">"Capture"</span>, <span class="hljs-variable">$capture</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$capture</span>);</div></div></div></div></body></html>

View File

@@ -6,10 +6,8 @@ Note various query parameters that you can
use to filter, and paginate through the
payments list.
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Payment $createdPayment */</span>
<span class="hljs-variable">$createdPayment</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'CreatePayment.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-variable">$createdPayment</span>-&gt;getId();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $paymentId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$paymentId</span> = <span class="hljs-string">"&lt;your paymentid here&gt;"</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<p>Retrieve the payment object by calling the
static <code>get</code> method
on the Payment class by passing a valid
@@ -20,4 +18,4 @@ Payment ID
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printResult(<span class="hljs-string">"Get Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$payment</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$payment</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>

View File

@@ -1,19 +1,22 @@
<!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="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">payments/Reauthorization.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><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-comment">/** <span class="hljs-doctag">@var</span> Authorization $authorization */</span>
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.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>;
API used: v1/payments/authorization/{authorization_id}/reauthorize</p></div></div><div class="code"><div class="wrapper"><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="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> {
has expired.</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $authorizationId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">"&lt;your authorization id here&gt;"</span>;
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$authorization</span> = Authorization::get(<span class="hljs-variable">$authorizationId</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>-&gt;setCurrency(<span class="hljs-string">"USD"</span>);
<span class="hljs-variable">$amount</span>-&gt;setTotal(<span class="hljs-number">1</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>-&gt;setAmount(<span class="hljs-variable">$amount</span>);
<span class="hljs-variable">$amount</span>-&gt;setTotal(<span class="hljs-number">1200</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>-&gt;setAmount(<span class="hljs-variable">$amount</span>);
<span class="hljs-variable">$reAuthorization</span> = <span class="hljs-variable">$authorization</span>-&gt;reauthorize(<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">"Reauthorize Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper">ResultPrinter::printResult(<span class="hljs-string">"Reauthorize Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$authorization</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$reAuthorization</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">"Reauthorize Payment"</span>, <span class="hljs-string">"Payment"</span>, <span class="hljs-variable">$authorizationId</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$reAuthorization</span>);</div></div></div></div></body></html>

View File

@@ -2,19 +2,19 @@
<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-comment">/** <span class="hljs-doctag">@var</span> Capture $capture */</span>
<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>;
<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">$refundRequest</span> = <span class="hljs-keyword">new</span> RefundRequest();
<span class="hljs-variable">$refundRequest</span>-&gt;setAmount(<span class="hljs-variable">$amt</span>);
refund amount and call the refund method</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $captureId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$captureId</span> = <span class="hljs-string">"&lt;your authorization id here&gt;"</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>);
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>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="retrieve-capture-details">Retrieve Capture details</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$capture</span> = Capture::get(<span class="hljs-variable">$captureId</span>, <span class="hljs-variable">$apiContext</span>);</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="refund-the-capture">Refund the Capture</h3></div></div></div><div class="segment"><div class="code"><div class="wrapper"> <span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>-&gt;refundCapturedPayment(<span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$apiContext</span>);
<span class="hljs-variable">$captureRefund</span> = <span class="hljs-variable">$capture</span>-&gt;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>-&gt;getId(), <span class="hljs-variable">$refundRequest</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>-&gt;getId(), <span class="hljs-variable">$refundRequest</span>, <span class="hljs-variable">$captureRefund</span>);</div></div></div></div></body></html>

View File

@@ -1,8 +1,8 @@
<!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="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">payments/VoidAuthorization.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="voidauthorization">VoidAuthorization</h1>
<p>This sample code demonstrates how you can
void an authorized payment.
API used: /v1/payments/authorization/&lt;{authorizationid}&gt;/void&quot;</p></div></div><div class="code"><div class="wrapper"><span class="hljs-comment">/** <span class="hljs-doctag">@var</span> Authorization $authorization */</span>
<span class="hljs-variable">$authorization</span> = <span class="hljs-keyword">require</span> <span class="hljs-string">'AuthorizePayment.php'</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $authorizationid with any static Id you might already have. It will do a void on it</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">'1BF65516U6866543H'</span>; <span class="hljs-comment">// $authorization-&gt;getId();</span>
API used: /v1/payments/authorization/&lt;{authorizationid}&gt;/void&quot;</p></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Replace $authorizationId with any static Id you might already have. </p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$authorizationId</span> = <span class="hljs-string">"&lt;your authorization id here&gt;"</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-&gt;void method
@@ -11,4 +11,4 @@ with a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)<
<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">"Void Authorization"</span>, <span class="hljs-string">"Authorization"</span>, <span class="hljs-variable">$voidedAuth</span>-&gt;getId(), <span class="hljs-keyword">null</span>, <span class="hljs-variable">$voidedAuth</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$voidedAuth</span>;</div></div></div></div></body></html>
<span class="hljs-keyword">return</span> <span class="hljs-variable">$voidedAuth</span>;</div></div></div></div></body></html>

View File

@@ -268,17 +268,6 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Payments using credit card information</h5></div>
<div class="col-md-4">
<a href="payments/CreatePayment.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/CreatePayment.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Payments to a 3rd-Party Payee</h5></div>
@@ -290,18 +279,7 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Payments using saved credit card <small>(using Vault APIs)</small></h5></div>
<div class="col-md-4">
<a href="payments/CreatePaymentUsingSavedCard.php"
class="btn btn-primary pull-left execute">
Try It <i class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/CreatePaymentUsingSavedCard.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8">
@@ -431,10 +409,10 @@ if (PHP_SAPI == 'cli') {
<div class="row">
<div class="col-md-8"><h5>Authorize Payment</h5></div>
<div class="col-md-4">
<a href="payments/AuthorizePayment.php" class="btn btn-primary pull-left execute"> Try It
<a href="payments/AuthorizePaymentUsingPayPal.php" class="btn btn-primary pull-left execute"> Try It
<i
class="fa fa-play-circle-o"></i></a>
<a href="doc/payments/AuthorizePayment.html" class="btn btn-default pull-right">Source <i
<a href="doc/payments/AuthorizePaymentUsingPayPal.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
</div>
</div>
@@ -758,19 +736,6 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Create Billing Agreement With Credit Card</h5></div>
<div class="col-md-4">
<a href="billing/CreateBillingAgreementWithCreditCard.php"
class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/billing/CreateBillingAgreementWithCreditCard.html"
class="btn btn-default pull-right">Source
<i class="fa fa-file-code-o"></i></a>
</div>
</div>
</li>
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Create Billing Agreement With PayPal</h5></div>

View File

@@ -5,18 +5,22 @@
// API used: /v1/payments/payment
// https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization
/** @var Authorization $authorization */
$authorization = require 'GetAuthorization.php';
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
use PayPal\Api\Capture;
// Replace $authorizationId with any static Id you might already have.
$authorizationId = "<your authorization id here>";
// ### Capture Payment
// 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 `ApiContext`)
try {
$authId = $authorization->getId();
// Retrieve the authorization
$authorization = Authorization::get($authorizationId, $apiContext);
$amt = new Amount();
$amt->setCurrency("USD")

View File

@@ -1,84 +0,0 @@
<?php
// # Authorize Payment
// This sample code demonstrates how you can authorize a payment.
// API used: /v1/payments/authorization
// https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\PaymentCard;
use PayPal\Api\Transaction;
// The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment
// to correct setting. In this case, it would be 'authorize'
$addr = new Address();
$addr->setLine1("3909 Witmer Road")
->setLine2("Niagara Falls")
->setCity("Niagara Falls")
->setState("NY")
->setPostalCode("14305")
->setCountryCode("US")
->setPhone("716-298-1822");
$paymentCard = new PaymentCard();
$paymentCard->setType("visa")
->setNumber("4417119669820331")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper")
->setBillingCountry("US")
->setBillingAddress($addr);
$fi = new FundingInstrument();
$fi->setPaymentCard($paymentCard);
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(1);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setDescription("Payment description.");
$payment = new Payment();
// Setting intent to authorize creates a payment
// authorization. Setting it to sale creates actual payment
$payment->setIntent("authorize")
->setPayer($payer)
->setTransactions(array($transaction));
// For Sample Purposes Only.
$request = clone $payment;
// ### Create Payment
// Create a payment by calling the payment->create() method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the state.
try {
$payment->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment);
$transactions = $payment->getTransactions();
$relatedResources = $transactions[0]->getRelatedResources();
$authorization = $relatedResources[0]->getAuthorization();
return $authorization;

View File

@@ -1,125 +0,0 @@
<?php
// # CreatePaymentSample
//
// 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
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\PaymentCard;
use PayPal\Api\Transaction;
// ### PaymentCard
// A resource representing a payment card that can be
// used to fund a payment.
$card = new PaymentCard();
$card->setType("visa")
->setNumber("4669424246660779")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setBillingCountry("US")
->setLastName("Shopper");
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// For direct credit card payments, set the CreditCard
// field on this object.
$fi = new FundingInstrument();
$fi->setPaymentCard($card);
// ### Payer
// 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.
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setDescription('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setTax(0.3)
->setPrice(7.50);
$item2 = new Item();
$item2->setName('Granola bars')
->setDescription('Granola Bars with Peanuts')
->setCurrency('USD')
->setQuantity(5)
->setTax(0.2)
->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details = new Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.5);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(20)
->setDetails($details);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it.
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
// ### Payment
// A Payment Resource; create one using
// the above types and intent set to sale 'sale'
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
// For Sample Purposes Only.
$request = clone $payment;
// ### Create Payment
// Create a payment by calling the payment->create() method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the state.
try {
$payment->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError('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.', 'Payment', null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
return $payment;

View File

@@ -1,115 +0,0 @@
<?php
// # Create payment using a saved credit card
// This sample code demonstrates how you can process a
// Payment using a previously stored credit card token.
// API used: /v1/payments/payment
/** @var CreditCard $card */
$card = require __DIR__ . '/../vault/CreateCreditCard.php';
use PayPal\Api\Amount;
use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken;
use PayPal\Api\Details;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\Transaction;
// ### Credit card token
// Saved credit card id from a previous call to
// CreateCreditCard.php
$creditCardToken = new CreditCardToken();
$creditCardToken->setCreditCardId($card->getId());
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// For stored credit card payments, set the CreditCardToken
// field on this object.
$fi = new FundingInstrument();
$fi->setCreditCardToken($creditCardToken);
// ### Payer
// A resource representing a Payer that funds a payment
// For stored credit card payments, set payment method
// to 'credit_card'.
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
->setCurrency('USD')
->setQuantity(1)
->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
->setCurrency('USD')
->setQuantity(5)
->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details = new Details();
$details->setShipping(1.2)
->setTax(1.3)
->setSubtotal(17.5);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(20)
->setDetails($details);
// ### Transaction
// A transaction defines the contract of a
// payment - what is the payment for and who
// is fulfilling it.
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription("Payment description")
->setInvoiceNumber(uniqid());
// ### Payment
// A Payment Resource; create one using
// the above types and intent set to 'sale'
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
// For Sample Purposes Only.
$request = clone $payment;
// ###Create Payment
// Create a payment by calling the 'create' method
// passing it a valid apiContext.
// (See bootstrap.php for more on `ApiContext`)
// The return object contains the state.
try {
$payment->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment);
return $card;

View File

@@ -3,12 +3,13 @@
// This sample code demonstrates how you can get details
// of an authorized payment.
// API used: /v1/payments/authorization/<$authorizationId>
/** @var Authorization $authorization */
$authorization = require 'AuthorizePayment.php';
$authorizationId = $authorization->getId();
use PayPal\Api\Authorization;
// Replace $authorizationId with any static Id you might already have.
$authorizationId = "<your authorization id here>";
// ### GetAuthorization
// You can retrieve info about an Authorization
// by invoking the Authorization::get method

View File

@@ -4,19 +4,19 @@
// of a captured payment.
// API used: /v1/payments/capture/<$captureId>
/** @var Capture $request */
$request = require 'AuthorizationCapture.php';
use PayPal\Api\Capture;
// Replace $captureId with any static Id you might already have.
$captureId = "<your authorization id here>";
// ### Retrieve Capture details
// You can look up a capture by invoking the Capture::get method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
try {
$capture = Capture::get($request->getId(), $apiContext);
$capture = Capture::get($captureId, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex);
ResultPrinter::printError("Get Captured Payment", "Capture", $captureId, null, $ex);
exit(1);
}

View File

@@ -9,10 +9,11 @@
// API used: GET /v1/payments/payments
/** @var Payment $createdPayment */
$createdPayment = require 'CreatePayment.php';
use PayPal\Api\Payment;
$paymentId = $createdPayment->getId();
// Replace $paymentId with any static Id you might already have.
$paymentId = "<your paymentid here>";
// ### Retrieve payment
// Retrieve the payment object by calling the

View File

@@ -3,8 +3,7 @@
// This sample code demonstrates how you can reauthorize a PayPal
// account payment.
// API used: v1/payments/authorization/{authorization_id}/reauthorize
/** @var Authorization $authorization */
$authorization = require 'AuthorizePayment.php';
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
@@ -16,10 +15,16 @@ use PayPal\Api\Authorization;
// days after the 3-day honor period for the original authorization
// has expired.
// Replace $authorizationId with any static Id you might already have.
$authorizationId = "<your authorization id here>";
try {
$authorization = Authorization::get($authorizationId, $apiContext);
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal(1);
$amount->setTotal(1200);
// ### Reauthorize with amount being reauthorized
$authorization->setAmount($amount);
@@ -32,4 +37,4 @@ try {
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization);
ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorizationId, null, $reAuthorization);

View File

@@ -4,7 +4,7 @@
// process a refund on a Captured transaction.
// API used: /v1/payments/capture/{<captureID>}/refund
/** @var Capture $capture */
$capture = require 'AuthorizationCapture.php';
use PayPal\Api\Capture;
use PayPal\Api\Refund;
@@ -14,15 +14,22 @@ use PayPal\Api\RefundRequest;
// Create a refund object indicating
// refund amount and call the refund method
$refundRequest = new RefundRequest();
$refundRequest->setAmount($amt);
// Replace $captureId with any static Id you might already have.
$captureId = "<your authorization id here>";
try {
// Create a new apiContext object so we send a new
// PayPal-Request-Id (idempotency) header for this resource
$apiContext = getApiContext($clientId, $clientSecret);
// ### Retrieve Capture details
$capture = Capture::get($captureId, $apiContext);
// ### Refund the Capture
$captureRefund = $capture->refundCapturedPayment($refundRequest, $apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Refund Capture", "Capture", null, $refundRequest, $ex);

View File

@@ -4,10 +4,10 @@
// void an authorized payment.
// API used: /v1/payments/authorization/<{authorizationid}>/void"
/** @var Authorization $authorization */
$authorization = require 'AuthorizePayment.php';
// Replace $authorizationid with any static Id you might already have. It will do a void on it
$authorizationId = '1BF65516U6866543H'; // $authorization->getId();
// Replace $authorizationId with any static Id you might already have.
$authorizationId = "<your authorization id here>";
use PayPal\Api\Authorization;
// ### VoidAuthorization