From f4d687b52b8423b504e50dcca7a8e827016a5250 Mon Sep 17 00:00:00 2001 From: aydiv Date: Thu, 22 Aug 2013 17:24:04 +0530 Subject: [PATCH] Updating samples to use fluent setters + doc fixes --- sample/bootstrap.php | 23 +---- sample/common.php | 91 ++++++++++++++++++ sample/payments/AuthorizationCapture.php | 74 +++----------- sample/payments/CreatePayment.php | 58 ++++++----- sample/payments/CreatePaymentUsingPayPal.php | 20 ++-- .../payments/CreatePaymentUsingSavedCard.php | 18 ++-- sample/payments/GetAuthorization.php | 68 ++----------- sample/payments/GetCapture.php | 79 +++------------ sample/payments/Reauthorization.php | 23 +++-- sample/payments/RefundCapture.php | 75 ++------------- sample/payments/VoidAuthorization.php | 70 ++------------ sample/sale/RefundSale.php | 4 +- sample/source/AuthorizationCapture.html | 76 +++------------ sample/source/CreateCreditCard.html | 16 ++-- sample/source/CreatePayment.html | 48 +++++----- sample/source/CreatePaymentUsingPayPal.html | 20 ++-- .../source/CreatePaymentUsingSavedCard.html | 18 ++-- sample/source/DeleteCreditCard.html | 19 ++-- sample/source/GetAuthorization.html | 71 ++------------ sample/source/GetCapture.html | 81 +++------------- sample/source/Reauthorization.html | 23 ++--- sample/source/RefundCapture.html | 82 +++------------- sample/source/RefundSale.html | 4 +- sample/source/VoidAuthorization.html | 73 ++------------ sample/vault/CreateCreditCard.php | 96 +++++++++---------- sample/vault/DeleteCreditCard.php | 19 ++-- sample/vault/GetCreditCard.php | 66 ++++++------- 27 files changed, 422 insertions(+), 893 deletions(-) create mode 100644 sample/common.php 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 {
- Capture payment: + Captured payment getParentPayment(); ?>. Capture Id: getId();?>
@@ -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

+use PayPal\Api\Capture; +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;

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']; -}
\ No newline at end of file +</html> \ No newline at end of file diff --git a/sample/source/CreateCreditCard.html b/sample/source/CreateCreditCard.html index 4e4dc69..9ca4434 100644 --- a/sample/source/CreateCreditCard.html +++ b/sample/source/CreateCreditCard.html @@ -13,18 +13,18 @@ API used: POST /v1/vault/credit-card

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");

Save card

+$card->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper");

Save card

Creates the credit card as a resource in the PayPal vault. The response contains an 'id' that you can use to refer to it -in the future payments. +in future payments. (See bootstrap.php for more on ApiContext)

try { $card->create($apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { diff --git a/sample/source/CreatePayment.html b/sample/source/CreatePayment.html index b3cd52e..ac4d0e6 100644 --- a/sample/source/CreatePayment.html +++ b/sample/source/CreatePayment.html @@ -13,24 +13,24 @@ API used: /v1/payments/payment

$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");

CreditCard

+$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);

FundingInstrument

+$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. Use a Payer ID (A unique identifier of the payer generated @@ -42,25 +42,25 @@ and the CreditCardDetails

A resource representing a Payer that funds a payment Use the List of FundingInstrument and the Payment Method as 'credit_card'

$payer = new Payer(); -$payer->setPaymentMethod("credit_card"); -$payer->setFundingInstruments(array($fi));

Amount

+$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");

Transaction

+$amount->setCurrency("USD") + ->setTotal("1.00");

Transaction

A transaction defines the contract of a payment - what is the payment for and who 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.");

Payment

+$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));

Create Payment

+$payment->setIntent("sale") + ->setPayer($payer) + ->setTransactions(array($transaction));

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/source/CreatePaymentUsingPayPal.html b/sample/source/CreatePaymentUsingPayPal.html index 28122f5..4cca2db 100644 --- a/sample/source/CreatePaymentUsingPayPal.html +++ b/sample/source/CreatePaymentUsingPayPal.html @@ -18,28 +18,28 @@ as 'credit_card'

$payer->setPaymentMethod("paypal");

Amount

Let's you specify a payment amount.

$amount = new Amount(); -$amount->setCurrency("USD"); -$amount->setTotal("1.00");

Transaction

+$amount->setCurrency("USD") + ->setTotal("1.00");

Transaction

A transaction defines the contract of a payment - what is the payment for and who 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.");

Redirect urls

+$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");

Payment

+$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));

Create Payment

+$payment->setIntent("sale") + ->setPayer($payer) + ->setRedirectUrls($redirectUrls) + ->setTransactions(array($transaction));

Create Payment

Create a payment by posting to the APIService using a valid apiContext. diff --git a/sample/source/CreatePaymentUsingSavedCard.html b/sample/source/CreatePaymentUsingSavedCard.html index fa4aeec..4b207e1 100644 --- a/sample/source/CreatePaymentUsingSavedCard.html +++ b/sample/source/CreatePaymentUsingSavedCard.html @@ -29,25 +29,25 @@ and the CreditCardDetails

