Merge branch 'dynamicconfig'

This commit is contained in:
aydiv
2013-04-26 16:42:04 +05:30
62 changed files with 1667 additions and 1797 deletions

View File

@@ -1,7 +1,13 @@
CHANGELOG CHANGELOG
========= =========
V0.5.0 (March 07, 2013) V0.6.0 (April 26, 2013)
----------------------- -----------------------
* Initial Release * 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)
-----------------------
* Initial Release

View File

@@ -1,4 +1,4 @@
REST API SDK for PHP (V0.5.0) [![Build Status](https://travis-ci.org/paypal/rest-api-sdk-php.png?branch=master)](https://travis-ci.org/paypal/rest-api-sdk-php) REST API SDK for PHP (V0.6.0) [![Build Status](https://travis-ci.org/paypal/rest-api-sdk-php.png?branch=master)](https://travis-ci.org/paypal/rest-api-sdk-php)
============================== ==============================
This repository contains PayPal's PHP SDK and samples for REST API. This repository contains PayPal's PHP SDK and samples for REST API.

View File

@@ -15,7 +15,7 @@
"php": ">=5.3.0", "php": ">=5.3.0",
"ext-curl": "*", "ext-curl": "*",
"ext-json": "*", "ext-json": "*",
"paypal/sdk-core-php": "1.2.*" "paypal/sdk-core-php": "1.4.*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "3.7.*" "phpunit/phpunit": "3.7.*"
@@ -25,4 +25,4 @@
"PayPal": "lib/" "PayPal": "lib/"
} }
} }
} }

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Address extends Resource { class Address extends Resource {
@@ -18,6 +18,7 @@ class Address extends Resource {
/** /**
* Getter for line1 * Getter for line1
* @return string
*/ */
public function getLine1() { public function getLine1() {
return $this->line1; return $this->line1;
@@ -33,6 +34,7 @@ class Address extends Resource {
/** /**
* Getter for line2 * Getter for line2
* @return string
*/ */
public function getLine2() { public function getLine2() {
return $this->line2; return $this->line2;
@@ -48,6 +50,7 @@ class Address extends Resource {
/** /**
* Getter for city * Getter for city
* @return string
*/ */
public function getCity() { public function getCity() {
return $this->city; return $this->city;
@@ -63,6 +66,7 @@ class Address extends Resource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -78,6 +82,7 @@ class Address extends Resource {
/** /**
* Getter for postal_code * Getter for postal_code
* @return string
*/ */
public function getPostal_code() { public function getPostal_code() {
return $this->postal_code; return $this->postal_code;
@@ -93,6 +98,7 @@ class Address extends Resource {
/** /**
* Getter for country_code * Getter for country_code
* @return string
*/ */
public function getCountry_code() { public function getCountry_code() {
return $this->country_code; return $this->country_code;
@@ -108,6 +114,7 @@ class Address extends Resource {
/** /**
* Getter for type * Getter for type
* @return string
*/ */
public function getType() { public function getType() {
return $this->type; return $this->type;
@@ -123,6 +130,7 @@ class Address extends Resource {
/** /**
* Getter for phone * Getter for phone
* @return string
*/ */
public function getPhone() { public function getPhone() {
return $this->phone; return $this->phone;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Amount extends Resource { class Amount extends Resource {
@@ -18,6 +18,7 @@ class Amount extends Resource {
/** /**
* Getter for total * Getter for total
* @return string
*/ */
public function getTotal() { public function getTotal() {
return $this->total; return $this->total;
@@ -33,6 +34,7 @@ class Amount extends Resource {
/** /**
* Getter for currency * Getter for currency
* @return string
*/ */
public function getCurrency() { public function getCurrency() {
return $this->currency; return $this->currency;
@@ -48,6 +50,7 @@ class Amount extends Resource {
/** /**
* Getter for details * Getter for details
* @return PayPal\Api\AmountDetails
*/ */
public function getDetails() { public function getDetails() {
return $this->details; return $this->details;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class AmountDetails extends Resource { class AmountDetails extends Resource {
@@ -18,6 +18,7 @@ class AmountDetails extends Resource {
/** /**
* Getter for subtotal * Getter for subtotal
* @return string
*/ */
public function getSubtotal() { public function getSubtotal() {
return $this->subtotal; return $this->subtotal;
@@ -33,6 +34,7 @@ class AmountDetails extends Resource {
/** /**
* Getter for tax * Getter for tax
* @return string
*/ */
public function getTax() { public function getTax() {
return $this->tax; return $this->tax;
@@ -48,6 +50,7 @@ class AmountDetails extends Resource {
/** /**
* Getter for shipping * Getter for shipping
* @return string
*/ */
public function getShipping() { public function getShipping() {
return $this->shipping; return $this->shipping;
@@ -63,6 +66,7 @@ class AmountDetails extends Resource {
/** /**
* Getter for fee * Getter for fee
* @return string
*/ */
public function getFee() { public function getFee() {
return $this->fee; return $this->fee;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Authorization extends Resource { class Authorization extends Resource {
@@ -18,6 +18,7 @@ class Authorization extends Resource {
/** /**
* Getter for id * Getter for id
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@@ -33,6 +34,7 @@ class Authorization extends Resource {
/** /**
* Getter for create_time * Getter for create_time
* @return string
*/ */
public function getCreate_time() { public function getCreate_time() {
return $this->create_time; return $this->create_time;
@@ -48,6 +50,7 @@ class Authorization extends Resource {
/** /**
* Getter for update_time * Getter for update_time
* @return string
*/ */
public function getUpdate_time() { public function getUpdate_time() {
return $this->update_time; return $this->update_time;
@@ -63,6 +66,7 @@ class Authorization extends Resource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -78,6 +82,7 @@ class Authorization extends Resource {
/** /**
* Getter for amount * Getter for amount
* @return PayPal\Api\Amount
*/ */
public function getAmount() { public function getAmount() {
return $this->amount; return $this->amount;
@@ -93,6 +98,7 @@ class Authorization extends Resource {
/** /**
* Getter for parent_payment * Getter for parent_payment
* @return string
*/ */
public function getParent_payment() { public function getParent_payment() {
return $this->parent_payment; return $this->parent_payment;
@@ -108,6 +114,7 @@ class Authorization extends Resource {
/** /**
* Getter for links * Getter for links
* @return PayPal\Api\Link
*/ */
public function getLinks() { public function getLinks() {
return $this->links; return $this->links;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Capture extends Resource { class Capture extends Resource {
@@ -18,6 +18,7 @@ class Capture extends Resource {
/** /**
* Getter for id * Getter for id
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@@ -33,6 +34,7 @@ class Capture extends Resource {
/** /**
* Getter for create_time * Getter for create_time
* @return string
*/ */
public function getCreate_time() { public function getCreate_time() {
return $this->create_time; return $this->create_time;
@@ -48,6 +50,7 @@ class Capture extends Resource {
/** /**
* Getter for update_time * Getter for update_time
* @return string
*/ */
public function getUpdate_time() { public function getUpdate_time() {
return $this->update_time; return $this->update_time;
@@ -63,6 +66,7 @@ class Capture extends Resource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -78,6 +82,7 @@ class Capture extends Resource {
/** /**
* Getter for amount * Getter for amount
* @return PayPal\Api\Amount
*/ */
public function getAmount() { public function getAmount() {
return $this->amount; return $this->amount;
@@ -93,6 +98,7 @@ class Capture extends Resource {
/** /**
* Getter for parent_payment * Getter for parent_payment
* @return string
*/ */
public function getParent_payment() { public function getParent_payment() {
return $this->parent_payment; return $this->parent_payment;
@@ -108,6 +114,7 @@ class Capture extends Resource {
/** /**
* Getter for authorization_id * Getter for authorization_id
* @return string
*/ */
public function getAuthorization_id() { public function getAuthorization_id() {
return $this->authorization_id; return $this->authorization_id;
@@ -123,6 +130,7 @@ class Capture extends Resource {
/** /**
* Getter for description * Getter for description
* @return string
*/ */
public function getDescription() { public function getDescription() {
return $this->description; return $this->description;
@@ -138,6 +146,7 @@ class Capture extends Resource {
/** /**
* Getter for links * Getter for links
* @return PayPal\Api\Link
*/ */
public function getLinks() { public function getLinks() {
return $this->links; return $this->links;

View File

@@ -6,12 +6,16 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext; use PayPal\Rest\ApiContext;
/** /**
* *
*/ */
class CreditCard extends Resource implements IResource { class CreditCard extends Resource implements IResource {
private static $credential; private static $credential;
/**
*
* @deprected. Pass ApiContext to create/get methods instead
*/
public static function setCredential($credential) { public static function setCredential($credential) {
self::$credential = $credential; self::$credential = $credential;
} }
@@ -26,6 +30,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for id * Getter for id
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@@ -41,6 +46,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for valid_until * Getter for valid_until
* @return string
*/ */
public function getValid_until() { public function getValid_until() {
return $this->valid_until; return $this->valid_until;
@@ -56,6 +62,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -71,6 +78,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for payer_id * Getter for payer_id
* @return string
*/ */
public function getPayer_id() { public function getPayer_id() {
return $this->payer_id; return $this->payer_id;
@@ -86,6 +94,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for type * Getter for type
* @return string
*/ */
public function getType() { public function getType() {
return $this->type; return $this->type;
@@ -101,6 +110,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for number * Getter for number
* @return string
*/ */
public function getNumber() { public function getNumber() {
return $this->number; return $this->number;
@@ -116,6 +126,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for expire_month * Getter for expire_month
* @return string
*/ */
public function getExpire_month() { public function getExpire_month() {
return $this->expire_month; return $this->expire_month;
@@ -131,6 +142,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for expire_year * Getter for expire_year
* @return string
*/ */
public function getExpire_year() { public function getExpire_year() {
return $this->expire_year; return $this->expire_year;
@@ -146,6 +158,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for cvv2 * Getter for cvv2
* @return string
*/ */
public function getCvv2() { public function getCvv2() {
return $this->cvv2; return $this->cvv2;
@@ -161,6 +174,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for first_name * Getter for first_name
* @return string
*/ */
public function getFirst_name() { public function getFirst_name() {
return $this->first_name; return $this->first_name;
@@ -176,6 +190,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for last_name * Getter for last_name
* @return string
*/ */
public function getLast_name() { public function getLast_name() {
return $this->last_name; return $this->last_name;
@@ -191,6 +206,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for billing_address * Getter for billing_address
* @return PayPal\Api\Address
*/ */
public function getBilling_address() { public function getBilling_address() {
return $this->billing_address; return $this->billing_address;
@@ -206,6 +222,7 @@ class CreditCard extends Resource implements IResource {
/** /**
* Getter for links * Getter for links
* @return PayPal\Api\Link
*/ */
public function getLinks() { public function getLinks() {
return $this->links; return $this->links;
@@ -217,15 +234,17 @@ class CreditCard extends Resource implements IResource {
* @path /v1/vault/credit-card * @path /v1/vault/credit-card
* @method POST * @method POST
* @param PayPal\Rest\ApiContext $apiContext optional * @param PayPal\Rest\ApiContext $apiContext optional
*/ */
public function create( $apiContext=null) { public function create( $apiContext=null) {
$payLoad = $this->toJSON(); $payLoad = $this->toJSON();
if($apiContext == null) { if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $apiContext = new ApiContext(self::$credential);
} }
$call = new Call(); $call = new \PPRestCall($apiContext);
$json = $call->execute("/v1/vault/credit-card", "POST", $payLoad, $apiContext); $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/vault/credit-card",
"POST", $payLoad);
$this->fromJson($json); $this->fromJson($json);
return $this; return $this;
} }
@@ -233,16 +252,21 @@ class CreditCard extends Resource implements IResource {
/** /**
* @path /v1/vault/credit-card/:credit-card-id * @path /v1/vault/credit-card/:credit-card-id
* @method GET * @method GET
* @param string $creditcardid * @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)) { if (($creditcardid == null) || (strlen($creditcardid) <= 0)) {
throw new \InvalidArgumentException("creditcardid cannot be null or empty"); throw new \InvalidArgumentException("creditcardid cannot be null or empty");
} }
$payLoad = ""; $payLoad = "";
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $call = new Call(); $apiContext = new ApiContext(self::$credential);
$json = $call->execute("/v1/vault/credit-card/$creditcardid", "GET", $payLoad, $apiContext); }
$call = new \PPRestCall($apiContext);
$json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/vault/credit-card/$creditcardid",
"GET", $payLoad);
$ret = new CreditCard(); $ret = new CreditCard();
$ret->fromJson($json); $ret->fromJson($json);
return $ret; return $ret;
@@ -250,4 +274,4 @@ class CreditCard extends Resource implements IResource {
} }
} }

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class CreditCardToken extends Resource { class CreditCardToken extends Resource {
@@ -18,6 +18,7 @@ class CreditCardToken extends Resource {
/** /**
* Getter for credit_card_id * Getter for credit_card_id
* @return string
*/ */
public function getCredit_card_id() { public function getCredit_card_id() {
return $this->credit_card_id; return $this->credit_card_id;
@@ -33,6 +34,7 @@ class CreditCardToken extends Resource {
/** /**
* Getter for payer_id * Getter for payer_id
* @return string
*/ */
public function getPayer_id() { public function getPayer_id() {
return $this->payer_id; return $this->payer_id;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class FundingInstrument extends Resource { class FundingInstrument extends Resource {
@@ -18,6 +18,7 @@ class FundingInstrument extends Resource {
/** /**
* Getter for credit_card * Getter for credit_card
* @return PayPal\Api\CreditCard
*/ */
public function getCredit_card() { public function getCredit_card() {
return $this->credit_card; return $this->credit_card;
@@ -33,6 +34,7 @@ class FundingInstrument extends Resource {
/** /**
* Getter for credit_card_token * Getter for credit_card_token
* @return PayPal\Api\CreditCardToken
*/ */
public function getCredit_card_token() { public function getCredit_card_token() {
return $this->credit_card_token; return $this->credit_card_token;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Item extends Resource { class Item extends Resource {
@@ -18,6 +18,7 @@ class Item extends Resource {
/** /**
* Getter for name * Getter for name
* @return string
*/ */
public function getName() { public function getName() {
return $this->name; return $this->name;
@@ -33,6 +34,7 @@ class Item extends Resource {
/** /**
* Getter for sku * Getter for sku
* @return string
*/ */
public function getSku() { public function getSku() {
return $this->sku; return $this->sku;
@@ -48,6 +50,7 @@ class Item extends Resource {
/** /**
* Getter for price * Getter for price
* @return string
*/ */
public function getPrice() { public function getPrice() {
return $this->price; return $this->price;
@@ -63,6 +66,7 @@ class Item extends Resource {
/** /**
* Getter for currency * Getter for currency
* @return string
*/ */
public function getCurrency() { public function getCurrency() {
return $this->currency; return $this->currency;
@@ -78,6 +82,7 @@ class Item extends Resource {
/** /**
* Getter for quantity * Getter for quantity
* @return string
*/ */
public function getQuantity() { public function getQuantity() {
return $this->quantity; return $this->quantity;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class ItemList extends Resource { class ItemList extends Resource {
@@ -18,6 +18,7 @@ class ItemList extends Resource {
/** /**
* Getter for items * Getter for items
* @return PayPal\Api\Item
*/ */
public function getItems() { public function getItems() {
return $this->items; return $this->items;
@@ -33,6 +34,7 @@ class ItemList extends Resource {
/** /**
* Getter for shipping_address * Getter for shipping_address
* @return PayPal\Api\ShippingAddress
*/ */
public function getShipping_address() { public function getShipping_address() {
return $this->shipping_address; return $this->shipping_address;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Link extends Resource { class Link extends Resource {
@@ -18,6 +18,7 @@ class Link extends Resource {
/** /**
* Getter for href * Getter for href
* @return string
*/ */
public function getHref() { public function getHref() {
return $this->href; return $this->href;
@@ -33,6 +34,7 @@ class Link extends Resource {
/** /**
* Getter for rel * Getter for rel
* @return string
*/ */
public function getRel() { public function getRel() {
return $this->rel; return $this->rel;
@@ -48,6 +50,7 @@ class Link extends Resource {
/** /**
* Getter for method * Getter for method
* @return string
*/ */
public function getMethod() { public function getMethod() {
return $this->method; return $this->method;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Payee extends Resource { class Payee extends Resource {
@@ -18,6 +18,7 @@ class Payee extends Resource {
/** /**
* Getter for merchant_id * Getter for merchant_id
* @return string
*/ */
public function getMerchant_id() { public function getMerchant_id() {
return $this->merchant_id; return $this->merchant_id;
@@ -33,6 +34,7 @@ class Payee extends Resource {
/** /**
* Getter for email * Getter for email
* @return string
*/ */
public function getEmail() { public function getEmail() {
return $this->email; return $this->email;
@@ -48,6 +50,7 @@ class Payee extends Resource {
/** /**
* Getter for phone * Getter for phone
* @return string
*/ */
public function getPhone() { public function getPhone() {
return $this->phone; return $this->phone;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Payer extends Resource { class Payer extends Resource {
@@ -18,6 +18,7 @@ class Payer extends Resource {
/** /**
* Getter for payment_method * Getter for payment_method
* @return string
*/ */
public function getPayment_method() { public function getPayment_method() {
return $this->payment_method; return $this->payment_method;
@@ -33,6 +34,7 @@ class Payer extends Resource {
/** /**
* Getter for payer_info * Getter for payer_info
* @return PayPal\Api\PayerInfo
*/ */
public function getPayer_info() { public function getPayer_info() {
return $this->payer_info; return $this->payer_info;
@@ -48,6 +50,7 @@ class Payer extends Resource {
/** /**
* Getter for funding_instruments * Getter for funding_instruments
* @return PayPal\Api\FundingInstrument
*/ */
public function getFunding_instruments() { public function getFunding_instruments() {
return $this->funding_instruments; return $this->funding_instruments;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class PayerInfo extends Resource { class PayerInfo extends Resource {
@@ -18,6 +18,7 @@ class PayerInfo extends Resource {
/** /**
* Getter for email * Getter for email
* @return string
*/ */
public function getEmail() { public function getEmail() {
return $this->email; return $this->email;
@@ -33,6 +34,7 @@ class PayerInfo extends Resource {
/** /**
* Getter for first_name * Getter for first_name
* @return string
*/ */
public function getFirst_name() { public function getFirst_name() {
return $this->first_name; return $this->first_name;
@@ -48,6 +50,7 @@ class PayerInfo extends Resource {
/** /**
* Getter for last_name * Getter for last_name
* @return string
*/ */
public function getLast_name() { public function getLast_name() {
return $this->last_name; return $this->last_name;
@@ -63,6 +66,7 @@ class PayerInfo extends Resource {
/** /**
* Getter for payer_id * Getter for payer_id
* @return string
*/ */
public function getPayer_id() { public function getPayer_id() {
return $this->payer_id; return $this->payer_id;
@@ -78,6 +82,7 @@ class PayerInfo extends Resource {
/** /**
* Getter for shipping_address * Getter for shipping_address
* @return PayPal\Api\Address
*/ */
public function getShipping_address() { public function getShipping_address() {
return $this->shipping_address; return $this->shipping_address;
@@ -93,6 +98,7 @@ class PayerInfo extends Resource {
/** /**
* Getter for phone * Getter for phone
* @return string
*/ */
public function getPhone() { public function getPhone() {
return $this->phone; return $this->phone;

View File

@@ -6,12 +6,16 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext; use PayPal\Rest\ApiContext;
/** /**
* *
*/ */
class Payment extends Resource implements IResource { class Payment extends Resource implements IResource {
private static $credential; private static $credential;
/**
*
* @deprected. Pass ApiContext to create/get methods instead
*/
public static function setCredential($credential) { public static function setCredential($credential) {
self::$credential = $credential; self::$credential = $credential;
} }
@@ -26,6 +30,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for id * Getter for id
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@@ -41,6 +46,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for create_time * Getter for create_time
* @return string
*/ */
public function getCreate_time() { public function getCreate_time() {
return $this->create_time; return $this->create_time;
@@ -56,6 +62,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for update_time * Getter for update_time
* @return string
*/ */
public function getUpdate_time() { public function getUpdate_time() {
return $this->update_time; return $this->update_time;
@@ -71,6 +78,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -86,6 +94,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for intent * Getter for intent
* @return string
*/ */
public function getIntent() { public function getIntent() {
return $this->intent; return $this->intent;
@@ -101,6 +110,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for payer * Getter for payer
* @return PayPal\Api\Payer
*/ */
public function getPayer() { public function getPayer() {
return $this->payer; return $this->payer;
@@ -116,6 +126,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for transactions * Getter for transactions
* @return PayPal\Api\Transaction
*/ */
public function getTransactions() { public function getTransactions() {
return $this->transactions; return $this->transactions;
@@ -131,6 +142,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for redirect_urls * Getter for redirect_urls
* @return PayPal\Api\RedirectUrls
*/ */
public function getRedirect_urls() { public function getRedirect_urls() {
return $this->redirect_urls; return $this->redirect_urls;
@@ -146,6 +158,7 @@ class Payment extends Resource implements IResource {
/** /**
* Getter for links * Getter for links
* @return PayPal\Api\Link
*/ */
public function getLinks() { public function getLinks() {
return $this->links; return $this->links;
@@ -167,14 +180,19 @@ class Payment extends Resource implements IResource {
* payee_id, * payee_id,
* sort_by, * sort_by,
* sort_order, * sort_order,
* All other keys in the map are ignored by the SDK * All other keys in the map are ignored by the SDK
* @param PayPal\Rest\ApiContext $apiContext optional
*/ */
public static function all($params) { public static function all($params, $apiContext=null) {
$payLoad = ""; $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, ); $allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $call = new Call(); $apiContext = new ApiContext(self::$credential);
$json = $call->execute("/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad, $apiContext); }
$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 = new PaymentHistory();
$ret->fromJson($json); $ret->fromJson($json);
return $ret; return $ret;
@@ -185,15 +203,17 @@ class Payment extends Resource implements IResource {
* @path /v1/payments/payment * @path /v1/payments/payment
* @method POST * @method POST
* @param PayPal\Rest\ApiContext $apiContext optional * @param PayPal\Rest\ApiContext $apiContext optional
*/ */
public function create( $apiContext=null) { public function create( $apiContext=null) {
$payLoad = $this->toJSON(); $payLoad = $this->toJSON();
if($apiContext == null) { if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $apiContext = new ApiContext(self::$credential);
} }
$call = new Call(); $call = new \PPRestCall($apiContext);
$json = $call->execute("/v1/payments/payment", "POST", $payLoad, $apiContext); $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment",
"POST", $payLoad);
$this->fromJson($json); $this->fromJson($json);
return $this; return $this;
} }
@@ -201,16 +221,21 @@ class Payment extends Resource implements IResource {
/** /**
* @path /v1/payments/payment/:payment-id * @path /v1/payments/payment/:payment-id
* @method GET * @method GET
* @param string $paymentid * @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)) { if (($paymentid == null) || (strlen($paymentid) <= 0)) {
throw new \InvalidArgumentException("paymentid cannot be null or empty"); throw new \InvalidArgumentException("paymentid cannot be null or empty");
} }
$payLoad = ""; $payLoad = "";
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $call = new Call(); $apiContext = new ApiContext(self::$credential);
$json = $call->execute("/v1/payments/payment/$paymentid", "GET", $payLoad, $apiContext); }
$call = new \PPRestCall($apiContext);
$json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment/$paymentid",
"GET", $payLoad);
$ret = new Payment(); $ret = new Payment();
$ret->fromJson($json); $ret->fromJson($json);
return $ret; return $ret;
@@ -221,7 +246,7 @@ class Payment extends Resource implements IResource {
* @path /v1/payments/payment/:payment-id/execute * @path /v1/payments/payment/:payment-id/execute
* @method POST * @method POST
* @param PaymentExecution $payment_execution * @param PaymentExecution $payment_execution
* @param PayPal\Rest\ApiContext $apiContext optional * @param PayPal\Rest\ApiContext $apiContext optional
*/ */
public function execute( $payment_execution, $apiContext=null) { public function execute( $payment_execution, $apiContext=null) {
if ($payment_execution == null) { if ($payment_execution == null) {
@@ -234,11 +259,13 @@ class Payment extends Resource implements IResource {
if($apiContext == null) { if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $apiContext = new ApiContext(self::$credential);
} }
$call = new Call(); $call = new \PPRestCall($apiContext);
$json = $call->execute("/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad, $apiContext); $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/payment/{$this->getId()}/execute",
"POST", $payLoad);
$this->fromJson($json); $this->fromJson($json);
return $this; return $this;
} }
} }

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class PaymentExecution extends Resource { class PaymentExecution extends Resource {
@@ -18,6 +18,7 @@ class PaymentExecution extends Resource {
/** /**
* Getter for payer_id * Getter for payer_id
* @return string
*/ */
public function getPayer_id() { public function getPayer_id() {
return $this->payer_id; return $this->payer_id;
@@ -33,6 +34,7 @@ class PaymentExecution extends Resource {
/** /**
* Getter for transactions * Getter for transactions
* @return PayPal\Api\Amount
*/ */
public function getTransactions() { public function getTransactions() {
return $this->transactions; return $this->transactions;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class PaymentHistory extends Resource { class PaymentHistory extends Resource {
@@ -18,6 +18,7 @@ class PaymentHistory extends Resource {
/** /**
* Getter for payments * Getter for payments
* @return PayPal\Api\Payment
*/ */
public function getPayments() { public function getPayments() {
return $this->payments; return $this->payments;
@@ -33,6 +34,7 @@ class PaymentHistory extends Resource {
/** /**
* Getter for count * Getter for count
* @return integer
*/ */
public function getCount() { public function getCount() {
return $this->count; return $this->count;
@@ -48,6 +50,7 @@ class PaymentHistory extends Resource {
/** /**
* Getter for next_id * Getter for next_id
* @return string
*/ */
public function getNext_id() { public function getNext_id() {
return $this->next_id; return $this->next_id;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class RedirectUrls extends Resource { class RedirectUrls extends Resource {
@@ -18,6 +18,7 @@ class RedirectUrls extends Resource {
/** /**
* Getter for return_url * Getter for return_url
* @return string
*/ */
public function getReturn_url() { public function getReturn_url() {
return $this->return_url; return $this->return_url;
@@ -33,6 +34,7 @@ class RedirectUrls extends Resource {
/** /**
* Getter for cancel_url * Getter for cancel_url
* @return string
*/ */
public function getCancel_url() { public function getCancel_url() {
return $this->cancel_url; return $this->cancel_url;

View File

@@ -6,12 +6,16 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext; use PayPal\Rest\ApiContext;
/** /**
* *
*/ */
class Refund extends Resource implements IResource { class Refund extends Resource implements IResource {
private static $credential; private static $credential;
/**
*
* @deprected. Pass ApiContext to the get method instead
*/
public static function setCredential($credential) { public static function setCredential($credential) {
self::$credential = $credential; self::$credential = $credential;
} }
@@ -26,6 +30,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for id * Getter for id
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@@ -41,6 +46,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for create_time * Getter for create_time
* @return string
*/ */
public function getCreate_time() { public function getCreate_time() {
return $this->create_time; return $this->create_time;
@@ -56,6 +62,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for update_time * Getter for update_time
* @return string
*/ */
public function getUpdate_time() { public function getUpdate_time() {
return $this->update_time; return $this->update_time;
@@ -71,6 +78,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -86,6 +94,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for amount * Getter for amount
* @return PayPal\Api\Amount
*/ */
public function getAmount() { public function getAmount() {
return $this->amount; return $this->amount;
@@ -101,6 +110,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for sale_id * Getter for sale_id
* @return string
*/ */
public function getSale_id() { public function getSale_id() {
return $this->sale_id; return $this->sale_id;
@@ -116,6 +126,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for capture_id * Getter for capture_id
* @return string
*/ */
public function getCapture_id() { public function getCapture_id() {
return $this->capture_id; return $this->capture_id;
@@ -131,6 +142,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for parent_payment * Getter for parent_payment
* @return string
*/ */
public function getParent_payment() { public function getParent_payment() {
return $this->parent_payment; return $this->parent_payment;
@@ -146,6 +158,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for description * Getter for description
* @return string
*/ */
public function getDescription() { public function getDescription() {
return $this->description; return $this->description;
@@ -161,6 +174,7 @@ class Refund extends Resource implements IResource {
/** /**
* Getter for links * Getter for links
* @return PayPal\Api\Link
*/ */
public function getLinks() { public function getLinks() {
return $this->links; return $this->links;
@@ -171,16 +185,21 @@ class Refund extends Resource implements IResource {
/** /**
* @path /v1/payments/refund/:refund-id * @path /v1/payments/refund/:refund-id
* @method GET * @method GET
* @param string $refundid * @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)) { if (($refundid == null) || (strlen($refundid) <= 0)) {
throw new \InvalidArgumentException("refundid cannot be null or empty"); throw new \InvalidArgumentException("refundid cannot be null or empty");
} }
$payLoad = ""; $payLoad = "";
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $call = new Call(); $apiContext = new ApiContext(self::$credential);
$json = $call->execute("/v1/payments/refund/$refundid", "GET", $payLoad, $apiContext); }
$call = new \PPRestCall($apiContext);
$json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/refund/$refundid",
"GET", $payLoad);
$ret = new Refund(); $ret = new Refund();
$ret->fromJson($json); $ret->fromJson($json);
return $ret; return $ret;
@@ -188,4 +207,4 @@ class Refund extends Resource implements IResource {
} }
} }

View File

@@ -1,12 +1,10 @@
<?php <?php
namespace PayPal\Api; namespace PayPal\Api;
use PayPal\Common\Model;
/** /**
* *
*/ */
class Resource extends Model { class Resource extends \PPModel {

View File

@@ -6,12 +6,16 @@ use PayPal\Rest\Call;
use PayPal\Rest\ApiContext; use PayPal\Rest\ApiContext;
/** /**
* *
*/ */
class Sale extends Resource implements IResource { class Sale extends Resource implements IResource {
private static $credential; private static $credential;
/**
*
* @deprected. Pass ApiContext to refund/get methods instead
*/
public static function setCredential($credential) { public static function setCredential($credential) {
self::$credential = $credential; self::$credential = $credential;
} }
@@ -26,6 +30,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for id * Getter for id
* @return string
*/ */
public function getId() { public function getId() {
return $this->id; return $this->id;
@@ -41,6 +46,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for create_time * Getter for create_time
* @return string
*/ */
public function getCreate_time() { public function getCreate_time() {
return $this->create_time; return $this->create_time;
@@ -56,6 +62,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for update_time * Getter for update_time
* @return string
*/ */
public function getUpdate_time() { public function getUpdate_time() {
return $this->update_time; return $this->update_time;
@@ -71,6 +78,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for state * Getter for state
* @return string
*/ */
public function getState() { public function getState() {
return $this->state; return $this->state;
@@ -86,6 +94,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for amount * Getter for amount
* @return PayPal\Api\Amount
*/ */
public function getAmount() { public function getAmount() {
return $this->amount; return $this->amount;
@@ -101,6 +110,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for parent_payment * Getter for parent_payment
* @return string
*/ */
public function getParent_payment() { public function getParent_payment() {
return $this->parent_payment; return $this->parent_payment;
@@ -116,6 +126,7 @@ class Sale extends Resource implements IResource {
/** /**
* Getter for links * Getter for links
* @return PayPal\Api\Link
*/ */
public function getLinks() { public function getLinks() {
return $this->links; return $this->links;
@@ -126,16 +137,21 @@ class Sale extends Resource implements IResource {
/** /**
* @path /v1/payments/sale/:sale-id * @path /v1/payments/sale/:sale-id
* @method GET * @method GET
* @param string $saleid * @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)) { if (($saleid == null) || (strlen($saleid) <= 0)) {
throw new \InvalidArgumentException("saleid cannot be null or empty"); throw new \InvalidArgumentException("saleid cannot be null or empty");
} }
$payLoad = ""; $payLoad = "";
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $call = new Call(); $apiContext = new ApiContext(self::$credential);
$json = $call->execute("/v1/payments/sale/$saleid", "GET", $payLoad, $apiContext); }
$call = new \PPRestCall($apiContext);
$json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/sale/$saleid",
"GET", $payLoad);
$ret = new Sale(); $ret = new Sale();
$ret->fromJson($json); $ret->fromJson($json);
return $ret; return $ret;
@@ -146,7 +162,7 @@ class Sale extends Resource implements IResource {
* @path /v1/payments/sale/:sale-id/refund * @path /v1/payments/sale/:sale-id/refund
* @method POST * @method POST
* @param Refund $refund * @param Refund $refund
* @param PayPal\Rest\ApiContext $apiContext optional * @param PayPal\Rest\ApiContext $apiContext optional
*/ */
public function refund( $refund, $apiContext=null) { public function refund( $refund, $apiContext=null) {
if ($refund == null) { if ($refund == null) {
@@ -159,11 +175,13 @@ class Sale extends Resource implements IResource {
if($apiContext == null) { if($apiContext == null) {
$apiContext = new ApiContext(self::$credential); $apiContext = new ApiContext(self::$credential);
} }
$call = new Call(); $call = new \PPRestCall($apiContext);
$json = $call->execute("/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad, $apiContext); $json = $call->execute( array('PayPal\Rest\RestHandler'),
"/v1/payments/sale/{$this->getId()}/refund",
"POST", $payLoad);
$this->fromJson($json); $this->fromJson($json);
return $this; return $this;
} }
} }

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class ShippingAddress extends Address { class ShippingAddress extends Address {
@@ -18,6 +18,7 @@ class ShippingAddress extends Address {
/** /**
* Getter for recipient_name * Getter for recipient_name
* @return string
*/ */
public function getRecipient_name() { public function getRecipient_name() {
return $this->recipient_name; return $this->recipient_name;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class SubTransaction extends Resource { class SubTransaction extends Resource {
@@ -18,6 +18,7 @@ class SubTransaction extends Resource {
/** /**
* Getter for sale * Getter for sale
* @return PayPal\Api\Sale
*/ */
public function getSale() { public function getSale() {
return $this->sale; return $this->sale;
@@ -33,6 +34,7 @@ class SubTransaction extends Resource {
/** /**
* Getter for authorization * Getter for authorization
* @return PayPal\Api\Authorization
*/ */
public function getAuthorization() { public function getAuthorization() {
return $this->authorization; return $this->authorization;
@@ -48,6 +50,7 @@ class SubTransaction extends Resource {
/** /**
* Getter for refund * Getter for refund
* @return PayPal\Api\Refund
*/ */
public function getRefund() { public function getRefund() {
return $this->refund; return $this->refund;
@@ -63,6 +66,7 @@ class SubTransaction extends Resource {
/** /**
* Getter for capture * Getter for capture
* @return PayPal\Api\Capture
*/ */
public function getCapture() { public function getCapture() {
return $this->capture; return $this->capture;

View File

@@ -3,7 +3,7 @@
namespace PayPal\Api; namespace PayPal\Api;
/** /**
* *
*/ */
class Transaction extends Resource { class Transaction extends Resource {
@@ -18,6 +18,7 @@ class Transaction extends Resource {
/** /**
* Getter for amount * Getter for amount
* @return PayPal\Api\Amount
*/ */
public function getAmount() { public function getAmount() {
return $this->amount; return $this->amount;
@@ -33,6 +34,7 @@ class Transaction extends Resource {
/** /**
* Getter for payee * Getter for payee
* @return PayPal\Api\Payee
*/ */
public function getPayee() { public function getPayee() {
return $this->payee; return $this->payee;
@@ -48,6 +50,7 @@ class Transaction extends Resource {
/** /**
* Getter for description * Getter for description
* @return string
*/ */
public function getDescription() { public function getDescription() {
return $this->description; return $this->description;
@@ -63,6 +66,7 @@ class Transaction extends Resource {
/** /**
* Getter for item_list * Getter for item_list
* @return PayPal\Api\ItemList
*/ */
public function getItem_list() { public function getItem_list() {
return $this->item_list; return $this->item_list;
@@ -78,6 +82,7 @@ class Transaction extends Resource {
/** /**
* Getter for related_resources * Getter for related_resources
* @return PayPal\Api\SubTransaction
*/ */
public function getRelated_resources() { public function getRelated_resources() {
return $this->related_resources; return $this->related_resources;

View File

@@ -1,118 +1,133 @@
<?php <?php
namespace PayPal\Auth; namespace PayPal\Auth;
/** /**
* Oauth Token credential * Oauth Token credential
* *
*/ */
class OAuthTokenCredential { use PayPal\Rest\RestHandler;
private static $expiryBufferTime = 120; use PayPal\Common\UserAgent;
private $logger; class OAuthTokenCredential {
/** private static $expiryBufferTime = 120;
* Client ID as obtained from the developer portal
*/ private $logger;
private $clientId;
/**
/** * Client ID as obtained from the developer portal
* Client secret as obtained from the developer portal */
*/ private $clientId;
private $clientSecret;
/**
* Client secret as obtained from the developer portal
/** */
* Generated Access Token private $clientSecret;
*/
private $accessToken;
/**
/** * Generated Access Token
* Seconds for with access token is valid */
*/ private $accessToken;
private $tokenExpiresIn;
/**
/** * Seconds for with access token is valid
* Last time (in milliseconds) when access token was generated */
*/ private $tokenExpiresIn;
private $tokenCreateTime;
/**
/** * Last time (in milliseconds) when access token was generated
* */
* @param string $clientId client id obtained from the developer portal private $tokenCreateTime;
* @param string $clientSecret client secret obtained from the developer portal
*/ /**
public function __construct($clientId, $clientSecret) { *
$this->clientId = $clientId; * @param string $clientId client id obtained from the developer portal
$this->clientSecret = $clientSecret; * @param string $clientSecret client secret obtained from the developer portal
$this->logger = new \PPLoggingManager(__CLASS__); */
} public function __construct($clientId, $clientSecret) {
$this->clientId = $clientId;
/** $this->clientSecret = $clientSecret;
* @return the accessToken }
*/
public function getAccessToken() { /**
// Check if Access Token is not null and has not expired. * @return the accessToken
// The API returns expiry time as a relative time unit */
// We use a buffer time when checking for token expiry to account public function getAccessToken($config) {
// for API call delays and any delay between the time the token is
// retrieved and subsequently used $this->logger = new \PPLoggingManager(__CLASS__, $config);
if ($this->accessToken != null && // Check if Access Token is not null and has not expired.
(time() - $this->tokenCreateTime) > ($this->tokenExpiresIn - self::$expiryBufferTime)) { // The API returns expiry time as a relative time unit
$this->accessToken = null; // We use a buffer time when checking for token expiry to account
} // for API call delays and any delay between the time the token is
// If accessToken is Null, obtain a new token // retrieved and subsequently used
if ($this->accessToken == null) { if ($this->accessToken != null &&
$this->generateAccessToken(); (time() - $this->tokenCreateTime) > ($this->tokenExpiresIn - self::$expiryBufferTime)) {
} $this->accessToken = null;
return $this->accessToken; }
} // If accessToken is Null, obtain a new token
if ($this->accessToken == null) {
/** $this->_generateAccessToken($config);
* Generates a new access token }
*/ return $this->accessToken;
private function generateAccessToken() { }
return $this->generateOAuthToken(base64_encode($this->clientId . ":" . $this->clientSecret));
} /**
* Generates a new access token
/** */
* Generate OAuth type token from Base64Client ID private function _generateAccessToken($config) {
*/
private function generateOAuthToken($base64ClientID) { $base64ClientID = base64_encode($this->clientId . ":" . $this->clientSecret);
$headers = array(
$headers = array( "User-Agent" => \PPUserAgent::getValue(RestHandler::$sdkName, RestHandler::$sdkVersion),
"Authorization" => "Basic " . $base64ClientID, "Authorization" => "Basic " . $base64ClientID,
"Accept" => "*/*" "Accept" => "*/*"
); );
$httpConfiguration = $this->getOAuthHttpConfiguration(); $httpConfiguration = $this->getOAuthHttpConfiguration($config);
$httpConfiguration->setHeaders($headers); $httpConfiguration->setHeaders($headers);
$connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration); $connection = \PPConnectionManager::getInstance()->getConnection($httpConfiguration, $config);
$res = $connection->execute("grant_type=client_credentials"); $res = $connection->execute("grant_type=client_credentials");
$jsonResponse = json_decode($res, true); $jsonResponse = json_decode($res, true);
if($jsonResponse == NULL || if($jsonResponse == NULL ||
!isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) { !isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) {
$this->accessToken = NULL; $this->accessToken = NULL;
$this->tokenExpiresIn = NULL; $this->tokenExpiresIn = NULL;
$this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse); $this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);
} else { } else {
$this->accessToken = $jsonResponse["access_token"]; $this->accessToken = $jsonResponse["access_token"];
$this->tokenExpiresIn = $jsonResponse["expires_in"]; $this->tokenExpiresIn = $jsonResponse["expires_in"];
} }
$this->tokenCreateTime = time(); $this->tokenCreateTime = time();
return $this->accessToken; return $this->accessToken;
} }
/* /*
* Get HttpConfiguration object for OAuth API * Get HttpConfiguration object for OAuth API
*/ */
private function getOAuthHttpConfiguration() { private function getOAuthHttpConfiguration($config) {
$configMgr = \PPConfigManager::getInstance(); if (isset($config['oauth.EndPoint'])) {
$baseEndpoint = $config['oauth.EndPoint'];
$baseEndpoint = ($configMgr->get("oauth.EndPoint") != '' && !is_array($configMgr->get("oauth.EndPoint"))) ? } else if (isset($config['service.EndPoint'])) {
$configMgr->get("oauth.EndPoint") : $configMgr->get("service.EndPoint"); $baseEndpoint = $config['service.EndPoint'];
$baseEndpoint = rtrim(trim($baseEndpoint), '/'); } else if (isset($config['mode'])) {
return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST"); switch (strtoupper($config['mode'])) {
} case 'SANDBOX':
} $baseEndpoint = \PPConstants::REST_SANDBOX_ENDPOINT;
break;
case 'LIVE':
$baseEndpoint = \PPConstants::REST_LIVE_ENDPOINT;
break;
default:
throw new \PPConfigurationException('The mode config parameter must be set to either sandbox/live');
}
} else {
throw new PPConfigurationException('You must set one of service.endpoint or mode parameters in your configuration');
}
$baseEndpoint = rtrim(trim($baseEndpoint), '/');
return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST");
}
}

View File

@@ -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;
}
}

View File

@@ -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());
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -1,74 +1,74 @@
<?php <?php
namespace PayPal\Rest; namespace PayPal\Rest;
/** /**
* *
* Call level parameters such as * Call level parameters such as
* request id, credentials etc * request id, credentials etc
*/ */
class ApiContext { class ApiContext extends \PPApiContext {
/** /**
* OAuth Credentials to use for this call * OAuth Credentials to use for this call
* @var PayPal/Api/OAuthTokenCredential * @var PayPal/Api/OAuthTokenCredential
*/ */
private $credential; private $credential;
/** /**
* Unique request id to be used for this call * Unique request id to be used for this call
* The user can either generate one as per application * The user can either generate one as per application
* needs or let the SDK generate one * needs or let the SDK generate one
* @var string * @var string
*/ */
private $requestId; private $requestId;
/**
/** *
* */
*/ public function getCredential() {
public function getCredential() { return $this->credential;
return $this->credential; }
}
public function getrequestId() {
public function getrequestId() { if($this->requestId == null) {
if($this->requestId == null) { $this->requestId = $this->generateRequestId();
$this->requestId = $this->generaterequestId(); }
} return $this->requestId;
return $this->requestId; }
}
/** /**
* *
* @param PayPal/Api/OAuthTokenCredential $credential * @param PayPal/Api/OAuthTokenCredential $credential
* @param string $requestId * @param string $requestId
*/ */
public function __construct($credential, $requestId=null) { public function __construct($credential, $requestId=null) {
$this->credential = $credential; $this->credential = $credential;
$this->requestId = $requestId; $this->requestId = $requestId;
} }
/** /**
* Generates a unique per request id that * Generates a unique per request id that
* can be used to set the PayPal-Request-Id header * can be used to set the PayPal-Request-Id header
* that is used for idemptency * that is used for idemptency
* @return string * @return string
*/ */
private function generateRequestId() { private function generateRequestId() {
static $pid = -1; static $pid = -1;
static $addr = -1; static $addr = -1;
if ($pid == -1) { if ($pid == -1) {
$pid = getmypid(); $pid = getmypid();
} }
if ($addr == -1) { if ($addr == -1) {
if(array_key_exists('SERVER_ADDR', $_SERVER)) { if(array_key_exists('SERVER_ADDR', $_SERVER)) {
$addr = ip2long($_SERVER['SERVER_ADDR']); $addr = ip2long($_SERVER['SERVER_ADDR']);
} else { } else {
$addr = php_uname('n'); $addr = php_uname('n');
} }
} }
return $addr . $pid . $_SERVER['REQUEST_TIME'] . mt_rand(0, 0xffff); return $addr . $pid . $_SERVER['REQUEST_TIME'] . mt_rand(0, 0xffff);
} }
} }

View File

@@ -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;
}
}

View 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');
}
}
}

View File

@@ -1,50 +1,57 @@
<?php <?php
/* /*
* Sample bootstrap file. * Sample bootstrap file.
*/ */
// Include the composer autoloader // Include the composer autoloader
if(!file_exists(__DIR__ .'/vendor/autoload.php')) { if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n"; echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n";
exit(1); exit(1);
} }
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
use PayPal\Auth\OAuthTokenCredential; define("PP_CONFIG_PATH", __DIR__);
define("PP_CONFIG_PATH", __DIR__); use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
$configManager = \PPConfigManager::getInstance();
// ### Api Context
// $cred is used by samples that include this bootstrap file // Pass in a `PayPal\Rest\ApiContext` object to authenticate
// This piece of code simply demonstrates how you can // the call. You can also send a unique request id
// dynamically pass in a client id/secret instead of using // (that ensures idempotency). The SDK generates
// the config file. If you do not need a way to pass // a request id if you do not pass one explicitly.
// in credentials dynamically, you can skip the $apiContext = new ApiContext(new OAuthTokenCredential(
// <Resource>::setCredential($cred) calls that 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
// you see in the samples. 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'));
$cred = new OAuthTokenCredential( // Uncomment this step if you want to use per request
$configManager->get('acct1.ClientId'), // dynamic configuration instead of using sdk_config.ini
$configManager->get('acct1.ClientSecret')); /*
$apiContext->setConfig(array(
'mode' => 'sandbox',
/** 'http.ConnectionTimeOut' => 30,
* ### getBaseUrl function 'log.LogEnabled' => true,
* // utility function that returns base url for 'log.FileName' => '../PayPal.log',
* // determining return/cancel urls 'log.LogLevel' => 'FINE'
* @return string ));
*/ */
function getBaseUrl() {
/**
$protocol = 'http'; * ### getBaseUrl function
if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) { * // utility function that returns base url for
$protocol .= 's'; * // determining return/cancel urls
$protocol_port = $_SERVER['SERVER_PORT']; * @return string
} else { */
$protocol_port = 80; function getBaseUrl() {
}
$protocol = 'http';
$host = $_SERVER['HTTP_HOST']; if ($_SERVER['SERVER_PORT'] == 443 || (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on')) {
$port = $_SERVER['SERVER_PORT']; $protocol .= 's';
$request = $_SERVER['PHP_SELF']; $protocol_port = $_SERVER['SERVER_PORT'];
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request); } else {
} $protocol_port = 80;
}
$host = $_SERVER['HTTP_HOST'];
$port = $_SERVER['SERVER_PORT'];
$request = $_SERVER['PHP_SELF'];
return dirname($protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request);
}

View File

@@ -1,14 +1,14 @@
{ {
"name": "paypal/rest-api-sdk-sample-php", "name": "paypal/rest-api-sdk-sample-php",
"description": "Samples using PayPal's REST API SDK for PHP", "description": "Samples using PayPal's REST API SDK for PHP",
"homepage": "https://github.com/paypal/rest-api-sdk-php", "homepage": "https://github.com/paypal/rest-api-sdk-php",
"config": { "config": {
"require-all": true "require-all": true
}, },
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.0",
"ext-curl": "*", "ext-curl": "*",
"ext-json": "*", "ext-json": "*",
"paypal/rest-api-sdk-php" : "0.5.*" "paypal/rest-api-sdk-php" : "0.6.*"
} }
} }

View File

@@ -1,111 +1,105 @@
<?php <?php
// # CreatePaymentSample // # CreatePaymentSample
// This sample code demonstrate how you can process // This sample code demonstrate how you can process
// a payment with a credit card. // a payment with a credit card.
// API used: /v1/payments/payment // API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address; use PayPal\Api\Address;
use PayPal\Api\Amount; use PayPal\Api\Amount;
use PayPal\Api\CreditCard; use PayPal\Api\CreditCard;
use PayPal\Api\Payer; use PayPal\Api\Payer;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument; use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
use PayPal\Rest\ApiContext;
// ### Address
// ### Address // Base Address object used as shipping or billing
// Base Address object used as shipping or billing // address in a payment. [Optional]
// address in a payment. [Optional] $addr = new Address();
$addr = new Address(); $addr->setLine1("3909 Witmer Road");
$addr->setLine1("3909 Witmer Road"); $addr->setLine2("Niagara Falls");
$addr->setLine2("Niagara Falls"); $addr->setCity("Niagara Falls");
$addr->setCity("Niagara Falls"); $addr->setState("NY");
$addr->setState("NY"); $addr->setPostal_code("14305");
$addr->setPostal_code("14305"); $addr->setCountry_code("US");
$addr->setCountry_code("US"); $addr->setPhone("716-298-1822");
$addr->setPhone("716-298-1822");
// ### CreditCard
// ### CreditCard // A resource representing a credit card that can be
// A resource representing a credit card that can be // used to fund a payment.
// used to fund a payment. $card = new CreditCard();
$card = new CreditCard(); $card->setType("visa");
$card->setType("visa"); $card->setNumber("4417119669820331");
$card->setNumber("4417119669820331"); $card->setExpire_month("11");
$card->setExpire_month("11"); $card->setExpire_year("2019");
$card->setExpire_year("2019"); $card->setCvv2("012");
$card->setCvv2("012"); $card->setFirst_name("Joe");
$card->setFirst_name("Joe"); $card->setLast_name("Shopper");
$card->setLast_name("Shopper"); $card->setBilling_address($addr);
$card->setBilling_address($addr);
// ### FundingInstrument
// ### FundingInstrument // A resource representing a Payer's funding instrument.
// A resource representing a Payer's funding instrument. // Use a Payer ID (A unique identifier of the payer generated
// Use a Payer ID (A unique identifier of the payer generated // and provided by the facilitator. This is required when
// and provided by the facilitator. This is required when // creating or using a tokenized funding instrument)
// creating or using a tokenized funding instrument) // and the `CreditCardDetails`
// and the `CreditCardDetails` $fi = new FundingInstrument();
$fi = new FundingInstrument(); $fi->setCredit_card($card);
$fi->setCredit_card($card);
// ### Payer
// ### Payer // A resource representing a Payer that funds a payment
// A resource representing a Payer that funds a payment // Use the List of `FundingInstrument` and the Payment Method
// Use the List of `FundingInstrument` and the Payment Method // as 'credit_card'
// as 'credit_card' $payer = new Payer();
$payer = new Payer(); $payer->setPayment_method("credit_card");
$payer->setPayment_method("credit_card"); $payer->setFunding_instruments(array($fi));
$payer->setFunding_instruments(array($fi));
// ### Amount
// ### Amount // Let's you specify a payment amount.
// Let's you specify a payment amount. $amount = new Amount();
$amount = new Amount(); $amount->setCurrency("USD");
$amount->setCurrency("USD"); $amount->setTotal("1.00");
$amount->setTotal("1.00");
// ### Transaction
// ### Transaction // A transaction defines the contract of a
// A transaction defines the contract of a // payment - what is the payment for and who
// payment - what is the payment for and who // is fulfilling it. Transaction is created with
// is fulfilling it. Transaction is created with // a `Payee` and `Amount` types
// a `Payee` and `Amount` types $transaction = new Transaction();
$transaction = new Transaction(); $transaction->setAmount($amount);
$transaction->setAmount($amount); $transaction->setDescription("This is the payment description.");
$transaction->setDescription("This is the payment description.");
// ### Payment
// ### Payment // A Payment Resource; create one using
// A Payment Resource; create one using // the above types and intent as 'sale'
// the above types and intent as 'sale' $payment = new Payment();
$payment = new Payment(); $payment->setIntent("sale");
$payment->setIntent("sale"); $payment->setPayer($payer);
$payment->setPayer($payer); $payment->setTransactions(array($transaction));
$payment->setTransactions(array($transaction));
// ### Api Context
// Pass in a `ApiContext` object to authenticate // ### Create Payment
// the call and to send a unique request id // Create a payment by posting to the APIService
// (that ensures idempotency). The SDK generates // using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// a request id if you do not pass one explicitly. // The return object contains the status;
$apiContext = new ApiContext($cred, 'Request' . time()); try {
$payment->create($apiContext);
// ### Create Payment } catch (\PPConnectionException $ex) {
// Create a payment by posting to the APIService echo "Exception: " . $ex->getMessage() . PHP_EOL;
// using a valid ApiContext var_dump($ex->getData());
// The return object contains the status; exit(1);
try { }
$payment->create($apiContext); ?>
} catch (\PPConnectionException $ex) { <html>
echo "Exception: " . $ex->getMessage() . PHP_EOL; <body>
var_dump($ex->getData()); <div>
exit(1); Created payment:
} <?php echo $payment->getId();?>
?> </div>
<html> <pre><?php var_dump($payment->toArray());?></pre>
<body> <a href='../index.html'>Back</a>
<div> </body>
Created payment: </html>
<?php echo $payment->getId();?>
</div>
<pre><?php var_dump($payment->toArray());?></pre>
<a href='../index.html'>Back</a>
</body>
</html>

View File

@@ -1,93 +1,86 @@
<?php <?php
// # Create Payment using PayPal as payment method // # Create Payment using PayPal as payment method
// This sample code demonstrates how you can process a // This sample code demonstrates how you can process a
// PayPal Account based Payment. // PayPal Account based Payment.
// API used: /v1/payments/payment // API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address; use PayPal\Api\Address;
use PayPal\Api\Amount; use PayPal\Api\Amount;
use PayPal\Api\Payer; use PayPal\Api\Payer;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument; use PayPal\Api\FundingInstrument;
use PayPal\Api\RedirectUrls; use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
use PayPal\Rest\ApiContext; session_start();
session_start();
// ### Payer
// ### Payer // A resource representing a Payer that funds a payment
// A resource representing a Payer that funds a payment // Use the List of `FundingInstrument` and the Payment Method
// Use the List of `FundingInstrument` and the Payment Method // as 'credit_card'
// as 'credit_card' $payer = new Payer();
$payer = new Payer(); $payer->setPayment_method("paypal");
$payer->setPayment_method("paypal");
// ### Amount
// ### Amount // Let's you specify a payment amount.
// Let's you specify a payment amount. $amount = new Amount();
$amount = new Amount(); $amount->setCurrency("USD");
$amount->setCurrency("USD"); $amount->setTotal("1.00");
$amount->setTotal("1.00");
// ### Transaction
// ### Transaction // A transaction defines the contract of a
// A transaction defines the contract of a // payment - what is the payment for and who
// payment - what is the payment for and who // is fulfilling it. Transaction is created with
// is fulfilling it. Transaction is created with // a `Payee` and `Amount` types
// a `Payee` and `Amount` types $transaction = new Transaction();
$transaction = new Transaction(); $transaction->setAmount($amount);
$transaction->setAmount($amount); $transaction->setDescription("This is the payment description.");
$transaction->setDescription("This is the payment description.");
// ### Redirect urls
// ### Redirect urls // Set the urls that the buyer must be redirected to after
// Set the urls that the buyer must be redirected to after // payment approval/ cancellation.
// payment approval/ cancellation. $baseUrl = getBaseUrl();
$baseUrl = getBaseUrl(); $redirectUrls = new RedirectUrls();
$redirectUrls = new RedirectUrls(); $redirectUrls->setReturn_url("$baseUrl/ExecutePayment.php?success=true");
$redirectUrls->setReturn_url("$baseUrl/ExecutePayment.php?success=true"); $redirectUrls->setCancel_url("$baseUrl/ExecutePayment.php?success=false");
$redirectUrls->setCancel_url("$baseUrl/ExecutePayment.php?success=false");
// ### Payment
// ### Payment // A Payment Resource; create one using
// A Payment Resource; create one using // the above types and intent as 'sale'
// the above types and intent as 'sale' $payment = new Payment();
$payment = new Payment(); $payment->setIntent("sale");
$payment->setIntent("sale"); $payment->setPayer($payer);
$payment->setPayer($payer); $payment->setRedirect_urls($redirectUrls);
$payment->setRedirect_urls($redirectUrls); $payment->setTransactions(array($transaction));
$payment->setTransactions(array($transaction));
// ### Create Payment
// ### Api Context // Create a payment by posting to the APIService
// Pass in a `ApiContext` object to authenticate // using a valid apiContext.
// the call and to send a unique request id // (See bootstrap.php for more on `ApiContext`)
// (that ensures idempotency). The SDK generates // The return object contains the status and the
// a request id if you do not pass one explicitly. // url to which the buyer must be redirected to
$apiContext = new ApiContext($cred, 'Request' . time()); // for payment approval
try {
// ### Create Payment $payment->create($apiContext);
// Create a payment by posting to the APIService } catch (\PPConnectionException $ex) {
// using a valid apiContext echo "Exception: " . $ex->getMessage() . PHP_EOL;
// The return object contains the status and the var_dump($ex->getData());
// url to which the buyer must be redirected to exit(1);
// for payment approval }
try {
$payment->create($apiContext); // ### Redirect buyer to paypal
} catch (\PPConnectionException $ex) { // Retrieve buyer approval url from the `payment` object.
echo "Exception: " . $ex->getMessage() . PHP_EOL; foreach($payment->getLinks() as $link) {
var_dump($ex->getData()); if($link->getRel() == 'approval_url') {
exit(1); $redirectUrl = $link->getHref();
} }
}
// ### Redirect buyer to paypal // It is not really a great idea to store the payment id
// Retrieve buyer approval url from the `payment` object. // in the session. In a real world app, please store the
foreach($payment->getLinks() as $link) { // payment id in a database.
if($link->getRel() == 'approval_url') { $_SESSION['paymentId'] = $payment->getId();
$redirectUrl = $link->getHref(); if(isset($redirectUrl)) {
} header("Location: $redirectUrl");
} exit;
// It is not really a great idea to store the payment id }
// in the session. In a real world app, please store the
// payment id in a database.
$_SESSION['paymentId'] = $payment->getId();
if(isset($redirectUrl)) {
header("Location: $redirectUrl");
exit;
}

View File

@@ -1,96 +1,88 @@
<?php <?php
// # Create payment using a saved credit card // # Create payment using a saved credit card
// This sample code demonstrates how you can process a // This sample code demonstrates how you can process a
// Payment using a previously saved credit card. // Payment using a previously saved credit card.
// API used: /v1/payments/payment // API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Address; use PayPal\Api\Address;
use PayPal\Api\Amount; use PayPal\Api\Amount;
use PayPal\Api\CreditCard; use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken; use PayPal\Api\CreditCardToken;
use PayPal\Api\Payer; use PayPal\Api\Payer;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument; use PayPal\Api\FundingInstrument;
use PayPal\Api\RedirectUrls; use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction; use PayPal\Api\Transaction;
use PayPal\Auth\OAuthTokenCredential; use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;
// ### Credit card token
// ### Credit card token // Saved credit card id from a previous call to
// Saved credit card id from a previous call to // CreateCreditCard.php
// CreateCreditCard.php $creditCardId = 'CARD-5BT058015C739554AKE2GCEI';
$creditCardId = 'CARD-5BT058015C739554AKE2GCEI'; $creditCardToken = new CreditCardToken();
$creditCardToken = new CreditCardToken(); $creditCardToken->setCredit_card_id($creditCardId);
$creditCardToken->setCredit_card_id($creditCardId);
// ### FundingInstrument
// ### FundingInstrument // A resource representing a Payer's funding instrument.
// A resource representing a Payer's funding instrument. // Use a Payer ID (A unique identifier of the payer generated
// Use a Payer ID (A unique identifier of the payer generated // and provided by the facilitator. This is required when
// and provided by the facilitator. This is required when // creating or using a tokenized funding instrument)
// creating or using a tokenized funding instrument) // and the `CreditCardDetails`
// and the `CreditCardDetails` $fi = new FundingInstrument();
$fi = new FundingInstrument(); $fi->setCredit_card_token($creditCardToken);
$fi->setCredit_card_token($creditCardToken);
// ### Payer
// ### Payer // A resource representing a Payer that funds a payment
// A resource representing a Payer that funds a payment // Use the List of `FundingInstrument` and the Payment Method
// Use the List of `FundingInstrument` and the Payment Method // as 'credit_card'
// as 'credit_card' $payer = new Payer();
$payer = new Payer(); $payer->setPayment_method("credit_card");
$payer->setPayment_method("credit_card"); $payer->setFunding_instruments(array($fi));
$payer->setFunding_instruments(array($fi));
// ### Amount
// ### Amount // Let's you specify a payment amount.
// Let's you specify a payment amount. $amount = new Amount();
$amount = new Amount(); $amount->setCurrency("USD");
$amount->setCurrency("USD"); $amount->setTotal("1.00");
$amount->setTotal("1.00");
// ### Transaction
// ### Transaction // A transaction defines the contract of a
// A transaction defines the contract of a // payment - what is the payment for and who
// payment - what is the payment for and who // is fulfilling it. Transaction is created with
// is fulfilling it. Transaction is created with // a `Payee` and `Amount` types
// a `Payee` and `Amount` types $transaction = new Transaction();
$transaction = new Transaction(); $transaction->setAmount($amount);
$transaction->setAmount($amount); $transaction->setDescription("This is the payment description.");
$transaction->setDescription("This is the payment description.");
// ### Payment
// ### Payment // A Payment Resource; create one using
// A Payment Resource; create one using // the above types and intent as 'sale'
// the above types and intent as 'sale' $payment = new Payment();
$payment = new Payment(); $payment->setIntent("sale");
$payment->setIntent("sale"); $payment->setPayer($payer);
$payment->setPayer($payer); $payment->setTransactions(array($transaction));
$payment->setTransactions(array($transaction));
// ###Create Payment
// ### Api Context // Create a payment by posting to the APIService
// Pass in a `ApiContext` object to authenticate // (See bootstrap.php for more on `ApiContext`)
// the call and to send a unique request id // The return object contains the status;
// (that ensures idempotency). The SDK generates try {
// a request id if you do not pass one explicitly. $payment->create($apiContext);
$apiContext = new ApiContext($cred, 'Request' . time()); } catch (\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
// ###Create Payment var_dump($ex->getData());
// Create a payment by posting to the APIService exit(1);
// using a valid apiContext }
// The return object contains the status; ?>
try { <html>
$payment->create($apiContext); <body>
} catch (\PPConnectionException $ex) { <div>
echo "Exception: " . $ex->getMessage() . PHP_EOL; Created payment:
var_dump($ex->getData()); <?php echo $payment->getId();?>
exit(1); </div>
} <pre><?php var_dump($payment->toArray());?></pre>
?> <a href='../index.html'>Back</a>
<html> </body>
<body>
<div>
Created payment:
<?php echo $payment->getId();?>
</div>
<pre><?php var_dump($payment->toArray());?></pre>
<a href='../index.html'>Back</a>
</body>
</html> </html>

View File

@@ -1,47 +1,40 @@
<?php <?php
// #Execute Payment Sample // #Execute Payment Sample
// This sample shows how you can complete // This sample shows how you can complete
// a payment that has been approved by // a payment that has been approved by
// the buyer by logging into paypal site. // the buyer by logging into paypal site.
// You can optionally update transaction // You can optionally update transaction
// information by passing in one or more transactions. // information by passing in one or more transactions.
// API used: POST '/v1/payments/payment/<payment-id>/execute'. // API used: POST '/v1/payments/payment/<payment-id>/execute'.
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\ExecutePayment; use PayPal\Api\ExecutePayment;
use PayPal\Api\Payment; use PayPal\Api\Payment;
use PayPal\Api\PaymentExecution; use PayPal\Api\PaymentExecution;
use PayPal\Rest\ApiContext; session_start();
session_start(); if(isset($_GET['success']) && $_GET['success'] == 'true') {
if(isset($_GET['success']) && $_GET['success'] == 'true') { // Get the payment Object by passing paymentId
// ### Api Context // payment id was previously stored in session in
// Pass in a `ApiContext` object to authenticate // CreatePaymentUsingPayPal.php
// the call and to send a unique request id $paymentId = $_SESSION['paymentId'];
// (that ensures idempotency). The SDK generates $payment = Payment::get($paymentId, $apiContext);
// a request id if you do not pass one explicitly.
$apiContext = new ApiContext($cred); // PaymentExecution object includes information necessary
// to execute a PayPal account payment.
// Get the payment Object by passing paymentId // The payer_id is added to the request query parameters
// payment id was previously stored in session in // when the user is redirected from paypal back to your site
// CreatePaymentUsingPayPal.php $execution = new PaymentExecution();
$paymentId = $_SESSION['paymentId']; $execution->setPayer_id($_GET['PayerID']);
$payment = Payment::get($paymentId);
//Execute the payment
// PaymentExecution object includes information necessary // (See bootstrap.php for more on `ApiContext`)
// to execute a PayPal account payment. $payment->execute($execution, $apiContext);
// The payer_id is added to the request query parameters
// when the user is redirected from paypal back to your site echo "<html><body><pre>";
$execution = new PaymentExecution(); var_dump($payment->toArray());
$execution->setPayer_id($_GET['PayerID']); echo "</pre><a href='../index.html'>Back</a></body></html>";
//Execute the payment } else {
$payment->execute($execution, $apiContext); echo "User cancelled payment.";
echo "<html><body><pre>";
var_dump($payment->toArray());
echo "</pre><a href='../index.html'>Back</a></body></html>";
} else {
echo "User cancelled payment.";
} }

View File

@@ -1,39 +1,36 @@
<?php <?php
// # GetPaymentSample // # GetPaymentSample
// This sample code demonstrate how you can // This sample code demonstrate how you can
// retrieve a list of all Payment resources // retrieve a list of all Payment resources
// you've created using the Payments API. // you've created using the Payments API.
// Note various query parameters that you can // Note various query parameters that you can
// use to filter, and paginate through the // use to filter, and paginate through the
// payments list. // payments list.
// API used: GET /v1/payments/payments // API used: GET /v1/payments/payments
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Payment; use PayPal\Api\Payment;
$paymentId = "PAY-0XL713371A312273YKE2GCNI"; $paymentId = "PAY-0XL713371A312273YKE2GCNI";
// ### Authentication // ### Retrieve payment
// Pass in a `OAuthTokenCredential` object // Retrieve the payment object by calling the
// explicilty to authenticate the call. // static `get` method
Payment::setCredential($cred); // on the Payment class by passing a valid
// ### Retrieve payment // Payment ID
// Retrieve the payment object by calling the // (See bootstrap.php for more on `ApiContext`)
// static `get` method try {
// on the Payment class by passing a valid $payment = Payment::get($paymentId, $apiContext);
// Payment ID } catch (\PPConnectionException $ex) {
try { echo "Exception:" . $ex->getMessage() . PHP_EOL;
$payment = Payment::get($paymentId); var_dump($ex->getData());
} catch (\PPConnectionException $ex) { exit(1);
echo "Exception:" . $ex->getMessage() . PHP_EOL; }
var_dump($ex->getData()); ?>
exit(1); <html>
} <body>
?> <div>Retrieving Payment ID: <?php echo $paymentId;?></div>
<html> <pre><?php var_dump($payment->toArray());?></pre>
<body> <a href='../index.html'>Back</a>
<div>Retrieving Payment ID: <?php echo $paymentId;?></div> </body>
<pre><?php var_dump($payment->toArray());?></pre>
<a href='../index.html'>Back</a>
</body>
</html> </html>

View File

@@ -1,42 +1,37 @@
<?php <?php
// #GetPaymentList // #GetPaymentList
// This sample code demonstrate how you can // This sample code demonstrate how you can
// retrieve a list of all Payment resources // retrieve a list of all Payment resources
// you've created using the Payments API. // you've created using the Payments API.
// Note various query parameters that you can // Note various query parameters that you can
// use to filter, and paginate through the // use to filter, and paginate through the
// payments list. // payments list.
// API used: GET /v1/payments/payments // API used: GET /v1/payments/payments
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Payment; use PayPal\Api\Payment;
// ### Authentication
// Pass in a `OAuthTokenCredential` object // ### Retrieve payment
// explicilty to authenticate the call. // Retrieve the PaymentHistory object by calling the
// If you skip this step, the client id/secret // static `get` method on the Payment class,
// set in the config file will be used. // and pass a Map object that contains
Payment::setCredential($cred); // query parameters for paginations and filtering.
// Refer the method doc for valid values for keys
// ### Retrieve payment // (See bootstrap.php for more on `ApiContext`)
// Retrieve the PaymentHistory object by calling the try {
// static `get` method on the Payment class, $payments = Payment::all(array('count' => 10, 'start_index' => 5), $apiContext);
// and pass a Map object that contains } catch (\PPConnectionException $ex) {
// query parameters for paginations and filtering. echo "Exception:" . $ex->getMessage() . PHP_EOL;
// Refer the method doc for valid values for keys var_dump($ex->getData());
try { exit(1);
$payments = Payment::all(array('count' => 10, 'start_index' => 5)); }
} catch (\PPConnectionException $ex) { ?>
echo "Exception:" . $ex->getMessage() . PHP_EOL; <html>
var_dump($ex->getData()); <body>
exit(1); <div>Got <?php echo $payments->getCount(); ?> matching payments </div>
} <pre><?php var_dump($payments->toArray());?></pre>
?> <a href='../index.html'>Back</a>
<html> </body>
<body> </html>
<div>Got <?php echo $payments->getCount(); ?> matching payments </div>
<pre><?php var_dump($payments->toArray());?></pre>
<a href='../index.html'>Back</a>
</body>
</html>

View File

@@ -1,35 +1,30 @@
<?php <?php
// # Get Sale sample // # Get Sale sample
// This sample code demonstrates how you can retrieve // This sample code demonstrates how you can retrieve
// details of completed Sale Transaction. // details of completed Sale Transaction.
// API used: /v1/payments/sale/{sale-id} // API used: /v1/payments/sale/{sale-id}
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Sale; use PayPal\Api\Sale;
$saleId = '3RM92092UW5126232'; $saleId = '3RM92092UW5126232';
// ### Authentication
// Pass in a `OAuthTokenCredential` object try {
// explicilty to authenticate the call. // ### Retrieve the sale object
// If you skip this step, the client id/secret // Pass the ID of the sale
// set in the config file will be used. // transaction from your payment resource.
Sale::setCredential($cred); $sale = Sale::get($saleId, $apiContext);
try { } catch (\PPConnectionException $ex) {
// ### Retrieve the sale object echo "Exception:" . $ex->getMessage() . PHP_EOL;
// Pass the ID of the sale var_dump($ex->getData());
// transaction from your payment resource. exit(1);
$sale = Sale::get($saleId); }
} catch (\PPConnectionException $ex) { ?>
echo "Exception:" . $ex->getMessage() . PHP_EOL; <html>
var_dump($ex->getData()); <body>
exit(1); <div>Retrieving sale id: <?php echo $saleId;?></div>
} <pre><?php var_dump($sale);?></pre>
?> <a href='../index.html'>Back</a>
<html> </body>
<body>
<div>Retrieving sale id: <?php echo $saleId;?></div>
<pre><?php var_dump($sale);?></pre>
<a href='../index.html'>Back</a>
</body>
</html> </html>

View File

@@ -1,55 +1,49 @@
<?php <?php
// # Sale Refund Sample // # Sale Refund Sample
// This sample code demonstrate how you can // This sample code demonstrate how you can
// process a refund on a sale transaction created // process a refund on a sale transaction created
// using the Payments API. // using the Payments API.
// API used: /v1/payments/sale/{sale-id}/refund // API used: /v1/payments/sale/{sale-id}/refund
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount; use PayPal\Api\Amount;
use PayPal\Api\Refund; use PayPal\Api\Refund;
use PayPal\Api\Sale; use PayPal\Api\Sale;
use PayPal\Rest\ApiContext;
// ### Refund
// ### Refund // Create a refund object indicating
// Create a refund object indicating // refund amount
// refund amount $amt = new Amount();
$amt = new Amount(); $amt->setCurrency('USD');
$amt->setCurrency('USD'); $amt->setTotal('0.01');
$amt->setTotal('0.01');
$refund = new Refund();
$refund = new Refund(); $refund->setAmount($amt);
$refund->setAmount($amt);
$saleId = '3RM92092UW5126232';
$saleId = '3RM92092UW5126232';
// ###Sale
// ###Sale // A sale transaction.
// A sale transaction. // Create a Sale object with the
// Create a Sale object with the // given sale transaction id.
// given sale transaction id. $sale = new Sale();
$sale = new Sale(); $sale->setId($saleId);
$sale->setId($saleId);
try {
// ### Api Context // Refund the sale
// Pass in a `ApiContext` object to authenticate // (See bootstrap.php for more on `ApiContext`)
// the call and to send a unique request id $sale->refund($refund, $apiContext);
// (that ensures idempotency). The SDK generates } catch (\PPConnectionException $ex) {
// a request id if you do not pass one explicitly. echo "Exception:" . $ex->getMessage() . PHP_EOL;
$apiContext = new ApiContext($cred, 'Request' . time()); var_dump($ex->getData());
try { exit(1);
// Refund the sale }
$sale->refund($refund, $apiContext); ?>
} catch (\PPConnectionException $ex) { <html>
echo "Exception:" . $ex->getMessage() . PHP_EOL; <body>
var_dump($ex->getData()); <div>Refunding sale id: <?php echo $saleId;?></div>
exit(1); <pre><?php var_dump($sale);?></pre>
} <a href='../index.html'>Back</a>
?> </body>
<html>
<body>
<div>Refunding sale id: <?php echo $saleId;?></div>
<pre><?php var_dump($sale);?></pre>
<a href='../index.html'>Back</a>
</body>
</html> </html>

View File

@@ -1,35 +1,26 @@
;Account credentials from developer portal ;Connection Information
[Account] [Http]
acct1.ClientId = EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM http.ConnectionTimeOut = 30
acct1.ClientSecret = EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM http.Retry = 1
;http.Proxy=http://[username:password]@hostname[:port][/path]
;Connection Information
[Http] ;Service Configuration
http.ConnectionTimeOut = 30 [Service]
http.Retry = 1 mode=sandbox ; can be set to sandbox / live
;http.Proxy=http://[username:password]@hostname[:port][/path]
;Logging Information
[Log]
;Service Configuration
[Service] log.LogEnabled=true
service.EndPoint="https://api.sandbox.paypal.com"
; Uncomment this line for integrating with the live endpoint # When using a relative path, the log file is created
; service.EndPoint="https://api.paypal.com" # relative to the .php file that is the entry point
# for this request. You can also provide an absolute
# path here
;Logging Information log.FileName=../PayPal.log
[Log]
# Logging level can be one of FINE, INFO, WARN or ERROR
log.LogEnabled=true # Logging is most verbose in the 'FINE' level and
# decreases as you proceed towards ERROR
# When using a relative path, the log file is created
# relative to the .php file that is the entry point
# for this request. You can also provide an absolute
# path here
log.FileName=../PayPal.log
# Logging level can be one of FINE, INFO, WARN or ERROR
# Logging is most verbose in the 'FINE' level and
# decreases as you proceed towards ERROR
log.LogLevel=FINE log.LogLevel=FINE

View File

@@ -7,42 +7,36 @@ a payment in the future.
The following code demonstrates how The following code demonstrates how
can save a Credit Card on PayPal using can save a Credit Card on PayPal using
the Vault API. 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> 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">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
<span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</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> <span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow"></a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3>
<p>A resource representing a credit card that can be <p>A resource representing a credit card that can be
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span> used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setType</span><span class="p">(</span><span class="s2">&quot;visa&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setType</span><span class="p">(</span><span class="s2">&quot;visa&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setNumber</span><span class="p">(</span><span class="s2">&quot;4417119669820331&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setNumber</span><span class="p">(</span><span class="s2">&quot;4417119669820331&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">&quot;11&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">&quot;11&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">&quot;2019&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">&quot;2019&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">&quot;012&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">&quot;012&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">&quot;Joe&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">&quot;Joe&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">&quot;Shopper&quot;</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> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">&quot;Shopper&quot;</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>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">&#39;Request&#39;</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="save-card">Save card</h3>
<p>Creates the credit card as a resource <p>Creates the credit card as a resource
in the PayPal vault. The response contains in the PayPal vault. The response contains
an 'id' that you can use to refer to it an 'id' that you can use to refer to it
in the future payments.</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span> in the future payments.
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">();</span> (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="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="nv">$card</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span>
<span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="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="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</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="cp">?&gt;</span><span class="x"></span> <span class="p">}</span>
<span class="x">&lt;html&gt;</span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;body&gt;</span> <span class="x">&lt;html&gt;</span>
<span class="x"> &lt;div&gt;Saved a new credit card with id: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span> <span class="x">&lt;body&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="x"> &lt;div&gt;Saved a new credit card with id: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x">&lt;/body&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -2,89 +2,83 @@
<p>This sample code demonstrate how you can process <p>This sample code demonstrate how you can process
a payment with a credit card. a payment with a credit card.
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\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\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\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\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>
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow"></a></div><div class="wrapper"><h3 id="address">Address</h3>
<p>Base Address object used as shipping or billing <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> address in a payment. [Optional]</p></div></div><div class="code"><div class="wrapper"><span class="nv">$addr</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Address</span><span class="p">();</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setLine1</span><span class="p">(</span><span class="s2">&quot;3909 Witmer Road&quot;</span><span class="p">);</span> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setLine1</span><span class="p">(</span><span class="s2">&quot;3909 Witmer Road&quot;</span><span class="p">);</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setLine2</span><span class="p">(</span><span class="s2">&quot;Niagara Falls&quot;</span><span class="p">);</span> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setLine2</span><span class="p">(</span><span class="s2">&quot;Niagara Falls&quot;</span><span class="p">);</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setCity</span><span class="p">(</span><span class="s2">&quot;Niagara Falls&quot;</span><span class="p">);</span> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setCity</span><span class="p">(</span><span class="s2">&quot;Niagara Falls&quot;</span><span class="p">);</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setState</span><span class="p">(</span><span class="s2">&quot;NY&quot;</span><span class="p">);</span> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setState</span><span class="p">(</span><span class="s2">&quot;NY&quot;</span><span class="p">);</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setPostal_code</span><span class="p">(</span><span class="s2">&quot;14305&quot;</span><span class="p">);</span> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setPostal_code</span><span class="p">(</span><span class="s2">&quot;14305&quot;</span><span class="p">);</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setCountry_code</span><span class="p">(</span><span class="s2">&quot;US&quot;</span><span class="p">);</span> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setCountry_code</span><span class="p">(</span><span class="s2">&quot;US&quot;</span><span class="p">);</span>
<span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setPhone</span><span class="p">(</span><span class="s2">&quot;716-298-1822&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3> <span class="nv">$addr</span><span class="o">-&gt;</span><span class="na">setPhone</span><span class="p">(</span><span class="s2">&quot;716-298-1822&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="creditcard">CreditCard</h3>
<p>A resource representing a credit card that can be <p>A resource representing a credit card that can be
used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span> used to fund a payment.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$card</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCard</span><span class="p">();</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setType</span><span class="p">(</span><span class="s2">&quot;visa&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setType</span><span class="p">(</span><span class="s2">&quot;visa&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setNumber</span><span class="p">(</span><span class="s2">&quot;4417119669820331&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setNumber</span><span class="p">(</span><span class="s2">&quot;4417119669820331&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">&quot;11&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_month</span><span class="p">(</span><span class="s2">&quot;11&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">&quot;2019&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setExpire_year</span><span class="p">(</span><span class="s2">&quot;2019&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">&quot;012&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setCvv2</span><span class="p">(</span><span class="s2">&quot;012&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">&quot;Joe&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setFirst_name</span><span class="p">(</span><span class="s2">&quot;Joe&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">&quot;Shopper&quot;</span><span class="p">);</span> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setLast_name</span><span class="p">(</span><span class="s2">&quot;Shopper&quot;</span><span class="p">);</span>
<span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setBilling_address</span><span class="p">(</span><span class="nv">$addr</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3> <span class="nv">$card</span><span class="o">-&gt;</span><span class="na">setBilling_address</span><span class="p">(</span><span class="nv">$addr</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
<p>A resource representing a Payer's funding instrument. <p>A resource representing a Payer's funding instrument.
Use a Payer ID (A unique identifier of the payer generated Use a Payer ID (A unique identifier of the payer generated
and provided by the facilitator. This is required when and provided by the facilitator. This is required when
creating or using a tokenized funding instrument) creating or using a tokenized funding instrument)
and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span> and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span>
<span class="nv">$fi</span><span class="o">-&gt;</span><span class="na">setCredit_card</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow"></a></div><div class="wrapper"><h3 id="payer">Payer</h3> <span class="nv">$fi</span><span class="o">-&gt;</span><span class="na">setCredit_card</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow"></a></div><div class="wrapper"><h3 id="payer">Payer</h3>
<p>A resource representing a Payer that funds a payment <p>A resource representing a Payer that funds a payment
Use the List of <code>FundingInstrument</code> and the Payment Method Use the List of <code>FundingInstrument</code> and the Payment Method
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span> as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
<span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">&quot;credit_card&quot;</span><span class="p">);</span> <span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">&quot;credit_card&quot;</span><span class="p">);</span>
<span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow"></a></div><div class="wrapper"><h3 id="amount">Amount</h3> <span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow"></a></div><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span> <p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span> <span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow"></a></div><div class="wrapper"><h3 id="transaction">Transaction</h3> <span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow"></a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a <p>A transaction defines the contract of a
payment - what is the payment for and who payment - what is the payment for and who
is fulfilling it. Transaction is created with is fulfilling it. Transaction is created with
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span> a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
<span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span> <span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
<span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setDescription</span><span class="p">(</span><span class="s2">&quot;This is the payment description.&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow"></a></div><div class="wrapper"><h3 id="payment">Payment</h3> <span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setDescription</span><span class="p">(</span><span class="s2">&quot;This is the payment description.&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow"></a></div><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using <p>A Payment Resource; create one using
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span> 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">-&gt;</span><span class="na">setIntent</span><span class="p">(</span><span class="s2">&quot;sale&quot;</span><span class="p">);</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">setIntent</span><span class="p">(</span><span class="s2">&quot;sale&quot;</span><span class="p">);</span>
<span class="nv">$payment</span><span class="o">-&gt;</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">-&gt;</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">-&gt;</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> <span class="nv">$payment</span><span class="o">-&gt;</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>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">&#39;Request&#39;</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-10" name="segment-10" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-10" class="pilcrow"></a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by posting to the APIService <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> 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">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span> <span class="nv">$payment</span><span class="o">-&gt;</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="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">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</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="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span> <span class="p">}</span>
<span class="cp">?&gt;</span><span class="x"></span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;html&gt;</span> <span class="x">&lt;html&gt;</span>
<span class="x">&lt;body&gt;</span> <span class="x">&lt;body&gt;</span>
<span class="x"> &lt;div&gt;</span> <span class="x"> &lt;div&gt;</span>
<span class="x"> Created payment:</span> <span class="x"> Created payment:</span>
<span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x"></span> <span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x"></span>
<span class="x"> &lt;/div&gt;</span> <span class="x"> &lt;/div&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span> <span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -2,71 +2,66 @@
<p>This sample code demonstrates how you can process a <p>This sample code demonstrates how you can process a
PayPal Account based Payment. PayPal Account based Payment.
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\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\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\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\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\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> <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 <p>A resource representing a Payer that funds a payment
Use the List of <code>FundingInstrument</code> and the Payment Method Use the List of <code>FundingInstrument</code> and the Payment Method
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span> as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
<span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">&quot;paypal&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="amount">Amount</h3> <span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">&quot;paypal&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span> <p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span> <span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="transaction">Transaction</h3> <span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a <p>A transaction defines the contract of a
payment - what is the payment for and who payment - what is the payment for and who
is fulfilling it. Transaction is created with is fulfilling it. Transaction is created with
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span> a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
<span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span> <span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
<span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setDescription</span><span class="p">(</span><span class="s2">&quot;This is the payment description.&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow"></a></div><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3> <span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setDescription</span><span class="p">(</span><span class="s2">&quot;This is the payment description.&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow"></a></div><div class="wrapper"><h3 id="redirect-urls">Redirect urls</h3>
<p>Set the urls that the buyer must be redirected to after <p>Set the urls that the buyer must be redirected to after
payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$baseUrl</span> <span class="o">=</span> <span class="nx">getBaseUrl</span><span class="p">();</span> payment approval/ cancellation.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$baseUrl</span> <span class="o">=</span> <span class="nx">getBaseUrl</span><span class="p">();</span>
<span class="nv">$redirectUrls</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">RedirectUrls</span><span class="p">();</span> <span class="nv">$redirectUrls</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">RedirectUrls</span><span class="p">();</span>
<span class="nv">$redirectUrls</span><span class="o">-&gt;</span><span class="na">setReturn_url</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=true&quot;</span><span class="p">);</span> <span class="nv">$redirectUrls</span><span class="o">-&gt;</span><span class="na">setReturn_url</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=true&quot;</span><span class="p">);</span>
<span class="nv">$redirectUrls</span><span class="o">-&gt;</span><span class="na">setCancel_url</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=false&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow"></a></div><div class="wrapper"><h3 id="payment">Payment</h3> <span class="nv">$redirectUrls</span><span class="o">-&gt;</span><span class="na">setCancel_url</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">$baseUrl</span><span class="s2">/ExecutePayment.php?success=false&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow"></a></div><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using <p>A Payment Resource; create one using
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span> 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">-&gt;</span><span class="na">setIntent</span><span class="p">(</span><span class="s2">&quot;sale&quot;</span><span class="p">);</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">setIntent</span><span class="p">(</span><span class="s2">&quot;sale&quot;</span><span class="p">);</span>
<span class="nv">$payment</span><span class="o">-&gt;</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">-&gt;</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">-&gt;</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">-&gt;</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">-&gt;</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> <span class="nv">$payment</span><span class="o">-&gt;</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>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">&#39;Request&#39;</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-8" name="segment-8" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-8" class="pilcrow"></a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by posting to the APIService <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 The return object contains the status and the
url to which the buyer must be redirected to 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> for payment approval</p></div></div><div class="code"><div class="wrapper"><span class="k">try</span> <span class="p">{</span>
<span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span> <span class="nv">$payment</span><span class="o">-&gt;</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="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">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</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="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">-&gt;</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> <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">-&gt;</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">-&gt;</span><span class="na">getRel</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;approval_url&#39;</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">-&gt;</span><span class="na">getRel</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;approval_url&#39;</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">-&gt;</span><span class="na">getHref</span><span class="p">();</span> <span class="nv">$redirectUrl</span> <span class="o">=</span> <span class="nv">$link</span><span class="o">-&gt;</span><span class="na">getHref</span><span class="p">();</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 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">&#39;paymentId&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span> 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">&#39;paymentId&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span>
<span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$redirectUrl</span><span class="p">))</span> <span class="p">{</span> <span class="k">if</span><span class="p">(</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$redirectUrl</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">header</span><span class="p">(</span><span class="s2">&quot;Location: </span><span class="si">$redirectUrl</span><span class="s2">&quot;</span><span class="p">);</span> <span class="nx">header</span><span class="p">(</span><span class="s2">&quot;Location: </span><span class="si">$redirectUrl</span><span class="s2">&quot;</span><span class="p">);</span>
<span class="k">exit</span><span class="p">;</span> <span class="k">exit</span><span class="p">;</span>
<span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -2,76 +2,70 @@
<p>This sample code demonstrates how you can process a <p>This sample code demonstrates how you can process a
Payment using a previously saved credit card. Payment using a previously saved credit card.
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\Address</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\Amount</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\CreditCard</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\CreditCardToken</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\CreditCardToken</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\Payer</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\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\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\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\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\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\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>
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow"></a></div><div class="wrapper"><h3 id="credit-card-token">Credit card token</h3>
<p>Saved credit card id from a previous call to <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">&#39;CARD-5BT058015C739554AKE2GCEI&#39;</span><span class="p">;</span> CreateCreditCard.php</p></div></div><div class="code"><div class="wrapper"><span class="nv">$creditCardId</span> <span class="o">=</span> <span class="s1">&#39;CARD-5BT058015C739554AKE2GCEI&#39;</span><span class="p">;</span>
<span class="nv">$creditCardToken</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCardToken</span><span class="p">();</span> <span class="nv">$creditCardToken</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">CreditCardToken</span><span class="p">();</span>
<span class="nv">$creditCardToken</span><span class="o">-&gt;</span><span class="na">setCredit_card_id</span><span class="p">(</span><span class="nv">$creditCardId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3> <span class="nv">$creditCardToken</span><span class="o">-&gt;</span><span class="na">setCredit_card_id</span><span class="p">(</span><span class="nv">$creditCardId</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="fundinginstrument">FundingInstrument</h3>
<p>A resource representing a Payer's funding instrument. <p>A resource representing a Payer's funding instrument.
Use a Payer ID (A unique identifier of the payer generated Use a Payer ID (A unique identifier of the payer generated
and provided by the facilitator. This is required when and provided by the facilitator. This is required when
creating or using a tokenized funding instrument) creating or using a tokenized funding instrument)
and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span> and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper"><span class="nv">$fi</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FundingInstrument</span><span class="p">();</span>
<span class="nv">$fi</span><span class="o">-&gt;</span><span class="na">setCredit_card_token</span><span class="p">(</span><span class="nv">$creditCardToken</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="payer">Payer</h3> <span class="nv">$fi</span><span class="o">-&gt;</span><span class="na">setCredit_card_token</span><span class="p">(</span><span class="nv">$creditCardToken</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-4" name="segment-4" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-4" class="pilcrow"></a></div><div class="wrapper"><h3 id="payer">Payer</h3>
<p>A resource representing a Payer that funds a payment <p>A resource representing a Payer that funds a payment
Use the List of <code>FundingInstrument</code> and the Payment Method Use the List of <code>FundingInstrument</code> and the Payment Method
as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span> as 'credit_card'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payer</span><span class="p">();</span>
<span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">&quot;credit_card&quot;</span><span class="p">);</span> <span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setPayment_method</span><span class="p">(</span><span class="s2">&quot;credit_card&quot;</span><span class="p">);</span>
<span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow"></a></div><div class="wrapper"><h3 id="amount">Amount</h3> <span class="nv">$payer</span><span class="o">-&gt;</span><span class="na">setFunding_instruments</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$fi</span><span class="p">));</span></div></div></div><div class="segment"><a id="segment-5" name="segment-5" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-5" class="pilcrow"></a></div><div class="wrapper"><h3 id="amount">Amount</h3>
<p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span> <p>Let's you specify a payment amount.</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amount</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span> <span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s2">&quot;USD&quot;</span><span class="p">);</span>
<span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow"></a></div><div class="wrapper"><h3 id="transaction">Transaction</h3> <span class="nv">$amount</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s2">&quot;1.00&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-6" name="segment-6" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-6" class="pilcrow"></a></div><div class="wrapper"><h3 id="transaction">Transaction</h3>
<p>A transaction defines the contract of a <p>A transaction defines the contract of a
payment - what is the payment for and who payment - what is the payment for and who
is fulfilling it. Transaction is created with is fulfilling it. Transaction is created with
a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span> a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper"><span class="nv">$transaction</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Transaction</span><span class="p">();</span>
<span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span> <span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amount</span><span class="p">);</span>
<span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setDescription</span><span class="p">(</span><span class="s2">&quot;This is the payment description.&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow"></a></div><div class="wrapper"><h3 id="payment">Payment</h3> <span class="nv">$transaction</span><span class="o">-&gt;</span><span class="na">setDescription</span><span class="p">(</span><span class="s2">&quot;This is the payment description.&quot;</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-7" name="segment-7" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-7" class="pilcrow"></a></div><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one using <p>A Payment Resource; create one using
the above types and intent as 'sale'</p></div></div><div class="code"><div class="wrapper"><span class="nv">$payment</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Payment</span><span class="p">();</span> 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">-&gt;</span><span class="na">setIntent</span><span class="p">(</span><span class="s2">&quot;sale&quot;</span><span class="p">);</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">setIntent</span><span class="p">(</span><span class="s2">&quot;sale&quot;</span><span class="p">);</span>
<span class="nv">$payment</span><span class="o">-&gt;</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">-&gt;</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">-&gt;</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> <span class="nv">$payment</span><span class="o">-&gt;</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>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">&#39;Request&#39;</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span></div></div></div><div class="segment"><a id="segment-9" name="segment-9" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-9" class="pilcrow"></a></div><div class="wrapper"><h3 id="create-payment">Create Payment</h3>
<p>Create a payment by posting to the APIService <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> 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">-&gt;</span><span class="na">create</span><span class="p">(</span><span class="nv">$apiContext</span><span class="p">);</span> <span class="nv">$payment</span><span class="o">-&gt;</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="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">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</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="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span> <span class="p">}</span>
<span class="cp">?&gt;</span><span class="x"></span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;html&gt;</span> <span class="x">&lt;html&gt;</span>
<span class="x">&lt;body&gt;</span> <span class="x">&lt;body&gt;</span>
<span class="x"> &lt;div&gt;</span> <span class="x"> &lt;div&gt;</span>
<span class="x"> Created payment:</span> <span class="x"> Created payment:</span>
<span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x"></span> <span class="x"> </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">getId</span><span class="p">();</span><span class="cp">?&gt;</span><span class="x"></span>
<span class="x"> &lt;/div&gt;</span> <span class="x"> &lt;/div&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span> <span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -5,36 +5,28 @@ a payment that has been approved by
the buyer by logging into paypal site. the buyer by logging into paypal site.
You can optionally update transaction You can optionally update transaction
information by passing in one or more transactions. information by passing in one or more transactions.
API used: POST '/v1/payments/payment/<payment-id>/execute'.</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> API used: POST '/v1/payments/payment/<payment-id>/execute'.</p></div></div><div class="code"><div class="wrapper"><span class="k">require</span> <span class="nx">__DIR__</span> <span class="o">.</span> <span class="s1">&#39;/../bootstrap.php&#39;</span><span class="p">;</span>
<span class="k">use</span> <span class="nx">PayPal\Api\ExecutePayment</span><span class="p">;</span> <span class="k">use</span> <span class="nx">PayPal\Api\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\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\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="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">&#39;success&#39;</span><span class="p">])</span> <span class="o">&amp;&amp;</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">&#39;success&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;true&#39;</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
<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">&#39;success&#39;</span><span class="p">])</span> <span class="o">&amp;&amp;</span> <span class="nv">$_GET</span><span class="p">[</span><span class="s1">&#39;success&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;true&#39;</span><span class="p">)</span> <span class="p">{</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow"></a></div><div class="wrapper"><h3 id="api-context">Api Context</h3>
<p>Pass in a <code>ApiContext</code> object to authenticate
the call and to send a unique request id
(that ensures idempotency). The SDK generates
a request id if you do not pass one explicitly. </p></div></div><div class="code"><div class="wrapper"> <span class="nv">$apiContext</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ApiContext</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
</div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><p>Get the payment Object by passing paymentId
payment id was previously stored in session in 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">&#39;paymentId&#39;</span><span class="p">];</span> 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">&#39;paymentId&#39;</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">$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-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 </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. to execute a PayPal account payment.
The payer_id is added to the request query parameters 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> 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">-&gt;</span><span class="na">setPayer_id</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">&#39;PayerID&#39;</span><span class="p">]);</span> <span class="nv">$execution</span><span class="o">-&gt;</span><span class="na">setPayer_id</span><span class="p">(</span><span class="nv">$_GET</span><span class="p">[</span><span class="s1">&#39;PayerID&#39;</span><span class="p">]);</span>
<span class="c1">//Execute the payment</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">-&gt;</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="nv">$payment</span><span class="o">-&gt;</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">&quot;&lt;html&gt;&lt;body&gt;&lt;pre&gt;&quot;</span><span class="p">;</span>
<span class="k">echo</span> <span class="s2">&quot;&lt;html&gt;&lt;body&gt;&lt;pre&gt;&quot;</span><span class="p">;</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span>
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span> <span class="k">echo</span> <span class="s2">&quot;&lt;/pre&gt;&lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span class="p">;</span>
<span class="k">echo</span> <span class="s2">&quot;&lt;/pre&gt;&lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="k">echo</span> <span class="s2">&quot;User cancelled payment.&quot;</span><span class="p">;</span>
<span class="k">echo</span> <span class="s2">&quot;User cancelled payment.&quot;</span><span class="p">;</span>
<span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="p">}</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -5,27 +5,22 @@ retrieve previously saved CreditCards,
by sending a GET request to the URI by sending a GET request to the URI
'/v1/vault/credit-card' '/v1/vault/credit-card'
The following code takes you through The following code takes you through
the process of retrieving a saved CreditCard</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">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> 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">&#39;/../bootstrap.php&#39;</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 <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">&quot;CARD-5BT058015C739554AKE2GCEI&quot;</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">&quot;CARD-5BT058015C739554AKE2GCEI&quot;</span><span class="p">;</span>
<p>Pass in a <code>OAuthTokenCredential</code> object <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>
explicilty to authenticate the call. <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>
If you skip this step, the client id/secret <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>
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="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="c1">/// ### Retrieve card</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span>
<span class="k">try</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="nv">$card</span> <span class="o">=</span> <span class="nx">CreditCard</span><span class="o">::</span><span class="na">get</span><span class="p">(</span><span class="nv">$cardId</span><span class="p">);</span> <span class="p">}</span>
<span class="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="cp">?&gt;</span><span class="x"></span>
<span class="k">echo</span> <span class="s2">&quot;Exception: &quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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">&lt;html&gt;</span>
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="x">&lt;body&gt;</span>
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="x"> &lt;div&gt;Retrieving credit card: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$cardId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span>
<span class="p">}</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="cp">?&gt;</span><span class="x"></span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;html&gt;</span> <span class="x">&lt;/body&gt;</span>
<span class="x">&lt;body&gt;</span>
<span class="x"> &lt;div&gt;Retrieving credit card: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$cardId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$card</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -6,29 +6,27 @@ you've created using the Payments API.
Note various query parameters that you can Note various query parameters that you can
use to filter, and paginate through the use to filter, and paginate through the
payments list. 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">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> 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">&#39;/../bootstrap.php&#39;</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\Payment</span><span class="p">;</span>
<span class="nv">$paymentId</span> <span class="o">=</span> <span class="s2">&quot;PAY-0XL713371A312273YKE2GCNI&quot;</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">$paymentId</span> <span class="o">=</span> <span class="s2">&quot;PAY-0XL713371A312273YKE2GCNI&quot;</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>Pass in a <code>OAuthTokenCredential</code> object
explicilty to authenticate the call. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<p>Retrieve the payment object by calling the <p>Retrieve the payment object by calling the
static <code>get</code> method static <code>get</code> method
on the Payment class by passing a valid 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> Payment ID
<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> (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="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="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="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="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="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</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="cp">?&gt;</span><span class="x"></span> <span class="p">}</span>
<span class="x">&lt;html&gt;</span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;body&gt;</span> <span class="x">&lt;html&gt;</span>
<span class="x"> &lt;div&gt;Retrieving Payment ID: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$paymentId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span> <span class="x">&lt;body&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="x"> &lt;div&gt;Retrieving Payment ID: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$paymentId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payment</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x">&lt;/body&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -2,29 +2,25 @@
<p>This sample code demonstrates how you can retrieve <p>This sample code demonstrates how you can retrieve
details of completed Sale Transaction. details of completed Sale Transaction.
API used: /v1/payments/sale/{sale-id}</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">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> 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">&#39;/../bootstrap.php&#39;</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\Api\Sale</span><span class="p">;</span>
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">&#39;3RM92092UW5126232&#39;</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">&#39;3RM92092UW5126232&#39;</span><span class="p">;</span>
<p>Pass in a <code>OAuthTokenCredential</code> object <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>
explicilty to authenticate the call.
If you skip this step, the client id/secret
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Sale</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span>
<span class="k">try</span> <span class="p">{</span> </div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="retrieve-the-sale-object">Retrieve the sale object</h3>
<p>Pass the ID of the sale <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="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">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</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="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span> <span class="p">}</span>
<span class="cp">?&gt;</span><span class="x"></span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;html&gt;</span> <span class="x">&lt;html&gt;</span>
<span class="x">&lt;body&gt;</span> <span class="x">&lt;body&gt;</span>
<span class="x"> &lt;div&gt;Retrieving sale id: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span> <span class="x"> &lt;div&gt;Retrieving sale id: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span> <span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -6,30 +6,26 @@ you've created using the Payments API.
Note various query parameters that you can Note various query parameters that you can
use to filter, and paginate through the use to filter, and paginate through the
payments list. 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">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> 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">&#39;/../bootstrap.php&#39;</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> <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>Pass in a <code>OAuthTokenCredential</code> object
explicilty to authenticate the call.
If you skip this step, the client id/secret
set in the config file will be used. </p></div></div><div class="code"><div class="wrapper"><span class="nx">Payment</span><span class="o">::</span><span class="na">setCredential</span><span class="p">(</span><span class="nv">$cred</span><span class="p">);</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="retrieve-payment">Retrieve payment</h3>
<p>Retrieve the PaymentHistory object by calling the <p>Retrieve the PaymentHistory object by calling the
static <code>get</code> method on the Payment class, static <code>get</code> method on the Payment class,
and pass a Map object that contains and pass a Map object that contains
query parameters for paginations and filtering. 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> Refer the method doc for valid values for keys
<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">&#39;count&#39;</span> <span class="o">=&gt;</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;start_index&#39;</span> <span class="o">=&gt;</span> <span class="mi">5</span><span class="p">));</span> (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="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="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">&#39;count&#39;</span> <span class="o">=&gt;</span> <span class="mi">10</span><span class="p">,</span> <span class="s1">&#39;start_index&#39;</span> <span class="o">=&gt;</span> <span class="mi">5</span><span class="p">),</span> <span class="nv">$apiContext</span><span class="p">);</span>
<span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="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="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</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="cp">?&gt;</span><span class="x"></span> <span class="p">}</span>
<span class="x">&lt;html&gt;</span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="x">&lt;body&gt;</span> <span class="x">&lt;html&gt;</span>
<span class="x"> &lt;div&gt;Got </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$payments</span><span class="o">-&gt;</span><span class="na">getCount</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"> matching payments &lt;/div&gt;</span> <span class="x">&lt;body&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payments</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span> <span class="x"> &lt;div&gt;Got </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$payments</span><span class="o">-&gt;</span><span class="na">getCount</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="x"> matching payments &lt;/div&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$payments</span><span class="o">-&gt;</span><span class="na">toArray</span><span class="p">());</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x">&lt;/body&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -3,42 +3,38 @@
<p>This sample code demonstrate how you can <p>This sample code demonstrate how you can
process a refund on a sale transaction created process a refund on a sale transaction created
using the Payments API. 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">&#39;/../bootstrap.php&#39;</span><span class="p">;</span> 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">&#39;/../bootstrap.php&#39;</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\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\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\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>
<span class="k">use</span> <span class="nx">PayPal\Rest\ApiContext</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-2" name="segment-2" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-2" class="pilcrow"></a></div><div class="wrapper"><h3 id="refund">Refund</h3>
<p>Create a refund object indicating <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> refund amount</p></div></div><div class="code"><div class="wrapper"><span class="nv">$amt</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Amount</span><span class="p">();</span>
<span class="nv">$amt</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s1">&#39;USD&#39;</span><span class="p">);</span> <span class="nv">$amt</span><span class="o">-&gt;</span><span class="na">setCurrency</span><span class="p">(</span><span class="s1">&#39;USD&#39;</span><span class="p">);</span>
<span class="nv">$amt</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s1">&#39;0.01&#39;</span><span class="p">);</span> <span class="nv">$amt</span><span class="o">-&gt;</span><span class="na">setTotal</span><span class="p">(</span><span class="s1">&#39;0.01&#39;</span><span class="p">);</span>
<span class="nv">$refund</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Refund</span><span class="p">();</span> <span class="nv">$refund</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Refund</span><span class="p">();</span>
<span class="nv">$refund</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amt</span><span class="p">);</span> <span class="nv">$refund</span><span class="o">-&gt;</span><span class="na">setAmount</span><span class="p">(</span><span class="nv">$amt</span><span class="p">);</span>
<span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">&#39;3RM92092UW5126232&#39;</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="sale">Sale</h3> <span class="nv">$saleId</span> <span class="o">=</span> <span class="s1">&#39;3RM92092UW5126232&#39;</span><span class="p">;</span></div></div></div><div class="segment"><a id="segment-3" name="segment-3" class="section_anchor"></a><div class="comments"><div class="pilwrap"><a href="#segment-3" class="pilcrow"></a></div><div class="wrapper"><h3 id="sale">Sale</h3>
<p>A sale transaction. <p>A sale transaction.
Create a Sale object with the 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> 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">-&gt;</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">-&gt;</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 <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
the call and to send a unique request id (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">-&gt;</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>
(that ensures idempotency). The SDK generates <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>
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">&#39;Request&#39;</span> <span class="o">.</span> <span class="nb">time</span><span class="p">());</span> <span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="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">-&gt;</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="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</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">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="k">echo</span> <span class="s2">&quot;Exception:&quot;</span> <span class="o">.</span> <span class="nv">$ex</span><span class="o">-&gt;</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="p">}</span>
<span class="nb">var_dump</span><span class="p">(</span><span class="nv">$ex</span><span class="o">-&gt;</span><span class="na">getData</span><span class="p">());</span> <span class="cp">?&gt;</span><span class="x"></span>
<span class="k">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="x">&lt;html&gt;</span>
<span class="p">}</span> <span class="x">&lt;body&gt;</span>
<span class="cp">?&gt;</span><span class="x"></span> <span class="x"> &lt;div&gt;Refunding sale id: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span>
<span class="x">&lt;html&gt;</span> <span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x">&lt;body&gt;</span> <span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x"> &lt;div&gt;Refunding sale id: </span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$saleId</span><span class="p">;</span><span class="cp">?&gt;</span><span class="x">&lt;/div&gt;</span> <span class="x">&lt;/body&gt;</span>
<span class="x"> &lt;pre&gt;</span><span class="cp">&lt;?php</span> <span class="nb">var_dump</span><span class="p">(</span><span class="nv">$sale</span><span class="p">);</span><span class="cp">?&gt;</span><span class="x">&lt;/pre&gt;</span>
<span class="x"> &lt;a href=&#39;../index.html&#39;&gt;Back&lt;/a&gt;</span>
<span class="x">&lt;/body&gt;</span>
<span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html> <span class="x">&lt;/html&gt;</span></div></div></div><div class="segment"><div class="comments"><a href="../">Back</a></div></div></div><script type="text/javascript" src="assets/jquery.min.js"></script><script type="text/javascript" src="assets/docs.js"></script></body></html>

View File

@@ -1,57 +1,50 @@
<?php <?php
// # Create Credit Card Sample
// Using the 'vault' API, you can store a
// Credit Card securely on PayPal. You can
// use a saved Credit Card to process
// a payment in the future.
// The following code demonstrates how
// can save a Credit Card on PayPal using
// the Vault API.
// API used: POST /v1/vault/credit-card
// # Create Credit Card Sample
// Using the 'vault' API, you can store a require __DIR__ . '/../bootstrap.php';
// Credit Card securely on PayPal. You can use PayPal\Api\CreditCard;
// use a saved Credit Card to process use PayPal\Api\Address;
// a payment in the future.
// The following code demonstrates how // ### CreditCard
// can save a Credit Card on PayPal using // A resource representing a credit card that can be
// the Vault API. // used to fund a payment.
// API used: POST /v1/vault/credit-card $card = new CreditCard();
$card->setType("visa");
use PayPal\Rest\ApiContext; $card->setNumber("4417119669820331");
$card->setExpire_month("11");
require __DIR__ . '/../bootstrap.php'; $card->setExpire_year("2019");
use PayPal\Api\CreditCard; $card->setCvv2("012");
use PayPal\Api\Address; $card->setFirst_name("Joe");
$card->setLast_name("Shopper");
// ### CreditCard
// A resource representing a credit card that can be // ### Save card
// used to fund a payment. // Creates the credit card as a resource
$card = new CreditCard(); // in the PayPal vault. The response contains
$card->setType("visa"); // an 'id' that you can use to refer to it
$card->setNumber("4417119669820331"); // in the future payments.
$card->setExpire_month("11"); // (See bootstrap.php for more on `ApiContext`)
$card->setExpire_year("2019"); try {
$card->setCvv2("012"); $card->create($apiContext);
$card->setFirst_name("Joe"); } catch (\PPConnectionException $ex) {
$card->setLast_name("Shopper"); echo "Exception:" . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
// ### Api Context exit(1);
// Pass in a `ApiContext` object to authenticate }
// the call and to send a unique request id ?>
// (that ensures idempotency). The SDK generates <html>
// a request id if you do not pass one explicitly. <body>
$apiContext = new ApiContext($cred, 'Request' . time()); <div>Saved a new credit card with id: <?php echo $card->getId();?></div>
<pre><?php var_dump($card);?></pre>
// ### Save card <a href='../index.html'>Back</a>
// Creates the credit card as a resource </body>
// in the PayPal vault. The response contains
// an 'id' that you can use to refer to it
// in the future payments.
try {
$card->create();
} catch (\PPConnectionException $ex) {
echo "Exception:" . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
exit(1);
}
?>
<html>
<body>
<div>Saved a new credit card with id: <?php echo $card->getId();?></div>
<pre><?php var_dump($card);?></pre>
<a href='../index.html'>Back</a>
</body>
</html> </html>

View File

@@ -1,38 +1,33 @@
<?php <?php
// # Get Credit Card Sample // # Get Credit Card Sample
// The CreditCard resource allows you to // The CreditCard resource allows you to
// retrieve previously saved CreditCards, // retrieve previously saved CreditCards,
// by sending a GET request to the URI // by sending a GET request to the URI
// '/v1/vault/credit-card' // '/v1/vault/credit-card'
// The following code takes you through // The following code takes you through
// the process of retrieving a saved CreditCard // the process of retrieving a saved CreditCard
require __DIR__ . '/../bootstrap.php'; require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard; use PayPal\Api\CreditCard;
// The cardId can be obtained from a previous save credit // The cardId can be obtained from a previous save credit
// card operation. Use $card->getId() // card operation. Use $card->getId()
$cardId = "CARD-5BT058015C739554AKE2GCEI"; $cardId = "CARD-5BT058015C739554AKE2GCEI";
// ### Authentication /// ### Retrieve card
// Pass in a `OAuthTokenCredential` object // (See bootstrap.php for more on `ApiContext`)
// explicilty to authenticate the call. try {
// If you skip this step, the client id/secret $card = CreditCard::get($cardId, $apiContext);
// set in the config file will be used. } catch (\PPConnectionException $ex) {
CreditCard::setCredential($cred); echo "Exception: " . $ex->getMessage() . PHP_EOL;
/// ### Retrieve card var_dump($ex->getData());
try { exit(1);
$card = CreditCard::get($cardId); }
} catch (\PPConnectionException $ex) { ?>
echo "Exception: " . $ex->getMessage() . PHP_EOL; <html>
var_dump($ex->getData()); <body>
exit(1); <div>Retrieving credit card: <?php echo $cardId;?></div>
} <pre><?php var_dump($card);?></pre>
?> <a href='../index.html'>Back</a>
<html> </body>
<body>
<div>Retrieving credit card: <?php echo $cardId;?></div>
<pre><?php var_dump($card);?></pre>
<a href='../index.html'>Back</a>
</body>
</html> </html>

View File

@@ -1,33 +1,34 @@
<?php <?php
// namespace PayPal\Test\Common; // namespace PayPal\Test\Common;
use PayPal\Auth\OAuthTokenCredential; use PayPal\Auth\OAuthTokenCredential;
use PayPal\Test\Constants; use PayPal\Test\Constants;
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase { class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
public function testGetAccessToken() { public function testGetAccessToken() {
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET); $cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$config = \PPConfigManager::getInstance()->getConfigHashmap();
$token = $cred->getAccessToken();
$this->assertNotNull($token); $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(); // Check that we get the same token when issuing a new call before token expiry
$this->assertNotNull($newToken); $newToken = $cred->getAccessToken($config);
$this->assertEquals($token, $newToken); $this->assertNotNull($newToken);
$this->assertEquals($token, $newToken);
// sleep(60*8);
// $newToken = $cred->getAccessToken(); // sleep(60*8);
// $this->assertNotNull($newToken); // $newToken = $cred->getAccessToken();
// $this->assertNotEqual($token, $newToken); // $this->assertNotNull($newToken);
// $this->assertNotEqual($token, $newToken);
}
}
public function testInvalidCredentials() {
$this->setExpectedException('\PPConnectionException'); public function testInvalidCredentials() {
$cred = new OAuthTokenCredential('dummy', 'secret'); $this->setExpectedException('\PPConnectionException');
$this->assertNull($cred->getAccessToken()); $cred = new OAuthTokenCredential('dummy', 'secret');
} $this->assertNull($cred->getAccessToken(\PPConfigManager::getInstance()->getConfigHashmap()));
}
} }

View File

@@ -1,22 +1,21 @@
<?php <?php
// namespace PayPal\Test\Common; // namespace PayPal\Test\Common;
use PayPal\Common\ArrayUtil;
class ArrayUtilTest extends PHPUnit_Framework_TestCase {
class ArrayUtilTest extends PHPUnit_Framework_TestCase {
public function testIsAssocArray() {
public function testIsAssocArray() {
$arr = array(1, 2, 3);
$arr = array(1, 2, 3); $this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
$arr = array(
$arr = array( 'name' => 'John Doe',
'name' => 'John Doe', 'City' => 'San Jose'
'City' => 'San Jose' );
); $this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
$this->assertEquals(true, ArrayUtil::isAssocArray($arr));
$arr[] = 'CA';
$arr[] = 'CA'; $this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
$this->assertEquals(false, ArrayUtil::isAssocArray($arr)); }
} }
}

View File

@@ -1,135 +1,138 @@
<?php <?php
// namespace PayPal\Test\Common; // namespace PayPal\Test\Common;
use PayPal\Common\Model;
class SimpleClass extends \PPModel {
class SimpleClass extends Model {
public function setName($name) {
public function setName($name) { $this->name = $name;
$this->name = $name; }
} public function getName() {
public function getName() { return $this->name;
return $this->name; }
}
public function setDescription($desc) {
public function setDescription($desc) { $this->desc = $desc;
$this->desc = $desc; }
} public function getDescription() {
public function getDescription() { return $this->desc;
return $this->desc; }
} }
}
class ArrayClass extends \PPModel {
class ArrayClass extends Model {
public function setName($name) {
public function setName($name) { $this->name = $name;
$this->name = $name; }
} public function getName() {
public function getName() { return $this->name;
return $this->name; }
}
public function setDescription($desc) {
public function setDescription($desc) { $this->desc = $desc;
$this->desc = $desc; }
} public function getDescription() {
public function getDescription() { return $this->desc;
return $this->desc; }
}
public function setTags($tags) {
public function setTags($tags) { if(!is_array($tags)) {
if(!is_array($tags)) { $tags = array($tags);
$tags = array($tags); }
} $this->tags = $tags;
$this->tags = $tags; }
} public function getTags() {
public function getTags() { return $this->tags;
return $this->tags; }
} }
}
class NestedClass extends \PPModel {
class NestedClass extends Model {
public function setId($id) {
public function setId($id) { $this->id = $id;
$this->id = $id; }
} public function getId() {
public function getId() { return $this->id;
return $this->id; }
}
/**
/** *
* * @param ArrayClass $info
* @param ArrayClass $info */
*/ public function setInfo($info) {
public function setInfo($info) { $this->info = $info;
$this->info = $info; }
} /**
public function getInfo() { *
return $this->info; * @return ArrayClass
} */
} public function getInfo() {
return $this->info;
class ChildClass extends SimpleClass { }
}
}
class ChildClass extends SimpleClass {
class ModelTest extends PHPUnit_Framework_TestCase {
}
public function testSimpleClassConversion() {
$o = new SimpleClass(); class ModelTest extends PHPUnit_Framework_TestCase {
$o->setName("test");
$o->setDescription("description"); public function testSimpleClassConversion() {
$o = new SimpleClass();
$this->assertEquals("test", $o->getName()); $o->setName("test");
$this->assertEquals("description", $o->getDescription()); $o->setDescription("description");
$json = $o->toJSON(); $this->assertEquals("test", $o->getName());
$this->assertEquals('{"name":"test","desc":"description"}', $json); $this->assertEquals("description", $o->getDescription());
$newO = new SimpleClass(); $json = $o->toJSON();
$newO->fromJson($json); $this->assertEquals('{"name":"test","desc":"description"}', $json);
$this->assertEquals($o, $newO);
$newO = new SimpleClass();
} $newO->fromJson($json);
$this->assertEquals($o, $newO);
public function testArrayClassConversion() { }
$o = new ArrayClass();
$o->setName("test");
$o->setDescription("description"); public function testArrayClassConversion() {
$o->setTags(array('payment', 'info', 'test')); $o = new ArrayClass();
$o->setName("test");
$this->assertEquals("test", $o->getName()); $o->setDescription("description");
$this->assertEquals("description", $o->getDescription()); $o->setTags(array('payment', 'info', 'test'));
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
$this->assertEquals("test", $o->getName());
$json = $o->toJSON(); $this->assertEquals("description", $o->getDescription());
$this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json); $this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
$newO = new ArrayClass(); $json = $o->toJSON();
$newO->fromJson($json); $this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json);
$this->assertEquals($o, $newO);
} $newO = new ArrayClass();
$newO->fromJson($json);
public function testNestedClassConversion() { $this->assertEquals($o, $newO);
$n = new ArrayClass(); }
$n->setName("test");
$n->setDescription("description"); public function testNestedClassConversion() {
// $n->setTags(array('payment', 'info', 'test')); $n = new ArrayClass();
$o = new NestedClass(); $n->setName("test");
$o->setId('123'); $n->setDescription("description");
$o->setInfo($n); // $n->setTags(array('payment', 'info', 'test'));
$o = new NestedClass();
$this->assertEquals("123", $o->getId()); $o->setId('123');
$this->assertEquals("test", $o->getInfo()->getName()); $o->setInfo($n);
// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
$this->assertEquals("123", $o->getId());
$json = $o->toJSON(); $this->assertEquals("test", $o->getInfo()->getName());
// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json); // $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
$this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
$json = $o->toJSON();
$newO = new NestedClass(); // $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
$newO->fromJson($json); $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
$this->assertEquals($o, $newO);
} $newO = new NestedClass();
} $newO->fromJson($json);
$this->assertEquals($o, $newO);
}
}

View File

@@ -1,23 +1,26 @@
<?php <?php
use PayPal\Common\UserAgent; use PayPal\Common\UserAgent;
class UserAgentTest extends PHPUnit_Framework_TestCase { class UserAgentTest extends PHPUnit_Framework_TestCase {
public function testGetValue() { public function testGetValue() {
$ua = UserAgent::getValue(); $ua = PPUserAgent::getValue("name", "version");
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)"); list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
// Check that we pass the useragent in the expected format // Check that we pass the useragent in the expected format
$this->assertNotNull($id); $this->assertNotNull($id);
$this->assertNotNull($version); $this->assertNotNull($version);
$this->assertNotNull($features); $this->assertNotNull($features);
// Check that we pass in these mininal features $this->assertEquals("name", $id);
$this->assertThat($features, $this->stringContains("OS=")); $this->assertEquals("version", $version);
$this->assertThat($features, $this->stringContains("Bit="));
$this->assertThat($features, $this->stringContains("Lang=")); // Check that we pass in these mininal features
$this->assertThat($features, $this->stringContains("V=")); $this->assertThat($features, $this->stringContains("OS="));
$this->assertGreaterThan(5, count(explode(';', $features))); $this->assertThat($features, $this->stringContains("Bit="));
} $this->assertThat($features, $this->stringContains("Lang="));
$this->assertThat($features, $this->stringContains("V="));
$this->assertGreaterThan(5, count(explode(';', $features)));
}
} }