forked from LiveCarta/PayPal-PHP-SDK
Updating samples to use fluent setters + doc fixes
This commit is contained in:
@@ -4,35 +4,30 @@
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
|
||||
// ### Capture Payment
|
||||
// Capture Payment by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
// 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 {
|
||||
// create payment to get authorization Id
|
||||
// createAuthorization defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setId($authId);
|
||||
$capture->setAmount($amt);
|
||||
$capture->setId($authId)
|
||||
->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
// Get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
$getCapture = $authorization->capture($capture, $apiContext);
|
||||
@@ -45,7 +40,7 @@ try {
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Capture payment:
|
||||
Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id:
|
||||
<?php echo $getCapture->getId();?>
|
||||
</div>
|
||||
<pre>
|
||||
@@ -54,50 +49,3 @@ try {
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostalCode("14305");
|
||||
$addr->setCountryCode("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpireMonth("11");
|
||||
$card->setExpireYear("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirstName("Joe");
|
||||
$card->setLastName("Shopper");
|
||||
$card->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("authorize");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
@@ -18,26 +18,26 @@ use PayPal\Api\Transaction;
|
||||
// Base Address object used as shipping or billing
|
||||
// address in a payment. [Optional]
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostalCode("14305");
|
||||
$addr->setCountryCode("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
$addr->setLine1("3909 Witmer Road")
|
||||
->setLine2("Niagara Falls")
|
||||
->setCity("Niagara Falls")
|
||||
->setState("NY")
|
||||
->setPostalCode("14305")
|
||||
->setCountryCode("US")
|
||||
->setPhone("716-298-1822");
|
||||
|
||||
// ### CreditCard
|
||||
// A resource representing a credit card that can be
|
||||
// used to fund a payment.
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpireMonth("11");
|
||||
$card->setExpireYear("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirstName("Joe");
|
||||
$card->setLastName("Shopper");
|
||||
$card->setBillingAddress($addr);
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper")
|
||||
->setBillingAddress($addr);
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
@@ -53,14 +53,14 @@ $fi->setCreditCard($card);
|
||||
// Use the List of `FundingInstrument` and the Payment Method
|
||||
// as 'credit_card'
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
// ### Amount
|
||||
// Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -68,19 +68,25 @@ $amount->setTotal("1.00");
|
||||
// is fulfilling it. Transaction is created with
|
||||
// a `Payee` and `Amount` types
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("This is the payment description.");
|
||||
|
||||
$transaction2 = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("This is fee payment.");
|
||||
var_dump($transaction2->toJson());
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
|
||||
$payment->setIntent("sale")
|
||||
// ->setPayer($payer)
|
||||
->addTransaction($transaction)->addTransaction($transaction2);
|
||||
|
||||
echo "*************<br/>";
|
||||
var_dump($payment->toJson());
|
||||
exit;
|
||||
// ### Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
|
||||
@@ -25,8 +25,8 @@ $payer->setPaymentMethod("paypal");
|
||||
// ### Amount
|
||||
// Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -34,25 +34,25 @@ $amount->setTotal("1.00");
|
||||
// is fulfilling it. Transaction is created with
|
||||
// a `Payee` and `Amount` types
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("This is the payment description.");
|
||||
|
||||
// ### Redirect urls
|
||||
// Set the urls that the buyer must be redirected to after
|
||||
// payment approval/ cancellation.
|
||||
$baseUrl = getBaseUrl();
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true");
|
||||
$redirectUrls->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setRedirectUrls($redirectUrls);
|
||||
$payment->setTransactions(array($transaction));
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
|
||||
@@ -38,14 +38,14 @@ $fi->setCreditCardToken($creditCardToken);
|
||||
// Use the List of `FundingInstrument` and the Payment Method
|
||||
// as 'credit_card'
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
// ### Amount
|
||||
// Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -53,16 +53,16 @@ $amount->setTotal("1.00");
|
||||
// is fulfilling it. Transaction is created with
|
||||
// a `Payee` and `Amount` types
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("This is the payment description.");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ###Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
|
||||
@@ -6,23 +6,20 @@
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
|
||||
// ### GetAuthorization
|
||||
// GetAuthorization by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
// You can retrieve info about an Authorization
|
||||
// by invoking the Authorization::get method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the authorization state.
|
||||
|
||||
try {
|
||||
// create payment to get authorization Id
|
||||
// create a authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Retrieve the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
@@ -33,57 +30,10 @@ try {
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Get Authorization:
|
||||
Retrieved Authorization:
|
||||
<?php echo $authorization->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($authorization->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostalCode("14305");
|
||||
$addr->setCountryCode("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpireMonth("11");
|
||||
$card->setExpireYear("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirstName("Joe");
|
||||
$card->setLastName("Shopper");
|
||||
$card->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("authorize");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
@@ -4,36 +4,29 @@
|
||||
// API used: /v1/payments/capture/<$captureId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
|
||||
// ### Capture Payment
|
||||
// Capture Payment by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
// ### Create a mock Capture
|
||||
try {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$captur = new Capture();
|
||||
$captur->setId($authId);
|
||||
$captur->setAmount($amt);
|
||||
$captur->setId($authId)
|
||||
->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
|
||||
// Create a capture
|
||||
$capt = $authorization->capture($captur, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
@@ -41,10 +34,9 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Get Capture
|
||||
// Get Capture by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
// ### 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($capt->getId(), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
@@ -56,57 +48,10 @@ try {
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Get Capture :
|
||||
Capture Id:
|
||||
<?php echo $capture->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($capture->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostalCode("14305");
|
||||
$addr->setCountryCode("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpireMonth("11");
|
||||
$card->setExpireYear("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirstName("Joe");
|
||||
$card->setLastName("Shopper");
|
||||
$card->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("authorize");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
@@ -2,27 +2,32 @@
|
||||
// ##Reauthorization Sample
|
||||
// Sample showing how to do a reauthorization
|
||||
// API used: v1/payments/authorization/{authorization_id}/reauthorize
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Amount;
|
||||
|
||||
// ### Reauthorization
|
||||
// Reauthorization is available only for PayPal account payments
|
||||
// and not for credit card payments.
|
||||
|
||||
// You can reauthorize a payment only once 4 to 29
|
||||
// days after the 3-day honor period for the original authorization
|
||||
// has expired.
|
||||
|
||||
try {
|
||||
// ###Reauthorization
|
||||
// Retrieve a authorization id from authorization object
|
||||
// by making a `Payment Using PayPal` with intent
|
||||
// as `authorize`. You can reauthorize a payment only once 4 to 29
|
||||
// days after 3-day honor period for the original authorization
|
||||
// expires.
|
||||
|
||||
// ### Retrieve a authorization using the authorization id
|
||||
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
// ### Reauthorize with amount being reauthorized
|
||||
$authorization->setAmount($amount);
|
||||
|
||||
$reauthorization = $authorization->reauthorize($apiContext);
|
||||
}catch (PayPal\Exception\PPConnectionException $ex){
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
@@ -31,7 +36,7 @@ try {
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Reauthorize:
|
||||
Reauthorization Id:
|
||||
<?php echo $reauthorization->getId();?>
|
||||
</div>
|
||||
<pre>
|
||||
|
||||
@@ -5,39 +5,31 @@
|
||||
// using the Capture API.
|
||||
// API used: /v1/payments/capture/{<captureID>}/refund
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
|
||||
|
||||
// ### Capture Payment
|
||||
// Capture Payment by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
// ### Create a mock capture
|
||||
try {
|
||||
// create payment to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD");
|
||||
$amt->setTotal("1.00");
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$captur = new Capture();
|
||||
$captur->setAmount($amt);
|
||||
|
||||
// get the authorization
|
||||
// Get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
// Create a capture
|
||||
$capt = $authorization->capture($captur, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
@@ -47,20 +39,16 @@ try {
|
||||
|
||||
// ### Refund
|
||||
// Create a refund object indicating
|
||||
// refund amount
|
||||
|
||||
// refund amount and call the refund method
|
||||
|
||||
$refund = new Refund();
|
||||
$refund->setAmount($amt);
|
||||
|
||||
|
||||
try {
|
||||
$capture = Capture::get($capt->getId(), $apiContext);
|
||||
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = new ApiContext($apiContext->getCredential());
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
$captureRefund = $capt->refund($refund, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
@@ -75,50 +63,3 @@ try {
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostalCode("14305");
|
||||
$addr->setCountryCode("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpireMonth("11");
|
||||
$card->setExpireYear("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirstName("Joe");
|
||||
$card->setLastName("Shopper");
|
||||
$card->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("10.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("authorize");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
@@ -6,26 +6,19 @@
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
|
||||
|
||||
// ### VoidAuthorization
|
||||
// VoidAuthorization by posting to the APIService
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
// You can void a previously authorized payment
|
||||
// by invoking the $authorization->void method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
// create payment to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
$void = $authorization->void($apiContext);
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
$voidedAuth = $authorization->void($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
@@ -35,56 +28,9 @@ try {
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Void Authorization:
|
||||
Voided authorization
|
||||
</div>
|
||||
<pre><?php var_dump($void->toArray());?></pre>
|
||||
<pre><?php var_dump($voidedAuth->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
function createAuthorization($apiContext)
|
||||
{
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostalCode("14305");
|
||||
$addr->setCountryCode("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpireMonth("11");
|
||||
$card->setExpireYear("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirstName("Joe");
|
||||
$card->setLastName("Shopper");
|
||||
$card->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card");
|
||||
$payer->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("authorize");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
$paymnt = $payment->create($apiContext);
|
||||
$resArray = $paymnt->toArray();
|
||||
|
||||
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user