A resource representing a Payer that funds a payment Use the List of FundingInstrument and the Payment Method as 'credit_card'

$payer = new Payer(); -$payer->setPaymentMethod("credit_card"); -$payer->setFundingInstruments(array($fi));

Amount

+$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");

Transaction

+$amount->setCurrency("USD") + ->setTotal("1.00");

Transaction

A transaction defines the contract of a payment - what is the payment for and who 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.");

Payment

+$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));

Create Payment

+$payment->setIntent("sale") + ->setPayer($payer) + ->setTransactions(array($transaction));

Create Payment

Create a payment by posting to the APIService (See bootstrap.php for more on ApiContext) diff --git a/sample/source/DeleteCreditCard.html b/sample/source/DeleteCreditCard.html index 2988d11..a18ab74 100644 --- a/sample/source/DeleteCreditCard.html +++ b/sample/source/DeleteCreditCard.html @@ -10,27 +10,27 @@ NOTE: HTTP method used here is DELETE

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");

Save card

+$card->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper");

Save card

Creates the credit card as a resource in the PayPal vault. The response contains an 'id' that you can use to refer to it in the future payments. (See bootstrap.php for more on ApiContext)

try { - $res = $card->create($apiContext); + $card = $card->create($apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception:" . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } -$creditCard = CreditCard::get($res->getId(), $apiContext); +$creditCard = CreditCard::get($card->getId(), $apiContext); try {

Delete Card

deletes saved credit card @@ -43,7 +43,6 @@ in the future payments. <html> <body> -<div>Delete CreditCard:</div> <p> Credit Card deleted Successfully</p> <a href='../index.html'>Back</a> </body> diff --git a/sample/source/GetAuthorization.html b/sample/source/GetAuthorization.html index e690427..c9a1d71 100644 --- a/sample/source/GetAuthorization.html +++ b/sample/source/GetAuthorization.html @@ -3,20 +3,14 @@

This sample code demonstrate how you can get details of an authorized payment API used: /v1/payments/authorization/<$authorizationId>

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

+use PayPal\Api\Authorization;

GetAuthorization

-

GetAuthorization 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); - - $authorization = Authorization::get($authId, $apiContext); +

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 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()); @@ -26,57 +20,10 @@ The return object contains the status;

<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']; -}
\ No newline at end of file +</html> \ No newline at end of file diff --git a/sample/source/GetCapture.html b/sample/source/GetCapture.html index 7fe202b..481e401 100644 --- a/sample/source/GetCapture.html +++ b/sample/source/GetCapture.html @@ -2,38 +2,26 @@

This sample code demonstrate how you can get the details of Captured Payment 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;

try {

create payment to get authorization Id

$authId = createAuthorization($apiContext); +use PayPal\Api\Authorization;

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);

get the authorization

$authorization = Authorization::get($authId, $apiContext); - - $capt = $authorization->capture($captur, $apiContext); + $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; var_dump($ex->getData()); exit(1); -}

Get Capture

+}

Retrieve Capture details

-

Get Capture by posting to the APIService -using a valid ApiContext (See bootstrap.php for more on ApiContext) -The return object contains the status;

try { +

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) { echo "Exception: " . $ex->getMessage() . PHP_EOL; @@ -44,57 +32,10 @@ The return object contains the status;

<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']; -}
\ No newline at end of file +</html> \ No newline at end of file diff --git a/sample/source/Reauthorization.html b/sample/source/Reauthorization.html index a42eb16..a26843b 100644 --- a/sample/source/Reauthorization.html +++ b/sample/source/Reauthorization.html @@ -3,24 +3,19 @@

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; - -try {

Reauthorization

+use PayPal\Api\Amount;

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.

$authorization = Authorization::get('7GH53639GA425732B', $apiContext); +

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 { +

Retrieve a authorization using the authorization id

$authorization = Authorization::get('7GH53639GA425732B', $apiContext); $amount = new Amount(); $amount->setCurrency("USD"); - $amount->setTotal("1.00"); - - $authorization->setAmount($amount); - + $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); @@ -29,7 +24,7 @@ expires.

<html> <body> <div> - Reauthorize: + Reauthorization Id: <?php echo $reauthorization->getId();?> </div> <pre> diff --git a/sample/source/RefundCapture.html b/sample/source/RefundCapture.html index 30ee488..4969b7f 100644 --- a/sample/source/RefundCapture.html +++ b/sample/source/RefundCapture.html @@ -4,47 +4,34 @@ process a refund on a Captured transaction created 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;

try {

create payment to get authorization Id

$authId = createAuthorization($apiContext); +use PayPal\Rest\ApiContext;

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

$authorization = Authorization::get($authId, $apiContext); - - $capt = $authorization->capture($captur, $apiContext); + $captur->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; var_dump($ex->getData()); exit(1); -}

Refund

+}

Refund

Create a refund object indicating -refund amount

$refund = new Refund(); +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 +try {

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()); @@ -58,51 +45,4 @@ PayPal-Request-Id (idempotency) header for this resource

<pre><?php var_dump($captureRefund);?></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("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']; -}
\ No newline at end of file +</html> \ No newline at end of file diff --git a/sample/source/RefundSale.html b/sample/source/RefundSale.html index 3c18b91..c7acbd5 100644 --- a/sample/source/RefundSale.html +++ b/sample/source/RefundSale.html @@ -10,8 +10,8 @@ API used: /v1/payments/sale/{sale-id}/refund

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/VoidAuthorization.html b/sample/source/VoidAuthorization.html index 1351f16..2c58302 100644 --- a/sample/source/VoidAuthorization.html +++ b/sample/source/VoidAuthorization.html @@ -3,21 +3,15 @@

This sample code demonstrate how you can void an authorized payment API used: /v1/payments/authorization/<{authorizationid}>/void"

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

+use PayPal\Api\Authorization;

VoidAuthorization

-

VoidAuthorization 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); - $authorization = Authorization::get($authId, $apiContext); +

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); - $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()); @@ -27,56 +21,9 @@ The return object contains the status;

