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

@@ -36,7 +36,7 @@ function getBaseUrl() {
} }
/** /**
* Creates a new payment authorization * Creates a new mock 'payment authorization'
* *
* @param PayPal\Api\ApiContext apiContext * @param PayPal\Api\ApiContext apiContext
* @return PayPal\Api\Authorization * @return PayPal\Api\Authorization
@@ -74,12 +74,12 @@ function createAuthorization($apiContext) {
$transaction = new Transaction(); $transaction = new Transaction();
$transaction->setAmount($amount) $transaction->setAmount($amount)
->setDescription("This is the payment description."); ->setDescription("Payment description.");
$payment = new Payment(); $payment = new Payment();
// Setting intent to authorize creates a payment // Setting intent to authorize creates a payment
// authorization. Setting it to sale makes an actual payment // authorization. Setting it to sale creates actual payment
$payment->setIntent("authorize") $payment->setIntent("authorize")
->setPayer($payer) ->setPayer($payer)
->setTransactions(array($transaction)); ->setTransactions(array($transaction));

View File

@@ -31,15 +31,19 @@
<td>Payments</td> <td>Payments</td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<td>Payment with a credit card</td> <td>Direct credit card payments</td>
<td width="30%" ><a href="payments/CreatePayment.php" class="execute imagelink">Execute</a></td> <td width="30%" ><a href="payments/CreatePayment.php" class="execute imagelink">Execute</a></td>
<td width="30%"><a href="source/CreatePayment.html" class="source imagelink">Source</a></td> <td width="30%"><a href="source/CreatePayment.html" class="source imagelink">Source</a></td>
</tr> </tr>
<tr> <tr>
<td>Payment with a PayPal Account</td> <td>PayPal account payments</td>
<td><a href="payments/CreatePaymentUsingPayPal.php" class="execute imagelink">Execute</a></td> <td><a href="payments/CreatePaymentUsingPayPal.php" class="execute imagelink">Execute</a></td>
<td><a href="source/CreatePaymentUsingPayPal.html" class="source imagelink">Source</a></td> <td><a href="source/CreatePaymentUsingPayPal.html" class="source imagelink">Source</a></td>
</tr> </tr>
<tr>
<td>Stored credit card payments</td>
<td><a href="payments/CreatePaymentUsingSavedCard.php" class="execute imagelink">Execute</a></td>
<td><a href="source/CreatePaymentUsingSavedCard.html" class="source imagelink">Source</a></td>
<tr> <tr>
<td>Get payment details</td> <td>Get payment details</td>
<td><a href="payments/GetPayment.php" class="execute imagelink" >Execute</a></td> <td><a href="payments/GetPayment.php" class="execute imagelink" >Execute</a></td>

View File

@@ -1,6 +1,7 @@
<?php <?php
// # AuthorizationCapture // # AuthorizationCapture
// This sample code demonstrate how you can capture the authorized payment // This sample code demonstrates how you can capture
// a previously authorized payment.
// API used: /v1/payments/payment // API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -14,7 +15,7 @@ use PayPal\Api\Authorization;
// by invoking the $authorization->capture method // by invoking the $authorization->capture method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
try { try {
// create payment to get authorization Id // Create a new authorization to get authorization Id
// createAuthorization defined in common.php // createAuthorization defined in common.php
$authId = createAuthorization($apiContext); $authId = createAuthorization($apiContext);
@@ -27,9 +28,10 @@ try {
$capture->setId($authId) $capture->setId($authId)
->setAmount($amt); ->setAmount($amt);
// Get the authorization // Lookup the authorization.
$authorization = Authorization::get($authId, $apiContext); $authorization = Authorization::get($authId, $apiContext);
// Perform a capture
$getCapture = $authorization->capture($capture, $apiContext); $getCapture = $authorization->capture($capture, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
@@ -38,14 +40,15 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Capturing an authorization</title>
</head>
<body> <body>
<div> <div>
Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id: Captured payment <?php echo $getCapture->getParentPayment(); ?>. Capture Id:
<?php echo $getCapture->getId();?> <?php echo $getCapture->getId();?>
</div> </div>
<pre> <pre><?php var_dump($getCapture->toArray());?></pre>
<?php var_dump($getCapture->toArray());?>
</pre>
<a href='../index.html'>Back</a> <a href='../index.html'>Back</a>
</body> </body>
</html> </html>

View File

@@ -1,8 +1,11 @@
<?php <?php
// # CreatePaymentSample // # CreatePaymentSample
//
// This sample code demonstrate how you can process // This sample code demonstrate how you can process
// a payment with a credit card. // 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 // API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -15,8 +18,7 @@ use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
// ### Address // ### Address
// Base Address object used as shipping or billing // [Optional] Billing address associated with card.
// address in a payment. [Optional]
$addr = new Address(); $addr = new Address();
$addr->setLine1("3909 Witmer Road") $addr->setLine1("3909 Witmer Road")
->setLine2("Niagara Falls") ->setLine2("Niagara Falls")
@@ -41,23 +43,23 @@ $card->setType("visa")
// ### FundingInstrument // ### FundingInstrument
// A resource representing a Payer's funding instrument. // A resource representing a Payer's funding instrument.
// Use a Payer ID (A unique identifier of the payer generated // For direct credit card payments, set the CreditCard
// and provided by the facilitator. This is required when // field on this object.
// creating or using a tokenized funding instrument)
// and the `CreditCardDetails`
$fi = new FundingInstrument(); $fi = new FundingInstrument();
$fi->setCreditCard($card); $fi->setCreditCard($card);
// ### Payer // ### Payer
// A resource representing a Payer that funds a payment // A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method // For direct credit card payments, set payment method
// as 'credit_card' // to 'credit_card' and add an array of funding instruments.
$payer = new Payer(); $payer = new Payer();
$payer->setPaymentMethod("credit_card") $payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi)); ->setFundingInstruments(array($fi));
// ### Amount // ### 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 = new Amount();
$amount->setCurrency("USD") $amount->setCurrency("USD")
->setTotal("1.00"); ->setTotal("1.00");
@@ -65,15 +67,14 @@ $amount->setCurrency("USD")
// ### Transaction // ### Transaction
// A transaction defines the contract of a // A transaction defines the contract of a
// payment - what is the payment for and who // payment - what is the payment for and who
// is fulfilling it. Transaction is created with // is fulfilling it.
// a `Payee` and `Amount` types
$transaction = new Transaction(); $transaction = new Transaction();
$transaction->setAmount($amount) $transaction->setAmount($amount)
->setDescription("This is the payment description."); ->setDescription("Payment description");
// ### Payment // ### Payment
// A Payment Resource; create one using // A Payment Resource; create one using
// the above types and intent as 'sale' // the above types and intent set to sale 'sale'
$payment = new Payment(); $payment = new Payment();
$payment->setIntent("sale") $payment->setIntent("sale")
->setPayer($payer) ->setPayer($payer)
@@ -82,7 +83,7 @@ $payment->setIntent("sale")
// ### Create Payment // ### Create Payment
// Create a payment by posting to the APIService // Create a payment by posting to the APIService
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`) // using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the status; // The return object contains the state.
try { try {
$payment->create($apiContext); $payment->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
@@ -92,6 +93,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Direct Credit card payments</title>
</head>
<body> <body>
<div> <div>
Created payment: Created payment:

View File

@@ -6,24 +6,24 @@
// API used: /v1/payments/payment // API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address;
use PayPal\Api\Amount; use PayPal\Api\Amount;
use PayPal\Api\Payer; use PayPal\Api\Payer;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\RedirectUrls; use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
session_start(); session_start();
// ### Payer // ### Payer
// A resource representing a Payer that funds a payment // A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method // For paypal account payments, set payment method
// as 'credit_card' // to 'paypal'.
$payer = new Payer(); $payer = new Payer();
$payer->setPaymentMethod("paypal"); $payer->setPaymentMethod("paypal");
// ### Amount // ### 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 = new Amount();
$amount->setCurrency("USD") $amount->setCurrency("USD")
->setTotal("1.00"); ->setTotal("1.00");
@@ -31,11 +31,10 @@ $amount->setCurrency("USD")
// ### Transaction // ### Transaction
// A transaction defines the contract of a // A transaction defines the contract of a
// payment - what is the payment for and who // payment - what is the payment for and who
// is fulfilling it. Transaction is created with // is fulfilling it.
// a `Payee` and `Amount` types
$transaction = new Transaction(); $transaction = new Transaction();
$transaction->setAmount($amount) $transaction->setAmount($amount)
->setDescription("This is the payment description."); ->setDescription("Payment description");
// ### Redirect urls // ### Redirect urls
// Set the urls that the buyer must be redirected to after // Set the urls that the buyer must be redirected to after
@@ -47,7 +46,7 @@ $redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
// ### Payment // ### Payment
// A Payment Resource; create one using // 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 = new Payment();
$payment->setIntent("sale") $payment->setIntent("sale")
->setPayer($payer) ->setPayer($payer)
@@ -55,10 +54,10 @@ $payment->setIntent("sale")
->setTransactions(array($transaction)); ->setTransactions(array($transaction));
// ### Create Payment // ### Create Payment
// Create a payment by posting to the APIService // Create a payment by calling the 'create' method
// using a valid apiContext. // passing it a valid apiContext.
// (See bootstrap.php for more on `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 // url to which the buyer must be redirected to
// for payment approval // for payment approval
try { try {
@@ -69,16 +68,25 @@ try {
exit(1); exit(1);
} }
// ### Redirect buyer to paypal // ### Get redirect url
// Retrieve buyer approval url from the `payment` object. // 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) { foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') { if($link->getRel() == 'approval_url') {
$redirectUrl = $link->getHref(); $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 // It is not really a great idea to store the payment id
// in the session. In a real world app, please store the // in the session. In a real world app, you may want to
// payment id in a database. // store the payment id in a database.
$_SESSION['paymentId'] = $payment->getId(); $_SESSION['paymentId'] = $payment->getId();
if(isset($redirectUrl)) { if(isset($redirectUrl)) {
header("Location: $redirectUrl"); header("Location: $redirectUrl");

View File

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

View File

@@ -1,6 +1,7 @@
<?php <?php
// # GetAuthorization // # GetAuthorization
// This sample code demonstrate how you can get details of an authorized payment // This sample code demonstrates how you can get details
// of an authorized payment.
// API used: /v1/payments/authorization/<$authorizationId> // API used: /v1/payments/authorization/<$authorizationId>
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -28,6 +29,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Lookup an authorization</title>
</head>
<body> <body>
<div> <div>
Retrieved Authorization: Retrieved Authorization:

View File

@@ -1,6 +1,7 @@
<?php <?php
// # GetCapture // # GetCapture
// This sample code demonstrate how you can get the details of Captured Payment // This sample code demonstrates how you can lookup the details
// of a captured payment.
// API used: /v1/payments/capture/<$captureId> // API used: /v1/payments/capture/<$captureId>
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -12,22 +13,25 @@ use PayPal\Api\Authorization;
// ### Create a mock Capture // ### Create a mock Capture
try { try {
// create payment to get authorization Id // create a mock authorization to get authorization Id
// createAuthorization is defined in common.php
$authId = createAuthorization($apiContext); $authId = createAuthorization($apiContext);
// Lookup the authorization
$authorization = Authorization::get($authId, $apiContext);
### Capture
$amt = new Amount(); $amt = new Amount();
$amt->setCurrency("USD") $amt->setCurrency("USD")
->setTotal("1.00"); ->setTotal("1.00");
### Capture // Create a capture
$captur = new Capture(); $captureInfo = new Capture();
$captur->setId($authId) $captureInfo->setId($authId)
->setAmount($amt); ->setAmount($amt);
// get the authorization $capture = $authorization->capture($captureInfo, $apiContext);
$authorization = Authorization::get($authId, $apiContext);
// Create a capture
$capt = $authorization->capture($captur, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData()); var_dump($ex->getData());
@@ -38,7 +42,7 @@ try {
// You can look up a capture by invoking the Capture::get method // You can look up a capture by invoking the Capture::get method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
try { try {
$capture = Capture::get($capt->getId(), $apiContext); $capture = Capture::get($capture->getId(), $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData()); var_dump($ex->getData());
@@ -46,6 +50,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Lookup a capture</title>
</head>
<body> <body>
<div> <div>
Capture Id: Capture Id:

View File

@@ -28,6 +28,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Lookup a payment</title>
</head>
<body> <body>
<div>Retrieving Payment ID: <?php echo $paymentId;?></div> <div>Retrieving Payment ID: <?php echo $paymentId;?></div>
<pre><?php var_dump($payment->toArray());?></pre> <pre><?php var_dump($payment->toArray());?></pre>

View File

@@ -29,6 +29,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Lookup payment history</title>
</head>
<body> <body>
<div>Got <?php echo $payments->getCount(); ?> matching payments </div> <div>Got <?php echo $payments->getCount(); ?> matching payments </div>
<pre><?php var_dump($payments->toArray());?></pre> <pre><?php var_dump($payments->toArray());?></pre>

View File

@@ -1,6 +1,7 @@
<?php <?php
// ##Reauthorization Sample // ##Reauthorization Sample
// Sample showing how to do a reauthorization // This sample code demonstrates how you can reauthorize a PayPal
// account payment.
// API used: v1/payments/authorization/{authorization_id}/reauthorize // API used: v1/payments/authorization/{authorization_id}/reauthorize
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -17,7 +18,7 @@ use PayPal\Api\Amount;
try { try {
// ### Retrieve a authorization using the authorization id // ### Lookup authorization using the authorization id
$authorization = Authorization::get('7GH53639GA425732B', $apiContext); $authorization = Authorization::get('7GH53639GA425732B', $apiContext);
$amount = new Amount(); $amount = new Amount();
@@ -34,6 +35,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Reauthorize a payment</title>
</head>
<body> <body>
<div> <div>
Reauthorization Id: Reauthorization Id:

View File

@@ -1,9 +1,9 @@
<?php <?php
// # Refund Capture Sample // # Refund Capture Sample
// This sample code demonstrate how you can // This sample code demonstrates how you can
// process a refund on a Captured transaction created // process a refund on a Captured transaction.
// using the Capture API.
// API used: /v1/payments/capture/{<captureID>}/refund // API used: /v1/payments/capture/{<captureID>}/refund
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Authorization; use PayPal\Api\Authorization;
@@ -13,24 +13,25 @@ use PayPal\Api\Amount;
use PayPal\Rest\ApiContext; use PayPal\Rest\ApiContext;
// ### Create a mock capture
try { try {
// create payment to get authorization Id // Create a mock authorization to get authorization Id
$authId = createAuthorization($apiContext); $authId = createAuthorization($apiContext);
// Get the authorization
$authorization = Authorization::get($authId, $apiContext);
// ### Capture
$amt = new Amount(); $amt = new Amount();
$amt->setCurrency("USD") $amt->setCurrency("USD")
->setTotal("1.00"); ->setTotal("1.00");
### Capture
$captur = new Capture();
$captur->setAmount($amt);
// Get the authorization
$authorization = Authorization::get($authId, $apiContext);
// Create a capture // Create a capture
$capt = $authorization->capture($captur, $apiContext); $captureInfo = new Capture();
$captureInfo->setAmount($amt);
$capture = $authorization->capture($captureInfo, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData()); var_dump($ex->getData());
@@ -48,7 +49,8 @@ try {
// Create a new apiContext object so we send a new // Create a new apiContext object so we send a new
// PayPal-Request-Id (idempotency) header for this resource // PayPal-Request-Id (idempotency) header for this resource
$apiContext = new ApiContext($apiContext->getCredential()); $apiContext = new ApiContext($apiContext->getCredential());
$captureRefund = $capt->refund($refund, $apiContext);
$captureRefund = $capture->refund($refund, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData()); var_dump($ex->getData());
@@ -57,6 +59,9 @@ try {
?> ?>
<html> <html>
<head>
<title>Refund a captured payment</title>
</head>
<body> <body>
<div>Refund Capture:</div> <div>Refund Capture:</div>
<pre><?php var_dump($captureRefund);?></pre> <pre><?php var_dump($captureRefund);?></pre>

View File

@@ -1,6 +1,7 @@
<?php <?php
// # VoidAuthorization // # VoidAuthorization
// This sample code demonstrate how you can void an authorized payment // This sample code demonstrates how you can
// void an authorized payment.
// API used: /v1/payments/authorization/<{authorizationid}>/void" // API used: /v1/payments/authorization/<{authorizationid}>/void"
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -13,11 +14,14 @@ use PayPal\Api\Authorization;
// by invoking the $authorization->void method // by invoking the $authorization->void method
// with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
try { try {
// create payment to get authorization Id // create an authorization to get authorization Id
// createAuthorization is defined in common.php // createAuthorization is defined in common.php
$authId = createAuthorization($apiContext); $authId = createAuthorization($apiContext);
// Lookup the authorization
$authorization = Authorization::get($authId, $apiContext); $authorization = Authorization::get($authId, $apiContext);
// Void the authorization
$voidedAuth = $authorization->void($apiContext); $voidedAuth = $authorization->void($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
@@ -26,6 +30,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Void an authorization</title>
</head>
<body> <body>
<div> <div>
Voided authorization Voided authorization

View File

@@ -1,6 +1,7 @@
<?php <?php
// # Get Sale sample // # Get Sale sample
// Sale transactions are nothing but completed payments.
// This sample code demonstrates how you can retrieve // This sample code demonstrates how you can retrieve
// details of completed Sale Transaction. // details of completed Sale Transaction.
// API used: /v1/payments/sale/{sale-id} // API used: /v1/payments/sale/{sale-id}
@@ -22,6 +23,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Lookup a sale</title>
</head>
<body> <body>
<div>Retrieving sale id: <?php echo $saleId;?></div> <div>Retrieving sale id: <?php echo $saleId;?></div>
<pre><?php var_dump($sale);?></pre> <pre><?php var_dump($sale);?></pre>

View File

@@ -11,13 +11,15 @@ use PayPal\Api\Amount;
use PayPal\Api\Refund; use PayPal\Api\Refund;
use PayPal\Api\Sale; use PayPal\Api\Sale;
// ### Refund // ### Refund amount
// Create a refund object indicating // Includes both the refunded amount (to Payer)
// refund amount // and refunded fee (to Payee). Use the $amt->details
// field to mention fees refund details.
$amt = new Amount(); $amt = new Amount();
$amt->setCurrency('USD') $amt->setCurrency('USD')
->setTotal('0.01'); ->setTotal('0.01');
// ### Refund object
$refund = new Refund(); $refund = new Refund();
$refund->setAmount($amt); $refund->setAmount($amt);
@@ -29,7 +31,6 @@ $saleId = '3RM92092UW5126232';
// given sale transaction id. // given sale transaction id.
$sale = new Sale(); $sale = new Sale();
$sale->setId($saleId); $sale->setId($saleId);
try { try {
// Refund the sale // Refund the sale
// (See bootstrap.php for more on `ApiContext`) // (See bootstrap.php for more on `ApiContext`)
@@ -41,6 +42,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Refund a sale</title>
</head>
<body> <body>
<div>Refunding sale id: <?php echo $saleId;?></div> <div>Refunding sale id: <?php echo $saleId;?></div>
<pre><?php var_dump($sale);?></pre> <pre><?php var_dump($sale);?></pre>

View File

@@ -1,23 +1,18 @@
<?php <?php
// # Create Credit Card Sample // # Create Credit Card Sample
// Using the 'vault' API, you can store a // You can store credit card details securely
// Credit Card securely on PayPal. You can // with PayPal. You can then use the returned
// use a saved Credit Card to process // Credit card id to process future payments.
// 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 // API used: POST /v1/vault/credit-card
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard; use PayPal\Api\CreditCard;
use PayPal\Api\Address;
// ### CreditCard // ### CreditCard
// A resource representing a credit card that can be // A resource representing a credit card that is
// used to fund a payment. // to be stored with PayPal.
$card = new CreditCard(); $card = new CreditCard();
$card->setType("visa") $card->setType("visa")
->setNumber("4417119669820331") ->setNumber("4417119669820331")
@@ -42,6 +37,9 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Save a credit card</title>
</head>
<body> <body>
<div>Saved a new credit card with id: <?php echo $card->getId();?></div> <div>Saved a new credit card with id: <?php echo $card->getId();?></div>
<pre><?php var_dump($card);?></pre> <pre><?php var_dump($card);?></pre>

View File

@@ -1,15 +1,14 @@
<?php <?php
// # Delete CreditCard Sample // # Delete CreditCard Sample
// This sample code demonstrate how you can // This sample code demonstrate how you can
//delete a saved creditcard // delete a saved credit card.
// using the delete API.
// API used: /v1/vault/credit-card/{<creditCardId>} // API used: /v1/vault/credit-card/{<creditCardId>}
// NOTE: HTTP method used here is DELETE // NOTE: HTTP method used here is DELETE
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard; use PayPal\Api\CreditCard;
use PayPal\Api\Address;
// save card for demo // Store a mock card that can be deleted later.
// ### CreditCard // ### CreditCard
// A resource representing a credit card that can be // A resource representing a credit card that can be
// used to fund a payment. // used to fund a payment.
@@ -25,8 +24,7 @@ $card->setType("visa")
// ### Save card // ### Save card
// Creates the credit card as a resource // Creates the credit card as a resource
// in the PayPal vault. The response contains // in the PayPal vault. The response contains
// an 'id' that you can use to refer to it // an 'id' that you can use to refer to it later.
// in the future payments.
// (See bootstrap.php for more on `ApiContext`) // (See bootstrap.php for more on `ApiContext`)
try { try {
$card = $card->create($apiContext); $card = $card->create($apiContext);
@@ -36,19 +34,22 @@ try {
exit(1); exit(1);
} }
$creditCard = CreditCard::get($card->getId(), $apiContext);
try { try {
// ### Delete Card // ### Delete Card
// deletes saved credit card // deletes saved credit card
// (See bootstrap.php for more on `ApiContext`) // (See bootstrap.php for more on `ApiContext`)
$creditCard = CreditCard::get($card->getId(), $apiContext);
$creditCard->delete($apiContext); $creditCard->delete($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) { } catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL; echo "Exception: " . $ex->getMessage() . PHP_EOL;
exit(1); exit(1);
} }
?> ?>
<html> <html>
<head>
<title>Delete a saved credit card</title>
</head>
<body> <body>
<p> Credit Card deleted Successfully</p> <p> Credit Card deleted Successfully</p>
<a href='../index.html'>Back</a> <a href='../index.html'>Back</a>

View File

@@ -2,9 +2,8 @@
// # Get Credit Card Sample // # Get Credit Card Sample
// The CreditCard resource allows you to // The CreditCard resource allows you to
// retrieve previously saved CreditCards, // retrieve previously saved CreditCards.
// by sending a GET request to the URI // API called: '/v1/vault/credit-card'
// '/v1/vault/credit-card'
// The following code takes you through // The following code takes you through
// the process of retrieving a saved CreditCard // the process of retrieving a saved CreditCard
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
@@ -25,8 +24,11 @@ try {
} }
?> ?>
<html> <html>
<head>
<title>Lookup a saved credit card</title>
</head>
<body> <body>
<div>Retrieving credit card: <?php echo $cardId;?></div> <div>Retrieving saved credit card: <?php echo $cardId;?></div>
<pre><?php var_dump($card);?></pre> <pre><?php var_dump($card);?></pre>
<a href='../index.html'>Back</a> <a href='../index.html'>Back</a>
</body> </body>