From b3423b6c118b787144826b28a9031e1bb6144ee9 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Fri, 26 Apr 2013 12:00:20 +0530
Subject: [PATCH] Updating stubs and samples to use apiContext
---
CHANGELOG.md | 3 +-
lib/PayPal/Api/CreditCard.php | 8 +-
lib/PayPal/Api/Payment.php | 16 +-
lib/PayPal/Api/Refund.php | 4 +-
lib/PayPal/Api/Sale.php | 8 +-
lib/PayPal/Auth/OAuthTokenCredential.php | 7 +-
sample/bootstrap.php | 105 +++++----
sample/payments/CreatePayment.php | 216 +++++++++---------
sample/payments/CreatePaymentUsingPayPal.php | 179 +++++++--------
.../payments/CreatePaymentUsingSavedCard.php | 182 +++++++--------
sample/payments/ExecutePayment.php | 85 ++++---
sample/payments/GetPayment.php | 73 +++---
sample/payments/ListPayments.php | 79 +++----
sample/sale/GetSale.php | 63 +++--
sample/sale/RefundSale.php | 102 ++++-----
sample/sdk_config.ini | 59 ++---
sample/source/CreateCreditCard.html | 56 ++---
sample/source/CreatePayment.html | 112 +++++----
sample/source/CreatePaymentUsingPayPal.html | 83 ++++---
.../source/CreatePaymentUsingSavedCard.html | 90 ++++----
sample/source/ExecutePayment.html | 50 ++--
sample/source/GetCreditCard.html | 39 ++--
sample/source/GetPayment.html | 40 ++--
sample/source/GetSale.html | 42 ++--
sample/source/ListPayments.html | 38 ++-
sample/source/RefundSale.html | 60 +++--
sample/vault/CreateCreditCard.php | 103 ++++-----
sample/vault/GetCreditCard.php | 69 +++---
28 files changed, 931 insertions(+), 1040 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e687b2..fd0d180 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,10 +1,11 @@
CHANGELOG
=========
-V0.6.0 (April 25, 2013)
+V0.6.0 (April 26, 2013)
-----------------------
* Adding support for dynamic configuration of SDK (Upgrading sdk-core-php dependency to V1.4.0)
+ * Changing resource class methods to take an ApiContext argument instead of a OauthTokenCredential argument.
V0.5.0 (March 07, 2013)
-----------------------
diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php
index 0a47b5a..982f51f 100644
--- a/lib/PayPal/Api/CreditCard.php
+++ b/lib/PayPal/Api/CreditCard.php
@@ -237,8 +237,8 @@ class CreditCard extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/vault/credit-card",
"POST", $payLoad);
$this->fromJson($json);
@@ -259,8 +259,8 @@ class CreditCard extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/vault/credit-card/$creditcardid",
"GET", $payLoad);
$ret = new CreditCard();
diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php
index 3492d32..7ea69ba 100644
--- a/lib/PayPal/Api/Payment.php
+++ b/lib/PayPal/Api/Payment.php
@@ -185,8 +185,8 @@ class Payment extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET", $payLoad);
$ret = new PaymentHistory();
@@ -206,8 +206,8 @@ class Payment extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment",
"POST", $payLoad);
$this->fromJson($json);
@@ -228,8 +228,8 @@ class Payment extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment/$paymentid",
"GET", $payLoad);
$ret = new Payment();
@@ -255,8 +255,8 @@ class Payment extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment/{$this->getId()}/execute",
"POST", $payLoad);
$this->fromJson($json);
diff --git a/lib/PayPal/Api/Refund.php b/lib/PayPal/Api/Refund.php
index 89729ee..592fe4e 100644
--- a/lib/PayPal/Api/Refund.php
+++ b/lib/PayPal/Api/Refund.php
@@ -192,8 +192,8 @@ class Refund extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/refund/$refundid",
"GET", $payLoad);
$ret = new Refund();
diff --git a/lib/PayPal/Api/Sale.php b/lib/PayPal/Api/Sale.php
index bcb0619..4b431f4 100644
--- a/lib/PayPal/Api/Sale.php
+++ b/lib/PayPal/Api/Sale.php
@@ -144,8 +144,8 @@ class Sale extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/sale/$saleid",
"GET", $payLoad);
$ret = new Sale();
@@ -171,8 +171,8 @@ class Sale extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new \PPRestCall();
- $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ $call = new \PPRestCall($apiContext);
+ $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/sale/{$this->getId()}/refund",
"POST", $payLoad);
$this->fromJson($json);
diff --git a/lib/PayPal/Auth/OAuthTokenCredential.php b/lib/PayPal/Auth/OAuthTokenCredential.php
index 96e49c7..e5d375d 100644
--- a/lib/PayPal/Auth/OAuthTokenCredential.php
+++ b/lib/PayPal/Auth/OAuthTokenCredential.php
@@ -49,14 +49,15 @@ class OAuthTokenCredential {
*/
public function __construct($clientId, $clientSecret) {
$this->clientId = $clientId;
- $this->clientSecret = $clientSecret;
- $this->logger = new \PPLoggingManager(__CLASS__);
+ $this->clientSecret = $clientSecret;
}
/**
* @return the accessToken
*/
- public function getAccessToken($config) {
+ public function getAccessToken($config) {
+
+ $this->logger = new \PPLoggingManager(__CLASS__, $config);
// Check if Access Token is not null and has not expired.
// The API returns expiry time as a relative time unit
// We use a buffer time when checking for token expiry to account
diff --git a/sample/bootstrap.php b/sample/bootstrap.php
index 3d8f23c..5095a03 100644
--- a/sample/bootstrap.php
+++ b/sample/bootstrap.php
@@ -1,50 +1,57 @@
-::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);
-}
+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';
+define("PP_CONFIG_PATH", __DIR__);
+
+use PayPal\Rest\ApiContext;
+use PayPal\Auth\OAuthTokenCredential;
+
+// ### Api Context
+// Pass in a `PayPal\Rest\ApiContext` object to authenticate
+// the call. You can also send a unique request id
+// (that ensures idempotency). The SDK generates
+// a request id if you do not pass one explicitly.
+$apiContext = new ApiContext(new OAuthTokenCredential(
+ 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
+ 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'));
+// Uncomment this step if you want to use per request
+// dynamic configuration instead of using sdk_config.ini
+/*
+$apiContext->setConfig(array(
+ 'mode' => 'sandbox',
+ 'http.ConnectionTimeOut' => 30,
+ 'log.LogEnabled' => true,
+ 'log.FileName' => '../PayPal.log',
+ 'log.LogLevel' => 'FINE'
+));
+*/
+
+/**
+ * ### 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);
+}
diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php
index 562a70d..258629f 100644
--- a/sample/payments/CreatePayment.php
+++ b/sample/payments/CreatePayment.php
@@ -1,111 +1,105 @@
-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);
-}
-?>
-
-
-
- Created payment:
- getId();?>
-
- toArray());?>
- Back
-
-
+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));
+
+
+
+// ### Create Payment
+// Create a payment by posting to the APIService
+// using a valid ApiContext (See bootstrap.php for more on `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);
+}
+?>
+
+
+
+ Created payment:
+ getId();?>
+
+ toArray());?>
+ Back
+
+
diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php
index 8467c15..e4cf904 100644
--- a/sample/payments/CreatePaymentUsingPayPal.php
+++ b/sample/payments/CreatePaymentUsingPayPal.php
@@ -1,93 +1,86 @@
-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;
-}
+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));
+
+// ### Create Payment
+// Create a payment by posting to the APIService
+// using a valid apiContext.
+// (See bootstrap.php for more on `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;
+}
diff --git a/sample/payments/CreatePaymentUsingSavedCard.php b/sample/payments/CreatePaymentUsingSavedCard.php
index 5994c7c..40c9bf6 100644
--- a/sample/payments/CreatePaymentUsingSavedCard.php
+++ b/sample/payments/CreatePaymentUsingSavedCard.php
@@ -1,96 +1,88 @@
-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);
-}
-?>
-
-
-
- Created payment:
- getId();?>
-
- toArray());?>
- Back
-
+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));
+
+// ###Create Payment
+// Create a payment by posting to the APIService
+// (See bootstrap.php for more on `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);
+}
+?>
+
+
+
+ Created payment:
+ getId();?>
+
+ toArray());?>
+ Back
+
\ No newline at end of file
diff --git a/sample/payments/ExecutePayment.php b/sample/payments/ExecutePayment.php
index 45224fd..6827c99 100644
--- a/sample/payments/ExecutePayment.php
+++ b/sample/payments/ExecutePayment.php
@@ -1,47 +1,40 @@
-/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 "";
- var_dump($payment->toArray());
- echo "
Back";
-
-} else {
- echo "User cancelled payment.";
+/execute'.
+
+require __DIR__ . '/../bootstrap.php';
+use PayPal\Api\ExecutePayment;
+use PayPal\Api\Payment;
+use PayPal\Api\PaymentExecution;
+session_start();
+if(isset($_GET['success']) && $_GET['success'] == 'true') {
+
+ // Get the payment Object by passing paymentId
+ // payment id was previously stored in session in
+ // CreatePaymentUsingPayPal.php
+ $paymentId = $_SESSION['paymentId'];
+ $payment = Payment::get($paymentId, $apiContext);
+
+ // PaymentExecution object includes information necessary
+ // to execute a PayPal account payment.
+ // The payer_id is added to the request query parameters
+ // when the user is redirected from paypal back to your site
+ $execution = new PaymentExecution();
+ $execution->setPayer_id($_GET['PayerID']);
+
+ //Execute the payment
+ // (See bootstrap.php for more on `ApiContext`)
+ $payment->execute($execution, $apiContext);
+
+ echo "";
+ var_dump($payment->toArray());
+ echo "
Back";
+
+} else {
+ echo "User cancelled payment.";
}
\ No newline at end of file
diff --git a/sample/payments/GetPayment.php b/sample/payments/GetPayment.php
index 97415ca..288d49e 100644
--- a/sample/payments/GetPayment.php
+++ b/sample/payments/GetPayment.php
@@ -1,39 +1,36 @@
-getMessage() . PHP_EOL;
- var_dump($ex->getData());
- exit(1);
-}
-?>
-
-
- Retrieving Payment ID:
- toArray());?>
- Back
-
+getMessage() . PHP_EOL;
+ var_dump($ex->getData());
+ exit(1);
+}
+?>
+
+
+ Retrieving Payment ID:
+ toArray());?>
+ Back
+
\ No newline at end of file
diff --git a/sample/payments/ListPayments.php b/sample/payments/ListPayments.php
index c11396c..4f950c4 100644
--- a/sample/payments/ListPayments.php
+++ b/sample/payments/ListPayments.php
@@ -1,42 +1,37 @@
- 10, 'start_index' => 5));
-} catch (\PPConnectionException $ex) {
- echo "Exception:" . $ex->getMessage() . PHP_EOL;
- var_dump($ex->getData());
- exit(1);
-}
-?>
-
-
- Got getCount(); ?> matching payments
- toArray());?>
- Back
-
-
+ 10, 'start_index' => 5), $apiContext);
+} catch (\PPConnectionException $ex) {
+ echo "Exception:" . $ex->getMessage() . PHP_EOL;
+ var_dump($ex->getData());
+ exit(1);
+}
+?>
+
+
+ Got getCount(); ?> matching payments
+ toArray());?>
+ Back
+
+
diff --git a/sample/sale/GetSale.php b/sample/sale/GetSale.php
index 9ac1697..521f445 100644
--- a/sample/sale/GetSale.php
+++ b/sample/sale/GetSale.php
@@ -1,35 +1,30 @@
-getMessage() . PHP_EOL;
- var_dump($ex->getData());
- exit(1);
-}
-?>
-
-
- Retrieving sale id:
-
- Back
-
+getMessage() . PHP_EOL;
+ var_dump($ex->getData());
+ exit(1);
+}
+?>
+
+
+ Retrieving sale id:
+
+ Back
+
\ No newline at end of file
diff --git a/sample/sale/RefundSale.php b/sample/sale/RefundSale.php
index 072af6d..bcf9df7 100644
--- a/sample/sale/RefundSale.php
+++ b/sample/sale/RefundSale.php
@@ -1,55 +1,49 @@
-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);
-}
-?>
-
-
- Refunding sale id:
-
- Back
-
+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);
+
+try {
+ // Refund the sale
+ // (See bootstrap.php for more on `ApiContext`)
+ $sale->refund($refund, $apiContext);
+} catch (\PPConnectionException $ex) {
+ echo "Exception:" . $ex->getMessage() . PHP_EOL;
+ var_dump($ex->getData());
+ exit(1);
+}
+?>
+
+
+ Refunding sale id:
+
+ Back
+
\ No newline at end of file
diff --git a/sample/sdk_config.ini b/sample/sdk_config.ini
index 69de99f..4906f19 100644
--- a/sample/sdk_config.ini
+++ b/sample/sdk_config.ini
@@ -1,35 +1,26 @@
-;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
+;Connection Information
+[Http]
+http.ConnectionTimeOut = 30
+http.Retry = 1
+;http.Proxy=http://[username:password]@hostname[:port][/path]
+
+
+;Service Configuration
+[Service]
+mode=sandbox ; can be set to sandbox / live
+
+;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
\ No newline at end of file
diff --git a/sample/source/CreateCreditCard.html b/sample/source/CreateCreditCard.html
index 86eaa6f..23b4c92 100644
--- a/sample/source/CreateCreditCard.html
+++ b/sample/source/CreateCreditCard.html
@@ -7,42 +7,36 @@ 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;
+API used: POST /v1/vault/credit-card
require __DIR__ . '/../bootstrap.php';
+use PayPal\Api\CreditCard;
use PayPal\Api\Address;
$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");
$apiContext = new ApiContext($cred, 'Request' . time());
$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");
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>
+in the future payments.
+(See bootstrap.php for more on ApiContext)
try {
+ $card->create($apiContext);
+} 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>
\ No newline at end of file
diff --git a/sample/source/CreatePayment.html b/sample/source/CreatePayment.html
index 284662e..11c231e 100644
--- a/sample/source/CreatePayment.html
+++ b/sample/source/CreatePayment.html
@@ -2,89 +2,83 @@
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;
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;
$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");
+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");
$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");
+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);
$fi = new FundingInstrument();
+and the CreditCardDetails
$fi = new FundingInstrument();
$fi->setCredit_card($card);
$payer = new Payer();
-$payer->setPayment_method("credit_card");
+as 'credit_card'
$payer = new Payer();
+$payer->setPayment_method("credit_card");
$payer->setFunding_instruments(array($fi));
$amount = new Amount();
-
$amount->setCurrency("USD");
+
Let's you specify a payment amount.
$amount = new Amount();
+$amount->setCurrency("USD");
$amount->setTotal("1.00");
$transaction = new Transaction();
-$transaction->setAmount($amount);
+a Payee and Amount types
$transaction = new Transaction();
+$transaction->setAmount($amount);
$transaction->setDescription("This is the payment description.");
$payment = new Payment();
-$payment->setIntent("sale");
-$payment->setPayer($payer);
-$payment->setTransactions(array($transaction));
$apiContext = new ApiContext($cred, 'Request' . time());
$payment = new Payment();
+$payment->setIntent("sale");
+$payment->setPayer($payer);
+$payment->setTransactions(array($transaction));
try {
- $payment->create($apiContext);
-} catch (\PPConnectionException $ex) {
- echo "Exception: " . $ex->getMessage() . PHP_EOL;
- <pre><?php var_dump($card);?></pre>
- 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>
+using a valid ApiContext (See bootstrap.php for more on 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>
CreditCard
A resource representing a credit card that can be -used to fund a payment.