diff --git a/README.md b/README.md index b6ae880..11082b0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # REST API SDK for PHP -[](https://travis-ci.org/paypal/rest-api-sdk-php) [](https://coveralls.io/r/paypal/rest-api-sdk-php?branch=master) [](https://packagist.org/packages/paypal/rest-api-sdk-php) [](https://packagist.org/packages/paypal/rest-api-sdk-php) +[](https://travis-ci.org/paypal/PayPal-PHP-SDK) [](https://coveralls.io/r/paypal/PayPal-PHP-SDK?branch=master) [](https://packagist.org/packages/paypal/rest-api-sdk-php) [](https://packagist.org/packages/paypal/rest-api-sdk-php) This repository contains PayPal's PHP SDK and samples for REST API. @@ -27,7 +27,7 @@ Currently, Paypal PHP Rest API SDK is available at [https://packagist.org](https * Running `composer require paypal/rest-api-sdk-php:*` command on your project root location (where project composer.json is located.) -* Or, manually editing composer.json file `require` field, and adding `"paypal\rest-api-sdk-php" : "*"` inside it. +* Or, manually editing composer.json file `require` field, and adding `"paypal/rest-api-sdk-php" : "*"` inside it. The resultant sample *composer.json* would look like this: @@ -49,7 +49,7 @@ The resultant sample *composer.json* would look like this: If you do not want to use composer, you can grab the SDK zip that contains Paypal PHP Rest API SDK with all its dependencies with it. #### Steps to Install : -- Download zip archive with desired version from our [Releases](https://github.com/paypal/rest-api-sdk-php/releases). Each release will have a `direct-download-*.zip` that contains PHP Rest API SDK and its dependencies. +- Download zip archive with desired version from our [Releases](https://github.com/paypal/PayPal-PHP-SDK/releases). Each release will have a `direct-download-*.zip` that contains PHP Rest API SDK and its dependencies. - Unzip and copy vendor directory inside your project, e.g. project root directory. @@ -134,7 +134,7 @@ We recently introduced a validation to determine if Model Object contains all th This validation could be configured by updating the configuration settings in your sdk_config.ini file -Please visit our [sample sdk_config.ini](https://github.com/paypal/rest-api-sdk-php/blob/master/sample/sdk_config.ini) +Please visit our [sample sdk_config.ini](https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/sdk_config.ini) ``` ;Validation Configuration [validation] @@ -149,12 +149,12 @@ validation.level=strict The warning message would be logged into your PayPal.log file, for e.g.: ``` -PayPal\Validation\ModelAccessorValidator: WARNING: Missing Accessor: PayPal\Api\Payment:setFirstName . Please let us know by creating an issue at https://github.com/paypal/rest-api-sdk-php/issues +PayPal\Validation\ModelAccessorValidator: WARNING: Missing Accessor: PayPal\Api\Payment:setFirstName . Please let us know by creating an issue at https://github.com/paypal/PayPal-PHP-SDK/issues ``` ## Contributing -* If you find solution to an [issue/improvements](https://github.com/paypal/rest-api-sdk-php/issues) in sdk that would be helpful to everyone, feel free to send us a pull request. +* If you find solution to an [issue/improvements](https://github.com/paypal/PayPal-PHP-SDK/issues) in sdk that would be helpful to everyone, feel free to send us a pull request. * The ideal approach to create a fix would be to fork the repository, create a branch in your repository, and make a pull request out of it. * It is desirable if there is enough comments/documentation and Tests included in the pull request. * For general idea of contribution, please follow the guidelines mentioned [here](https://guides.github.com/activities/contributing-to-open-source/). @@ -162,6 +162,5 @@ PayPal\Validation\ModelAccessorValidator: WARNING: Missing Accessor: PayPal\Api\ ## More help * [API Reference](https://developer.paypal.com/webapps/developer/docs/api/) - * [Reporting issues / feature requests] (https://github.com/paypal/rest-api-sdk-php/issues) + * [Reporting issues / feature requests] (https://github.com/paypal/PayPal-PHP-SDK/issues) * [Pizza App Using Paypal REST API] (https://github.com/paypal/rest-api-sample-app-php) -[](https://bitdeli.com/free "Bitdeli Badge") diff --git a/lib/PayPal/Api/Address.php b/lib/PayPal/Api/Address.php index 1e4aa77..7b93d48 100644 --- a/lib/PayPal/Api/Address.php +++ b/lib/PayPal/Api/Address.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class Address @@ -24,7 +23,6 @@ class Address extends PPModel { /** * Line 1 of the Address (eg. number, street, etc). - * * * @param string $line1 * @@ -48,7 +46,6 @@ class Address extends PPModel /** * Optional line 2 of the Address (eg. suite, apt #, etc.). - * * * @param string $line2 * @@ -72,7 +69,6 @@ class Address extends PPModel /** * City name. - * * * @param string $city * @@ -96,7 +92,6 @@ class Address extends PPModel /** * 2 letter country code. - * * * @param string $country_code * @@ -145,7 +140,6 @@ class Address extends PPModel /** * Zip code or equivalent is usually required for countries that have them. For list of countries that do not have postal codes please refer to http://en.wikipedia.org/wiki/Postal_code. - * * * @param string $postal_code * @@ -194,7 +188,6 @@ class Address extends PPModel /** * 2 letter code for US states, and the equivalent for other countries. - * * * @param string $state * @@ -218,7 +211,6 @@ class Address extends PPModel /** * Phone number in E.123 format. - * * * @param \PayPal\Api\Phone $phone * diff --git a/lib/PayPal/Api/Agreement.php b/lib/PayPal/Api/Agreement.php new file mode 100644 index 0000000..6509200 --- /dev/null +++ b/lib/PayPal/Api/Agreement.php @@ -0,0 +1,832 @@ +id = $id; + return $this; + } + + /** + * Identifier of the agreement. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * State of the agreement. + * + * @param string $state + * + * @return $this + */ + public function setState($state) + { + $this->state = $state; + return $this; + } + + /** + * State of the agreement. + * + * @return string + */ + public function getState() + { + return $this->state; + } + + /** + * Name of the agreement. + * + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * Name of the agreement. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Description of the agreement. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Description of the agreement. + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @param string $start_date + * + * @return $this + */ + public function setStartDate($start_date) + { + $this->start_date = $start_date; + return $this; + } + + /** + * Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @return string + */ + public function getStartDate() + { + return $this->start_date; + } + + /** + * Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @deprecated Instead use setStartDate + * + * @param string $start_date + * @return $this + */ + public function setStart_date($start_date) + { + $this->start_date = $start_date; + return $this; + } + + /** + * Start date of the agreement. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * @deprecated Instead use getStartDate + * + * @return string + */ + public function getStart_date() + { + return $this->start_date; + } + + /** + * Details of the buyer who is enrolling in this agreement. This information is gathered from execution of the approval URL. + * + * @param \PayPal\Api\Payer $payer + * + * @return $this + */ + public function setPayer($payer) + { + $this->payer = $payer; + return $this; + } + + /** + * Details of the buyer who is enrolling in this agreement. This information is gathered from execution of the approval URL. + * + * @return \PayPal\Api\Payer + */ + public function getPayer() + { + return $this->payer; + } + + /** + * Shipping address object of the agreement, which should be provided if it is different from the default address. + * + * @param \PayPal\Api\Address $shipping_address + * + * @return $this + */ + public function setShippingAddress($shipping_address) + { + $this->shipping_address = $shipping_address; + return $this; + } + + /** + * Shipping address object of the agreement, which should be provided if it is different from the default address. + * + * @return \PayPal\Api\Address + */ + public function getShippingAddress() + { + return $this->shipping_address; + } + + /** + * Shipping address object of the agreement, which should be provided if it is different from the default address. + * + * @deprecated Instead use setShippingAddress + * + * @param \PayPal\Api\Address $shipping_address + * @return $this + */ + public function setShipping_address($shipping_address) + { + $this->shipping_address = $shipping_address; + return $this; + } + + /** + * Shipping address object of the agreement, which should be provided if it is different from the default address. + * @deprecated Instead use getShippingAddress + * + * @return \PayPal\Api\Address + */ + public function getShipping_address() + { + return $this->shipping_address; + } + + /** + * Default merchant preferences from the billing plan are used, unless override preferences are provided here. + * + * @param \PayPal\Api\MerchantPreferences $override_merchant_preferences + * + * @return $this + */ + public function setOverrideMerchantPreferences($override_merchant_preferences) + { + $this->override_merchant_preferences = $override_merchant_preferences; + return $this; + } + + /** + * Default merchant preferences from the billing plan are used, unless override preferences are provided here. + * + * @return \PayPal\Api\MerchantPreferences + */ + public function getOverrideMerchantPreferences() + { + return $this->override_merchant_preferences; + } + + /** + * Default merchant preferences from the billing plan are used, unless override preferences are provided here. + * + * @deprecated Instead use setOverrideMerchantPreferences + * + * @param \PayPal\Api\MerchantPreferences $override_merchant_preferences + * @return $this + */ + public function setOverride_merchant_preferences($override_merchant_preferences) + { + $this->override_merchant_preferences = $override_merchant_preferences; + return $this; + } + + /** + * Default merchant preferences from the billing plan are used, unless override preferences are provided here. + * @deprecated Instead use getOverrideMerchantPreferences + * + * @return \PayPal\Api\MerchantPreferences + */ + public function getOverride_merchant_preferences() + { + return $this->override_merchant_preferences; + } + + /** + * Array of override_charge_model for this agreement if needed to change the default models from the billing plan. + * + * @param \PayPal\Api\OverrideChargeModel[] $override_charge_models + * + * @return $this + */ + public function setOverrideChargeModels($override_charge_models) + { + $this->override_charge_models = $override_charge_models; + return $this; + } + + /** + * Array of override_charge_model for this agreement if needed to change the default models from the billing plan. + * + * @return \PayPal\Api\OverrideChargeModel[] + */ + public function getOverrideChargeModels() + { + return $this->override_charge_models; + } + + /** + * Append OverrideChargeModels to the list. + * + * @param \PayPal\Api\OverrideChargeModel $overrideChargeModel + * @return $this + */ + public function addOverrideChargeModel($overrideChargeModel) + { + if (!$this->getOverrideChargeModels()) { + return $this->setOverrideChargeModels(array($overrideChargeModel)); + } else { + return $this->setOverrideChargeModels( + array_merge($this->getOverrideChargeModels(), array($overrideChargeModel)) + ); + } + } + + /** + * Remove OverrideChargeModels from the list. + * + * @param \PayPal\Api\OverrideChargeModel $overrideChargeModel + * @return $this + */ + public function removeOverrideChargeModel($overrideChargeModel) + { + return $this->setOverrideChargeModels( + array_diff($this->getOverrideChargeModels(), array($overrideChargeModel)) + ); + } + + /** + * Array of override_charge_model for this agreement if needed to change the default models from the billing plan. + * + * @deprecated Instead use setOverrideChargeModels + * + * @param \PayPal\Api\OverrideChargeModel $override_charge_models + * @return $this + */ + public function setOverride_charge_models($override_charge_models) + { + $this->override_charge_models = $override_charge_models; + return $this; + } + + /** + * Array of override_charge_model for this agreement if needed to change the default models from the billing plan. + * @deprecated Instead use getOverrideChargeModels + * + * @return \PayPal\Api\OverrideChargeModel + */ + public function getOverride_charge_models() + { + return $this->override_charge_models; + } + + /** + * Plan details for this agreement. + * + * @param \PayPal\Api\Plan $plan + * + * @return $this + */ + public function setPlan($plan) + { + $this->plan = $plan; + return $this; + } + + /** + * Plan details for this agreement. + * + * @return \PayPal\Api\Plan + */ + public function getPlan() + { + return $this->plan; + } + + /** + * Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @param string $create_time + * + * @return $this + */ + public function setCreateTime($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @return string + */ + public function getCreateTime() + { + return $this->create_time; + } + + /** + * Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @deprecated Instead use setCreateTime + * + * @param string $create_time + * @return $this + */ + public function setCreate_time($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * @deprecated Instead use getCreateTime + * + * @return string + */ + public function getCreate_time() + { + return $this->create_time; + } + + /** + * Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @param string $update_time + * + * @return $this + */ + public function setUpdateTime($update_time) + { + $this->update_time = $update_time; + return $this; + } + + /** + * Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @return string + */ + public function getUpdateTime() + { + return $this->update_time; + } + + /** + * Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @deprecated Instead use setUpdateTime + * + * @param string $update_time + * @return $this + */ + public function setUpdate_time($update_time) + { + $this->update_time = $update_time; + return $this; + } + + /** + * Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * @deprecated Instead use getUpdateTime + * + * @return string + */ + public function getUpdate_time() + { + return $this->update_time; + } + + /** + * Agreement Details + * + * @param \PayPal\Api\AgreementDetails $agreement_details + * + * @return $this + */ + public function setAgreementDetails($agreement_details) + { + $this->{"agreement-details"} = $agreement_details; + return $this; + } + + /** + * Agreement Details + * + * @return \PayPal\Api\AgreementDetails + */ + public function getAgreementDetails() + { + return $this->{"agreement-details"}; + } + + /** + * Agreement Details + * + * @deprecated Instead use setAgreementDetails + * + * @param \PayPal\Api\AgreementDetails $agreement-details + * @return $this + */ + public function setAgreement_details($agreement_details) + { + $this->{"agreement-details"} = $agreement_details; + return $this; + } + + /** + * Agreement Details + * @deprecated Instead use getAgreementDetails + * + * @return \PayPal\Api\AgreementDetails + */ + public function getAgreement_details() + { + return $this->{"agreement-details"}; + } + + /** + * Sets Links + * + * @param \PayPal\Api\Links[] $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + + /** + * Gets Links + * + * @return \PayPal\Api\Links[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + + /** + * Create a new billing agreement by passing the details for the agreement, including the name, description, start date, payer, and billing plan in the request JSON. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Agreement + */ + public function create($apiContext = null, $restCall = null) + { + $payLoad = $this->toJSON(); + $json = self::executeCall( + "/v1/payments/billing-agreements/", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Execute a billing agreement after buyer approval by passing the payment token to the request URI. + * + * @param $paymentToken + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Agreement + */ + public function execute($paymentToken, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($paymentToken, 'paymentToken'); + $payLoad = ""; + $json = self::executeCall( + "/v1/payments/billing-agreements/$paymentToken/agreement-execute", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Retrieve details for a particular billing agreement by passing the ID of the agreement to the request URI. + * + * @param string $agreementId + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Agreement + */ + public static function get($agreementId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($agreementId, 'agreementId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/payments/billing-agreements/$agreementId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new Agreement(); + $ret->fromJson($json); + return $ret; + } + + /** + * Update details of a billing agreement, such as the description, shipping address, and start date, by passing the ID of the agreement to the request URI. + * + * @param PatchRequest $patchRequest + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function update($patchRequest, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($patchRequest, 'patchRequest'); + $payLoad = $patchRequest->toJSON(); + self::executeCall( + "/v1/payments/billing-agreements/{$this->getId()}", + "PATCH", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * Suspend a particular billing agreement by passing the ID of the agreement to the request URI. + * + * @param AgreementStateDescriptor $agreementStateDescriptor + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function suspend($agreementStateDescriptor, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor'); + $payLoad = $agreementStateDescriptor->toJSON(); + self::executeCall( + "/v1/payments/billing-agreements/{$this->getId()}/suspend", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * Reactivate a suspended billing agreement by passing the ID of the agreement to the appropriate URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement. + * + * @param AgreementStateDescriptor $agreementStateDescriptor + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function reActivate($agreementStateDescriptor, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor'); + $payLoad = $agreementStateDescriptor->toJSON(); + self::executeCall( + "/v1/payments/billing-agreements/{$this->getId()}/re-activate", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * Cancel a billing agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement. + * + * @param AgreementStateDescriptor $agreementStateDescriptor + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function cancel($agreementStateDescriptor, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor'); + $payLoad = $agreementStateDescriptor->toJSON(); + self::executeCall( + "/v1/payments/billing-agreements/{$this->getId()}/cancel", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * Bill an outstanding amount for an agreement by passing the ID of the agreement to the request URI. In addition, pass an agreement_state_descriptor object in the request JSON that includes a note about the reason for changing the state of the agreement and the amount and currency for the agreement. + * + * @param AgreementStateDescriptor $agreementStateDescriptor + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function billBalance($agreementStateDescriptor, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($agreementStateDescriptor, 'agreementStateDescriptor'); + $payLoad = $agreementStateDescriptor->toJSON(); + self::executeCall( + "/v1/payments/billing-agreements/{$this->getId()}/bill-balance", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * Set the balance for an agreement by passing the ID of the agreement to the request URI. In addition, pass a common_currency object in the request JSON that specifies the currency type and value of the balance. + * + * @param Currency $currency + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function setBalance($currency, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($currency, 'currency'); + $payLoad = $currency->toJSON(); + self::executeCall( + "/v1/payments/billing-agreements/{$this->getId()}/set-balance", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * List transactions for a billing agreement by passing the ID of the agreement, as well as the start and end dates of the range of transactions to list, to the request URI. + * + * @param string $agreementId + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return AgreementTransactions + */ + public static function transactions($agreementId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($agreementId, 'agreementId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/payments/billing-agreements/$agreementId/transactions", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new AgreementTransactions(); + $ret->fromJson($json); + return $ret; + } + +} diff --git a/lib/PayPal/Api/AgreementDetails.php b/lib/PayPal/Api/AgreementDetails.php new file mode 100644 index 0000000..6bc33bc --- /dev/null +++ b/lib/PayPal/Api/AgreementDetails.php @@ -0,0 +1,409 @@ +outstanding_balance = $outstanding_balance; + return $this; + } + + /** + * The outstanding balance for this agreement. + * + * @return \PayPal\Api\Currency + */ + public function getOutstandingBalance() + { + return $this->outstanding_balance; + } + + /** + * The outstanding balance for this agreement. + * + * @deprecated Instead use setOutstandingBalance + * + * @param \PayPal\Api\Currency $outstanding_balance + * @return $this + */ + public function setOutstanding_balance($outstanding_balance) + { + $this->outstanding_balance = $outstanding_balance; + return $this; + } + + /** + * The outstanding balance for this agreement. + * @deprecated Instead use getOutstandingBalance + * + * @return \PayPal\Api\Currency + */ + public function getOutstanding_balance() + { + return $this->outstanding_balance; + } + + /** + * Number of cycles remaining for this agreement. + * + * @param string $cycles_remaining + * + * @return $this + */ + public function setCyclesRemaining($cycles_remaining) + { + $this->cycles_remaining = $cycles_remaining; + return $this; + } + + /** + * Number of cycles remaining for this agreement. + * + * @return string + */ + public function getCyclesRemaining() + { + return $this->cycles_remaining; + } + + /** + * Number of cycles remaining for this agreement. + * + * @deprecated Instead use setCyclesRemaining + * + * @param string $cycles_remaining + * @return $this + */ + public function setCycles_remaining($cycles_remaining) + { + $this->cycles_remaining = $cycles_remaining; + return $this; + } + + /** + * Number of cycles remaining for this agreement. + * @deprecated Instead use getCyclesRemaining + * + * @return string + */ + public function getCycles_remaining() + { + return $this->cycles_remaining; + } + + /** + * Number of cycles completed for this agreement. + * + * @param string $cycles_completed + * + * @return $this + */ + public function setCyclesCompleted($cycles_completed) + { + $this->cycles_completed = $cycles_completed; + return $this; + } + + /** + * Number of cycles completed for this agreement. + * + * @return string + */ + public function getCyclesCompleted() + { + return $this->cycles_completed; + } + + /** + * Number of cycles completed for this agreement. + * + * @deprecated Instead use setCyclesCompleted + * + * @param string $cycles_completed + * @return $this + */ + public function setCycles_completed($cycles_completed) + { + $this->cycles_completed = $cycles_completed; + return $this; + } + + /** + * Number of cycles completed for this agreement. + * @deprecated Instead use getCyclesCompleted + * + * @return string + */ + public function getCycles_completed() + { + return $this->cycles_completed; + } + + /** + * The next billing date for this agreement, represented as 2014-02-19T10:00:00Z format. + * + * @param string $next_billing_date + * + * @return $this + */ + public function setNextBillingDate($next_billing_date) + { + $this->next_billing_date = $next_billing_date; + return $this; + } + + /** + * The next billing date for this agreement, represented as 2014-02-19T10:00:00Z format. + * + * @return string + */ + public function getNextBillingDate() + { + return $this->next_billing_date; + } + + /** + * The next billing date for this agreement, represented as 2014-02-19T10:00:00Z format. + * + * @deprecated Instead use setNextBillingDate + * + * @param string $next_billing_date + * @return $this + */ + public function setNext_billing_date($next_billing_date) + { + $this->next_billing_date = $next_billing_date; + return $this; + } + + /** + * The next billing date for this agreement, represented as 2014-02-19T10:00:00Z format. + * @deprecated Instead use getNextBillingDate + * + * @return string + */ + public function getNext_billing_date() + { + return $this->next_billing_date; + } + + /** + * Last payment date for this agreement, represented as 2014-06-09T09:42:31Z format. + * + * @param string $last_payment_date + * + * @return $this + */ + public function setLastPaymentDate($last_payment_date) + { + $this->last_payment_date = $last_payment_date; + return $this; + } + + /** + * Last payment date for this agreement, represented as 2014-06-09T09:42:31Z format. + * + * @return string + */ + public function getLastPaymentDate() + { + return $this->last_payment_date; + } + + /** + * Last payment date for this agreement, represented as 2014-06-09T09:42:31Z format. + * + * @deprecated Instead use setLastPaymentDate + * + * @param string $last_payment_date + * @return $this + */ + public function setLast_payment_date($last_payment_date) + { + $this->last_payment_date = $last_payment_date; + return $this; + } + + /** + * Last payment date for this agreement, represented as 2014-06-09T09:42:31Z format. + * @deprecated Instead use getLastPaymentDate + * + * @return string + */ + public function getLast_payment_date() + { + return $this->last_payment_date; + } + + /** + * Last payment amount for this agreement. + * + * @param \PayPal\Api\Currency $last_payment_amount + * + * @return $this + */ + public function setLastPaymentAmount($last_payment_amount) + { + $this->last_payment_amount = $last_payment_amount; + return $this; + } + + /** + * Last payment amount for this agreement. + * + * @return \PayPal\Api\Currency + */ + public function getLastPaymentAmount() + { + return $this->last_payment_amount; + } + + /** + * Last payment amount for this agreement. + * + * @deprecated Instead use setLastPaymentAmount + * + * @param \PayPal\Api\Currency $last_payment_amount + * @return $this + */ + public function setLast_payment_amount($last_payment_amount) + { + $this->last_payment_amount = $last_payment_amount; + return $this; + } + + /** + * Last payment amount for this agreement. + * @deprecated Instead use getLastPaymentAmount + * + * @return \PayPal\Api\Currency + */ + public function getLast_payment_amount() + { + return $this->last_payment_amount; + } + + /** + * Last payment date for this agreement, represented as 2015-02-19T10:00:00Z format. + * + * @param string $final_payment_date + * + * @return $this + */ + public function setFinalPaymentDate($final_payment_date) + { + $this->final_payment_date = $final_payment_date; + return $this; + } + + /** + * Last payment date for this agreement, represented as 2015-02-19T10:00:00Z format. + * + * @return string + */ + public function getFinalPaymentDate() + { + return $this->final_payment_date; + } + + /** + * Last payment date for this agreement, represented as 2015-02-19T10:00:00Z format. + * + * @deprecated Instead use setFinalPaymentDate + * + * @param string $final_payment_date + * @return $this + */ + public function setFinal_payment_date($final_payment_date) + { + $this->final_payment_date = $final_payment_date; + return $this; + } + + /** + * Last payment date for this agreement, represented as 2015-02-19T10:00:00Z format. + * @deprecated Instead use getFinalPaymentDate + * + * @return string + */ + public function getFinal_payment_date() + { + return $this->final_payment_date; + } + + /** + * Total number of failed payments for this agreement. + * + * @param string $failed_payment_count + * + * @return $this + */ + public function setFailedPaymentCount($failed_payment_count) + { + $this->failed_payment_count = $failed_payment_count; + return $this; + } + + /** + * Total number of failed payments for this agreement. + * + * @return string + */ + public function getFailedPaymentCount() + { + return $this->failed_payment_count; + } + + /** + * Total number of failed payments for this agreement. + * + * @deprecated Instead use setFailedPaymentCount + * + * @param string $failed_payment_count + * @return $this + */ + public function setFailed_payment_count($failed_payment_count) + { + $this->failed_payment_count = $failed_payment_count; + return $this; + } + + /** + * Total number of failed payments for this agreement. + * @deprecated Instead use getFailedPaymentCount + * + * @return string + */ + public function getFailed_payment_count() + { + return $this->failed_payment_count; + } + +} diff --git a/lib/PayPal/Api/AgreementStateDescriptor.php b/lib/PayPal/Api/AgreementStateDescriptor.php new file mode 100644 index 0000000..59d853d --- /dev/null +++ b/lib/PayPal/Api/AgreementStateDescriptor.php @@ -0,0 +1,65 @@ +note = $note; + return $this; + } + + /** + * Reason for changing the state of the agreement. + * + * @return string + */ + public function getNote() + { + return $this->note; + } + + /** + * The amount and currency of the agreement. + * + * @param \PayPal\Api\Currency $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * The amount and currency of the agreement. + * + * @return \PayPal\Api\Currency + */ + public function getAmount() + { + return $this->amount; + } + +} diff --git a/lib/PayPal/Api/AgreementTransaction.php b/lib/PayPal/Api/AgreementTransaction.php new file mode 100644 index 0000000..b1688c2 --- /dev/null +++ b/lib/PayPal/Api/AgreementTransaction.php @@ -0,0 +1,457 @@ +transaction_id = $transaction_id; + return $this; + } + + /** + * Id corresponding to this transaction. + * + * @return string + */ + public function getTransactionId() + { + return $this->transaction_id; + } + + /** + * Id corresponding to this transaction. + * + * @deprecated Instead use setTransactionId + * + * @param string $transaction_id + * @return $this + */ + public function setTransaction_id($transaction_id) + { + $this->transaction_id = $transaction_id; + return $this; + } + + /** + * Id corresponding to this transaction. + * @deprecated Instead use getTransactionId + * + * @return string + */ + public function getTransaction_id() + { + return $this->transaction_id; + } + + /** + * State of the subscription at this time. + * + * @param string $status + * + * @return $this + */ + public function setStatus($status) + { + $this->status = $status; + return $this; + } + + /** + * State of the subscription at this time. + * + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * Type of transaction, usually Recurring Payment. + * + * @param string $transaction_type + * + * @return $this + */ + public function setTransactionType($transaction_type) + { + $this->transaction_type = $transaction_type; + return $this; + } + + /** + * Type of transaction, usually Recurring Payment. + * + * @return string + */ + public function getTransactionType() + { + return $this->transaction_type; + } + + /** + * Type of transaction, usually Recurring Payment. + * + * @deprecated Instead use setTransactionType + * + * @param string $transaction_type + * @return $this + */ + public function setTransaction_type($transaction_type) + { + $this->transaction_type = $transaction_type; + return $this; + } + + /** + * Type of transaction, usually Recurring Payment. + * @deprecated Instead use getTransactionType + * + * @return string + */ + public function getTransaction_type() + { + return $this->transaction_type; + } + + /** + * Amount for this transaction. + * + * @param \PayPal\Api\Currency $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * Amount for this transaction. + * + * @return \PayPal\Api\Currency + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Fee amount for this transaction. + * + * @param \PayPal\Api\Currency $fee_amount + * + * @return $this + */ + public function setFeeAmount($fee_amount) + { + $this->fee_amount = $fee_amount; + return $this; + } + + /** + * Fee amount for this transaction. + * + * @return \PayPal\Api\Currency + */ + public function getFeeAmount() + { + return $this->fee_amount; + } + + /** + * Fee amount for this transaction. + * + * @deprecated Instead use setFeeAmount + * + * @param \PayPal\Api\Currency $fee_amount + * @return $this + */ + public function setFee_amount($fee_amount) + { + $this->fee_amount = $fee_amount; + return $this; + } + + /** + * Fee amount for this transaction. + * @deprecated Instead use getFeeAmount + * + * @return \PayPal\Api\Currency + */ + public function getFee_amount() + { + return $this->fee_amount; + } + + /** + * Net amount for this transaction. + * + * @param \PayPal\Api\Currency $net_amount + * + * @return $this + */ + public function setNetAmount($net_amount) + { + $this->net_amount = $net_amount; + return $this; + } + + /** + * Net amount for this transaction. + * + * @return \PayPal\Api\Currency + */ + public function getNetAmount() + { + return $this->net_amount; + } + + /** + * Net amount for this transaction. + * + * @deprecated Instead use setNetAmount + * + * @param \PayPal\Api\Currency $net_amount + * @return $this + */ + public function setNet_amount($net_amount) + { + $this->net_amount = $net_amount; + return $this; + } + + /** + * Net amount for this transaction. + * @deprecated Instead use getNetAmount + * + * @return \PayPal\Api\Currency + */ + public function getNet_amount() + { + return $this->net_amount; + } + + /** + * Email id of payer. + * + * @param string $payer_email + * + * @return $this + */ + public function setPayerEmail($payer_email) + { + $this->payer_email = $payer_email; + return $this; + } + + /** + * Email id of payer. + * + * @return string + */ + public function getPayerEmail() + { + return $this->payer_email; + } + + /** + * Email id of payer. + * + * @deprecated Instead use setPayerEmail + * + * @param string $payer_email + * @return $this + */ + public function setPayer_email($payer_email) + { + $this->payer_email = $payer_email; + return $this; + } + + /** + * Email id of payer. + * @deprecated Instead use getPayerEmail + * + * @return string + */ + public function getPayer_email() + { + return $this->payer_email; + } + + /** + * Business name of payer. + * + * @param string $payer_name + * + * @return $this + */ + public function setPayerName($payer_name) + { + $this->payer_name = $payer_name; + return $this; + } + + /** + * Business name of payer. + * + * @return string + */ + public function getPayerName() + { + return $this->payer_name; + } + + /** + * Business name of payer. + * + * @deprecated Instead use setPayerName + * + * @param string $payer_name + * @return $this + */ + public function setPayer_name($payer_name) + { + $this->payer_name = $payer_name; + return $this; + } + + /** + * Business name of payer. + * @deprecated Instead use getPayerName + * + * @return string + */ + public function getPayer_name() + { + return $this->payer_name; + } + + /** + * Time at which this transaction happened. + * + * @param string $time_updated + * + * @return $this + */ + public function setTimeUpdated($time_updated) + { + $this->time_updated = $time_updated; + return $this; + } + + /** + * Time at which this transaction happened. + * + * @return string + */ + public function getTimeUpdated() + { + return $this->time_updated; + } + + /** + * Time at which this transaction happened. + * + * @deprecated Instead use setTimeUpdated + * + * @param string $time_updated + * @return $this + */ + public function setTime_updated($time_updated) + { + $this->time_updated = $time_updated; + return $this; + } + + /** + * Time at which this transaction happened. + * @deprecated Instead use getTimeUpdated + * + * @return string + */ + public function getTime_updated() + { + return $this->time_updated; + } + + /** + * Time zone of time_updated field. + * + * @param string $time_zone + * + * @return $this + */ + public function setTimeZone($time_zone) + { + $this->time_zone = $time_zone; + return $this; + } + + /** + * Time zone of time_updated field. + * + * @return string + */ + public function getTimeZone() + { + return $this->time_zone; + } + + /** + * Time zone of time_updated field. + * + * @deprecated Instead use setTimeZone + * + * @param string $time_zone + * @return $this + */ + public function setTime_zone($time_zone) + { + $this->time_zone = $time_zone; + return $this; + } + + /** + * Time zone of time_updated field. + * @deprecated Instead use getTimeZone + * + * @return string + */ + public function getTime_zone() + { + return $this->time_zone; + } + +} diff --git a/lib/PayPal/Api/AgreementTransactions.php b/lib/PayPal/Api/AgreementTransactions.php new file mode 100644 index 0000000..9299375 --- /dev/null +++ b/lib/PayPal/Api/AgreementTransactions.php @@ -0,0 +1,96 @@ +agreement_transaction_list = $agreement_transaction_list; + return $this; + } + + /** + * Array of agreement_transaction object. + * + * @return \PayPal\Api\AgreementTransaction[] + */ + public function getAgreementTransactionList() + { + return $this->agreement_transaction_list; + } + + /** + * Append AgreementTransactionList to the list. + * + * @param \PayPal\Api\AgreementTransaction $agreementTransaction + * @return $this + */ + public function addAgreementTransactionList($agreementTransaction) + { + if (!$this->getAgreementTransactionList()) { + return $this->setAgreementTransactionList(array($agreementTransaction)); + } else { + return $this->setAgreementTransactionList( + array_merge($this->getAgreementTransactionList(), array($agreementTransaction)) + ); + } + } + + /** + * Remove AgreementTransactionList from the list. + * + * @param \PayPal\Api\AgreementTransaction $agreementTransaction + * @return $this + */ + public function removeAgreementTransactionList($agreementTransaction) + { + return $this->setAgreementTransactionList( + array_diff($this->getAgreementTransactionList(), array($agreementTransaction)) + ); + } + + /** + * Array of agreement_transaction object. + * + * @deprecated Instead use setAgreementTransactionList + * + * @param \PayPal\Api\AgreementTransaction $agreement_transaction_list + * @return $this + */ + public function setAgreement_transaction_list($agreement_transaction_list) + { + $this->agreement_transaction_list = $agreement_transaction_list; + return $this; + } + + /** + * Array of agreement_transaction object. + * @deprecated Instead use getAgreementTransactionList + * + * @return \PayPal\Api\AgreementTransaction + */ + public function getAgreement_transaction_list() + { + return $this->agreement_transaction_list; + } + +} diff --git a/lib/PayPal/Api/BankAccount.php b/lib/PayPal/Api/BankAccount.php index 385d78f..fb87bc5 100644 --- a/lib/PayPal/Api/BankAccount.php +++ b/lib/PayPal/Api/BankAccount.php @@ -2,11 +2,10 @@ namespace PayPal\Api; -use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; -use PayPal\Rest\IResource; -use PayPal\Transport\PPRestCall; +use PayPal\Common\ResourceModel; use PayPal\Validation\ArgumentValidator; +use PayPal\Rest\ApiContext; +use PayPal\Transport\PPRestCall; /** * Class BankAccount @@ -38,31 +37,12 @@ use PayPal\Validation\ArgumentValidator; * @property string create_time * @property string update_time * @property string valid_until - * @property \PayPal\Api\Links links + * @property \PayPal\Api\Links[] links */ -class BankAccount extends PPModel implements IResource +class BankAccount extends ResourceModel { - /** - * OAuth Credentials to use for this call - * - * @var \PayPal\Auth\OAuthTokenCredential $credential - */ - protected static $credential; - - /** - * Sets Credential - * - * @deprecated Pass ApiContext to create/get methods instead - * @param \PayPal\Auth\OAuthTokenCredential $credential - */ - public static function setCredential($credential) - { - self::$credential = $credential; - } - /** * ID of the bank account being saved for later use. - * * * @param string $id * @@ -86,7 +66,6 @@ class BankAccount extends PPModel implements IResource /** * Account number in either IBAN (max length 34) or BBAN (max length 17) format. - * * * @param string $account_number * @@ -135,7 +114,7 @@ class BankAccount extends PPModel implements IResource /** * Type of the bank account number (International or Basic Bank Account Number). For more information refer to http://en.wikipedia.org/wiki/International_Bank_Account_Number. - * Valid Values: ["BBAN", "IBAN"] + * Valid Values: ["BBAN", "IBAN"] * * @param string $account_number_type * @@ -184,7 +163,6 @@ class BankAccount extends PPModel implements IResource /** * Routing transit number (aka Bank Code) of the bank (typically for domestic use only - for international use, IBAN includes bank code). For more information refer to http://en.wikipedia.org/wiki/Bank_code. - * * * @param string $routing_number * @@ -233,7 +211,7 @@ class BankAccount extends PPModel implements IResource /** * Type of the bank account. - * Valid Values: ["CHECKING", "SAVINGS"] + * Valid Values: ["CHECKING", "SAVINGS"] * * @param string $account_type * @@ -282,7 +260,6 @@ class BankAccount extends PPModel implements IResource /** * A customer designated name. - * * * @param string $account_name * @@ -331,7 +308,7 @@ class BankAccount extends PPModel implements IResource /** * Type of the check when this information was obtained through a check by the facilitator or merchant. - * Valid Values: ["PERSONAL", "COMPANY"] + * Valid Values: ["PERSONAL", "COMPANY"] * * @param string $check_type * @@ -380,7 +357,7 @@ class BankAccount extends PPModel implements IResource /** * How the check was obtained from the customer, if check was the source of the information provided. - * Valid Values: ["CCD", "PPD", "TEL", "POP", "ARC", "RCK", "WEB"] + * Valid Values: ["CCD", "PPD", "TEL", "POP", "ARC", "RCK", "WEB"] * * @param string $auth_type * @@ -429,7 +406,6 @@ class BankAccount extends PPModel implements IResource /** * Time at which the authorization (or check) was captured. Use this field if the user authorization needs to be captured due to any privacy requirements. - * * * @param string $auth_capture_timestamp * @@ -478,7 +454,6 @@ class BankAccount extends PPModel implements IResource /** * Name of the bank. - * * * @param string $bank_name * @@ -527,7 +502,6 @@ class BankAccount extends PPModel implements IResource /** * 2 letter country code of the Bank. - * * * @param string $country_code * @@ -576,7 +550,6 @@ class BankAccount extends PPModel implements IResource /** * Account holder's first name. - * * * @param string $first_name * @@ -625,7 +598,6 @@ class BankAccount extends PPModel implements IResource /** * Account holder's last name. - * * * @param string $last_name * @@ -674,7 +646,6 @@ class BankAccount extends PPModel implements IResource /** * Birth date of the bank account holder. - * * * @param string $birth_date * @@ -723,7 +694,6 @@ class BankAccount extends PPModel implements IResource /** * Billing address. - * * * @param \PayPal\Api\Address $billing_address * @@ -772,7 +742,7 @@ class BankAccount extends PPModel implements IResource /** * State of this funding instrument. - * Valid Values: ["ACTIVE", "INACTIVE", "DELETED"] + * Valid Values: ["ACTIVE", "INACTIVE", "DELETED"] * * @param string $state * @@ -796,7 +766,7 @@ class BankAccount extends PPModel implements IResource /** * Confirmation status of a bank account. - * Valid Values: ["UNCONFIRMED", "CONFIRMED"] + * Valid Values: ["UNCONFIRMED", "CONFIRMED"] * * @param string $confirmation_status * @@ -845,7 +815,6 @@ class BankAccount extends PPModel implements IResource /** * Deprecated - Use external_customer_id instead. - * * * @param string $payer_id * @@ -894,7 +863,6 @@ class BankAccount extends PPModel implements IResource /** * A unique identifier of the customer to whom this bank account belongs to. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. - * * * @param string $external_customer_id * @@ -943,7 +911,6 @@ class BankAccount extends PPModel implements IResource /** * A unique identifier of the merchant for which this bank account has been stored for. Generated and provided by the facilitator so it can be used to restrict the usage of the bank account to the specific merchnt. - * * * @param string $merchant_id * @@ -992,7 +959,6 @@ class BankAccount extends PPModel implements IResource /** * Time the resource was created. - * * * @param string $create_time * @@ -1041,7 +1007,6 @@ class BankAccount extends PPModel implements IResource /** * Time the resource was last updated. - * * * @param string $update_time * @@ -1090,7 +1055,6 @@ class BankAccount extends PPModel implements IResource /** * Date/Time until this resource can be used to fund a payment. - * * * @param string $valid_until * @@ -1139,9 +1103,8 @@ class BankAccount extends PPModel implements IResource /** * Sets Links - * * - * @param \PayPal\Api\Links $links + * @param \PayPal\Api\Links[] $links * * @return $this */ @@ -1161,21 +1124,54 @@ class BankAccount extends PPModel implements IResource return $this->links; } + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + /** * Creates a new Bank Account Resource. * - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return BankAccount */ - public function create($apiContext = null) + public function create($apiContext = null, $restCall = null) { - $payLoad = $this->toJSON(); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/bank-accounts", "POST", $payLoad); + $json = self::executeCall( + "/v1/vault/bank-accounts", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); $this->fromJson($json); return $this; } @@ -1184,19 +1180,22 @@ class BankAccount extends PPModel implements IResource * Obtain the Bank Account resource for the given identifier. * * @param string $bankAccountId - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return BankAccount */ - public static function get($bankAccountId, $apiContext = null) + public static function get($bankAccountId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($bankAccountId, 'bankAccountId'); - $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/bank-accounts/$bankAccountId", "GET", $payLoad); + $json = self::executeCall( + "/v1/vault/bank-accounts/$bankAccountId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); $ret = new BankAccount(); $ret->fromJson($json); return $ret; @@ -1205,38 +1204,46 @@ class BankAccount extends PPModel implements IResource /** * Delete the bank account resource for the given identifier. * - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return bool */ - public function delete($apiContext = null) + public function delete($apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); - $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/bank-accounts/{$this->getId()}", "DELETE", $payLoad); + self::executeCall( + "/v1/vault/bank-accounts/{$this->getId()}", + "DELETE", + $payLoad, + null, + $apiContext, + $restCall + ); return true; } /** * Update information in a previously saved bank account. Only the modified fields need to be passed in the request. * - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PatchRequest $patchRequest + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return BankAccount */ - public function update($apiContext = null) + public function update($patchRequest, $apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); - - $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/bank-accounts/{$this->getId()}", "PATCH", $payLoad); + ArgumentValidator::validate($patchRequest, 'patchRequest'); + $payLoad = $patchRequest->toJSON(); + $json = self::executeCall( + "/v1/vault/bank-accounts/{$this->getId()}", + "PATCH", + $payLoad, + null, + $apiContext, + $restCall + ); $this->fromJson($json); return $this; } diff --git a/lib/PayPal/Api/BankAccountsList.php b/lib/PayPal/Api/BankAccountsList.php index f6ab98f..540a1f1 100644 --- a/lib/PayPal/Api/BankAccountsList.php +++ b/lib/PayPal/Api/BankAccountsList.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class BankAccountsList @@ -12,7 +11,7 @@ use PayPal\Rest\ApiContext; * * @package PayPal\Api * - * @property \PayPal\Api\BankAccount bank_accounts + * @property \PayPal\Api\BankAccount[] bank_accounts * @property int count * @property string next_id */ @@ -20,9 +19,8 @@ class BankAccountsList extends PPModel { /** * A list of bank account resources - * * - * @param \PayPal\Api\BankAccount $bank_accounts + * @param \PayPal\Api\BankAccount[] $bank_accounts * * @return $this */ @@ -42,6 +40,36 @@ class BankAccountsList extends PPModel return $this->{"bank-accounts"}; } + /** + * Append BankAccounts to the list. + * + * @param \PayPal\Api\BankAccount $bankAccount + * @return $this + */ + public function addBankAccount($bankAccount) + { + if (!$this->getBankAccounts()) { + return $this->setBankAccounts(array($bankAccount)); + } else { + return $this->setBankAccounts( + array_merge($this->getBankAccounts(), array($bankAccount)) + ); + } + } + + /** + * Remove BankAccounts from the list. + * + * @param \PayPal\Api\BankAccount $bankAccount + * @return $this + */ + public function removeBankAccount($bankAccount) + { + return $this->setBankAccounts( + array_diff($this->getBankAccounts(), array($bankAccount)) + ); + } + /** * A list of bank account resources * @@ -69,7 +97,6 @@ class BankAccountsList extends PPModel /** * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. - * * * @param int $count * @@ -93,7 +120,6 @@ class BankAccountsList extends PPModel /** * Identifier of the next element to get the next range of results. - * * * @param string $next_id * diff --git a/lib/PayPal/Api/BankToken.php b/lib/PayPal/Api/BankToken.php index b32788f..93d8dac 100644 --- a/lib/PayPal/Api/BankToken.php +++ b/lib/PayPal/Api/BankToken.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class BankToken @@ -20,7 +19,6 @@ class BankToken extends PPModel { /** * ID of a previously saved Bank resource using /vault/bank API. - * * * @param string $bank_id * @@ -69,7 +67,6 @@ class BankToken extends PPModel /** * The unique identifier of the payer used when saving this bank using /vault/bank API. - * * * @param string $external_customer_id * @@ -118,7 +115,6 @@ class BankToken extends PPModel /** * Identifier of the direct debit mandate to validate. Currently supported only for EU bank accounts(SEPA). - * * * @param string $mandate_reference_number * diff --git a/lib/PayPal/Api/ChargeModel.php b/lib/PayPal/Api/ChargeModel.php new file mode 100644 index 0000000..2a929f3 --- /dev/null +++ b/lib/PayPal/Api/ChargeModel.php @@ -0,0 +1,89 @@ +id = $id; + return $this; + } + + /** + * Identifier of the charge model. 128 characters max. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Type of charge model. Allowed values: `SHIPPING`, `TAX`. + * + * @param string $type + * + * @return $this + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Type of charge model. Allowed values: `SHIPPING`, `TAX`. + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Specific amount for this charge model. + * + * @param \PayPal\Api\Currency $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * Specific amount for this charge model. + * + * @return \PayPal\Api\Currency + */ + public function getAmount() + { + return $this->amount; + } + +} diff --git a/lib/PayPal/Api/Credit.php b/lib/PayPal/Api/Credit.php index 70acd83..857233e 100644 --- a/lib/PayPal/Api/Credit.php +++ b/lib/PayPal/Api/Credit.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class Credit @@ -20,7 +19,6 @@ class Credit extends PPModel { /** * Unique identifier of credit resource. - * * * @param string $id * @@ -43,8 +41,8 @@ class Credit extends PPModel } /** - * specifies type of credit - * Valid Values: ["BILL_ME_LATER", "PAYPAL_EXTRAS_MASTERCARD", "EBAY_MASTERCARD", "PAYPAL_SMART_CONNECT"] + * Specifies the type of credit. + * Valid Values: ["BILL_ME_LATER", "PAYPAL_EXTRAS_MASTERCARD", "EBAY_MASTERCARD", "PAYPAL_SMART_CONNECT"] * * @param string $type * @@ -57,7 +55,7 @@ class Credit extends PPModel } /** - * specifies type of credit + * Specifies the type of credit. * * @return string */ @@ -67,8 +65,7 @@ class Credit extends PPModel } /** - * URI to the associated terms - * + * URI to the associated terms. * * @param string $terms * @@ -81,7 +78,7 @@ class Credit extends PPModel } /** - * URI to the associated terms + * URI to the associated terms. * * @return string */ diff --git a/lib/PayPal/Api/CreditCard.php b/lib/PayPal/Api/CreditCard.php index 3cdd79c..0552c1a 100644 --- a/lib/PayPal/Api/CreditCard.php +++ b/lib/PayPal/Api/CreditCard.php @@ -2,11 +2,10 @@ namespace PayPal\Api; -use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; -use PayPal\Rest\IResource; -use PayPal\Transport\PPRestCall; +use PayPal\Common\ResourceModel; use PayPal\Validation\ArgumentValidator; +use PayPal\Rest\ApiContext; +use PayPal\Transport\PPRestCall; /** * Class CreditCard @@ -29,31 +28,12 @@ use PayPal\Validation\ArgumentValidator; * @property string valid_until * @property string create_time * @property string update_time - * @property \PayPal\Api\Links links + * @property \PayPal\Api\Links[] links */ -class CreditCard extends PPModel implements IResource +class CreditCard extends ResourceModel { - /** - * OAuth Credentials to use for this call - * - * @var \PayPal\Auth\OAuthTokenCredential $credential - */ - protected static $credential; - - /** - * Sets Credential - * - * @deprecated Pass ApiContext to create/get methods instead - * @param \PayPal\Auth\OAuthTokenCredential $credential - */ - public static function setCredential($credential) - { - self::$credential = $credential; - } - /** * ID of the credit card being saved for later use. - * * * @param string $id * @@ -77,7 +57,6 @@ class CreditCard extends PPModel implements IResource /** * Card number. - * * * @param string $number * @@ -101,7 +80,6 @@ class CreditCard extends PPModel implements IResource /** * Type of the Card (eg. Visa, Mastercard, etc.). - * * * @param string $type * @@ -125,7 +103,6 @@ class CreditCard extends PPModel implements IResource /** * 2 digit card expiry month. - * * * @param int $expire_month * @@ -174,7 +151,6 @@ class CreditCard extends PPModel implements IResource /** * 4 digit card expiry year - * * * @param int $expire_year * @@ -223,7 +199,6 @@ class CreditCard extends PPModel implements IResource /** * Card validation code. Only supported when making a Payment but not when saving a credit card for future use. - * * * @param int $cvv2 * @@ -247,7 +222,6 @@ class CreditCard extends PPModel implements IResource /** * Card holder's first name. - * * * @param string $first_name * @@ -296,7 +270,6 @@ class CreditCard extends PPModel implements IResource /** * Card holder's last name. - * * * @param string $last_name * @@ -345,7 +318,6 @@ class CreditCard extends PPModel implements IResource /** * Billing Address associated with this card. - * * * @param \PayPal\Api\Address $billing_address * @@ -394,7 +366,6 @@ class CreditCard extends PPModel implements IResource /** * A unique identifier of the customer to whom this bank account belongs to. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. - * * * @param string $external_customer_id * @@ -443,7 +414,7 @@ class CreditCard extends PPModel implements IResource /** * State of the funding instrument. - * Valid Values: ["expired", "ok"] + * Valid Values: ["expired", "ok"] * * @param string $state * @@ -467,7 +438,6 @@ class CreditCard extends PPModel implements IResource /** * Date/Time until this resource can be used fund a payment. - * * * @param string $valid_until * @@ -516,7 +486,6 @@ class CreditCard extends PPModel implements IResource /** * Time the resource was created in UTC ISO8601 format. - * * * @param string $create_time * @@ -564,8 +533,7 @@ class CreditCard extends PPModel implements IResource } /** - * Time the resource was last updated in UTC ISO8601 format. - * + * Time the resource was created in UTC ISO8601 format. * * @param string $update_time * @@ -578,7 +546,7 @@ class CreditCard extends PPModel implements IResource } /** - * Time the resource was last updated in UTC ISO8601 format. + * Time the resource was created in UTC ISO8601 format. * * @return string */ @@ -588,7 +556,7 @@ class CreditCard extends PPModel implements IResource } /** - * Time the resource was last updated in UTC ISO8601 format. + * Time the resource was created in UTC ISO8601 format. * * @deprecated Instead use setUpdateTime * @@ -602,7 +570,7 @@ class CreditCard extends PPModel implements IResource } /** - * Time the resource was last updated in UTC ISO8601 format. + * Time the resource was created in UTC ISO8601 format. * @deprecated Instead use getUpdateTime * * @return string @@ -614,9 +582,8 @@ class CreditCard extends PPModel implements IResource /** * Sets Links - * * - * @param \PayPal\Api\Links $links + * @param \PayPal\Api\Links[] $links * * @return $this */ @@ -636,21 +603,54 @@ class CreditCard extends PPModel implements IResource return $this->links; } + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + /** * Creates a new Credit Card Resource (aka Tokenize). * - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return CreditCard */ - public function create($apiContext = null) + public function create($apiContext = null, $restCall = null) { - $payLoad = $this->toJSON(); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/credit-card", "POST", $payLoad); + $json = self::executeCall( + "/v1/vault/credit-card", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); $this->fromJson($json); return $this; } @@ -659,19 +659,22 @@ class CreditCard extends PPModel implements IResource * Obtain the Credit Card resource for the given identifier. * * @param string $creditCardId - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return CreditCard */ - public static function get($creditCardId, $apiContext = null) + public static function get($creditCardId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($creditCardId, 'creditCardId'); - $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/credit-card/$creditCardId", "GET", $payLoad); + $json = self::executeCall( + "/v1/vault/credit-card/$creditCardId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); $ret = new CreditCard(); $ret->fromJson($json); return $ret; @@ -680,38 +683,44 @@ class CreditCard extends PPModel implements IResource /** * Delete the Credit Card resource for the given identifier. * - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return bool */ - public function delete($apiContext = null) + public function delete($apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); - $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/credit-card/{$this->getId()}", "DELETE", $payLoad); + self::executeCall( + "/v1/vault/credit-card/{$this->getId()}", + "DELETE", + $payLoad, + null, + $apiContext, + $restCall + ); return true; } /** * Update information in a previously saved card. Only the modified fields need to be passed in the request. * - * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return CreditCard */ - public function update($apiContext = null) + public function update($apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); - $payLoad = $this->toJSON(); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/vault/credit-card/{$this->getId()}", "PATCH", $payLoad); + $json = self::executeCall( + "/v1/vault/credit-card/{$this->getId()}", + "PATCH", + $payLoad, + null, + $apiContext, + $restCall + ); $this->fromJson($json); return $this; } diff --git a/lib/PayPal/Api/CreditCardList.php b/lib/PayPal/Api/CreditCardList.php index d5f2f97..26cd7db 100644 --- a/lib/PayPal/Api/CreditCardList.php +++ b/lib/PayPal/Api/CreditCardList.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class CreditCardList @@ -12,7 +11,7 @@ use PayPal\Rest\ApiContext; * * @package PayPal\Api * - * @property \PayPal\Api\CreditCard credit_cards + * @property \PayPal\Api\CreditCard[] credit_cards * @property int count * @property string next_id */ @@ -20,9 +19,8 @@ class CreditCardList extends PPModel { /** * A list of credit card resources - * * - * @param \PayPal\Api\CreditCard $credit_cards + * @param \PayPal\Api\CreditCard[] $credit_cards * * @return $this */ @@ -42,6 +40,36 @@ class CreditCardList extends PPModel return $this->{"credit-cards"}; } + /** + * Append CreditCards to the list. + * + * @param \PayPal\Api\CreditCard $creditCard + * @return $this + */ + public function addCreditCard($creditCard) + { + if (!$this->getCreditCards()) { + return $this->setCreditCards(array($creditCard)); + } else { + return $this->setCreditCards( + array_merge($this->getCreditCards(), array($creditCard)) + ); + } + } + + /** + * Remove CreditCards from the list. + * + * @param \PayPal\Api\CreditCard $creditCard + * @return $this + */ + public function removeCreditCard($creditCard) + { + return $this->setCreditCards( + array_diff($this->getCreditCards(), array($creditCard)) + ); + } + /** * A list of credit card resources * @@ -69,7 +97,6 @@ class CreditCardList extends PPModel /** * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. - * * * @param int $count * @@ -93,7 +120,6 @@ class CreditCardList extends PPModel /** * Identifier of the next element to get the next range of results. - * * * @param string $next_id * diff --git a/lib/PayPal/Api/CreditCardToken.php b/lib/PayPal/Api/CreditCardToken.php index 5bd36b5..1ee5829 100644 --- a/lib/PayPal/Api/CreditCardToken.php +++ b/lib/PayPal/Api/CreditCardToken.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class CreditCardToken @@ -23,7 +22,6 @@ class CreditCardToken extends PPModel { /** * ID of a previously saved Credit Card resource using /vault/credit-card API. - * * * @param string $credit_card_id * @@ -72,7 +70,6 @@ class CreditCardToken extends PPModel /** * The unique identifier of the payer used when saving this credit card using /vault/credit-card API. - * * * @param string $payer_id * @@ -121,7 +118,6 @@ class CreditCardToken extends PPModel /** * Last 4 digits of the card number from the saved card. - * * * @param string $last4 * @@ -145,7 +141,6 @@ class CreditCardToken extends PPModel /** * Type of the Card (eg. visa, mastercard, etc.) from the saved card. Please note that the values are always in lowercase and not meant to be used directly for display. - * * * @param string $type * @@ -168,8 +163,7 @@ class CreditCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 - * + * Expiry month from the saved card, represented as 1 - 12. * * @param int $expire_month * @@ -182,7 +176,7 @@ class CreditCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 + * Expiry month from the saved card, represented as 1 - 12. * * @return int */ @@ -192,7 +186,7 @@ class CreditCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 + * Expiry month from the saved card, represented as 1 - 12. * * @deprecated Instead use setExpireMonth * @@ -206,7 +200,7 @@ class CreditCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 + * Expiry month from the saved card, represented as 1 - 12. * @deprecated Instead use getExpireMonth * * @return int @@ -217,8 +211,7 @@ class CreditCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card - * + * Expiry year from the saved card, represented as YYYY format. * * @param int $expire_year * @@ -231,7 +224,7 @@ class CreditCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card + * Expiry year from the saved card, represented as YYYY format. * * @return int */ @@ -241,7 +234,7 @@ class CreditCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card + * Expiry year from the saved card, represented as YYYY format. * * @deprecated Instead use setExpireYear * @@ -255,7 +248,7 @@ class CreditCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card + * Expiry year from the saved card, represented as YYYY format. * @deprecated Instead use getExpireYear * * @return int diff --git a/lib/PayPal/Api/Currency.php b/lib/PayPal/Api/Currency.php index d6884cc..3e4c982 100644 --- a/lib/PayPal/Api/Currency.php +++ b/lib/PayPal/Api/Currency.php @@ -1,15 +1,27 @@ currency; } - /** - * amount upto 2 decimals represented as string + * amount up to N digit after the decimals separator as defined in ISO 4217 for the appropriate currency code. * * @param string $value + * + * @return $this */ public function setValue($value) { @@ -40,7 +53,7 @@ class Currency extends PPModel } /** - * amount upto 2 decimals represented as string + * amount up to N digit after the decimals separator as defined in ISO 4217 for the appropriate currency code. * * @return string */ @@ -49,5 +62,4 @@ class Currency extends PPModel return $this->value; } - } diff --git a/lib/PayPal/Api/ExtendedBankAccount.php b/lib/PayPal/Api/ExtendedBankAccount.php index 999c0f2..11e5297 100644 --- a/lib/PayPal/Api/ExtendedBankAccount.php +++ b/lib/PayPal/Api/ExtendedBankAccount.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class ExtendedBankAccount @@ -18,7 +17,6 @@ class ExtendedBankAccount extends BankAccount { /** * Identifier of the direct debit mandate to validate. Currently supported only for EU bank accounts(SEPA). - * * * @param string $mandate_reference_number * diff --git a/lib/PayPal/Api/FundingInstrument.php b/lib/PayPal/Api/FundingInstrument.php index cd7d558..d2aa844 100644 --- a/lib/PayPal/Api/FundingInstrument.php +++ b/lib/PayPal/Api/FundingInstrument.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class FundingInstrument @@ -24,7 +23,6 @@ class FundingInstrument extends PPModel { /** * Credit Card information. - * * * @param \PayPal\Api\CreditCard $credit_card * @@ -73,7 +71,6 @@ class FundingInstrument extends PPModel /** * Credit Card information. - * * * @param \PayPal\Api\CreditCardToken $credit_card_token * @@ -122,7 +119,6 @@ class FundingInstrument extends PPModel /** * Payment Card information. - * * * @param \PayPal\Api\PaymentCard $payment_card * @@ -171,7 +167,6 @@ class FundingInstrument extends PPModel /** * Payment card token information. - * * * @param \PayPal\Api\PaymentCardToken $payment_card_token * @@ -220,7 +215,6 @@ class FundingInstrument extends PPModel /** * Bank Account information. - * * * @param \PayPal\Api\ExtendedBankAccount $bank_account * @@ -269,7 +263,6 @@ class FundingInstrument extends PPModel /** * Bank Account information. - * * * @param \PayPal\Api\BankToken $bank_account_token * @@ -318,7 +311,6 @@ class FundingInstrument extends PPModel /** * Credit funding information. - * * * @param \PayPal\Api\Credit $credit * diff --git a/lib/PayPal/Api/HyperSchema.php b/lib/PayPal/Api/HyperSchema.php index 014e89b..9c2d6f2 100644 --- a/lib/PayPal/Api/HyperSchema.php +++ b/lib/PayPal/Api/HyperSchema.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class HyperSchema @@ -12,7 +11,7 @@ use PayPal\Rest\ApiContext; * * @package PayPal\Api * - * @property \PayPal\Api\Links links + * @property \PayPal\Api\Links[] links * @property string fragmentResolution * @property bool readonly * @property string contentEncoding @@ -23,9 +22,8 @@ class HyperSchema extends PPModel { /** * Sets Links - * * - * @param \PayPal\Api\Links $links + * @param \PayPal\Api\Links[] $links * * @return $this */ @@ -45,9 +43,38 @@ class HyperSchema extends PPModel return $this->links; } + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + /** * Sets FragmentResolution - * * * @param string $fragmentResolution * @@ -71,7 +98,6 @@ class HyperSchema extends PPModel /** * Sets Readonly - * * * @param bool $readonly * @@ -95,7 +121,6 @@ class HyperSchema extends PPModel /** * Sets ContentEncoding - * * * @param string $contentEncoding * @@ -119,7 +144,6 @@ class HyperSchema extends PPModel /** * Sets PathStart - * * * @param string $pathStart * @@ -143,7 +167,6 @@ class HyperSchema extends PPModel /** * Sets MediaType - * * * @param string $mediaType * diff --git a/lib/PayPal/Api/Links.php b/lib/PayPal/Api/Links.php index 671112c..64c3841 100644 --- a/lib/PayPal/Api/Links.php +++ b/lib/PayPal/Api/Links.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class Links @@ -23,7 +22,6 @@ class Links extends PPModel { /** * Sets Href - * * * @param string $href * @@ -47,7 +45,6 @@ class Links extends PPModel /** * Sets Rel - * * * @param string $rel * @@ -71,7 +68,6 @@ class Links extends PPModel /** * Sets TargetSchema - * * * @param \PayPal\Api\HyperSchema $targetSchema * @@ -95,7 +91,6 @@ class Links extends PPModel /** * Sets Method - * * * @param string $method * @@ -119,7 +114,6 @@ class Links extends PPModel /** * Sets Enctype - * * * @param string $enctype * @@ -143,7 +137,6 @@ class Links extends PPModel /** * Sets Schema - * * * @param \PayPal\Api\HyperSchema $schema * diff --git a/lib/PayPal/Api/MerchantPreferences.php b/lib/PayPal/Api/MerchantPreferences.php new file mode 100644 index 0000000..404eee0 --- /dev/null +++ b/lib/PayPal/Api/MerchantPreferences.php @@ -0,0 +1,486 @@ +id = $id; + return $this; + } + + /** + * Identifier of the merchant_preferences. 128 characters max. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Setup fee amount. Default is 0. + * + * @param \PayPal\Api\Currency $setup_fee + * + * @return $this + */ + public function setSetupFee($setup_fee) + { + $this->setup_fee = $setup_fee; + return $this; + } + + /** + * Setup fee amount. Default is 0. + * + * @return \PayPal\Api\Currency + */ + public function getSetupFee() + { + return $this->setup_fee; + } + + /** + * Setup fee amount. Default is 0. + * + * @deprecated Instead use setSetupFee + * + * @param \PayPal\Api\Currency $setup_fee + * @return $this + */ + public function setSetup_fee($setup_fee) + { + $this->setup_fee = $setup_fee; + return $this; + } + + /** + * Setup fee amount. Default is 0. + * @deprecated Instead use getSetupFee + * + * @return \PayPal\Api\Currency + */ + public function getSetup_fee() + { + return $this->setup_fee; + } + + /** + * Redirect URL on cancellation of agreement request. 1000 characters max. + * + * @param string $cancel_url + * @throws \InvalidArgumentException + * @return $this + */ + public function setCancelUrl($cancel_url) + { + UrlValidator::validate($cancel_url, "CancelUrl"); + $this->cancel_url = $cancel_url; + return $this; + } + + /** + * Redirect URL on cancellation of agreement request. 1000 characters max. + * + * @return string + */ + public function getCancelUrl() + { + return $this->cancel_url; + } + + /** + * Redirect URL on cancellation of agreement request. 1000 characters max. + * + * @deprecated Instead use setCancelUrl + * + * @param string $cancel_url + * @return $this + */ + public function setCancel_url($cancel_url) + { + $this->cancel_url = $cancel_url; + return $this; + } + + /** + * Redirect URL on cancellation of agreement request. 1000 characters max. + * @deprecated Instead use getCancelUrl + * + * @return string + */ + public function getCancel_url() + { + return $this->cancel_url; + } + + /** + * Redirect URL on creation of agreement request. 1000 characters max. + * + * @param string $return_url + * @throws \InvalidArgumentException + * @return $this + */ + public function setReturnUrl($return_url) + { + UrlValidator::validate($return_url, "ReturnUrl"); + $this->return_url = $return_url; + return $this; + } + + /** + * Redirect URL on creation of agreement request. 1000 characters max. + * + * @return string + */ + public function getReturnUrl() + { + return $this->return_url; + } + + /** + * Redirect URL on creation of agreement request. 1000 characters max. + * + * @deprecated Instead use setReturnUrl + * + * @param string $return_url + * @return $this + */ + public function setReturn_url($return_url) + { + $this->return_url = $return_url; + return $this; + } + + /** + * Redirect URL on creation of agreement request. 1000 characters max. + * @deprecated Instead use getReturnUrl + * + * @return string + */ + public function getReturn_url() + { + return $this->return_url; + } + + /** + * Notify URL on agreement creation. 1000 characters max. + * + * @param string $notify_url + * @throws \InvalidArgumentException + * @return $this + */ + public function setNotifyUrl($notify_url) + { + UrlValidator::validate($notify_url, "NotifyUrl"); + $this->notify_url = $notify_url; + return $this; + } + + /** + * Notify URL on agreement creation. 1000 characters max. + * + * @return string + */ + public function getNotifyUrl() + { + return $this->notify_url; + } + + /** + * Notify URL on agreement creation. 1000 characters max. + * + * @deprecated Instead use setNotifyUrl + * + * @param string $notify_url + * @return $this + */ + public function setNotify_url($notify_url) + { + $this->notify_url = $notify_url; + return $this; + } + + /** + * Notify URL on agreement creation. 1000 characters max. + * @deprecated Instead use getNotifyUrl + * + * @return string + */ + public function getNotify_url() + { + return $this->notify_url; + } + + /** + * Total number of failed attempts allowed. Default is 0, representing an infinite number of failed attempts. + * + * @param string $max_fail_attempts + * + * @return $this + */ + public function setMaxFailAttempts($max_fail_attempts) + { + $this->max_fail_attempts = $max_fail_attempts; + return $this; + } + + /** + * Total number of failed attempts allowed. Default is 0, representing an infinite number of failed attempts. + * + * @return string + */ + public function getMaxFailAttempts() + { + return $this->max_fail_attempts; + } + + /** + * Total number of failed attempts allowed. Default is 0, representing an infinite number of failed attempts. + * + * @deprecated Instead use setMaxFailAttempts + * + * @param string $max_fail_attempts + * @return $this + */ + public function setMax_fail_attempts($max_fail_attempts) + { + $this->max_fail_attempts = $max_fail_attempts; + return $this; + } + + /** + * Total number of failed attempts allowed. Default is 0, representing an infinite number of failed attempts. + * @deprecated Instead use getMaxFailAttempts + * + * @return string + */ + public function getMax_fail_attempts() + { + return $this->max_fail_attempts; + } + + /** + * Allow auto billing for the outstanding amount of the agreement in the next cycle. Allowed values: `YES`, `NO`. Default is `NO`. + * + * @param string $auto_bill_amount + * + * @return $this + */ + public function setAutoBillAmount($auto_bill_amount) + { + $this->auto_bill_amount = $auto_bill_amount; + return $this; + } + + /** + * Allow auto billing for the outstanding amount of the agreement in the next cycle. Allowed values: `YES`, `NO`. Default is `NO`. + * + * @return string + */ + public function getAutoBillAmount() + { + return $this->auto_bill_amount; + } + + /** + * Allow auto billing for the outstanding amount of the agreement in the next cycle. Allowed values: `YES`, `NO`. Default is `NO`. + * + * @deprecated Instead use setAutoBillAmount + * + * @param string $auto_bill_amount + * @return $this + */ + public function setAuto_bill_amount($auto_bill_amount) + { + $this->auto_bill_amount = $auto_bill_amount; + return $this; + } + + /** + * Allow auto billing for the outstanding amount of the agreement in the next cycle. Allowed values: `YES`, `NO`. Default is `NO`. + * @deprecated Instead use getAutoBillAmount + * + * @return string + */ + public function getAuto_bill_amount() + { + return $this->auto_bill_amount; + } + + /** + * Action to take if a failure occurs during initial payment. Allowed values: `CONTINUE`, `CANCEL`. Default is continue. + * + * @param string $initial_fail_amount_action + * + * @return $this + */ + public function setInitialFailAmountAction($initial_fail_amount_action) + { + $this->initial_fail_amount_action = $initial_fail_amount_action; + return $this; + } + + /** + * Action to take if a failure occurs during initial payment. Allowed values: `CONTINUE`, `CANCEL`. Default is continue. + * + * @return string + */ + public function getInitialFailAmountAction() + { + return $this->initial_fail_amount_action; + } + + /** + * Action to take if a failure occurs during initial payment. Allowed values: `CONTINUE`, `CANCEL`. Default is continue. + * + * @deprecated Instead use setInitialFailAmountAction + * + * @param string $initial_fail_amount_action + * @return $this + */ + public function setInitial_fail_amount_action($initial_fail_amount_action) + { + $this->initial_fail_amount_action = $initial_fail_amount_action; + return $this; + } + + /** + * Action to take if a failure occurs during initial payment. Allowed values: `CONTINUE`, `CANCEL`. Default is continue. + * @deprecated Instead use getInitialFailAmountAction + * + * @return string + */ + public function getInitial_fail_amount_action() + { + return $this->initial_fail_amount_action; + } + + /** + * Payment types that are accepted for this plan. + * + * @param string $accepted_payment_type + * + * @return $this + */ + public function setAcceptedPaymentType($accepted_payment_type) + { + $this->accepted_payment_type = $accepted_payment_type; + return $this; + } + + /** + * Payment types that are accepted for this plan. + * + * @return string + */ + public function getAcceptedPaymentType() + { + return $this->accepted_payment_type; + } + + /** + * Payment types that are accepted for this plan. + * + * @deprecated Instead use setAcceptedPaymentType + * + * @param string $accepted_payment_type + * @return $this + */ + public function setAccepted_payment_type($accepted_payment_type) + { + $this->accepted_payment_type = $accepted_payment_type; + return $this; + } + + /** + * Payment types that are accepted for this plan. + * @deprecated Instead use getAcceptedPaymentType + * + * @return string + */ + public function getAccepted_payment_type() + { + return $this->accepted_payment_type; + } + + /** + * char_set for this plan. + * + * @param string $char_set + * + * @return $this + */ + public function setCharSet($char_set) + { + $this->char_set = $char_set; + return $this; + } + + /** + * char_set for this plan. + * + * @return string + */ + public function getCharSet() + { + return $this->char_set; + } + + /** + * char_set for this plan. + * + * @deprecated Instead use setCharSet + * + * @param string $char_set + * @return $this + */ + public function setChar_set($char_set) + { + $this->char_set = $char_set; + return $this; + } + + /** + * char_set for this plan. + * @deprecated Instead use getCharSet + * + * @return string + */ + public function getChar_set() + { + return $this->char_set; + } + +} diff --git a/lib/PayPal/Api/OverrideChargeModel.php b/lib/PayPal/Api/OverrideChargeModel.php new file mode 100644 index 0000000..b720222 --- /dev/null +++ b/lib/PayPal/Api/OverrideChargeModel.php @@ -0,0 +1,90 @@ +charge_id = $charge_id; + return $this; + } + + /** + * ID of charge model. + * + * @return string + */ + public function getChargeId() + { + return $this->charge_id; + } + + /** + * ID of charge model. + * + * @deprecated Instead use setChargeId + * + * @param string $charge_id + * @return $this + */ + public function setCharge_id($charge_id) + { + $this->charge_id = $charge_id; + return $this; + } + + /** + * ID of charge model. + * @deprecated Instead use getChargeId + * + * @return string + */ + public function getCharge_id() + { + return $this->charge_id; + } + + /** + * Updated Amount to be associated with this charge model. + * + * @param \PayPal\Api\Currency $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * Updated Amount to be associated with this charge model. + * + * @return \PayPal\Api\Currency + */ + public function getAmount() + { + return $this->amount; + } + +} diff --git a/lib/PayPal/Api/Patch.php b/lib/PayPal/Api/Patch.php index 23502b7..5b1974b 100644 --- a/lib/PayPal/Api/Patch.php +++ b/lib/PayPal/Api/Patch.php @@ -20,7 +20,7 @@ class Patch extends PPModel { /** * The operation to perform. - * Valid Values: ["add", "remove", "replace", "move", "copy", "test"] + * Valid Values: ["add", "remove", "replace", "move", "copy", "test"] * * @param string $op * @@ -44,7 +44,6 @@ class Patch extends PPModel /** * String containing a JSON-Pointer value that references a location within the target document where the operation is performed. - * * * @param string $path * @@ -68,7 +67,6 @@ class Patch extends PPModel /** * New value to apply based on the operation. op=remove does not require value. - * * * @param mixed $value * @@ -92,7 +90,6 @@ class Patch extends PPModel /** * A string containing a JSON Pointer value that references the location in the target document from which to move the value. Required for use where op=move. - * * * @param string $from * diff --git a/lib/PayPal/Api/PatchRequest.php b/lib/PayPal/Api/PatchRequest.php new file mode 100644 index 0000000..fe5a82f --- /dev/null +++ b/lib/PayPal/Api/PatchRequest.php @@ -0,0 +1,86 @@ +patches = $patches; + return $this; + } + + /** + * Placeholder for holding array of patch objects + * + * @return \PayPal\Api\Patch[] + */ + public function getPatches() + { + return $this->patches; + } + + /** + * Append Patches to the list. + * + * @param \PayPal\Api\Patch $patch + * @return $this + */ + public function addPatch($patch) + { + if (!$this->getPatches()) { + return $this->setPatches(array($patch)); + } else { + return $this->setPatches( + array_merge($this->getPatches(), array($patch)) + ); + } + } + + /** + * Remove Patches from the list. + * + * @param \PayPal\Api\Patch $patch + * @return $this + */ + public function removePatch($patch) + { + return $this->setPatches( + array_diff($this->getPatches(), array($patch)) + ); + } + + /** + * As PatchRequest holds the array of Patch object, we would override the json conversion to return + * a json representation of array of Patch objects. + * + * @param int $options + * @return mixed|string + */ + public function toJSON($options = 0) + { + $json = array(); + foreach ($this->getPatches() as $patch) { + $json[] = $patch->toArray(); + } + return json_encode($json, $options); + } +} diff --git a/lib/PayPal/Api/Payer.php b/lib/PayPal/Api/Payer.php index 3c00ac5..d6d87d7 100644 --- a/lib/PayPal/Api/Payer.php +++ b/lib/PayPal/Api/Payer.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class Payer @@ -14,15 +13,15 @@ use PayPal\Rest\ApiContext; * * @property string payment_method * @property string status - * @property \PayPal\Api\FundingInstrument funding_instruments + * @property \PayPal\Api\FundingInstrument[] funding_instruments * @property string funding_option_id * @property \PayPal\Api\PayerInfo payer_info */ class Payer extends PPModel { /** - * Payment method being used - PayPal Wallet payment, Bank Direct Debit or Direct Credit card. - * Valid Values: ["credit_card", "bank", "paypal"] + * Payment method being used - PayPal Wallet payment, Bank Direct Debit, or Direct Credit card. + * Valid Values: ["credit_card", "bank", "paypal"] * * @param string $payment_method * @@ -35,7 +34,7 @@ class Payer extends PPModel } /** - * Payment method being used - PayPal Wallet payment, Bank Direct Debit or Direct Credit card. + * Payment method being used - PayPal Wallet payment, Bank Direct Debit, or Direct Credit card. * * @return string */ @@ -45,7 +44,7 @@ class Payer extends PPModel } /** - * Payment method being used - PayPal Wallet payment, Bank Direct Debit or Direct Credit card. + * Payment method being used - PayPal Wallet payment, Bank Direct Debit, or Direct Credit card. * * @deprecated Instead use setPaymentMethod * @@ -59,7 +58,7 @@ class Payer extends PPModel } /** - * Payment method being used - PayPal Wallet payment, Bank Direct Debit or Direct Credit card. + * Payment method being used - PayPal Wallet payment, Bank Direct Debit, or Direct Credit card. * @deprecated Instead use getPaymentMethod * * @return string @@ -71,7 +70,7 @@ class Payer extends PPModel /** * Status of Payer PayPal Account. - * Valid Values: ["VERIFIED", "UNVERIFIED"] + * Valid Values: ["VERIFIED", "UNVERIFIED"] * * @param string $status * @@ -94,10 +93,9 @@ class Payer extends PPModel } /** - * List of funding instruments from where the funds of the current payment come from. Typically a credit card. - * + * List of funding instruments from which the funds of the current payment come. Typically a credit card. * - * @param \PayPal\Api\FundingInstrument $funding_instruments + * @param \PayPal\Api\FundingInstrument[] $funding_instruments * * @return $this */ @@ -108,7 +106,7 @@ class Payer extends PPModel } /** - * List of funding instruments from where the funds of the current payment come from. Typically a credit card. + * List of funding instruments from which the funds of the current payment come. Typically a credit card. * * @return \PayPal\Api\FundingInstrument[] */ @@ -118,7 +116,37 @@ class Payer extends PPModel } /** - * List of funding instruments from where the funds of the current payment come from. Typically a credit card. + * Append FundingInstruments to the list. + * + * @param \PayPal\Api\FundingInstrument $fundingInstrument + * @return $this + */ + public function addFundingInstrument($fundingInstrument) + { + if (!$this->getFundingInstruments()) { + return $this->setFundingInstruments(array($fundingInstrument)); + } else { + return $this->setFundingInstruments( + array_merge($this->getFundingInstruments(), array($fundingInstrument)) + ); + } + } + + /** + * Remove FundingInstruments from the list. + * + * @param \PayPal\Api\FundingInstrument $fundingInstrument + * @return $this + */ + public function removeFundingInstrument($fundingInstrument) + { + return $this->setFundingInstruments( + array_diff($this->getFundingInstruments(), array($fundingInstrument)) + ); + } + + /** + * List of funding instruments from which the funds of the current payment come. Typically a credit card. * * @deprecated Instead use setFundingInstruments * @@ -132,7 +160,7 @@ class Payer extends PPModel } /** - * List of funding instruments from where the funds of the current payment come from. Typically a credit card. + * List of funding instruments from which the funds of the current payment come. Typically a credit card. * @deprecated Instead use getFundingInstruments * * @return \PayPal\Api\FundingInstrument @@ -143,8 +171,7 @@ class Payer extends PPModel } /** - * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present - * + * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present. * * @param string $funding_option_id * @@ -157,7 +184,7 @@ class Payer extends PPModel } /** - * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present + * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present. * * @return string */ @@ -167,7 +194,7 @@ class Payer extends PPModel } /** - * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present + * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present. * * @deprecated Instead use setFundingOptionId * @@ -181,7 +208,7 @@ class Payer extends PPModel } /** - * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present + * Id of user selected funding option for the payment. 'OneOf' funding_instruments or funding_option_id to be present. * @deprecated Instead use getFundingOptionId * * @return string @@ -193,7 +220,6 @@ class Payer extends PPModel /** * Information related to the Payer. - * * * @param \PayPal\Api\PayerInfo $payer_info * diff --git a/lib/PayPal/Api/PayerInfo.php b/lib/PayPal/Api/PayerInfo.php index 0a040b6..0439117 100644 --- a/lib/PayPal/Api/PayerInfo.php +++ b/lib/PayPal/Api/PayerInfo.php @@ -3,12 +3,11 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class PayerInfo * - * A resource representing a information about Payer. + * A resource representing information about a Payer. * * @package PayPal\Api * @@ -30,7 +29,6 @@ class PayerInfo extends PPModel { /** * Email address representing the Payer. - * * * @param string $email * @@ -54,7 +52,6 @@ class PayerInfo extends PPModel /** * External Remember Me id representing the Payer - * * * @param string $external_remember_me_id * @@ -103,7 +100,6 @@ class PayerInfo extends PPModel /** * Account Number representing the Payer - * * * @param string $buyer_account_number * @@ -152,7 +148,6 @@ class PayerInfo extends PPModel /** * First Name of the Payer. - * * * @param string $first_name * @@ -201,7 +196,6 @@ class PayerInfo extends PPModel /** * Last Name of the Payer. - * * * @param string $last_name * @@ -250,7 +244,6 @@ class PayerInfo extends PPModel /** * PayPal assigned Payer ID. - * * * @param string $payer_id * @@ -299,7 +292,6 @@ class PayerInfo extends PPModel /** * Phone number representing the Payer. - * * * @param string $phone * @@ -323,7 +315,7 @@ class PayerInfo extends PPModel /** * Phone type - * Valid Values: ["HOME", "WORK", "MOBILE", "OTHER"] + * Valid Values: ["HOME", "WORK", "MOBILE", "OTHER"] * * @param string $phone_type * @@ -372,7 +364,6 @@ class PayerInfo extends PPModel /** * Birth date of the Payer in ISO8601 format (YYYY-MM-DD). - * * * @param string $birth_date * @@ -421,7 +412,6 @@ class PayerInfo extends PPModel /** * Payer's tax ID. - * * * @param string $tax_id * @@ -470,7 +460,7 @@ class PayerInfo extends PPModel /** * Payer's tax ID type. - * Valid Values: ["BR_CPF", "BR_CNPJ"] + * Valid Values: ["BR_CPF", "BR_CNPJ"] * * @param string $tax_id_type * @@ -519,7 +509,6 @@ class PayerInfo extends PPModel /** * Billing address of the Payer. - * * * @param \PayPal\Api\Address $billing_address * @@ -568,7 +557,6 @@ class PayerInfo extends PPModel /** * Obsolete. Use shipping address present in purchase unit. - * * * @param \PayPal\Api\ShippingAddress $shipping_address * diff --git a/lib/PayPal/Api/Payment.php b/lib/PayPal/Api/Payment.php index 0213fc0..1217a6c 100644 --- a/lib/PayPal/Api/Payment.php +++ b/lib/PayPal/Api/Payment.php @@ -3,6 +3,7 @@ namespace PayPal\Api; use PayPal\Common\PPModel; +use PayPal\Common\ResourceModel; use PayPal\Rest\ApiContext; use PayPal\Rest\IResource; use PayPal\Api\PaymentHistory; @@ -28,7 +29,7 @@ use PayPal\Validation\ArgumentValidator; * @property \PayPal\Api\Links links * @property string experience_profile_id */ -class Payment extends PPModel implements IResource +class Payment extends ResourceModel { /** * OAuth Credentials to use for this call @@ -392,17 +393,21 @@ class Payment extends PPModel implements IResource * Creates (and processes) a new Payment Resource. * * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Payment */ - public function create($apiContext = null) + public function create($apiContext = null, $restCall = null) { $payLoad = $this->toJSON(); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment", "POST", $payLoad); + $json = self::executeCall( + "/v1/payments/payment", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); $this->fromJson($json); return $this; } @@ -412,18 +417,22 @@ class Payment extends PPModel implements IResource * * @param string $paymentId * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Payment */ - public static function get($paymentId, $apiContext = null) + public static function get($paymentId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($paymentId, 'paymentId'); $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/$paymentId", "GET", $payLoad); + $json = self::executeCall( + "/v1/payments/payment/$paymentId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); $ret = new Payment(); $ret->fromJson($json); return $ret; @@ -434,19 +443,23 @@ class Payment extends PPModel implements IResource * * @param PaymentExecution $paymentExecution * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Payment */ - public function execute($paymentExecution, $apiContext = null) + public function execute($paymentExecution, $apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); ArgumentValidator::validate($paymentExecution, 'paymentExecution'); $payLoad = $paymentExecution->toJSON(); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment/{$this->getId()}/execute", "POST", $payLoad); + $json = self::executeCall( + "/v1/payments/payment/{$this->getId()}/execute", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); $this->fromJson($json); return $this; } @@ -456,9 +469,10 @@ class Payment extends PPModel implements IResource * * @param array $params * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return PaymentHistory */ - public static function all($params, $apiContext = null) + public static function all($params, $apiContext = null, $restCall = null) { ArgumentValidator::validate($params, 'params'); @@ -473,11 +487,14 @@ class Payment extends PPModel implements IResource 'sort_by' => 1, 'sort_order' => 1, ); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), "GET", $payLoad); + $json = self::executeCall( + "/v1/payments/payment?" . http_build_query(array_intersect_key($params, $allowedParams)), + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); $ret = new PaymentHistory(); $ret->fromJson($json); return $ret; diff --git a/lib/PayPal/Api/PaymentCard.php b/lib/PayPal/Api/PaymentCard.php index 0c3328c..9e844b8 100644 --- a/lib/PayPal/Api/PaymentCard.php +++ b/lib/PayPal/Api/PaymentCard.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class PaymentCard @@ -26,13 +25,12 @@ use PayPal\Rest\ApiContext; * @property string external_customer_id * @property string status * @property string valid_until - * @property \PayPal\Api\Links links + * @property \PayPal\Api\Links[] links */ class PaymentCard extends PPModel { /** * ID of the credit card being saved for later use. - * * * @param string $id * @@ -56,7 +54,6 @@ class PaymentCard extends PPModel /** * Card number. - * * * @param string $number * @@ -80,7 +77,7 @@ class PaymentCard extends PPModel /** * Type of the Card. - * Valid Values: ["VISA", "AMEX", "SOLO", "JCB", "STAR", "DELTA", "DISCOVER", "SWITCH", "MAESTRO", "CB_NATIONALE", "CONFINOGA", "COFIDIS", "ELECTRON", "CETELEM", "CHINA_UNION_PAY", "MASTERCARD"] + * Valid Values: ["VISA", "AMEX", "SOLO", "JCB", "STAR", "DELTA", "DISCOVER", "SWITCH", "MAESTRO", "CB_NATIONALE", "CONFINOGA", "COFIDIS", "ELECTRON", "CETELEM", "CHINA_UNION_PAY", "MASTERCARD"] * * @param string $type * @@ -104,7 +101,6 @@ class PaymentCard extends PPModel /** * 2 digit card expiry month. - * * * @param int $expire_month * @@ -152,8 +148,7 @@ class PaymentCard extends PPModel } /** - * 4 digit card expiry year - * + * 4 digit card expiry year. * * @param int $expire_year * @@ -166,7 +161,7 @@ class PaymentCard extends PPModel } /** - * 4 digit card expiry year + * 4 digit card expiry year. * * @return int */ @@ -176,7 +171,7 @@ class PaymentCard extends PPModel } /** - * 4 digit card expiry year + * 4 digit card expiry year. * * @deprecated Instead use setExpireYear * @@ -190,7 +185,7 @@ class PaymentCard extends PPModel } /** - * 4 digit card expiry year + * 4 digit card expiry year. * @deprecated Instead use getExpireYear * * @return int @@ -202,7 +197,6 @@ class PaymentCard extends PPModel /** * 2 digit card start month. - * * * @param int $start_month * @@ -251,7 +245,6 @@ class PaymentCard extends PPModel /** * 4 digit card start year. - * * * @param int $start_year * @@ -299,8 +292,7 @@ class PaymentCard extends PPModel } /** - * Card validation code. Only supported when making a Payment but not when saving a payment card for future use. - * + * Card validation code. Only supported when making a Payment, but not when saving a payment card for future use. * * @param int $cvv2 * @@ -313,7 +305,7 @@ class PaymentCard extends PPModel } /** - * Card validation code. Only supported when making a Payment but not when saving a payment card for future use. + * Card validation code. Only supported when making a Payment, but not when saving a payment card for future use. * * @return int */ @@ -324,7 +316,6 @@ class PaymentCard extends PPModel /** * Card holder's first name. - * * * @param string $first_name * @@ -373,7 +364,6 @@ class PaymentCard extends PPModel /** * Card holder's last name. - * * * @param string $last_name * @@ -422,7 +412,6 @@ class PaymentCard extends PPModel /** * Billing Address associated with this card. - * * * @param \PayPal\Api\Address $billing_address * @@ -470,8 +459,7 @@ class PaymentCard extends PPModel } /** - * A unique identifier of the customer to whom this card account belongs to. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. - * + * A unique identifier of the customer to whom this card account belongs. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. * * @param string $external_customer_id * @@ -484,7 +472,7 @@ class PaymentCard extends PPModel } /** - * A unique identifier of the customer to whom this card account belongs to. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. + * A unique identifier of the customer to whom this card account belongs. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. * * @return string */ @@ -494,7 +482,7 @@ class PaymentCard extends PPModel } /** - * A unique identifier of the customer to whom this card account belongs to. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. + * A unique identifier of the customer to whom this card account belongs. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. * * @deprecated Instead use setExternalCustomerId * @@ -508,7 +496,7 @@ class PaymentCard extends PPModel } /** - * A unique identifier of the customer to whom this card account belongs to. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. + * A unique identifier of the customer to whom this card account belongs. Generated and provided by the facilitator. This is required when creating or using a stored funding instrument in vault. * @deprecated Instead use getExternalCustomerId * * @return string @@ -520,7 +508,7 @@ class PaymentCard extends PPModel /** * State of the funding instrument. - * Valid Values: ["EXPIRED", "ACTIVE"] + * Valid Values: ["EXPIRED", "ACTIVE"] * * @param string $status * @@ -543,8 +531,7 @@ class PaymentCard extends PPModel } /** - * Date/Time until this resource can be used fund a payment. - * + * Date/Time until this resource can be used to fund a payment. * * @param string $valid_until * @@ -557,7 +544,7 @@ class PaymentCard extends PPModel } /** - * Date/Time until this resource can be used fund a payment. + * Date/Time until this resource can be used to fund a payment. * * @return string */ @@ -567,7 +554,7 @@ class PaymentCard extends PPModel } /** - * Date/Time until this resource can be used fund a payment. + * Date/Time until this resource can be used to fund a payment. * * @deprecated Instead use setValidUntil * @@ -581,7 +568,7 @@ class PaymentCard extends PPModel } /** - * Date/Time until this resource can be used fund a payment. + * Date/Time until this resource can be used to fund a payment. * @deprecated Instead use getValidUntil * * @return string @@ -593,9 +580,8 @@ class PaymentCard extends PPModel /** * Sets Links - * * - * @param \PayPal\Api\Links $links + * @param \PayPal\Api\Links[] $links * * @return $this */ @@ -615,4 +601,34 @@ class PaymentCard extends PPModel return $this->links; } + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + } diff --git a/lib/PayPal/Api/PaymentCardToken.php b/lib/PayPal/Api/PaymentCardToken.php index a8dba69..aa52cea 100644 --- a/lib/PayPal/Api/PaymentCardToken.php +++ b/lib/PayPal/Api/PaymentCardToken.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class PaymentCardToken @@ -23,7 +22,6 @@ class PaymentCardToken extends PPModel { /** * ID of a previously saved Payment Card resource. - * * * @param string $payment_card_id * @@ -72,7 +70,6 @@ class PaymentCardToken extends PPModel /** * The unique identifier of the payer used when saving this payment card. - * * * @param string $external_customer_id * @@ -121,7 +118,6 @@ class PaymentCardToken extends PPModel /** * Last 4 digits of the card number from the saved card. - * * * @param string $last4 * @@ -145,7 +141,7 @@ class PaymentCardToken extends PPModel /** * Type of the Card. - * Valid Values: ["VISA", "AMEX", "SOLO", "JCB", "STAR", "DELTA", "DISCOVER", "SWITCH", "MAESTRO", "CB_NATIONALE", "CONFINOGA", "COFIDIS", "ELECTRON", "CETELEM", "CHINA_UNION_PAY", "MASTERCARD"] + * Valid Values: ["VISA", "AMEX", "SOLO", "JCB", "STAR", "DELTA", "DISCOVER", "SWITCH", "MAESTRO", "CB_NATIONALE", "CONFINOGA", "COFIDIS", "ELECTRON", "CETELEM", "CHINA_UNION_PAY", "MASTERCARD"] * * @param string $type * @@ -168,8 +164,7 @@ class PaymentCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 - * + * Expiry month from the saved card with value 1 - 12. * * @param int $expire_month * @@ -182,7 +177,7 @@ class PaymentCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 + * Expiry month from the saved card with value 1 - 12. * * @return int */ @@ -192,7 +187,7 @@ class PaymentCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 + * Expiry month from the saved card with value 1 - 12. * * @deprecated Instead use setExpireMonth * @@ -206,7 +201,7 @@ class PaymentCardToken extends PPModel } /** - * card expiry month from the saved card with value 1 - 12 + * Expiry month from the saved card with value 1 - 12. * @deprecated Instead use getExpireMonth * * @return int @@ -217,8 +212,7 @@ class PaymentCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card - * + * Four digit expiry year from the saved card, represented as YYYY format. * * @param int $expire_year * @@ -231,7 +225,7 @@ class PaymentCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card + * Four digit expiry year from the saved card, represented as YYYY format. * * @return int */ @@ -241,7 +235,7 @@ class PaymentCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card + * Four digit expiry year from the saved card, represented as YYYY format. * * @deprecated Instead use setExpireYear * @@ -255,7 +249,7 @@ class PaymentCardToken extends PPModel } /** - * 4 digit card expiry year from the saved card + * Four digit expiry year from the saved card, represented as YYYY format. * @deprecated Instead use getExpireYear * * @return int diff --git a/lib/PayPal/Api/PaymentDefinition.php b/lib/PayPal/Api/PaymentDefinition.php new file mode 100644 index 0000000..e78245e --- /dev/null +++ b/lib/PayPal/Api/PaymentDefinition.php @@ -0,0 +1,289 @@ +id = $id; + return $this; + } + + /** + * Identifier of the payment_definition. 128 characters max. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Name of the payment definition. 128 characters max. + * + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * Name of the payment definition. 128 characters max. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Type of the payment definition. Allowed values: `TRIAL`, `REGULAR`. + * + * @param string $type + * + * @return $this + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Type of the payment definition. Allowed values: `TRIAL`, `REGULAR`. + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * How frequently the customer should be charged. + * + * @param string $frequency_interval + * + * @return $this + */ + public function setFrequencyInterval($frequency_interval) + { + $this->frequency_interval = $frequency_interval; + return $this; + } + + /** + * How frequently the customer should be charged. + * + * @return string + */ + public function getFrequencyInterval() + { + return $this->frequency_interval; + } + + /** + * How frequently the customer should be charged. + * + * @deprecated Instead use setFrequencyInterval + * + * @param string $frequency_interval + * @return $this + */ + public function setFrequency_interval($frequency_interval) + { + $this->frequency_interval = $frequency_interval; + return $this; + } + + /** + * How frequently the customer should be charged. + * @deprecated Instead use getFrequencyInterval + * + * @return string + */ + public function getFrequency_interval() + { + return $this->frequency_interval; + } + + /** + * Frequency of the payment definition offered. Allowed values: `WEEK`, `DAY`, `YEAR`, `MONTH`. + * + * @param string $frequency + * + * @return $this + */ + public function setFrequency($frequency) + { + $this->frequency = $frequency; + return $this; + } + + /** + * Frequency of the payment definition offered. Allowed values: `WEEK`, `DAY`, `YEAR`, `MONTH`. + * + * @return string + */ + public function getFrequency() + { + return $this->frequency; + } + + /** + * Number of cycles in this payment definition. + * + * @param string $cycles + * + * @return $this + */ + public function setCycles($cycles) + { + $this->cycles = $cycles; + return $this; + } + + /** + * Number of cycles in this payment definition. + * + * @return string + */ + public function getCycles() + { + return $this->cycles; + } + + /** + * Amount that will be charged at the end of each cycle for this payment definition. + * + * @param \PayPal\Api\Currency $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + return $this; + } + + /** + * Amount that will be charged at the end of each cycle for this payment definition. + * + * @return \PayPal\Api\Currency + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Array of charge_models for this payment definition. + * + * @param \PayPal\Api\ChargeModel[] $charge_models + * + * @return $this + */ + public function setChargeModels($charge_models) + { + $this->charge_models = $charge_models; + return $this; + } + + /** + * Array of charge_models for this payment definition. + * + * @return \PayPal\Api\ChargeModel[] + */ + public function getChargeModels() + { + return $this->charge_models; + } + + /** + * Append ChargeModels to the list. + * + * @param \PayPal\Api\ChargeModel $chargeModel + * @return $this + */ + public function addChargeModel($chargeModel) + { + if (!$this->getChargeModels()) { + return $this->setChargeModels(array($chargeModel)); + } else { + return $this->setChargeModels( + array_merge($this->getChargeModels(), array($chargeModel)) + ); + } + } + + /** + * Remove ChargeModels from the list. + * + * @param \PayPal\Api\ChargeModel $chargeModel + * @return $this + */ + public function removeChargeModel($chargeModel) + { + return $this->setChargeModels( + array_diff($this->getChargeModels(), array($chargeModel)) + ); + } + + /** + * Array of charge_models for this payment definition. + * + * @deprecated Instead use setChargeModels + * + * @param \PayPal\Api\ChargeModel $charge_models + * @return $this + */ + public function setCharge_models($charge_models) + { + $this->charge_models = $charge_models; + return $this; + } + + /** + * Array of charge_models for this payment definition. + * @deprecated Instead use getChargeModels + * + * @return \PayPal\Api\ChargeModel + */ + public function getCharge_models() + { + return $this->charge_models; + } + +} diff --git a/lib/PayPal/Api/Plan.php b/lib/PayPal/Api/Plan.php new file mode 100644 index 0000000..3b46398 --- /dev/null +++ b/lib/PayPal/Api/Plan.php @@ -0,0 +1,577 @@ +id = $id; + return $this; + } + + /** + * Identifier of the billing plan. 128 characters max. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Name of the billing plan. 128 characters max. + * + * @param string $name + * + * @return $this + */ + public function setName($name) + { + $this->name = $name; + return $this; + } + + /** + * Name of the billing plan. 128 characters max. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Description of the billing plan. 128 characters max. + * + * @param string $description + * + * @return $this + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Description of the billing plan. 128 characters max. + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Type of the billing plan. Allowed values: `FIXED`, `INFINITE`. + * + * @param string $type + * + * @return $this + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Type of the billing plan. Allowed values: `FIXED`, `INFINITE`. + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Status of the billing plan. Allowed values: `CREATED`, `ACTIVE`, `INACTIVE`, and `DELETED`. + * + * @param string $state + * + * @return $this + */ + public function setState($state) + { + $this->state = $state; + return $this; + } + + /** + * Status of the billing plan. Allowed values: `CREATED`, `ACTIVE`, `INACTIVE`, and `DELETED`. + * + * @return string + */ + public function getState() + { + return $this->state; + } + + /** + * Time when the billing plan was created. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @param string $create_time + * + * @return $this + */ + public function setCreateTime($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Time when the billing plan was created. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @return string + */ + public function getCreateTime() + { + return $this->create_time; + } + + /** + * Time when the billing plan was created. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @deprecated Instead use setCreateTime + * + * @param string $create_time + * @return $this + */ + public function setCreate_time($create_time) + { + $this->create_time = $create_time; + return $this; + } + + /** + * Time when the billing plan was created. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * @deprecated Instead use getCreateTime + * + * @return string + */ + public function getCreate_time() + { + return $this->create_time; + } + + /** + * Time when this billing plan was updated. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @param string $update_time + * + * @return $this + */ + public function setUpdateTime($update_time) + { + $this->update_time = $update_time; + return $this; + } + + /** + * Time when this billing plan was updated. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @return string + */ + public function getUpdateTime() + { + return $this->update_time; + } + + /** + * Time when this billing plan was updated. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * + * @deprecated Instead use setUpdateTime + * + * @param string $update_time + * @return $this + */ + public function setUpdate_time($update_time) + { + $this->update_time = $update_time; + return $this; + } + + /** + * Time when this billing plan was updated. Format YYYY-MM-DDTimeTimezone, as defined in [ISO8601](http://tools.ietf.org/html/rfc3339#section-5.6). + * @deprecated Instead use getUpdateTime + * + * @return string + */ + public function getUpdate_time() + { + return $this->update_time; + } + + /** + * Array of payment definitions for this billing plan. + * + * @param \PayPal\Api\PaymentDefinition[] $payment_definitions + * + * @return $this + */ + public function setPaymentDefinitions($payment_definitions) + { + $this->payment_definitions = $payment_definitions; + return $this; + } + + /** + * Array of payment definitions for this billing plan. + * + * @return \PayPal\Api\PaymentDefinition[] + */ + public function getPaymentDefinitions() + { + return $this->payment_definitions; + } + + /** + * Append PaymentDefinitions to the list. + * + * @param \PayPal\Api\PaymentDefinition $paymentDefinition + * @return $this + */ + public function addPaymentDefinition($paymentDefinition) + { + if (!$this->getPaymentDefinitions()) { + return $this->setPaymentDefinitions(array($paymentDefinition)); + } else { + return $this->setPaymentDefinitions( + array_merge($this->getPaymentDefinitions(), array($paymentDefinition)) + ); + } + } + + /** + * Remove PaymentDefinitions from the list. + * + * @param \PayPal\Api\PaymentDefinition $paymentDefinition + * @return $this + */ + public function removePaymentDefinition($paymentDefinition) + { + return $this->setPaymentDefinitions( + array_diff($this->getPaymentDefinitions(), array($paymentDefinition)) + ); + } + + /** + * Array of payment definitions for this billing plan. + * + * @deprecated Instead use setPaymentDefinitions + * + * @param \PayPal\Api\PaymentDefinition $payment_definitions + * @return $this + */ + public function setPayment_definitions($payment_definitions) + { + $this->payment_definitions = $payment_definitions; + return $this; + } + + /** + * Array of payment definitions for this billing plan. + * @deprecated Instead use getPaymentDefinitions + * + * @return \PayPal\Api\PaymentDefinition + */ + public function getPayment_definitions() + { + return $this->payment_definitions; + } + + /** + * Array of terms for this billing plan. + * + * @param \PayPal\Api\Terms[] $terms + * + * @return $this + */ + public function setTerms($terms) + { + $this->terms = $terms; + return $this; + } + + /** + * Array of terms for this billing plan. + * + * @return \PayPal\Api\Terms[] + */ + public function getTerms() + { + return $this->terms; + } + + /** + * Append Terms to the list. + * + * @param \PayPal\Api\Terms $terms + * @return $this + */ + public function addTerm($terms) + { + if (!$this->getTerms()) { + return $this->setTerms(array($terms)); + } else { + return $this->setTerms( + array_merge($this->getTerms(), array($terms)) + ); + } + } + + /** + * Remove Terms from the list. + * + * @param \PayPal\Api\Terms $terms + * @return $this + */ + public function removeTerm($terms) + { + return $this->setTerms( + array_diff($this->getTerms(), array($terms)) + ); + } + + /** + * Specific preferences such as: set up fee, max fail attempts, autobill amount, and others that are configured for this billing plan. + * + * @param \PayPal\Api\MerchantPreferences $merchant_preferences + * + * @return $this + */ + public function setMerchantPreferences($merchant_preferences) + { + $this->merchant_preferences = $merchant_preferences; + return $this; + } + + /** + * Specific preferences such as: set up fee, max fail attempts, autobill amount, and others that are configured for this billing plan. + * + * @return \PayPal\Api\MerchantPreferences + */ + public function getMerchantPreferences() + { + return $this->merchant_preferences; + } + + /** + * Specific preferences such as: set up fee, max fail attempts, autobill amount, and others that are configured for this billing plan. + * + * @deprecated Instead use setMerchantPreferences + * + * @param \PayPal\Api\MerchantPreferences $merchant_preferences + * @return $this + */ + public function setMerchant_preferences($merchant_preferences) + { + $this->merchant_preferences = $merchant_preferences; + return $this; + } + + /** + * Specific preferences such as: set up fee, max fail attempts, autobill amount, and others that are configured for this billing plan. + * @deprecated Instead use getMerchantPreferences + * + * @return \PayPal\Api\MerchantPreferences + */ + public function getMerchant_preferences() + { + return $this->merchant_preferences; + } + + /** + * Sets Links + * + * @param \PayPal\Api\Links[] $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + + /** + * Gets Links + * + * @return \PayPal\Api\Links[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + + /** + * Retrieve the details for a particular billing plan by passing the billing plan ID to the request URI. + * + * @param string $planId + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Plan + */ + public static function get($planId, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($planId, 'planId'); + $payLoad = ""; + $json = self::executeCall( + "/v1/payments/billing-plans/$planId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new Plan(); + $ret->fromJson($json); + return $ret; + } + + /** + * Create a new billing plan by passing the details for the plan, including the plan name, description, and type, to the request URI. + * + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return Plan + */ + public function create($apiContext = null, $restCall = null) + { + $payLoad = $this->toJSON(); + $json = self::executeCall( + "/v1/payments/billing-plans/", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); + $this->fromJson($json); + return $this; + } + + /** + * Replace specific fields within a billing plan by passing the ID of the billing plan to the request URI. In addition, pass a patch object in the request JSON that specifies the operation to perform, field to update, and new value for each update. + * + * @param PatchRequest $patchRequest + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return bool + */ + public function update($patchRequest, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($this->getId(), "Id"); + ArgumentValidator::validate($patchRequest, 'patchRequest'); + $payLoad = $patchRequest->toJSON(); + self::executeCall( + "/v1/payments/billing-plans/{$this->getId()}", + "PATCH", + $payLoad, + null, + $apiContext, + $restCall + ); + return true; + } + + /** + * List billing plans according to optional query string parameters specified. + * + * @param array $params + * @param ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls + * @return PlanList + */ + public static function all($params, $apiContext = null, $restCall = null) + { + ArgumentValidator::validate($params, 'params'); + $payLoad = ""; + $allowedParams = array( + 'page_size' => 1, + 'status' => 1, + 'page' => 1, + 'total_required' => 1 + ); + $json = self::executeCall( + "/v1/payments/billing-plans/" . "?" . http_build_query(array_intersect_key($params, $allowedParams)), + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); + $ret = new PlanList(); + $ret->fromJson($json); + return $ret; + } + +} diff --git a/lib/PayPal/Api/PlanList.php b/lib/PayPal/Api/PlanList.php new file mode 100644 index 0000000..9f4b3cd --- /dev/null +++ b/lib/PayPal/Api/PlanList.php @@ -0,0 +1,223 @@ +plans = $plans; + return $this; + } + + /** + * Array of billing plans. + * + * @return \PayPal\Api\Plan[] + */ + public function getPlans() + { + return $this->plans; + } + + /** + * Append Plans to the list. + * + * @param \PayPal\Api\Plan $plan + * @return $this + */ + public function addPlan($plan) + { + if (!$this->getPlans()) { + return $this->setPlans(array($plan)); + } else { + return $this->setPlans( + array_merge($this->getPlans(), array($plan)) + ); + } + } + + /** + * Remove Plans from the list. + * + * @param \PayPal\Api\Plan $plan + * @return $this + */ + public function removePlan($plan) + { + return $this->setPlans( + array_diff($this->getPlans(), array($plan)) + ); + } + + /** + * Total number of items. + * + * @param string $total_items + * + * @return $this + */ + public function setTotalItems($total_items) + { + $this->total_items = $total_items; + return $this; + } + + /** + * Total number of items. + * + * @return string + */ + public function getTotalItems() + { + return $this->total_items; + } + + /** + * Total number of items. + * + * @deprecated Instead use setTotalItems + * + * @param string $total_items + * @return $this + */ + public function setTotal_items($total_items) + { + $this->total_items = $total_items; + return $this; + } + + /** + * Total number of items. + * @deprecated Instead use getTotalItems + * + * @return string + */ + public function getTotal_items() + { + return $this->total_items; + } + + /** + * Total number of pages. + * + * @param string $total_pages + * + * @return $this + */ + public function setTotalPages($total_pages) + { + $this->total_pages = $total_pages; + return $this; + } + + /** + * Total number of pages. + * + * @return string + */ + public function getTotalPages() + { + return $this->total_pages; + } + + /** + * Total number of pages. + * + * @deprecated Instead use setTotalPages + * + * @param string $total_pages + * @return $this + */ + public function setTotal_pages($total_pages) + { + $this->total_pages = $total_pages; + return $this; + } + + /** + * Total number of pages. + * @deprecated Instead use getTotalPages + * + * @return string + */ + public function getTotal_pages() + { + return $this->total_pages; + } + + /** + * Sets Links + * + * @param \PayPal\Api\Links[] $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + return $this; + } + + /** + * Gets Links + * + * @return \PayPal\Api\Links[] + */ + public function getLinks() + { + return $this->links; + } + + /** + * Append Links to the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function addLink($links) + { + if (!$this->getLinks()) { + return $this->setLinks(array($links)); + } else { + return $this->setLinks( + array_merge($this->getLinks(), array($links)) + ); + } + } + + /** + * Remove Links from the list. + * + * @param \PayPal\Api\Links $links + * @return $this + */ + public function removeLink($links) + { + return $this->setLinks( + array_diff($this->getLinks(), array($links)) + ); + } + +} diff --git a/lib/PayPal/Api/Sale.php b/lib/PayPal/Api/Sale.php index 72059c6..1ba5c00 100644 --- a/lib/PayPal/Api/Sale.php +++ b/lib/PayPal/Api/Sale.php @@ -2,9 +2,8 @@ namespace PayPal\Api; -use PayPal\Common\PPModel; +use PayPal\Common\ResourceModel; use PayPal\Rest\ApiContext; -use PayPal\Rest\IResource; use PayPal\Api\Refund; use PayPal\Transport\PPRestCall; use PayPal\Validation\ArgumentValidator; @@ -30,7 +29,7 @@ use PayPal\Validation\ArgumentValidator; * @property string parent_payment * @property \PayPal\Api\Links links */ -class Sale extends PPModel implements IResource +class Sale extends ResourceModel { /** * OAuth Credentials to use for this call @@ -592,18 +591,22 @@ class Sale extends PPModel implements IResource * * @param string $saleId * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Sale */ - public static function get($saleId, $apiContext = null) + public static function get($saleId, $apiContext = null, $restCall = null) { ArgumentValidator::validate($saleId, 'saleId'); $payLoad = ""; - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/sale/$saleId", "GET", $payLoad); + $json = self::executeCall( + "/v1/payments/sale/$saleId", + "GET", + $payLoad, + null, + $apiContext, + $restCall + ); $ret = new Sale(); $ret->fromJson($json); return $ret; @@ -614,19 +617,23 @@ class Sale extends PPModel implements IResource * * @param Refund $refund * @param \PayPal\Rest\ApiContext $apiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials. + * @param PPRestCall $restCall is the Rest Call Service that is used to make rest calls * @return Refund */ - public function refund($refund, $apiContext = null) + public function refund($refund, $apiContext = null, $restCall = null) { ArgumentValidator::validate($this->getId(), "Id"); ArgumentValidator::validate($refund, 'refund'); $payLoad = $refund->toJSON(); - if ($apiContext == null) { - $apiContext = new ApiContext(self::$credential); - } - $call = new PPRestCall($apiContext); - $json = $call->execute(array('PayPal\Rest\RestHandler'), "/v1/payments/sale/{$this->getId()}/refund", "POST", $payLoad); + $json = self::executeCall( + "/v1/payments/sale/{$this->getId()}/refund", + "POST", + $payLoad, + null, + $apiContext, + $restCall + ); $ret = new Refund(); $ret->fromJson($json); return $ret; diff --git a/lib/PayPal/Api/ShippingAddress.php b/lib/PayPal/Api/ShippingAddress.php index c331d43..c04e5f1 100644 --- a/lib/PayPal/Api/ShippingAddress.php +++ b/lib/PayPal/Api/ShippingAddress.php @@ -3,7 +3,6 @@ namespace PayPal\Api; use PayPal\Common\PPModel; -use PayPal\Rest\ApiContext; /** * Class ShippingAddress @@ -20,7 +19,6 @@ class ShippingAddress extends Address { /** * Address ID assigned in PayPal system. - * * * @param string $id * @@ -44,7 +42,6 @@ class ShippingAddress extends Address /** * Name of the recipient at this address. - * * * @param string $recipient_name * @@ -93,7 +90,6 @@ class ShippingAddress extends Address /** * Default shipping address of the Payer. - * * * @param bool $default_address * diff --git a/lib/PayPal/Api/Terms.php b/lib/PayPal/Api/Terms.php new file mode 100644 index 0000000..20582ca --- /dev/null +++ b/lib/PayPal/Api/Terms.php @@ -0,0 +1,236 @@ +id = $id; + return $this; + } + + /** + * Identifier of the terms. 128 characters max. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Term type. Allowed values: `MONTHLY`, `WEEKLY`, `YEARLY`. + * + * @param string $type + * + * @return $this + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * Term type. Allowed values: `MONTHLY`, `WEEKLY`, `YEARLY`. + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Max Amount associated with this term. + * + * @param \PayPal\Api\Currency $max_billing_amount + * + * @return $this + */ + public function setMaxBillingAmount($max_billing_amount) + { + $this->max_billing_amount = $max_billing_amount; + return $this; + } + + /** + * Max Amount associated with this term. + * + * @return \PayPal\Api\Currency + */ + public function getMaxBillingAmount() + { + return $this->max_billing_amount; + } + + /** + * Max Amount associated with this term. + * + * @deprecated Instead use setMaxBillingAmount + * + * @param \PayPal\Api\Currency $max_billing_amount + * @return $this + */ + public function setMax_billing_amount($max_billing_amount) + { + $this->max_billing_amount = $max_billing_amount; + return $this; + } + + /** + * Max Amount associated with this term. + * @deprecated Instead use getMaxBillingAmount + * + * @return \PayPal\Api\Currency + */ + public function getMax_billing_amount() + { + return $this->max_billing_amount; + } + + /** + * How many times money can be pulled during this term. + * + * @param string $occurrences + * + * @return $this + */ + public function setOccurrences($occurrences) + { + $this->occurrences = $occurrences; + return $this; + } + + /** + * How many times money can be pulled during this term. + * + * @return string + */ + public function getOccurrences() + { + return $this->occurrences; + } + + /** + * Amount_range associated with this term. + * + * @param \PayPal\Api\Currency $amount_range + * + * @return $this + */ + public function setAmountRange($amount_range) + { + $this->amount_range = $amount_range; + return $this; + } + + /** + * Amount_range associated with this term. + * + * @return \PayPal\Api\Currency + */ + public function getAmountRange() + { + return $this->amount_range; + } + + /** + * Amount_range associated with this term. + * + * @deprecated Instead use setAmountRange + * + * @param \PayPal\Api\Currency $amount_range + * @return $this + */ + public function setAmount_range($amount_range) + { + $this->amount_range = $amount_range; + return $this; + } + + /** + * Amount_range associated with this term. + * @deprecated Instead use getAmountRange + * + * @return \PayPal\Api\Currency + */ + public function getAmount_range() + { + return $this->amount_range; + } + + /** + * Buyer's ability to edit the amount in this term. + * + * @param string $buyer_editable + * + * @return $this + */ + public function setBuyerEditable($buyer_editable) + { + $this->buyer_editable = $buyer_editable; + return $this; + } + + /** + * Buyer's ability to edit the amount in this term. + * + * @return string + */ + public function getBuyerEditable() + { + return $this->buyer_editable; + } + + /** + * Buyer's ability to edit the amount in this term. + * + * @deprecated Instead use setBuyerEditable + * + * @param string $buyer_editable + * @return $this + */ + public function setBuyer_editable($buyer_editable) + { + $this->buyer_editable = $buyer_editable; + return $this; + } + + /** + * Buyer's ability to edit the amount in this term. + * @deprecated Instead use getBuyerEditable + * + * @return string + */ + public function getBuyer_editable() + { + return $this->buyer_editable; + } + +} diff --git a/lib/PayPal/Common/PPModel.php b/lib/PayPal/Common/PPModel.php index 5b6800b..770724a 100644 --- a/lib/PayPal/Common/PPModel.php +++ b/lib/PayPal/Common/PPModel.php @@ -173,7 +173,7 @@ class PPModel $this->assignValue($k, $arr); } } else { - $this->$k = $v; + $this->assignValue($k, $v); } } return $this; diff --git a/lib/PayPal/Core/PPConfigManager.php b/lib/PayPal/Core/PPConfigManager.php index 4c61b3d..96815aa 100644 --- a/lib/PayPal/Core/PPConfigManager.php +++ b/lib/PayPal/Core/PPConfigManager.php @@ -41,7 +41,9 @@ class PPConfigManager $configFile = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), "..", "config", "sdk_config.ini")); } - $this->addConfigFromIni($configFile); + if (file_exists($configFile)) { + $this->addConfigFromIni($configFile); + } } /** @@ -65,7 +67,7 @@ class PPConfigManager */ public function addConfigFromIni($fileName) { - if ($configs = @parse_ini_file($fileName)) { + if ($configs = parse_ini_file($fileName)) { $this->addConfigs($configs); } return $this; diff --git a/lib/PayPal/Core/PPConstants.php b/lib/PayPal/Core/PPConstants.php index c21253b..d9f44ae 100644 --- a/lib/PayPal/Core/PPConstants.php +++ b/lib/PayPal/Core/PPConstants.php @@ -11,8 +11,8 @@ namespace PayPal\Core; class PPConstants { - const SDK_NAME = 'rest-api-sdk-php'; - const SDK_VERSION = '0.11.0'; + const SDK_NAME = 'PayPal-PHP-SDK'; + const SDK_VERSION = '0.14.0'; const REST_SANDBOX_ENDPOINT = "https://api.sandbox.paypal.com/"; const OPENID_REDIRECT_SANDBOX_URL = "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect"; diff --git a/lib/PayPal/Core/PPCredentialManager.php b/lib/PayPal/Core/PPCredentialManager.php index c636d93..c7a46a4 100644 --- a/lib/PayPal/Core/PPCredentialManager.php +++ b/lib/PayPal/Core/PPCredentialManager.php @@ -144,7 +144,7 @@ class PPCredentialManager */ public function getCredentialObject($userId = null) { - if ($userId == null) { + if ($userId == null && array_key_exists($this->defaultAccountName, $this->credentialHashmap)) { $credObj = $this->credentialHashmap[$this->defaultAccountName]; } else if (array_key_exists($userId, $this->credentialHashmap)) { $credObj = $this->credentialHashmap[$userId]; diff --git a/lib/PayPal/Core/PPHttpConnection.php b/lib/PayPal/Core/PPHttpConnection.php index 8f0e8e9..8554686 100644 --- a/lib/PayPal/Core/PPHttpConnection.php +++ b/lib/PayPal/Core/PPHttpConnection.php @@ -107,7 +107,7 @@ class PPHttpConnection $this->logger->fine($header); } - $this->logger->fine("Payload : " . $data . "\n"); + $this->logger->fine(($data && $data != '' ? "Payload : " . $data : "No Request Payload") . "\n"); //Execute Curl Request $result = curl_exec($ch); @@ -144,6 +144,8 @@ class PPHttpConnection } //Close the curl request curl_close($ch); + + $this->logger->fine(($result && $result != '' ? "Response : " . $result : "No Response Body") . "\n\n"); //More Exceptions based on HttpStatus Code if (in_array($httpStatus, self::$retryCodes)) { $ex = new PPConnectionException( @@ -151,7 +153,6 @@ class PPHttpConnection "Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}. " . "Retried $retries times." ); - $this->logger->fine("Response : " . $result . "\n\n"); $ex->setData($result); throw $ex; } else if ($httpStatus < 200 || $httpStatus >= 300) { @@ -160,12 +161,10 @@ class PPHttpConnection "Got Http response code $httpStatus when accessing {$this->httpConfig->getUrl()}.", $httpStatus ); - $this->logger->fine("Response : " . $result . "\n\n"); $ex->setData($result); throw $ex; } - $this->logger->fine("Response : " . $result . "\n\n"); //Return result object return $result; diff --git a/lib/PayPal/Validation/ArgumentValidator.php b/lib/PayPal/Validation/ArgumentValidator.php index 2d38f8c..2aa1ad7 100644 --- a/lib/PayPal/Validation/ArgumentValidator.php +++ b/lib/PayPal/Validation/ArgumentValidator.php @@ -29,9 +29,9 @@ class ArgumentValidator ) { //Throw an Exception for string or array throw new \InvalidArgumentException("$argumentName cannot be null or empty"); - } elseif ($argument == null) { + } elseif ($argument === null) { //Generic Exception throw new \InvalidArgumentException("$argumentName cannot be null"); } } -} \ No newline at end of file +} diff --git a/release_notes.md b/release_notes.md index a283dfd..2925012 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,5 +1,9 @@ PayPal PHP SDK release notes ============================ +v0.14.0 +---- +* Enabled Billing Plans and Agreements APIs +* Renamed SDK name to PayPal-PHP-SDK v0.13.2 ---- diff --git a/sample/README.md b/sample/README.md index bda3407..cb22013 100644 --- a/sample/README.md +++ b/sample/README.md @@ -3,12 +3,12 @@ Rest API Samples This sample project is a simple web app that you can explore to understand what the payment APIs can do for you. -To try out the sample, run `composer update --no-dev` from the rest-api-sdk-php folder and you are all set. +To try out the sample, run `composer update --no-dev` from the PayPal-PHP-SDK folder and you are all set. The sample comes pre-configured with a test account but in case you need to try them against your account, you must * Obtain your client id and client secret from the developer portal - * Update the sdk_config.ini file with your new client id and secret. + * Update the bootstrap.php file with your new client id and secret. If you are looking for a full fledged application that uses the new RESTful APIs, check out the Pizza store sample app at https://github.com/paypal/rest-api-sample-app-php diff --git a/sample/billing/CreateBillingAgreementWithCreditCard.php b/sample/billing/CreateBillingAgreementWithCreditCard.php new file mode 100644 index 0000000..faab2b4 --- /dev/null +++ b/sample/billing/CreateBillingAgreementWithCreditCard.php @@ -0,0 +1,111 @@ +setName('DPRP') + ->setDescription('Payment with credit Card') + ->setStartDate('2015-06-17T9:45:04Z'); + +// Add Plan ID +// Please note that the plan Id should be only set in this case. +$plan = new Plan(); +$plan->setId($createdPlan->getId()); +$agreement->setPlan($plan); + +// Add Payer +$payer = new Payer(); +$payer->setPaymentMethod('credit_card') + ->setPayerInfo(new PayerInfo(['email' => 'jaypatel512-facilitator@hotmail.com'])); + +// Add Credit Card to Funding Instruments +$creditCard = new CreditCard(); +$creditCard->setType('visa') + ->setNumber('4417119669820331') + ->setExpireMonth('12') + ->setExpireYear('2017') + ->setCvv2('128'); + +$fundingInstrument = new FundingInstrument(); +$fundingInstrument->setCreditCard($creditCard); +$payer->setFundingInstruments(array($fundingInstrument)); +//Add Payer to Agreement +$agreement->setPayer($payer); + +// Add Shipping Address +$shippingAddress = new ShippingAddress(); +$shippingAddress->setLine1('111 First Street') + ->setCity('Saratoga') + ->setState('CA') + ->setPostalCode('95070') + ->setCountryCode('US'); +$agreement->setShippingAddress($shippingAddress); + +// For Sample Purposes Only. +$request = clone $agreement; + +// ### Create Agreement +try { + // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet. + $agreement = $agreement->create($apiContext); + +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Created Billing Agreement.", "Agreement", $agreement->getId(), $request, $agreement); + +return $agreement; diff --git a/sample/billing/CreateBillingAgreementWithPayPal.php b/sample/billing/CreateBillingAgreementWithPayPal.php new file mode 100644 index 0000000..8363df1 --- /dev/null +++ b/sample/billing/CreateBillingAgreementWithPayPal.php @@ -0,0 +1,91 @@ +setName('Base Agreement') + ->setDescription('Basic Agreement') + ->setStartDate('2015-06-17T9:45:04Z'); + +// Add Plan ID +// Please note that the plan Id should be only set in this case. +$plan = new Plan(); +$plan->setId($createdPlan->getId()); +$agreement->setPlan($plan); + +// Add Payer +$payer = new Payer(); +$payer->setPaymentMethod('paypal'); +$agreement->setPayer($payer); + +// Add Shipping Address +$shippingAddress = new ShippingAddress(); +$shippingAddress->setLine1('111 First Street') + ->setCity('Saratoga') + ->setState('CA') + ->setPostalCode('95070') + ->setCountryCode('US'); +$agreement->setShippingAddress($shippingAddress); + +// For Sample Purposes Only. +$request = clone $agreement; + +// ### Create Agreement +try { + // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet. + $agreement = $agreement->create($apiContext); + + // ### Get redirect url + // The API response provides the url that you must redirect + // the buyer to. Retrieve the url from the $agreement->getLinks() + // method + foreach ($agreement->getLinks() as $link) { + if ($link->getRel() == 'approval_url') { + $approvalUrl = $link->getHref(); + break; + } + } + +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Created Billing Agreement. Please visit the URL to Approve.", "Agreement", "$approvalUrl", $request, $agreement); + +return $agreement; diff --git a/sample/billing/CreatePlan.php b/sample/billing/CreatePlan.php new file mode 100644 index 0000000..4248874 --- /dev/null +++ b/sample/billing/CreatePlan.php @@ -0,0 +1,72 @@ +setName('T-Shirt of the Month Club Plan') + ->setDescription('Template creation.') + ->setType('fixed'); + +// # Payment definitions for this billing plan. +$paymentDefinition = new PaymentDefinition(); + +// The possible values for such setters are mentioned in the setter method documentation. +// Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method. +// You should be able to see the acceptable values in the comments. +$paymentDefinition->setName('Regular Payments') + ->setType('REGULAR') + ->setFrequency('Month') + ->setFrequencyInterval("2") + ->setCycles("12") + ->setAmount(new Currency(['value' => '100', 'currency' => 'USD'])); + +// Charge Models +$chargeModel = new ChargeModel(); +$chargeModel->setType('SHIPPING') + ->setAmount(new Currency(['value' => '10', 'currency' => 'USD'])); + +$paymentDefinition->setChargeModels(array($chargeModel)); + +$merchantPreferences = new MerchantPreferences(); +$baseUrl = getBaseUrl(); +$merchantPreferences->setReturnUrl("$baseUrl/ExecuteAgreement.php?success=true") + ->setCancelUrl("$baseUrl/ExecuteAgreement.php?success=false") + ->setAutoBillAmount("YES") + ->setInitialFailAmountAction("CONTINUE") + ->setMaxFailAttempts("0") + ->setSetupFee(new Currency(['value' => '1', 'currency' => 'USD'])); + + +$plan->setPaymentDefinitions(array($paymentDefinition)); +$plan->setMerchantPreferences($merchantPreferences); + +// For Sample Purposes Only. +$request = clone $plan; + +// ### Create Plan +try { + $output = $plan->create($apiContext); +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Created Plan", "Plan", $output->getId(), $request, $output); + +return $output; diff --git a/sample/billing/ExecuteAgreement.php b/sample/billing/ExecuteAgreement.php new file mode 100644 index 0000000..1f3cc71 --- /dev/null +++ b/sample/billing/ExecuteAgreement.php @@ -0,0 +1,22 @@ +execute($token, $apiContext); + } catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); + } + ResultPrinter::printResult("Executed an Agreement", "Agreement", $agreement->getId(), $_GET['token'], $agreement); + +} else { + ResultPrinter::printResult("User Cancelled the Approval", null); +} diff --git a/sample/billing/GetBillingAgreement.php b/sample/billing/GetBillingAgreement.php new file mode 100644 index 0000000..336678f --- /dev/null +++ b/sample/billing/GetBillingAgreement.php @@ -0,0 +1,25 @@ + + +// Retrieving the Agreement object from Create Agreement From Credit Card Sample +/** @var Agreement $createdAgreement */ +$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php'; + +use PayPal\Api\Agreement; + +try { + $agreement = Agreement::get($createdAgreement->getId(), $apiContext); +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Retrieved an Agreement", "Agreement", $agreement->getId(), $createdAgreement->getId(), $agreement); + +return $agreement; diff --git a/sample/billing/GetPlan.php b/sample/billing/GetPlan.php new file mode 100644 index 0000000..ceeec77 --- /dev/null +++ b/sample/billing/GetPlan.php @@ -0,0 +1,25 @@ +getId(), $apiContext); +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Retrieved a Plan", "Plan", $plan->getId(), null, $plan); + +return $plan; diff --git a/sample/billing/ListPlans.php b/sample/billing/ListPlans.php new file mode 100644 index 0000000..972ff7f --- /dev/null +++ b/sample/billing/ListPlans.php @@ -0,0 +1,30 @@ + '2'); + $planList = Plan::all($params, $apiContext); +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("List of Plans", "Plan", null, $params, $planList); + +return $planList; diff --git a/sample/billing/ReactivateBillingAgreement.php b/sample/billing/ReactivateBillingAgreement.php new file mode 100644 index 0000000..d56ad35 --- /dev/null +++ b/sample/billing/ReactivateBillingAgreement.php @@ -0,0 +1,35 @@ +/suspend + +// Retrieving the Agreement object from Suspend Agreement Sample to demonstrate the List +/** @var Agreement $suspendedAgreement */ +$suspendedAgreement = require 'SuspendBillingAgreement.php'; + +use PayPal\Api\Agreement; +use PayPal\Api\AgreementStateDescriptor; + +//Create an Agreement State Descriptor, explaining the reason to suspend. +$agreementStateDescriptor = new AgreementStateDescriptor(); +$agreementStateDescriptor->setNote("Reactivating the agreement"); + +try { + + $suspendedAgreement->reActivate($agreementStateDescriptor, $apiContext); + + // Lets get the updated Agreement Object + $agreement = Agreement::get($suspendedAgreement->getId(), $apiContext); + +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Reactivate the Agreement", "Agreement", $agreement->getId(), $suspendedAgreement, $agreement); + +return $agreement; diff --git a/sample/billing/SuspendBillingAgreement.php b/sample/billing/SuspendBillingAgreement.php new file mode 100644 index 0000000..e56f289 --- /dev/null +++ b/sample/billing/SuspendBillingAgreement.php @@ -0,0 +1,35 @@ +/suspend + +// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List +/** @var Agreement $createdAgreement */ +$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php'; + +use PayPal\Api\Agreement; +use PayPal\Api\AgreementStateDescriptor; + +//Create an Agreement State Descriptor, explaining the reason to suspend. +$agreementStateDescriptor = new AgreementStateDescriptor(); +$agreementStateDescriptor->setNote("Suspending the agreement"); + +try { + + $createdAgreement->suspend($agreementStateDescriptor, $apiContext); + + // Lets get the updated Agreement Object + $agreement = Agreement::get($createdAgreement->getId(), $apiContext); + +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Suspended the Agreement", "Agreement", $agreement->getId(), $agreementStateDescriptor, $agreement); + +return $agreement; diff --git a/sample/billing/UpdateBillingAgreement.php b/sample/billing/UpdateBillingAgreement.php new file mode 100644 index 0000000..7c28fe2 --- /dev/null +++ b/sample/billing/UpdateBillingAgreement.php @@ -0,0 +1,47 @@ + + +// Retrieving the Agreement object from Create Agreement Sample to demonstrate the List +/** @var Agreement $createdAgreement */ +$createdAgreement = require 'CreateBillingAgreementWithCreditCard.php'; + +use PayPal\Api\Agreement; +use PayPal\Api\PatchRequest; +use PayPal\Api\Patch; + +$patch = new Patch(); + +$patch->setOp('replace') + ->setPath('/') + ->setValue(json_decode('{ + "description": "New Description", + "shipping_address": { + "line1": "2065 Hamilton Ave", + "city": "San Jose", + "state": "CA", + "postal_code": "95125", + "country_code": "US" + } + }')); +$patchRequest = new PatchRequest(); +$patchRequest->addPatch($patch); +try { + $createdAgreement->update($patchRequest, $apiContext); + + // Lets get the updated Agreement Object + $agreement = Agreement::get($createdAgreement->getId(), $apiContext); + +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Updated the Agreement with new Description and Updated Shipping Address", "Agreement", $agreement->getId(), $patchRequest, $agreement); + +return $agreement; diff --git a/sample/billing/UpdatePlan.php b/sample/billing/UpdatePlan.php new file mode 100644 index 0000000..9e2364e --- /dev/null +++ b/sample/billing/UpdatePlan.php @@ -0,0 +1,45 @@ + + +// ### Making Plan Active +// This example demonstrate how you could activate the Plan. + +// Retrieving the Plan object from Create Plan Sample to demonstrate the List +/** @var Plan $createdPlan */ +$createdPlan = require 'CreatePlan.php'; + +use PayPal\Api\Plan; +use PayPal\Api\PatchRequest; +use PayPal\Api\Patch; +use PayPal\Common\PPModel; +try { + $patch = new Patch(); + + $value = new PPModel('{ + "state":"ACTIVE" + }'); + + $patch->setOp('replace') + ->setPath('/') + ->setValue($value); + $patchRequest = new PatchRequest(); + $patchRequest->addPatch($patch); + + $createdPlan->update($patchRequest, $apiContext); + + $plan = Plan::get($createdPlan->getId(), $apiContext); + +} catch (PayPal\Exception\PPConnectionException $ex) { + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); +} + +ResultPrinter::printResult("Updated the Plan to Active State", "Plan", $plan->getId(), $patchRequest, $plan); + +return $plan; diff --git a/sample/common.php b/sample/common.php index a623ac6..ae7db11 100644 --- a/sample/common.php +++ b/sample/common.php @@ -12,25 +12,80 @@ use PayPal\Api\Payment; use PayPal\Api\Transaction; use PayPal\Api\FundingInstrument; +/** + * Helper Class for Printing Results + * + * Class ResultPrinter + */ +class ResultPrinter { -function print_result($title, $objectName, $objectId = null, $output = null) -{ - echo "
" . $output->toJSON(128) . ""; - } elseif (is_string($output)) { - echo "
$output"; + protected static function printObject($object) + { + if ($object) { + if (is_a($object, 'PayPal\Common\PPModel')) { + /** @var $object \PayPal\Common\PPModel */ + echo '
' . $object->toJSON(128) . ""; + } elseif (is_string($object)) { + echo "
$object"; + } else { + echo "
"; + print_r($object); + echo ""; + } + } else { + echo "No Data"; } } - echo "
Retrieving the Plan from the Create Update Sample. This would be used to +define Plan information to create an agreement. Make sure the plan you are using is in active state.
Add Plan ID +Please note that the plan Id should be only set in this case.
Add Payer
Add Credit Card to Funding Instruments
Add Shipping Address
For Sample Purposes Only.
Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
This sample code demonstrate how you can create a billing agreement, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement +API used: /v1/payments/billing-agreements
Retrieving the Plan from the Create Update Sample. This would be used to +define Plan information to create an agreement. Make sure the plan you are using is in active state.
Add Plan ID +Please note that the plan Id should be only set in this case.
Add Payer
Add Shipping Address
For Sample Purposes Only.
Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
The API response provides the url that you must redirect +the buyer to. Retrieve the url from the $agreement->getLinks() +method
This sample code demonstrate how you can create a billing plan, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#create-a-plan +API used: /v1/payments/billing-plans
Create a new instance of Plan object
Fill up the basic information that is required for the plan
The possible values for such setters are mentioned in the setter method documentation. +Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method. +You should be able to see the acceptable values in the comments.
Charge Models
For Sample Purposes Only.
This sample code demonstrate how you can get a billing agreement, as documented here at:
+https://developer.paypal.com/webapps/developer/docs/api/#retrieve-an-agreement
+API used: /v1/payments/billing-agreements/
Retrieving the Agreement object from Create Agreement From Credit Card Sample
This sample code demonstrate how you can get a billing plan, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#retrieve-a-plan +API used: /v1/payments/billing-plans
Retrieving the Plan object from Create Plan Sample
This sample code demonstrate how you can get a list of billing plan, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#list-plans +API used: /v1/payments/billing-plans
Retrieving the Plan object from Create Plan Sample to demonstrate the List
Get the list of all plans +You can modify different params to change the return list. +The explanation about each pagination information could be found here +at https://developer.paypal.com/webapps/developer/docs/api/#list-plans
This sample code demonstrate how you can reactivate a billing agreement, as documented here at:
+https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement
+API used: /v1/payments/billing-agreements/
Retrieving the Agreement object from Suspend Agreement Sample to demonstrate the List
Lets get the updated Agreement Object
This sample code demonstrate how you can suspend a billing agreement, as documented here at:
+https://developer.paypal.com/webapps/developer/docs/api/#suspend-an-agreement
+API used: /v1/payments/billing-agreements/
Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
Lets get the updated Agreement Object
This sample code demonstrate how you can update a billing agreement, as documented here at:
+https://developer.paypal.com/webapps/developer/docs/api/#update-an-agreement
+API used: /v1/payments/billing-agreements/
Retrieving the Agreement object from Create Agreement Sample to demonstrate the List
Lets get the updated Agreement Object
This sample code demonstrate how you can update a billing plan, as documented here at:
+https://developer.paypal.com/webapps/developer/docs/api/#update-a-plan
+API used: /v1/payments/billing-plans/
This example demonstrate how you could activate the Plan.
Retrieving the Plan object from Create Plan Sample to demonstrate the List
Create Billing Agreement with Credit Card as Payment Source
+This sample code demonstrate how you can create a billing agreement, as documented here at: +https://developer.paypal.com/webapps/developer/docs/api/#create-an-agreement +API used: /v1/payments/billing-agreements