Initial commit

This commit is contained in:
aydiv
2013-03-06 18:42:06 +05:30
commit 69cb3c4dcb
101 changed files with 6222 additions and 0 deletions

132
lib/PayPal/Api/Address.php Normal file
View File

@@ -0,0 +1,132 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Address extends Resource {
/**
* Setter for line1
* @param string $line1
*/
public function setLine1($line1) {
$this->line1 = $line1;
}
/**
* Getter for line1
*/
public function getLine1() {
return $this->line1;
}
/**
* Setter for line2
* @param string $line2
*/
public function setLine2($line2) {
$this->line2 = $line2;
}
/**
* Getter for line2
*/
public function getLine2() {
return $this->line2;
}
/**
* Setter for city
* @param string $city
*/
public function setCity($city) {
$this->city = $city;
}
/**
* Getter for city
*/
public function getCity() {
return $this->city;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for postal_code
* @param string $postal_code
*/
public function setPostal_code($postal_code) {
$this->postal_code = $postal_code;
}
/**
* Getter for postal_code
*/
public function getPostal_code() {
return $this->postal_code;
}
/**
* Setter for country_code
* @param string $country_code
*/
public function setCountry_code($country_code) {
$this->country_code = $country_code;
}
/**
* Getter for country_code
*/
public function getCountry_code() {
return $this->country_code;
}
/**
* Setter for type
* @param string $type
*/
public function setType($type) {
$this->type = $type;
}
/**
* Getter for type
*/
public function getType() {
return $this->type;
}
/**
* Setter for phone
* @param string $phone
*/
public function setPhone($phone) {
$this->phone = $phone;
}
/**
* Getter for phone
*/
public function getPhone() {
return $this->phone;
}
}

57
lib/PayPal/Api/Amount.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Amount extends Resource {
/**
* Setter for total
* @param string $total
*/
public function setTotal($total) {
$this->total = $total;
}
/**
* Getter for total
*/
public function getTotal() {
return $this->total;
}
/**
* Setter for currency
* @param string $currency
*/
public function setCurrency($currency) {
$this->currency = $currency;
}
/**
* Getter for currency
*/
public function getCurrency() {
return $this->currency;
}
/**
* Setter for details
* @param PayPal\Api\AmountDetails $details
*/
public function setDetails($details) {
$this->details = $details;
}
/**
* Getter for details
*/
public function getDetails() {
return $this->details;
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace PayPal\Api;
/**
*
*/
class AmountDetails extends Resource {
/**
* Setter for subtotal
* @param string $subtotal
*/
public function setSubtotal($subtotal) {
$this->subtotal = $subtotal;
}
/**
* Getter for subtotal
*/
public function getSubtotal() {
return $this->subtotal;
}
/**
* Setter for tax
* @param string $tax
*/
public function setTax($tax) {
$this->tax = $tax;
}
/**
* Getter for tax
*/
public function getTax() {
return $this->tax;
}
/**
* Setter for shipping
* @param string $shipping
*/
public function setShipping($shipping) {
$this->shipping = $shipping;
}
/**
* Getter for shipping
*/
public function getShipping() {
return $this->shipping;
}
/**
* Setter for fee
* @param string $fee
*/
public function setFee($fee) {
$this->fee = $fee;
}
/**
* Getter for fee
*/
public function getFee() {
return $this->fee;
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Authorization extends Resource {
/**
* Setter for id
* @param string $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* Getter for id
*/
public function getId() {
return $this->id;
}
/**
* Setter for create_time
* @param string $create_time
*/
public function setCreate_time($create_time) {
$this->create_time = $create_time;
}
/**
* Getter for create_time
*/
public function getCreate_time() {
return $this->create_time;
}
/**
* Setter for update_time
* @param string $update_time
*/
public function setUpdate_time($update_time) {
$this->update_time = $update_time;
}
/**
* Getter for update_time
*/
public function getUpdate_time() {
return $this->update_time;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for amount
* @param PayPal\Api\Amount $amount
*/
public function setAmount($amount) {
$this->amount = $amount;
}
/**
* Getter for amount
*/
public function getAmount() {
return $this->amount;
}
/**
* Setter for parent_payment
* @param string $parent_payment
*/
public function setParent_payment($parent_payment) {
$this->parent_payment = $parent_payment;
}
/**
* Getter for parent_payment
*/
public function getParent_payment() {
return $this->parent_payment;
}
/**
* Setter for links
* @param PayPal\Api\Link $links
*/
public function setLinks($links) {
$this->links = $links;
}
/**
* Getter for links
*/
public function getLinks() {
return $this->links;
}
}

147
lib/PayPal/Api/Capture.php Normal file
View File

@@ -0,0 +1,147 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Capture extends Resource {
/**
* Setter for id
* @param string $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* Getter for id
*/
public function getId() {
return $this->id;
}
/**
* Setter for create_time
* @param string $create_time
*/
public function setCreate_time($create_time) {
$this->create_time = $create_time;
}
/**
* Getter for create_time
*/
public function getCreate_time() {
return $this->create_time;
}
/**
* Setter for update_time
* @param string $update_time
*/
public function setUpdate_time($update_time) {
$this->update_time = $update_time;
}
/**
* Getter for update_time
*/
public function getUpdate_time() {
return $this->update_time;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for amount
* @param PayPal\Api\Amount $amount
*/
public function setAmount($amount) {
$this->amount = $amount;
}
/**
* Getter for amount
*/
public function getAmount() {
return $this->amount;
}
/**
* Setter for parent_payment
* @param string $parent_payment
*/
public function setParent_payment($parent_payment) {
$this->parent_payment = $parent_payment;
}
/**
* Getter for parent_payment
*/
public function getParent_payment() {
return $this->parent_payment;
}
/**
* Setter for authorization_id
* @param string $authorization_id
*/
public function setAuthorization_id($authorization_id) {
$this->authorization_id = $authorization_id;
}
/**
* Getter for authorization_id
*/
public function getAuthorization_id() {
return $this->authorization_id;
}
/**
* Setter for description
* @param string $description
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* Getter for description
*/
public function getDescription() {
return $this->description;
}
/**
* Setter for links
* @param PayPal\Api\Link $links
*/
public function setLinks($links) {
$this->links = $links;
}
/**
* Getter for links
*/
public function getLinks() {
return $this->links;
}
}

View File

@@ -0,0 +1,253 @@
<?php
namespace PayPal\Api;
use PayPal\Rest\IResource;
use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
*
*/
class CreditCard extends Resource implements IResource {
private static $credential;
public static function setCredential($credential) {
self::$credential = $credential;
}
/**
* Setter for id
* @param string $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* Getter for id
*/
public function getId() {
return $this->id;
}
/**
* Setter for valid_until
* @param string $valid_until
*/
public function setValid_until($valid_until) {
$this->valid_until = $valid_until;
}
/**
* Getter for valid_until
*/
public function getValid_until() {
return $this->valid_until;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for payer_id
* @param string $payer_id
*/
public function setPayer_id($payer_id) {
$this->payer_id = $payer_id;
}
/**
* Getter for payer_id
*/
public function getPayer_id() {
return $this->payer_id;
}
/**
* Setter for type
* @param string $type
*/
public function setType($type) {
$this->type = $type;
}
/**
* Getter for type
*/
public function getType() {
return $this->type;
}
/**
* Setter for number
* @param string $number
*/
public function setNumber($number) {
$this->number = $number;
}
/**
* Getter for number
*/
public function getNumber() {
return $this->number;
}
/**
* Setter for expire_month
* @param string $expire_month
*/
public function setExpire_month($expire_month) {
$this->expire_month = $expire_month;
}
/**
* Getter for expire_month
*/
public function getExpire_month() {
return $this->expire_month;
}
/**
* Setter for expire_year
* @param string $expire_year
*/
public function setExpire_year($expire_year) {
$this->expire_year = $expire_year;
}
/**
* Getter for expire_year
*/
public function getExpire_year() {
return $this->expire_year;
}
/**
* Setter for cvv2
* @param string $cvv2
*/
public function setCvv2($cvv2) {
$this->cvv2 = $cvv2;
}
/**
* Getter for cvv2
*/
public function getCvv2() {
return $this->cvv2;
}
/**
* Setter for first_name
* @param string $first_name
*/
public function setFirst_name($first_name) {
$this->first_name = $first_name;
}
/**
* Getter for first_name
*/
public function getFirst_name() {
return $this->first_name;
}
/**
* Setter for last_name
* @param string $last_name
*/
public function setLast_name($last_name) {
$this->last_name = $last_name;
}
/**
* Getter for last_name
*/
public function getLast_name() {
return $this->last_name;
}
/**
* Setter for billing_address
* @param PayPal\Api\Address $billing_address
*/
public function setBilling_address($billing_address) {
$this->billing_address = $billing_address;
}
/**
* Getter for billing_address
*/
public function getBilling_address() {
return $this->billing_address;
}
/**
* Setter for links
* @param PayPal\Api\Link $links
*/
public function setLinks($links) {
$this->links = $links;
}
/**
* Getter for links
*/
public function getLinks() {
return $this->links;
}
/**
* @path /v1/vault/credit-card
* @method POST
* @param PayPal\Rest\ApiContext $apiContext optional
*/
public function create( $apiContext=null) {
$payLoad = $this->toJSON();
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
$call = new Call();
$json = $call->execute("/v1/vault/credit-card", "POST", $payLoad, $apiContext);
$this->fromJson($json);
return $this;
}
/**
* @path /v1/vault/credit-card/:credit-card-id
* @method GET
* @param string $creditcardid
*/
public static function get( $creditcardid) {
if (($creditcardid == null) || (strlen($creditcardid) <= 0)) {
throw new \InvalidArgumentException("creditcardid cannot be null or empty");
}
$payLoad = "";
$apiContext = new ApiContext(self::$credential); $call = new Call();
$json = $call->execute("/v1/vault/credit-card/$creditcardid", "GET", $payLoad, $apiContext);
$ret = new CreditCard();
$ret->fromJson($json);
return $ret;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
/**
*
*/
class CreditCardToken extends Resource {
/**
* Setter for credit_card_id
* @param string $credit_card_id
*/
public function setCredit_card_id($credit_card_id) {
$this->credit_card_id = $credit_card_id;
}
/**
* Getter for credit_card_id
*/
public function getCredit_card_id() {
return $this->credit_card_id;
}
/**
* Setter for payer_id
* @param string $payer_id
*/
public function setPayer_id($payer_id) {
$this->payer_id = $payer_id;
}
/**
* Getter for payer_id
*/
public function getPayer_id() {
return $this->payer_id;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
/**
*
*/
class FundingInstrument extends Resource {
/**
* Setter for credit_card
* @param PayPal\Api\CreditCard $credit_card
*/
public function setCredit_card($credit_card) {
$this->credit_card = $credit_card;
}
/**
* Getter for credit_card
*/
public function getCredit_card() {
return $this->credit_card;
}
/**
* Setter for credit_card_token
* @param PayPal\Api\CreditCardToken $credit_card_token
*/
public function setCredit_card_token($credit_card_token) {
$this->credit_card_token = $credit_card_token;
}
/**
* Getter for credit_card_token
*/
public function getCredit_card_token() {
return $this->credit_card_token;
}
}

87
lib/PayPal/Api/Item.php Normal file
View File

@@ -0,0 +1,87 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Item extends Resource {
/**
* Setter for name
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}
/**
* Getter for name
*/
public function getName() {
return $this->name;
}
/**
* Setter for sku
* @param string $sku
*/
public function setSku($sku) {
$this->sku = $sku;
}
/**
* Getter for sku
*/
public function getSku() {
return $this->sku;
}
/**
* Setter for price
* @param string $price
*/
public function setPrice($price) {
$this->price = $price;
}
/**
* Getter for price
*/
public function getPrice() {
return $this->price;
}
/**
* Setter for currency
* @param string $currency
*/
public function setCurrency($currency) {
$this->currency = $currency;
}
/**
* Getter for currency
*/
public function getCurrency() {
return $this->currency;
}
/**
* Setter for quantity
* @param string $quantity
*/
public function setQuantity($quantity) {
$this->quantity = $quantity;
}
/**
* Getter for quantity
*/
public function getQuantity() {
return $this->quantity;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
/**
*
*/
class ItemList extends Resource {
/**
* Setter for items
* @param PayPal\Api\Item $items
*/
public function setItems($items) {
$this->items = $items;
}
/**
* Getter for items
*/
public function getItems() {
return $this->items;
}
/**
* Setter for shipping_address
* @param PayPal\Api\ShippingAddress $shipping_address
*/
public function setShipping_address($shipping_address) {
$this->shipping_address = $shipping_address;
}
/**
* Getter for shipping_address
*/
public function getShipping_address() {
return $this->shipping_address;
}
}

57
lib/PayPal/Api/Link.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Link extends Resource {
/**
* Setter for href
* @param string $href
*/
public function setHref($href) {
$this->href = $href;
}
/**
* Getter for href
*/
public function getHref() {
return $this->href;
}
/**
* Setter for rel
* @param string $rel
*/
public function setRel($rel) {
$this->rel = $rel;
}
/**
* Getter for rel
*/
public function getRel() {
return $this->rel;
}
/**
* Setter for method
* @param string $method
*/
public function setMethod($method) {
$this->method = $method;
}
/**
* Getter for method
*/
public function getMethod() {
return $this->method;
}
}

57
lib/PayPal/Api/Payee.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Payee extends Resource {
/**
* Setter for merchant_id
* @param string $merchant_id
*/
public function setMerchant_id($merchant_id) {
$this->merchant_id = $merchant_id;
}
/**
* Getter for merchant_id
*/
public function getMerchant_id() {
return $this->merchant_id;
}
/**
* Setter for email
* @param string $email
*/
public function setEmail($email) {
$this->email = $email;
}
/**
* Getter for email
*/
public function getEmail() {
return $this->email;
}
/**
* Setter for phone
* @param string $phone
*/
public function setPhone($phone) {
$this->phone = $phone;
}
/**
* Getter for phone
*/
public function getPhone() {
return $this->phone;
}
}

57
lib/PayPal/Api/Payer.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Payer extends Resource {
/**
* Setter for payment_method
* @param string $payment_method
*/
public function setPayment_method($payment_method) {
$this->payment_method = $payment_method;
}
/**
* Getter for payment_method
*/
public function getPayment_method() {
return $this->payment_method;
}
/**
* Setter for payer_info
* @param PayPal\Api\PayerInfo $payer_info
*/
public function setPayer_info($payer_info) {
$this->payer_info = $payer_info;
}
/**
* Getter for payer_info
*/
public function getPayer_info() {
return $this->payer_info;
}
/**
* Setter for funding_instruments
* @param PayPal\Api\FundingInstrument $funding_instruments
*/
public function setFunding_instruments($funding_instruments) {
$this->funding_instruments = $funding_instruments;
}
/**
* Getter for funding_instruments
*/
public function getFunding_instruments() {
return $this->funding_instruments;
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace PayPal\Api;
/**
*
*/
class PayerInfo extends Resource {
/**
* Setter for email
* @param string $email
*/
public function setEmail($email) {
$this->email = $email;
}
/**
* Getter for email
*/
public function getEmail() {
return $this->email;
}
/**
* Setter for first_name
* @param string $first_name
*/
public function setFirst_name($first_name) {
$this->first_name = $first_name;
}
/**
* Getter for first_name
*/
public function getFirst_name() {
return $this->first_name;
}
/**
* Setter for last_name
* @param string $last_name
*/
public function setLast_name($last_name) {
$this->last_name = $last_name;
}
/**
* Getter for last_name
*/
public function getLast_name() {
return $this->last_name;
}
/**
* Setter for payer_id
* @param string $payer_id
*/
public function setPayer_id($payer_id) {
$this->payer_id = $payer_id;
}
/**
* Getter for payer_id
*/
public function getPayer_id() {
return $this->payer_id;
}
/**
* Setter for shipping_address
* @param PayPal\Api\Address $shipping_address
*/
public function setShipping_address($shipping_address) {
$this->shipping_address = $shipping_address;
}
/**
* Getter for shipping_address
*/
public function getShipping_address() {
return $this->shipping_address;
}
/**
* Setter for phone
* @param string $phone
*/
public function setPhone($phone) {
$this->phone = $phone;
}
/**
* Getter for phone
*/
public function getPhone() {
return $this->phone;
}
}

244
lib/PayPal/Api/Payment.php Normal file
View File

@@ -0,0 +1,244 @@
<?php
namespace PayPal\Api;
use PayPal\Rest\IResource;
use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
*
*/
class Payment extends Resource implements IResource {
private static $credential;
public static function setCredential($credential) {
self::$credential = $credential;
}
/**
* Setter for id
* @param string $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* Getter for id
*/
public function getId() {
return $this->id;
}
/**
* Setter for create_time
* @param string $create_time
*/
public function setCreate_time($create_time) {
$this->create_time = $create_time;
}
/**
* Getter for create_time
*/
public function getCreate_time() {
return $this->create_time;
}
/**
* Setter for update_time
* @param string $update_time
*/
public function setUpdate_time($update_time) {
$this->update_time = $update_time;
}
/**
* Getter for update_time
*/
public function getUpdate_time() {
return $this->update_time;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for intent
* @param string $intent
*/
public function setIntent($intent) {
$this->intent = $intent;
}
/**
* Getter for intent
*/
public function getIntent() {
return $this->intent;
}
/**
* Setter for payer
* @param PayPal\Api\Payer $payer
*/
public function setPayer($payer) {
$this->payer = $payer;
}
/**
* Getter for payer
*/
public function getPayer() {
return $this->payer;
}
/**
* Setter for transactions
* @param PayPal\Api\Transaction $transactions
*/
public function setTransactions($transactions) {
$this->transactions = $transactions;
}
/**
* Getter for transactions
*/
public function getTransactions() {
return $this->transactions;
}
/**
* Setter for redirect_urls
* @param PayPal\Api\RedirectUrls $redirect_urls
*/
public function setRedirect_urls($redirect_urls) {
$this->redirect_urls = $redirect_urls;
}
/**
* Getter for redirect_urls
*/
public function getRedirect_urls() {
return $this->redirect_urls;
}
/**
* Setter for links
* @param PayPal\Api\Link $links
*/
public function setLinks($links) {
$this->links = $links;
}
/**
* Getter for links
*/
public function getLinks() {
return $this->links;
}
/**
* @path /v1/payments/payment
* @method GET
* @param array $params
* array containing the query strings with the
* following values as keys:
* count,
* start_id,
* start_index,
* start_time,
* end_time,
* payee_id,
* sort_by,
* sort_order,
* All other keys in the map are ignored by the SDK
*/
public static function all($params) {
$payLoad = "";
$allowedParams = array('count' => 1, 'start_id' => 1, 'start_index' => 1, 'start_time' => 1, 'end_time' => 1, 'payee_id' => 1, 'sort_by' => 1, 'sort_order' => 1, );
$apiContext = new ApiContext(self::$credential); $call = new Call();
$json = $call->execute("/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad, $apiContext);
$ret = new PaymentHistory();
$ret->fromJson($json);
return $ret;
}
/**
* @path /v1/payments/payment
* @method POST
* @param PayPal\Rest\ApiContext $apiContext optional
*/
public function create( $apiContext=null) {
$payLoad = $this->toJSON();
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
$call = new Call();
$json = $call->execute("/v1/payments/payment", "POST", $payLoad, $apiContext);
$this->fromJson($json);
return $this;
}
/**
* @path /v1/payments/payment/:payment-id
* @method GET
* @param string $paymentid
*/
public static function get( $paymentid) {
if (($paymentid == null) || (strlen($paymentid) <= 0)) {
throw new \InvalidArgumentException("paymentid cannot be null or empty");
}
$payLoad = "";
$apiContext = new ApiContext(self::$credential); $call = new Call();
$json = $call->execute("/v1/payments/payment/$paymentid", "GET", $payLoad, $apiContext);
$ret = new Payment();
$ret->fromJson($json);
return $ret;
}
/**
* @path /v1/payments/payment/:payment-id/execute
* @method POST
* @param PaymentExecution $payment_execution
* @param PayPal\Rest\ApiContext $apiContext optional
*/
public function execute( $payment_execution, $apiContext=null) {
if ($payment_execution == null) {
throw new \InvalidArgumentException("payment_execution cannot be null");
}
if ($this->getId() == null) {
throw new \InvalidArgumentException("Id cannot be null");
}
$payLoad = $payment_execution->toJSON();
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
$call = new Call();
$json = $call->execute("/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad, $apiContext);
$this->fromJson($json);
return $this;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
/**
*
*/
class PaymentExecution extends Resource {
/**
* Setter for payer_id
* @param string $payer_id
*/
public function setPayer_id($payer_id) {
$this->payer_id = $payer_id;
}
/**
* Getter for payer_id
*/
public function getPayer_id() {
return $this->payer_id;
}
/**
* Setter for transactions
* @param PayPal\Api\Amount $transactions
*/
public function setTransactions($transactions) {
$this->transactions = $transactions;
}
/**
* Getter for transactions
*/
public function getTransactions() {
return $this->transactions;
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace PayPal\Api;
/**
*
*/
class PaymentHistory extends Resource {
/**
* Setter for payments
* @param PayPal\Api\Payment $payments
*/
public function setPayments($payments) {
$this->payments = $payments;
}
/**
* Getter for payments
*/
public function getPayments() {
return $this->payments;
}
/**
* Setter for count
* @param integer $count
*/
public function setCount($count) {
$this->count = $count;
}
/**
* Getter for count
*/
public function getCount() {
return $this->count;
}
/**
* Setter for next_id
* @param string $next_id
*/
public function setNext_id($next_id) {
$this->next_id = $next_id;
}
/**
* Getter for next_id
*/
public function getNext_id() {
return $this->next_id;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace PayPal\Api;
/**
*
*/
class RedirectUrls extends Resource {
/**
* Setter for return_url
* @param string $return_url
*/
public function setReturn_url($return_url) {
$this->return_url = $return_url;
}
/**
* Getter for return_url
*/
public function getReturn_url() {
return $this->return_url;
}
/**
* Setter for cancel_url
* @param string $cancel_url
*/
public function setCancel_url($cancel_url) {
$this->cancel_url = $cancel_url;
}
/**
* Getter for cancel_url
*/
public function getCancel_url() {
return $this->cancel_url;
}
}

191
lib/PayPal/Api/Refund.php Normal file
View File

@@ -0,0 +1,191 @@
<?php
namespace PayPal\Api;
use PayPal\Rest\IResource;
use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
*
*/
class Refund extends Resource implements IResource {
private static $credential;
public static function setCredential($credential) {
self::$credential = $credential;
}
/**
* Setter for id
* @param string $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* Getter for id
*/
public function getId() {
return $this->id;
}
/**
* Setter for create_time
* @param string $create_time
*/
public function setCreate_time($create_time) {
$this->create_time = $create_time;
}
/**
* Getter for create_time
*/
public function getCreate_time() {
return $this->create_time;
}
/**
* Setter for update_time
* @param string $update_time
*/
public function setUpdate_time($update_time) {
$this->update_time = $update_time;
}
/**
* Getter for update_time
*/
public function getUpdate_time() {
return $this->update_time;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for amount
* @param PayPal\Api\Amount $amount
*/
public function setAmount($amount) {
$this->amount = $amount;
}
/**
* Getter for amount
*/
public function getAmount() {
return $this->amount;
}
/**
* Setter for sale_id
* @param string $sale_id
*/
public function setSale_id($sale_id) {
$this->sale_id = $sale_id;
}
/**
* Getter for sale_id
*/
public function getSale_id() {
return $this->sale_id;
}
/**
* Setter for capture_id
* @param string $capture_id
*/
public function setCapture_id($capture_id) {
$this->capture_id = $capture_id;
}
/**
* Getter for capture_id
*/
public function getCapture_id() {
return $this->capture_id;
}
/**
* Setter for parent_payment
* @param string $parent_payment
*/
public function setParent_payment($parent_payment) {
$this->parent_payment = $parent_payment;
}
/**
* Getter for parent_payment
*/
public function getParent_payment() {
return $this->parent_payment;
}
/**
* Setter for description
* @param string $description
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* Getter for description
*/
public function getDescription() {
return $this->description;
}
/**
* Setter for links
* @param PayPal\Api\Link $links
*/
public function setLinks($links) {
$this->links = $links;
}
/**
* Getter for links
*/
public function getLinks() {
return $this->links;
}
/**
* @path /v1/payments/refund/:refund-id
* @method GET
* @param string $refundid
*/
public static function get( $refundid) {
if (($refundid == null) || (strlen($refundid) <= 0)) {
throw new \InvalidArgumentException("refundid cannot be null or empty");
}
$payLoad = "";
$apiContext = new ApiContext(self::$credential); $call = new Call();
$json = $call->execute("/v1/payments/refund/$refundid", "GET", $payLoad, $apiContext);
$ret = new Refund();
$ret->fromJson($json);
return $ret;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace PayPal\Api;
use PayPal\Common\Model;
/**
*
*/
class Resource extends Model {
}

169
lib/PayPal/Api/Sale.php Normal file
View File

@@ -0,0 +1,169 @@
<?php
namespace PayPal\Api;
use PayPal\Rest\IResource;
use PayPal\Rest\Call;
use PayPal\Rest\ApiContext;
/**
*
*/
class Sale extends Resource implements IResource {
private static $credential;
public static function setCredential($credential) {
self::$credential = $credential;
}
/**
* Setter for id
* @param string $id
*/
public function setId($id) {
$this->id = $id;
}
/**
* Getter for id
*/
public function getId() {
return $this->id;
}
/**
* Setter for create_time
* @param string $create_time
*/
public function setCreate_time($create_time) {
$this->create_time = $create_time;
}
/**
* Getter for create_time
*/
public function getCreate_time() {
return $this->create_time;
}
/**
* Setter for update_time
* @param string $update_time
*/
public function setUpdate_time($update_time) {
$this->update_time = $update_time;
}
/**
* Getter for update_time
*/
public function getUpdate_time() {
return $this->update_time;
}
/**
* Setter for state
* @param string $state
*/
public function setState($state) {
$this->state = $state;
}
/**
* Getter for state
*/
public function getState() {
return $this->state;
}
/**
* Setter for amount
* @param PayPal\Api\Amount $amount
*/
public function setAmount($amount) {
$this->amount = $amount;
}
/**
* Getter for amount
*/
public function getAmount() {
return $this->amount;
}
/**
* Setter for parent_payment
* @param string $parent_payment
*/
public function setParent_payment($parent_payment) {
$this->parent_payment = $parent_payment;
}
/**
* Getter for parent_payment
*/
public function getParent_payment() {
return $this->parent_payment;
}
/**
* Setter for links
* @param PayPal\Api\Link $links
*/
public function setLinks($links) {
$this->links = $links;
}
/**
* Getter for links
*/
public function getLinks() {
return $this->links;
}
/**
* @path /v1/payments/sale/:sale-id
* @method GET
* @param string $saleid
*/
public static function get( $saleid) {
if (($saleid == null) || (strlen($saleid) <= 0)) {
throw new \InvalidArgumentException("saleid cannot be null or empty");
}
$payLoad = "";
$apiContext = new ApiContext(self::$credential); $call = new Call();
$json = $call->execute("/v1/payments/sale/$saleid", "GET", $payLoad, $apiContext);
$ret = new Sale();
$ret->fromJson($json);
return $ret;
}
/**
* @path /v1/payments/sale/:sale-id/refund
* @method POST
* @param Refund $refund
* @param PayPal\Rest\ApiContext $apiContext optional
*/
public function refund( $refund, $apiContext=null) {
if ($refund == null) {
throw new \InvalidArgumentException("refund cannot be null");
}
if ($this->getId() == null) {
throw new \InvalidArgumentException("Id cannot be null");
}
$payLoad = $refund->toJSON();
if($apiContext == null) {
$apiContext = new ApiContext(self::$credential);
}
$call = new Call();
$json = $call->execute("/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad, $apiContext);
$this->fromJson($json);
return $this;
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace PayPal\Api;
/**
*
*/
class ShippingAddress extends Address {
/**
* Setter for recipient_name
* @param string $recipient_name
*/
public function setRecipient_name($recipient_name) {
$this->recipient_name = $recipient_name;
}
/**
* Getter for recipient_name
*/
public function getRecipient_name() {
return $this->recipient_name;
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace PayPal\Api;
/**
*
*/
class SubTransaction extends Resource {
/**
* Setter for sale
* @param PayPal\Api\Sale $sale
*/
public function setSale($sale) {
$this->sale = $sale;
}
/**
* Getter for sale
*/
public function getSale() {
return $this->sale;
}
/**
* Setter for authorization
* @param PayPal\Api\Authorization $authorization
*/
public function setAuthorization($authorization) {
$this->authorization = $authorization;
}
/**
* Getter for authorization
*/
public function getAuthorization() {
return $this->authorization;
}
/**
* Setter for refund
* @param PayPal\Api\Refund $refund
*/
public function setRefund($refund) {
$this->refund = $refund;
}
/**
* Getter for refund
*/
public function getRefund() {
return $this->refund;
}
/**
* Setter for capture
* @param PayPal\Api\Capture $capture
*/
public function setCapture($capture) {
$this->capture = $capture;
}
/**
* Getter for capture
*/
public function getCapture() {
return $this->capture;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace PayPal\Api;
/**
*
*/
class Transaction extends Resource {
/**
* Setter for amount
* @param PayPal\Api\Amount $amount
*/
public function setAmount($amount) {
$this->amount = $amount;
}
/**
* Getter for amount
*/
public function getAmount() {
return $this->amount;
}
/**
* Setter for payee
* @param PayPal\Api\Payee $payee
*/
public function setPayee($payee) {
$this->payee = $payee;
}
/**
* Getter for payee
*/
public function getPayee() {
return $this->payee;
}
/**
* Setter for description
* @param string $description
*/
public function setDescription($description) {
$this->description = $description;
}
/**
* Getter for description
*/
public function getDescription() {
return $this->description;
}
/**
* Setter for item_list
* @param PayPal\Api\ItemList $item_list
*/
public function setItem_list($item_list) {
$this->item_list = $item_list;
}
/**
* Getter for item_list
*/
public function getItem_list() {
return $this->item_list;
}
/**
* Setter for related_resources
* @param PayPal\Api\SubTransaction $related_resources
*/
public function setRelated_resources($related_resources) {
$this->related_resources = $related_resources;
}
/**
* Getter for related_resources
*/
public function getRelated_resources() {
return $this->related_resources;
}
}

View File

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

View File

@@ -0,0 +1,19 @@
<?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

@@ -0,0 +1,88 @@
<?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

@@ -0,0 +1,73 @@
<?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

@@ -0,0 +1,44 @@
<?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

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

59
lib/PayPal/Rest/Call.php Normal file
View File

@@ -0,0 +1,59 @@
<?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,7 @@
<?php
namespace PayPal\Rest;
interface IResource {
}