diff --git a/sample/bootstrap.php b/sample/bootstrap.php index cb36f0a..eb9fed9 100644 --- a/sample/bootstrap.php +++ b/sample/bootstrap.php @@ -9,6 +9,8 @@ if(!file_exists(__DIR__ .'/vendor/autoload.php')) { exit(1); } require __DIR__ . '/vendor/autoload.php'; +require __DIR__ . '/common.php'; + define("PP_CONFIG_PATH", __DIR__); use PayPal\Rest\ApiContext; @@ -36,24 +38,3 @@ $apiContext->setConfig(array( */ -/** - * ### getBaseUrl function - * // utility function that returns base url for - * // determining return/cancel urls - * @return string - */ -function getBaseUrl() { - - $protocol = 'http'; - if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { - $protocol .= 's'; - $protocol_port = $_SERVER['SERVER_PORT']; - } else { - $protocol_port = 80; - } - - $host = $_SERVER['HTTP_HOST']; - $port = $_SERVER['SERVER_PORT']; - $request = $_SERVER['PHP_SELF']; - return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); -} diff --git a/sample/common.php b/sample/common.php new file mode 100644 index 0000000..2ab665f --- /dev/null +++ b/sample/common.php @@ -0,0 +1,91 @@ +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("This is the payment description."); + + $payment = new Payment(); + + // Setting intent to authorize creates a payment + // authorization. Setting it to sale makes an actual payment + $payment->setIntent("authorize") + ->setPayer($payer) + ->setTransactions(array($transaction)); + + $paymnt = $payment->create($apiContext); + $resArray = $paymnt->toArray(); + + return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id']; +} diff --git a/sample/payments/AuthorizationCapture.php b/sample/payments/AuthorizationCapture.php index d39e607..df5ed7a 100644 --- a/sample/payments/AuthorizationCapture.php +++ b/sample/payments/AuthorizationCapture.php @@ -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 {
@@ -54,50 +49,3 @@ try {
Back
-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'];
-}
diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php
index 257226a..3218f1c 100644
--- a/sample/payments/CreatePayment.php
+++ b/sample/payments/CreatePayment.php
@@ -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 "*************
";
+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`)
diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php
index ea116e1..d228111 100644
--- a/sample/payments/CreatePaymentUsingPayPal.php
+++ b/sample/payments/CreatePaymentUsingPayPal.php
@@ -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
diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php
index dc93e4e..e74cee3 100644
--- a/sample/payments/CreatePaymentUsingSavedCard.php
+++ b/sample/payments/CreatePaymentUsingSavedCard.php
@@ -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
diff --git a/sample/payments/GetAuthorization.php b/sample/payments/GetAuthorization.php
index d57da8e..db3400c 100644
--- a/sample/payments/GetAuthorization.php
+++ b/sample/payments/GetAuthorization.php
@@ -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 {
- Get Authorization:
+ Retrieved Authorization:
getId();?>
toArray());?>
Back
-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'];
-}
diff --git a/sample/payments/GetCapture.php b/sample/payments/GetCapture.php
index 8db26af..5fbe148 100644
--- a/sample/payments/GetCapture.php
+++ b/sample/payments/GetCapture.php
@@ -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 {
- Get Capture :
+ Capture Id:
getId();?>
toArray());?>
Back
-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'];
-}
diff --git a/sample/payments/Reauthorization.php b/sample/payments/Reauthorization.php
index 8e5f004..e4c42b2 100644
--- a/sample/payments/Reauthorization.php
+++ b/sample/payments/Reauthorization.php
@@ -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 {
- Reauthorize:
+ Reauthorization Id:
getId();?>
diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php
index 2d8ec26..7a9bfd3 100644
--- a/sample/payments/RefundCapture.php
+++ b/sample/payments/RefundCapture.php
@@ -5,39 +5,31 @@
// using the Capture API.
// API used: /v1/payments/capture/{}/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 {
Back
-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'];
-}
diff --git a/sample/payments/VoidAuthorization.php b/sample/payments/VoidAuthorization.php
index ddddc76..bc9dc7d 100644
--- a/sample/payments/VoidAuthorization.php
+++ b/sample/payments/VoidAuthorization.php
@@ -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 {
- Void Authorization:
+ Voided authorization
- toArray());?>
+ toArray());?>
Back
-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'];
-}
diff --git a/sample/sale/RefundSale.php b/sample/sale/RefundSale.php
index 1e9bff9..fa34854 100644
--- a/sample/sale/RefundSale.php
+++ b/sample/sale/RefundSale.php
@@ -15,8 +15,8 @@ use PayPal\Api\Sale;
// Create a refund object indicating
// refund amount
$amt = new Amount();
-$amt->setCurrency('USD');
-$amt->setTotal('0.01');
+$amt->setCurrency('USD')
+ ->setTotal('0.01');
$refund = new Refund();
$refund->setAmount($amt);
diff --git a/sample/source/AuthorizationCapture.html b/sample/source/AuthorizationCapture.html
index 3bc228e..463eb12 100644
--- a/sample/source/AuthorizationCapture.html
+++ b/sample/source/AuthorizationCapture.html
@@ -2,28 +2,23 @@
This sample code demonstrate how you can capture the authorized payment
API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php';
-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;
try {create payment to get authorization Id
$authId = createAuthorization($apiContext);
+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);get the authorization
$authorization = Authorization::get($authId, $apiContext);
+ $capture->setId($authId)
+ ->setAmount($amt);Get the authorization
$authorization = Authorization::get($authId, $apiContext);
$getCapture = $authorization->capture($capture, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
@@ -35,7 +30,7 @@ The return object contains the status;<html>
<body>
<div>
- Capture payment:
+ Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id:
<?php echo $getCapture->getId();?>
</div>
<pre>
@@ -43,51 +38,4 @@ The return object contains the status; </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'];
-}
Capture Payment
+use PayPal\Api\Capture; +use PayPal\Api\Authorization;