<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']; -}
\ No newline at end of file +</html> \ No newline at end of file diff --git a/sample/vault/CreateCreditCard.php b/sample/vault/CreateCreditCard.php index 04bda56..9cc6bce 100644 --- a/sample/vault/CreateCreditCard.php +++ b/sample/vault/CreateCreditCard.php @@ -1,50 +1,50 @@ -setType("visa"); -$card->setNumber("4417119669820331"); -$card->setExpireMonth("11"); -$card->setExpireYear("2019"); -$card->setCvv2("012"); -$card->setFirstName("Joe"); -$card->setLastName("Shopper"); - -// ### Save card -// Creates the credit card as a resource -// in the PayPal vault. The response contains -// an 'id' that you can use to refer to it -// in the future payments. -// (See bootstrap.php for more on `ApiContext`) -try { - $card->create($apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception:" . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - - -
Saved a new credit card with id: getId();?>
-
- Back - +// # Create Credit Card Sample +// Using the 'vault' API, you can store a +// Credit Card securely on PayPal. You can +// use a saved Credit Card to process +// a payment in the future. +// The following code demonstrates how +// can save a Credit Card on PayPal using +// the Vault API. +// API used: POST /v1/vault/credit-card + + +require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\CreditCard; +use PayPal\Api\Address; + +// ### CreditCard +// A resource representing a credit card that can be +// used to fund a payment. +$card = new CreditCard(); +$card->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper"); + +// ### Save card +// Creates the credit card as a resource +// in the PayPal vault. The response contains +// an 'id' that you can use to refer to it +// in future payments. +// (See bootstrap.php for more on `ApiContext`) +try { + $card->create($apiContext); +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception:" . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + + +
Saved a new credit card with id: getId();?>
+
+ Back + diff --git a/sample/vault/DeleteCreditCard.php b/sample/vault/DeleteCreditCard.php index 0e409ab..32020bd 100644 --- a/sample/vault/DeleteCreditCard.php +++ b/sample/vault/DeleteCreditCard.php @@ -14,13 +14,13 @@ use PayPal\Api\Address; // 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->setType("visa") + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper"); // ### Save card // Creates the credit card as a resource @@ -29,14 +29,14 @@ $card->setLastName("Shopper"); // in the future payments. // (See bootstrap.php for more on `ApiContext`) try { - $res = $card->create($apiContext); + $card = $card->create($apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { echo "Exception:" . $ex->getMessage() . PHP_EOL; var_dump($ex->getData()); exit(1); } -$creditCard = CreditCard::get($res->getId(), $apiContext); +$creditCard = CreditCard::get($card->getId(), $apiContext); try { // ### Delete Card // deletes saved credit card @@ -50,7 +50,6 @@ try { -
Delete CreditCard:

Credit Card deleted Successfully

Back diff --git a/sample/vault/GetCreditCard.php b/sample/vault/GetCreditCard.php index c8781a4..6489485 100644 --- a/sample/vault/GetCreditCard.php +++ b/sample/vault/GetCreditCard.php @@ -1,33 +1,33 @@ -getId() -$cardId = "CARD-5AR29593TC404090HKIKN77Q"; - -/// ### Retrieve card -// (See bootstrap.php for more on `ApiContext`) -try { - $card = CreditCard::get($cardId, $apiContext); -} catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); -} -?> - - -
Retrieving credit card:
-
- Back - - +getId() +$cardId = "CARD-5AR29593TC404090HKIKN77Q"; + +/// ### Retrieve card +// (See bootstrap.php for more on `ApiContext`) +try { + $card = CreditCard::get($cardId, $apiContext); +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} +?> + + +
Retrieving credit card:
+
+ Back + +