forked from LiveCarta/PayPal-PHP-SDK
Updates to Sample Code
- Updated UI Presentation on samples - Fixed Bugs
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
// This sample code demonstrates how you can capture
|
||||
// a previously authorized payment.
|
||||
// API used: /v1/payments/payment
|
||||
// https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'GetAuthorization.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Authorization;
|
||||
@@ -15,40 +17,23 @@ use PayPal\Api\Authorization;
|
||||
// by invoking the $authorization->capture method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
// Create a new authorization to get authorization Id
|
||||
// createAuthorization defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
$authId = $authorization->getId();
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setId($authId)
|
||||
->setAmount($amt);
|
||||
### Capture
|
||||
$capture = new Capture();
|
||||
$capture->setAmount($amt);
|
||||
|
||||
// Lookup the authorization.
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
// Perform a capture
|
||||
$getCapture = $authorization->capture($capture, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Perform a capture
|
||||
$getCapture = $authorization->capture($capture, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Capture Payment", "Authorization", null, $capture, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Capturing an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id:
|
||||
<?php echo $getCapture->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $getCapture->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Capture Payment", "Authorization", $getCapture->getId(), $capture, $getCapture);
|
||||
|
||||
return $getCapture;
|
||||
|
||||
81
sample/payments/AuthorizePayment.php
Normal file
81
sample/payments/AuthorizePayment.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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\CreditCard;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
// 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");
|
||||
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa")
|
||||
->setNumber("4417119669820331")
|
||||
->setExpireMonth("11")
|
||||
->setExpireYear("2019")
|
||||
->setCvv2("012")
|
||||
->setFirstName("Joe")
|
||||
->setLastName("Shopper")
|
||||
->setBillingAddress($addr);
|
||||
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
$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) {
|
||||
ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment);
|
||||
|
||||
$transactions = $payment->getTransactions();
|
||||
$relatedResources = $transactions[0]->getRelatedResources();
|
||||
$authorization = $relatedResources[0]->getAuthorization();
|
||||
|
||||
return $authorization;
|
||||
@@ -70,6 +70,9 @@ try {
|
||||
// Update the access token in apiContext
|
||||
$payment->updateAccessToken($refreshToken, $apiContext);
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ### Create Future Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
// passing it a valid apiContext.
|
||||
@@ -80,23 +83,11 @@ try {
|
||||
// Please note that currently future payments works only with PayPal as a funding instrument.
|
||||
$payment->create($apiContext, $correlationId);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Future Payment", "Payment", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Future payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Future Payment", "Payment", $payment->getId(), $request, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -92,7 +92,8 @@ $amount->setCurrency("USD")
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
->setDescription("Payment description")
|
||||
->setInvoiceNumber(uniqid());
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
@@ -102,28 +103,20 @@ $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 (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError('Create Payment Using Credit Card', 'Payment', null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -27,14 +27,14 @@ $payer->setPaymentMethod("paypal");
|
||||
// information
|
||||
$item1 = new Item();
|
||||
$item1->setName('Ground Coffee 40 oz')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
$item2 = new Item();
|
||||
$item2->setName('Granola bars')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
|
||||
$itemList = new ItemList();
|
||||
$itemList->setItems(array($item1, $item2));
|
||||
@@ -45,8 +45,8 @@ $itemList->setItems(array($item1, $item2));
|
||||
// charges etc.
|
||||
$details = new Details();
|
||||
$details->setShipping('1.20')
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
|
||||
// ### Amount
|
||||
// Lets you specify a payment amount.
|
||||
@@ -54,8 +54,8 @@ $details->setShipping('1.20')
|
||||
// such as shipping, tax.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -63,8 +63,9 @@ $amount->setCurrency("USD")
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description")
|
||||
->setInvoiceNumber(uniqid());
|
||||
|
||||
// ### Redirect urls
|
||||
// Set the urls that the buyer must be redirected to after
|
||||
@@ -72,16 +73,20 @@ $transaction->setAmount($amount)
|
||||
$baseUrl = getBaseUrl();
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
@@ -91,26 +96,23 @@ $payment->setIntent("sale")
|
||||
// url to which the buyer must be redirected to
|
||||
// for payment approval
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$payment->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Get redirect url
|
||||
// The API response provides the url that you must redirect
|
||||
// the buyer to. Retrieve the url from the $payment->getLinks()
|
||||
// method
|
||||
foreach($payment->getLinks() as $link) {
|
||||
if($link->getRel() == 'approval_url') {
|
||||
$redirectUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
foreach ($payment->getLinks() as $link) {
|
||||
if ($link->getRel() == 'approval_url') {
|
||||
$approvalUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ### Redirect buyer to PayPal website
|
||||
if(isset($redirectUrl)) {
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
// Payment using a previously stored credit card token.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var CreditCard $card */
|
||||
$card = require __DIR__ . '/../vault/CreateCreditCard.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Details;
|
||||
use PayPal\Api\Item;
|
||||
@@ -15,12 +16,13 @@ use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Api\CreditCard;
|
||||
|
||||
// ### Credit card token
|
||||
// Saved credit card id from a previous call to
|
||||
// CreateCreditCard.php
|
||||
$creditCardToken = new CreditCardToken();
|
||||
$creditCardToken->setCreditCardId('CARD-17M96700G1952584EKRCTV5Y');
|
||||
$creditCardToken->setCreditCardId($card->getId());
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
@@ -35,21 +37,21 @@ $fi->setCreditCardToken($creditCardToken);
|
||||
// to 'credit_card'.
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("credit_card")
|
||||
->setFundingInstruments(array($fi));
|
||||
->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.50');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setPrice('7.50');
|
||||
$item2 = new Item();
|
||||
$item2->setName('Granola bars')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setPrice('2.00');
|
||||
|
||||
$itemList = new ItemList();
|
||||
$itemList->setItems(array($item1, $item2));
|
||||
@@ -60,8 +62,8 @@ $itemList->setItems(array($item1, $item2));
|
||||
// charges etc.
|
||||
$details = new Details();
|
||||
$details->setShipping('1.20')
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
->setTax('1.30')
|
||||
->setSubtotal('17.50');
|
||||
|
||||
// ### Amount
|
||||
// Lets you specify a payment amount.
|
||||
@@ -69,8 +71,8 @@ $details->setShipping('1.20')
|
||||
// such as shipping, tax.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD")
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
->setTotal("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
@@ -78,16 +80,21 @@ $amount->setCurrency("USD")
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
->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));
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
|
||||
// For Sample Purposes Only.
|
||||
$request = clone $payment;
|
||||
|
||||
// ###Create Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
@@ -95,23 +102,12 @@ $payment->setIntent("sale")
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the state.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$payment->create($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Create Payment using Saved Card", "Payment", null, $request, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Saved Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Create Payment using Saved Card", "Payment", $payment->getId(), $request, $payment);
|
||||
|
||||
return $card;
|
||||
|
||||
@@ -31,12 +31,8 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$result = $payment->execute($execution, $apiContext);
|
||||
|
||||
echo "<html><body><pre>";
|
||||
echo $result->toJSON(128);
|
||||
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||
ResultPrinter::printResult("Executed Payment", "Payment", $payment->getId(), $execution, $result);
|
||||
|
||||
} else {
|
||||
echo "<html><body><h1>";
|
||||
echo "User cancelled payment.";
|
||||
echo "</h1><a href='../index.html'>Back</a></body></html>";
|
||||
ResultPrinter::printResult("User Cancelled the Approval", null);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
// of an authorized payment.
|
||||
// API used: /v1/payments/authorization/<$authorizationId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'AuthorizePayment.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
// ### GetAuthorization
|
||||
// You can retrieve info about an Authorization
|
||||
@@ -16,28 +17,13 @@ use PayPal\Api\Authorization;
|
||||
// The return object contains the authorization state.
|
||||
|
||||
try {
|
||||
// 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;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Retrieve the authorization
|
||||
$result = Authorization::get($authorization->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Authorization", "Authorization", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Retrieved Authorization:
|
||||
<?php echo $authorization->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $authorization->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Authorization", "Authorization", $authorization->getId(), null, $result);
|
||||
|
||||
return $authorization;
|
||||
|
||||
@@ -4,61 +4,21 @@
|
||||
// of a captured payment.
|
||||
// API used: /v1/payments/capture/<$captureId>
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Capture $request */
|
||||
$request = require 'AuthorizationCapture.php';
|
||||
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
|
||||
// ### Create a mock Capture
|
||||
try {
|
||||
// create a mock authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
### Capture
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// Create a capture
|
||||
$captureInfo = new Capture();
|
||||
$captureInfo->setId($authId)
|
||||
->setAmount($amt);
|
||||
|
||||
$capture = $authorization->capture($captureInfo, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### 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($capture->getId(), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$capture = Capture::get($request->getId(), $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Captured Payment", "Capture", $request->getId(), null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a capture</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Capture Id:
|
||||
<?php echo $capture->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $capture->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Captured Payment", "Capture", $capture->getId(), null, $capture);
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
// payments list.
|
||||
// API used: GET /v1/payments/payments
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Payment $createdPayment */
|
||||
$createdPayment = require 'CreatePayment.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
$paymentId = "PAY-2AH507590P6615624KRCTUSY";
|
||||
$paymentId = $createdPayment->getId();
|
||||
|
||||
// ### Retrieve payment
|
||||
// Retrieve the payment object by calling the
|
||||
@@ -20,20 +21,12 @@ $paymentId = "PAY-2AH507590P6615624KRCTUSY";
|
||||
// Payment ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Get Payment", "Payment", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
|
||||
<pre><?php echo $payment->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Get Payment", "Payment", $payment->getId(), null, $payment);
|
||||
|
||||
return $payment;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// payments list.
|
||||
// API used: GET /v1/payments/payments
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
require 'CreatePayment.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
|
||||
@@ -21,20 +21,13 @@ use PayPal\Api\Payment;
|
||||
// Refer the method doc for valid values for keys
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payments = Payment::all(array('count' => 10, 'start_index' => 5), $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
|
||||
$params = array('count' => 10, 'start_index' => 5);
|
||||
|
||||
$payments = Payment::all($params, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("List Payments", "Payment", null, $params, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup payment history</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Got <?php echo $payments->getCount(); ?> matching payments </div>
|
||||
<pre><?php echo $payments->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("List Payments", "Payment", null, $params, $payments);
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// This sample code demonstrates how you can reauthorize a PayPal
|
||||
// account payment.
|
||||
// API used: v1/payments/authorization/{authorization_id}/reauthorize
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'AuthorizePayment.php';
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Amount;
|
||||
|
||||
@@ -17,35 +17,18 @@ use PayPal\Api\Amount;
|
||||
// has expired.
|
||||
|
||||
try {
|
||||
|
||||
// ### Lookup authorization using the authorization id
|
||||
$authorization = Authorization::get('7GH53639GA425732B', $apiContext);
|
||||
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
$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) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// ### Reauthorize with amount being reauthorized
|
||||
$authorization->setAmount($amount);
|
||||
|
||||
$reAuthorization = $authorization->reauthorize($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Reauthorize Payment", "Payment", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Reauthorize a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Reauthorization Id:
|
||||
<?php echo $reauthorization->getId();?>
|
||||
</div>
|
||||
<pre>
|
||||
<?php echo $reauthorization->toJSON(128);?>
|
||||
</pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Reauthorize Payment", "Payment", $authorization->getId(), null, $reAuthorization);
|
||||
|
||||
@@ -3,40 +3,13 @@
|
||||
// This sample code demonstrates how you can
|
||||
// process a refund on a Captured transaction.
|
||||
// API used: /v1/payments/capture/{<captureID>}/refund
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Capture $capture */
|
||||
$capture = require 'AuthorizationCapture.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
|
||||
try {
|
||||
// Create a mock authorization to get authorization Id
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Get the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
|
||||
|
||||
// ### Capture
|
||||
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency("USD")
|
||||
->setTotal("1.00");
|
||||
|
||||
// Create a capture
|
||||
$captureInfo = new Capture();
|
||||
$captureInfo->setAmount($amt);
|
||||
|
||||
$capture = $authorization->capture($captureInfo, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Refund
|
||||
// Create a refund object indicating
|
||||
@@ -46,25 +19,14 @@ $refund = new Refund();
|
||||
$refund->setAmount($amt);
|
||||
|
||||
try {
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = getApiContext();
|
||||
// Create a new apiContext object so we send a new
|
||||
// PayPal-Request-Id (idempotency) header for this resource
|
||||
$apiContext = getApiContext($clientId, $clientSecret);
|
||||
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
$captureRefund = $capture->refund($refund, $apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Refund Capture", "Capture", null, $refund, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Refund a captured payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Refund Capture:</div>
|
||||
<pre><?php echo $captureRefund->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
ResultPrinter::printResult("Refund Capture", "Capture", $captureRefund->getId(), $refund, $captureRefund);
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
// void an authorized payment.
|
||||
// API used: /v1/payments/authorization/<{authorizationid}>/void"
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
/** @var Authorization $authorization */
|
||||
$authorization = require 'AuthorizePayment.php';
|
||||
|
||||
use PayPal\Api\Authorization;
|
||||
|
||||
@@ -14,30 +15,17 @@ use PayPal\Api\Authorization;
|
||||
// by invoking the $authorization->void method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
// create an authorization to get authorization Id
|
||||
// createAuthorization is defined in common.php
|
||||
$authId = createAuthorization($apiContext);
|
||||
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authId, $apiContext);
|
||||
// Lookup the authorization
|
||||
$authorization = Authorization::get($authorization->getId(), $apiContext);
|
||||
|
||||
// Void the authorization
|
||||
$voidedAuth = $authorization->void($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
// Void the authorization
|
||||
$voidedAuth = $authorization->void($apiContext);
|
||||
} catch (Exception $ex) {
|
||||
ResultPrinter::printError("Void Authorization", "Authorization", null, null, $ex);
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Void an authorization</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Voided authorization
|
||||
</div>
|
||||
<pre><?php echo $voidedAuth->toJSON(128);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
ResultPrinter::printResult("Void Authorization", "Authorization", $voidedAuth->getId(), null, $voidedAuth);
|
||||
|
||||
return $voidedAuth;
|
||||
|
||||
Reference in New Issue
Block a user