diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php index 5c17c7e..34ed64b 100644 --- a/sample/payments/CreatePayment.php +++ b/sample/payments/CreatePayment.php @@ -9,25 +9,16 @@ // API used: /v1/payments/payment require __DIR__ . '/../bootstrap.php'; -use PayPal\Api\Address; use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; use PayPal\Api\CreditCard; use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\FundingInstrument; use PayPal\Api\Transaction; -// ### Address -// [Optional] Billing address associated with card. -$addr = new Address(); -$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. @@ -38,8 +29,7 @@ $card->setType("visa") ->setExpireYear("2019") ->setCvv2("012") ->setFirstName("Joe") - ->setLastName("Shopper") - ->setBillingAddress($addr); + ->setLastName("Shopper"); // ### FundingInstrument // A resource representing a Payer's funding instrument. @@ -56,13 +46,40 @@ $payer = new Payer(); $payer->setPaymentMethod("credit_card") ->setFundingInstruments(array($fi)); +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice('7.50'); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping('1.20') + ->setTax('1.30') + ->setSubtotal('17.50'); + // ### Amount // Lets you specify a payment amount. // You can also specify additional details // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("1.00"); + ->setTotal("20.00") + ->setDetails($details); // ### Transaction // A transaction defines the contract of a @@ -70,6 +87,7 @@ $amount->setCurrency("USD") // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount) + ->setItemList($itemList) ->setDescription("Payment description"); // ### Payment diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index 4de5273..b8fcae0 100644 --- a/sample/payments/CreatePaymentUsingPayPal.php +++ b/sample/payments/CreatePaymentUsingPayPal.php @@ -7,6 +7,9 @@ require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; @@ -20,13 +23,40 @@ session_start(); $payer = new Payer(); $payer->setPaymentMethod("paypal"); +// ### 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'); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping('1.20') + ->setTax('1.30') + ->setSubtotal('17.50'); + // ### Amount // Lets you specify a payment amount. // You can also specify additional details // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("1.00"); + ->setTotal("20.00") + ->setDetails($details); // ### Transaction // A transaction defines the contract of a @@ -34,6 +64,7 @@ $amount->setCurrency("USD") // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount) + ->setItemList($itemList) ->setDescription("Payment description"); // ### Redirect urls @@ -80,11 +111,11 @@ foreach($payment->getLinks() as $link) { } // ### Redirect buyer to PayPal website -// Save payment id so that you can 'complete' the payment +// Save the payment id so that you can 'complete' the payment // once the buyer approves the payment and is redirected -// bacl to your website. +// back to your website. // -// It is not really a great idea to store the payment id +// It is not a great idea to store the payment id // in the session. In a real world app, you may want to // store the payment id in a database. $_SESSION['paymentId'] = $payment->getId(); diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php index ed40229..5f90f62 100644 --- a/sample/payments/CreatePaymentUsingSavedCard.php +++ b/sample/payments/CreatePaymentUsingSavedCard.php @@ -7,6 +7,9 @@ require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Amount; +use PayPal\Api\Details; +use PayPal\Api\Item; +use PayPal\Api\ItemList; use PayPal\Api\CreditCardToken; use PayPal\Api\Payer; use PayPal\Api\Payment; @@ -34,13 +37,40 @@ $payer = new Payer(); $payer->setPaymentMethod("credit_card") ->setFundingInstruments(array($fi)); +// ### Itemized information +// (Optional) Lets you specify item wise +// information +$item1 = new Item(); +$item1->setName('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setPrice('7.50'); +$item2 = new Item(); +$item2->setName('Granola bars') + ->setCurrency('USD') + ->setQuantity(5) + ->setPrice('2.00'); + +$itemList = new ItemList(); +$itemList->setItems(array($item1, $item2)); + +// ### Additional payment details +// Use this optional field to set additional +// payment information such as tax, shipping +// charges etc. +$details = new Details(); +$details->setShipping('1.20') + ->setTax('1.30') + ->setSubtotal('17.50'); + // ### Amount // Lets you specify a payment amount. // You can also specify additional details // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("1.00"); + ->setTotal("20.00") + ->setDetails($details); // ### Transaction // A transaction defines the contract of a @@ -48,6 +78,7 @@ $amount->setCurrency("USD") // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount) + ->setItemList($itemList) ->setDescription("Payment description"); // ### Payment diff --git a/sample/source/CreatePayment.html b/sample/source/CreatePayment.html index e1c57d2..747f8b0 100644 --- a/sample/source/CreatePayment.html +++ b/sample/source/CreatePayment.html @@ -1,85 +1,103 @@ -
This sample code demonstrate how you can process +
This sample code demonstrate how you can process a direct credit card payment. Please note that direct credit card payment and related features using the REST API is restricted in some countries. -API used: /v1/payments/payment
[Optional] Billing address associated with card.
A resource representing a credit card that can be -used to fund a payment.
A resource representing a Payer's funding instrument. For direct credit card payments, set the CreditCard -field on this object.
A resource representing a Payer that funds a payment For direct credit card payments, set payment method -to 'credit_card' and add an array of funding instruments.
(Optional) Lets you specify item wise +information
Use this optional field to set additional +payment information such as tax, shipping +charges etc.
Lets you specify a payment amount. You can also specify additional details -such as shipping, tax.
A transaction defines the contract of a payment - what is the payment for and who -is fulfilling it.
A Payment Resource; create one using -the above types and intent set to sale 'sale'
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.
This sample code demonstrates how you can process a PayPal Account based Payment. -API used: /v1/payments/payment
A resource representing a Payer that funds a payment For paypal account payments, set payment method -to 'paypal'.
(Optional) Lets you specify item wise +information
Use this optional field to set additional +payment information such as tax, shipping +charges etc.
Lets you specify a payment amount. You can also specify additional details -such as shipping, tax.
A transaction defines the contract of a payment - what is the payment for and who -is fulfilling it.
Set the urls that the buyer must be redirected to after -payment approval/ cancellation.
A Payment Resource; create one using -the above types and intent set to 'sale'
Create a payment by calling the 'create' method
passing it a valid apiContext.
(See bootstrap.php for more on ApiContext)
The return object contains the state and the
url to which the buyer must be redirected to
-for payment approval
The API response provides the url that you must redirect the buyer to. Retrieve the url from the $payment->getLinks() -method
Save payment id so that you can 'complete' the payment +
Save the payment id so that you can 'complete' the payment once the buyer approves the payment and is redirected -bacl to your website.
It is not really a great idea to store the payment id +back to your website. +It is not a great idea to store the payment id in the session. In a real world app, you may want to -store the payment id in a database.
This sample code demonstrates how you can process a Payment using a previously stored credit card token. -API used: /v1/payments/payment
Saved credit card id from a previous call to -CreateCreditCard.php
A resource representing a Payer's funding instrument. For stored credit card payments, set the CreditCardToken -field on this object.
A resource representing a Payer that funds a payment For stored credit card payments, set payment method -to 'credit_card'.
(Optional) Lets you specify item wise +information
Use this optional field to set additional +payment information such as tax, shipping +charges etc.
Lets you specify a payment amount. You can also specify additional details -such as shipping, tax.
A transaction defines the contract of a payment - what is the payment for and who -is fulfilling it.
A Payment Resource; create one using -the above types and intent set to 'sale'
Create a payment by calling the 'create' method
passing it a valid apiContext.
(See bootstrap.php for more on ApiContext)
-The return object contains the state.
CreatePaymentSample