forked from LiveCarta/PayPal-PHP-SDK
Updates to LIPP & Future Payments
- Updated LIPP Sample code - Updated Future Payments to have helper functions for retrieving access token - Updated Logging Syntax to include timestamp and response json
This commit is contained in:
@@ -7,11 +7,8 @@
|
||||
|
||||
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\FuturePayment;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
session_start();
|
||||
@@ -50,7 +47,7 @@ $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment = new FuturePayment();
|
||||
$payment->setIntent("authorize")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
@@ -60,7 +57,7 @@ $payment->setIntent("authorize")
|
||||
// You need to get a permanent refresh token from the authorization code, retrieved from the mobile sdk.
|
||||
|
||||
// authorization code from mobile sdk
|
||||
$authorizationCode = 'EF4Ds2Wv1JbHiU_UuhR5v-ftTbeJD03RBX-Zjg9pLCAhdLqLeRR6YSKTNsrbQGX7lFoZ3SxwFyxADEZbBOxpn023W9SA0JzSQAy-9eLdON5eDPAyMyKlHyNVS2DqBR2iWVfQGfudbd9MDoRxMEjIZbY';
|
||||
$authorizationCode = 'EJfRuAqXEE95pdVMmOym_mftTbeJD03RBX-Zjg9pLCAhdLqLeRR6YSKTNsrbQGX7lFoZ3SxwFyxADEZbBOxpn023W9SA0JzSQAy-9eLdON5eDPAyMyKlHyNVS2DqBR2iWVfQGfudbd9MDoRxMEjIZbY';
|
||||
|
||||
// correlation id from mobile sdk
|
||||
$correlationId = '123123456';
|
||||
@@ -68,10 +65,10 @@ $correlationId = '123123456';
|
||||
try {
|
||||
// Exchange authorization_code for long living refresh token. You should store
|
||||
// it in a database for later use
|
||||
$refreshToken = $apiContext->getCredential()->getRefreshToken($apiContext->getConfig(), $authorizationCode);
|
||||
$refreshToken = FuturePayment::getRefreshToken($authorizationCode, $apiContext);
|
||||
|
||||
// Update the access token in apiContext
|
||||
$apiContext->getCredential()->updateAccessToken($apiContext->getConfig(), $refreshToken);
|
||||
$payment->updateAccessToken($refreshToken, $apiContext);
|
||||
|
||||
// ### Create Future Payment
|
||||
// Create a payment by calling the 'create' method
|
||||
@@ -80,7 +77,7 @@ try {
|
||||
// The return object contains the state and the
|
||||
// url to which the buyer must be redirected to
|
||||
// for payment approval
|
||||
// Please note that currently future payments works only with Paypal as a funding instrument.
|
||||
// Please note that currently future payments works only with PayPal as a funding instrument.
|
||||
$payment->create($apiContext, $correlationId);
|
||||
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
|
||||
@@ -1,129 +1,129 @@
|
||||
<?php
|
||||
|
||||
// # CreatePaymentSample
|
||||
//
|
||||
// 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
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
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;
|
||||
|
||||
// ### 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");
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
// For direct credit card payments, set the CreditCard
|
||||
// field on this object.
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
// ### Payer
|
||||
// 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.
|
||||
$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')
|
||||
->setDescription('Ground Coffee 40 oz')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setTax('0.30')
|
||||
->setPrice('7.50');
|
||||
$item2 = new Item();
|
||||
$item2->setName('Granola bars')
|
||||
->setDescription('Granola Bars with Peanuts')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setTax('0.20')
|
||||
->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("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
// payment - what is the payment for and who
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to sale 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by calling the payment->create() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the state.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(JSON_PRETTY_PRINT);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
|
||||
// # CreatePaymentSample
|
||||
//
|
||||
// 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
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
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;
|
||||
|
||||
// ### 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");
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
// For direct credit card payments, set the CreditCard
|
||||
// field on this object.
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCard($card);
|
||||
|
||||
// ### Payer
|
||||
// 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.
|
||||
$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')
|
||||
->setDescription('Ground Coffee 40 oz')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(1)
|
||||
->setTax('0.30')
|
||||
->setPrice('7.50');
|
||||
$item2 = new Item();
|
||||
$item2->setName('Granola bars')
|
||||
->setDescription('Granola Bars with Peanuts')
|
||||
->setCurrency('USD')
|
||||
->setQuantity(5)
|
||||
->setTax('0.20')
|
||||
->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("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
// payment - what is the payment for and who
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to sale 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by calling the payment->create() method
|
||||
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the state.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Direct Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(JSON_PRETTY_PRINT);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,125 +1,125 @@
|
||||
<?php
|
||||
|
||||
// # Create Payment using PayPal as payment method
|
||||
// This sample code demonstrates how you can process a
|
||||
// PayPal Account based Payment.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
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;
|
||||
use PayPal\Api\Transaction;
|
||||
session_start();
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// For paypal account payments, set payment method
|
||||
// to 'paypal'.
|
||||
$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("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
// payment - what is the payment for and who
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("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")
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ### Create Payment
|
||||
// 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
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Get redirect url
|
||||
// The API response provides the url that you must redirect
|
||||
// the buyer to. Retrieve the url from the $payment->getLinks()
|
||||
// method
|
||||
foreach($payment->getLinks() as $link) {
|
||||
if($link->getRel() == 'approval_url') {
|
||||
$redirectUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ### Redirect buyer to PayPal website
|
||||
// Save the payment id so that you can 'complete' the payment
|
||||
// once the buyer approves the payment and is redirected
|
||||
// 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.
|
||||
$_SESSION['paymentId'] = $payment->getId();
|
||||
if(isset($redirectUrl)) {
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
<?php
|
||||
|
||||
// # Create Payment using PayPal as payment method
|
||||
// This sample code demonstrates how you can process a
|
||||
// PayPal Account based Payment.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
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;
|
||||
use PayPal\Api\Transaction;
|
||||
session_start();
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// For paypal account payments, set payment method
|
||||
// to 'paypal'.
|
||||
$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("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
// payment - what is the payment for and who
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("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")
|
||||
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setRedirectUrls($redirectUrls)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ### Create Payment
|
||||
// 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
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Get redirect url
|
||||
// The API response provides the url that you must redirect
|
||||
// the buyer to. Retrieve the url from the $payment->getLinks()
|
||||
// method
|
||||
foreach($payment->getLinks() as $link) {
|
||||
if($link->getRel() == 'approval_url') {
|
||||
$redirectUrl = $link->getHref();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ### Redirect buyer to PayPal website
|
||||
// Save the payment id so that you can 'complete' the payment
|
||||
// once the buyer approves the payment and is redirected
|
||||
// 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.
|
||||
$_SESSION['paymentId'] = $payment->getId();
|
||||
if(isset($redirectUrl)) {
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -1,117 +1,117 @@
|
||||
<?php
|
||||
|
||||
// # Create payment using a saved credit card
|
||||
// This sample code demonstrates how you can process a
|
||||
// Payment using a previously stored credit card token.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
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;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
// ### Credit card token
|
||||
// Saved credit card id from a previous call to
|
||||
// CreateCreditCard.php
|
||||
$creditCardToken = new CreditCardToken();
|
||||
$creditCardToken->setCreditCardId('CARD-29H07236G1554552FKINPBHQ');
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
// For stored credit card payments, set the CreditCardToken
|
||||
// field on this object.
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCardToken($creditCardToken);
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// For stored credit card payments, set payment method
|
||||
// to 'credit_card'.
|
||||
$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("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
// payment - what is the payment for and who
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ###Create Payment
|
||||
// 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.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Saved Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(JSON_PRETTY_PRINT);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
|
||||
// # Create payment using a saved credit card
|
||||
// This sample code demonstrates how you can process a
|
||||
// Payment using a previously stored credit card token.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
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;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
|
||||
// ### Credit card token
|
||||
// Saved credit card id from a previous call to
|
||||
// CreateCreditCard.php
|
||||
$creditCardToken = new CreditCardToken();
|
||||
$creditCardToken->setCreditCardId('CARD-17M96700G1952584EKRCTV5Y');
|
||||
|
||||
// ### FundingInstrument
|
||||
// A resource representing a Payer's funding instrument.
|
||||
// For stored credit card payments, set the CreditCardToken
|
||||
// field on this object.
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCreditCardToken($creditCardToken);
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// For stored credit card payments, set payment method
|
||||
// to 'credit_card'.
|
||||
$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("20.00")
|
||||
->setDetails($details);
|
||||
|
||||
// ### Transaction
|
||||
// A transaction defines the contract of a
|
||||
// payment - what is the payment for and who
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setItemList($itemList)
|
||||
->setDescription("Payment description");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ###Create Payment
|
||||
// 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.
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Saved Credit card payments</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php echo $payment->toJSON(JSON_PRETTY_PRINT);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,40 +1,42 @@
|
||||
<?php
|
||||
// #Execute Payment Sample
|
||||
// This sample shows how you can complete
|
||||
// a payment that has been approved by
|
||||
// the buyer by logging into paypal site.
|
||||
// You can optionally update transaction
|
||||
// information by passing in one or more transactions.
|
||||
// API used: POST '/v1/payments/payment/<payment-id>/execute'.
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\ExecutePayment;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\PaymentExecution;
|
||||
session_start();
|
||||
if(isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
// Get the payment Object by passing paymentId
|
||||
// payment id was previously stored in session in
|
||||
// CreatePaymentUsingPayPal.php
|
||||
$paymentId = $_SESSION['paymentId'];
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
|
||||
// PaymentExecution object includes information necessary
|
||||
// to execute a PayPal account payment.
|
||||
// The payer_id is added to the request query parameters
|
||||
// when the user is redirected from paypal back to your site
|
||||
$execution = new PaymentExecution();
|
||||
$execution->setPayerId($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$result = $payment->execute($execution, $apiContext);
|
||||
|
||||
echo "<html><body><pre>";
|
||||
echo $result->toJSON(JSON_PRETTY_PRINT);
|
||||
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||
|
||||
} else {
|
||||
echo "User cancelled payment.";
|
||||
}
|
||||
<?php
|
||||
// #Execute Payment Sample
|
||||
// This sample shows how you can complete
|
||||
// a payment that has been approved by
|
||||
// the buyer by logging into paypal site.
|
||||
// You can optionally update transaction
|
||||
// information by passing in one or more transactions.
|
||||
// API used: POST '/v1/payments/payment/<payment-id>/execute'.
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\ExecutePayment;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\PaymentExecution;
|
||||
session_start();
|
||||
if(isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
|
||||
// Get the payment Object by passing paymentId
|
||||
// payment id was previously stored in session in
|
||||
// CreatePaymentUsingPayPal.php
|
||||
$paymentId = $_SESSION['paymentId'];
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
|
||||
// PaymentExecution object includes information necessary
|
||||
// to execute a PayPal account payment.
|
||||
// The payer_id is added to the request query parameters
|
||||
// when the user is redirected from paypal back to your site
|
||||
$execution = new PaymentExecution();
|
||||
$execution->setPayerId($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$result = $payment->execute($execution, $apiContext);
|
||||
|
||||
echo "<html><body><pre>";
|
||||
echo $result->toJSON(JSON_PRETTY_PRINT);
|
||||
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||
|
||||
} else {
|
||||
echo "<html><body><h1>";
|
||||
echo "User cancelled payment.";
|
||||
echo "</h1><a href='../index.html'>Back</a></body></html>";
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
<?php
|
||||
// # GetPaymentSample
|
||||
// This sample code demonstrate how you can
|
||||
// retrieve a list of all Payment resources
|
||||
// you've created using the Payments API.
|
||||
// Note various query parameters that you can
|
||||
// use to filter, and paginate through the
|
||||
// payments list.
|
||||
// API used: GET /v1/payments/payments
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
$paymentId = "PAY-0XL713371A312273YKE2GCNI";
|
||||
|
||||
// ### Retrieve payment
|
||||
// Retrieve the payment object by calling the
|
||||
// static `get` method
|
||||
// on the Payment class by passing a valid
|
||||
// Payment ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
|
||||
<pre><?php echo $payment->toJSON(JSON_PRETTY_PRINT);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
// # GetPaymentSample
|
||||
// This sample code demonstrate how you can
|
||||
// retrieve a list of all Payment resources
|
||||
// you've created using the Payments API.
|
||||
// Note various query parameters that you can
|
||||
// use to filter, and paginate through the
|
||||
// payments list.
|
||||
// API used: GET /v1/payments/payments
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
$paymentId = "PAY-2AH507590P6615624KRCTUSY";
|
||||
|
||||
// ### Retrieve payment
|
||||
// Retrieve the payment object by calling the
|
||||
// static `get` method
|
||||
// on the Payment class by passing a valid
|
||||
// Payment ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>Lookup a payment</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
|
||||
<pre><?php echo $payment->toJSON(JSON_PRETTY_PRINT);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user