forked from LiveCarta/PayPal-PHP-SDK
Initial commit
This commit is contained in:
14
sample/README.md
Normal file
14
sample/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
Rest API Samples
|
||||
===================
|
||||
|
||||
|
||||
This sample project is a simple web app that you can explore to understand what the payment APIs can do for you. To try out the sample, run `composer update` from the samples folder and you are all set.
|
||||
|
||||
|
||||
The sample comes pre-configured with a test account but in case you need to try them against your account, you must
|
||||
|
||||
* Obtain your client id and client secret from the developer portal
|
||||
* Update the sdk_config.ini file with your new client id and secret.
|
||||
|
||||
|
||||
If you are looking for a full fledged application that uses the new RESTful APIs, check out the Pizza store sample app at https://github.com/paypal/rest-api-sample-app-php
|
||||
50
sample/bootstrap.php
Normal file
50
sample/bootstrap.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*
|
||||
* Sample bootstrap file.
|
||||
*/
|
||||
|
||||
// Include the composer autoloader
|
||||
if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
|
||||
echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n";
|
||||
exit(1);
|
||||
}
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
|
||||
define("PP_CONFIG_PATH", __DIR__);
|
||||
|
||||
$configManager = \PPConfigManager::getInstance();
|
||||
|
||||
// $cred is used by samples that include this bootstrap file
|
||||
// This piece of code simply demonstrates how you can
|
||||
// dynamically pass in a client id/secret instead of using
|
||||
// the config file. If you do not need a way to pass
|
||||
// in credentials dynamically, you can skip the
|
||||
// <Resource>::setCredential($cred) calls that
|
||||
// you see in the samples.
|
||||
$cred = new OAuthTokenCredential(
|
||||
$configManager->get('acct1.ClientId'),
|
||||
$configManager->get('acct1.ClientSecret'));
|
||||
|
||||
|
||||
/**
|
||||
* ### getBaseUrl function
|
||||
* // utility function that returns base url for
|
||||
* // determining return/cancel urls
|
||||
* @return string
|
||||
*/
|
||||
function getBaseUrl() {
|
||||
|
||||
$protocol = 'http';
|
||||
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) {
|
||||
$protocol .= 's';
|
||||
$protocol_port = $_SERVER['SERVER_PORT'];
|
||||
} else {
|
||||
$protocol_port = 80;
|
||||
}
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
$request = $_SERVER['PHP_SELF'];
|
||||
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
|
||||
}
|
||||
14
sample/composer.json
Normal file
14
sample/composer.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "paypal/rest-api-sdk-sample-php",
|
||||
"description": "Samples using PayPal's REST API SDK for PHP",
|
||||
"homepage": "https://github.com/paypal/rest-api-sdk-php",
|
||||
"config": {
|
||||
"require-all": true
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"paypal/rest-api-sdk-php" : "0.5.*"
|
||||
}
|
||||
}
|
||||
BIN
sample/images/edt-format-source-button.png
Normal file
BIN
sample/images/edt-format-source-button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 173 B |
BIN
sample/images/play_button.png
Normal file
BIN
sample/images/play_button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
94
sample/index.html
Normal file
94
sample/index.html
Normal file
@@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>PayPal REST API Samples</title>
|
||||
<style>
|
||||
.imagelink {
|
||||
padding: 5px 0px 5px 28px;
|
||||
}
|
||||
.execute {
|
||||
background: url('images/play_button.png') no-repeat left top;
|
||||
}
|
||||
.source {
|
||||
background: url('images/edt-format-source-button.png') no-repeat left top;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<h3>PayPal REST API Samples</h3>
|
||||
</center>
|
||||
<br /><br />
|
||||
<table cellspacing="5" width="85%">
|
||||
<tbody>
|
||||
<tr valign="top">
|
||||
<td>Payment with a credit card</td>
|
||||
<td></td>
|
||||
<td width="30%" ><a href="payments/CreatePayment.php" class="execute imagelink">Execute</a></td>
|
||||
<td></td>
|
||||
<td width="30%"><a href="source/CreatePayment.html" class="source imagelink">Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Payment with a PayPal Account</td>
|
||||
|
||||
<td></td>
|
||||
<td><a href="payments/CreatePaymentUsingPayPal.php" class="execute imagelink">Execute</a></td>
|
||||
|
||||
<td></td>
|
||||
<td><a href="source/CreatePaymentUsingPayPal.html" class="source imagelink">Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Get Payment Details</td>
|
||||
<td></td>
|
||||
<td><a href="payments/GetPayment.php" class="execute imagelink" >Execute</a></td>
|
||||
|
||||
<td></td>
|
||||
<td><a href="source/GetPayment.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Get Payment History</td>
|
||||
<td></td>
|
||||
<td><a href="payments/ListPayments.php" class="execute imagelink" >Execute</a></td>
|
||||
<td></td>
|
||||
<td><a href="source/ListPayments.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Get Sale Details</td>
|
||||
<td></td>
|
||||
<td><a href="sale/GetSale.php" class="execute imagelink" >Execute</a></td>
|
||||
<td></td>
|
||||
<td><a href="source/GetSale.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Refund a Payment</td>
|
||||
<td></td>
|
||||
<td><a href="sale/RefundSale.php" class="execute imagelink" >Execute</a></td>
|
||||
<td></td>
|
||||
<td><a href="source/RefundSale.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Save a credit card</td>
|
||||
<td></td>
|
||||
<td><a href="vault/CreateCreditCard.php" class="execute imagelink" >Execute</a></td>
|
||||
<td></td>
|
||||
<td><a href="source/CreateCreditCard.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Retrieve saved credit card</td>
|
||||
<td></td>
|
||||
<td><a href="vault/GetCreditCard.php" class="execute imagelink" >Execute</a></td>
|
||||
<td></td>
|
||||
<td><a href="source/GetCreditCard.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Payment with saved credit card</td>
|
||||
<td></td>
|
||||
<td><a href="payments/CreatePaymentUsingSavedCard.php" class="execute imagelink" >Execute</a></td>
|
||||
<td></td>
|
||||
<td><a href="source/CreatePaymentUsingSavedCard.html" class="source imagelink" >Source</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
111
sample/payments/CreatePayment.php
Normal file
111
sample/payments/CreatePayment.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
// # CreatePaymentSample
|
||||
// This sample code demonstrate how you can process
|
||||
// a payment with a credit card.
|
||||
// API used: /v1/payments/payment
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
// ### Address
|
||||
// Base Address object used as shipping or billing
|
||||
// address in a payment. [Optional]
|
||||
$addr = new Address();
|
||||
$addr->setLine1("3909 Witmer Road");
|
||||
$addr->setLine2("Niagara Falls");
|
||||
$addr->setCity("Niagara Falls");
|
||||
$addr->setState("NY");
|
||||
$addr->setPostal_code("14305");
|
||||
$addr->setCountry_code("US");
|
||||
$addr->setPhone("716-298-1822");
|
||||
|
||||
// ### CreditCard
|
||||
// A resource representing a credit card that can be
|
||||
// used to fund a payment.
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpire_month("11");
|
||||
$card->setExpire_year("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirst_name("Joe");
|
||||
$card->setLast_name("Shopper");
|
||||
$card->setBilling_address($addr);
|
||||
|
||||
// ### 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`
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCredit_card($card);
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// Use the List of `FundingInstrument` and the Payment Method
|
||||
// as 'credit_card'
|
||||
$payer = new Payer();
|
||||
$payer->setPayment_method("credit_card");
|
||||
$payer->setFunding_instruments(array($fi));
|
||||
|
||||
// ### Amount
|
||||
// Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
// ### 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
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
// using a valid ApiContext
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($payment->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
93
sample/payments/CreatePaymentUsingPayPal.php
Normal file
93
sample/payments/CreatePaymentUsingPayPal.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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\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;
|
||||
use PayPal\Rest\ApiContext;
|
||||
session_start();
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// Use the List of `FundingInstrument` and the Payment Method
|
||||
// as 'credit_card'
|
||||
$payer = new Payer();
|
||||
$payer->setPayment_method("paypal");
|
||||
|
||||
// ### Amount
|
||||
// Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
// ### 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
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
// ### Redirect urls
|
||||
// Set the urls that the buyer must be redirected to after
|
||||
// payment approval/ cancellation.
|
||||
$baseUrl = getBaseUrl();
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturn_url("$baseUrl/ExecutePayment.php?success=true");
|
||||
$redirectUrls->setCancel_url("$baseUrl/ExecutePayment.php?success=false");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setRedirect_urls($redirectUrls);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||
|
||||
// ### Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
// using a valid apiContext
|
||||
// The return object contains the status and the
|
||||
// url to which the buyer must be redirected to
|
||||
// for payment approval
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// ### Redirect buyer to paypal
|
||||
// Retrieve buyer approval url from the `payment` object.
|
||||
foreach($payment->getLinks() as $link) {
|
||||
if($link->getRel() == 'approval_url') {
|
||||
$redirectUrl = $link->getHref();
|
||||
}
|
||||
}
|
||||
// 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.
|
||||
$_SESSION['paymentId'] = $payment->getId();
|
||||
if(isset($redirectUrl)) {
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
}
|
||||
96
sample/payments/CreatePaymentUsingSavedCard.php
Normal file
96
sample/payments/CreatePaymentUsingSavedCard.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
// # Create payment using a saved credit card
|
||||
// This sample code demonstrates how you can process a
|
||||
// Payment using a previously saved credit card.
|
||||
// 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;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
// ### Credit card token
|
||||
// Saved credit card id from a previous call to
|
||||
// CreateCreditCard.php
|
||||
$creditCardId = 'CARD-5BT058015C739554AKE2GCEI';
|
||||
$creditCardToken = new CreditCardToken();
|
||||
$creditCardToken->setCredit_card_id($creditCardId);
|
||||
|
||||
// ### 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`
|
||||
$fi = new FundingInstrument();
|
||||
$fi->setCredit_card_token($creditCardToken);
|
||||
|
||||
// ### Payer
|
||||
// A resource representing a Payer that funds a payment
|
||||
// Use the List of `FundingInstrument` and the Payment Method
|
||||
// as 'credit_card'
|
||||
$payer = new Payer();
|
||||
$payer->setPayment_method("credit_card");
|
||||
$payer->setFunding_instruments(array($fi));
|
||||
|
||||
// ### Amount
|
||||
// Let's you specify a payment amount.
|
||||
$amount = new Amount();
|
||||
$amount->setCurrency("USD");
|
||||
$amount->setTotal("1.00");
|
||||
|
||||
// ### 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
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount($amount);
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
// ### Payment
|
||||
// A Payment Resource; create one using
|
||||
// the above types and intent as 'sale'
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||
|
||||
// ###Create Payment
|
||||
// Create a payment by posting to the APIService
|
||||
// using a valid apiContext
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
Created payment:
|
||||
<?php echo $payment->getId();?>
|
||||
</div>
|
||||
<pre><?php var_dump($payment->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
47
sample/payments/ExecutePayment.php
Normal file
47
sample/payments/ExecutePayment.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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;
|
||||
use PayPal\Rest\ApiContext;
|
||||
session_start();
|
||||
|
||||
if(isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred);
|
||||
|
||||
// Get the payment Object by passing paymentId
|
||||
// payment id was previously stored in session in
|
||||
// CreatePaymentUsingPayPal.php
|
||||
$paymentId = $_SESSION['paymentId'];
|
||||
$payment = Payment::get($paymentId);
|
||||
|
||||
// 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->setPayer_id($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
$payment->execute($execution, $apiContext);
|
||||
|
||||
echo "<html><body><pre>";
|
||||
var_dump($payment->toArray());
|
||||
echo "</pre><a href='../index.html'>Back</a></body></html>";
|
||||
|
||||
} else {
|
||||
echo "User cancelled payment.";
|
||||
}
|
||||
39
sample/payments/GetPayment.php
Normal file
39
sample/payments/GetPayment.php
Normal file
@@ -0,0 +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";
|
||||
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
Payment::setCredential($cred);
|
||||
// ### Retrieve payment
|
||||
// Retrieve the payment object by calling the
|
||||
// static `get` method
|
||||
// on the Payment class by passing a valid
|
||||
// Payment ID
|
||||
try {
|
||||
$payment = Payment::get($paymentId);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>Retrieving Payment ID: <?php echo $paymentId;?></div>
|
||||
<pre><?php var_dump($payment->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
42
sample/payments/ListPayments.php
Normal file
42
sample/payments/ListPayments.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// #GetPaymentList
|
||||
// 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;
|
||||
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
// If you skip this step, the client id/secret
|
||||
// set in the config file will be used.
|
||||
Payment::setCredential($cred);
|
||||
|
||||
// ### Retrieve payment
|
||||
// Retrieve the PaymentHistory object by calling the
|
||||
// static `get` method on the Payment class,
|
||||
// and pass a Map object that contains
|
||||
// query parameters for paginations and filtering.
|
||||
// Refer the method doc for valid values for keys
|
||||
try {
|
||||
$payments = Payment::all(array('count' => 10, 'start_index' => 5));
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>Got <?php echo $payments->getCount(); ?> matching payments </div>
|
||||
<pre><?php var_dump($payments->toArray());?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
35
sample/sale/GetSale.php
Normal file
35
sample/sale/GetSale.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// # Get Sale sample
|
||||
// This sample code demonstrates how you can retrieve
|
||||
// details of completed Sale Transaction.
|
||||
// API used: /v1/payments/sale/{sale-id}
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Sale;
|
||||
|
||||
$saleId = '3RM92092UW5126232';
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
// If you skip this step, the client id/secret
|
||||
// set in the config file will be used.
|
||||
Sale::setCredential($cred);
|
||||
try {
|
||||
// ### Retrieve the sale object
|
||||
// Pass the ID of the sale
|
||||
// transaction from your payment resource.
|
||||
$sale = Sale::get($saleId);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>Retrieving sale id: <?php echo $saleId;?></div>
|
||||
<pre><?php var_dump($sale);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
55
sample/sale/RefundSale.php
Normal file
55
sample/sale/RefundSale.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
// # Sale Refund Sample
|
||||
// This sample code demonstrate how you can
|
||||
// process a refund on a sale transaction created
|
||||
// using the Payments API.
|
||||
// API used: /v1/payments/sale/{sale-id}/refund
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Sale;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
// ### Refund
|
||||
// Create a refund object indicating
|
||||
// refund amount
|
||||
$amt = new Amount();
|
||||
$amt->setCurrency('USD');
|
||||
$amt->setTotal('0.01');
|
||||
|
||||
$refund = new Refund();
|
||||
$refund->setAmount($amt);
|
||||
|
||||
$saleId = '3RM92092UW5126232';
|
||||
|
||||
// ###Sale
|
||||
// A sale transaction.
|
||||
// Create a Sale object with the
|
||||
// given sale transaction id.
|
||||
$sale = new Sale();
|
||||
$sale->setId($saleId);
|
||||
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||
try {
|
||||
// Refund the sale
|
||||
$sale->refund($refund, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>Refunding sale id: <?php echo $saleId;?></div>
|
||||
<pre><?php var_dump($sale);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
35
sample/sdk_config.ini
Normal file
35
sample/sdk_config.ini
Normal file
@@ -0,0 +1,35 @@
|
||||
;Account credentials from developer portal
|
||||
[Account]
|
||||
acct1.ClientId = EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
||||
acct1.ClientSecret = EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
||||
|
||||
|
||||
;Connection Information
|
||||
[Http]
|
||||
http.ConnectionTimeOut = 30
|
||||
http.Retry = 1
|
||||
;http.Proxy=http://[username:password]@hostname[:port][/path]
|
||||
|
||||
|
||||
;Service Configuration
|
||||
[Service]
|
||||
service.EndPoint="https://api.sandbox.paypal.com"
|
||||
; Uncomment this line for integrating with the live endpoint
|
||||
; service.EndPoint="https://api.paypal.com"
|
||||
|
||||
|
||||
;Logging Information
|
||||
[Log]
|
||||
|
||||
log.LogEnabled=true
|
||||
|
||||
# When using a relative path, the log file is created
|
||||
# relative to the .php file that is the entry point
|
||||
# for this request. You can also provide an absolute
|
||||
# path here
|
||||
log.FileName=../PayPal.log
|
||||
|
||||
# Logging level can be one of FINE, INFO, WARN or ERROR
|
||||
# Logging is most verbose in the 'FINE' level and
|
||||
# decreases as you proceed towards ERROR
|
||||
log.LogLevel=FINE
|
||||
48
sample/source/CreateCreditCard.html
Normal file
48
sample/source/CreateCreditCard.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>CreateCreditCard</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="CreateCreditCard"><meta name="groc-project-path" content="CreateCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="create-credit-card-sample">Create Credit Card Sample</h1>
|
||||
|
||||
<p>Using the 'vault' API, you can store a
|
||||
Credit Card securely on PayPal. You can
|
||||
use a saved Credit Card to process
|
||||
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</p></div></div><div class="code"><div class="wrapper"><span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||
|
||||
<span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3>
|
||||
|
||||
<p>A resource representing a credit card that can be
|
||||
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setType</span><span class="p">(</span><span class="s2">"visa"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setNumber</span><span class="p">(</span><span class="s2">"4417119669820331"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">"11"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">"2019"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">"012"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">"Joe"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="save-card">Save card</h3>
|
||||
|
||||
<p>Creates the credit card as a resource
|
||||
in the PayPal vault. The response contains
|
||||
an 'id' that you can use to refer to it
|
||||
in the future payments.</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">create</span><span class="p">();</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div>Saved a new credit card with id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$card</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span><span class="cp">?></span><span class="x"></div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
90
sample/source/CreatePayment.html
Normal file
90
sample/source/CreatePayment.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>CreatePayment</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="CreatePayment"><meta name="groc-project-path" content="CreatePayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="createpaymentsample">CreatePaymentSample</h1>
|
||||
|
||||
<p>This sample code demonstrate how you can process
|
||||
a payment with a credit card.
|
||||
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="address">Address</h3>
|
||||
|
||||
<p>Base Address object used as shipping or billing
|
||||
address in a payment. [Optional]</p></div></div><div class="code"><div class="wrapper"><span class="nv">$addr</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Address</span><span class="p">();</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setLine1</span><span class="p">(</span><span class="s2">"3909 Witmer Road"</span><span class="p">);</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setLine2</span><span class="p">(</span><span class="s2">"Niagara Falls"</span><span class="p">);</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setCity</span><span class="p">(</span><span class="s2">"Niagara Falls"</span><span class="p">);</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setState</span><span class="p">(</span><span class="s2">"NY"</span><span class="p">);</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setPostal_code</span><span class="p">(</span><span class="s2">"14305"</span><span class="p">);</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setCountry_code</span><span class="p">(</span><span class="s2">"US"</span><span class="p">);</span>
|
||||
<span class="nv">$addr</span><span class="o">-></span><span class="na">setPhone</span><span class="p">(</span><span class="s2">"716-298-1822"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3>
|
||||
|
||||
<p>A resource representing a credit card that can be
|
||||
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setType</span><span class="p">(</span><span class="s2">"visa"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setNumber</span><span class="p">(</span><span class="s2">"4417119669820331"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">"11"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">"2019"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">"012"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">"Joe"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setBilling_address</span><span class="p">(</span><span class="nv">$addr</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||
|
||||
<p>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 <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span>
|
||||
<span class="nv">$fi</span><span class="o">-></span><span class="na">setCredit_card</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||
|
||||
<p>A resource representing a Payer that funds a payment
|
||||
Use the List of <code>FundingInstrument</code> and the Payment Method
|
||||
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
|
||||
<span class="nv">$payer</span><span class="o">-></span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">"credit_card"</span><span class="p">);</span>
|
||||
<span class="nv">$payer</span><span class="o">-></span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
|
||||
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">"USD"</span><span class="p">);</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setTotal</span><span class="p">(</span><span class="s2">"1.00"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||
|
||||
<p>A transaction defines the contract of a
|
||||
payment - what is the payment for and who
|
||||
is fulfilling it. Transaction is created with
|
||||
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
|
||||
<span class="nv">$transaction</span><span class="o">-></span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
|
||||
<span class="nv">$transaction</span><span class="o">-></span><span class="na">setDescription</span><span class="p">(</span><span class="s2">"This is the payment description."</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
<p>Create a payment by posting to the APIService
|
||||
using a valid ApiContext
|
||||
The return object contains the status;</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div></span>
|
||||
<span class="x"> Created payment:</span>
|
||||
<span class="x"> </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$payment</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span><span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"> </div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
72
sample/source/CreatePaymentUsingPayPal.html
Normal file
72
sample/source/CreatePaymentUsingPayPal.html
Normal file
@@ -0,0 +1,72 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>CreatePaymentUsingPayPal</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="CreatePaymentUsingPayPal"><meta name="groc-project-path" content="CreatePaymentUsingPayPal.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="create-payment-using-paypal-as-payment-method">Create Payment using PayPal as payment method</h1>
|
||||
|
||||
<p>This sample code demonstrates how you can process a
|
||||
PayPal Account based Payment.
|
||||
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\RedirectUrls</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||
<span class="nb">session_start</span><span class="p">();</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||
|
||||
<p>A resource representing a Payer that funds a payment
|
||||
Use the List of <code>FundingInstrument</code> and the Payment Method
|
||||
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
|
||||
<span class="nv">$payer</span><span class="o">-></span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">"paypal"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
|
||||
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">"USD"</span><span class="p">);</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setTotal</span><span class="p">(</span><span class="s2">"1.00"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||
|
||||
<p>A transaction defines the contract of a
|
||||
payment - what is the payment for and who
|
||||
is fulfilling it. Transaction is created with
|
||||
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
|
||||
<span class="nv">$transaction</span><span class="o">-></span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
|
||||
<span class="nv">$transaction</span><span class="o">-></span><span class="na">setDescription</span><span class="p">(</span><span class="s2">"This is the payment description."</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
|
||||
|
||||
<p>Set the urls that the buyer must be redirected to after
|
||||
payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$baseUrl</span> <span class="o">=</span> <span class="nx">getBaseUrl</span><span class="p">();</span>
|
||||
<span class="nv">$redirectUrls</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">RedirectUrls</span><span class="p">();</span>
|
||||
<span class="nv">$redirectUrls</span><span class="o">-></span><span class="na">setReturn_url</span><span class="p">(</span><span class="s2">"</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=true"</span><span class="p">);</span>
|
||||
<span class="nv">$redirectUrls</span><span class="o">-></span><span class="na">setCancel_url</span><span class="p">(</span><span class="s2">"</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=false"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setRedirect_urls</span><span class="p">(</span><span class="nv">$redirectUrls</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
<p>Create a payment by posting to the APIService
|
||||
using a valid apiContext
|
||||
The return object contains the status and the
|
||||
url to which the buyer must be redirected to
|
||||
for payment approval</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="redirect-buyer-to-paypal">Redirect buyer to paypal</h3>
|
||||
|
||||
<p>Retrieve buyer approval url from the <code>payment</code> object.</p></div></div><div class="code"><div class="wrapper"><span class="k">foreach</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">getLinks</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$link</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="nv">$link</span><span class="o">-></span><span class="na">getRel</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'approval_url'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nv">$redirectUrl</span> <span class="o">=</span> <span class="nv">$link</span><span class="o">-></span><span class="na">getHref</span><span class="p">();</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow">¶</a></div><div class="wrapper"><p>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.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$payment</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$redirectUrl</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="nx">header</span><span class="p">(</span><span class="s2">"Location: </span><span class="si">$redirectUrl</span><span class="s2">"</span><span class="p">);</span>
|
||||
<span class="k">exit</span><span class="p">;</span>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
77
sample/source/CreatePaymentUsingSavedCard.html
Normal file
77
sample/source/CreatePaymentUsingSavedCard.html
Normal file
@@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>CreatePaymentUsingSavedCard</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="CreatePaymentUsingSavedCard"><meta name="groc-project-path" content="CreatePaymentUsingSavedCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="create-payment-using-a-saved-credit-card">Create payment using a saved credit card</h1>
|
||||
|
||||
<p>This sample code demonstrates how you can process a
|
||||
Payment using a previously saved credit card.
|
||||
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCardToken</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\RedirectUrls</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Auth\OAuthTokenCredential</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="credit-card-token">Credit card token</h3>
|
||||
|
||||
<p>Saved credit card id from a previous call to
|
||||
CreateCreditCard.php</p></div></div><div class="code"><div class="wrapper"><span class="nv">$creditCardId</span> <span class="o">=</span> <span class="s1">'CARD-5BT058015C739554AKE2GCEI'</span><span class="p">;</span>
|
||||
<span class="nv">$creditCardToken</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCardToken</span><span class="p">();</span>
|
||||
<span class="nv">$creditCardToken</span><span class="o">-></span><span class="na">setCredit_card_id</span><span class="p">(</span><span class="nv">$creditCardId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
|
||||
|
||||
<p>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 <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span>
|
||||
<span class="nv">$fi</span><span class="o">-></span><span class="na">setCredit_card_token</span><span class="p">(</span><span class="nv">$creditCardToken</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||
|
||||
<p>A resource representing a Payer that funds a payment
|
||||
Use the List of <code>FundingInstrument</code> and the Payment Method
|
||||
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
|
||||
<span class="nv">$payer</span><span class="o">-></span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">"credit_card"</span><span class="p">);</span>
|
||||
<span class="nv">$payer</span><span class="o">-></span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="amount">Amount</h3>
|
||||
|
||||
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">"USD"</span><span class="p">);</span>
|
||||
<span class="nv">$amount</span><span class="o">-></span><span class="na">setTotal</span><span class="p">(</span><span class="s2">"1.00"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
|
||||
|
||||
<p>A transaction defines the contract of a
|
||||
payment - what is the payment for and who
|
||||
is fulfilling it. Transaction is created with
|
||||
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
|
||||
<span class="nv">$transaction</span><span class="o">-></span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
|
||||
<span class="nv">$transaction</span><span class="o">-></span><span class="na">setDescription</span><span class="p">(</span><span class="s2">"This is the payment description."</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payment">Payment</h3>
|
||||
|
||||
<p>A Payment Resource; create one using
|
||||
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
<p>Create a payment by posting to the APIService
|
||||
using a valid apiContext
|
||||
The return object contains the status;</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div></span>
|
||||
<span class="x"> Created payment:</span>
|
||||
<span class="x"> </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$payment</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span><span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"> </div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
40
sample/source/ExecutePayment.html
Normal file
40
sample/source/ExecutePayment.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>ExecutePayment</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="ExecutePayment"><meta name="groc-project-path" content="ExecutePayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="execute-payment-sample">Execute Payment Sample</h1>
|
||||
|
||||
<p>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'.</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\ExecutePayment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\PaymentExecution</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||
<span class="nb">session_start</span><span class="p">();</span>
|
||||
|
||||
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">])</span> <span class="o">&&</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'true'</span><span class="p">)</span> <span class="p">{</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"> <span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||
</div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
payment id was previously stored in session in
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$paymentId</span> <span class="o">=</span> <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">];</span>
|
||||
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">);</span>
|
||||
</div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><p>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</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$execution</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PaymentExecution</span><span class="p">();</span>
|
||||
<span class="nv">$execution</span><span class="o">-></span><span class="na">setPayer_id</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'PayerID'</span><span class="p">]);</span>
|
||||
|
||||
<span class="c1">//Execute the payment</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">execute</span><span class="p">(</span><span class="nv">$execution</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
|
||||
<span class="k">echo</span> <span class="s2">"<html><body><pre>"</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span>
|
||||
<span class="k">echo</span> <span class="s2">"</pre><a href='../index.html'>Back</a></body></html>"</span><span class="p">;</span>
|
||||
|
||||
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"User cancelled payment."</span><span class="p">;</span>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
31
sample/source/GetCreditCard.html
Normal file
31
sample/source/GetCreditCard.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>GetCreditCard</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="GetCreditCard"><meta name="groc-project-path" content="GetCreditCard.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="get-credit-card-sample">Get Credit Card Sample</h1>
|
||||
|
||||
<p>The CreditCard resource allows you to
|
||||
retrieve previously saved CreditCards,
|
||||
by sending a GET request to the URI
|
||||
'/v1/vault/credit-card'
|
||||
The following code takes you through
|
||||
the process of retrieving a saved CreditCard</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><p>The cardId can be obtained from a previous save credit
|
||||
card operation. Use $card->getId()</p></div></div><div class="code"><div class="wrapper"><span class="nv">$cardId</span> <span class="o">=</span> <span class="s2">"CARD-5BT058015C739554AKE2GCEI"</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call.
|
||||
If you skip this step, the client id/secret
|
||||
set in the config file will be used.</p></div></div><div class="code"><div class="wrapper"><span class="nx">CreditCard</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||
<span class="c1">/// ### Retrieve card</span>
|
||||
<span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$card</span> <span class="o">=</span> <span class="nx">CreditCard</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$cardId</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div>Retrieving credit card: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$cardId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
34
sample/source/GetPayment.html
Normal file
34
sample/source/GetPayment.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>GetPayment</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="GetPayment"><meta name="groc-project-path" content="GetPayment.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="getpaymentsample">GetPaymentSample</h1>
|
||||
|
||||
<p>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</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
|
||||
<span class="nv">$paymentId</span> <span class="o">=</span> <span class="s2">"PAY-0XL713371A312273YKE2GCNI"</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
|
||||
<p>Retrieve the payment object by calling the
|
||||
static <code>get</code> method
|
||||
on the Payment class by passing a valid
|
||||
Payment ID</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div>Retrieving Payment ID: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$paymentId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
30
sample/source/GetSale.html
Normal file
30
sample/source/GetSale.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>GetSale</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="GetSale"><meta name="groc-project-path" content="GetSale.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="get-sale-sample">Get Sale sample</h1>
|
||||
|
||||
<p>This sample code demonstrates how you can retrieve
|
||||
details of completed Sale Transaction.
|
||||
API used: /v1/payments/sale/{sale-id}</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Sale</span><span class="p">;</span>
|
||||
|
||||
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">'3RM92092UW5126232'</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call.
|
||||
If you skip this step, the client id/secret
|
||||
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Sale</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
|
||||
|
||||
<p>Pass the ID of the sale
|
||||
transaction from your payment resource.</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span> <span class="o">=</span> <span class="nx">Sale</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div>Retrieving sale id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
35
sample/source/ListPayments.html
Normal file
35
sample/source/ListPayments.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>ListPayments</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="ListPayments"><meta name="groc-project-path" content="ListPayments.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="getpaymentlist">GetPaymentList</h1>
|
||||
|
||||
<p>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</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call.
|
||||
If you skip this step, the client id/secret
|
||||
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
|
||||
<p>Retrieve the PaymentHistory object by calling the
|
||||
static <code>get</code> method on the Payment class,
|
||||
and pass a Map object that contains
|
||||
query parameters for paginations and filtering.
|
||||
Refer the method doc for valid values for keys</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payments</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">all</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'count'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'start_index'</span> <span class="o">=></span> <span class="mi">5</span><span class="p">));</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div>Got </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$payments</span><span class="o">-></span><span class="na">getCount</span><span class="p">();</span> <span class="cp">?></span><span class="x"> matching payments </div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payments</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
44
sample/source/RefundSale.html
Normal file
44
sample/source/RefundSale.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>RefundSale</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="RefundSale"><meta name="groc-project-path" content="RefundSale.php"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><body><div id="document"><div class="segment"><a id="segment-0" name="segment-0" class="section_anchor"></a><div class="code"><div class="wrapper"><span class="cp"><?php</span></div></div></div><div class="segment"><a id="segment-1" name="segment-1" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-1" class="pilcrow">¶</a></div><div class="wrapper"><h1 id="sale-refund-sample">Sale Refund Sample</h1>
|
||||
|
||||
<p>This sample code demonstrate how you can
|
||||
process a refund on a sale transaction created
|
||||
using the Payments API.
|
||||
API used: /v1/payments/sale/{sale-id}/refund</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Refund</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Sale</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
|
||||
<p>Create a refund object indicating
|
||||
refund amount</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amt</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
|
||||
<span class="nv">$amt</span><span class="o">-></span><span class="na">setCurrency</span><span class="p">(</span><span class="s1">'USD'</span><span class="p">);</span>
|
||||
<span class="nv">$amt</span><span class="o">-></span><span class="na">setTotal</span><span class="p">(</span><span class="s1">'0.01'</span><span class="p">);</span>
|
||||
|
||||
<span class="nv">$refund</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Refund</span><span class="p">();</span>
|
||||
<span class="nv">$refund</span><span class="o">-></span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amt</span><span class="p">);</span>
|
||||
|
||||
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">'3RM92092UW5126232'</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="sale">Sale</h3>
|
||||
|
||||
<p>A sale transaction.
|
||||
Create a Sale object with the
|
||||
given sale transaction id.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$sale</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Sale</span><span class="p">();</span>
|
||||
<span class="nv">$sale</span><span class="o">-></span><span class="na">setId</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span>
|
||||
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><p>Refund the sale</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span><span class="o">-></span><span class="na">refund</span><span class="p">(</span><span class="nv">$refund</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
<span class="x"><html></span>
|
||||
<span class="x"><body></span>
|
||||
<span class="x"> <div>Refunding sale id: </span><span class="cp"><?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?></span><span class="x"></div></span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="x"> <a href='../index.html'>Back</a></span>
|
||||
<span class="x"></body></span>
|
||||
<span class="x"></html></span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>
|
||||
459
sample/source/assets/behavior.js
Normal file
459
sample/source/assets/behavior.js
Normal file
File diff suppressed because one or more lines are too long
93
sample/source/assets/docs.js
Normal file
93
sample/source/assets/docs.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @depend jquery.nicescroll.js
|
||||
*/
|
||||
|
||||
var j_window = $(window),
|
||||
j_flybar = $('#flybar');
|
||||
j_sidebar = $('.sidebar_popout'),
|
||||
j_content = $('#document');
|
||||
|
||||
var docs = {
|
||||
init: function() {
|
||||
this.sidebar_popout();
|
||||
this.url_rewrite();
|
||||
},
|
||||
|
||||
sidebar_popout: function() {
|
||||
$('#sidebar_button').on('click', function() {
|
||||
var sidebar_hidden_class = 'sidebar_hidden',
|
||||
animation_speed = 200;
|
||||
|
||||
if ( !j_sidebar.hasClass(sidebar_hidden_class) ) {
|
||||
j_sidebar.stop()
|
||||
.animate({
|
||||
marginLeft: -270
|
||||
}, animation_speed)
|
||||
.addClass(sidebar_hidden_class);
|
||||
j_content.stop()
|
||||
.animate({
|
||||
paddingLeft: 18
|
||||
}, animation_speed);
|
||||
j_flybar.stop()
|
||||
.animate({
|
||||
marginLeft: -282
|
||||
}, animation_speed);
|
||||
$(this).stop()
|
||||
.animate({
|
||||
marginLeft: -270
|
||||
}, animation_speed);
|
||||
}
|
||||
else {
|
||||
j_sidebar.stop()
|
||||
.animate({
|
||||
marginLeft: 0
|
||||
}, animation_speed)
|
||||
.removeClass(sidebar_hidden_class);
|
||||
j_content.stop()
|
||||
.animate({
|
||||
paddingLeft: 300
|
||||
}, animation_speed);
|
||||
j_flybar.stop()
|
||||
.animate({
|
||||
marginLeft: 0
|
||||
}, animation_speed);
|
||||
$(this).stop()
|
||||
.animate({
|
||||
marginLeft: 0
|
||||
}, animation_speed);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
url_rewrite: function() {
|
||||
$('.sidebar .menu a').each(function() {
|
||||
var j_this = $(this),
|
||||
href = j_this.attr('href'),
|
||||
url = new RegExp(window.location.protocol + '//' + window.location.host + window.location.pathname);
|
||||
|
||||
if (url.test(href)) {
|
||||
href = href.replace(url, '#') // Replace domain and path
|
||||
.replace(/\//g, '-') // Replace '/' with '-'
|
||||
.replace(/-$/, ''); // Remove last '-'
|
||||
|
||||
j_this.attr('href', encodeURI(href));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
docs.init();
|
||||
|
||||
/* Enable Nice Scroll on docs sidebar */
|
||||
// j_sidebar_docs.niceScroll({
|
||||
// zindex: 1,
|
||||
// cursorcolor: '#bbb',
|
||||
// cursorwidth: '7px',
|
||||
// cursorborder: '0',
|
||||
// cursorborderradius: '10px',
|
||||
// autohidemode: false,
|
||||
// railoffset: { left: 15 }
|
||||
// });
|
||||
|
||||
});
|
||||
4
sample/source/assets/jquery.min.js
vendored
Normal file
4
sample/source/assets/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
sample/source/assets/sideNavOut.png
Normal file
BIN
sample/source/assets/sideNavOut.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 289 B |
BIN
sample/source/assets/sideNavOver.png
Normal file
BIN
sample/source/assets/sideNavOver.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 300 B |
1
sample/source/assets/style.css
Normal file
1
sample/source/assets/style.css
Normal file
File diff suppressed because one or more lines are too long
57
sample/vault/CreateCreditCard.php
Normal file
57
sample/vault/CreateCreditCard.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
// # Create Credit Card Sample
|
||||
// Using the 'vault' API, you can store a
|
||||
// Credit Card securely on PayPal. You can
|
||||
// use a saved Credit Card to process
|
||||
// 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
|
||||
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Address;
|
||||
|
||||
// ### CreditCard
|
||||
// A resource representing a credit card that can be
|
||||
// used to fund a payment.
|
||||
$card = new CreditCard();
|
||||
$card->setType("visa");
|
||||
$card->setNumber("4417119669820331");
|
||||
$card->setExpire_month("11");
|
||||
$card->setExpire_year("2019");
|
||||
$card->setCvv2("012");
|
||||
$card->setFirst_name("Joe");
|
||||
$card->setLast_name("Shopper");
|
||||
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||
|
||||
// ### Save card
|
||||
// Creates the credit card as a resource
|
||||
// in the PayPal vault. The response contains
|
||||
// an 'id' that you can use to refer to it
|
||||
// in the future payments.
|
||||
try {
|
||||
$card->create();
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>Saved a new credit card with id: <?php echo $card->getId();?></div>
|
||||
<pre><?php var_dump($card);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
38
sample/vault/GetCreditCard.php
Normal file
38
sample/vault/GetCreditCard.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
// # Get Credit Card Sample
|
||||
// The CreditCard resource allows you to
|
||||
// retrieve previously saved CreditCards,
|
||||
// by sending a GET request to the URI
|
||||
// '/v1/vault/credit-card'
|
||||
// The following code takes you through
|
||||
// the process of retrieving a saved CreditCard
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\CreditCard;
|
||||
|
||||
// The cardId can be obtained from a previous save credit
|
||||
// card operation. Use $card->getId()
|
||||
$cardId = "CARD-5BT058015C739554AKE2GCEI";
|
||||
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
// If you skip this step, the client id/secret
|
||||
// set in the config file will be used.
|
||||
CreditCard::setCredential($cred);
|
||||
/// ### Retrieve card
|
||||
try {
|
||||
$card = CreditCard::get($cardId);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
exit(1);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<body>
|
||||
<div>Retrieving credit card: <?php echo $cardId;?></div>
|
||||
<pre><?php var_dump($card);?></pre>
|
||||
<a href='../index.html'>Back</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user