forked from LiveCarta/PayPal-PHP-SDK
Updating sample comments
This commit is contained in:
@@ -6,24 +6,24 @@
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
session_start();
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// Use the List of `FundingInstrument` and the Payment Method
|
||||
// as 'credit_card'
|
||||
// For paypal account payments, set payment method
|
||||
// to 'paypal'.
|
||||
$payer = new Payer();
|
||||
$payer->setPaymentMethod("paypal");
|
||||
|
||||
// ### Amount
|
||||
// Let's you specify a payment 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");
|
||||
@@ -31,11 +31,10 @@ $amount->setCurrency("USD")
|
||||
// ### 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
|
||||
// is fulfilling it.
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount)
|
||||
->setDescription("This is the payment description.");
|
||||
->setDescription("Payment description");
|
||||
|
||||
// ### Redirect urls
|
||||
// Set the urls that the buyer must be redirected to after
|
||||
@@ -47,7 +46,7 @@ $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
// the above types and intent set to 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale")
|
||||
->setPayer($payer)
|
||||
@@ -55,10 +54,10 @@ $payment->setIntent("sale")
|
||||
->setTransactions(array($transaction));
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
// using a valid apiContext.
|
||||
// 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 status and the
|
||||
// The return object contains the state and the
|
||||
// url to which the buyer must be redirected to
|
||||
// for payment approval
|
||||
try {
|
||||
@@ -69,16 +68,25 @@ try {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Redirect buyer to paypal
|
||||
// Retrieve buyer approval url from the `payment` object.
|
||||
// ### 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 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
|
||||
// in the session. In a real world app, please store the
|
||||
// payment id in a database.
|
||||
// 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");
|
||||
|
||||
Reference in New Issue
Block a user