Updating sample comments

This commit is contained in:
aydiv
2013-08-26 12:21:29 +05:30
parent b1f1887cec
commit 05a4aef55e
18 changed files with 180 additions and 121 deletions

View File

@@ -2,47 +2,42 @@
// # Create payment using a saved credit card
// This sample code demonstrates how you can process a
// Payment using a previously saved credit card.
// Payment using a previously stored credit card token.
// API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Auth\OAuthTokenCredential;
// ### Credit card token
// Saved credit card id from a previous call to
// CreateCreditCard.php
$creditCardId = 'CARD-5BT058015C739554AKE2GCEI';
$creditCardToken = new CreditCardToken();
$creditCardToken->setCreditCardId($creditCardId);
$creditCardToken->setCreditCardId('CARD-29H07236G1554552FKINPBHQ');
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// Use a Payer ID (A unique identifier of the payer generated
// and provided by the facilitator. This is required when
// creating or using a tokenized funding instrument)
// and the `CreditCardDetails`
// 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
// Use the List of `FundingInstrument` and the Payment Method
// as 'credit_card'
// For stored credit card payments, set payment method
// to 'credit_card'.
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
// ### 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");
@@ -50,24 +45,24 @@ $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");
// ### 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)
->setTransactions(array($transaction));
// ###Create Payment
// Create a payment by posting to the APIService
// 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;
// The return object contains the state.
try {
$payment->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
@@ -77,6 +72,9 @@ try {
}
?>
<html>
<head>
<title>Saved Credit card payments</title>
</head>
<body>
<div>
Created payment: