forked from LiveCarta/PayPal-PHP-SDK
Merge branch 'dynamicconfig'
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
V0.6.0 (April 26, 2013)
|
||||
-----------------------
|
||||
|
||||
* Adding support for dynamic configuration of SDK (Upgrading sdk-core-php dependency to V1.4.0)
|
||||
* Deprecating the setCredential method and changing resource class methods to take an ApiContext argument instead of a OauthTokenCredential argument.
|
||||
|
||||
V0.5.0 (March 07, 2013)
|
||||
-----------------------
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
REST API SDK for PHP (V0.5.0) [](https://travis-ci.org/paypal/rest-api-sdk-php)
|
||||
REST API SDK for PHP (V0.6.0) [](https://travis-ci.org/paypal/rest-api-sdk-php)
|
||||
==============================
|
||||
|
||||
This repository contains PayPal's PHP SDK and samples for REST API.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
"php": ">=5.3.0",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"paypal/sdk-core-php": "1.2.*"
|
||||
"paypal/sdk-core-php": "1.4.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "3.7.*"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,6 +12,10 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
private static $credential;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprected. Pass ApiContext to create/get methods instead
|
||||
*/
|
||||
public static function setCredential($credential) {
|
||||
self::$credential = $credential;
|
||||
}
|
||||
@@ -26,6 +30,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for id
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
@@ -41,6 +46,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for valid_until
|
||||
* @return string
|
||||
*/
|
||||
public function getValid_until() {
|
||||
return $this->valid_until;
|
||||
@@ -56,6 +62,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for state
|
||||
* @return string
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
@@ -71,6 +78,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for payer_id
|
||||
* @return string
|
||||
*/
|
||||
public function getPayer_id() {
|
||||
return $this->payer_id;
|
||||
@@ -86,6 +94,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for type
|
||||
* @return string
|
||||
*/
|
||||
public function getType() {
|
||||
return $this->type;
|
||||
@@ -101,6 +110,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for number
|
||||
* @return string
|
||||
*/
|
||||
public function getNumber() {
|
||||
return $this->number;
|
||||
@@ -116,6 +126,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for expire_month
|
||||
* @return string
|
||||
*/
|
||||
public function getExpire_month() {
|
||||
return $this->expire_month;
|
||||
@@ -131,6 +142,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for expire_year
|
||||
* @return string
|
||||
*/
|
||||
public function getExpire_year() {
|
||||
return $this->expire_year;
|
||||
@@ -146,6 +158,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for cvv2
|
||||
* @return string
|
||||
*/
|
||||
public function getCvv2() {
|
||||
return $this->cvv2;
|
||||
@@ -161,6 +174,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for first_name
|
||||
* @return string
|
||||
*/
|
||||
public function getFirst_name() {
|
||||
return $this->first_name;
|
||||
@@ -176,6 +190,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for last_name
|
||||
* @return string
|
||||
*/
|
||||
public function getLast_name() {
|
||||
return $this->last_name;
|
||||
@@ -191,6 +206,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 +222,7 @@ class CreditCard extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for links
|
||||
* @return PayPal\Api\Link
|
||||
*/
|
||||
public function getLinks() {
|
||||
return $this->links;
|
||||
@@ -224,8 +241,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($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/vault/credit-card",
|
||||
"POST", $payLoad);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
@@ -234,15 +253,20 @@ class CreditCard extends Resource implements IResource {
|
||||
* @path /v1/vault/credit-card/:credit-card-id
|
||||
* @method GET
|
||||
* @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");
|
||||
}
|
||||
$payLoad = "";
|
||||
|
||||
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||
$json = $call->execute("/v1/vault/credit-card/$creditcardid", "GET", $payLoad, $apiContext);
|
||||
if($apiContext == null) {
|
||||
$apiContext = new ApiContext(self::$credential);
|
||||
}
|
||||
$call = new \PPRestCall($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/vault/credit-card/$creditcardid",
|
||||
"GET", $payLoad);
|
||||
$ret = new CreditCard();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,6 +12,10 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
private static $credential;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprected. Pass ApiContext to create/get methods instead
|
||||
*/
|
||||
public static function setCredential($credential) {
|
||||
self::$credential = $credential;
|
||||
}
|
||||
@@ -26,6 +30,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for id
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
@@ -41,6 +46,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for create_time
|
||||
* @return string
|
||||
*/
|
||||
public function getCreate_time() {
|
||||
return $this->create_time;
|
||||
@@ -56,6 +62,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for update_time
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdate_time() {
|
||||
return $this->update_time;
|
||||
@@ -71,6 +78,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for state
|
||||
* @return string
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
@@ -86,6 +94,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for intent
|
||||
* @return string
|
||||
*/
|
||||
public function getIntent() {
|
||||
return $this->intent;
|
||||
@@ -101,6 +110,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for payer
|
||||
* @return PayPal\Api\Payer
|
||||
*/
|
||||
public function getPayer() {
|
||||
return $this->payer;
|
||||
@@ -116,6 +126,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for transactions
|
||||
* @return PayPal\Api\Transaction
|
||||
*/
|
||||
public function getTransactions() {
|
||||
return $this->transactions;
|
||||
@@ -131,6 +142,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 +158,7 @@ class Payment extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for links
|
||||
* @return PayPal\Api\Link
|
||||
*/
|
||||
public function getLinks() {
|
||||
return $this->links;
|
||||
@@ -168,13 +181,18 @@ class Payment extends Resource implements IResource {
|
||||
* sort_by,
|
||||
* sort_order,
|
||||
* 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, );
|
||||
|
||||
$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);
|
||||
if($apiContext == null) {
|
||||
$apiContext = new ApiContext(self::$credential);
|
||||
}
|
||||
$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();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
@@ -192,8 +210,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($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/payments/payment",
|
||||
"POST", $payLoad);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
@@ -202,15 +222,20 @@ class Payment extends Resource implements IResource {
|
||||
* @path /v1/payments/payment/:payment-id
|
||||
* @method GET
|
||||
* @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");
|
||||
}
|
||||
$payLoad = "";
|
||||
|
||||
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||
$json = $call->execute("/v1/payments/payment/$paymentid", "GET", $payLoad, $apiContext);
|
||||
if($apiContext == null) {
|
||||
$apiContext = new ApiContext(self::$credential);
|
||||
}
|
||||
$call = new \PPRestCall($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/payments/payment/$paymentid",
|
||||
"GET", $payLoad);
|
||||
$ret = new Payment();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
@@ -234,8 +259,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($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/payments/payment/{$this->getId()}/execute",
|
||||
"POST", $payLoad);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -12,6 +12,10 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
private static $credential;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprected. Pass ApiContext to the get method instead
|
||||
*/
|
||||
public static function setCredential($credential) {
|
||||
self::$credential = $credential;
|
||||
}
|
||||
@@ -26,6 +30,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for id
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
@@ -41,6 +46,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for create_time
|
||||
* @return string
|
||||
*/
|
||||
public function getCreate_time() {
|
||||
return $this->create_time;
|
||||
@@ -56,6 +62,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for update_time
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdate_time() {
|
||||
return $this->update_time;
|
||||
@@ -71,6 +78,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for state
|
||||
* @return string
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
@@ -86,6 +94,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for amount
|
||||
* @return PayPal\Api\Amount
|
||||
*/
|
||||
public function getAmount() {
|
||||
return $this->amount;
|
||||
@@ -101,6 +110,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for sale_id
|
||||
* @return string
|
||||
*/
|
||||
public function getSale_id() {
|
||||
return $this->sale_id;
|
||||
@@ -116,6 +126,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for capture_id
|
||||
* @return string
|
||||
*/
|
||||
public function getCapture_id() {
|
||||
return $this->capture_id;
|
||||
@@ -131,6 +142,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for parent_payment
|
||||
* @return string
|
||||
*/
|
||||
public function getParent_payment() {
|
||||
return $this->parent_payment;
|
||||
@@ -146,6 +158,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for description
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
@@ -161,6 +174,7 @@ class Refund extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for links
|
||||
* @return PayPal\Api\Link
|
||||
*/
|
||||
public function getLinks() {
|
||||
return $this->links;
|
||||
@@ -172,15 +186,20 @@ class Refund extends Resource implements IResource {
|
||||
* @path /v1/payments/refund/:refund-id
|
||||
* @method GET
|
||||
* @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");
|
||||
}
|
||||
$payLoad = "";
|
||||
|
||||
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||
$json = $call->execute("/v1/payments/refund/$refundid", "GET", $payLoad, $apiContext);
|
||||
if($apiContext == null) {
|
||||
$apiContext = new ApiContext(self::$credential);
|
||||
}
|
||||
$call = new \PPRestCall($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/payments/refund/$refundid",
|
||||
"GET", $payLoad);
|
||||
$ret = new Refund();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Api;
|
||||
use PayPal\Common\Model;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Resource extends Model {
|
||||
class Resource extends \PPModel {
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
private static $credential;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprected. Pass ApiContext to refund/get methods instead
|
||||
*/
|
||||
public static function setCredential($credential) {
|
||||
self::$credential = $credential;
|
||||
}
|
||||
@@ -26,6 +30,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for id
|
||||
* @return string
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
@@ -41,6 +46,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for create_time
|
||||
* @return string
|
||||
*/
|
||||
public function getCreate_time() {
|
||||
return $this->create_time;
|
||||
@@ -56,6 +62,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for update_time
|
||||
* @return string
|
||||
*/
|
||||
public function getUpdate_time() {
|
||||
return $this->update_time;
|
||||
@@ -71,6 +78,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for state
|
||||
* @return string
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->state;
|
||||
@@ -86,6 +94,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for amount
|
||||
* @return PayPal\Api\Amount
|
||||
*/
|
||||
public function getAmount() {
|
||||
return $this->amount;
|
||||
@@ -101,6 +110,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for parent_payment
|
||||
* @return string
|
||||
*/
|
||||
public function getParent_payment() {
|
||||
return $this->parent_payment;
|
||||
@@ -116,6 +126,7 @@ class Sale extends Resource implements IResource {
|
||||
|
||||
/**
|
||||
* Getter for links
|
||||
* @return PayPal\Api\Link
|
||||
*/
|
||||
public function getLinks() {
|
||||
return $this->links;
|
||||
@@ -127,15 +138,20 @@ class Sale extends Resource implements IResource {
|
||||
* @path /v1/payments/sale/:sale-id
|
||||
* @method GET
|
||||
* @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");
|
||||
}
|
||||
$payLoad = "";
|
||||
|
||||
$apiContext = new ApiContext(self::$credential); $call = new Call();
|
||||
$json = $call->execute("/v1/payments/sale/$saleid", "GET", $payLoad, $apiContext);
|
||||
if($apiContext == null) {
|
||||
$apiContext = new ApiContext(self::$credential);
|
||||
}
|
||||
$call = new \PPRestCall($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/payments/sale/$saleid",
|
||||
"GET", $payLoad);
|
||||
$ret = new Sale();
|
||||
$ret->fromJson($json);
|
||||
return $ret;
|
||||
@@ -159,8 +175,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($apiContext);
|
||||
$json = $call->execute( array('PayPal\Rest\RestHandler'),
|
||||
"/v1/payments/sale/{$this->getId()}/refund",
|
||||
"POST", $payLoad);
|
||||
$this->fromJson($json);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class ShippingAddress extends Address {
|
||||
|
||||
/**
|
||||
* Getter for recipient_name
|
||||
* @return string
|
||||
*/
|
||||
public function getRecipient_name() {
|
||||
return $this->recipient_name;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -6,6 +6,10 @@ namespace PayPal\Auth;
|
||||
* Oauth Token credential
|
||||
*
|
||||
*/
|
||||
use PayPal\Rest\RestHandler;
|
||||
|
||||
use PayPal\Common\UserAgent;
|
||||
|
||||
class OAuthTokenCredential {
|
||||
|
||||
private static $expiryBufferTime = 120;
|
||||
@@ -46,13 +50,14 @@ class OAuthTokenCredential {
|
||||
public function __construct($clientId, $clientSecret) {
|
||||
$this->clientId = $clientId;
|
||||
$this->clientSecret = $clientSecret;
|
||||
$this->logger = new \PPLoggingManager(__CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accessToken
|
||||
*/
|
||||
public function getAccessToken() {
|
||||
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
|
||||
@@ -64,7 +69,7 @@ class OAuthTokenCredential {
|
||||
}
|
||||
// If accessToken is Null, obtain a new token
|
||||
if ($this->accessToken == null) {
|
||||
$this->generateAccessToken();
|
||||
$this->_generateAccessToken($config);
|
||||
}
|
||||
return $this->accessToken;
|
||||
}
|
||||
@@ -72,23 +77,18 @@ class OAuthTokenCredential {
|
||||
/**
|
||||
* 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) {
|
||||
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();
|
||||
$httpConfiguration = $this->getOAuthHttpConfiguration($config);
|
||||
$httpConfiguration->setHeaders($headers);
|
||||
|
||||
$connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration);
|
||||
$connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration, $config);
|
||||
$res = $connection->execute("grant_type=client_credentials");
|
||||
$jsonResponse = json_decode($res, true);
|
||||
if($jsonResponse == NULL ||
|
||||
@@ -107,11 +107,26 @@ class OAuthTokenCredential {
|
||||
/*
|
||||
* Get HttpConfiguration object for OAuth API
|
||||
*/
|
||||
private function getOAuthHttpConfiguration() {
|
||||
$configMgr = \PPConfigManager::getInstance();
|
||||
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 = ($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");
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
namespace PayPal\Common;
|
||||
|
||||
class ArrayUtil {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $arr
|
||||
* @return true if $arr is an associative array
|
||||
*/
|
||||
public static function isAssocArray(array $arr) {
|
||||
foreach($arr as $k => $v) {
|
||||
if(is_int($k)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Common;
|
||||
|
||||
use PayPal\Api\Payer;
|
||||
|
||||
/**
|
||||
* Generic Model class that all API domain classes extend
|
||||
* Stores all member data in a hashmap that enables easy
|
||||
* JSON encoding/decoding
|
||||
*/
|
||||
class Model {
|
||||
|
||||
private $_propMap = array();
|
||||
|
||||
public function __get($key) {
|
||||
return $this->_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());
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
namespace PayPal\Common;
|
||||
|
||||
class ReflectionUtil {
|
||||
|
||||
|
||||
/**
|
||||
* @var array|ReflectionMethod[]
|
||||
*/
|
||||
private static $propertiesRefl = array();
|
||||
|
||||
/**
|
||||
* @var array|string[]
|
||||
*/
|
||||
private static $propertiesType = array();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $propertyName
|
||||
*/
|
||||
public static function getPropertyClass($class, $propertyName) {
|
||||
|
||||
if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['param'])) {
|
||||
// if (substr($annotations['param'], -2) === '[]') {
|
||||
// $param = substr($annotations['param'], 0, -2);
|
||||
// }
|
||||
$param = $annotations['param'];
|
||||
}
|
||||
|
||||
if(isset($param)) {
|
||||
$anno = explode(' ', $param);
|
||||
return $anno[0];
|
||||
} else {
|
||||
return 'string';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string $propertyName
|
||||
* @throws RuntimeException
|
||||
* @return string
|
||||
*/
|
||||
public static function propertyAnnotations($class, $propertyName)
|
||||
{
|
||||
$class = is_object($class) ? get_class($class) : $class;
|
||||
if (!class_exists('ReflectionProperty')) {
|
||||
throw new RuntimeException("Property type of " . $class . "::{$propertyName} cannot be resolved");
|
||||
}
|
||||
|
||||
if ($annotations =& self::$propertiesType[$class][$propertyName]) {
|
||||
return $annotations;
|
||||
}
|
||||
|
||||
$setterFunc = "set" . ucfirst($propertyName);
|
||||
if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
|
||||
$refl = new \ReflectionMethod($class, $setterFunc);
|
||||
}
|
||||
|
||||
// todo: smarter regexp
|
||||
if (!preg_match_all('~\@([^\s@\(]+)[\t ]*(?:\(?([^\n@]+)\)?)?~i', $refl->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;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Common;
|
||||
|
||||
define('SDK_NAME', 'rest-sdk-php');
|
||||
define('SDK_VERSION', '0.5.0');
|
||||
|
||||
class UserAgent {
|
||||
|
||||
/**
|
||||
* Returns the value of the User-Agent header
|
||||
* Add environment values and php version numbers
|
||||
*/
|
||||
public static function getValue() {
|
||||
|
||||
$featureList = array(
|
||||
'lang=PHP',
|
||||
'v=' . PHP_VERSION,
|
||||
'bit=' . UserAgent::_getPHPBit(),
|
||||
'os=' . str_replace(' ' , '_', php_uname('s') . ' ' . php_uname('r')),
|
||||
'machine=' . php_uname('m')
|
||||
);
|
||||
if(defined('OPENSSL_VERSION_TEXT')) {
|
||||
$opensslVersion = explode(' ', OPENSSL_VERSION_TEXT);
|
||||
$featureList[] = 'openssl='. $opensslVersion[1];
|
||||
}
|
||||
if(function_exists('curl_version')) {
|
||||
$curlVersion = curl_version();
|
||||
$featureList[] = 'curl=' . $curlVersion['version'];
|
||||
}
|
||||
return sprintf("PayPalSDK/%s %s (%s)", SDK_NAME, SDK_VERSION, implode(';', $featureList));
|
||||
}
|
||||
|
||||
private static function _getPHPBit() {
|
||||
switch(PHP_INT_SIZE) {
|
||||
case 4:
|
||||
return '32';
|
||||
case 8:
|
||||
return '64';
|
||||
default:
|
||||
return PHP_INT_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace PayPal\Rest;
|
||||
* Call level parameters such as
|
||||
* request id, credentials etc
|
||||
*/
|
||||
class ApiContext {
|
||||
class ApiContext extends \PPApiContext {
|
||||
|
||||
/**
|
||||
* OAuth Credentials to use for this call
|
||||
@@ -22,7 +22,6 @@ class ApiContext {
|
||||
*/
|
||||
private $requestId;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -32,11 +31,12 @@ class ApiContext {
|
||||
|
||||
public function getrequestId() {
|
||||
if($this->requestId == null) {
|
||||
$this->requestId = $this->generaterequestId();
|
||||
$this->requestId = $this->generateRequestId();
|
||||
}
|
||||
return $this->requestId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param PayPal/Api/OAuthTokenCredential $credential
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
namespace PayPal\Rest;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
|
||||
use PayPal\Common\UserAgent;
|
||||
|
||||
class Call {
|
||||
|
||||
private $logger;
|
||||
|
||||
public function __construct() {
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
77
lib/PayPal/Rest/RestHandler.php
Normal file
77
lib/PayPal/Rest/RestHandler.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
namespace PayPal\Rest;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
|
||||
/**
|
||||
*
|
||||
* API handler for all REST API calls
|
||||
*/
|
||||
class RestHandler implements \IPPHandler {
|
||||
|
||||
private $apiContext;
|
||||
|
||||
public static $sdkName = "rest-sdk-php";
|
||||
public static $sdkVersion = "0.6.0";
|
||||
|
||||
public function __construct($apiContext) {
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
* Sample bootstrap file.
|
||||
*/
|
||||
*/
|
||||
|
||||
// Include the composer autoloader
|
||||
if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
|
||||
@@ -9,23 +9,30 @@ if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
|
||||
exit(1);
|
||||
}
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
|
||||
define("PP_CONFIG_PATH", __DIR__);
|
||||
|
||||
$configManager = \PPConfigManager::getInstance();
|
||||
|
||||
// $cred is used by samples that include this bootstrap file
|
||||
// This piece of code simply demonstrates how you can
|
||||
// dynamically pass in a client id/secret instead of using
|
||||
// the config file. If you do not need a way to pass
|
||||
// in credentials dynamically, you can skip the
|
||||
// <Resource>::setCredential($cred) calls that
|
||||
// you see in the samples.
|
||||
$cred = new OAuthTokenCredential(
|
||||
$configManager->get('acct1.ClientId'),
|
||||
$configManager->get('acct1.ClientSecret'));
|
||||
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
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
"php": ">=5.3.0",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"paypal/rest-api-sdk-php" : "0.5.*"
|
||||
"paypal/rest-api-sdk-php" : "0.6.*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
// ### Address
|
||||
// Base Address object used as shipping or billing
|
||||
@@ -80,16 +79,11 @@ $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
|
||||
// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
|
||||
@@ -13,7 +13,6 @@ use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Rest\ApiContext;
|
||||
session_start();
|
||||
|
||||
// ### Payer
|
||||
@@ -55,16 +54,10 @@ $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
|
||||
// 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
|
||||
|
||||
@@ -16,7 +16,6 @@ use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\RedirectUrls;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
// ### Credit card token
|
||||
// Saved credit card id from a previous call to
|
||||
@@ -65,16 +64,9 @@ $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
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
// The return object contains the status;
|
||||
try {
|
||||
$payment->create($apiContext);
|
||||
|
||||
@@ -11,22 +11,14 @@ 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);
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
|
||||
// PaymentExecution object includes information necessary
|
||||
// to execute a PayPal account payment.
|
||||
@@ -36,6 +28,7 @@ if(isset($_GET['success']) && $_GET['success'] == 'true') {
|
||||
$execution->setPayer_id($_GET['PayerID']);
|
||||
|
||||
//Execute the payment
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$payment->execute($execution, $apiContext);
|
||||
|
||||
echo "<html><body><pre>";
|
||||
|
||||
@@ -13,17 +13,14 @@ use PayPal\Api\Payment;
|
||||
|
||||
$paymentId = "PAY-0XL713371A312273YKE2GCNI";
|
||||
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
Payment::setCredential($cred);
|
||||
// ### Retrieve payment
|
||||
// Retrieve the payment object by calling the
|
||||
// static `get` method
|
||||
// on the Payment class by passing a valid
|
||||
// Payment ID
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payment = Payment::get($paymentId);
|
||||
$payment = Payment::get($paymentId, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
|
||||
@@ -12,12 +12,6 @@
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Payment;
|
||||
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
// If you skip this step, the client id/secret
|
||||
// set in the config file will be used.
|
||||
Payment::setCredential($cred);
|
||||
|
||||
// ### Retrieve payment
|
||||
// Retrieve the PaymentHistory object by calling the
|
||||
@@ -25,8 +19,9 @@ Payment::setCredential($cred);
|
||||
// and pass a Map object that contains
|
||||
// query parameters for paginations and filtering.
|
||||
// Refer the method doc for valid values for keys
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$payments = Payment::all(array('count' => 10, 'start_index' => 5));
|
||||
$payments = Payment::all(array('count' => 10, 'start_index' => 5), $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
|
||||
@@ -9,17 +9,12 @@ require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Sale;
|
||||
|
||||
$saleId = '3RM92092UW5126232';
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
// If you skip this step, the client id/secret
|
||||
// set in the config file will be used.
|
||||
Sale::setCredential($cred);
|
||||
|
||||
try {
|
||||
// ### Retrieve the sale object
|
||||
// Pass the ID of the sale
|
||||
// transaction from your payment resource.
|
||||
$sale = Sale::get($saleId);
|
||||
$sale = Sale::get($saleId, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
|
||||
@@ -10,7 +10,6 @@ require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Refund;
|
||||
use PayPal\Api\Sale;
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
// ### Refund
|
||||
// Create a refund object indicating
|
||||
@@ -31,14 +30,9 @@ $saleId = '3RM92092UW5126232';
|
||||
$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
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
$sale->refund($refund, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
;Account credentials from developer portal
|
||||
[Account]
|
||||
acct1.ClientId = EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM
|
||||
acct1.ClientSecret = EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM
|
||||
|
||||
|
||||
;Connection Information
|
||||
[Http]
|
||||
http.ConnectionTimeOut = 30
|
||||
@@ -13,10 +7,7 @@ http.Retry = 1
|
||||
|
||||
;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"
|
||||
|
||||
mode=sandbox ; can be set to sandbox / live
|
||||
|
||||
;Logging Information
|
||||
[Log]
|
||||
|
||||
@@ -7,9 +7,7 @@ a payment in the future.
|
||||
The following code demonstrates how
|
||||
can save a Credit Card on PayPal using
|
||||
the Vault API.
|
||||
API used: POST /v1/vault/credit-card</p></div></div><div class="code"><div class="wrapper"><span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||
|
||||
<span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
API used: POST /v1/vault/credit-card</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3>
|
||||
|
||||
@@ -21,18 +19,14 @@ used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><s
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">"2019"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">"012"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">"Joe"</span><span class="p">);</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="save-card">Save card</h3>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">"Shopper"</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="save-card">Save card</h3>
|
||||
|
||||
<p>Creates the credit card as a resource
|
||||
in the PayPal vault. The response contains
|
||||
an 'id' that you can use to refer to it
|
||||
in the future payments.</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">create</span><span class="p">();</span>
|
||||
in the future payments.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$card</span><span class="o">-></span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
|
||||
@@ -9,8 +9,7 @@ API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrap
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="address">Address</h3>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="address">Address</h3>
|
||||
|
||||
<p>Base Address object used as shipping or billing
|
||||
address in a payment. [Optional]</p></div></div><div class="code"><div class="wrapper"><span class="nv">$addr</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Address</span><span class="p">();</span>
|
||||
@@ -61,20 +60,15 @@ a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="co
|
||||
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
<p>Create a payment by posting to the APIService
|
||||
using a valid ApiContext
|
||||
using a valid ApiContext (See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the status;</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="x"> <pre></span><span class="cp"><?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?></span><span class="x"></pre></span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
<span class="cp">?></span><span class="x"></span>
|
||||
|
||||
@@ -10,7 +10,6 @@ API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrap
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\RedirectUrls</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||
<span class="nb">session_start</span><span class="p">();</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="payer">Payer</h3>
|
||||
|
||||
<p>A resource representing a Payer that funds a payment
|
||||
@@ -40,15 +39,11 @@ the above types and intent as 'sale'</p></div></div><div class="code"><div class
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setRedirect_urls</span><span class="p">(</span><span class="nv">$redirectUrls</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
<p>Create a payment by posting to the APIService
|
||||
using a valid apiContext
|
||||
using a valid apiContext.
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the status and the
|
||||
url to which the buyer must be redirected to
|
||||
for payment approval</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
@@ -57,13 +52,13 @@ for payment approval</p></div></div><div class="code"><div class="wrapper"><span
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="redirect-buyer-to-paypal">Redirect buyer to paypal</h3>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="redirect-buyer-to-paypal">Redirect buyer to paypal</h3>
|
||||
|
||||
<p>Retrieve buyer approval url from the <code>payment</code> object.</p></div></div><div class="code"><div class="wrapper"><span class="k">foreach</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">getLinks</span><span class="p">()</span> <span class="k">as</span> <span class="nv">$link</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="nv">$link</span><span class="o">-></span><span class="na">getRel</span><span class="p">()</span> <span class="o">==</span> <span class="s1">'approval_url'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nv">$redirectUrl</span> <span class="o">=</span> <span class="nv">$link</span><span class="o">-></span><span class="na">getHref</span><span class="p">();</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow">¶</a></div><div class="wrapper"><p>It is not really a great idea to store the payment id
|
||||
<span class="p">}</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><p>It is not really a great idea to store the payment id
|
||||
in the session. In a real world app, please store the
|
||||
payment id in a database.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$payment</span><span class="o">-></span><span class="na">getId</span><span class="p">();</span>
|
||||
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$redirectUrl</span><span class="p">))</span> <span class="p">{</span>
|
||||
|
||||
@@ -12,8 +12,7 @@ API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrap
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\FundingInstrument</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\RedirectUrls</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Transaction</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Auth\OAuthTokenCredential</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="credit-card-token">Credit card token</h3>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Auth\OAuthTokenCredential</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="credit-card-token">Credit card token</h3>
|
||||
|
||||
<p>Saved credit card id from a previous call to
|
||||
CreateCreditCard.php</p></div></div><div class="code"><div class="wrapper"><span class="nv">$creditCardId</span> <span class="o">=</span> <span class="s1">'CARD-5BT058015C739554AKE2GCEI'</span><span class="p">;</span>
|
||||
@@ -48,15 +47,10 @@ a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="co
|
||||
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setIntent</span><span class="p">(</span><span class="s2">"sale"</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setPayer</span><span class="p">(</span><span class="nv">$payer</span><span class="p">);</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">setTransactions</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$transaction</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
|
||||
|
||||
<p>Create a payment by posting to the APIService
|
||||
using a valid apiContext
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)
|
||||
The return object contains the status;</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
|
||||
@@ -9,27 +9,19 @@ API used: POST '/v1/payments/payment/<payment-id>/execute'.</p></div></div><div
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\ExecutePayment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\PaymentExecution</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span>
|
||||
<span class="nb">session_start</span><span class="p">();</span>
|
||||
|
||||
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">])</span> <span class="o">&&</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'true'</span><span class="p">)</span> <span class="p">{</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"> <span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||
</div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">])</span> <span class="o">&&</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">'success'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'true'</span><span class="p">)</span> <span class="p">{</span>
|
||||
</div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><p>Get the payment Object by passing paymentId
|
||||
payment id was previously stored in session in
|
||||
CreatePaymentUsingPayPal.php</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$paymentId</span> <span class="o">=</span> <span class="nv">$_SESSION</span><span class="p">[</span><span class="s1">'paymentId'</span><span class="p">];</span>
|
||||
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">);</span>
|
||||
</div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
</div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><p>PaymentExecution object includes information necessary
|
||||
to execute a PayPal account payment.
|
||||
The payer_id is added to the request query parameters
|
||||
when the user is redirected from paypal back to your site</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$execution</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">PaymentExecution</span><span class="p">();</span>
|
||||
<span class="nv">$execution</span><span class="o">-></span><span class="na">setPayer_id</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">'PayerID'</span><span class="p">]);</span>
|
||||
|
||||
<span class="c1">//Execute the payment</span>
|
||||
<span class="nv">$payment</span><span class="o">-></span><span class="na">execute</span><span class="p">(</span><span class="nv">$execution</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="c1">//Execute the payment</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><p>(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$payment</span><span class="o">-></span><span class="na">execute</span><span class="p">(</span><span class="nv">$execution</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
|
||||
<span class="k">echo</span> <span class="s2">"<html><body><pre>"</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-></span><span class="na">toArray</span><span class="p">());</span>
|
||||
|
||||
@@ -7,15 +7,10 @@ by sending a GET request to the URI
|
||||
The following code takes you through
|
||||
the process of retrieving a saved CreditCard</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><p>The cardId can be obtained from a previous save credit
|
||||
card operation. Use $card->getId()</p></div></div><div class="code"><div class="wrapper"><span class="nv">$cardId</span> <span class="o">=</span> <span class="s2">"CARD-5BT058015C739554AKE2GCEI"</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
card operation. Use $card->getId()</p></div></div><div class="code"><div class="wrapper"><span class="nv">$cardId</span> <span class="o">=</span> <span class="s2">"CARD-5BT058015C739554AKE2GCEI"</span><span class="p">;</span>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call.
|
||||
If you skip this step, the client id/secret
|
||||
set in the config file will be used.</p></div></div><div class="code"><div class="wrapper"><span class="nx">CreditCard</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||
<span class="c1">/// ### Retrieve card</span>
|
||||
<span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$card</span> <span class="o">=</span> <span class="nx">CreditCard</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$cardId</span><span class="p">);</span>
|
||||
<span class="c1">/// ### Retrieve card</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><p>(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$card</span> <span class="o">=</span> <span class="nx">CreditCard</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$cardId</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception: "</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
|
||||
@@ -9,16 +9,14 @@ payments list.
|
||||
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span>
|
||||
|
||||
<span class="nv">$paymentId</span> <span class="o">=</span> <span class="s2">"PAY-0XL713371A312273YKE2GCNI"</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
<span class="nv">$paymentId</span> <span class="o">=</span> <span class="s2">"PAY-0XL713371A312273YKE2GCNI"</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
|
||||
<p>Retrieve the payment object by calling the
|
||||
static <code>get</code> method
|
||||
on the Payment class by passing a valid
|
||||
Payment ID</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">);</span>
|
||||
Payment ID
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payment</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$paymentId</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
|
||||
@@ -5,16 +5,12 @@ details of completed Sale Transaction.
|
||||
API used: /v1/payments/sale/{sale-id}</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Sale</span><span class="p">;</span>
|
||||
|
||||
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">'3RM92092UW5126232'</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">'3RM92092UW5126232'</span><span class="p">;</span>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call.
|
||||
If you skip this step, the client id/secret
|
||||
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Sale</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
|
||||
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
|
||||
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
|
||||
|
||||
<p>Pass the ID of the sale
|
||||
transaction from your payment resource.</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span> <span class="o">=</span> <span class="nx">Sale</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">);</span>
|
||||
transaction from your payment resource.</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span> <span class="o">=</span> <span class="nx">Sale</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
|
||||
@@ -7,19 +7,15 @@ Note various query parameters that you can
|
||||
use to filter, and paginate through the
|
||||
payments list.
|
||||
API used: GET /v1/payments/payments</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="authentication">Authentication</h3>
|
||||
|
||||
<p>Pass in a <code>OAuthTokenCredential</code> object
|
||||
explicilty to authenticate the call.
|
||||
If you skip this step, the client id/secret
|
||||
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Payment</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
|
||||
|
||||
<p>Retrieve the PaymentHistory object by calling the
|
||||
static <code>get</code> method on the Payment class,
|
||||
and pass a Map object that contains
|
||||
query parameters for paginations and filtering.
|
||||
Refer the method doc for valid values for keys</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payments</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">all</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'count'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'start_index'</span> <span class="o">=></span> <span class="mi">5</span><span class="p">));</span>
|
||||
Refer the method doc for valid values for keys
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
|
||||
<span class="nv">$payments</span> <span class="o">=</span> <span class="nx">Payment</span><span class="o">::</span><span class="na">all</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'count'</span> <span class="o">=></span> <span class="mi">10</span><span class="p">,</span> <span class="s1">'start_index'</span> <span class="o">=></span> <span class="mi">5</span><span class="p">),</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
|
||||
@@ -6,8 +6,7 @@ using the Payments API.
|
||||
API used: /v1/payments/sale/{sale-id}/refund</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">'/../bootstrap.php'</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Refund</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Sale</span><span class="p">;</span>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
<span class="k">use</span> <span class="nx">PayPal\Api\Sale</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="refund">Refund</h3>
|
||||
|
||||
<p>Create a refund object indicating
|
||||
refund amount</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amt</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
|
||||
@@ -22,13 +21,10 @@ refund amount</p></div></div><div class="code"><div class="wrapper"><span class=
|
||||
<p>A sale transaction.
|
||||
Create a Sale object with the
|
||||
given sale transaction id.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$sale</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Sale</span><span class="p">();</span>
|
||||
<span class="nv">$sale</span><span class="o">-></span><span class="na">setId</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
|
||||
<span class="nv">$sale</span><span class="o">-></span><span class="na">setId</span><span class="p">(</span><span class="nv">$saleId</span><span class="p">);</span>
|
||||
|
||||
<p>Pass in a <code>ApiContext</code> object to authenticate
|
||||
the call and to send a unique request id
|
||||
(that ensures idempotency). The SDK generates
|
||||
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"><span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">,</span> <span class="s1">'Request'</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span>
|
||||
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow">¶</a></div><div class="wrapper"><p>Refund the sale</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span><span class="o">-></span><span class="na">refund</span><span class="p">(</span><span class="nv">$refund</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow">¶</a></div><div class="wrapper"><p>Refund the sale
|
||||
(See bootstrap.php for more on <code>ApiContext</code>)</p></div></div><div class="code"><div class="wrapper"> <span class="nv">$sale</span><span class="o">-></span><span class="na">refund</span><span class="p">(</span><span class="nv">$refund</span><span class="p">,</span> <span class="nv">$apiContext</span><span class="p">);</span>
|
||||
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">\PPConnectionException</span> <span class="nv">$ex</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">echo</span> <span class="s2">"Exception:"</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-></span><span class="na">getMessage</span><span class="p">()</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span>
|
||||
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-></span><span class="na">getData</span><span class="p">());</span>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
// the Vault API.
|
||||
// API used: POST /v1/vault/credit-card
|
||||
|
||||
use PayPal\Rest\ApiContext;
|
||||
|
||||
require __DIR__ . '/../bootstrap.php';
|
||||
use PayPal\Api\CreditCard;
|
||||
@@ -28,20 +27,14 @@ $card->setCvv2("012");
|
||||
$card->setFirst_name("Joe");
|
||||
$card->setLast_name("Shopper");
|
||||
|
||||
// ### Api Context
|
||||
// Pass in a `ApiContext` object to authenticate
|
||||
// the call and to send a unique request id
|
||||
// (that ensures idempotency). The SDK generates
|
||||
// a request id if you do not pass one explicitly.
|
||||
$apiContext = new ApiContext($cred, 'Request' . time());
|
||||
|
||||
// ### Save card
|
||||
// Creates the credit card as a resource
|
||||
// in the PayPal vault. The response contains
|
||||
// an 'id' that you can use to refer to it
|
||||
// in the future payments.
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$card->create();
|
||||
$card->create($apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception:" . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
|
||||
@@ -14,15 +14,10 @@ use PayPal\Api\CreditCard;
|
||||
// card operation. Use $card->getId()
|
||||
$cardId = "CARD-5BT058015C739554AKE2GCEI";
|
||||
|
||||
// ### Authentication
|
||||
// Pass in a `OAuthTokenCredential` object
|
||||
// explicilty to authenticate the call.
|
||||
// If you skip this step, the client id/secret
|
||||
// set in the config file will be used.
|
||||
CreditCard::setCredential($cred);
|
||||
/// ### Retrieve card
|
||||
// (See bootstrap.php for more on `ApiContext`)
|
||||
try {
|
||||
$card = CreditCard::get($cardId);
|
||||
$card = CreditCard::get($cardId, $apiContext);
|
||||
} catch (\PPConnectionException $ex) {
|
||||
echo "Exception: " . $ex->getMessage() . PHP_EOL;
|
||||
var_dump($ex->getData());
|
||||
|
||||
@@ -9,12 +9,13 @@ class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testGetAccessToken() {
|
||||
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
|
||||
$config = \PPConfigManager::getInstance()->getConfigHashmap();
|
||||
|
||||
$token = $cred->getAccessToken();
|
||||
$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();
|
||||
$newToken = $cred->getAccessToken($config);
|
||||
$this->assertNotNull($newToken);
|
||||
$this->assertEquals($token, $newToken);
|
||||
|
||||
@@ -28,6 +29,6 @@ class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
|
||||
public function testInvalidCredentials() {
|
||||
$this->setExpectedException('\PPConnectionException');
|
||||
$cred = new OAuthTokenCredential('dummy', 'secret');
|
||||
$this->assertNull($cred->getAccessToken());
|
||||
$this->assertNull($cred->getAccessToken(\PPConfigManager::getInstance()->getConfigHashmap()));
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\ArrayUtil;
|
||||
|
||||
class ArrayUtilTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testIsAssocArray() {
|
||||
|
||||
$arr = array(1, 2, 3);
|
||||
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
|
||||
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr = array(
|
||||
'name' => 'John Doe',
|
||||
'City' => 'San Jose'
|
||||
);
|
||||
$this->assertEquals(true, ArrayUtil::isAssocArray($arr));
|
||||
$this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr[] = 'CA';
|
||||
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
|
||||
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\Model;
|
||||
|
||||
class SimpleClass extends Model {
|
||||
class SimpleClass extends \PPModel {
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
@@ -21,7 +20,7 @@ class SimpleClass extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
class ArrayClass extends Model {
|
||||
class ArrayClass extends \PPModel {
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
@@ -48,7 +47,7 @@ class ArrayClass extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
class NestedClass extends Model {
|
||||
class NestedClass extends \PPModel {
|
||||
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
@@ -64,6 +63,10 @@ class NestedClass extends Model {
|
||||
public function setInfo($info) {
|
||||
$this->info = $info;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return ArrayClass
|
||||
*/
|
||||
public function getInfo() {
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use PayPal\Common\UserAgent;
|
||||
class UserAgentTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testGetValue() {
|
||||
$ua = UserAgent::getValue();
|
||||
$ua = PPUserAgent::getValue("name", "version");
|
||||
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
|
||||
|
||||
// Check that we pass the useragent in the expected format
|
||||
@@ -13,6 +13,9 @@ class UserAgentTest extends PHPUnit_Framework_TestCase {
|
||||
$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="));
|
||||
|
||||
Reference in New Issue
Block a user