From e8e7ad807e3af44d914104ae82220987433a4d21 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Wed, 24 Apr 2013 17:13:47 +0530
Subject: [PATCH 1/7] Updating model classes to use dynamic config - Moving
common classes to sdk-core-php
---
composer.json | 4 +-
lib/PayPal/Api/Address.php | 10 +-
lib/PayPal/Api/Amount.php | 5 +-
lib/PayPal/Api/AmountDetails.php | 6 +-
lib/PayPal/Api/Authorization.php | 9 +-
lib/PayPal/Api/Capture.php | 11 +-
lib/PayPal/Api/CreditCard.php | 27 +-
lib/PayPal/Api/CreditCardToken.php | 4 +-
lib/PayPal/Api/FundingInstrument.php | 4 +-
lib/PayPal/Api/Item.php | 7 +-
lib/PayPal/Api/ItemList.php | 4 +-
lib/PayPal/Api/Link.php | 5 +-
lib/PayPal/Api/Payee.php | 5 +-
lib/PayPal/Api/Payer.php | 5 +-
lib/PayPal/Api/PayerInfo.php | 8 +-
lib/PayPal/Api/Payment.php | 35 ++-
lib/PayPal/Api/PaymentExecution.php | 4 +-
lib/PayPal/Api/PaymentHistory.php | 5 +-
lib/PayPal/Api/RedirectUrls.php | 4 +-
lib/PayPal/Api/Refund.php | 18 +-
lib/PayPal/Api/Resource.php | 6 +-
lib/PayPal/Api/Sale.php | 21 +-
lib/PayPal/Api/ShippingAddress.php | 3 +-
lib/PayPal/Api/SubTransaction.php | 6 +-
lib/PayPal/Api/Transaction.php | 7 +-
lib/PayPal/Auth/OAuthTokenCredential.php | 250 ++++++++--------
lib/PayPal/Common/ArrayUtil.php | 19 --
lib/PayPal/Common/Model.php | 88 ------
lib/PayPal/Common/ReflectionUtil.php | 73 -----
lib/PayPal/Common/UserAgent.php | 44 ---
lib/PayPal/Rest/ApiContext.php | 148 +++++-----
lib/PayPal/Rest/Call.php | 59 ----
lib/PayPal/Rest/RestHandler.php | 77 +++++
.../Test/Auth/OAuthTokenCredentialTest.php | 65 +++--
tests/PayPal/Test/Common/ArrayUtilTest.php | 43 ++-
tests/PayPal/Test/Common/ModelTest.php | 273 +++++++++---------
tests/PayPal/Test/Common/UserAgentTest.php | 47 +--
37 files changed, 676 insertions(+), 733 deletions(-)
delete mode 100644 lib/PayPal/Common/ArrayUtil.php
delete mode 100644 lib/PayPal/Common/Model.php
delete mode 100644 lib/PayPal/Common/ReflectionUtil.php
delete mode 100644 lib/PayPal/Common/UserAgent.php
delete mode 100644 lib/PayPal/Rest/Call.php
create mode 100644 lib/PayPal/Rest/RestHandler.php
diff --git a/composer.json b/composer.json
index 8cd0749..600041b 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,7 @@
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
- "paypal/sdk-core-php": "1.2.*"
+ "paypal/sdk-core-php": "dev-openidconnect"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
@@ -25,4 +25,4 @@
"PayPal": "lib/"
}
}
-}
\ No newline at end of file
+}
diff --git a/lib/PayPal/Api/Address.php b/lib/PayPal/Api/Address.php
index 70f0376..9ba7716 100644
--- a/lib/PayPal/Api/Address.php
+++ b/lib/PayPal/Api/Address.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Address extends Resource {
@@ -18,6 +18,7 @@ class Address extends Resource {
/**
* Getter for line1
+ * @return string
*/
public function getLine1() {
return $this->line1;
@@ -33,6 +34,7 @@ class Address extends Resource {
/**
* Getter for line2
+ * @return string
*/
public function getLine2() {
return $this->line2;
@@ -48,6 +50,7 @@ class Address extends Resource {
/**
* Getter for city
+ * @return string
*/
public function getCity() {
return $this->city;
@@ -63,6 +66,7 @@ class Address extends Resource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -78,6 +82,7 @@ class Address extends Resource {
/**
* Getter for postal_code
+ * @return string
*/
public function getPostal_code() {
return $this->postal_code;
@@ -93,6 +98,7 @@ class Address extends Resource {
/**
* Getter for country_code
+ * @return string
*/
public function getCountry_code() {
return $this->country_code;
@@ -108,6 +114,7 @@ class Address extends Resource {
/**
* Getter for type
+ * @return string
*/
public function getType() {
return $this->type;
@@ -123,6 +130,7 @@ class Address extends Resource {
/**
* Getter for phone
+ * @return string
*/
public function getPhone() {
return $this->phone;
diff --git a/lib/PayPal/Api/Amount.php b/lib/PayPal/Api/Amount.php
index ad7191d..673c14b 100644
--- a/lib/PayPal/Api/Amount.php
+++ b/lib/PayPal/Api/Amount.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Amount extends Resource {
@@ -18,6 +18,7 @@ class Amount extends Resource {
/**
* Getter for total
+ * @return string
*/
public function getTotal() {
return $this->total;
@@ -33,6 +34,7 @@ class Amount extends Resource {
/**
* Getter for currency
+ * @return string
*/
public function getCurrency() {
return $this->currency;
@@ -48,6 +50,7 @@ class Amount extends Resource {
/**
* Getter for details
+ * @return PayPal\Api\AmountDetails
*/
public function getDetails() {
return $this->details;
diff --git a/lib/PayPal/Api/AmountDetails.php b/lib/PayPal/Api/AmountDetails.php
index 65e5a33..96b8a9b 100644
--- a/lib/PayPal/Api/AmountDetails.php
+++ b/lib/PayPal/Api/AmountDetails.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class AmountDetails extends Resource {
@@ -18,6 +18,7 @@ class AmountDetails extends Resource {
/**
* Getter for subtotal
+ * @return string
*/
public function getSubtotal() {
return $this->subtotal;
@@ -33,6 +34,7 @@ class AmountDetails extends Resource {
/**
* Getter for tax
+ * @return string
*/
public function getTax() {
return $this->tax;
@@ -48,6 +50,7 @@ class AmountDetails extends Resource {
/**
* Getter for shipping
+ * @return string
*/
public function getShipping() {
return $this->shipping;
@@ -63,6 +66,7 @@ class AmountDetails extends Resource {
/**
* Getter for fee
+ * @return string
*/
public function getFee() {
return $this->fee;
diff --git a/lib/PayPal/Api/Authorization.php b/lib/PayPal/Api/Authorization.php
index 3b4b82c..b7602da 100644
--- a/lib/PayPal/Api/Authorization.php
+++ b/lib/PayPal/Api/Authorization.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Authorization extends Resource {
@@ -18,6 +18,7 @@ class Authorization extends Resource {
/**
* Getter for id
+ * @return string
*/
public function getId() {
return $this->id;
@@ -33,6 +34,7 @@ class Authorization extends Resource {
/**
* Getter for create_time
+ * @return string
*/
public function getCreate_time() {
return $this->create_time;
@@ -48,6 +50,7 @@ class Authorization extends Resource {
/**
* Getter for update_time
+ * @return string
*/
public function getUpdate_time() {
return $this->update_time;
@@ -63,6 +66,7 @@ class Authorization extends Resource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -78,6 +82,7 @@ class Authorization extends Resource {
/**
* Getter for amount
+ * @return PayPal\Api\Amount
*/
public function getAmount() {
return $this->amount;
@@ -93,6 +98,7 @@ class Authorization extends Resource {
/**
* Getter for parent_payment
+ * @return string
*/
public function getParent_payment() {
return $this->parent_payment;
@@ -108,6 +114,7 @@ class Authorization extends Resource {
/**
* Getter for links
+ * @return PayPal\Api\Link
*/
public function getLinks() {
return $this->links;
diff --git a/lib/PayPal/Api/Capture.php b/lib/PayPal/Api/Capture.php
index 3c36e5a..c34e37d 100644
--- a/lib/PayPal/Api/Capture.php
+++ b/lib/PayPal/Api/Capture.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Capture extends Resource {
@@ -18,6 +18,7 @@ class Capture extends Resource {
/**
* Getter for id
+ * @return string
*/
public function getId() {
return $this->id;
@@ -33,6 +34,7 @@ class Capture extends Resource {
/**
* Getter for create_time
+ * @return string
*/
public function getCreate_time() {
return $this->create_time;
@@ -48,6 +50,7 @@ class Capture extends Resource {
/**
* Getter for update_time
+ * @return string
*/
public function getUpdate_time() {
return $this->update_time;
@@ -63,6 +66,7 @@ class Capture extends Resource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -78,6 +82,7 @@ class Capture extends Resource {
/**
* Getter for amount
+ * @return PayPal\Api\Amount
*/
public function getAmount() {
return $this->amount;
@@ -93,6 +98,7 @@ class Capture extends Resource {
/**
* Getter for parent_payment
+ * @return string
*/
public function getParent_payment() {
return $this->parent_payment;
@@ -108,6 +114,7 @@ class Capture extends Resource {
/**
* Getter for authorization_id
+ * @return string
*/
public function getAuthorization_id() {
return $this->authorization_id;
@@ -123,6 +130,7 @@ class Capture extends Resource {
/**
* Getter for description
+ * @return string
*/
public function getDescription() {
return $this->description;
@@ -138,6 +146,7 @@ class Capture extends Resource {
/**
* Getter for links
+ * @return PayPal\Api\Link
*/
public function getLinks() {
return $this->links;
diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php
index 7486242..424cb81 100644
--- a/lib/PayPal/Api/CreditCard.php
+++ b/lib/PayPal/Api/CreditCard.php
@@ -6,7 +6,7 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
- *
+ *
*/
class CreditCard extends Resource implements IResource {
@@ -26,6 +26,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for id
+ * @return string
*/
public function getId() {
return $this->id;
@@ -41,6 +42,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for valid_until
+ * @return string
*/
public function getValid_until() {
return $this->valid_until;
@@ -56,6 +58,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -71,6 +74,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for payer_id
+ * @return string
*/
public function getPayer_id() {
return $this->payer_id;
@@ -86,6 +90,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for type
+ * @return string
*/
public function getType() {
return $this->type;
@@ -101,6 +106,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for number
+ * @return string
*/
public function getNumber() {
return $this->number;
@@ -116,6 +122,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for expire_month
+ * @return string
*/
public function getExpire_month() {
return $this->expire_month;
@@ -131,6 +138,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for expire_year
+ * @return string
*/
public function getExpire_year() {
return $this->expire_year;
@@ -146,6 +154,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for cvv2
+ * @return string
*/
public function getCvv2() {
return $this->cvv2;
@@ -161,6 +170,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for first_name
+ * @return string
*/
public function getFirst_name() {
return $this->first_name;
@@ -176,6 +186,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for last_name
+ * @return string
*/
public function getLast_name() {
return $this->last_name;
@@ -191,6 +202,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for billing_address
+ * @return PayPal\Api\Address
*/
public function getBilling_address() {
return $this->billing_address;
@@ -206,6 +218,7 @@ class CreditCard extends Resource implements IResource {
/**
* Getter for links
+ * @return PayPal\Api\Link
*/
public function getLinks() {
return $this->links;
@@ -224,8 +237,10 @@ class CreditCard extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new Call();
- $json = $call->execute("/v1/vault/credit-card", "POST", $payLoad, $apiContext);
+ $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/vault/credit-card",
+ "POST", $payLoad);
$this->fromJson($json);
return $this;
}
@@ -241,8 +256,10 @@ class CreditCard extends Resource implements IResource {
}
$payLoad = "";
- $apiContext = new ApiContext(self::$credential); $call = new Call();
- $json = $call->execute("/v1/vault/credit-card/$creditcardid", "GET", $payLoad, $apiContext);
+ $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/vault/credit-card/$creditcardid",
+ "GET", $payLoad);
$ret = new CreditCard();
$ret->fromJson($json);
return $ret;
diff --git a/lib/PayPal/Api/CreditCardToken.php b/lib/PayPal/Api/CreditCardToken.php
index 7ca48f1..0dae9e6 100644
--- a/lib/PayPal/Api/CreditCardToken.php
+++ b/lib/PayPal/Api/CreditCardToken.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class CreditCardToken extends Resource {
@@ -18,6 +18,7 @@ class CreditCardToken extends Resource {
/**
* Getter for credit_card_id
+ * @return string
*/
public function getCredit_card_id() {
return $this->credit_card_id;
@@ -33,6 +34,7 @@ class CreditCardToken extends Resource {
/**
* Getter for payer_id
+ * @return string
*/
public function getPayer_id() {
return $this->payer_id;
diff --git a/lib/PayPal/Api/FundingInstrument.php b/lib/PayPal/Api/FundingInstrument.php
index 7fc07a0..0379245 100644
--- a/lib/PayPal/Api/FundingInstrument.php
+++ b/lib/PayPal/Api/FundingInstrument.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class FundingInstrument extends Resource {
@@ -18,6 +18,7 @@ class FundingInstrument extends Resource {
/**
* Getter for credit_card
+ * @return PayPal\Api\CreditCard
*/
public function getCredit_card() {
return $this->credit_card;
@@ -33,6 +34,7 @@ class FundingInstrument extends Resource {
/**
* Getter for credit_card_token
+ * @return PayPal\Api\CreditCardToken
*/
public function getCredit_card_token() {
return $this->credit_card_token;
diff --git a/lib/PayPal/Api/Item.php b/lib/PayPal/Api/Item.php
index 7d547ae..1e88ebb 100644
--- a/lib/PayPal/Api/Item.php
+++ b/lib/PayPal/Api/Item.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Item extends Resource {
@@ -18,6 +18,7 @@ class Item extends Resource {
/**
* Getter for name
+ * @return string
*/
public function getName() {
return $this->name;
@@ -33,6 +34,7 @@ class Item extends Resource {
/**
* Getter for sku
+ * @return string
*/
public function getSku() {
return $this->sku;
@@ -48,6 +50,7 @@ class Item extends Resource {
/**
* Getter for price
+ * @return string
*/
public function getPrice() {
return $this->price;
@@ -63,6 +66,7 @@ class Item extends Resource {
/**
* Getter for currency
+ * @return string
*/
public function getCurrency() {
return $this->currency;
@@ -78,6 +82,7 @@ class Item extends Resource {
/**
* Getter for quantity
+ * @return string
*/
public function getQuantity() {
return $this->quantity;
diff --git a/lib/PayPal/Api/ItemList.php b/lib/PayPal/Api/ItemList.php
index 2c7fe18..232856e 100644
--- a/lib/PayPal/Api/ItemList.php
+++ b/lib/PayPal/Api/ItemList.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class ItemList extends Resource {
@@ -18,6 +18,7 @@ class ItemList extends Resource {
/**
* Getter for items
+ * @return PayPal\Api\Item
*/
public function getItems() {
return $this->items;
@@ -33,6 +34,7 @@ class ItemList extends Resource {
/**
* Getter for shipping_address
+ * @return PayPal\Api\ShippingAddress
*/
public function getShipping_address() {
return $this->shipping_address;
diff --git a/lib/PayPal/Api/Link.php b/lib/PayPal/Api/Link.php
index 643c95c..01ac708 100644
--- a/lib/PayPal/Api/Link.php
+++ b/lib/PayPal/Api/Link.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Link extends Resource {
@@ -18,6 +18,7 @@ class Link extends Resource {
/**
* Getter for href
+ * @return string
*/
public function getHref() {
return $this->href;
@@ -33,6 +34,7 @@ class Link extends Resource {
/**
* Getter for rel
+ * @return string
*/
public function getRel() {
return $this->rel;
@@ -48,6 +50,7 @@ class Link extends Resource {
/**
* Getter for method
+ * @return string
*/
public function getMethod() {
return $this->method;
diff --git a/lib/PayPal/Api/Payee.php b/lib/PayPal/Api/Payee.php
index ab3cba3..eb33dea 100644
--- a/lib/PayPal/Api/Payee.php
+++ b/lib/PayPal/Api/Payee.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Payee extends Resource {
@@ -18,6 +18,7 @@ class Payee extends Resource {
/**
* Getter for merchant_id
+ * @return string
*/
public function getMerchant_id() {
return $this->merchant_id;
@@ -33,6 +34,7 @@ class Payee extends Resource {
/**
* Getter for email
+ * @return string
*/
public function getEmail() {
return $this->email;
@@ -48,6 +50,7 @@ class Payee extends Resource {
/**
* Getter for phone
+ * @return string
*/
public function getPhone() {
return $this->phone;
diff --git a/lib/PayPal/Api/Payer.php b/lib/PayPal/Api/Payer.php
index f083087..c1fe6f2 100644
--- a/lib/PayPal/Api/Payer.php
+++ b/lib/PayPal/Api/Payer.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Payer extends Resource {
@@ -18,6 +18,7 @@ class Payer extends Resource {
/**
* Getter for payment_method
+ * @return string
*/
public function getPayment_method() {
return $this->payment_method;
@@ -33,6 +34,7 @@ class Payer extends Resource {
/**
* Getter for payer_info
+ * @return PayPal\Api\PayerInfo
*/
public function getPayer_info() {
return $this->payer_info;
@@ -48,6 +50,7 @@ class Payer extends Resource {
/**
* Getter for funding_instruments
+ * @return PayPal\Api\FundingInstrument
*/
public function getFunding_instruments() {
return $this->funding_instruments;
diff --git a/lib/PayPal/Api/PayerInfo.php b/lib/PayPal/Api/PayerInfo.php
index 5d6a108..fe1af5c 100644
--- a/lib/PayPal/Api/PayerInfo.php
+++ b/lib/PayPal/Api/PayerInfo.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class PayerInfo extends Resource {
@@ -18,6 +18,7 @@ class PayerInfo extends Resource {
/**
* Getter for email
+ * @return string
*/
public function getEmail() {
return $this->email;
@@ -33,6 +34,7 @@ class PayerInfo extends Resource {
/**
* Getter for first_name
+ * @return string
*/
public function getFirst_name() {
return $this->first_name;
@@ -48,6 +50,7 @@ class PayerInfo extends Resource {
/**
* Getter for last_name
+ * @return string
*/
public function getLast_name() {
return $this->last_name;
@@ -63,6 +66,7 @@ class PayerInfo extends Resource {
/**
* Getter for payer_id
+ * @return string
*/
public function getPayer_id() {
return $this->payer_id;
@@ -78,6 +82,7 @@ class PayerInfo extends Resource {
/**
* Getter for shipping_address
+ * @return PayPal\Api\Address
*/
public function getShipping_address() {
return $this->shipping_address;
@@ -93,6 +98,7 @@ class PayerInfo extends Resource {
/**
* Getter for phone
+ * @return string
*/
public function getPhone() {
return $this->phone;
diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php
index a736b59..fc71a30 100644
--- a/lib/PayPal/Api/Payment.php
+++ b/lib/PayPal/Api/Payment.php
@@ -6,7 +6,7 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
- *
+ *
*/
class Payment extends Resource implements IResource {
@@ -26,6 +26,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for id
+ * @return string
*/
public function getId() {
return $this->id;
@@ -41,6 +42,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for create_time
+ * @return string
*/
public function getCreate_time() {
return $this->create_time;
@@ -56,6 +58,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for update_time
+ * @return string
*/
public function getUpdate_time() {
return $this->update_time;
@@ -71,6 +74,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -86,6 +90,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for intent
+ * @return string
*/
public function getIntent() {
return $this->intent;
@@ -101,6 +106,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for payer
+ * @return PayPal\Api\Payer
*/
public function getPayer() {
return $this->payer;
@@ -116,6 +122,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for transactions
+ * @return PayPal\Api\Transaction
*/
public function getTransactions() {
return $this->transactions;
@@ -131,6 +138,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for redirect_urls
+ * @return PayPal\Api\RedirectUrls
*/
public function getRedirect_urls() {
return $this->redirect_urls;
@@ -146,6 +154,7 @@ class Payment extends Resource implements IResource {
/**
* Getter for links
+ * @return PayPal\Api\Link
*/
public function getLinks() {
return $this->links;
@@ -173,8 +182,10 @@ class Payment extends Resource implements IResource {
$payLoad = "";
$allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
- $apiContext = new ApiContext(self::$credential); $call = new Call();
- $json = $call->execute("/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad, $apiContext);
+ $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)),
+ "GET", $payLoad);
$ret = new PaymentHistory();
$ret->fromJson($json);
return $ret;
@@ -192,8 +203,10 @@ class Payment extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new Call();
- $json = $call->execute("/v1/payments/payment", "POST", $payLoad, $apiContext);
+ $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/payment",
+ "POST", $payLoad);
$this->fromJson($json);
return $this;
}
@@ -209,8 +222,10 @@ class Payment extends Resource implements IResource {
}
$payLoad = "";
- $apiContext = new ApiContext(self::$credential); $call = new Call();
- $json = $call->execute("/v1/payments/payment/$paymentid", "GET", $payLoad, $apiContext);
+ $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/payment/$paymentid",
+ "GET", $payLoad);
$ret = new Payment();
$ret->fromJson($json);
return $ret;
@@ -234,8 +249,10 @@ class Payment extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new Call();
- $json = $call->execute("/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad, $apiContext);
+ $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/payment/{$this->getId()}/execute",
+ "POST", $payLoad);
$this->fromJson($json);
return $this;
}
diff --git a/lib/PayPal/Api/PaymentExecution.php b/lib/PayPal/Api/PaymentExecution.php
index b095a96..4de31a5 100644
--- a/lib/PayPal/Api/PaymentExecution.php
+++ b/lib/PayPal/Api/PaymentExecution.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class PaymentExecution extends Resource {
@@ -18,6 +18,7 @@ class PaymentExecution extends Resource {
/**
* Getter for payer_id
+ * @return string
*/
public function getPayer_id() {
return $this->payer_id;
@@ -33,6 +34,7 @@ class PaymentExecution extends Resource {
/**
* Getter for transactions
+ * @return PayPal\Api\Amount
*/
public function getTransactions() {
return $this->transactions;
diff --git a/lib/PayPal/Api/PaymentHistory.php b/lib/PayPal/Api/PaymentHistory.php
index de232c3..98735de 100644
--- a/lib/PayPal/Api/PaymentHistory.php
+++ b/lib/PayPal/Api/PaymentHistory.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class PaymentHistory extends Resource {
@@ -18,6 +18,7 @@ class PaymentHistory extends Resource {
/**
* Getter for payments
+ * @return PayPal\Api\Payment
*/
public function getPayments() {
return $this->payments;
@@ -33,6 +34,7 @@ class PaymentHistory extends Resource {
/**
* Getter for count
+ * @return integer
*/
public function getCount() {
return $this->count;
@@ -48,6 +50,7 @@ class PaymentHistory extends Resource {
/**
* Getter for next_id
+ * @return string
*/
public function getNext_id() {
return $this->next_id;
diff --git a/lib/PayPal/Api/RedirectUrls.php b/lib/PayPal/Api/RedirectUrls.php
index 2a92f8c..99ffb04 100644
--- a/lib/PayPal/Api/RedirectUrls.php
+++ b/lib/PayPal/Api/RedirectUrls.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class RedirectUrls extends Resource {
@@ -18,6 +18,7 @@ class RedirectUrls extends Resource {
/**
* Getter for return_url
+ * @return string
*/
public function getReturn_url() {
return $this->return_url;
@@ -33,6 +34,7 @@ class RedirectUrls extends Resource {
/**
* Getter for cancel_url
+ * @return string
*/
public function getCancel_url() {
return $this->cancel_url;
diff --git a/lib/PayPal/Api/Refund.php b/lib/PayPal/Api/Refund.php
index 93b14a2..cb52e26 100644
--- a/lib/PayPal/Api/Refund.php
+++ b/lib/PayPal/Api/Refund.php
@@ -6,7 +6,7 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
- *
+ *
*/
class Refund extends Resource implements IResource {
@@ -26,6 +26,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for id
+ * @return string
*/
public function getId() {
return $this->id;
@@ -41,6 +42,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for create_time
+ * @return string
*/
public function getCreate_time() {
return $this->create_time;
@@ -56,6 +58,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for update_time
+ * @return string
*/
public function getUpdate_time() {
return $this->update_time;
@@ -71,6 +74,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -86,6 +90,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for amount
+ * @return PayPal\Api\Amount
*/
public function getAmount() {
return $this->amount;
@@ -101,6 +106,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for sale_id
+ * @return string
*/
public function getSale_id() {
return $this->sale_id;
@@ -116,6 +122,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for capture_id
+ * @return string
*/
public function getCapture_id() {
return $this->capture_id;
@@ -131,6 +138,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for parent_payment
+ * @return string
*/
public function getParent_payment() {
return $this->parent_payment;
@@ -146,6 +154,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for description
+ * @return string
*/
public function getDescription() {
return $this->description;
@@ -161,6 +170,7 @@ class Refund extends Resource implements IResource {
/**
* Getter for links
+ * @return PayPal\Api\Link
*/
public function getLinks() {
return $this->links;
@@ -179,8 +189,10 @@ class Refund extends Resource implements IResource {
}
$payLoad = "";
- $apiContext = new ApiContext(self::$credential); $call = new Call();
- $json = $call->execute("/v1/payments/refund/$refundid", "GET", $payLoad, $apiContext);
+ $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/refund/$refundid",
+ "GET", $payLoad);
$ret = new Refund();
$ret->fromJson($json);
return $ret;
diff --git a/lib/PayPal/Api/Resource.php b/lib/PayPal/Api/Resource.php
index 825384a..725b01c 100644
--- a/lib/PayPal/Api/Resource.php
+++ b/lib/PayPal/Api/Resource.php
@@ -1,12 +1,10 @@
id;
@@ -41,6 +42,7 @@ class Sale extends Resource implements IResource {
/**
* Getter for create_time
+ * @return string
*/
public function getCreate_time() {
return $this->create_time;
@@ -56,6 +58,7 @@ class Sale extends Resource implements IResource {
/**
* Getter for update_time
+ * @return string
*/
public function getUpdate_time() {
return $this->update_time;
@@ -71,6 +74,7 @@ class Sale extends Resource implements IResource {
/**
* Getter for state
+ * @return string
*/
public function getState() {
return $this->state;
@@ -86,6 +90,7 @@ class Sale extends Resource implements IResource {
/**
* Getter for amount
+ * @return PayPal\Api\Amount
*/
public function getAmount() {
return $this->amount;
@@ -101,6 +106,7 @@ class Sale extends Resource implements IResource {
/**
* Getter for parent_payment
+ * @return string
*/
public function getParent_payment() {
return $this->parent_payment;
@@ -116,6 +122,7 @@ class Sale extends Resource implements IResource {
/**
* Getter for links
+ * @return PayPal\Api\Link
*/
public function getLinks() {
return $this->links;
@@ -134,8 +141,10 @@ class Sale extends Resource implements IResource {
}
$payLoad = "";
- $apiContext = new ApiContext(self::$credential); $call = new Call();
- $json = $call->execute("/v1/payments/sale/$saleid", "GET", $payLoad, $apiContext);
+ $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/sale/$saleid",
+ "GET", $payLoad);
$ret = new Sale();
$ret->fromJson($json);
return $ret;
@@ -159,8 +168,10 @@ class Sale extends Resource implements IResource {
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
- $call = new Call();
- $json = $call->execute("/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad, $apiContext);
+ $call = new \PPRestCall();
+ $json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
+ "/v1/payments/sale/{$this->getId()}/refund",
+ "POST", $payLoad);
$this->fromJson($json);
return $this;
}
diff --git a/lib/PayPal/Api/ShippingAddress.php b/lib/PayPal/Api/ShippingAddress.php
index 798df69..80252b6 100644
--- a/lib/PayPal/Api/ShippingAddress.php
+++ b/lib/PayPal/Api/ShippingAddress.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class ShippingAddress extends Address {
@@ -18,6 +18,7 @@ class ShippingAddress extends Address {
/**
* Getter for recipient_name
+ * @return string
*/
public function getRecipient_name() {
return $this->recipient_name;
diff --git a/lib/PayPal/Api/SubTransaction.php b/lib/PayPal/Api/SubTransaction.php
index 4e92a09..7afc5c3 100644
--- a/lib/PayPal/Api/SubTransaction.php
+++ b/lib/PayPal/Api/SubTransaction.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class SubTransaction extends Resource {
@@ -18,6 +18,7 @@ class SubTransaction extends Resource {
/**
* Getter for sale
+ * @return PayPal\Api\Sale
*/
public function getSale() {
return $this->sale;
@@ -33,6 +34,7 @@ class SubTransaction extends Resource {
/**
* Getter for authorization
+ * @return PayPal\Api\Authorization
*/
public function getAuthorization() {
return $this->authorization;
@@ -48,6 +50,7 @@ class SubTransaction extends Resource {
/**
* Getter for refund
+ * @return PayPal\Api\Refund
*/
public function getRefund() {
return $this->refund;
@@ -63,6 +66,7 @@ class SubTransaction extends Resource {
/**
* Getter for capture
+ * @return PayPal\Api\Capture
*/
public function getCapture() {
return $this->capture;
diff --git a/lib/PayPal/Api/Transaction.php b/lib/PayPal/Api/Transaction.php
index f5857a5..d3749d0 100644
--- a/lib/PayPal/Api/Transaction.php
+++ b/lib/PayPal/Api/Transaction.php
@@ -3,7 +3,7 @@
namespace PayPal\Api;
/**
- *
+ *
*/
class Transaction extends Resource {
@@ -18,6 +18,7 @@ class Transaction extends Resource {
/**
* Getter for amount
+ * @return PayPal\Api\Amount
*/
public function getAmount() {
return $this->amount;
@@ -33,6 +34,7 @@ class Transaction extends Resource {
/**
* Getter for payee
+ * @return PayPal\Api\Payee
*/
public function getPayee() {
return $this->payee;
@@ -48,6 +50,7 @@ class Transaction extends Resource {
/**
* Getter for description
+ * @return string
*/
public function getDescription() {
return $this->description;
@@ -63,6 +66,7 @@ class Transaction extends Resource {
/**
* Getter for item_list
+ * @return PayPal\Api\ItemList
*/
public function getItem_list() {
return $this->item_list;
@@ -78,6 +82,7 @@ class Transaction extends Resource {
/**
* Getter for related_resources
+ * @return PayPal\Api\SubTransaction
*/
public function getRelated_resources() {
return $this->related_resources;
diff --git a/lib/PayPal/Auth/OAuthTokenCredential.php b/lib/PayPal/Auth/OAuthTokenCredential.php
index cd28348..96e49c7 100644
--- a/lib/PayPal/Auth/OAuthTokenCredential.php
+++ b/lib/PayPal/Auth/OAuthTokenCredential.php
@@ -1,118 +1,132 @@
-clientId = $clientId;
- $this->clientSecret = $clientSecret;
- $this->logger = new \PPLoggingManager(__CLASS__);
- }
-
- /**
- * @return the accessToken
- */
- public function getAccessToken() {
- // 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
- // for API call delays and any delay between the time the token is
- // retrieved and subsequently used
- if ($this->accessToken != null &&
- (time() - $this->tokenCreateTime) > ($this->tokenExpiresIn - self::$expiryBufferTime)) {
- $this->accessToken = null;
- }
- // If accessToken is Null, obtain a new token
- if ($this->accessToken == null) {
- $this->generateAccessToken();
- }
- return $this->accessToken;
- }
-
- /**
- * Generates a new access token
- */
- private function generateAccessToken() {
- return $this->generateOAuthToken(base64_encode($this->clientId . ":" . $this->clientSecret));
- }
-
- /**
- * Generate OAuth type token from Base64Client ID
- */
- private function generateOAuthToken($base64ClientID) {
-
- $headers = array(
- "Authorization" => "Basic " . $base64ClientID,
- "Accept" => "*/*"
- );
- $httpConfiguration = $this->getOAuthHttpConfiguration();
- $httpConfiguration->setHeaders($headers);
-
- $connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration);
- $res = $connection->execute("grant_type=client_credentials");
- $jsonResponse = json_decode($res, true);
- if($jsonResponse == NULL ||
- !isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) {
- $this->accessToken = NULL;
- $this->tokenExpiresIn = NULL;
- $this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);
- } else {
- $this->accessToken = $jsonResponse["access_token"];
- $this->tokenExpiresIn = $jsonResponse["expires_in"];
- }
- $this->tokenCreateTime = time();
- return $this->accessToken;
- }
-
- /*
- * Get HttpConfiguration object for OAuth API
- */
- private function getOAuthHttpConfiguration() {
- $configMgr = \PPConfigManager::getInstance();
-
- $baseEndpoint = ($configMgr->get("oauth.EndPoint") != '' && !is_array($configMgr->get("oauth.EndPoint"))) ?
- $configMgr->get("oauth.EndPoint") : $configMgr->get("service.EndPoint");
- $baseEndpoint = rtrim(trim($baseEndpoint), '/');
- return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST");
- }
-}
+clientId = $clientId;
+ $this->clientSecret = $clientSecret;
+ $this->logger = new \PPLoggingManager(__CLASS__);
+ }
+
+ /**
+ * @return the accessToken
+ */
+ public function getAccessToken($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
+ // for API call delays and any delay between the time the token is
+ // retrieved and subsequently used
+ if ($this->accessToken != null &&
+ (time() - $this->tokenCreateTime) > ($this->tokenExpiresIn - self::$expiryBufferTime)) {
+ $this->accessToken = null;
+ }
+ // If accessToken is Null, obtain a new token
+ if ($this->accessToken == null) {
+ $this->_generateAccessToken($config);
+ }
+ return $this->accessToken;
+ }
+
+ /**
+ * Generates a new access token
+ */
+ private function _generateAccessToken($config) {
+
+ $base64ClientID = base64_encode($this->clientId . ":" . $this->clientSecret);
+ $headers = array(
+ "User-Agent" => \PPUserAgent::getValue(RestHandler::$sdkName, RestHandler::$sdkVersion),
+ "Authorization" => "Basic " . $base64ClientID,
+ "Accept" => "*/*"
+ );
+ $httpConfiguration = $this->getOAuthHttpConfiguration($config);
+ $httpConfiguration->setHeaders($headers);
+
+ $connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration, $config);
+ $res = $connection->execute("grant_type=client_credentials");
+ $jsonResponse = json_decode($res, true);
+ if($jsonResponse == NULL ||
+ !isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) {
+ $this->accessToken = NULL;
+ $this->tokenExpiresIn = NULL;
+ $this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);
+ } else {
+ $this->accessToken = $jsonResponse["access_token"];
+ $this->tokenExpiresIn = $jsonResponse["expires_in"];
+ }
+ $this->tokenCreateTime = time();
+ return $this->accessToken;
+ }
+
+ /*
+ * Get HttpConfiguration object for OAuth API
+ */
+ private function getOAuthHttpConfiguration($config) {
+ if (isset($config['oauth.EndPoint'])) {
+ $baseEndpoint = $config['oauth.EndPoint'];
+ } else if (isset($config['service.EndPoint'])) {
+ $baseEndpoint = $config['service.EndPoint'];
+ } else if (isset($config['mode'])) {
+ switch (strtoupper($config['mode'])) {
+ case 'SANDBOX':
+ $baseEndpoint = \PPConstants::REST_SANDBOX_ENDPOINT;
+ break;
+ case 'LIVE':
+ $baseEndpoint = \PPConstants::REST_LIVE_ENDPOINT;
+ break;
+ default:
+ throw new \PPConfigurationException('The mode config parameter must be set to either sandbox/live');
+ }
+ } else {
+ throw new PPConfigurationException('You must set one of service.endpoint or mode parameters in your configuration');
+ }
+
+ $baseEndpoint = rtrim(trim($baseEndpoint), '/');
+ return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST");
+ }
+}
diff --git a/lib/PayPal/Common/ArrayUtil.php b/lib/PayPal/Common/ArrayUtil.php
deleted file mode 100644
index 315a2e4..0000000
--- a/lib/PayPal/Common/ArrayUtil.php
+++ /dev/null
@@ -1,19 +0,0 @@
- $v) {
- if(is_int($k)) {
- return false;
- }
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/lib/PayPal/Common/Model.php b/lib/PayPal/Common/Model.php
deleted file mode 100644
index ff72c52..0000000
--- a/lib/PayPal/Common/Model.php
+++ /dev/null
@@ -1,88 +0,0 @@
-_propMap[$key];
- }
-
- public function __set($key, $value) {
- $this->_propMap[$key] = $value;
- }
-
- public function __isset($key) {
- return isset($this->_propMap[$key]);
- }
-
- public function __unset($key) {
- unset($this->_propMap[$key]);
- }
-
-
- private function _convertToArray($param) {
- $ret = array();
- foreach($param as $k => $v) {
- if($v instanceof Model ) {
- $ret[$k] = $v->toArray();
- } else if (is_array($v)) {
- $ret[$k] = $this->_convertToArray($v);
- } else {
- $ret[$k] = $v;
- }
- }
- return $ret;
- }
-
- public function fromArray($arr) {
-
- foreach($arr as $k => $v) {
- if(is_array($v)) {
- $clazz = ReflectionUtil::getPropertyClass(get_class($this), $k);
- if(ArrayUtil::isAssocArray($v)) {
- $o = new $clazz();
- $o->fromArray($v);
- $setterFunc = "set".ucfirst($k);
- $this->$setterFunc($o);
- } else {
- $setterFunc = "set".ucfirst($k);
- $arr = array();
- foreach($v as $nk => $nv) {
- if(is_array($nv)) {
- $o = new $clazz();
- $o->fromArray($nv);
- $arr[$nk] = $o;
- } else {
- $arr[$nk] = $nv;
- }
- }
- $this->$setterFunc($arr); //TODO: Cleaning up any current values in this case. Should be doing this allways
- }
- }else {
- $this->$k = $v;
- }
- }
- }
-
- public function fromJson($json) {
- $this->fromArray(json_decode($json, true));
- }
-
- public function toArray() {
- return $this->_convertToArray($this->_propMap);
- }
-
- public function toJSON() {
- return json_encode($this->toArray());
- }
-}
\ No newline at end of file
diff --git a/lib/PayPal/Common/ReflectionUtil.php b/lib/PayPal/Common/ReflectionUtil.php
deleted file mode 100644
index 3aa0fcd..0000000
--- a/lib/PayPal/Common/ReflectionUtil.php
+++ /dev/null
@@ -1,73 +0,0 @@
-getDocComment(), $annots, PREG_PATTERN_ORDER)) {
- return NULL;
- }
- foreach ($annots[1] as $i => $annot) {
- $annotations[strtolower($annot)] = empty($annots[2][$i]) ? TRUE : rtrim($annots[2][$i], " \t\n\r)");
- }
-
- return $annotations;
- }
-}
\ No newline at end of file
diff --git a/lib/PayPal/Common/UserAgent.php b/lib/PayPal/Common/UserAgent.php
deleted file mode 100644
index 99edf16..0000000
--- a/lib/PayPal/Common/UserAgent.php
+++ /dev/null
@@ -1,44 +0,0 @@
-credential;
- }
-
- public function getrequestId() {
- if($this->requestId == null) {
- $this->requestId = $this->generaterequestId();
- }
- return $this->requestId;
- }
-
- /**
- *
- * @param PayPal/Api/OAuthTokenCredential $credential
- * @param string $requestId
- */
- public function __construct($credential, $requestId=null) {
- $this->credential = $credential;
- $this->requestId = $requestId;
- }
-
- /**
- * Generates a unique per request id that
- * can be used to set the PayPal-Request-Id header
- * that is used for idemptency
- * @return string
- */
- private function generateRequestId() {
-
- static $pid = -1;
- static $addr = -1;
-
- if ($pid == -1) {
- $pid = getmypid();
- }
- if ($addr == -1) {
- if(array_key_exists('SERVER_ADDR', $_SERVER)) {
- $addr = ip2long($_SERVER['SERVER_ADDR']);
- } else {
- $addr = php_uname('n');
- }
- }
-
- return $addr . $pid . $_SERVER['REQUEST_TIME'] . mt_rand(0, 0xffff);
- }
-}
+credential;
+ }
+
+ public function getrequestId() {
+ if($this->requestId == null) {
+ $this->requestId = $this->generateRequestId();
+ }
+ return $this->requestId;
+ }
+
+
+ /**
+ *
+ * @param PayPal/Api/OAuthTokenCredential $credential
+ * @param string $requestId
+ */
+ public function __construct($credential, $requestId=null) {
+ $this->credential = $credential;
+ $this->requestId = $requestId;
+ }
+
+ /**
+ * Generates a unique per request id that
+ * can be used to set the PayPal-Request-Id header
+ * that is used for idemptency
+ * @return string
+ */
+ private function generateRequestId() {
+
+ static $pid = -1;
+ static $addr = -1;
+
+ if ($pid == -1) {
+ $pid = getmypid();
+ }
+ if ($addr == -1) {
+ if(array_key_exists('SERVER_ADDR', $_SERVER)) {
+ $addr = ip2long($_SERVER['SERVER_ADDR']);
+ } else {
+ $addr = php_uname('n');
+ }
+ }
+
+ return $addr . $pid . $_SERVER['REQUEST_TIME'] . mt_rand(0, 0xffff);
+ }
+}
diff --git a/lib/PayPal/Rest/Call.php b/lib/PayPal/Rest/Call.php
deleted file mode 100644
index 2a1fceb..0000000
--- a/lib/PayPal/Rest/Call.php
+++ /dev/null
@@ -1,59 +0,0 @@
-logger = new \PPLoggingManager(__CLASS__);
- }
-
- /**
- *
- * @param string $path
- * @param string $data
- * @param PayPal/Rest/ApiContext $apiContext
- * @param array $headers
- */
- public function execute($path, $method, $data='', $apiContext, $headers=array()) {
- $configMgr = \PPConfigManager::getInstance();
-
- $credential = $apiContext->getCredential();
- if($credential == NULL) {
- // Try picking credentials from the config file
- $credMgr = \PPCredentialManager::getInstance();
- $credValues = $credMgr->getCredentialObject();
- if(!is_array($credValues)) {
- throw new \PPMissingCredentialException("Empty or invalid credentials passed");
- }
- $credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
- }
- if($credential == NULL || ! ($credential instanceof OAuthTokenCredential) ) {
- throw new \PPInvalidCredentialException("Invalid credentials passed");
- }
-
- $resourceUrl = rtrim( trim($configMgr->get('service.EndPoint')), '/') . $path;
- $config = new \PPHttpConfig($resourceUrl, $method);
- $headers += array(
- 'Content-Type' => 'application/json',
- 'User-Agent' => UserAgent::getValue()
- );
- if(!is_null($credential) && $credential instanceof OAuthTokenCredential) {
- $headers['Authorization'] = "Bearer " . $credential->getAccessToken();
- }
- if($method == 'POST' || $method == 'PUT') {
- $headers['PayPal-Request-Id'] = $apiContext->getRequestId();
- }
- $config->setHeaders($headers);
- $connection = new \PPHttpConnection($config);
- $response = $connection->execute($data);
- $this->logger->fine($response);
-
- return $response;
- }
-}
diff --git a/lib/PayPal/Rest/RestHandler.php b/lib/PayPal/Rest/RestHandler.php
new file mode 100644
index 0000000..19f8c86
--- /dev/null
+++ b/lib/PayPal/Rest/RestHandler.php
@@ -0,0 +1,77 @@
+apiContext = $apiContext;
+ }
+
+ public function handle($httpConfig, $request, $options) {
+
+ $credential = $this->apiContext->getCredential();
+ $config = $this->apiContext->getConfig();
+
+ if($credential == NULL) {
+ // Try picking credentials from the config file
+ $credMgr = \PPCredentialManager::getInstance($config);
+ $credValues = $credMgr->getCredentialObject();
+ if(!is_array($credValues)) {
+ throw new \PPMissingCredentialException("Empty or invalid credentials passed");
+ }
+ $credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
+ }
+ if($credential == NULL || ! ($credential instanceof OAuthTokenCredential) ) {
+ throw new \PPInvalidCredentialException("Invalid credentials passed");
+ }
+
+
+ $httpConfig->setUrl(
+ rtrim( trim($this->_getEndpoint($config)), '/') .
+ (isset($options['path']) ? $options['path'] : '')
+ );
+
+ if(!array_key_exists("User-Agent", $httpConfig->getHeaders())) {
+ $httpConfig->addHeader("User-Agent", \PPUserAgent::getValue(self::$sdkName, self::$sdkVersion));
+ }
+ if(!is_null($credential) && $credential instanceof OAuthTokenCredential) {
+ $httpConfig->addHeader('Authorization', "Bearer " . $credential->getAccessToken($config));
+ }
+ if($httpConfig->getMethod() == 'POST' || $httpConfig->getMethod() == 'PUT') {
+ $httpConfig->addHeader('PayPal-Request-Id', $this->apiContext->getRequestId());
+ }
+
+ }
+
+ private function _getEndpoint($config) {
+ if (isset($config['service.EndPoint'])) {
+ return $config['service.EndPoint'];
+ } else if (isset($config['mode'])) {
+ switch (strtoupper($config['mode'])) {
+ case 'SANDBOX':
+ return \PPConstants::REST_SANDBOX_ENDPOINT;
+ break;
+ case 'LIVE':
+ return \PPConstants::REST_LIVE_ENDPOINT;
+ break;
+ default:
+ throw new PPConfigurationException('The mode config parameter must be set to either sandbox/live');
+ break;
+ }
+ } else {
+ throw new PPConfigurationException('You must set one of service.endpoint or mode parameters in your configuration');
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/tests/PayPal/Test/Auth/OAuthTokenCredentialTest.php b/tests/PayPal/Test/Auth/OAuthTokenCredentialTest.php
index 962b42b..5597d03 100644
--- a/tests/PayPal/Test/Auth/OAuthTokenCredentialTest.php
+++ b/tests/PayPal/Test/Auth/OAuthTokenCredentialTest.php
@@ -1,33 +1,34 @@
-getAccessToken();
- $this->assertNotNull($token);
-
- // Check that we get the same token when issuing a new call before token expiry
- $newToken = $cred->getAccessToken();
- $this->assertNotNull($newToken);
- $this->assertEquals($token, $newToken);
-
-// sleep(60*8);
-// $newToken = $cred->getAccessToken();
-// $this->assertNotNull($newToken);
-// $this->assertNotEqual($token, $newToken);
-
- }
-
- public function testInvalidCredentials() {
- $this->setExpectedException('\PPConnectionException');
- $cred = new OAuthTokenCredential('dummy', 'secret');
- $this->assertNull($cred->getAccessToken());
- }
+getConfigHashmap();
+
+ $token = $cred->getAccessToken($config);
+ $this->assertNotNull($token);
+
+ // Check that we get the same token when issuing a new call before token expiry
+ $newToken = $cred->getAccessToken($config);
+ $this->assertNotNull($newToken);
+ $this->assertEquals($token, $newToken);
+
+// sleep(60*8);
+// $newToken = $cred->getAccessToken();
+// $this->assertNotNull($newToken);
+// $this->assertNotEqual($token, $newToken);
+
+ }
+
+ public function testInvalidCredentials() {
+ $this->setExpectedException('\PPConnectionException');
+ $cred = new OAuthTokenCredential('dummy', 'secret');
+ $this->assertNull($cred->getAccessToken(\PPConfigManager::getInstance()->getConfigHashmap()));
+ }
}
\ No newline at end of file
diff --git a/tests/PayPal/Test/Common/ArrayUtilTest.php b/tests/PayPal/Test/Common/ArrayUtilTest.php
index c6c79ca..6dd2930 100644
--- a/tests/PayPal/Test/Common/ArrayUtilTest.php
+++ b/tests/PayPal/Test/Common/ArrayUtilTest.php
@@ -1,22 +1,21 @@
-assertEquals(false, ArrayUtil::isAssocArray($arr));
-
- $arr = array(
- 'name' => 'John Doe',
- 'City' => 'San Jose'
- );
- $this->assertEquals(true, ArrayUtil::isAssocArray($arr));
-
- $arr[] = 'CA';
- $this->assertEquals(false, ArrayUtil::isAssocArray($arr));
- }
-}
+assertEquals(false, PPArrayUtil::isAssocArray($arr));
+
+ $arr = array(
+ 'name' => 'John Doe',
+ 'City' => 'San Jose'
+ );
+ $this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
+
+ $arr[] = 'CA';
+ $this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
+ }
+}
diff --git a/tests/PayPal/Test/Common/ModelTest.php b/tests/PayPal/Test/Common/ModelTest.php
index c810b7f..a25b900 100644
--- a/tests/PayPal/Test/Common/ModelTest.php
+++ b/tests/PayPal/Test/Common/ModelTest.php
@@ -1,135 +1,138 @@
-name = $name;
- }
- public function getName() {
- return $this->name;
- }
-
- public function setDescription($desc) {
- $this->desc = $desc;
- }
- public function getDescription() {
- return $this->desc;
- }
-}
-
-class ArrayClass extends Model {
-
- public function setName($name) {
- $this->name = $name;
- }
- public function getName() {
- return $this->name;
- }
-
- public function setDescription($desc) {
- $this->desc = $desc;
- }
- public function getDescription() {
- return $this->desc;
- }
-
- public function setTags($tags) {
- if(!is_array($tags)) {
- $tags = array($tags);
- }
- $this->tags = $tags;
- }
- public function getTags() {
- return $this->tags;
- }
-}
-
-class NestedClass extends Model {
-
- public function setId($id) {
- $this->id = $id;
- }
- public function getId() {
- return $this->id;
- }
-
- /**
- *
- * @param ArrayClass $info
- */
- public function setInfo($info) {
- $this->info = $info;
- }
- public function getInfo() {
- return $this->info;
- }
-}
-
-class ChildClass extends SimpleClass {
-
-}
-
-class ModelTest extends PHPUnit_Framework_TestCase {
-
- public function testSimpleClassConversion() {
- $o = new SimpleClass();
- $o->setName("test");
- $o->setDescription("description");
-
- $this->assertEquals("test", $o->getName());
- $this->assertEquals("description", $o->getDescription());
-
- $json = $o->toJSON();
- $this->assertEquals('{"name":"test","desc":"description"}', $json);
-
- $newO = new SimpleClass();
- $newO->fromJson($json);
- $this->assertEquals($o, $newO);
-
- }
-
-
- public function testArrayClassConversion() {
- $o = new ArrayClass();
- $o->setName("test");
- $o->setDescription("description");
- $o->setTags(array('payment', 'info', 'test'));
-
- $this->assertEquals("test", $o->getName());
- $this->assertEquals("description", $o->getDescription());
- $this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
-
- $json = $o->toJSON();
- $this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json);
-
- $newO = new ArrayClass();
- $newO->fromJson($json);
- $this->assertEquals($o, $newO);
- }
-
- public function testNestedClassConversion() {
- $n = new ArrayClass();
- $n->setName("test");
- $n->setDescription("description");
-// $n->setTags(array('payment', 'info', 'test'));
- $o = new NestedClass();
- $o->setId('123');
- $o->setInfo($n);
-
- $this->assertEquals("123", $o->getId());
- $this->assertEquals("test", $o->getInfo()->getName());
-// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
-
- $json = $o->toJSON();
-// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
- $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
-
- $newO = new NestedClass();
- $newO->fromJson($json);
- $this->assertEquals($o, $newO);
- }
-}
\ No newline at end of file
+name = $name;
+ }
+ public function getName() {
+ return $this->name;
+ }
+
+ public function setDescription($desc) {
+ $this->desc = $desc;
+ }
+ public function getDescription() {
+ return $this->desc;
+ }
+}
+
+class ArrayClass extends \PPModel {
+
+ public function setName($name) {
+ $this->name = $name;
+ }
+ public function getName() {
+ return $this->name;
+ }
+
+ public function setDescription($desc) {
+ $this->desc = $desc;
+ }
+ public function getDescription() {
+ return $this->desc;
+ }
+
+ public function setTags($tags) {
+ if(!is_array($tags)) {
+ $tags = array($tags);
+ }
+ $this->tags = $tags;
+ }
+ public function getTags() {
+ return $this->tags;
+ }
+}
+
+class NestedClass extends \PPModel {
+
+ public function setId($id) {
+ $this->id = $id;
+ }
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ *
+ * @param ArrayClass $info
+ */
+ public function setInfo($info) {
+ $this->info = $info;
+ }
+ /**
+ *
+ * @return ArrayClass
+ */
+ public function getInfo() {
+ return $this->info;
+ }
+}
+
+class ChildClass extends SimpleClass {
+
+}
+
+class ModelTest extends PHPUnit_Framework_TestCase {
+
+ public function testSimpleClassConversion() {
+ $o = new SimpleClass();
+ $o->setName("test");
+ $o->setDescription("description");
+
+ $this->assertEquals("test", $o->getName());
+ $this->assertEquals("description", $o->getDescription());
+
+ $json = $o->toJSON();
+ $this->assertEquals('{"name":"test","desc":"description"}', $json);
+
+ $newO = new SimpleClass();
+ $newO->fromJson($json);
+ $this->assertEquals($o, $newO);
+
+ }
+
+
+ public function testArrayClassConversion() {
+ $o = new ArrayClass();
+ $o->setName("test");
+ $o->setDescription("description");
+ $o->setTags(array('payment', 'info', 'test'));
+
+ $this->assertEquals("test", $o->getName());
+ $this->assertEquals("description", $o->getDescription());
+ $this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
+
+ $json = $o->toJSON();
+ $this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json);
+
+ $newO = new ArrayClass();
+ $newO->fromJson($json);
+ $this->assertEquals($o, $newO);
+ }
+
+ public function testNestedClassConversion() {
+ $n = new ArrayClass();
+ $n->setName("test");
+ $n->setDescription("description");
+// $n->setTags(array('payment', 'info', 'test'));
+ $o = new NestedClass();
+ $o->setId('123');
+ $o->setInfo($n);
+
+ $this->assertEquals("123", $o->getId());
+ $this->assertEquals("test", $o->getInfo()->getName());
+// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
+
+ $json = $o->toJSON();
+// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
+ $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
+
+ $newO = new NestedClass();
+ $newO->fromJson($json);
+ $this->assertEquals($o, $newO);
+ }
+}
diff --git a/tests/PayPal/Test/Common/UserAgentTest.php b/tests/PayPal/Test/Common/UserAgentTest.php
index 9436ab2..5bf8765 100644
--- a/tests/PayPal/Test/Common/UserAgentTest.php
+++ b/tests/PayPal/Test/Common/UserAgentTest.php
@@ -1,23 +1,26 @@
-assertNotNull($id);
- $this->assertNotNull($version);
- $this->assertNotNull($features);
-
- // Check that we pass in these mininal features
- $this->assertThat($features, $this->stringContains("OS="));
- $this->assertThat($features, $this->stringContains("Bit="));
- $this->assertThat($features, $this->stringContains("Lang="));
- $this->assertThat($features, $this->stringContains("V="));
- $this->assertGreaterThan(5, count(explode(';', $features)));
- }
+assertNotNull($id);
+ $this->assertNotNull($version);
+ $this->assertNotNull($features);
+
+ $this->assertEquals("name", $id);
+ $this->assertEquals("version", $version);
+
+ // Check that we pass in these mininal features
+ $this->assertThat($features, $this->stringContains("OS="));
+ $this->assertThat($features, $this->stringContains("Bit="));
+ $this->assertThat($features, $this->stringContains("Lang="));
+ $this->assertThat($features, $this->stringContains("V="));
+ $this->assertGreaterThan(5, count(explode(';', $features)));
+ }
}
\ No newline at end of file
From 0699f628bd024b56e310d1a054a7748925e85796 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Thu, 25 Apr 2013 17:17:36 +0530
Subject: [PATCH 2/7] Updating version nos for V0.6.0 release
---
CHANGELOG.md | 19 +++--
README.md | 122 ++++++++++++++++----------------
lib/PayPal/Rest/RestHandler.php | 4 +-
sample/composer.json | 28 ++++----
4 files changed, 89 insertions(+), 84 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec7af6f..1e687b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,12 @@
-CHANGELOG
-=========
-
-V0.5.0 (March 07, 2013)
------------------------
-
- * Initial Release
+CHANGELOG
+=========
+
+V0.6.0 (April 25, 2013)
+-----------------------
+
+ * Adding support for dynamic configuration of SDK (Upgrading sdk-core-php dependency to V1.4.0)
+
+V0.5.0 (March 07, 2013)
+-----------------------
+
+ * Initial Release
diff --git a/README.md b/README.md
index cbb0ff8..47ef698 100644
--- a/README.md
+++ b/README.md
@@ -1,61 +1,61 @@
-REST API SDK for PHP (V0.5.0)
-==============================
-
- PayPal's PHP SDK for the RESTful APIs
-
-
-Prerequisites
--------------
-
- * PHP 5.3 or above
- * curl, json & openssl extensions must be enabled
- * composer for running the sample out of the box (See http://getcomposer.org)
-
-
-Running the sample
-------------------
-
- * Ensure that you have composer installed on your machine.
- * Navigate to the samples folder and run 'composer update'.
- * Optionally, update the sdk_config.ini file with your own client Id and client secret.
- * Run any of the command line samples in the folder to see what the APIs can do.
-
-
-Usage
------
-
-To write an app that uses the SDK
-
- * Copy the composer.json file from the sample folder over to your project and run 'composer update' to fetch all
-dependencies
- * Copy the sample configuration file sdk_config.ini to a location of your choice and let the SDK know your config path using the following define directive
-
- define('PP_SDK_CONFIG_PATH', /path/to/your/sdk_config.ini);
-
- * Obtain your clientId and client secret from the developer portal and add them to your config file
- * Now you are all set to make your first API call. Create a resource object as per your need and call the relevant operation or invoke one of the static methods on your resource class.
-
- $payment = new Payment();
-
- $payment->setIntent("Sale");
-
- ...
-
- $payment->create();
-
- *OR*
-
- $payment = Payment::get('payment_id');
-
- These examples pick the client id / secret automatically from your config file. You can also set API credentials dynamically. See the sample code for how you can do this.
-
-
-Contributing
-------------
-
-More help
----------
-
- * API Reference
- * Reporting issues / feature requests
-
+REST API SDK for PHP (V0.6.0)
+==============================
+
+ PayPal's PHP SDK for the RESTful APIs
+
+
+Prerequisites
+-------------
+
+ * PHP 5.3 or above
+ * curl, json & openssl extensions must be enabled
+ * composer for running the sample out of the box (See http://getcomposer.org)
+
+
+Running the sample
+------------------
+
+ * Ensure that you have composer installed on your machine.
+ * Navigate to the samples folder and run 'composer update'.
+ * Optionally, update the sdk_config.ini file with your own client Id and client secret.
+ * Run any of the command line samples in the folder to see what the APIs can do.
+
+
+Usage
+-----
+
+To write an app that uses the SDK
+
+ * Copy the composer.json file from the sample folder over to your project and run 'composer update' to fetch all
+dependencies
+ * Copy the sample configuration file sdk_config.ini to a location of your choice and let the SDK know your config path using the following define directive
+
+ define('PP_SDK_CONFIG_PATH', /path/to/your/sdk_config.ini);
+
+ * Obtain your clientId and client secret from the developer portal and add them to your config file
+ * Now you are all set to make your first API call. Create a resource object as per your need and call the relevant operation or invoke one of the static methods on your resource class.
+
+ $payment = new Payment();
+
+ $payment->setIntent("Sale");
+
+ ...
+
+ $payment->create();
+
+ *OR*
+
+ $payment = Payment::get('payment_id');
+
+ These examples pick the client id / secret automatically from your config file. You can also set API credentials dynamically. See the sample code for how you can do this.
+
+
+Contributing
+------------
+
+More help
+---------
+
+ * API Reference
+ * Reporting issues / feature requests
+
diff --git a/lib/PayPal/Rest/RestHandler.php b/lib/PayPal/Rest/RestHandler.php
index 19f8c86..15dd599 100644
--- a/lib/PayPal/Rest/RestHandler.php
+++ b/lib/PayPal/Rest/RestHandler.php
@@ -12,7 +12,7 @@ class RestHandler implements \IPPHandler {
private $apiContext;
public static $sdkName = "rest-sdk-php";
- public static $sdkVersion = "0.5.0";
+ public static $sdkVersion = "0.6.0";
public function __construct($apiContext) {
$this->apiContext = $apiContext;
@@ -74,4 +74,4 @@ class RestHandler implements \IPPHandler {
}
}
-}
\ No newline at end of file
+}
diff --git a/sample/composer.json b/sample/composer.json
index f3c60bf..691fc66 100644
--- a/sample/composer.json
+++ b/sample/composer.json
@@ -1,14 +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.*"
- }
-}
+{
+ "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.6.*"
+ }
+}
From cbc9055e4d1b2b77067fa88e50c9f8076eb2798a Mon Sep 17 00:00:00 2001
From: aydiv
Date: Thu, 25 Apr 2013 18:04:49 +0530
Subject: [PATCH 3/7] Adding apiContext arg for static methods
---
lib/PayPal/Api/CreditCard.php | 11 +++++++----
lib/PayPal/Api/Payment.php | 22 ++++++++++++++--------
lib/PayPal/Api/Refund.php | 9 ++++++---
lib/PayPal/Api/Sale.php | 11 +++++++----
4 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php
index 424cb81..db2613e 100644
--- a/lib/PayPal/Api/CreditCard.php
+++ b/lib/PayPal/Api/CreditCard.php
@@ -230,7 +230,7 @@ class CreditCard extends Resource implements IResource {
* @path /v1/vault/credit-card
* @method POST
- * @param PayPal\Rest\ApiContext $apiContext optional
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public function create( $apiContext=null) {
$payLoad = $this->toJSON();
@@ -248,15 +248,18 @@ class CreditCard extends Resource implements IResource {
/**
* @path /v1/vault/credit-card/:credit-card-id
* @method GET
- * @param string $creditcardid
+ * @param string $creditcardid
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public static function get( $creditcardid) {
if (($creditcardid == null) || (strlen($creditcardid) <= 0)) {
throw new \InvalidArgumentException("creditcardid cannot be null or empty");
}
$payLoad = "";
-
- $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ if($apiContext == null) {
+ $apiContext = new ApiContext(self::$credential);
+ }
+ $call = new \PPRestCall();
$json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
"/v1/vault/credit-card/$creditcardid",
"GET", $payLoad);
diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php
index fc71a30..7fa2dd0 100644
--- a/lib/PayPal/Api/Payment.php
+++ b/lib/PayPal/Api/Payment.php
@@ -176,13 +176,16 @@ class Payment extends Resource implements IResource {
* payee_id,
* sort_by,
* sort_order,
- * All other keys in the map are ignored by the SDK
+ * All other keys in the map are ignored by the SDK
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public static function all($params) {
$payLoad = "";
$allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
-
- $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ if($apiContext == null) {
+ $apiContext = new ApiContext(self::$credential);
+ }
+ $call = new \PPRestCall();
$json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
"/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)),
"GET", $payLoad);
@@ -196,7 +199,7 @@ class Payment extends Resource implements IResource {
* @path /v1/payments/payment
* @method POST
- * @param PayPal\Rest\ApiContext $apiContext optional
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public function create( $apiContext=null) {
$payLoad = $this->toJSON();
@@ -214,15 +217,18 @@ class Payment extends Resource implements IResource {
/**
* @path /v1/payments/payment/:payment-id
* @method GET
- * @param string $paymentid
+ * @param string $paymentid
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public static function get( $paymentid) {
if (($paymentid == null) || (strlen($paymentid) <= 0)) {
throw new \InvalidArgumentException("paymentid cannot be null or empty");
}
$payLoad = "";
-
- $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ if($apiContext == null) {
+ $apiContext = new ApiContext(self::$credential);
+ }
+ $call = new \PPRestCall();
$json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
"/v1/payments/payment/$paymentid",
"GET", $payLoad);
@@ -236,7 +242,7 @@ class Payment extends Resource implements IResource {
* @path /v1/payments/payment/:payment-id/execute
* @method POST
* @param PaymentExecution $payment_execution
- * @param PayPal\Rest\ApiContext $apiContext optional
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public function execute( $payment_execution, $apiContext=null) {
if ($payment_execution == null) {
diff --git a/lib/PayPal/Api/Refund.php b/lib/PayPal/Api/Refund.php
index cb52e26..61db1dd 100644
--- a/lib/PayPal/Api/Refund.php
+++ b/lib/PayPal/Api/Refund.php
@@ -181,15 +181,18 @@ class Refund extends Resource implements IResource {
/**
* @path /v1/payments/refund/:refund-id
* @method GET
- * @param string $refundid
+ * @param string $refundid
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public static function get( $refundid) {
if (($refundid == null) || (strlen($refundid) <= 0)) {
throw new \InvalidArgumentException("refundid cannot be null or empty");
}
$payLoad = "";
-
- $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ if($apiContext == null) {
+ $apiContext = new ApiContext(self::$credential);
+ }
+ $call = new \PPRestCall();
$json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
"/v1/payments/refund/$refundid",
"GET", $payLoad);
diff --git a/lib/PayPal/Api/Sale.php b/lib/PayPal/Api/Sale.php
index 1b62ef4..46f8aa5 100644
--- a/lib/PayPal/Api/Sale.php
+++ b/lib/PayPal/Api/Sale.php
@@ -133,15 +133,18 @@ class Sale extends Resource implements IResource {
/**
* @path /v1/payments/sale/:sale-id
* @method GET
- * @param string $saleid
+ * @param string $saleid
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public static function get( $saleid) {
if (($saleid == null) || (strlen($saleid) <= 0)) {
throw new \InvalidArgumentException("saleid cannot be null or empty");
}
$payLoad = "";
-
- $apiContext = new ApiContext(self::$credential); $call = new \PPRestCall();
+ if($apiContext == null) {
+ $apiContext = new ApiContext(self::$credential);
+ }
+ $call = new \PPRestCall();
$json = $call->execute($apiContext, array('PayPal\Rest\RestHandler'),
"/v1/payments/sale/$saleid",
"GET", $payLoad);
@@ -155,7 +158,7 @@ class Sale extends Resource implements IResource {
* @path /v1/payments/sale/:sale-id/refund
* @method POST
* @param Refund $refund
- * @param PayPal\Rest\ApiContext $apiContext optional
+ * @param PayPal\Rest\ApiContext $apiContext optional
*/
public function refund( $refund, $apiContext=null) {
if ($refund == null) {
From c624834f158d0aee318f4ccee931a4c29928bf42 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Thu, 25 Apr 2013 20:39:13 +0530
Subject: [PATCH 4/7] Added missing apiContext arg
---
lib/PayPal/Api/CreditCard.php | 4 ++--
lib/PayPal/Api/Payment.php | 6 +++---
lib/PayPal/Api/Refund.php | 4 ++--
lib/PayPal/Api/Sale.php | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php
index db2613e..0a47b5a 100644
--- a/lib/PayPal/Api/CreditCard.php
+++ b/lib/PayPal/Api/CreditCard.php
@@ -251,7 +251,7 @@ class CreditCard extends Resource implements IResource {
* @param string $creditcardid
* @param PayPal\Rest\ApiContext $apiContext optional
*/
- public static function get( $creditcardid) {
+ public static function get( $creditcardid, $apiContext=null) {
if (($creditcardid == null) || (strlen($creditcardid) <= 0)) {
throw new \InvalidArgumentException("creditcardid cannot be null or empty");
}
@@ -270,4 +270,4 @@ class CreditCard extends Resource implements IResource {
}
-}
\ No newline at end of file
+}
diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php
index 7fa2dd0..3492d32 100644
--- a/lib/PayPal/Api/Payment.php
+++ b/lib/PayPal/Api/Payment.php
@@ -179,7 +179,7 @@ class Payment extends Resource implements IResource {
* All other keys in the map are ignored by the SDK
* @param PayPal\Rest\ApiContext $apiContext optional
*/
- public static function all($params) {
+ public static function all($params, $apiContext=null) {
$payLoad = "";
$allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
if($apiContext == null) {
@@ -220,7 +220,7 @@ class Payment extends Resource implements IResource {
* @param string $paymentid
* @param PayPal\Rest\ApiContext $apiContext optional
*/
- public static function get( $paymentid) {
+ public static function get( $paymentid, $apiContext=null) {
if (($paymentid == null) || (strlen($paymentid) <= 0)) {
throw new \InvalidArgumentException("paymentid cannot be null or empty");
}
@@ -264,4 +264,4 @@ class Payment extends Resource implements IResource {
}
-}
\ No newline at end of file
+}
diff --git a/lib/PayPal/Api/Refund.php b/lib/PayPal/Api/Refund.php
index 61db1dd..89729ee 100644
--- a/lib/PayPal/Api/Refund.php
+++ b/lib/PayPal/Api/Refund.php
@@ -184,7 +184,7 @@ class Refund extends Resource implements IResource {
* @param string $refundid
* @param PayPal\Rest\ApiContext $apiContext optional
*/
- public static function get( $refundid) {
+ public static function get( $refundid, $apiContext=null) {
if (($refundid == null) || (strlen($refundid) <= 0)) {
throw new \InvalidArgumentException("refundid cannot be null or empty");
}
@@ -203,4 +203,4 @@ class Refund extends Resource implements IResource {
}
-}
\ No newline at end of file
+}
diff --git a/lib/PayPal/Api/Sale.php b/lib/PayPal/Api/Sale.php
index 46f8aa5..bcb0619 100644
--- a/lib/PayPal/Api/Sale.php
+++ b/lib/PayPal/Api/Sale.php
@@ -136,7 +136,7 @@ class Sale extends Resource implements IResource {
* @param string $saleid
* @param PayPal\Rest\ApiContext $apiContext optional
*/
- public static function get( $saleid) {
+ public static function get( $saleid, $apiContext=null) {
if (($saleid == null) || (strlen($saleid) <= 0)) {
throw new \InvalidArgumentException("saleid cannot be null or empty");
}
@@ -180,4 +180,4 @@ class Sale extends Resource implements IResource {
}
-}
\ No newline at end of file
+}
From b3423b6c118b787144826b28a9031e1bb6144ee9 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Fri, 26 Apr 2013 12:00:20 +0530
Subject: [PATCH 5/7] 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.