From 4d481ad104b0bbd314d9a358b527841b13956e0f Mon Sep 17 00:00:00 2001 From: japatel Date: Fri, 31 Oct 2014 10:16:13 -0500 Subject: [PATCH] Enabled Billing Plans and Agreements APIs - Added API Classes, Samples, and Tests - Updated Functional Tests - Updated Documentation with new SDK Name - Updated Few Samples to use newer nicer result page --- README.md | 15 +- lib/PayPal/Api/Address.php | 8 - lib/PayPal/Api/Agreement.php | 832 ++++++++++++++++++ lib/PayPal/Api/AgreementDetails.php | 409 +++++++++ lib/PayPal/Api/AgreementStateDescriptor.php | 65 ++ lib/PayPal/Api/AgreementTransaction.php | 457 ++++++++++ lib/PayPal/Api/AgreementTransactions.php | 96 ++ lib/PayPal/Api/BankAccount.php | 171 ++-- lib/PayPal/Api/BankAccountsList.php | 38 +- lib/PayPal/Api/BankToken.php | 4 - lib/PayPal/Api/ChargeModel.php | 89 ++ lib/PayPal/Api/Credit.php | 13 +- lib/PayPal/Api/CreditCard.php | 161 ++-- lib/PayPal/Api/CreditCardList.php | 38 +- lib/PayPal/Api/CreditCardToken.php | 23 +- lib/PayPal/Api/Currency.php | 26 +- lib/PayPal/Api/ExtendedBankAccount.php | 2 - lib/PayPal/Api/FundingInstrument.php | 8 - lib/PayPal/Api/HyperSchema.php | 41 +- lib/PayPal/Api/Links.php | 7 - lib/PayPal/Api/MerchantPreferences.php | 486 ++++++++++ lib/PayPal/Api/OverrideChargeModel.php | 90 ++ lib/PayPal/Api/Patch.php | 5 +- lib/PayPal/Api/PatchRequest.php | 86 ++ lib/PayPal/Api/Payer.php | 66 +- lib/PayPal/Api/PayerInfo.php | 18 +- lib/PayPal/Api/Payment.php | 67 +- lib/PayPal/Api/PaymentCard.php | 80 +- lib/PayPal/Api/PaymentCardToken.php | 24 +- lib/PayPal/Api/PaymentDefinition.php | 289 ++++++ lib/PayPal/Api/Plan.php | 577 ++++++++++++ lib/PayPal/Api/PlanList.php | 223 +++++ lib/PayPal/Api/Sale.php | 37 +- lib/PayPal/Api/ShippingAddress.php | 4 - lib/PayPal/Api/Terms.php | 236 +++++ lib/PayPal/Common/PPModel.php | 2 +- lib/PayPal/Core/PPConfigManager.php | 6 +- lib/PayPal/Core/PPConstants.php | 4 +- lib/PayPal/Core/PPCredentialManager.php | 2 +- lib/PayPal/Core/PPHttpConnection.php | 7 +- lib/PayPal/Validation/ArgumentValidator.php | 4 +- release_notes.md | 4 + sample/README.md | 4 +- .../CreateBillingAgreementWithCreditCard.php | 111 +++ .../CreateBillingAgreementWithPayPal.php | 91 ++ sample/billing/CreatePlan.php | 72 ++ sample/billing/ExecuteAgreement.php | 22 + sample/billing/GetBillingAgreement.php | 25 + sample/billing/GetPlan.php | 25 + sample/billing/ListPlans.php | 30 + sample/billing/ReactivateBillingAgreement.php | 35 + sample/billing/SuspendBillingAgreement.php | 35 + sample/billing/UpdateBillingAgreement.php | 47 + sample/billing/UpdatePlan.php | 45 + sample/common.php | 81 +- sample/doc/assets/behavior.js | 387 ++++++++ .../CreateBillingAgreementWithCreditCard.html | 85 ++ .../CreateBillingAgreementWithPayPal.html | 65 ++ sample/doc/billing/CreatePlan.html | 46 + sample/doc/billing/ExecuteAgreement.html | 22 + sample/doc/billing/GetBillingAgreement.html | 19 + sample/doc/billing/GetPlan.html | 19 + sample/doc/billing/ListPlans.html | 22 + .../billing/ReactivateBillingAgreement.html | 26 + .../doc/billing/SuspendBillingAgreement.html | 26 + .../doc/billing/UpdateBillingAgreement.html | 38 + sample/doc/billing/UpdatePlan.html | 37 + sample/doc/invoice/CancelInvoice.html | 13 +- sample/doc/invoice/CreateInvoice.html | 18 +- sample/doc/invoice/GetInvoice.html | 13 +- sample/doc/invoice/ListInvoice.html | 12 +- sample/doc/invoice/RemindInvoice.html | 13 +- sample/doc/invoice/SendInvoice.html | 12 +- .../GenerateAccessTokenFromRefreshToken.html | 2 +- sample/doc/lipp/GetUserInfo.html | 2 +- sample/doc/lipp/ObtainUserConsent.html | 2 +- sample/doc/lipp/UserConsentRedirect.html | 2 +- .../payment-experience/CreateWebProfile.html | 4 +- .../payment-experience/DeleteWebProfile.html | 2 +- .../doc/payment-experience/GetWebProfile.html | 2 +- .../payment-experience/ListWebProfiles.html | 6 +- .../PartiallyUpdateWebProfile.html | 2 +- .../payment-experience/UpdateWebProfile.html | 2 +- sample/doc/payments/AuthorizationCapture.html | 4 +- sample/doc/payments/CreateFuturePayment.html | 4 +- sample/doc/payments/CreatePayment.html | 4 +- .../payments/CreatePaymentUsingPayPal.html | 12 +- .../payments/CreatePaymentUsingSavedCard.html | 4 +- sample/doc/payments/ExecutePayment.html | 30 +- sample/doc/payments/GetAuthorization.html | 4 +- sample/doc/payments/GetCapture.html | 4 +- sample/doc/payments/GetPayment.html | 4 +- sample/doc/payments/ListPayments.html | 4 +- sample/doc/payments/Reauthorization.html | 4 +- sample/doc/payments/RefundCapture.html | 4 +- sample/doc/payments/VoidAuthorization.html | 4 +- sample/doc/sale/GetSale.html | 4 +- sample/doc/sale/RefundSale.html | 4 +- sample/doc/vault/CreateCreditCard.html | 4 +- sample/doc/vault/GetCreditCard.html | 4 +- sample/header.html | 82 ++ sample/index.html | 117 ++- sample/invoice/CancelInvoice.php | 13 +- sample/invoice/CreateInvoice.php | 20 +- sample/invoice/GetInvoice.php | 13 +- sample/invoice/ListInvoice.php | 12 +- sample/invoice/RemindInvoice.php | 12 +- sample/invoice/SendInvoice.php | 12 +- .../GenerateAccessTokenFromRefreshToken.php | 2 +- sample/lipp/GetUserInfo.php | 2 +- sample/lipp/ObtainUserConsent.php | 2 +- sample/lipp/UserConsentRedirect.php | 2 +- .../payment-experience/CreateWebProfile.php | 5 +- .../payment-experience/DeleteWebProfile.php | 2 +- sample/payment-experience/GetWebProfile.php | 2 +- sample/payment-experience/ListWebProfiles.php | 2 +- .../PartiallyUpdateWebProfile.php | 2 +- .../payment-experience/UpdateWebProfile.php | 2 +- sample/payments/CreatePaymentUsingPayPal.php | 9 - sample/payments/ExecutePayment.php | 46 +- tests/PayPal/Test/Api/AddressTest.php | 129 ++- .../Test/Api/AgreementStateDescriptorTest.php | 80 ++ tests/PayPal/Test/Api/AgreementTest.php | 367 ++++++++ .../Test/Api/AgreementTransactionTest.php | 168 ++++ .../Test/Api/AgreementTransactionsTest.php | 87 ++ tests/PayPal/Test/Api/AuthorizationTest.php | 2 +- tests/PayPal/Test/Api/BankAccountTest.php | 404 +++++++++ .../PayPal/Test/Api/BankAccountsListTest.php | 100 +++ tests/PayPal/Test/Api/BankTokenTest.php | 109 +++ tests/PayPal/Test/Api/CaptureTest.php | 6 +- tests/PayPal/Test/Api/ChargeModelTest.php | 82 ++ .../PayPal/Test/Api/CreditCardHistoryTest.php | 6 +- tests/PayPal/Test/Api/CreditCardListTest.php | 100 +++ tests/PayPal/Test/Api/CreditCardTest.php | 350 ++++++-- tests/PayPal/Test/Api/CreditCardTokenTest.php | 131 ++- tests/PayPal/Test/Api/CreditTest.php | 82 ++ tests/PayPal/Test/Api/CurrencyTest.php | 80 ++ .../Test/Api/ExtendedBankAccountTest.php | 87 ++ .../PayPal/Test/Api/FundingInstrumentTest.php | 147 +++- tests/PayPal/Test/Api/HyperSchemaTest.php | 88 ++ tests/PayPal/Test/Api/ItemListTest.php | 4 +- tests/PayPal/Test/Api/LinksTest.php | 95 +- .../Test/Api/MerchantPreferencesTest.php | 198 +++++ .../Test/Api/OverrideChargeModelTest.php | 89 ++ tests/PayPal/Test/Api/PatchRequestTest.php | 77 ++ tests/PayPal/Test/Api/PatchTest.php | 2 +- tests/PayPal/Test/Api/PayerInfoTest.php | 220 ++++- tests/PayPal/Test/Api/PayerTest.php | 134 ++- tests/PayPal/Test/Api/PaymentCardTest.php | 187 ++++ .../PayPal/Test/Api/PaymentCardTokenTest.php | 124 +++ .../PayPal/Test/Api/PaymentDefinitionTest.php | 110 +++ tests/PayPal/Test/Api/PaymentTest.php | 22 +- tests/PayPal/Test/Api/PlanListTest.php | 102 +++ tests/PayPal/Test/Api/PlanTest.php | 227 +++++ tests/PayPal/Test/Api/RefundTest.php | 5 +- tests/PayPal/Test/Api/SaleTest.php | 31 +- tests/PayPal/Test/Api/ShippingAddressTest.php | 125 ++- tests/PayPal/Test/Api/TermsTest.php | 115 +++ .../Api/BillingAgreementsFunctionalTest.php | 246 ++++++ .../Api/BillingPlansFunctionalTest.php | 217 +++++ .../Functional/Api/PaymentsFunctionalTest.php | 146 +++ ...eTest.php => WebProfileFunctionalTest.php} | 2 +- .../testBillBalance.json | 34 + .../testCancel.json | 30 + .../testCreateCCAgreement.json | 69 ++ .../testCreatePayPalAgreement.json | 141 +++ .../testCreateWithOverride.json | 170 ++++ .../testExecute.json | 37 + .../testGet.json | 140 +++ .../testGetCancelled.json | 140 +++ .../testGetSuspended.json | 140 +++ .../testGetTransactions.json | 67 ++ .../testReactivate.json | 30 + .../testSetBalance.json | 31 + .../testSuspend.json | 30 + .../testUpdate.json | 46 + .../testCreate.json | 186 ++++ .../testCreateWithNOChargeModel.json | 93 ++ .../BillingPlansFunctionalTest/testGet.json | 116 +++ .../testGetList.json | 87 ++ ...testUpdateChangingMerchantPreferences.json | 40 + .../testUpdateChangingPD.json | 41 + .../testUpdateChangingState.json | 39 + .../PaymentsFunctionalTest/testCreate.json | 148 ++++ .../testCreateWallet.json | 177 ++++ .../PaymentsFunctionalTest/testExecute.json | 98 +++ .../PaymentsFunctionalTest/testGet.json | 109 +++ .../testGetPending.json | 100 +++ .../PaymentsFunctionalTest/testGetSale.json | 60 ++ .../testRefundSale.json | 62 ++ tests/bootstrap.php | 2 +- tests/sdk_config.ini | 6 +- 192 files changed, 13310 insertions(+), 1045 deletions(-) create mode 100644 lib/PayPal/Api/Agreement.php create mode 100644 lib/PayPal/Api/AgreementDetails.php create mode 100644 lib/PayPal/Api/AgreementStateDescriptor.php create mode 100644 lib/PayPal/Api/AgreementTransaction.php create mode 100644 lib/PayPal/Api/AgreementTransactions.php create mode 100644 lib/PayPal/Api/ChargeModel.php create mode 100644 lib/PayPal/Api/MerchantPreferences.php create mode 100644 lib/PayPal/Api/OverrideChargeModel.php create mode 100644 lib/PayPal/Api/PatchRequest.php create mode 100644 lib/PayPal/Api/PaymentDefinition.php create mode 100644 lib/PayPal/Api/Plan.php create mode 100644 lib/PayPal/Api/PlanList.php create mode 100644 lib/PayPal/Api/Terms.php create mode 100644 sample/billing/CreateBillingAgreementWithCreditCard.php create mode 100644 sample/billing/CreateBillingAgreementWithPayPal.php create mode 100644 sample/billing/CreatePlan.php create mode 100644 sample/billing/ExecuteAgreement.php create mode 100644 sample/billing/GetBillingAgreement.php create mode 100644 sample/billing/GetPlan.php create mode 100644 sample/billing/ListPlans.php create mode 100644 sample/billing/ReactivateBillingAgreement.php create mode 100644 sample/billing/SuspendBillingAgreement.php create mode 100644 sample/billing/UpdateBillingAgreement.php create mode 100644 sample/billing/UpdatePlan.php create mode 100644 sample/doc/billing/CreateBillingAgreementWithCreditCard.html create mode 100644 sample/doc/billing/CreateBillingAgreementWithPayPal.html create mode 100644 sample/doc/billing/CreatePlan.html create mode 100644 sample/doc/billing/ExecuteAgreement.html create mode 100644 sample/doc/billing/GetBillingAgreement.html create mode 100644 sample/doc/billing/GetPlan.html create mode 100644 sample/doc/billing/ListPlans.html create mode 100644 sample/doc/billing/ReactivateBillingAgreement.html create mode 100644 sample/doc/billing/SuspendBillingAgreement.html create mode 100644 sample/doc/billing/UpdateBillingAgreement.html create mode 100644 sample/doc/billing/UpdatePlan.html create mode 100644 sample/header.html create mode 100644 tests/PayPal/Test/Api/AgreementStateDescriptorTest.php create mode 100644 tests/PayPal/Test/Api/AgreementTest.php create mode 100644 tests/PayPal/Test/Api/AgreementTransactionTest.php create mode 100644 tests/PayPal/Test/Api/AgreementTransactionsTest.php create mode 100644 tests/PayPal/Test/Api/BankAccountTest.php create mode 100644 tests/PayPal/Test/Api/BankAccountsListTest.php create mode 100644 tests/PayPal/Test/Api/BankTokenTest.php create mode 100644 tests/PayPal/Test/Api/ChargeModelTest.php create mode 100644 tests/PayPal/Test/Api/CreditCardListTest.php create mode 100644 tests/PayPal/Test/Api/CreditTest.php create mode 100644 tests/PayPal/Test/Api/CurrencyTest.php create mode 100644 tests/PayPal/Test/Api/ExtendedBankAccountTest.php create mode 100644 tests/PayPal/Test/Api/HyperSchemaTest.php create mode 100644 tests/PayPal/Test/Api/MerchantPreferencesTest.php create mode 100644 tests/PayPal/Test/Api/OverrideChargeModelTest.php create mode 100644 tests/PayPal/Test/Api/PatchRequestTest.php create mode 100644 tests/PayPal/Test/Api/PaymentCardTest.php create mode 100644 tests/PayPal/Test/Api/PaymentCardTokenTest.php create mode 100644 tests/PayPal/Test/Api/PaymentDefinitionTest.php create mode 100644 tests/PayPal/Test/Api/PlanListTest.php create mode 100644 tests/PayPal/Test/Api/PlanTest.php create mode 100644 tests/PayPal/Test/Api/TermsTest.php create mode 100644 tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php create mode 100644 tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php create mode 100644 tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php rename tests/PayPal/Test/Functional/Api/{WebProfileTest.php => WebProfileFunctionalTest.php} (99%) create mode 100644 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testBillBalance.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCancel.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreateCCAgreement.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreatePayPalAgreement.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testCreateWithOverride.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testExecute.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testGet.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testGetCancelled.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testGetSuspended.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testGetTransactions.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testReactivate.json create mode 100644 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testSetBalance.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testSuspend.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingAgreementsFunctionalTest/testUpdate.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testCreate.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testCreateWithNOChargeModel.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testGet.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testGetList.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testUpdateChangingMerchantPreferences.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testUpdateChangingPD.json create mode 100755 tests/PayPal/Test/Functional/resources/BillingPlansFunctionalTest/testUpdateChangingState.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testCreate.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testCreateWallet.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testExecute.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testGet.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testGetPending.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testGetSale.json create mode 100644 tests/PayPal/Test/Functional/resources/PaymentsFunctionalTest/testRefundSale.json 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 -[![Build Status](https://travis-ci.org/paypal/rest-api-sdk-php.png?branch=master)](https://travis-ci.org/paypal/rest-api-sdk-php) [![Coverage Status](https://coveralls.io/repos/paypal/rest-api-sdk-php/badge.png?branch=master)](https://coveralls.io/r/paypal/rest-api-sdk-php?branch=master) [![Latest Stable Version](https://poser.pugx.org/paypal/rest-api-sdk-php/v/stable.png)](https://packagist.org/packages/paypal/rest-api-sdk-php) [![Total Downloads](https://poser.pugx.org/paypal/rest-api-sdk-php/downloads.png)](https://packagist.org/packages/paypal/rest-api-sdk-php) +[![Build Status](https://travis-ci.org/paypal/PayPal-PHP-SDK.png?branch=master)](https://travis-ci.org/paypal/PayPal-PHP-SDK) [![Coverage Status](https://img.shields.io/coveralls/paypal/PayPal-PHP-SDK.svg)](https://coveralls.io/r/paypal/PayPal-PHP-SDK?branch=master) [![Latest Stable Version](https://poser.pugx.org/paypal/rest-api-sdk-php/v/stable.png)](https://packagist.org/packages/paypal/rest-api-sdk-php) [![Total Downloads](https://poser.pugx.org/paypal/rest-api-sdk-php/downloads.png)](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) -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/paypal/rest-api-sample-app-php/trend.png)](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 "

$title

"; + private static $printResultCounter = 0; - if ($objectId) { - echo "
Created " . ($objectName ? $objectName : "Object") . " with ID: $objectId
"; + public static function printResult($title, $objectName, $objectId = null, $request = null, $response = null) + { + if (self::$printResultCounter == 0) { + include "header.html"; + echo '
+
+
'; + echo '
'; + } + self::$printResultCounter++; + echo ' +
+ +
+
+ '; + + if ($objectId) { + echo '
' . ($objectName ? $objectName : "Object") . " with ID: $objectId
"; + } + + echo ''; + + echo '
+
+
'; + + flush(); } - if ($output) { - if (is_a($output, 'PayPal\Common\PPModel')) { - /** @var $output \PayPal\Common\PPModel */ - 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 "
"; - } /** diff --git a/sample/doc/assets/behavior.js b/sample/doc/assets/behavior.js index 1188e5c..9cc263e 100644 --- a/sample/doc/assets/behavior.js +++ b/sample/doc/assets/behavior.js @@ -6,6 +6,393 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 tableOfContents = [ { + "type": "folder", + "data": { + "path": "billing", + "title": "billing" + }, + "depth": 1, + "children": [ + { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/CreateBillingAgreementWithCreditCard.php", + "projectPath": "billing/CreateBillingAgreementWithCreditCard.php", + "targetPath": "billing/CreateBillingAgreementWithCreditCard", + "pageTitle": "billing/CreateBillingAgreementWithCreditCard", + "title": "CreateBillingAgreementWithCreditCard" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Billing Agreement with Credit Card as Payment Source", + "slug": "create-billing-agreement-with-credit-card-as-payment-source" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Agreement", + "slug": "create-agreement" + }, + "depth": 3 + } + ] + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/CreateBillingAgreementWithPayPal.php", + "projectPath": "billing/CreateBillingAgreementWithPayPal.php", + "targetPath": "billing/CreateBillingAgreementWithPayPal", + "pageTitle": "billing/CreateBillingAgreementWithPayPal", + "title": "CreateBillingAgreementWithPayPal" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Billing Agreement with PayPal as Payment Source", + "slug": "create-billing-agreement-with-paypal-as-payment-source" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Agreement", + "slug": "create-agreement" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Get redirect url", + "slug": "get-redirect-url" + }, + "depth": 3 + } + ] + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/CreatePlan.php", + "projectPath": "billing/CreatePlan.php", + "targetPath": "billing/CreatePlan", + "pageTitle": "billing/CreatePlan", + "title": "CreatePlan" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Create Plan Sample", + "slug": "create-plan-sample" + }, + "depth": 1 + }, { + "type": "heading", + "data": { + "level": 1, + "title": "Basic Information", + "slug": "basic-information" + }, + "depth": 1 + }, { + "type": "heading", + "data": { + "level": 1, + "title": "Payment definitions for this billing plan.", + "slug": "payment-definitions-for-this-billing-plan" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Create Plan", + "slug": "create-plan" + }, + "depth": 3 + } + ] + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/ExecuteAgreement.php", + "projectPath": "billing/ExecuteAgreement.php", + "targetPath": "billing/ExecuteAgreement", + "pageTitle": "billing/ExecuteAgreement", + "title": "ExecuteAgreement" + }, + "depth": 2, + "outline": [] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/GetBillingAgreement.php", + "projectPath": "billing/GetBillingAgreement.php", + "targetPath": "billing/GetBillingAgreement", + "pageTitle": "billing/GetBillingAgreement", + "title": "GetBillingAgreement" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get Billing Agreement Sample", + "slug": "get-billing-agreement-sample" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/GetPlan.php", + "projectPath": "billing/GetPlan.php", + "targetPath": "billing/GetPlan", + "pageTitle": "billing/GetPlan", + "title": "GetPlan" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get Plan Sample", + "slug": "get-plan-sample" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/ListPlans.php", + "projectPath": "billing/ListPlans.php", + "targetPath": "billing/ListPlans", + "pageTitle": "billing/ListPlans", + "title": "ListPlans" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Get List of Plan Sample", + "slug": "get-list-of-plan-sample" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/ReactivateBillingAgreement.php", + "projectPath": "billing/ReactivateBillingAgreement.php", + "targetPath": "billing/ReactivateBillingAgreement", + "pageTitle": "billing/ReactivateBillingAgreement", + "title": "ReactivateBillingAgreement" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Reactivate an agreement", + "slug": "reactivate-an-agreement" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/SuspendBillingAgreement.php", + "projectPath": "billing/SuspendBillingAgreement.php", + "targetPath": "billing/SuspendBillingAgreement", + "pageTitle": "billing/SuspendBillingAgreement", + "title": "SuspendBillingAgreement" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Suspend an agreement", + "slug": "suspend-an-agreement" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/UpdateBillingAgreement.php", + "projectPath": "billing/UpdateBillingAgreement.php", + "targetPath": "billing/UpdateBillingAgreement", + "pageTitle": "billing/UpdateBillingAgreement", + "title": "UpdateBillingAgreement" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Update an agreement", + "slug": "update-an-agreement" + }, + "depth": 1 + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [{}, ".fbp"], + "pygmentsLexer": "php", + "singleLineComment": ["//"], + "ignorePrefix": "}", + "foldPrefix": "^", + "name": "PHP" + }, + "sourcePath": "/Users/japatel/Documents/workspace/Server-SDK/rest-api-sdk-php/sample/billing/UpdatePlan.php", + "projectPath": "billing/UpdatePlan.php", + "targetPath": "billing/UpdatePlan", + "pageTitle": "billing/UpdatePlan", + "title": "UpdatePlan" + }, + "depth": 2, + "outline": [ + { + "type": "heading", + "data": { + "level": 1, + "title": "Update a plan", + "slug": "update-a-plan" + }, + "depth": 1, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Making Plan Active", + "slug": "making-plan-active" + }, + "depth": 3 + } + ] + } + ] + } + ] + }, { "type": "folder", "data": { "path": "invoice", diff --git a/sample/doc/billing/CreateBillingAgreementWithCreditCard.html b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html new file mode 100644 index 0000000..dae828c --- /dev/null +++ b/sample/doc/billing/CreateBillingAgreementWithCreditCard.html @@ -0,0 +1,85 @@ +billing/CreateBillingAgreementWithCreditCard
billing/CreateBillingAgreementWithCreditCard.php
<?php

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

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.

/** @var Plan $createdPlan */ +$createdPlan = require 'UpdatePlan.php'; + +use PayPal\Api\Agreement; +use PayPal\Api\Plan; +use PayPal\Api\Payer; +use PayPal\Api\ShippingAddress; +use PayPal\Api\PayerInfo; +use PayPal\Api\CreditCard; +use PayPal\Api\FundingInstrument; + +/* Create a new instance of Agreement object +{ + "name": "DPRP", + "description": "Payment with credit Card ", + "start_date": "2015-06-17T9:45:04Z", + "plan": { + "id": "P-1WJ68935LL406420PUTENA2I" + }, + "shipping_address": { + "line1": "111 First Street", + "city": "Saratoga", + "state": "CA", + "postal_code": "95070", + "country_code": "US" + }, + "payer": { + "payment_method": "credit_card", + "payer_info": { + "email": "jaypatel512-facilitator@hotmail.com" + }, + "funding_instruments": [ + { + "credit_card": { + "type": "visa", + "number": "4417119669820331", + "expire_month": "12", + "expire_year": "2017", + "cvv2": "128" + } + } + ] + } +}*/ +$agreement = new Agreement(); + +$agreement->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;
\ No newline at end of file diff --git a/sample/doc/billing/CreateBillingAgreementWithPayPal.html b/sample/doc/billing/CreateBillingAgreementWithPayPal.html new file mode 100644 index 0000000..a5c4334 --- /dev/null +++ b/sample/doc/billing/CreateBillingAgreementWithPayPal.html @@ -0,0 +1,65 @@ +billing/CreateBillingAgreementWithPayPal
billing/CreateBillingAgreementWithPayPal.php
<?php

Create Billing Agreement with PayPal 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

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.

/** @var Plan $createdPlan */ +$createdPlan = require 'UpdatePlan.php'; + +use PayPal\Api\Agreement; +use PayPal\Api\Plan; +use PayPal\Api\Payer; +use PayPal\Api\ShippingAddress; + +/* Create a new instance of Agreement object +{ + "name": "Base Agreement", + "description": "Basic agreement", + "start_date": "2015-06-17T9:45:04Z", + "plan": { + "id": "P-1WJ68935LL406420PUTENA2I" + }, + "payer": { + "payment_method": "paypal" + }, + "shipping_address": { + "line1": "111 First Street", + "city": "Saratoga", + "state": "CA", + "postal_code": "95070", + "country_code": "US" + } +}*/ +$agreement = new Agreement(); + +$agreement->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", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $agreement); + +return $agreement;
\ No newline at end of file diff --git a/sample/doc/billing/CreatePlan.html b/sample/doc/billing/CreatePlan.html new file mode 100644 index 0000000..e22e688 --- /dev/null +++ b/sample/doc/billing/CreatePlan.html @@ -0,0 +1,46 @@ +billing/CreatePlan
billing/CreatePlan.php
<?php

Create Plan Sample

+

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

require __DIR__ . '/../bootstrap.php'; +use PayPal\Api\Plan; +use PayPal\Api\PaymentDefinition; +use PayPal\Api\MerchantPreferences; +use PayPal\Api\Currency; +use PayPal\Api\ChargeModel;

Create a new instance of Plan object

$plan = new Plan();

Basic Information

+

Fill up the basic information that is required for the plan

$plan->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;
\ No newline at end of file diff --git a/sample/doc/billing/ExecuteAgreement.html b/sample/doc/billing/ExecuteAgreement.html new file mode 100644 index 0000000..c0bf4df --- /dev/null +++ b/sample/doc/billing/ExecuteAgreement.html @@ -0,0 +1,22 @@ +billing/ExecuteAgreement
billing/ExecuteAgreement.php
<?php + +require __DIR__ . '/../bootstrap.php'; +session_start(); +if (isset($_GET['success']) && $_GET['success'] == 'true') { + + $token = $_GET['token']; + + $agreement = new \PayPal\Api\Agreement(); + + try { + $agreement->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); +}
\ No newline at end of file diff --git a/sample/doc/billing/GetBillingAgreement.html b/sample/doc/billing/GetBillingAgreement.html new file mode 100644 index 0000000..778c5f7 --- /dev/null +++ b/sample/doc/billing/GetBillingAgreement.html @@ -0,0 +1,19 @@ +billing/GetBillingAgreement
billing/GetBillingAgreement.php
<?php

Get Billing Agreement Sample

+

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

/** @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;
\ No newline at end of file diff --git a/sample/doc/billing/GetPlan.html b/sample/doc/billing/GetPlan.html new file mode 100644 index 0000000..68d3460 --- /dev/null +++ b/sample/doc/billing/GetPlan.html @@ -0,0 +1,19 @@ +billing/GetPlan
billing/GetPlan.php
<?php

Get Plan 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

/** @var Plan $createdPlan */ +$createdPlan = require 'CreatePlan.php'; + +use PayPal\Api\Plan; + +try { + $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("Retrieved a Plan", "Plan", $plan->getId(), null, $plan); + +return $plan;
\ No newline at end of file diff --git a/sample/doc/billing/ListPlans.html b/sample/doc/billing/ListPlans.html new file mode 100644 index 0000000..02c24c3 --- /dev/null +++ b/sample/doc/billing/ListPlans.html @@ -0,0 +1,22 @@ +billing/ListPlans
billing/ListPlans.php
<?php

Get List of 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

/** @var Plan $createdPlan */ +$createdPlan = require 'CreatePlan.php'; + +use PayPal\Api\Plan; + +try {

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

$params = array('page_size' => '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;
\ No newline at end of file diff --git a/sample/doc/billing/ReactivateBillingAgreement.html b/sample/doc/billing/ReactivateBillingAgreement.html new file mode 100644 index 0000000..c0753f2 --- /dev/null +++ b/sample/doc/billing/ReactivateBillingAgreement.html @@ -0,0 +1,26 @@ +billing/ReactivateBillingAgreement
billing/ReactivateBillingAgreement.php
<?php

Reactivate an agreement

+

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//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;
\ No newline at end of file diff --git a/sample/doc/billing/SuspendBillingAgreement.html b/sample/doc/billing/SuspendBillingAgreement.html new file mode 100644 index 0000000..9d6101b --- /dev/null +++ b/sample/doc/billing/SuspendBillingAgreement.html @@ -0,0 +1,26 @@ +billing/SuspendBillingAgreement
billing/SuspendBillingAgreement.php
<?php

Suspend an agreement

+

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//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;
\ No newline at end of file diff --git a/sample/doc/billing/UpdateBillingAgreement.html b/sample/doc/billing/UpdateBillingAgreement.html new file mode 100644 index 0000000..602f0de --- /dev/null +++ b/sample/doc/billing/UpdateBillingAgreement.html @@ -0,0 +1,38 @@ +billing/UpdateBillingAgreement
billing/UpdateBillingAgreement.php
<?php

Update an agreement

+

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

/** @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;
\ No newline at end of file diff --git a/sample/doc/billing/UpdatePlan.html b/sample/doc/billing/UpdatePlan.html new file mode 100644 index 0000000..be2dff4 --- /dev/null +++ b/sample/doc/billing/UpdatePlan.html @@ -0,0 +1,37 @@ +billing/UpdatePlan
billing/UpdatePlan.php
<?php

Update a plan

+

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/

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;
\ No newline at end of file diff --git a/sample/doc/invoice/CancelInvoice.html b/sample/doc/invoice/CancelInvoice.html index 8ea3eed..286a67e 100644 --- a/sample/doc/invoice/CancelInvoice.html +++ b/sample/doc/invoice/CancelInvoice.html @@ -30,15 +30,4 @@ notification object exit(1); } -?> - -<html> -<head> - <title>Cancel Invoice</title> -</head> -<body> -<div>Cancel Invoice:</div> -<pre><?php echo $invoice->toJSON(128); ?></pre> -<a href='../index.html'>Back</a> -</body> -</html>
+ResultPrinter::printResult("Cancel Invoice", "Invoice", $invoice->getId(), $notify, null); \ No newline at end of file diff --git a/sample/doc/invoice/CreateInvoice.html b/sample/doc/invoice/CreateInvoice.html index 2b57627..b6aee93 100644 --- a/sample/doc/invoice/CreateInvoice.html +++ b/sample/doc/invoice/CreateInvoice.html @@ -69,7 +69,7 @@ detailed breakdown of invoice

"Portland") ->setState("OR") ->setPostalCode("97217") - ->setCountryCode("US"); + ->setCountryCode("US");

For Sample Purposes Only.

$request = clone $invoice; try {

Create Invoice

Create an invoice by calling the invoice->create() method @@ -79,17 +79,5 @@ with a valid ApiContext (See bootstrap.php for more on ApiContext)< var_dump($ex->getData()); exit(1); } -?> -<html> -<head> - <title>Invoice Creation</title> -</head> -<body> -<div> - Created Invoice: - <?php echo $invoice->getId(); ?> -</div> -<pre><?php echo $invoice->toJSON(128); ?></pre> -<a href='../index.html'>Back</a> -</body> -</html>

+ +ResultPrinter::printResult("Invoice Creation", "Invoice", $invoice->getId(), $request, $invoice); \ No newline at end of file diff --git a/sample/doc/invoice/GetInvoice.html b/sample/doc/invoice/GetInvoice.html index e59de18..19e0be0 100644 --- a/sample/doc/invoice/GetInvoice.html +++ b/sample/doc/invoice/GetInvoice.html @@ -15,14 +15,5 @@ Invoice ID var_dump($ex->getData()); exit(1); } -?> -<html> -<head> - <title>Lookup invoice details</title> -</head> -<body> - <div>Retrieving Invoice: <?php echo $invoiceId;?></div> - <pre><?php echo $invoice->toJSON(128); ?></pre> - <a href='../index.html'>Back</a> -</body> -</html> + +ResultPrinter::printResult("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $invoice); \ No newline at end of file diff --git a/sample/doc/invoice/ListInvoice.html b/sample/doc/invoice/ListInvoice.html index 14acc2b..4fe074f 100644 --- a/sample/doc/invoice/ListInvoice.html +++ b/sample/doc/invoice/ListInvoice.html @@ -13,14 +13,4 @@ Refer the method doc for valid values for keys var_dump($ex->getData()); exit(1); } -?> -<html> -<head> - <title>Lookup invoice history</title> -</head> -<body> - <div>Got invoices </div> - <pre><?php echo $invoices->toJSON(128); ?></pre> - <a href='../index.html'>Back</a> -</body> -</html> +ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices); \ No newline at end of file diff --git a/sample/doc/invoice/RemindInvoice.html b/sample/doc/invoice/RemindInvoice.html index 14e717d..586d17a 100644 --- a/sample/doc/invoice/RemindInvoice.html +++ b/sample/doc/invoice/RemindInvoice.html @@ -29,15 +29,4 @@ notification object exit(1); } -?> - -<html> -<head> - <title>Remind Invoice</title> -</head> -<body> -<div>Remind Invoice:</div> -<pre><?php echo $invoice->toJSON(128); ?></pre> -<a href='../index.html'>Back</a> -</body> -</html> +ResultPrinter::printResult("Remind Invoice", "Invoice", null, $notify, null); \ No newline at end of file diff --git a/sample/doc/invoice/SendInvoice.html b/sample/doc/invoice/SendInvoice.html index 9c87077..5847408 100644 --- a/sample/doc/invoice/SendInvoice.html +++ b/sample/doc/invoice/SendInvoice.html @@ -18,14 +18,4 @@ with a valid ApiContext (See bootstrap.php for more on ApiContext)< exit(1); } -?> -<html> -<head> - <title>Send Invoice</title> -</head> -<body> -<div>Send Invoice:</div> -<pre><?php echo $invoice->toJSON(128); ?></pre> -<a href='../index.html'>Back</a> -</body> -</html> +ResultPrinter::printResult("Send Invoice", "Invoice", $invoice->getId(), null, null); \ No newline at end of file diff --git a/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html b/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html index 9fd569f..2eb42b0 100644 --- a/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html +++ b/sample/doc/lipp/GenerateAccessTokenFromRefreshToken.html @@ -12,4 +12,4 @@ exit(1); } -print_result("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), $tokenInfo); \ No newline at end of file +ResultPrinter::printResult("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), null, $tokenInfo); \ No newline at end of file diff --git a/sample/doc/lipp/GetUserInfo.html b/sample/doc/lipp/GetUserInfo.html index 131e602..0b01e49 100644 --- a/sample/doc/lipp/GetUserInfo.html +++ b/sample/doc/lipp/GetUserInfo.html @@ -22,4 +22,4 @@ to retreive the information. The short lived access token can be retrieved using exit(1); } -print_result("User Information", "User Info", $userInfo->getUserId(), $userInfo->toJSON(128)); +ResultPrinter::printResult("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo); \ No newline at end of file diff --git a/sample/doc/lipp/ObtainUserConsent.html b/sample/doc/lipp/ObtainUserConsent.html index b8b1ca0..41a31b9 100644 --- a/sample/doc/lipp/ObtainUserConsent.html +++ b/sample/doc/lipp/ObtainUserConsent.html @@ -15,4 +15,4 @@ $apiContext ); -print_result("Generated the User Consent URL", "URL", null, '<a href="'. $redirectUrl . '" >Click Here to Obtain User Consent</a>'); \ No newline at end of file +ResultPrinter::printResult("Generated the User Consent URL", "URL", '<a href="'. $redirectUrl . '" >Click Here to Obtain User Consent</a>', $baseUrl, $redirectUrl); \ No newline at end of file diff --git a/sample/doc/lipp/UserConsentRedirect.html b/sample/doc/lipp/UserConsentRedirect.html index d7aced4..069101a 100644 --- a/sample/doc/lipp/UserConsentRedirect.html +++ b/sample/doc/lipp/UserConsentRedirect.html @@ -18,6 +18,6 @@ The user would then able to retrieve the access token by getting the code, which exit(1); } - print_result("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $accessToken); + ResultPrinter::printResult("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $_GET['code'], $accessToken); } \ No newline at end of file diff --git a/sample/doc/payment-experience/CreateWebProfile.html b/sample/doc/payment-experience/CreateWebProfile.html index 8742c22..1a24d5d 100644 --- a/sample/doc/payment-experience/CreateWebProfile.html +++ b/sample/doc/payment-experience/CreateWebProfile.html @@ -3,7 +3,7 @@ require __DIR__ . '/../bootstrap.php';

Create Web Profile

Use the /web-profiles resource to create seamless payment experience profiles. See the payment experience overview for further information about using the /payment resource to create the PayPal payment and pass the experience_profile_id. Documentation available at https://developer.paypal.com/webapps/developer/docs/api/#create-a-web-experience-profile

Lets create an instance of FlowConfig and add -landing page type information

$flowConfig = new \PayPal\Api\FlowConfig();

Type of PayPal page to be displayed when a user lands on the PayPal site for checkout. Allowed values: Billing or Login. When set to Billing, the Non-PayPal account landing page is used. When set to Login, the PayPal account login landing page is used.

$flowConfig->setLandingPageType("Billing");

The URL on the merchant site for transferring to after a bank transfer payment.

$flowConfig->setBankTxnPendingUrl("http://www.yeowza.com/");

Parameters for style and presentation.

$presentation = new \PayPal\Api\Presentation();

A URL to logo image. Allowed vaues: .gif, .jpg, or .png.

$presentation->setLogoImage("http://www.yeowza.com/favico.ico")

A label that overrides the business name in the PayPal account on the PayPal pages.

->setBrandName("YeowZa! Paypal")

Locale of pages displayed by PayPal payment experience.

->setLocaleCode("US");

Parameters for input fields customization.

$inputFields = new \PayPal\Api\InputFields();

Enables the buyer to enter a note to the merchant on the PayPal page during checkout.

$inputFields->setAllowNote(true)

Determines whether or not PayPal displays shipping address fields on the experience pages. Allowed values: 0, 1, or 2. When set to 0, PayPal displays the shipping address on the PayPal pages. When set to 1, PayPal does not display shipping address fields whatsoever. When set to 2, if you do not pass the shipping address, PayPal obtains it from the buyer’s account profile. For digital goods, this field is required, and you must set it to 1.

->setNoShipping(1)

Determines whether or not the PayPal pages should display the shipping address and not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. Allowed values: 0 or 1. When set to 0, the PayPal pages should not display the shipping address. When set to 1, the PayPal pages should display the shipping address.

->setAddressOverride(0);

Payment Web experience profile resource

$webProfile = new \PayPal\Api\WebProfile();

Name of the web experience profile. Required. Must be unique

$webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())

Parameters for flow configuration.

->setFlowConfig($flowConfig)

Parameters for style and presentation.

->setPresentation($presentation); +landing page type information

$flowConfig = new \PayPal\Api\FlowConfig();

Type of PayPal page to be displayed when a user lands on the PayPal site for checkout. Allowed values: Billing or Login. When set to Billing, the Non-PayPal account landing page is used. When set to Login, the PayPal account login landing page is used.

$flowConfig->setLandingPageType("Billing");

The URL on the merchant site for transferring to after a bank transfer payment.

$flowConfig->setBankTxnPendingUrl("http://www.yeowza.com/");

Parameters for style and presentation.

$presentation = new \PayPal\Api\Presentation();

A URL to logo image. Allowed vaues: .gif, .jpg, or .png.

$presentation->setLogoImage("http://www.yeowza.com/favico.ico")

A label that overrides the business name in the PayPal account on the PayPal pages.

->setBrandName("YeowZa! Paypal")

Locale of pages displayed by PayPal payment experience.

->setLocaleCode("US");

Parameters for input fields customization.

$inputFields = new \PayPal\Api\InputFields();

Enables the buyer to enter a note to the merchant on the PayPal page during checkout.

$inputFields->setAllowNote(true)

Determines whether or not PayPal displays shipping address fields on the experience pages. Allowed values: 0, 1, or 2. When set to 0, PayPal displays the shipping address on the PayPal pages. When set to 1, PayPal does not display shipping address fields whatsoever. When set to 2, if you do not pass the shipping address, PayPal obtains it from the buyer’s account profile. For digital goods, this field is required, and you must set it to 1.

->setNoShipping(1)

Determines whether or not the PayPal pages should display the shipping address and not the shipping address on file with PayPal for this buyer. Displaying the PayPal street address on file does not allow the buyer to edit that address. Allowed values: 0 or 1. When set to 0, the PayPal pages should not display the shipping address. When set to 1, the PayPal pages should display the shipping address.

->setAddressOverride(0);

Payment Web experience profile resource

$webProfile = new \PayPal\Api\WebProfile();

Name of the web experience profile. Required. Must be unique

$webProfile->setName("YeowZa! T-Shirt Shop" . uniqid())

Parameters for flow configuration.

->setFlowConfig($flowConfig)

Parameters for style and presentation.

->setPresentation($presentation);

For Sample Purposes Only.

$request = clone $webProfile; try {

Use this call to create a profile.

$createProfileResponse = $webProfile->create($apiContext); } catch (\Exception $ex) { @@ -15,6 +15,6 @@ landing page type information

exit(1); } -print_result("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $createProfileResponse); +ResultPrinter::printResult("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $request, $createProfileResponse); return $createProfileResponse;
\ No newline at end of file diff --git a/sample/doc/payment-experience/DeleteWebProfile.html b/sample/doc/payment-experience/DeleteWebProfile.html index 33427fe..a5df890 100644 --- a/sample/doc/payment-experience/DeleteWebProfile.html +++ b/sample/doc/payment-experience/DeleteWebProfile.html @@ -17,4 +17,4 @@ that contains the web profile ID.

exit(1); } -print_result("Deleted Web Profile", "Web Profile", $createProfileResponse->getId());
\ No newline at end of file +ResultPrinter::printResult("Deleted Web Profile", "Web Profile", $createProfileResponse->getId(), null, null); \ No newline at end of file diff --git a/sample/doc/payment-experience/GetWebProfile.html b/sample/doc/payment-experience/GetWebProfile.html index 8c6577a..18a240d 100644 --- a/sample/doc/payment-experience/GetWebProfile.html +++ b/sample/doc/payment-experience/GetWebProfile.html @@ -16,6 +16,6 @@ that contains the web profile ID.

exit(1); } -print_result("Get Web Profile", "Web Profile", $webProfile->getId(), $webProfile); +ResultPrinter::printResult("Get Web Profile", "Web Profile", $webProfile->getId(), null, $webProfile); return $webProfile;
\ No newline at end of file diff --git a/sample/doc/payment-experience/ListWebProfiles.html b/sample/doc/payment-experience/ListWebProfiles.html index 3dc01ae..c8398f7 100644 --- a/sample/doc/payment-experience/ListWebProfiles.html +++ b/sample/doc/payment-experience/ListWebProfiles.html @@ -15,9 +15,9 @@ static get_list method on the WebProfile class. } $result = ''; foreach ($list as $object) { - $result .= $object->toJSON(128) . PHP_EOL; + $result .= $object->toJSON(128) . PHP_EOL; } -print_result("Get List of All Web Profiles", "Web Profiles", null, $result); +ResultPrinter::printResult("Get List of All Web Profiles", "Web Profiles", null, null, $result); -return $list; +return $list; \ No newline at end of file diff --git a/sample/doc/payment-experience/PartiallyUpdateWebProfile.html b/sample/doc/payment-experience/PartiallyUpdateWebProfile.html index 827494c..4c1b873 100644 --- a/sample/doc/payment-experience/PartiallyUpdateWebProfile.html +++ b/sample/doc/payment-experience/PartiallyUpdateWebProfile.html @@ -26,4 +26,4 @@ as shown below

exit(1); } -print_result("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile);
\ No newline at end of file +ResultPrinter::printResult("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $webProfile); \ No newline at end of file diff --git a/sample/doc/payment-experience/UpdateWebProfile.html b/sample/doc/payment-experience/UpdateWebProfile.html index 415433a..f5b2000 100644 --- a/sample/doc/payment-experience/UpdateWebProfile.html +++ b/sample/doc/payment-experience/UpdateWebProfile.html @@ -16,4 +16,4 @@ object

exit(1); } -print_result("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $updatedWebProfile);
\ No newline at end of file +ResultPrinter::printResult("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $webProfile, $updatedWebProfile); \ No newline at end of file diff --git a/sample/doc/payments/AuthorizationCapture.html b/sample/doc/payments/AuthorizationCapture.html index e1adff5..34ffbf5 100644 --- a/sample/doc/payments/AuthorizationCapture.html +++ b/sample/doc/payments/AuthorizationCapture.html @@ -33,7 +33,7 @@ createAuthorization defined in common.php

<?php echo $getCapture->getParentPayment(); ?>. Capture Id: <?php echo $getCapture->getId();?> </div> - <pre><?php echo $getCapture->toJSON(128);?></pre> + <pre><?php echo $getCapture->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/payments/CreateFuturePayment.html b/sample/doc/payments/CreateFuturePayment.html index dcd2ee5..f8f794f 100644 --- a/sample/doc/payments/CreateFuturePayment.html +++ b/sample/doc/payments/CreateFuturePayment.html @@ -61,7 +61,7 @@ Please note that currently future payments works only with PayPal as a funding i Created payment: <?php echo $payment->getId();?> </div> -<pre><?php echo $payment->toJSON(128);?></pre> +<pre><?php echo $payment->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html> +</html> \ No newline at end of file diff --git a/sample/doc/payments/CreatePayment.html b/sample/doc/payments/CreatePayment.html index 6812541..7102b35 100644 --- a/sample/doc/payments/CreatePayment.html +++ b/sample/doc/payments/CreatePayment.html @@ -91,7 +91,7 @@ The return object contains the state.

<?php echo $payment->getId();?> </div> - <pre><?php echo $payment->toJSON(128);?></pre> + <pre><?php echo $payment->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/payments/CreatePaymentUsingPayPal.html b/sample/doc/payments/CreatePaymentUsingPayPal.html index 5bc2717..9b26c77 100644 --- a/sample/doc/payments/CreatePaymentUsingPayPal.html +++ b/sample/doc/payments/CreatePaymentUsingPayPal.html @@ -9,8 +9,7 @@ API used: /v1/payments/payment

use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; -use PayPal\Api\Transaction; -session_start();

Payer

+use PayPal\Api\Transaction;

Payer

A resource representing a Payer that funds a payment For paypal account payments, set payment method to 'paypal'.

$payer = new Payer(); @@ -77,14 +76,7 @@ method

$redirectUrl = $link->getHref(); break; } -}

Redirect buyer to PayPal website

-

Save the payment id so that you can 'complete' the payment -once the buyer approves the payment and is redirected -back to your website. -It is not a great idea to store the payment id -in the session. In a real world app, you may want to -store the payment id in a database.

$_SESSION['paymentId'] = $payment->getId(); -if(isset($redirectUrl)) { +}

Redirect buyer to PayPal website

if(isset($redirectUrl)) { header("Location: $redirectUrl"); exit; }
\ No newline at end of file diff --git a/sample/doc/payments/CreatePaymentUsingSavedCard.html b/sample/doc/payments/CreatePaymentUsingSavedCard.html index d63a18e..1929aa4 100644 --- a/sample/doc/payments/CreatePaymentUsingSavedCard.html +++ b/sample/doc/payments/CreatePaymentUsingSavedCard.html @@ -80,7 +80,7 @@ The return object contains the state.

<?php echo $payment->getId();?> </div> - <pre><?php echo $payment->toJSON(128);?></pre> + <pre><?php echo $payment->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/payments/ExecutePayment.html b/sample/doc/payments/ExecutePayment.html index 221287d..45cd116 100644 --- a/sample/doc/payments/ExecutePayment.html +++ b/sample/doc/payments/ExecutePayment.html @@ -8,26 +8,24 @@ API used: POST '/v1/payments/payment//execute'.

use PayPal\Api\ExecutePayment; use PayPal\Api\Payment; use PayPal\Api\PaymentExecution; -session_start(); -if(isset($_GET['success']) && $_GET['success'] == 'true') { -

Get the payment Object by passing paymentId + +if (isset($_GET['success']) && $_GET['success'] == 'true') {

Get the payment Object by passing paymentId payment id was previously stored in session in -CreatePaymentUsingPayPal.php

$paymentId = $_SESSION['paymentId']; - $payment = Payment::get($paymentId, $apiContext); -

PaymentExecution object includes information necessary -to execute a PayPal account payment. +CreatePaymentUsingPayPal.php

$paymentId = $_GET['paymentId']; + $payment = Payment::get($paymentId, $apiContext);

PaymentExecution object includes information necessary +to execute a PayPal account payment. The payer_id is added to the request query parameters -when the user is redirected from paypal back to your site

$execution = new PaymentExecution(); - $execution->setPayerId($_GET['PayerID']); - - //Execute the payment

(See bootstrap.php for more on ApiContext)

$result = $payment->execute($execution, $apiContext); +when the user is redirected from paypal back to your site

$execution = new PaymentExecution(); + $execution->setPayerId($_GET['PayerID']); + + //Execute the payment

(See bootstrap.php for more on ApiContext)

$result = $payment->execute($execution, $apiContext); echo "<html><body><pre>"; - echo $result->toJSON(128); - echo "</pre><a href='../index.html'>Back</a></body></html>"; - + echo $result->toJSON(128); + echo "</pre><a href='../index.html'>Back</a></body></html>"; + } else { echo "<html><body><h1>"; - echo "User cancelled payment."; + echo "User cancelled payment."; echo "</h1><a href='../index.html'>Back</a></body></html>"; -}
+} \ No newline at end of file diff --git a/sample/doc/payments/GetAuthorization.html b/sample/doc/payments/GetAuthorization.html index 3836bd0..ce43799 100644 --- a/sample/doc/payments/GetAuthorization.html +++ b/sample/doc/payments/GetAuthorization.html @@ -25,7 +25,7 @@ createAuthorization is defined in common.php

<?php echo $authorization->getId();?> </div> - <pre><?php echo $authorization->toJSON(128);?></pre> + <pre><?php echo $authorization->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/payments/GetCapture.html b/sample/doc/payments/GetCapture.html index 8aae25d..d86f09d 100644 --- a/sample/doc/payments/GetCapture.html +++ b/sample/doc/payments/GetCapture.html @@ -41,7 +41,7 @@ with a valid ApiContext (See bootstrap.php for more on ApiContext)< Capture Id: <?php echo $capture->getId();?> </div> - <pre><?php echo $capture->toJSON(128);?></pre> + <pre><?php echo $capture->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html> +</html> \ No newline at end of file diff --git a/sample/doc/payments/GetPayment.html b/sample/doc/payments/GetPayment.html index 82a25df..c56d14c 100644 --- a/sample/doc/payments/GetPayment.html +++ b/sample/doc/payments/GetPayment.html @@ -27,7 +27,7 @@ Payment ID </head> <body> <div>Retrieving Payment ID: <?php echo $paymentId;?></div> - <pre><?php echo $payment->toJSON(128);?></pre> + <pre><?php echo $payment->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html> +</html> \ No newline at end of file diff --git a/sample/doc/payments/ListPayments.html b/sample/doc/payments/ListPayments.html index 97352dc..5243a5c 100644 --- a/sample/doc/payments/ListPayments.html +++ b/sample/doc/payments/ListPayments.html @@ -26,7 +26,7 @@ Refer the method doc for valid values for keys </head> <body> <div>Got <?php echo $payments->getCount(); ?> matching payments </div> - <pre><?php echo $payments->toJSON(128);?></pre> + <pre><?php echo $payments->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html> +</html> \ No newline at end of file diff --git a/sample/doc/payments/Reauthorization.html b/sample/doc/payments/Reauthorization.html index cde56f5..a1551ea 100644 --- a/sample/doc/payments/Reauthorization.html +++ b/sample/doc/payments/Reauthorization.html @@ -30,8 +30,8 @@ has expired.

<?php echo $reauthorization->getId();?> </div> <pre> - <?php echo $reauthorization->toJSON(128);?> + <?php echo $reauthorization->toJSON(128);?> </pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/payments/RefundCapture.html b/sample/doc/payments/RefundCapture.html index dd84a19..2daef75 100644 --- a/sample/doc/payments/RefundCapture.html +++ b/sample/doc/payments/RefundCapture.html @@ -46,7 +46,7 @@ PayPal-Request-Id (idempotency) header for this resource

<?php echo $captureRefund->toJSON(128);?></pre> + <pre><?php echo $captureRefund->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/payments/VoidAuthorization.html b/sample/doc/payments/VoidAuthorization.html index f9b48fa..57ac7dc 100644 --- a/sample/doc/payments/VoidAuthorization.html +++ b/sample/doc/payments/VoidAuthorization.html @@ -22,7 +22,7 @@ createAuthorization is defined in common.php

<?php echo $voidedAuth->toJSON(128);?></pre> + <pre><?php echo $voidedAuth->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/sale/GetSale.html b/sample/doc/sale/GetSale.html index 9872fd4..4192a3b 100644 --- a/sample/doc/sale/GetSale.html +++ b/sample/doc/sale/GetSale.html @@ -22,7 +22,7 @@ transaction from your payment resource.

<?php echo $saleId;?></div> - <pre><?php echo $sale->toJSON(128)?></pre> + <pre><?php echo $sale->toJSON(128)?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/sale/RefundSale.html b/sample/doc/sale/RefundSale.html index e3999fb..6d23d95 100644 --- a/sample/doc/sale/RefundSale.html +++ b/sample/doc/sale/RefundSale.html @@ -32,7 +32,7 @@ given sale transaction id.

<?php echo $saleId;?></div> - <pre><?php echo $sale->toJSON(128);?></pre> + <pre><?php echo $sale->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/doc/vault/CreateCreditCard.html b/sample/doc/vault/CreateCreditCard.html index 6b006c4..3528ddf 100644 --- a/sample/doc/vault/CreateCreditCard.html +++ b/sample/doc/vault/CreateCreditCard.html @@ -31,7 +31,7 @@ in future payments. </head> <body> <div>Saved a new credit card with id: <?php echo $card->getId();?></div> - <pre><?php echo $card->toJSON(128);?></pre> + <pre><?php echo $card->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html> +</html> \ No newline at end of file diff --git a/sample/doc/vault/GetCreditCard.html b/sample/doc/vault/GetCreditCard.html index 91d46d2..1f09c1b 100644 --- a/sample/doc/vault/GetCreditCard.html +++ b/sample/doc/vault/GetCreditCard.html @@ -21,7 +21,7 @@ card operation. Use $card->getId()

<?php echo $cardId;?></div> - <pre><?php echo $card->toJSON(128);?></pre> + <pre><?php echo $card->toJSON(128);?></pre> <a href='../index.html'>Back</a> </body> -</html>
+</html> \ No newline at end of file diff --git a/sample/header.html b/sample/header.html new file mode 100644 index 0000000..7e8996a --- /dev/null +++ b/sample/header.html @@ -0,0 +1,82 @@ + + + + + + + + + + + + PayPal REST API Samples + + + + + + + + + + + + + diff --git a/sample/index.html b/sample/index.html index b80143f..24ea67e 100644 --- a/sample/index.html +++ b/sample/index.html @@ -36,19 +36,17 @@

REST API Samples

-

These examples are created to experiment with the rest-api-sdk-php capabilities. Each examples are designed to demonstrate the default use-cases in each segment. +

These examples are created to experiment with the PayPal-PHP-SDK capabilities. Each examples are designed to demonstrate the default use-cases in each segment. Many examples should be executable, and should allow you to experience the default behavior of our sdk, to expedite your integration experience.

-

-

-

Payments

+

Payments

    @@ -111,7 +109,7 @@
    -

    Sale

    +

    Sale

      @@ -136,9 +134,108 @@
    +
    + + + +
    +
    -

    Vault

    +

    Vault

      @@ -174,7 +271,7 @@
      -

      Authorization and capture

      +

      Authorization and capture

        @@ -237,7 +334,7 @@
        -

        Payment Experience

        +

        Payment Experience

          @@ -300,7 +397,7 @@
          -

          Invoice

          +

          Invoice

            @@ -363,7 +460,7 @@
            -

            Identity (LIPP)

            +

            Identity (LIPP)

              diff --git a/sample/invoice/CancelInvoice.php b/sample/invoice/CancelInvoice.php index 8480ed8..eb6ff79 100644 --- a/sample/invoice/CancelInvoice.php +++ b/sample/invoice/CancelInvoice.php @@ -43,15 +43,4 @@ try { exit(1); } -?> - - - - Cancel Invoice - - -
              Cancel Invoice:
              -
              toJSON(128); ?>
              -Back - - +ResultPrinter::printResult("Cancel Invoice", "Invoice", $invoice->getId(), $notify, null); diff --git a/sample/invoice/CreateInvoice.php b/sample/invoice/CreateInvoice.php index eaa17ca..69c2592 100644 --- a/sample/invoice/CreateInvoice.php +++ b/sample/invoice/CreateInvoice.php @@ -93,6 +93,9 @@ $invoice->getShippingInfo()->getAddress() ->setPostalCode("97217") ->setCountryCode("US"); +// For Sample Purposes Only. +$request = clone $invoice; + try { // ### Create Invoice // Create an invoice by calling the invoice->create() method @@ -103,17 +106,6 @@ try { var_dump($ex->getData()); exit(1); } -?> - - - Invoice Creation - - -
              - Created Invoice: - getId(); ?> -
              -
              toJSON(128); ?>
              -Back - - + +ResultPrinter::printResult("Invoice Creation", "Invoice", $invoice->getId(), $request, $invoice); + diff --git a/sample/invoice/GetInvoice.php b/sample/invoice/GetInvoice.php index 6c64017..9a7690d 100644 --- a/sample/invoice/GetInvoice.php +++ b/sample/invoice/GetInvoice.php @@ -22,14 +22,5 @@ try { var_dump($ex->getData()); exit(1); } -?> - - - Lookup invoice details - - -
              Retrieving Invoice:
              -
              toJSON(128); ?>
              - Back - - + +ResultPrinter::printResult("Get Invoice", "Invoice", $invoice->getId(), $invoiceId, $invoice); diff --git a/sample/invoice/ListInvoice.php b/sample/invoice/ListInvoice.php index b4e5dd3..0e52c2f 100644 --- a/sample/invoice/ListInvoice.php +++ b/sample/invoice/ListInvoice.php @@ -19,14 +19,4 @@ try { var_dump($ex->getData()); exit(1); } -?> - - - Lookup invoice history - - -
              Got invoices
              -
              toJSON(128); ?>
              - Back - - +ResultPrinter::printResult("Lookup Invoice History", "Invoice", null, null, $invoices); diff --git a/sample/invoice/RemindInvoice.php b/sample/invoice/RemindInvoice.php index b3d79a1..34a36a3 100644 --- a/sample/invoice/RemindInvoice.php +++ b/sample/invoice/RemindInvoice.php @@ -41,15 +41,5 @@ try { exit(1); } -?> +ResultPrinter::printResult("Remind Invoice", "Invoice", null, $notify, null); - - - Remind Invoice - - -
              Remind Invoice:
              -
              toJSON(128); ?>
              -Back - - diff --git a/sample/invoice/SendInvoice.php b/sample/invoice/SendInvoice.php index 2b314b3..17db216 100644 --- a/sample/invoice/SendInvoice.php +++ b/sample/invoice/SendInvoice.php @@ -27,14 +27,4 @@ try { exit(1); } -?> - - - Send Invoice - - -
              Send Invoice:
              -
              toJSON(128); ?>
              -Back - - +ResultPrinter::printResult("Send Invoice", "Invoice", $invoice->getId(), null, null); diff --git a/sample/lipp/GenerateAccessTokenFromRefreshToken.php b/sample/lipp/GenerateAccessTokenFromRefreshToken.php index 649faac..44e7b17 100644 --- a/sample/lipp/GenerateAccessTokenFromRefreshToken.php +++ b/sample/lipp/GenerateAccessTokenFromRefreshToken.php @@ -19,4 +19,4 @@ try { exit(1); } -print_result("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), $tokenInfo); +ResultPrinter::printResult("Obtained Access Token From Refresh Token", "Access Token", $tokenInfo->getAccessToken(), null, $tokenInfo); diff --git a/sample/lipp/GetUserInfo.php b/sample/lipp/GetUserInfo.php index f63f830..f79a450 100644 --- a/sample/lipp/GetUserInfo.php +++ b/sample/lipp/GetUserInfo.php @@ -34,4 +34,4 @@ try { exit(1); } -print_result("User Information", "User Info", $userInfo->getUserId(), $userInfo->toJSON(128)); +ResultPrinter::printResult("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo); diff --git a/sample/lipp/ObtainUserConsent.php b/sample/lipp/ObtainUserConsent.php index 9653e8b..f677e17 100644 --- a/sample/lipp/ObtainUserConsent.php +++ b/sample/lipp/ObtainUserConsent.php @@ -19,4 +19,4 @@ $redirectUrl = PPOpenIdSession::getAuthorizationUrl( $apiContext ); -print_result("Generated the User Consent URL", "URL", null, 'Click Here to Obtain User Consent'); +ResultPrinter::printResult("Generated the User Consent URL", "URL", 'Click Here to Obtain User Consent', $baseUrl, $redirectUrl); diff --git a/sample/lipp/UserConsentRedirect.php b/sample/lipp/UserConsentRedirect.php index e046923..62e0880 100644 --- a/sample/lipp/UserConsentRedirect.php +++ b/sample/lipp/UserConsentRedirect.php @@ -23,6 +23,6 @@ if (isset($_GET['success']) && $_GET['success'] == 'true') { exit(1); } - print_result("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $accessToken); + ResultPrinter::printResult("Obtained Access Token", "Access Token", $accessToken->getAccessToken(), $_GET['code'], $accessToken); } diff --git a/sample/payment-experience/CreateWebProfile.php b/sample/payment-experience/CreateWebProfile.php index a0a47a9..07cba83 100644 --- a/sample/payment-experience/CreateWebProfile.php +++ b/sample/payment-experience/CreateWebProfile.php @@ -43,6 +43,9 @@ $webProfile->setName("YeowZa! T-Shirt Shop" . uniqid()) // Parameters for style and presentation. ->setPresentation($presentation); +// For Sample Purposes Only. +$request = clone $webProfile; + try { // Use this call to create a profile. $createProfileResponse = $webProfile->create($apiContext); @@ -55,6 +58,6 @@ try { exit(1); } -print_result("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $createProfileResponse); +ResultPrinter::printResult("Created Web Profile", "Web Profile", $createProfileResponse->getId(), $request, $createProfileResponse); return $createProfileResponse; diff --git a/sample/payment-experience/DeleteWebProfile.php b/sample/payment-experience/DeleteWebProfile.php index dbc6849..847bcc2 100644 --- a/sample/payment-experience/DeleteWebProfile.php +++ b/sample/payment-experience/DeleteWebProfile.php @@ -27,4 +27,4 @@ try { exit(1); } -print_result("Deleted Web Profile", "Web Profile", $createProfileResponse->getId()); +ResultPrinter::printResult("Deleted Web Profile", "Web Profile", $createProfileResponse->getId(), null, null); diff --git a/sample/payment-experience/GetWebProfile.php b/sample/payment-experience/GetWebProfile.php index 2779858..77bcda8 100644 --- a/sample/payment-experience/GetWebProfile.php +++ b/sample/payment-experience/GetWebProfile.php @@ -23,6 +23,6 @@ try { exit(1); } -print_result("Get Web Profile", "Web Profile", $webProfile->getId(), $webProfile); +ResultPrinter::printResult("Get Web Profile", "Web Profile", $webProfile->getId(), null, $webProfile); return $webProfile; diff --git a/sample/payment-experience/ListWebProfiles.php b/sample/payment-experience/ListWebProfiles.php index d4794b7..1a190a6 100644 --- a/sample/payment-experience/ListWebProfiles.php +++ b/sample/payment-experience/ListWebProfiles.php @@ -23,6 +23,6 @@ foreach ($list as $object) { $result .= $object->toJSON(128) . PHP_EOL; } -print_result("Get List of All Web Profiles", "Web Profiles", null, $result); +ResultPrinter::printResult("Get List of All Web Profiles", "Web Profiles", null, null, $result); return $list; diff --git a/sample/payment-experience/PartiallyUpdateWebProfile.php b/sample/payment-experience/PartiallyUpdateWebProfile.php index fdfd995..1f97c0c 100644 --- a/sample/payment-experience/PartiallyUpdateWebProfile.php +++ b/sample/payment-experience/PartiallyUpdateWebProfile.php @@ -45,4 +45,4 @@ try { exit(1); } -print_result("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $webProfile); +ResultPrinter::printResult("Partially Updated Web Profile", "Web Profile", $webProfile->getId(), $patches, $webProfile); diff --git a/sample/payment-experience/UpdateWebProfile.php b/sample/payment-experience/UpdateWebProfile.php index 4733b11..12ad366 100644 --- a/sample/payment-experience/UpdateWebProfile.php +++ b/sample/payment-experience/UpdateWebProfile.php @@ -29,4 +29,4 @@ try { exit(1); } -print_result("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $updatedWebProfile); +ResultPrinter::printResult("Updated Web Profile", "Web Profile", $updatedWebProfile->getId(), $webProfile, $updatedWebProfile); diff --git a/sample/payments/CreatePaymentUsingPayPal.php b/sample/payments/CreatePaymentUsingPayPal.php index 712c629..7c0c794 100644 --- a/sample/payments/CreatePaymentUsingPayPal.php +++ b/sample/payments/CreatePaymentUsingPayPal.php @@ -14,7 +14,6 @@ use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; use PayPal\Api\Transaction; -session_start(); // ### Payer // A resource representing a Payer that funds a payment @@ -111,14 +110,6 @@ foreach($payment->getLinks() as $link) { } // ### Redirect buyer to PayPal website -// Save the payment id so that you can 'complete' the payment -// once the buyer approves the payment and is redirected -// back to your website. -// -// It is not a great idea to store the payment id -// in the session. In a real world app, you may want to -// store the payment id in a database. -$_SESSION['paymentId'] = $payment->getId(); if(isset($redirectUrl)) { header("Location: $redirectUrl"); exit; diff --git a/sample/payments/ExecutePayment.php b/sample/payments/ExecutePayment.php index 3edae33..031dadb 100644 --- a/sample/payments/ExecutePayment.php +++ b/sample/payments/ExecutePayment.php @@ -11,32 +11,32 @@ require __DIR__ . '/../bootstrap.php'; use PayPal\Api\ExecutePayment; use PayPal\Api\Payment; use PayPal\Api\PaymentExecution; -session_start(); -if(isset($_GET['success']) && $_GET['success'] == 'true') { - - // Get the payment Object by passing paymentId - // payment id was previously stored in session in - // CreatePaymentUsingPayPal.php - $paymentId = $_SESSION['paymentId']; - $payment = Payment::get($paymentId, $apiContext); - - // PaymentExecution object includes information necessary - // to execute a PayPal account payment. - // The payer_id is added to the request query parameters - // when the user is redirected from paypal back to your site - $execution = new PaymentExecution(); - $execution->setPayerId($_GET['PayerID']); - - //Execute the payment - // (See bootstrap.php for more on `ApiContext`) - $result = $payment->execute($execution, $apiContext); + +if (isset($_GET['success']) && $_GET['success'] == 'true') { + + // Get the payment Object by passing paymentId + // payment id was previously stored in session in + // CreatePaymentUsingPayPal.php + $paymentId = $_GET['paymentId']; + $payment = Payment::get($paymentId, $apiContext); + + // PaymentExecution object includes information necessary + // to execute a PayPal account payment. + // The payer_id is added to the request query parameters + // when the user is redirected from paypal back to your site + $execution = new PaymentExecution(); + $execution->setPayerId($_GET['PayerID']); + + //Execute the payment + // (See bootstrap.php for more on `ApiContext`) + $result = $payment->execute($execution, $apiContext); echo "
              ";
              -	echo $result->toJSON(128);
              -	echo "
              Back"; - + echo $result->toJSON(128); + echo "Back"; + } else { echo "

              "; - echo "User cancelled payment."; + echo "User cancelled payment."; echo "

              Back"; } diff --git a/tests/PayPal/Test/Api/AddressTest.php b/tests/PayPal/Test/Api/AddressTest.php index 1592538..39e1e39 100644 --- a/tests/PayPal/Test/Api/AddressTest.php +++ b/tests/PayPal/Test/Api/AddressTest.php @@ -1,59 +1,108 @@ setLine1(self::$line1); - $addr->setLine2(self::$line2); - $addr->setCity(self::$city); - $addr->setState(self::$state); - $addr->setPostalCode(self::$postalCode); - $addr->setCountryCode(self::$countryCode); - $addr->setPhone(self::$phone); - return $addr; + return '{"line1":"TestSample","line2":"TestSample","city":"TestSample","country_code":"TestSample","postal_code":"TestSample","state":"TestSample","phone":"TestSample"}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return Address + */ + public static function getObject() { - $this->address = self::createAddress(); + return new Address(self::getJson()); } - public function testGetterSetter() + + /** + * Tests for Serialization and Deserialization Issues + * @return Address + */ + public function testSerializationDeserialization() { - $this->assertEquals(self::$line1, $this->address->getLine1()); - $this->assertEquals(self::$line2, $this->address->getLine2()); - $this->assertEquals(self::$city, $this->address->getCity()); - $this->assertEquals(self::$state, $this->address->getState()); - $this->assertEquals(self::$postalCode, $this->address->getPostalCode()); - $this->assertEquals(self::$countryCode, $this->address->getCountryCode()); - $this->assertEquals(self::$phone, $this->address->getPhone()); + $obj = new Address(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getLine1()); + $this->assertNotNull($obj->getLine2()); + $this->assertNotNull($obj->getCity()); + $this->assertNotNull($obj->getCountryCode()); + $this->assertNotNull($obj->getPostalCode()); + $this->assertNotNull($obj->getState()); + $this->assertNotNull($obj->getPhone()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param Address $obj + */ + public function testGetters($obj) { - $a1 = $this->address; - - $a2 = new Address(); - $a2->fromJson($a1->toJson()); - - $this->assertEquals($a1, $a2); + $this->assertEquals($obj->getLine1(), "TestSample"); + $this->assertEquals($obj->getLine2(), "TestSample"); + $this->assertEquals($obj->getCity(), "TestSample"); + $this->assertEquals($obj->getCountryCode(), "TestSample"); + $this->assertEquals($obj->getPostalCode(), "TestSample"); + $this->assertEquals($obj->getState(), "TestSample"); + $this->assertEquals($obj->getPhone(), "TestSample"); } + + /** + * @depends testSerializationDeserialization + * @param Address $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCountry_code(), "TestSample"); + $this->assertEquals($obj->getPostal_code(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param Address $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Country_code + $obj->setCountryCode(null); + $this->assertNull($obj->getCountry_code()); + $this->assertNull($obj->getCountryCode()); + $this->assertSame($obj->getCountryCode(), $obj->getCountry_code()); + $obj->setCountry_code("TestSample"); + $this->assertEquals($obj->getCountry_code(), "TestSample"); + + // Check for Postal_code + $obj->setPostalCode(null); + $this->assertNull($obj->getPostal_code()); + $this->assertNull($obj->getPostalCode()); + $this->assertSame($obj->getPostalCode(), $obj->getPostal_code()); + $obj->setPostal_code("TestSample"); + $this->assertEquals($obj->getPostal_code(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + } diff --git a/tests/PayPal/Test/Api/AgreementStateDescriptorTest.php b/tests/PayPal/Test/Api/AgreementStateDescriptorTest.php new file mode 100644 index 0000000..08e7a2c --- /dev/null +++ b/tests/PayPal/Test/Api/AgreementStateDescriptorTest.php @@ -0,0 +1,80 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getNote()); + $this->assertNotNull($obj->getAmount()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param AgreementStateDescriptor $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getNote(), "TestSample"); + $this->assertEquals($obj->getAmount(), CurrencyTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param AgreementStateDescriptor $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param AgreementStateDescriptor $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/AgreementTest.php b/tests/PayPal/Test/Api/AgreementTest.php new file mode 100644 index 0000000..5e9a63f --- /dev/null +++ b/tests/PayPal/Test/Api/AgreementTest.php @@ -0,0 +1,367 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getState()); + $this->assertNotNull($obj->getName()); + $this->assertNotNull($obj->getDescription()); + $this->assertNotNull($obj->getStartDate()); + $this->assertNotNull($obj->getPayer()); + $this->assertNotNull($obj->getShippingAddress()); + $this->assertNotNull($obj->getOverrideMerchantPreferences()); + $this->assertNotNull($obj->getOverrideChargeModels()); + $this->assertNotNull($obj->getPlan()); + $this->assertNotNull($obj->getCreateTime()); + $this->assertNotNull($obj->getUpdateTime()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param Agreement $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getState(), "TestSample"); + $this->assertEquals($obj->getName(), "TestSample"); + $this->assertEquals($obj->getDescription(), "TestSample"); + $this->assertEquals($obj->getStartDate(), "TestSample"); + $this->assertEquals($obj->getPayer(), PayerTest::getObject()); + $this->assertEquals($obj->getShippingAddress(), AddressTest::getObject()); + $this->assertEquals($obj->getOverrideMerchantPreferences(), MerchantPreferencesTest::getObject()); + $this->assertEquals($obj->getOverrideChargeModels(), OverrideChargeModelTest::getObject()); + $this->assertEquals($obj->getPlan(), PlanTest::getObject()); + $this->assertEquals($obj->getCreateTime(), "TestSample"); + $this->assertEquals($obj->getUpdateTime(), "TestSample"); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param Agreement $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getStart_date(), "TestSample"); + $this->assertEquals($obj->getShipping_address(), AddressTest::getObject()); + $this->assertEquals($obj->getOverride_merchant_preferences(), MerchantPreferencesTest::getObject()); + $this->assertEquals($obj->getOverride_charge_models(), OverrideChargeModelTest::getObject()); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param Agreement $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Start_date + $obj->setStartDate(null); + $this->assertNull($obj->getStart_date()); + $this->assertNull($obj->getStartDate()); + $this->assertSame($obj->getStartDate(), $obj->getStart_date()); + $obj->setStart_date("TestSample"); + $this->assertEquals($obj->getStart_date(), "TestSample"); + + // Check for Shipping_address + $obj->setShippingAddress(null); + $this->assertNull($obj->getShipping_address()); + $this->assertNull($obj->getShippingAddress()); + $this->assertSame($obj->getShippingAddress(), $obj->getShipping_address()); + $obj->setShipping_address(AddressTest::getObject()); + $this->assertEquals($obj->getShipping_address(), AddressTest::getObject()); + + // Check for Override_merchant_preferences + $obj->setOverrideMerchantPreferences(null); + $this->assertNull($obj->getOverride_merchant_preferences()); + $this->assertNull($obj->getOverrideMerchantPreferences()); + $this->assertSame($obj->getOverrideMerchantPreferences(), $obj->getOverride_merchant_preferences()); + $obj->setOverride_merchant_preferences(MerchantPreferencesTest::getObject()); + $this->assertEquals($obj->getOverride_merchant_preferences(), MerchantPreferencesTest::getObject()); + + // Check for Override_charge_models + $obj->setOverrideChargeModels(null); + $this->assertNull($obj->getOverride_charge_models()); + $this->assertNull($obj->getOverrideChargeModels()); + $this->assertSame($obj->getOverrideChargeModels(), $obj->getOverride_charge_models()); + $obj->setOverride_charge_models(OverrideChargeModelTest::getObject()); + $this->assertEquals($obj->getOverride_charge_models(), OverrideChargeModelTest::getObject()); + + // Check for Create_time + $obj->setCreateTime(null); + $this->assertNull($obj->getCreate_time()); + $this->assertNull($obj->getCreateTime()); + $this->assertSame($obj->getCreateTime(), $obj->getCreate_time()); + $obj->setCreate_time("TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + + // Check for Update_time + $obj->setUpdateTime(null); + $this->assertNull($obj->getUpdate_time()); + $this->assertNull($obj->getUpdateTime()); + $this->assertSame($obj->getUpdateTime(), $obj->getUpdate_time()); + $obj->setUpdate_time("TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testCreate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->create($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testExecute($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->execute("123123", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + AgreementTest::getJson() + )); + + $result = $obj->get("agreementId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testUpdate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + $patchRequest = PatchRequestTest::getObject(); + + $result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testSuspend($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + $agreementStateDescriptor = AgreementStateDescriptorTest::getObject(); + + $result = $obj->suspend($agreementStateDescriptor, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testReActivate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + $agreementStateDescriptor = AgreementStateDescriptorTest::getObject(); + + $result = $obj->reActivate($agreementStateDescriptor, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testCancel($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + $agreementStateDescriptor = AgreementStateDescriptorTest::getObject(); + + $result = $obj->cancel($agreementStateDescriptor, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testBillBalance($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + $agreementStateDescriptor = AgreementStateDescriptorTest::getObject(); + + $result = $obj->billBalance($agreementStateDescriptor, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testSetBalance($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + $currency = CurrencyTest::getObject(); + + $result = $obj->setBalance($currency, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Agreement $obj + */ + public function testTransactions($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + AgreementTransactionsTest::getJson() + )); + + $result = $obj->transactions("agreementId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +} diff --git a/tests/PayPal/Test/Api/AgreementTransactionTest.php b/tests/PayPal/Test/Api/AgreementTransactionTest.php new file mode 100644 index 0000000..a59b61d --- /dev/null +++ b/tests/PayPal/Test/Api/AgreementTransactionTest.php @@ -0,0 +1,168 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getTransactionId()); + $this->assertNotNull($obj->getStatus()); + $this->assertNotNull($obj->getTransactionType()); + $this->assertNotNull($obj->getAmount()); + $this->assertNotNull($obj->getFeeAmount()); + $this->assertNotNull($obj->getNetAmount()); + $this->assertNotNull($obj->getPayerEmail()); + $this->assertNotNull($obj->getPayerName()); + $this->assertNotNull($obj->getTimeUpdated()); + $this->assertNotNull($obj->getTimeZone()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param AgreementTransaction $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getTransactionId(), "TestSample"); + $this->assertEquals($obj->getStatus(), "TestSample"); + $this->assertEquals($obj->getTransactionType(), "TestSample"); + $this->assertEquals($obj->getAmount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getFeeAmount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getNetAmount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getPayerEmail(), "TestSample"); + $this->assertEquals($obj->getPayerName(), "TestSample"); + $this->assertEquals($obj->getTimeUpdated(), "TestSample"); + $this->assertEquals($obj->getTimeZone(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param AgreementTransaction $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getTransaction_id(), "TestSample"); + $this->assertEquals($obj->getTransaction_type(), "TestSample"); + $this->assertEquals($obj->getFee_amount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getNet_amount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getPayer_email(), "TestSample"); + $this->assertEquals($obj->getPayer_name(), "TestSample"); + $this->assertEquals($obj->getTime_updated(), "TestSample"); + $this->assertEquals($obj->getTime_zone(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param AgreementTransaction $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Transaction_id + $obj->setTransactionId(null); + $this->assertNull($obj->getTransaction_id()); + $this->assertNull($obj->getTransactionId()); + $this->assertSame($obj->getTransactionId(), $obj->getTransaction_id()); + $obj->setTransaction_id("TestSample"); + $this->assertEquals($obj->getTransaction_id(), "TestSample"); + + // Check for Transaction_type + $obj->setTransactionType(null); + $this->assertNull($obj->getTransaction_type()); + $this->assertNull($obj->getTransactionType()); + $this->assertSame($obj->getTransactionType(), $obj->getTransaction_type()); + $obj->setTransaction_type("TestSample"); + $this->assertEquals($obj->getTransaction_type(), "TestSample"); + + // Check for Fee_amount + $obj->setFeeAmount(null); + $this->assertNull($obj->getFee_amount()); + $this->assertNull($obj->getFeeAmount()); + $this->assertSame($obj->getFeeAmount(), $obj->getFee_amount()); + $obj->setFee_amount(CurrencyTest::getObject()); + $this->assertEquals($obj->getFee_amount(), CurrencyTest::getObject()); + + // Check for Net_amount + $obj->setNetAmount(null); + $this->assertNull($obj->getNet_amount()); + $this->assertNull($obj->getNetAmount()); + $this->assertSame($obj->getNetAmount(), $obj->getNet_amount()); + $obj->setNet_amount(CurrencyTest::getObject()); + $this->assertEquals($obj->getNet_amount(), CurrencyTest::getObject()); + + // Check for Payer_email + $obj->setPayerEmail(null); + $this->assertNull($obj->getPayer_email()); + $this->assertNull($obj->getPayerEmail()); + $this->assertSame($obj->getPayerEmail(), $obj->getPayer_email()); + $obj->setPayer_email("TestSample"); + $this->assertEquals($obj->getPayer_email(), "TestSample"); + + // Check for Payer_name + $obj->setPayerName(null); + $this->assertNull($obj->getPayer_name()); + $this->assertNull($obj->getPayerName()); + $this->assertSame($obj->getPayerName(), $obj->getPayer_name()); + $obj->setPayer_name("TestSample"); + $this->assertEquals($obj->getPayer_name(), "TestSample"); + + // Check for Time_updated + $obj->setTimeUpdated(null); + $this->assertNull($obj->getTime_updated()); + $this->assertNull($obj->getTimeUpdated()); + $this->assertSame($obj->getTimeUpdated(), $obj->getTime_updated()); + $obj->setTime_updated("TestSample"); + $this->assertEquals($obj->getTime_updated(), "TestSample"); + + // Check for Time_zone + $obj->setTimeZone(null); + $this->assertNull($obj->getTime_zone()); + $this->assertNull($obj->getTimeZone()); + $this->assertSame($obj->getTimeZone(), $obj->getTime_zone()); + $obj->setTime_zone("TestSample"); + $this->assertEquals($obj->getTime_zone(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/AgreementTransactionsTest.php b/tests/PayPal/Test/Api/AgreementTransactionsTest.php new file mode 100644 index 0000000..11457f0 --- /dev/null +++ b/tests/PayPal/Test/Api/AgreementTransactionsTest.php @@ -0,0 +1,87 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getAgreementTransactionList()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param AgreementTransactions $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getAgreementTransactionList(), AgreementTransactionTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param AgreementTransactions $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getAgreement_transaction_list(), AgreementTransactionTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param AgreementTransactions $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Agreement_transaction_list + $obj->setAgreementTransactionList(null); + $this->assertNull($obj->getAgreement_transaction_list()); + $this->assertNull($obj->getAgreementTransactionList()); + $this->assertSame($obj->getAgreementTransactionList(), $obj->getAgreement_transaction_list()); + $obj->setAgreement_transaction_list(AgreementTransactionTest::getObject()); + $this->assertEquals($obj->getAgreement_transaction_list(), AgreementTransactionTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/AuthorizationTest.php b/tests/PayPal/Test/Api/AuthorizationTest.php index 4b55a48..111657c 100644 --- a/tests/PayPal/Test/Api/AuthorizationTest.php +++ b/tests/PayPal/Test/Api/AuthorizationTest.php @@ -41,7 +41,7 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase $authorization->setClearingTime(self::$clearing_time); $authorization->setAmount(AmountTest::createAmount()); - $authorization->setLinks(array(LinksTest::createLinks())); + $authorization->setLinks(array(LinksTest::getObject())); return $authorization; } diff --git a/tests/PayPal/Test/Api/BankAccountTest.php b/tests/PayPal/Test/Api/BankAccountTest.php new file mode 100644 index 0000000..dd8814b --- /dev/null +++ b/tests/PayPal/Test/Api/BankAccountTest.php @@ -0,0 +1,404 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getAccountNumber()); + $this->assertNotNull($obj->getAccountNumberType()); + $this->assertNotNull($obj->getRoutingNumber()); + $this->assertNotNull($obj->getAccountType()); + $this->assertNotNull($obj->getAccountName()); + $this->assertNotNull($obj->getCheckType()); + $this->assertNotNull($obj->getAuthType()); + $this->assertNotNull($obj->getAuthCaptureTimestamp()); + $this->assertNotNull($obj->getBankName()); + $this->assertNotNull($obj->getCountryCode()); + $this->assertNotNull($obj->getFirstName()); + $this->assertNotNull($obj->getLastName()); + $this->assertNotNull($obj->getBirthDate()); + $this->assertNotNull($obj->getBillingAddress()); + $this->assertNotNull($obj->getState()); + $this->assertNotNull($obj->getConfirmationStatus()); + $this->assertNotNull($obj->getPayerId()); + $this->assertNotNull($obj->getExternalCustomerId()); + $this->assertNotNull($obj->getMerchantId()); + $this->assertNotNull($obj->getCreateTime()); + $this->assertNotNull($obj->getUpdateTime()); + $this->assertNotNull($obj->getValidUntil()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param BankAccount $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getAccountNumber(), "TestSample"); + $this->assertEquals($obj->getAccountNumberType(), "TestSample"); + $this->assertEquals($obj->getRoutingNumber(), "TestSample"); + $this->assertEquals($obj->getAccountType(), "TestSample"); + $this->assertEquals($obj->getAccountName(), "TestSample"); + $this->assertEquals($obj->getCheckType(), "TestSample"); + $this->assertEquals($obj->getAuthType(), "TestSample"); + $this->assertEquals($obj->getAuthCaptureTimestamp(), "TestSample"); + $this->assertEquals($obj->getBankName(), "TestSample"); + $this->assertEquals($obj->getCountryCode(), "TestSample"); + $this->assertEquals($obj->getFirstName(), "TestSample"); + $this->assertEquals($obj->getLastName(), "TestSample"); + $this->assertEquals($obj->getBirthDate(), "TestSample"); + $this->assertEquals($obj->getBillingAddress(), AddressTest::getObject()); + $this->assertEquals($obj->getState(), "TestSample"); + $this->assertEquals($obj->getConfirmationStatus(), "TestSample"); + $this->assertEquals($obj->getPayerId(), "TestSample"); + $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); + $this->assertEquals($obj->getMerchantId(), "TestSample"); + $this->assertEquals($obj->getCreateTime(), "TestSample"); + $this->assertEquals($obj->getUpdateTime(), "TestSample"); + $this->assertEquals($obj->getValidUntil(), "TestSample"); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param BankAccount $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getAccount_number(), "TestSample"); + $this->assertEquals($obj->getAccount_number_type(), "TestSample"); + $this->assertEquals($obj->getRouting_number(), "TestSample"); + $this->assertEquals($obj->getAccount_type(), "TestSample"); + $this->assertEquals($obj->getAccount_name(), "TestSample"); + $this->assertEquals($obj->getCheck_type(), "TestSample"); + $this->assertEquals($obj->getAuth_type(), "TestSample"); + $this->assertEquals($obj->getAuth_capture_timestamp(), "TestSample"); + $this->assertEquals($obj->getBank_name(), "TestSample"); + $this->assertEquals($obj->getCountry_code(), "TestSample"); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + $this->assertEquals($obj->getBirth_date(), "TestSample"); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + $this->assertEquals($obj->getConfirmation_status(), "TestSample"); + $this->assertEquals($obj->getPayer_id(), "TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + $this->assertEquals($obj->getMerchant_id(), "TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + $this->assertEquals($obj->getValid_until(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param BankAccount $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Account_number + $obj->setAccountNumber(null); + $this->assertNull($obj->getAccount_number()); + $this->assertNull($obj->getAccountNumber()); + $this->assertSame($obj->getAccountNumber(), $obj->getAccount_number()); + $obj->setAccount_number("TestSample"); + $this->assertEquals($obj->getAccount_number(), "TestSample"); + + // Check for Account_number_type + $obj->setAccountNumberType(null); + $this->assertNull($obj->getAccount_number_type()); + $this->assertNull($obj->getAccountNumberType()); + $this->assertSame($obj->getAccountNumberType(), $obj->getAccount_number_type()); + $obj->setAccount_number_type("TestSample"); + $this->assertEquals($obj->getAccount_number_type(), "TestSample"); + + // Check for Routing_number + $obj->setRoutingNumber(null); + $this->assertNull($obj->getRouting_number()); + $this->assertNull($obj->getRoutingNumber()); + $this->assertSame($obj->getRoutingNumber(), $obj->getRouting_number()); + $obj->setRouting_number("TestSample"); + $this->assertEquals($obj->getRouting_number(), "TestSample"); + + // Check for Account_type + $obj->setAccountType(null); + $this->assertNull($obj->getAccount_type()); + $this->assertNull($obj->getAccountType()); + $this->assertSame($obj->getAccountType(), $obj->getAccount_type()); + $obj->setAccount_type("TestSample"); + $this->assertEquals($obj->getAccount_type(), "TestSample"); + + // Check for Account_name + $obj->setAccountName(null); + $this->assertNull($obj->getAccount_name()); + $this->assertNull($obj->getAccountName()); + $this->assertSame($obj->getAccountName(), $obj->getAccount_name()); + $obj->setAccount_name("TestSample"); + $this->assertEquals($obj->getAccount_name(), "TestSample"); + + // Check for Check_type + $obj->setCheckType(null); + $this->assertNull($obj->getCheck_type()); + $this->assertNull($obj->getCheckType()); + $this->assertSame($obj->getCheckType(), $obj->getCheck_type()); + $obj->setCheck_type("TestSample"); + $this->assertEquals($obj->getCheck_type(), "TestSample"); + + // Check for Auth_type + $obj->setAuthType(null); + $this->assertNull($obj->getAuth_type()); + $this->assertNull($obj->getAuthType()); + $this->assertSame($obj->getAuthType(), $obj->getAuth_type()); + $obj->setAuth_type("TestSample"); + $this->assertEquals($obj->getAuth_type(), "TestSample"); + + // Check for Auth_capture_timestamp + $obj->setAuthCaptureTimestamp(null); + $this->assertNull($obj->getAuth_capture_timestamp()); + $this->assertNull($obj->getAuthCaptureTimestamp()); + $this->assertSame($obj->getAuthCaptureTimestamp(), $obj->getAuth_capture_timestamp()); + $obj->setAuth_capture_timestamp("TestSample"); + $this->assertEquals($obj->getAuth_capture_timestamp(), "TestSample"); + + // Check for Bank_name + $obj->setBankName(null); + $this->assertNull($obj->getBank_name()); + $this->assertNull($obj->getBankName()); + $this->assertSame($obj->getBankName(), $obj->getBank_name()); + $obj->setBank_name("TestSample"); + $this->assertEquals($obj->getBank_name(), "TestSample"); + + // Check for Country_code + $obj->setCountryCode(null); + $this->assertNull($obj->getCountry_code()); + $this->assertNull($obj->getCountryCode()); + $this->assertSame($obj->getCountryCode(), $obj->getCountry_code()); + $obj->setCountry_code("TestSample"); + $this->assertEquals($obj->getCountry_code(), "TestSample"); + + // Check for First_name + $obj->setFirstName(null); + $this->assertNull($obj->getFirst_name()); + $this->assertNull($obj->getFirstName()); + $this->assertSame($obj->getFirstName(), $obj->getFirst_name()); + $obj->setFirst_name("TestSample"); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + + // Check for Last_name + $obj->setLastName(null); + $this->assertNull($obj->getLast_name()); + $this->assertNull($obj->getLastName()); + $this->assertSame($obj->getLastName(), $obj->getLast_name()); + $obj->setLast_name("TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + + // Check for Birth_date + $obj->setBirthDate(null); + $this->assertNull($obj->getBirth_date()); + $this->assertNull($obj->getBirthDate()); + $this->assertSame($obj->getBirthDate(), $obj->getBirth_date()); + $obj->setBirth_date("TestSample"); + $this->assertEquals($obj->getBirth_date(), "TestSample"); + + // Check for Billing_address + $obj->setBillingAddress(null); + $this->assertNull($obj->getBilling_address()); + $this->assertNull($obj->getBillingAddress()); + $this->assertSame($obj->getBillingAddress(), $obj->getBilling_address()); + $obj->setBilling_address(AddressTest::getObject()); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + + // Check for Confirmation_status + $obj->setConfirmationStatus(null); + $this->assertNull($obj->getConfirmation_status()); + $this->assertNull($obj->getConfirmationStatus()); + $this->assertSame($obj->getConfirmationStatus(), $obj->getConfirmation_status()); + $obj->setConfirmation_status("TestSample"); + $this->assertEquals($obj->getConfirmation_status(), "TestSample"); + + // Check for Payer_id + $obj->setPayerId(null); + $this->assertNull($obj->getPayer_id()); + $this->assertNull($obj->getPayerId()); + $this->assertSame($obj->getPayerId(), $obj->getPayer_id()); + $obj->setPayer_id("TestSample"); + $this->assertEquals($obj->getPayer_id(), "TestSample"); + + // Check for External_customer_id + $obj->setExternalCustomerId(null); + $this->assertNull($obj->getExternal_customer_id()); + $this->assertNull($obj->getExternalCustomerId()); + $this->assertSame($obj->getExternalCustomerId(), $obj->getExternal_customer_id()); + $obj->setExternal_customer_id("TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + + // Check for Merchant_id + $obj->setMerchantId(null); + $this->assertNull($obj->getMerchant_id()); + $this->assertNull($obj->getMerchantId()); + $this->assertSame($obj->getMerchantId(), $obj->getMerchant_id()); + $obj->setMerchant_id("TestSample"); + $this->assertEquals($obj->getMerchant_id(), "TestSample"); + + // Check for Create_time + $obj->setCreateTime(null); + $this->assertNull($obj->getCreate_time()); + $this->assertNull($obj->getCreateTime()); + $this->assertSame($obj->getCreateTime(), $obj->getCreate_time()); + $obj->setCreate_time("TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + + // Check for Update_time + $obj->setUpdateTime(null); + $this->assertNull($obj->getUpdate_time()); + $this->assertNull($obj->getUpdateTime()); + $this->assertSame($obj->getUpdateTime(), $obj->getUpdate_time()); + $obj->setUpdate_time("TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + + // Check for Valid_until + $obj->setValidUntil(null); + $this->assertNull($obj->getValid_until()); + $this->assertNull($obj->getValidUntil()); + $this->assertSame($obj->getValidUntil(), $obj->getValid_until()); + $obj->setValid_until("TestSample"); + $this->assertEquals($obj->getValid_until(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + /** + * @dataProvider mockProvider + * @param BankAccount $obj + */ + public function testCreate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->create($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param BankAccount $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + BankAccountTest::getJson() + )); + + $result = $obj->get("bankAccountId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param BankAccount $obj + */ + public function testDelete($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + + $result = $obj->delete($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param BankAccount $obj + */ + public function testUpdate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + $patchRequest = PatchRequestTest::getObject(); + + $result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +} diff --git a/tests/PayPal/Test/Api/BankAccountsListTest.php b/tests/PayPal/Test/Api/BankAccountsListTest.php new file mode 100644 index 0000000..010498d --- /dev/null +++ b/tests/PayPal/Test/Api/BankAccountsListTest.php @@ -0,0 +1,100 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getBankAccounts()); + $this->assertNotNull($obj->getCount()); + $this->assertNotNull($obj->getNextId()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param BankAccountsList $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getBankAccounts(), BankAccountTest::getObject()); + $this->assertEquals($obj->getCount(), 123); + $this->assertEquals($obj->getNextId(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param BankAccountsList $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getBank_accounts(), BankAccountTest::getObject()); + $this->assertEquals($obj->getNext_id(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param BankAccountsList $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Bank_accounts + $obj->setBankAccounts(null); + $this->assertNull($obj->getBank_accounts()); + $this->assertNull($obj->getBankAccounts()); + $this->assertSame($obj->getBankAccounts(), $obj->getBank_accounts()); + $obj->setBank_accounts(BankAccountTest::getObject()); + $this->assertEquals($obj->getBank_accounts(), BankAccountTest::getObject()); + + // Check for Next_id + $obj->setNextId(null); + $this->assertNull($obj->getNext_id()); + $this->assertNull($obj->getNextId()); + $this->assertSame($obj->getNextId(), $obj->getNext_id()); + $obj->setNext_id("TestSample"); + $this->assertEquals($obj->getNext_id(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/BankTokenTest.php b/tests/PayPal/Test/Api/BankTokenTest.php new file mode 100644 index 0000000..e462af3 --- /dev/null +++ b/tests/PayPal/Test/Api/BankTokenTest.php @@ -0,0 +1,109 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getBankId()); + $this->assertNotNull($obj->getExternalCustomerId()); + $this->assertNotNull($obj->getMandateReferenceNumber()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param BankToken $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getBankId(), "TestSample"); + $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); + $this->assertEquals($obj->getMandateReferenceNumber(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param BankToken $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getBank_id(), "TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + $this->assertEquals($obj->getMandate_reference_number(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param BankToken $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Bank_id + $obj->setBankId(null); + $this->assertNull($obj->getBank_id()); + $this->assertNull($obj->getBankId()); + $this->assertSame($obj->getBankId(), $obj->getBank_id()); + $obj->setBank_id("TestSample"); + $this->assertEquals($obj->getBank_id(), "TestSample"); + + // Check for External_customer_id + $obj->setExternalCustomerId(null); + $this->assertNull($obj->getExternal_customer_id()); + $this->assertNull($obj->getExternalCustomerId()); + $this->assertSame($obj->getExternalCustomerId(), $obj->getExternal_customer_id()); + $obj->setExternal_customer_id("TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + + // Check for Mandate_reference_number + $obj->setMandateReferenceNumber(null); + $this->assertNull($obj->getMandate_reference_number()); + $this->assertNull($obj->getMandateReferenceNumber()); + $this->assertSame($obj->getMandateReferenceNumber(), $obj->getMandate_reference_number()); + $obj->setMandate_reference_number("TestSample"); + $this->assertEquals($obj->getMandate_reference_number(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/CaptureTest.php b/tests/PayPal/Test/Api/CaptureTest.php index 5b31fc8..8cc8748 100644 --- a/tests/PayPal/Test/Api/CaptureTest.php +++ b/tests/PayPal/Test/Api/CaptureTest.php @@ -5,6 +5,7 @@ use PayPal\Api\Capture; use PayPal\Api\Refund; use PayPal\Api\Authorization; use PayPal\Api\Amount; +use PayPal\Exception\PPConnectionException; use PayPal\Test\Constants; class CaptureTest extends \PHPUnit_Framework_TestCase @@ -35,7 +36,7 @@ class CaptureTest extends \PHPUnit_Framework_TestCase $capture = self::createCapture(); $capture->setAmount(AmountTest::createAmount()); - $capture->setLinks(array(LinksTest::createLinks())); + $capture->setLinks(array(LinksTest::getObject())); $this->captures['full'] = $capture; } @@ -48,7 +49,6 @@ class CaptureTest extends \PHPUnit_Framework_TestCase $this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency()); $links = $this->captures['full']->getLinks(); - $this->assertEquals(LinksTest::$href, $links[0]->getHref()); } public function testSerializeDeserialize() @@ -98,4 +98,4 @@ class CaptureTest extends \PHPUnit_Framework_TestCase } } -} \ No newline at end of file +} diff --git a/tests/PayPal/Test/Api/ChargeModelTest.php b/tests/PayPal/Test/Api/ChargeModelTest.php new file mode 100644 index 0000000..be3e005 --- /dev/null +++ b/tests/PayPal/Test/Api/ChargeModelTest.php @@ -0,0 +1,82 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getAmount()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param ChargeModel $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getAmount(), CurrencyTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param ChargeModel $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param ChargeModel $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/CreditCardHistoryTest.php b/tests/PayPal/Test/Api/CreditCardHistoryTest.php index 5134d84..d6b8409 100644 --- a/tests/PayPal/Test/Api/CreditCardHistoryTest.php +++ b/tests/PayPal/Test/Api/CreditCardHistoryTest.php @@ -44,8 +44,8 @@ class CreditCardHistoryTest extends \PHPUnit_Framework_TestCase { $card = self::createCreditCard(); - $card->setBillingAddress(AddressTest::createAddress()); - $card->setLinks(array(LinksTest::createLinks())); + $card->setBillingAddress(AddressTest::getObject()); + $card->setLinks(array(LinksTest::getObject())); $this->cards['full'] = $card; $card = self::createCreditCard(); @@ -73,4 +73,4 @@ class CreditCardHistoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($cardHistory, $cardHistoryCopy); } -} \ No newline at end of file +} diff --git a/tests/PayPal/Test/Api/CreditCardListTest.php b/tests/PayPal/Test/Api/CreditCardListTest.php new file mode 100644 index 0000000..e3467cd --- /dev/null +++ b/tests/PayPal/Test/Api/CreditCardListTest.php @@ -0,0 +1,100 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getCreditCards()); + $this->assertNotNull($obj->getCount()); + $this->assertNotNull($obj->getNextId()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param CreditCardList $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getCreditCards(), CreditCardTest::getObject()); + $this->assertEquals($obj->getCount(), 123); + $this->assertEquals($obj->getNextId(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param CreditCardList $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCredit_cards(), CreditCardTest::getObject()); + $this->assertEquals($obj->getNext_id(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param CreditCardList $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Credit_cards + $obj->setCreditCards(null); + $this->assertNull($obj->getCredit_cards()); + $this->assertNull($obj->getCreditCards()); + $this->assertSame($obj->getCreditCards(), $obj->getCredit_cards()); + $obj->setCredit_cards(CreditCardTest::getObject()); + $this->assertEquals($obj->getCredit_cards(), CreditCardTest::getObject()); + + // Check for Next_id + $obj->setNextId(null); + $this->assertNull($obj->getNext_id()); + $this->assertNull($obj->getNextId()); + $this->assertSame($obj->getNextId(), $obj->getNext_id()); + $obj->setNext_id("TestSample"); + $this->assertEquals($obj->getNext_id(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/CreditCardTest.php b/tests/PayPal/Test/Api/CreditCardTest.php index 31626ce..a10b458 100644 --- a/tests/PayPal/Test/Api/CreditCardTest.php +++ b/tests/PayPal/Test/Api/CreditCardTest.php @@ -1,101 +1,277 @@ setType(self::$cardType); - $card->setNumber(self::$cardNumber); - $card->setExpireMonth(self::$expireMonth); - $card->setExpireYear(self::$expireYear); - $card->setCvv2(self::$cvv); - $card->setFirstName(self::$firstName); - $card->setLastName(self::$lastName); - return $card; - } - - public function setup() - { - - $card = self::createCreditCard(); - $card->setBillingAddress(AddressTest::createAddress()); - $card->setLinks(array(LinksTest::createLinks())); - $this->cards['full'] = $card; - - $card = self::createCreditCard(); - $this->cards['partial'] = $card; - } - - public function testGetterSetters() - { - /** @var CreditCard $c */ - $c = $this->cards['partial']; - $this->assertEquals(self::$cardType, $c->getType()); - $this->assertEquals(self::$cardNumber, $c->getNumber()); - $this->assertEquals(self::$expireMonth, $c->getExpireMonth()); - $this->assertEquals(self::$expireYear, $c->getExpireYear()); - $this->assertEquals(self::$cvv, $c->getCvv2()); - $this->assertEquals(self::$firstName, $c->getFirstName()); - $this->assertEquals(self::$lastName, $c->getLastName()); - - $c = $this->cards['full']; - $this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1()); - /** @var Links[] $link */ - $link = $c->getLinks(); - $this->assertEquals(LinksTest::$href, $link[0]->getHref()); - } - - public function testSerializeDeserialize() - { - /** @var CreditCard $c1 */ - $c1 = $this->cards['full']; - $json = $c1->toJson(); - - $c2 = new CreditCard(); - $c2->fromJson($json); - - $this->assertEquals($c1, $c2); + return '{"id":"TestSample","number":"TestSample","type":"TestSample","expire_month":123,"expire_year":123,"cvv2":123,"first_name":"TestSample","last_name":"TestSample","billing_address":' .AddressTest::getJson() . ',"external_customer_id":"TestSample","state":"TestSample","valid_until":"TestSample","create_time":"TestSample","update_time":"TestSample"}'; } /** - * @group integration + * Gets Object Instance with Json data filled in + * @return CreditCard */ - public function testOperations() + public static function getObject() { - /** @var CreditCard $c1 */ - $c1 = $this->cards['full']; - - $c1->create(); - $this->assertNotNull($c1->getId()); - - - $c2 = CreditCard::get($c1->getId()); - $this->assertEquals($c1->getBillingAddress(), $c2->getBillingAddress()); - $this->assertGreaterThan(0, count($c2->getLinks())); - $this->assertEquals(self::$cardType, $c2->getType()); - $this->assertNotNull($c2->getState()); - $this->assertEquals(true, $c2->delete()); + return new CreditCard(self::getJson()); } -} \ No newline at end of file + + + /** + * Tests for Serialization and Deserialization Issues + * @return CreditCard + */ + public function testSerializationDeserialization() + { + $obj = new CreditCard(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getNumber()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getExpireMonth()); + $this->assertNotNull($obj->getExpireYear()); + $this->assertNotNull($obj->getCvv2()); + $this->assertNotNull($obj->getFirstName()); + $this->assertNotNull($obj->getLastName()); + $this->assertNotNull($obj->getBillingAddress()); + $this->assertNotNull($obj->getExternalCustomerId()); + $this->assertNotNull($obj->getState()); + $this->assertNotNull($obj->getValidUntil()); + $this->assertNotNull($obj->getCreateTime()); + $this->assertNotNull($obj->getUpdateTime()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param CreditCard $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getNumber(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getExpireMonth(), 123); + $this->assertEquals($obj->getExpireYear(), 123); + $this->assertEquals($obj->getCvv2(), 123); + $this->assertEquals($obj->getFirstName(), "TestSample"); + $this->assertEquals($obj->getLastName(), "TestSample"); + $this->assertEquals($obj->getBillingAddress(), AddressTest::getObject()); + $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); + $this->assertEquals($obj->getState(), "TestSample"); + $this->assertEquals($obj->getValidUntil(), "TestSample"); + $this->assertEquals($obj->getCreateTime(), "TestSample"); + $this->assertEquals($obj->getUpdateTime(), "TestSample"); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param CreditCard $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getExpire_month(), 123); + $this->assertEquals($obj->getExpire_year(), 123); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + $this->assertEquals($obj->getValid_until(), "TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param CreditCard $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Expire_month + $obj->setExpireMonth(null); + $this->assertNull($obj->getExpire_month()); + $this->assertNull($obj->getExpireMonth()); + $this->assertSame($obj->getExpireMonth(), $obj->getExpire_month()); + $obj->setExpire_month(123); + $this->assertEquals($obj->getExpire_month(), 123); + + // Check for Expire_year + $obj->setExpireYear(null); + $this->assertNull($obj->getExpire_year()); + $this->assertNull($obj->getExpireYear()); + $this->assertSame($obj->getExpireYear(), $obj->getExpire_year()); + $obj->setExpire_year(123); + $this->assertEquals($obj->getExpire_year(), 123); + + // Check for First_name + $obj->setFirstName(null); + $this->assertNull($obj->getFirst_name()); + $this->assertNull($obj->getFirstName()); + $this->assertSame($obj->getFirstName(), $obj->getFirst_name()); + $obj->setFirst_name("TestSample"); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + + // Check for Last_name + $obj->setLastName(null); + $this->assertNull($obj->getLast_name()); + $this->assertNull($obj->getLastName()); + $this->assertSame($obj->getLastName(), $obj->getLast_name()); + $obj->setLast_name("TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + + // Check for Billing_address + $obj->setBillingAddress(null); + $this->assertNull($obj->getBilling_address()); + $this->assertNull($obj->getBillingAddress()); + $this->assertSame($obj->getBillingAddress(), $obj->getBilling_address()); + $obj->setBilling_address(AddressTest::getObject()); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + + // Check for External_customer_id + $obj->setExternalCustomerId(null); + $this->assertNull($obj->getExternal_customer_id()); + $this->assertNull($obj->getExternalCustomerId()); + $this->assertSame($obj->getExternalCustomerId(), $obj->getExternal_customer_id()); + $obj->setExternal_customer_id("TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + + // Check for Valid_until + $obj->setValidUntil(null); + $this->assertNull($obj->getValid_until()); + $this->assertNull($obj->getValidUntil()); + $this->assertSame($obj->getValidUntil(), $obj->getValid_until()); + $obj->setValid_until("TestSample"); + $this->assertEquals($obj->getValid_until(), "TestSample"); + + // Check for Create_time + $obj->setCreateTime(null); + $this->assertNull($obj->getCreate_time()); + $this->assertNull($obj->getCreateTime()); + $this->assertSame($obj->getCreateTime(), $obj->getCreate_time()); + $obj->setCreate_time("TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + + // Check for Update_time + $obj->setUpdateTime(null); + $this->assertNull($obj->getUpdate_time()); + $this->assertNull($obj->getUpdateTime()); + $this->assertSame($obj->getUpdateTime(), $obj->getUpdate_time()); + $obj->setUpdate_time("TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testCreate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->create($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + CreditCardTest::getJson() + )); + + $result = $obj->get("creditCardId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testDelete($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + + $result = $obj->delete($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param CreditCard $obj + */ + public function testUpdate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->update($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +} diff --git a/tests/PayPal/Test/Api/CreditCardTokenTest.php b/tests/PayPal/Test/Api/CreditCardTokenTest.php index 43a49dd..24abf6e 100644 --- a/tests/PayPal/Test/Api/CreditCardTokenTest.php +++ b/tests/PayPal/Test/Api/CreditCardTokenTest.php @@ -1,43 +1,124 @@ setPayerId(self::$payerId); - $ccToken->setCreditCardId(self::$creditCardId); - return $ccToken; + return '{"credit_card_id":"TestSample","payer_id":"TestSample","last4":"TestSample","type":"TestSample","expire_month":123,"expire_year":123}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return CreditCardToken + */ + public static function getObject() { - $this->ccToken = self::createCreditCardToken(); + return new CreditCardToken(self::getJson()); } - public function testGetterSetter() + + /** + * Tests for Serialization and Deserialization Issues + * @return CreditCardToken + */ + public function testSerializationDeserialization() { - $this->assertEquals(self::$payerId, $this->ccToken->getPayerId()); - $this->assertEquals(self::$creditCardId, $this->ccToken->getCreditCardId()); + $obj = new CreditCardToken(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getCreditCardId()); + $this->assertNotNull($obj->getPayerId()); + $this->assertNotNull($obj->getLast4()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getExpireMonth()); + $this->assertNotNull($obj->getExpireYear()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param CreditCardToken $obj + */ + public function testGetters($obj) { - $t1 = $this->ccToken; - - $t2 = new CreditCardToken(); - $t2->fromJson($t1->toJson()); - - $this->assertEquals($t1, $t2); + $this->assertEquals($obj->getCreditCardId(), "TestSample"); + $this->assertEquals($obj->getPayerId(), "TestSample"); + $this->assertEquals($obj->getLast4(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getExpireMonth(), 123); + $this->assertEquals($obj->getExpireYear(), 123); } -} \ No newline at end of file + + /** + * @depends testSerializationDeserialization + * @param CreditCardToken $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCredit_card_id(), "TestSample"); + $this->assertEquals($obj->getPayer_id(), "TestSample"); + $this->assertEquals($obj->getExpire_month(), 123); + $this->assertEquals($obj->getExpire_year(), 123); + } + + /** + * @depends testSerializationDeserialization + * @param CreditCardToken $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Credit_card_id + $obj->setCreditCardId(null); + $this->assertNull($obj->getCredit_card_id()); + $this->assertNull($obj->getCreditCardId()); + $this->assertSame($obj->getCreditCardId(), $obj->getCredit_card_id()); + $obj->setCredit_card_id("TestSample"); + $this->assertEquals($obj->getCredit_card_id(), "TestSample"); + + // Check for Payer_id + $obj->setPayerId(null); + $this->assertNull($obj->getPayer_id()); + $this->assertNull($obj->getPayerId()); + $this->assertSame($obj->getPayerId(), $obj->getPayer_id()); + $obj->setPayer_id("TestSample"); + $this->assertEquals($obj->getPayer_id(), "TestSample"); + + // Check for Expire_month + $obj->setExpireMonth(null); + $this->assertNull($obj->getExpire_month()); + $this->assertNull($obj->getExpireMonth()); + $this->assertSame($obj->getExpireMonth(), $obj->getExpire_month()); + $obj->setExpire_month(123); + $this->assertEquals($obj->getExpire_month(), 123); + + // Check for Expire_year + $obj->setExpireYear(null); + $this->assertNull($obj->getExpire_year()); + $this->assertNull($obj->getExpireYear()); + $this->assertSame($obj->getExpireYear(), $obj->getExpire_year()); + $obj->setExpire_year(123); + $this->assertEquals($obj->getExpire_year(), 123); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/CreditTest.php b/tests/PayPal/Test/Api/CreditTest.php new file mode 100644 index 0000000..419cb80 --- /dev/null +++ b/tests/PayPal/Test/Api/CreditTest.php @@ -0,0 +1,82 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getTerms()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param Credit $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getTerms(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param Credit $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param Credit $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/CurrencyTest.php b/tests/PayPal/Test/Api/CurrencyTest.php new file mode 100644 index 0000000..218618e --- /dev/null +++ b/tests/PayPal/Test/Api/CurrencyTest.php @@ -0,0 +1,80 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getCurrency()); + $this->assertNotNull($obj->getValue()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param Currency $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getCurrency(), "TestSample"); + $this->assertEquals($obj->getValue(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param Currency $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param Currency $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/ExtendedBankAccountTest.php b/tests/PayPal/Test/Api/ExtendedBankAccountTest.php new file mode 100644 index 0000000..533006c --- /dev/null +++ b/tests/PayPal/Test/Api/ExtendedBankAccountTest.php @@ -0,0 +1,87 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getMandateReferenceNumber()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param ExtendedBankAccount $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getMandateReferenceNumber(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param ExtendedBankAccount $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getMandate_reference_number(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param ExtendedBankAccount $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Mandate_reference_number + $obj->setMandateReferenceNumber(null); + $this->assertNull($obj->getMandate_reference_number()); + $this->assertNull($obj->getMandateReferenceNumber()); + $this->assertSame($obj->getMandateReferenceNumber(), $obj->getMandate_reference_number()); + $obj->setMandate_reference_number("TestSample"); + $this->assertEquals($obj->getMandate_reference_number(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/FundingInstrumentTest.php b/tests/PayPal/Test/Api/FundingInstrumentTest.php index 6fe8c8b..1844cd9 100644 --- a/tests/PayPal/Test/Api/FundingInstrumentTest.php +++ b/tests/PayPal/Test/Api/FundingInstrumentTest.php @@ -2,40 +2,143 @@ namespace PayPal\Test\Api; +use PayPal\Common\PPModel; use PayPal\Api\FundingInstrument; -use PayPal\Test\Constants; +/** + * Class FundingInstrument + * + * @package PayPal\Test\Api + */ class FundingInstrumentTest extends \PHPUnit_Framework_TestCase { - - private $fi; - - public static function createFundingInstrument() + /** + * Gets Json String of Object FundingInstrument + * @return string + */ + public static function getJson() { - $fi = new FundingInstrument(); - $fi->setCreditCard(CreditCardTest::createCreditCard()); - $fi->setCreditCardToken(CreditCardTokenTest::createCreditCardToken()); - return $fi; + return '{"credit_card":' .CreditCardTest::getJson() . ',"credit_card_token":' .CreditCardTokenTest::getJson() . ',"payment_card":' .PaymentCardTest::getJson() . ',"payment_card_token":' .PaymentCardTokenTest::getJson() . ',"bank_account":' .ExtendedBankAccountTest::getJson() . ',"bank_account_token":' .BankTokenTest::getJson() . ',"credit":' .CreditTest::getJson() . '}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return FundingInstrument + */ + public static function getObject() { - $this->fi = self::createFundingInstrument(); + return new FundingInstrument(self::getJson()); } - public function testGetterSetter() + + /** + * Tests for Serialization and Deserialization Issues + * @return FundingInstrument + */ + public function testSerializationDeserialization() { - $this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCreditCard()->getNumber()); - $this->assertEquals(CreditCardTokenTest::$creditCardId, - $this->fi->getCreditCardToken()->getCreditCardId()); + $obj = new FundingInstrument(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getCreditCard()); + $this->assertNotNull($obj->getCreditCardToken()); + $this->assertNotNull($obj->getPaymentCard()); + $this->assertNotNull($obj->getPaymentCardToken()); + $this->assertNotNull($obj->getBankAccount()); + $this->assertNotNull($obj->getBankAccountToken()); + $this->assertNotNull($obj->getCredit()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param FundingInstrument $obj + */ + public function testGetters($obj) { - $fi1 = $this->fi; - - $fi2 = new FundingInstrument(); - $fi2->fromJson($fi1->toJson()); - $this->assertEquals($fi1, $fi2); + $this->assertEquals($obj->getCreditCard(), CreditCardTest::getObject()); + $this->assertEquals($obj->getCreditCardToken(), CreditCardTokenTest::getObject()); + $this->assertEquals($obj->getPaymentCard(), PaymentCardTest::getObject()); + $this->assertEquals($obj->getPaymentCardToken(), PaymentCardTokenTest::getObject()); + $this->assertEquals($obj->getBankAccount(), ExtendedBankAccountTest::getObject()); + $this->assertEquals($obj->getBankAccountToken(), BankTokenTest::getObject()); + $this->assertEquals($obj->getCredit(), CreditTest::getObject()); } -} \ No newline at end of file + + /** + * @depends testSerializationDeserialization + * @param FundingInstrument $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCredit_card(), CreditCardTest::getObject()); + $this->assertEquals($obj->getCredit_card_token(), CreditCardTokenTest::getObject()); + $this->assertEquals($obj->getPayment_card(), PaymentCardTest::getObject()); + $this->assertEquals($obj->getPayment_card_token(), PaymentCardTokenTest::getObject()); + $this->assertEquals($obj->getBank_account(), ExtendedBankAccountTest::getObject()); + $this->assertEquals($obj->getBank_account_token(), BankTokenTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param FundingInstrument $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Credit_card + $obj->setCreditCard(null); + $this->assertNull($obj->getCredit_card()); + $this->assertNull($obj->getCreditCard()); + $this->assertSame($obj->getCreditCard(), $obj->getCredit_card()); + $obj->setCredit_card(CreditCardTest::getObject()); + $this->assertEquals($obj->getCredit_card(), CreditCardTest::getObject()); + + // Check for Credit_card_token + $obj->setCreditCardToken(null); + $this->assertNull($obj->getCredit_card_token()); + $this->assertNull($obj->getCreditCardToken()); + $this->assertSame($obj->getCreditCardToken(), $obj->getCredit_card_token()); + $obj->setCredit_card_token(CreditCardTokenTest::getObject()); + $this->assertEquals($obj->getCredit_card_token(), CreditCardTokenTest::getObject()); + + // Check for Payment_card + $obj->setPaymentCard(null); + $this->assertNull($obj->getPayment_card()); + $this->assertNull($obj->getPaymentCard()); + $this->assertSame($obj->getPaymentCard(), $obj->getPayment_card()); + $obj->setPayment_card(PaymentCardTest::getObject()); + $this->assertEquals($obj->getPayment_card(), PaymentCardTest::getObject()); + + // Check for Payment_card_token + $obj->setPaymentCardToken(null); + $this->assertNull($obj->getPayment_card_token()); + $this->assertNull($obj->getPaymentCardToken()); + $this->assertSame($obj->getPaymentCardToken(), $obj->getPayment_card_token()); + $obj->setPayment_card_token(PaymentCardTokenTest::getObject()); + $this->assertEquals($obj->getPayment_card_token(), PaymentCardTokenTest::getObject()); + + // Check for Bank_account + $obj->setBankAccount(null); + $this->assertNull($obj->getBank_account()); + $this->assertNull($obj->getBankAccount()); + $this->assertSame($obj->getBankAccount(), $obj->getBank_account()); + $obj->setBank_account(ExtendedBankAccountTest::getObject()); + $this->assertEquals($obj->getBank_account(), ExtendedBankAccountTest::getObject()); + + // Check for Bank_account_token + $obj->setBankAccountToken(null); + $this->assertNull($obj->getBank_account_token()); + $this->assertNull($obj->getBankAccountToken()); + $this->assertSame($obj->getBankAccountToken(), $obj->getBank_account_token()); + $obj->setBank_account_token(BankTokenTest::getObject()); + $this->assertEquals($obj->getBank_account_token(), BankTokenTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/HyperSchemaTest.php b/tests/PayPal/Test/Api/HyperSchemaTest.php new file mode 100644 index 0000000..6a8a724 --- /dev/null +++ b/tests/PayPal/Test/Api/HyperSchemaTest.php @@ -0,0 +1,88 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getLinks()); + $this->assertNotNull($obj->getFragmentResolution()); + $this->assertNotNull($obj->getReadonly()); + $this->assertNotNull($obj->getContentEncoding()); + $this->assertNotNull($obj->getPathStart()); + $this->assertNotNull($obj->getMediaType()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param HyperSchema $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + $this->assertEquals($obj->getFragmentResolution(), "TestSample"); + $this->assertEquals($obj->getReadonly(), true); + $this->assertEquals($obj->getContentEncoding(), "TestSample"); + $this->assertEquals($obj->getPathStart(), "TestSample"); + $this->assertEquals($obj->getMediaType(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param HyperSchema $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param HyperSchema $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/ItemListTest.php b/tests/PayPal/Test/Api/ItemListTest.php index 6367f4b..df3100a 100644 --- a/tests/PayPal/Test/Api/ItemListTest.php +++ b/tests/PayPal/Test/Api/ItemListTest.php @@ -24,7 +24,7 @@ class ItemListTest extends \PHPUnit_Framework_TestCase $itemList = new ItemList(); $itemList->setItems(array($item)); - $itemList->setShippingAddress(ShippingAddressTest::createAddress()); + $itemList->setShippingAddress(ShippingAddressTest::getObject()); return $itemList; } @@ -38,7 +38,7 @@ class ItemListTest extends \PHPUnit_Framework_TestCase { $items = $this->items->getItems(); $this->assertEquals(ItemTest::createItem(), $items[0]); - $this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShippingAddress()); + $this->assertEquals(ShippingAddressTest::getObject(), $this->items->getShippingAddress()); } public function testSerializeDeserialize() diff --git a/tests/PayPal/Test/Api/LinksTest.php b/tests/PayPal/Test/Api/LinksTest.php index 4c6b441..793826e 100644 --- a/tests/PayPal/Test/Api/LinksTest.php +++ b/tests/PayPal/Test/Api/LinksTest.php @@ -2,44 +2,87 @@ namespace PayPal\Test\Api; +use PayPal\Common\PPModel; use PayPal\Api\Links; -use PayPal\Test\Constants; +/** + * Class Links + * + * @package PayPal\Test\Api + */ class LinksTest extends \PHPUnit_Framework_TestCase { - - private $links; - - public static $href = "USD"; - public static $rel = "1.12"; - public static $method = "1.12"; - - public static function createLinks() + /** + * Gets Json String of Object Links + * @return string + */ + public static function getJson() { - $links = new Links(); - $links->setHref(self::$href); - $links->setRel(self::$rel); - $links->setMethod(self::$method); - - return $links; + return '{"href":"TestSample","rel":"TestSample","targetSchema":' .HyperSchemaTest::getJson() . ',"method":"TestSample","enctype":"TestSample","schema":' .HyperSchemaTest::getJson() . '}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return Links + */ + public static function getObject() { - $this->links = self::createLinks(); + return new Links(self::getJson()); } - public function testGetterSetters() + + /** + * Tests for Serialization and Deserialization Issues + * @return Links + */ + public function testSerializationDeserialization() { - $this->assertEquals(self::$href, $this->links->getHref()); - $this->assertEquals(self::$rel, $this->links->getRel()); - $this->assertEquals(self::$method, $this->links->getMethod()); + $obj = new Links(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getHref()); + $this->assertNotNull($obj->getRel()); + $this->assertNotNull($obj->getTargetSchema()); + $this->assertNotNull($obj->getMethod()); + $this->assertNotNull($obj->getEnctype()); + $this->assertNotNull($obj->getSchema()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param Links $obj + */ + public function testGetters($obj) { - $link2 = new Links(); - $link2->fromJson($this->links->toJSON()); - $this->assertEquals($this->links, $link2); + $this->assertEquals($obj->getHref(), "TestSample"); + $this->assertEquals($obj->getRel(), "TestSample"); + $this->assertEquals($obj->getTargetSchema(), HyperSchemaTest::getObject()); + $this->assertEquals($obj->getMethod(), "TestSample"); + $this->assertEquals($obj->getEnctype(), "TestSample"); + $this->assertEquals($obj->getSchema(), HyperSchemaTest::getObject()); } -} \ No newline at end of file + + /** + * @depends testSerializationDeserialization + * @param Links $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param Links $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/MerchantPreferencesTest.php b/tests/PayPal/Test/Api/MerchantPreferencesTest.php new file mode 100644 index 0000000..f7b925e --- /dev/null +++ b/tests/PayPal/Test/Api/MerchantPreferencesTest.php @@ -0,0 +1,198 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getSetupFee()); + $this->assertNotNull($obj->getCancelUrl()); + $this->assertNotNull($obj->getReturnUrl()); + $this->assertNotNull($obj->getNotifyUrl()); + $this->assertNotNull($obj->getMaxFailAttempts()); + $this->assertNotNull($obj->getAutoBillAmount()); + $this->assertNotNull($obj->getInitialFailAmountAction()); + $this->assertNotNull($obj->getAcceptedPaymentType()); + $this->assertNotNull($obj->getCharSet()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param MerchantPreferences $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getSetupFee(), CurrencyTest::getObject()); + $this->assertEquals($obj->getCancelUrl(), "http://www.google.com"); + $this->assertEquals($obj->getReturnUrl(), "http://www.google.com"); + $this->assertEquals($obj->getNotifyUrl(), "http://www.google.com"); + $this->assertEquals($obj->getMaxFailAttempts(), "TestSample"); + $this->assertEquals($obj->getAutoBillAmount(), "TestSample"); + $this->assertEquals($obj->getInitialFailAmountAction(), "TestSample"); + $this->assertEquals($obj->getAcceptedPaymentType(), "TestSample"); + $this->assertEquals($obj->getCharSet(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param MerchantPreferences $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getSetup_fee(), CurrencyTest::getObject()); + $this->assertEquals($obj->getCancel_url(), "http://www.google.com"); + $this->assertEquals($obj->getReturn_url(), "http://www.google.com"); + $this->assertEquals($obj->getNotify_url(), "http://www.google.com"); + $this->assertEquals($obj->getMax_fail_attempts(), "TestSample"); + $this->assertEquals($obj->getAuto_bill_amount(), "TestSample"); + $this->assertEquals($obj->getInitial_fail_amount_action(), "TestSample"); + $this->assertEquals($obj->getAccepted_payment_type(), "TestSample"); + $this->assertEquals($obj->getChar_set(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param MerchantPreferences $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Setup_fee + $obj->setSetupFee(null); + $this->assertNull($obj->getSetup_fee()); + $this->assertNull($obj->getSetupFee()); + $this->assertSame($obj->getSetupFee(), $obj->getSetup_fee()); + $obj->setSetup_fee(CurrencyTest::getObject()); + $this->assertEquals($obj->getSetup_fee(), CurrencyTest::getObject()); + + // Check for Max_fail_attempts + $obj->setMaxFailAttempts(null); + $this->assertNull($obj->getMax_fail_attempts()); + $this->assertNull($obj->getMaxFailAttempts()); + $this->assertSame($obj->getMaxFailAttempts(), $obj->getMax_fail_attempts()); + $obj->setMax_fail_attempts("TestSample"); + $this->assertEquals($obj->getMax_fail_attempts(), "TestSample"); + + // Check for Auto_bill_amount + $obj->setAutoBillAmount(null); + $this->assertNull($obj->getAuto_bill_amount()); + $this->assertNull($obj->getAutoBillAmount()); + $this->assertSame($obj->getAutoBillAmount(), $obj->getAuto_bill_amount()); + $obj->setAuto_bill_amount("TestSample"); + $this->assertEquals($obj->getAuto_bill_amount(), "TestSample"); + + // Check for Initial_fail_amount_action + $obj->setInitialFailAmountAction(null); + $this->assertNull($obj->getInitial_fail_amount_action()); + $this->assertNull($obj->getInitialFailAmountAction()); + $this->assertSame($obj->getInitialFailAmountAction(), $obj->getInitial_fail_amount_action()); + $obj->setInitial_fail_amount_action("TestSample"); + $this->assertEquals($obj->getInitial_fail_amount_action(), "TestSample"); + + // Check for Accepted_payment_type + $obj->setAcceptedPaymentType(null); + $this->assertNull($obj->getAccepted_payment_type()); + $this->assertNull($obj->getAcceptedPaymentType()); + $this->assertSame($obj->getAcceptedPaymentType(), $obj->getAccepted_payment_type()); + $obj->setAccepted_payment_type("TestSample"); + $this->assertEquals($obj->getAccepted_payment_type(), "TestSample"); + + // Check for Char_set + $obj->setCharSet(null); + $this->assertNull($obj->getChar_set()); + $this->assertNull($obj->getCharSet()); + $this->assertSame($obj->getCharSet(), $obj->getChar_set()); + $obj->setChar_set("TestSample"); + $this->assertEquals($obj->getChar_set(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage CancelUrl is not a fully qualified URL + */ + public function testUrlValidationForCancelUrl() + { + $obj = new MerchantPreferences(); + $obj->setCancelUrl(null); + } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage ReturnUrl is not a fully qualified URL + */ + public function testUrlValidationForReturnUrl() + { + $obj = new MerchantPreferences(); + $obj->setReturnUrl(null); + } + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage NotifyUrl is not a fully qualified URL + */ + public function testUrlValidationForNotifyUrl() + { + $obj = new MerchantPreferences(); + $obj->setNotifyUrl(null); + } + + public function testUrlValidationForCancelUrlDeprecated() + { + $obj = new MerchantPreferences(); + $obj->setCancel_url(null); + $this->assertNull($obj->getCancel_url()); + } + public function testUrlValidationForReturnUrlDeprecated() + { + $obj = new MerchantPreferences(); + $obj->setReturn_url(null); + $this->assertNull($obj->getReturn_url()); + } + public function testUrlValidationForNotifyUrlDeprecated() + { + $obj = new MerchantPreferences(); + $obj->setNotify_url(null); + $this->assertNull($obj->getNotify_url()); + } + +} diff --git a/tests/PayPal/Test/Api/OverrideChargeModelTest.php b/tests/PayPal/Test/Api/OverrideChargeModelTest.php new file mode 100644 index 0000000..c12d22b --- /dev/null +++ b/tests/PayPal/Test/Api/OverrideChargeModelTest.php @@ -0,0 +1,89 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getChargeId()); + $this->assertNotNull($obj->getAmount()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param OverrideChargeModel $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getChargeId(), "TestSample"); + $this->assertEquals($obj->getAmount(), CurrencyTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param OverrideChargeModel $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCharge_id(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param OverrideChargeModel $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Charge_id + $obj->setChargeId(null); + $this->assertNull($obj->getCharge_id()); + $this->assertNull($obj->getChargeId()); + $this->assertSame($obj->getChargeId(), $obj->getCharge_id()); + $obj->setCharge_id("TestSample"); + $this->assertEquals($obj->getCharge_id(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PatchRequestTest.php b/tests/PayPal/Test/Api/PatchRequestTest.php new file mode 100644 index 0000000..6c40b6a --- /dev/null +++ b/tests/PayPal/Test/Api/PatchRequestTest.php @@ -0,0 +1,77 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getPatches()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param PatchRequest $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getPatches(), PatchTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param PatchRequest $obj + */ + public function testDeprecatedGetters($obj) + { + } + + /** + * @depends testSerializationDeserialization + * @param PatchRequest $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PatchTest.php b/tests/PayPal/Test/Api/PatchTest.php index 94ecb08..b9f597c 100644 --- a/tests/PayPal/Test/Api/PatchTest.php +++ b/tests/PayPal/Test/Api/PatchTest.php @@ -18,7 +18,7 @@ class PatchTest extends \PHPUnit_Framework_TestCase */ public static function getJson() { - return json_encode(json_decode('{"op":"TestSample","path":"TestSample","value":"TestSampleObject","from":"TestSample"}')); + return '{"op":"TestSample","path":"TestSample","value":"TestSampleObject","from":"TestSample"}'; } /** diff --git a/tests/PayPal/Test/Api/PayerInfoTest.php b/tests/PayPal/Test/Api/PayerInfoTest.php index 0f21633..49c00ef 100644 --- a/tests/PayPal/Test/Api/PayerInfoTest.php +++ b/tests/PayPal/Test/Api/PayerInfoTest.php @@ -1,55 +1,201 @@ setEmail(self::$email); - $payerInfo->setFirstName(self::$firstName); - $payerInfo->setLastName(self::$lastName); - $payerInfo->setPhone(self::$phone); - $payerInfo->setPayerId(self::$payerId); - $payerInfo->setShippingAddress(ShippingAddressTest::createAddress()); - - return $payerInfo; + return '{"email":"TestSample","external_remember_me_id":"TestSample","buyer_account_number":"TestSample","first_name":"TestSample","last_name":"TestSample","payer_id":"TestSample","phone":"TestSample","phone_type":"TestSample","birth_date":"TestSample","tax_id":"TestSample","tax_id_type":"TestSample","billing_address":' .AddressTest::getJson() . ',"shipping_address":' .ShippingAddressTest::getJson() . '}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return PayerInfo + */ + public static function getObject() { - $this->payerInfo = self::createPayerInfo(); + return new PayerInfo(self::getJson()); } - public function testGetterSetter() + + /** + * Tests for Serialization and Deserialization Issues + * @return PayerInfo + */ + public function testSerializationDeserialization() { - $this->assertEquals(self::$email, $this->payerInfo->getEmail()); - $this->assertEquals(self::$firstName, $this->payerInfo->getFirstName()); - $this->assertEquals(self::$lastName, $this->payerInfo->getLastName()); - $this->assertEquals(self::$phone, $this->payerInfo->getPhone()); - $this->assertEquals(self::$payerId, $this->payerInfo->getPayerId()); - $this->assertEquals(ShippingAddressTest::$line1, $this->payerInfo->getShippingAddress()->getLine1()); + $obj = new PayerInfo(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getEmail()); + $this->assertNotNull($obj->getExternalRememberMeId()); + $this->assertNotNull($obj->getBuyerAccountNumber()); + $this->assertNotNull($obj->getFirstName()); + $this->assertNotNull($obj->getLastName()); + $this->assertNotNull($obj->getPayerId()); + $this->assertNotNull($obj->getPhone()); + $this->assertNotNull($obj->getPhoneType()); + $this->assertNotNull($obj->getBirthDate()); + $this->assertNotNull($obj->getTaxId()); + $this->assertNotNull($obj->getTaxIdType()); + $this->assertNotNull($obj->getBillingAddress()); + $this->assertNotNull($obj->getShippingAddress()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param PayerInfo $obj + */ + public function testGetters($obj) { - $p1 = $this->payerInfo; - - $p2 = new PayerInfo(); - $p2->fromJson($p1->toJson()); - - $this->assertEquals($p1, $p2); + $this->assertEquals($obj->getEmail(), "TestSample"); + $this->assertEquals($obj->getExternalRememberMeId(), "TestSample"); + $this->assertEquals($obj->getBuyerAccountNumber(), "TestSample"); + $this->assertEquals($obj->getFirstName(), "TestSample"); + $this->assertEquals($obj->getLastName(), "TestSample"); + $this->assertEquals($obj->getPayerId(), "TestSample"); + $this->assertEquals($obj->getPhone(), "TestSample"); + $this->assertEquals($obj->getPhoneType(), "TestSample"); + $this->assertEquals($obj->getBirthDate(), "TestSample"); + $this->assertEquals($obj->getTaxId(), "TestSample"); + $this->assertEquals($obj->getTaxIdType(), "TestSample"); + $this->assertEquals($obj->getBillingAddress(), AddressTest::getObject()); + $this->assertEquals($obj->getShippingAddress(), ShippingAddressTest::getObject()); } -} \ No newline at end of file + + /** + * @depends testSerializationDeserialization + * @param PayerInfo $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getExternal_remember_me_id(), "TestSample"); + $this->assertEquals($obj->getBuyer_account_number(), "TestSample"); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + $this->assertEquals($obj->getPayer_id(), "TestSample"); + $this->assertEquals($obj->getPhone_type(), "TestSample"); + $this->assertEquals($obj->getBirth_date(), "TestSample"); + $this->assertEquals($obj->getTax_id(), "TestSample"); + $this->assertEquals($obj->getTax_id_type(), "TestSample"); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + $this->assertEquals($obj->getShipping_address(), ShippingAddressTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param PayerInfo $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for External_remember_me_id + $obj->setExternalRememberMeId(null); + $this->assertNull($obj->getExternal_remember_me_id()); + $this->assertNull($obj->getExternalRememberMeId()); + $this->assertSame($obj->getExternalRememberMeId(), $obj->getExternal_remember_me_id()); + $obj->setExternal_remember_me_id("TestSample"); + $this->assertEquals($obj->getExternal_remember_me_id(), "TestSample"); + + // Check for Buyer_account_number + $obj->setBuyerAccountNumber(null); + $this->assertNull($obj->getBuyer_account_number()); + $this->assertNull($obj->getBuyerAccountNumber()); + $this->assertSame($obj->getBuyerAccountNumber(), $obj->getBuyer_account_number()); + $obj->setBuyer_account_number("TestSample"); + $this->assertEquals($obj->getBuyer_account_number(), "TestSample"); + + // Check for First_name + $obj->setFirstName(null); + $this->assertNull($obj->getFirst_name()); + $this->assertNull($obj->getFirstName()); + $this->assertSame($obj->getFirstName(), $obj->getFirst_name()); + $obj->setFirst_name("TestSample"); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + + // Check for Last_name + $obj->setLastName(null); + $this->assertNull($obj->getLast_name()); + $this->assertNull($obj->getLastName()); + $this->assertSame($obj->getLastName(), $obj->getLast_name()); + $obj->setLast_name("TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + + // Check for Payer_id + $obj->setPayerId(null); + $this->assertNull($obj->getPayer_id()); + $this->assertNull($obj->getPayerId()); + $this->assertSame($obj->getPayerId(), $obj->getPayer_id()); + $obj->setPayer_id("TestSample"); + $this->assertEquals($obj->getPayer_id(), "TestSample"); + + // Check for Phone_type + $obj->setPhoneType(null); + $this->assertNull($obj->getPhone_type()); + $this->assertNull($obj->getPhoneType()); + $this->assertSame($obj->getPhoneType(), $obj->getPhone_type()); + $obj->setPhone_type("TestSample"); + $this->assertEquals($obj->getPhone_type(), "TestSample"); + + // Check for Birth_date + $obj->setBirthDate(null); + $this->assertNull($obj->getBirth_date()); + $this->assertNull($obj->getBirthDate()); + $this->assertSame($obj->getBirthDate(), $obj->getBirth_date()); + $obj->setBirth_date("TestSample"); + $this->assertEquals($obj->getBirth_date(), "TestSample"); + + // Check for Tax_id + $obj->setTaxId(null); + $this->assertNull($obj->getTax_id()); + $this->assertNull($obj->getTaxId()); + $this->assertSame($obj->getTaxId(), $obj->getTax_id()); + $obj->setTax_id("TestSample"); + $this->assertEquals($obj->getTax_id(), "TestSample"); + + // Check for Tax_id_type + $obj->setTaxIdType(null); + $this->assertNull($obj->getTax_id_type()); + $this->assertNull($obj->getTaxIdType()); + $this->assertSame($obj->getTaxIdType(), $obj->getTax_id_type()); + $obj->setTax_id_type("TestSample"); + $this->assertEquals($obj->getTax_id_type(), "TestSample"); + + // Check for Billing_address + $obj->setBillingAddress(null); + $this->assertNull($obj->getBilling_address()); + $this->assertNull($obj->getBillingAddress()); + $this->assertSame($obj->getBillingAddress(), $obj->getBilling_address()); + $obj->setBilling_address(AddressTest::getObject()); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + + // Check for Shipping_address + $obj->setShippingAddress(null); + $this->assertNull($obj->getShipping_address()); + $this->assertNull($obj->getShippingAddress()); + $this->assertSame($obj->getShippingAddress(), $obj->getShipping_address()); + $obj->setShipping_address(ShippingAddressTest::getObject()); + $this->assertEquals($obj->getShipping_address(), ShippingAddressTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PayerTest.php b/tests/PayPal/Test/Api/PayerTest.php index fd32597..f56b32d 100644 --- a/tests/PayPal/Test/Api/PayerTest.php +++ b/tests/PayPal/Test/Api/PayerTest.php @@ -2,49 +2,121 @@ namespace PayPal\Test\Api; -use PayPal\Api\FundingInstrument; - +use PayPal\Common\PPModel; use PayPal\Api\Payer; -use PayPal\Test\Constants; +/** + * Class Payer + * + * @package PayPal\Test\Api + */ class PayerTest extends \PHPUnit_Framework_TestCase { - - private $payer; - - private static $paymentMethod = "credit_card"; - - public static function createPayer() + /** + * Gets Json String of Object Payer + * @return string + */ + public static function getJson() { - $payer = new Payer(); - $payer->setPaymentMethod(self::$paymentMethod); - $payer->setPayerInfo(PayerInfoTest::createPayerInfo()); - $payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument())); - - return $payer; + return '{"payment_method":"TestSample","status":"TestSample","funding_instruments":' .FundingInstrumentTest::getJson() . ',"funding_option_id":"TestSample","payer_info":' .PayerInfoTest::getJson() . '}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return Payer + */ + public static function getObject() { - $this->payer = self::createPayer(); + return new Payer(self::getJson()); } - public function testGetterSetter() - { - $this->assertEquals(self::$paymentMethod, $this->payer->getPaymentMethod()); - $this->assertEquals(PayerInfoTest::$email, $this->payer->getPayerInfo()->getEmail()); - $fi = $this->payer->getFundingInstruments(); - $this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCreditCardToken()->getCreditCardId()); + /** + * Tests for Serialization and Deserialization Issues + * @return Payer + */ + public function testSerializationDeserialization() + { + $obj = new Payer(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getPaymentMethod()); + $this->assertNotNull($obj->getStatus()); + $this->assertNotNull($obj->getFundingInstruments()); + $this->assertNotNull($obj->getFundingOptionId()); + $this->assertNotNull($obj->getPayerInfo()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param Payer $obj + */ + public function testGetters($obj) { - $p1 = $this->payer; - - $p2 = new Payer(); - $p2->fromJson($p1->toJson()); - - $this->assertEquals($p1, $p2); + $this->assertEquals($obj->getPaymentMethod(), "TestSample"); + $this->assertEquals($obj->getStatus(), "TestSample"); + $this->assertEquals($obj->getFundingInstruments(), FundingInstrumentTest::getObject()); + $this->assertEquals($obj->getFundingOptionId(), "TestSample"); + $this->assertEquals($obj->getPayerInfo(), PayerInfoTest::getObject()); } -} \ No newline at end of file + + /** + * @depends testSerializationDeserialization + * @param Payer $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getPayment_method(), "TestSample"); + $this->assertEquals($obj->getFunding_instruments(), FundingInstrumentTest::getObject()); + $this->assertEquals($obj->getFunding_option_id(), "TestSample"); + $this->assertEquals($obj->getPayer_info(), PayerInfoTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param Payer $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Payment_method + $obj->setPaymentMethod(null); + $this->assertNull($obj->getPayment_method()); + $this->assertNull($obj->getPaymentMethod()); + $this->assertSame($obj->getPaymentMethod(), $obj->getPayment_method()); + $obj->setPayment_method("TestSample"); + $this->assertEquals($obj->getPayment_method(), "TestSample"); + + // Check for Funding_instruments + $obj->setFundingInstruments(null); + $this->assertNull($obj->getFunding_instruments()); + $this->assertNull($obj->getFundingInstruments()); + $this->assertSame($obj->getFundingInstruments(), $obj->getFunding_instruments()); + $obj->setFunding_instruments(FundingInstrumentTest::getObject()); + $this->assertEquals($obj->getFunding_instruments(), FundingInstrumentTest::getObject()); + + // Check for Funding_option_id + $obj->setFundingOptionId(null); + $this->assertNull($obj->getFunding_option_id()); + $this->assertNull($obj->getFundingOptionId()); + $this->assertSame($obj->getFundingOptionId(), $obj->getFunding_option_id()); + $obj->setFunding_option_id("TestSample"); + $this->assertEquals($obj->getFunding_option_id(), "TestSample"); + + // Check for Payer_info + $obj->setPayerInfo(null); + $this->assertNull($obj->getPayer_info()); + $this->assertNull($obj->getPayerInfo()); + $this->assertSame($obj->getPayerInfo(), $obj->getPayer_info()); + $obj->setPayer_info(PayerInfoTest::getObject()); + $this->assertEquals($obj->getPayer_info(), PayerInfoTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PaymentCardTest.php b/tests/PayPal/Test/Api/PaymentCardTest.php new file mode 100644 index 0000000..6317de8 --- /dev/null +++ b/tests/PayPal/Test/Api/PaymentCardTest.php @@ -0,0 +1,187 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getNumber()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getExpireMonth()); + $this->assertNotNull($obj->getExpireYear()); + $this->assertNotNull($obj->getStartMonth()); + $this->assertNotNull($obj->getStartYear()); + $this->assertNotNull($obj->getCvv2()); + $this->assertNotNull($obj->getFirstName()); + $this->assertNotNull($obj->getLastName()); + $this->assertNotNull($obj->getBillingAddress()); + $this->assertNotNull($obj->getExternalCustomerId()); + $this->assertNotNull($obj->getStatus()); + $this->assertNotNull($obj->getValidUntil()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param PaymentCard $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getNumber(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getExpireMonth(), 123); + $this->assertEquals($obj->getExpireYear(), 123); + $this->assertEquals($obj->getStartMonth(), 123); + $this->assertEquals($obj->getStartYear(), 123); + $this->assertEquals($obj->getCvv2(), 123); + $this->assertEquals($obj->getFirstName(), "TestSample"); + $this->assertEquals($obj->getLastName(), "TestSample"); + $this->assertEquals($obj->getBillingAddress(), AddressTest::getObject()); + $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); + $this->assertEquals($obj->getStatus(), "TestSample"); + $this->assertEquals($obj->getValidUntil(), "TestSample"); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param PaymentCard $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getExpire_month(), 123); + $this->assertEquals($obj->getExpire_year(), 123); + $this->assertEquals($obj->getStart_month(), 123); + $this->assertEquals($obj->getStart_year(), 123); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + $this->assertEquals($obj->getValid_until(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param PaymentCard $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Expire_month + $obj->setExpireMonth(null); + $this->assertNull($obj->getExpire_month()); + $this->assertNull($obj->getExpireMonth()); + $this->assertSame($obj->getExpireMonth(), $obj->getExpire_month()); + $obj->setExpire_month(123); + $this->assertEquals($obj->getExpire_month(), 123); + + // Check for Expire_year + $obj->setExpireYear(null); + $this->assertNull($obj->getExpire_year()); + $this->assertNull($obj->getExpireYear()); + $this->assertSame($obj->getExpireYear(), $obj->getExpire_year()); + $obj->setExpire_year(123); + $this->assertEquals($obj->getExpire_year(), 123); + + // Check for Start_month + $obj->setStartMonth(null); + $this->assertNull($obj->getStart_month()); + $this->assertNull($obj->getStartMonth()); + $this->assertSame($obj->getStartMonth(), $obj->getStart_month()); + $obj->setStart_month(123); + $this->assertEquals($obj->getStart_month(), 123); + + // Check for Start_year + $obj->setStartYear(null); + $this->assertNull($obj->getStart_year()); + $this->assertNull($obj->getStartYear()); + $this->assertSame($obj->getStartYear(), $obj->getStart_year()); + $obj->setStart_year(123); + $this->assertEquals($obj->getStart_year(), 123); + + // Check for First_name + $obj->setFirstName(null); + $this->assertNull($obj->getFirst_name()); + $this->assertNull($obj->getFirstName()); + $this->assertSame($obj->getFirstName(), $obj->getFirst_name()); + $obj->setFirst_name("TestSample"); + $this->assertEquals($obj->getFirst_name(), "TestSample"); + + // Check for Last_name + $obj->setLastName(null); + $this->assertNull($obj->getLast_name()); + $this->assertNull($obj->getLastName()); + $this->assertSame($obj->getLastName(), $obj->getLast_name()); + $obj->setLast_name("TestSample"); + $this->assertEquals($obj->getLast_name(), "TestSample"); + + // Check for Billing_address + $obj->setBillingAddress(null); + $this->assertNull($obj->getBilling_address()); + $this->assertNull($obj->getBillingAddress()); + $this->assertSame($obj->getBillingAddress(), $obj->getBilling_address()); + $obj->setBilling_address(AddressTest::getObject()); + $this->assertEquals($obj->getBilling_address(), AddressTest::getObject()); + + // Check for External_customer_id + $obj->setExternalCustomerId(null); + $this->assertNull($obj->getExternal_customer_id()); + $this->assertNull($obj->getExternalCustomerId()); + $this->assertSame($obj->getExternalCustomerId(), $obj->getExternal_customer_id()); + $obj->setExternal_customer_id("TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + + // Check for Valid_until + $obj->setValidUntil(null); + $this->assertNull($obj->getValid_until()); + $this->assertNull($obj->getValidUntil()); + $this->assertSame($obj->getValidUntil(), $obj->getValid_until()); + $obj->setValid_until("TestSample"); + $this->assertEquals($obj->getValid_until(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PaymentCardTokenTest.php b/tests/PayPal/Test/Api/PaymentCardTokenTest.php new file mode 100644 index 0000000..ffed8f5 --- /dev/null +++ b/tests/PayPal/Test/Api/PaymentCardTokenTest.php @@ -0,0 +1,124 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getPaymentCardId()); + $this->assertNotNull($obj->getExternalCustomerId()); + $this->assertNotNull($obj->getLast4()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getExpireMonth()); + $this->assertNotNull($obj->getExpireYear()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param PaymentCardToken $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getPaymentCardId(), "TestSample"); + $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); + $this->assertEquals($obj->getLast4(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getExpireMonth(), 123); + $this->assertEquals($obj->getExpireYear(), 123); + } + + /** + * @depends testSerializationDeserialization + * @param PaymentCardToken $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getPayment_card_id(), "TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + $this->assertEquals($obj->getExpire_month(), 123); + $this->assertEquals($obj->getExpire_year(), 123); + } + + /** + * @depends testSerializationDeserialization + * @param PaymentCardToken $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Payment_card_id + $obj->setPaymentCardId(null); + $this->assertNull($obj->getPayment_card_id()); + $this->assertNull($obj->getPaymentCardId()); + $this->assertSame($obj->getPaymentCardId(), $obj->getPayment_card_id()); + $obj->setPayment_card_id("TestSample"); + $this->assertEquals($obj->getPayment_card_id(), "TestSample"); + + // Check for External_customer_id + $obj->setExternalCustomerId(null); + $this->assertNull($obj->getExternal_customer_id()); + $this->assertNull($obj->getExternalCustomerId()); + $this->assertSame($obj->getExternalCustomerId(), $obj->getExternal_customer_id()); + $obj->setExternal_customer_id("TestSample"); + $this->assertEquals($obj->getExternal_customer_id(), "TestSample"); + + // Check for Expire_month + $obj->setExpireMonth(null); + $this->assertNull($obj->getExpire_month()); + $this->assertNull($obj->getExpireMonth()); + $this->assertSame($obj->getExpireMonth(), $obj->getExpire_month()); + $obj->setExpire_month(123); + $this->assertEquals($obj->getExpire_month(), 123); + + // Check for Expire_year + $obj->setExpireYear(null); + $this->assertNull($obj->getExpire_year()); + $this->assertNull($obj->getExpireYear()); + $this->assertSame($obj->getExpireYear(), $obj->getExpire_year()); + $obj->setExpire_year(123); + $this->assertEquals($obj->getExpire_year(), 123); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PaymentDefinitionTest.php b/tests/PayPal/Test/Api/PaymentDefinitionTest.php new file mode 100644 index 0000000..3a05c76 --- /dev/null +++ b/tests/PayPal/Test/Api/PaymentDefinitionTest.php @@ -0,0 +1,110 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getName()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getFrequencyInterval()); + $this->assertNotNull($obj->getFrequency()); + $this->assertNotNull($obj->getCycles()); + $this->assertNotNull($obj->getAmount()); + $this->assertNotNull($obj->getChargeModels()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param PaymentDefinition $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getName(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getFrequencyInterval(), "TestSample"); + $this->assertEquals($obj->getFrequency(), "TestSample"); + $this->assertEquals($obj->getCycles(), "TestSample"); + $this->assertEquals($obj->getAmount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getChargeModels(), ChargeModelTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param PaymentDefinition $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getFrequency_interval(), "TestSample"); + $this->assertEquals($obj->getCharge_models(), ChargeModelTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param PaymentDefinition $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Frequency_interval + $obj->setFrequencyInterval(null); + $this->assertNull($obj->getFrequency_interval()); + $this->assertNull($obj->getFrequencyInterval()); + $this->assertSame($obj->getFrequencyInterval(), $obj->getFrequency_interval()); + $obj->setFrequency_interval("TestSample"); + $this->assertEquals($obj->getFrequency_interval(), "TestSample"); + + // Check for Charge_models + $obj->setChargeModels(null); + $this->assertNull($obj->getCharge_models()); + $this->assertNull($obj->getChargeModels()); + $this->assertSame($obj->getChargeModels(), $obj->getCharge_models()); + $obj->setCharge_models(ChargeModelTest::getObject()); + $this->assertEquals($obj->getCharge_models(), ChargeModelTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PaymentTest.php b/tests/PayPal/Test/Api/PaymentTest.php index 57aeab4..3f7a65d 100644 --- a/tests/PayPal/Test/Api/PaymentTest.php +++ b/tests/PayPal/Test/Api/PaymentTest.php @@ -26,7 +26,7 @@ class PaymentTest extends \PHPUnit_Framework_TestCase $payment = new Payment(); $payment->setIntent("sale"); $payment->setRedirectUrls($redirectUrls); - $payment->setPayer(PayerTest::createPayer()); + $payment->setPayer(PayerTest::getObject()); $payment->setTransactions(array(TransactionTest::createTransaction())); return $payment; @@ -35,7 +35,7 @@ class PaymentTest extends \PHPUnit_Framework_TestCase public static function createNewPayment() { - $funding = FundingInstrumentTest::createFundingInstrument(); + $funding = FundingInstrumentTest::getObject(); $funding->credit_card_token = null; $payer = new Payer(); @@ -72,24 +72,6 @@ class PaymentTest extends \PHPUnit_Framework_TestCase $this->assertEquals($p2, $this->payments['full']); } - /** - * @group integration - */ - public function testOperations() - { - - $p1 = $this->payments['new']; - - $p1->create(); - $this->assertNotNull($p1->getId()); - - $p2 = Payment::get($p1->getId()); - $this->assertNotNull($p2); - - $paymentHistory = Payment::all(array('count' => '10')); - $this->assertNotNull($paymentHistory); - } - /** * @group integration * diff --git a/tests/PayPal/Test/Api/PlanListTest.php b/tests/PayPal/Test/Api/PlanListTest.php new file mode 100644 index 0000000..7649bec --- /dev/null +++ b/tests/PayPal/Test/Api/PlanListTest.php @@ -0,0 +1,102 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getPlans()); + $this->assertNotNull($obj->getTotalItems()); + $this->assertNotNull($obj->getTotalPages()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param PlanList $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getPlans(), PlanTest::getObject()); + $this->assertEquals($obj->getTotalItems(), "TestSample"); + $this->assertEquals($obj->getTotalPages(), "TestSample"); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param PlanList $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getTotal_items(), "TestSample"); + $this->assertEquals($obj->getTotal_pages(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param PlanList $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Total_items + $obj->setTotalItems(null); + $this->assertNull($obj->getTotal_items()); + $this->assertNull($obj->getTotalItems()); + $this->assertSame($obj->getTotalItems(), $obj->getTotal_items()); + $obj->setTotal_items("TestSample"); + $this->assertEquals($obj->getTotal_items(), "TestSample"); + + // Check for Total_pages + $obj->setTotalPages(null); + $this->assertNull($obj->getTotal_pages()); + $this->assertNull($obj->getTotalPages()); + $this->assertSame($obj->getTotalPages(), $obj->getTotal_pages()); + $obj->setTotal_pages("TestSample"); + $this->assertEquals($obj->getTotal_pages(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/PlanTest.php b/tests/PayPal/Test/Api/PlanTest.php new file mode 100644 index 0000000..d295086 --- /dev/null +++ b/tests/PayPal/Test/Api/PlanTest.php @@ -0,0 +1,227 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getName()); + $this->assertNotNull($obj->getDescription()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getState()); + $this->assertNotNull($obj->getCreateTime()); + $this->assertNotNull($obj->getUpdateTime()); + $this->assertNotNull($obj->getPaymentDefinitions()); + $this->assertNotNull($obj->getTerms()); + $this->assertNotNull($obj->getMerchantPreferences()); + $this->assertNotNull($obj->getLinks()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param Plan $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getName(), "TestSample"); + $this->assertEquals($obj->getDescription(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getState(), "TestSample"); + $this->assertEquals($obj->getCreateTime(), "TestSample"); + $this->assertEquals($obj->getUpdateTime(), "TestSample"); + $this->assertEquals($obj->getPaymentDefinitions(), PaymentDefinitionTest::getObject()); + $this->assertEquals($obj->getTerms(), TermsTest::getObject()); + $this->assertEquals($obj->getMerchantPreferences(), MerchantPreferencesTest::getObject()); + $this->assertEquals($obj->getLinks(), LinksTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param Plan $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getCreate_time(), "TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + $this->assertEquals($obj->getPayment_definitions(), PaymentDefinitionTest::getObject()); + $this->assertEquals($obj->getMerchant_preferences(), MerchantPreferencesTest::getObject()); + } + + /** + * @depends testSerializationDeserialization + * @param Plan $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Create_time + $obj->setCreateTime(null); + $this->assertNull($obj->getCreate_time()); + $this->assertNull($obj->getCreateTime()); + $this->assertSame($obj->getCreateTime(), $obj->getCreate_time()); + $obj->setCreate_time("TestSample"); + $this->assertEquals($obj->getCreate_time(), "TestSample"); + + // Check for Update_time + $obj->setUpdateTime(null); + $this->assertNull($obj->getUpdate_time()); + $this->assertNull($obj->getUpdateTime()); + $this->assertSame($obj->getUpdateTime(), $obj->getUpdate_time()); + $obj->setUpdate_time("TestSample"); + $this->assertEquals($obj->getUpdate_time(), "TestSample"); + + // Check for Payment_definitions + $obj->setPaymentDefinitions(null); + $this->assertNull($obj->getPayment_definitions()); + $this->assertNull($obj->getPaymentDefinitions()); + $this->assertSame($obj->getPaymentDefinitions(), $obj->getPayment_definitions()); + $obj->setPayment_definitions(PaymentDefinitionTest::getObject()); + $this->assertEquals($obj->getPayment_definitions(), PaymentDefinitionTest::getObject()); + + // Check for Merchant_preferences + $obj->setMerchantPreferences(null); + $this->assertNull($obj->getMerchant_preferences()); + $this->assertNull($obj->getMerchantPreferences()); + $this->assertSame($obj->getMerchantPreferences(), $obj->getMerchant_preferences()); + $obj->setMerchant_preferences(MerchantPreferencesTest::getObject()); + $this->assertEquals($obj->getMerchant_preferences(), MerchantPreferencesTest::getObject()); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + /** + * @dataProvider mockProvider + * @param Plan $obj + */ + public function testGet($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + PlanTest::getJson() + )); + + $result = $obj->get("planId", $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Plan $obj + */ + public function testCreate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + self::getJson() + )); + + $result = $obj->create($mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Plan $obj + */ + public function testUpdate($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + true + )); + $patchRequest = PatchRequestTest::getObject(); + + $result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + /** + * @dataProvider mockProvider + * @param Plan $obj + */ + public function testList($obj, $mockApiContext) + { + $mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + PlanListTest::getJson() + )); + $params = ParamsTest::getObject(); + + $result = $obj->all($params, $mockApiContext, $mockPPRestCall); + $this->assertNotNull($result); + } + + public function mockProvider() + { + $obj = self::getObject(); + $mockApiContext = $this->getMockBuilder('ApiContext') + ->disableOriginalConstructor() + ->getMock(); + return array( + array($obj, $mockApiContext), + array($obj, null) + ); + } +} diff --git a/tests/PayPal/Test/Api/RefundTest.php b/tests/PayPal/Test/Api/RefundTest.php index 99c49b6..7c2e766 100644 --- a/tests/PayPal/Test/Api/RefundTest.php +++ b/tests/PayPal/Test/Api/RefundTest.php @@ -21,7 +21,7 @@ class RefundTest extends \PHPUnit_Framework_TestCase $refund->setAmount(AmountTest::createAmount()); $refund->setCaptureId(self::$captureId); $refund->setId(self::$id); - $refund->setLinks(array(LinksTest::createLinks())); + $refund->setLinks(array(LinksTest::getObject())); $refund->setParentPayment(self::$parentPayment); return $refund; @@ -40,7 +40,6 @@ class RefundTest extends \PHPUnit_Framework_TestCase $this->assertEquals(self::$parentPayment, $this->refund->getParentPayment()); $this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency()); $links = $this->refund->getLinks(); - $this->assertEquals(LinksTest::$href, $links[0]->getHref()); } public function testSerializeDeserialize() @@ -57,4 +56,4 @@ class RefundTest extends \PHPUnit_Framework_TestCase { } -} \ No newline at end of file +} diff --git a/tests/PayPal/Test/Api/SaleTest.php b/tests/PayPal/Test/Api/SaleTest.php index 8e6f0cf..c51e044 100644 --- a/tests/PayPal/Test/Api/SaleTest.php +++ b/tests/PayPal/Test/Api/SaleTest.php @@ -55,33 +55,4 @@ class SaleTest extends \PHPUnit_Framework_TestCase $this->assertEquals($s1, $s2); } - - /** - * @group integration - */ - public function testOperations() - { - try { - $payment = PaymentTest::createNewPayment(); - $payment->create(); - - $transactions = $payment->getTransactions(); - $resources = $transactions[0]->getRelatedResources(); - $saleId = $resources[0]->getSale()->getId(); - - $sale = Sale::get($saleId); - $this->assertNotNull($sale); - - $refund = new Refund(); - $refund->setAmount(AmountTest::createAmount()); - $sale->refund($refund); - - $this->setExpectedException('\InvalidArgumentException'); - $sale->refund(NULL); - } catch (PPConnectionException $ex) { - $this->markTestSkipped( - 'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage() - ); - } - } -} \ No newline at end of file +} diff --git a/tests/PayPal/Test/Api/ShippingAddressTest.php b/tests/PayPal/Test/Api/ShippingAddressTest.php index 8b6a947..7634bd8 100644 --- a/tests/PayPal/Test/Api/ShippingAddressTest.php +++ b/tests/PayPal/Test/Api/ShippingAddressTest.php @@ -1,61 +1,100 @@ setLine1(self::$line1); - $addr->setLine2(self::$line2); - $addr->setCity(self::$city); - $addr->setState(self::$state); - $addr->setPostalCode(self::$postalCode); - $addr->setCountryCode(self::$countryCode); - $addr->setPhone(self::$phone); - $addr->setRecipientName(self::$recipientName); - return $addr; + return '{"id":"TestSample","recipient_name":"TestSample","default_address":true}'; } - public function setup() + /** + * Gets Object Instance with Json data filled in + * @return ShippingAddress + */ + public static function getObject() { - $this->address = self::createAddress(); + return new ShippingAddress(self::getJson()); } - public function testGetterSetter() + + /** + * Tests for Serialization and Deserialization Issues + * @return ShippingAddress + */ + public function testSerializationDeserialization() { - $this->assertEquals(self::$line1, $this->address->getLine1()); - $this->assertEquals(self::$line2, $this->address->getLine2()); - $this->assertEquals(self::$city, $this->address->getCity()); - $this->assertEquals(self::$state, $this->address->getState()); - $this->assertEquals(self::$postalCode, $this->address->getPostalCode()); - $this->assertEquals(self::$countryCode, $this->address->getCountryCode()); - $this->assertEquals(self::$phone, $this->address->getPhone()); - $this->assertEquals(self::$recipientName, $this->address->getRecipientName()); + $obj = new ShippingAddress(self::getJson()); + $this->assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getRecipientName()); + $this->assertNotNull($obj->getDefaultAddress()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; } - public function testSerializeDeserialize() + /** + * @depends testSerializationDeserialization + * @param ShippingAddress $obj + */ + public function testGetters($obj) { - $a1 = $this->address; - - $a2 = new ShippingAddress(); - $a2->fromJson($a1->toJson()); - - $this->assertEquals($a1, $a2); + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getRecipientName(), "TestSample"); + $this->assertEquals($obj->getDefaultAddress(), true); } -} \ No newline at end of file + + /** + * @depends testSerializationDeserialization + * @param ShippingAddress $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getRecipient_name(), "TestSample"); + $this->assertEquals($obj->getDefault_address(), true); + } + + /** + * @depends testSerializationDeserialization + * @param ShippingAddress $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Recipient_name + $obj->setRecipientName(null); + $this->assertNull($obj->getRecipient_name()); + $this->assertNull($obj->getRecipientName()); + $this->assertSame($obj->getRecipientName(), $obj->getRecipient_name()); + $obj->setRecipient_name("TestSample"); + $this->assertEquals($obj->getRecipient_name(), "TestSample"); + + // Check for Default_address + $obj->setDefaultAddress(null); + $this->assertNull($obj->getDefault_address()); + $this->assertNull($obj->getDefaultAddress()); + $this->assertSame($obj->getDefaultAddress(), $obj->getDefault_address()); + $obj->setDefault_address(true); + $this->assertEquals($obj->getDefault_address(), true); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Api/TermsTest.php b/tests/PayPal/Test/Api/TermsTest.php new file mode 100644 index 0000000..6ab14cb --- /dev/null +++ b/tests/PayPal/Test/Api/TermsTest.php @@ -0,0 +1,115 @@ +assertNotNull($obj); + $this->assertNotNull($obj->getId()); + $this->assertNotNull($obj->getType()); + $this->assertNotNull($obj->getMaxBillingAmount()); + $this->assertNotNull($obj->getOccurrences()); + $this->assertNotNull($obj->getAmountRange()); + $this->assertNotNull($obj->getBuyerEditable()); + $this->assertEquals(self::getJson(), $obj->toJson()); + return $obj; + } + + /** + * @depends testSerializationDeserialization + * @param Terms $obj + */ + public function testGetters($obj) + { + $this->assertEquals($obj->getId(), "TestSample"); + $this->assertEquals($obj->getType(), "TestSample"); + $this->assertEquals($obj->getMaxBillingAmount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getOccurrences(), "TestSample"); + $this->assertEquals($obj->getAmountRange(), CurrencyTest::getObject()); + $this->assertEquals($obj->getBuyerEditable(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param Terms $obj + */ + public function testDeprecatedGetters($obj) + { + $this->assertEquals($obj->getMax_billing_amount(), CurrencyTest::getObject()); + $this->assertEquals($obj->getAmount_range(), CurrencyTest::getObject()); + $this->assertEquals($obj->getBuyer_editable(), "TestSample"); + } + + /** + * @depends testSerializationDeserialization + * @param Terms $obj + */ + public function testDeprecatedSetterNormalGetter($obj) + { + + // Check for Max_billing_amount + $obj->setMaxBillingAmount(null); + $this->assertNull($obj->getMax_billing_amount()); + $this->assertNull($obj->getMaxBillingAmount()); + $this->assertSame($obj->getMaxBillingAmount(), $obj->getMax_billing_amount()); + $obj->setMax_billing_amount(CurrencyTest::getObject()); + $this->assertEquals($obj->getMax_billing_amount(), CurrencyTest::getObject()); + + // Check for Amount_range + $obj->setAmountRange(null); + $this->assertNull($obj->getAmount_range()); + $this->assertNull($obj->getAmountRange()); + $this->assertSame($obj->getAmountRange(), $obj->getAmount_range()); + $obj->setAmount_range(CurrencyTest::getObject()); + $this->assertEquals($obj->getAmount_range(), CurrencyTest::getObject()); + + // Check for Buyer_editable + $obj->setBuyerEditable(null); + $this->assertNull($obj->getBuyer_editable()); + $this->assertNull($obj->getBuyerEditable()); + $this->assertSame($obj->getBuyerEditable(), $obj->getBuyer_editable()); + $obj->setBuyer_editable("TestSample"); + $this->assertEquals($obj->getBuyer_editable(), "TestSample"); + + //Test All Deprecated Getters and Normal Getters + $this->testDeprecatedGetters($obj); + $this->testGetters($obj); + } + + + +} diff --git a/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php b/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php new file mode 100644 index 0000000..42fb0b6 --- /dev/null +++ b/tests/PayPal/Test/Functional/Api/BillingAgreementsFunctionalTest.php @@ -0,0 +1,246 @@ +getClassName(); + $testName = $this->getName(); + $this->setupTest($className, $testName); + } + + public function setupTest($className, $testName) + { + $operationString = file_get_contents(__DIR__ . "/../resources/$className/$testName.json"); + $this->operation = json_decode($operationString, true); + $this->response = true; + if (array_key_exists('body', $this->operation['response'])) { + $this->response = json_encode($this->operation['response']['body']); + } + + $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; + if ($this->mode != 'sandbox') { + + // Mock PPRest Caller if mode set to mock + $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $this->mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + $this->response + )); + } + } + + /** + * Returns just the classname of the test you are executing. It removes the namespaces. + * @return string + */ + public function getClassName() + { + return join('', array_slice(explode('\\', get_class($this)), -1)); + } + + /** + * @return Agreement + */ + public function testCreatePayPalAgreement() + { + $plan = BillingPlansFunctionalTest::getPlan(); + $request = $this->operation['request']['body']; + $agreement = new Agreement($request); + // Update the Schema to use a working Plan + $agreement->getPlan()->setId($plan->getId()); + $result = $agreement->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } + + /** + * @depends testCreatePayPalAgreement + * @param $agreement Agreement + * @return Agreement + */ + public function testExecute($agreement) + { + if ($this->mode == 'sandbox') { + $this->markTestSkipped('Not executable on sandbox environment. Needs human interaction'); + } + $links = $agreement->getLinks(); + $url = parse_url($links[0]->getHref(), 6); + parse_str($url, $result); + $paymentToken = $result['token']; + $this->assertNotNull($paymentToken); + $this->assertNotEmpty($paymentToken); + $result = $agreement->execute($paymentToken, null, $this->mockPPRestCall); + return $result; + } + + /** + * @return Agreement + */ + public function testCreateCCAgreement() + { + $plan = BillingPlansFunctionalTest::getPlan(); + $request = $this->operation['request']['body']; + $agreement = new Agreement($request); + // Update the Schema to use a working Plan + $agreement->getPlan()->setId($plan->getId()); + $result = $agreement->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } + + /** + * @depends testCreateCCAgreement + * @param $agreement Agreement + * @return Plan + */ + public function testGet($agreement) + { + $result = Agreement::get($agreement->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals($agreement->getId(), $result->getId()); + return $result; + } + + /** + * @depends testGet + * @param $agreement Agreement + */ + public function testUpdate($agreement) + { + /** @var Patch[] $request */ + $request = $this->operation['request']['body'][0]; + $patch = new Patch(); + $patch->setOp($request['op']); + $patch->setPath($request['path']); + $patch->setValue($request['value']); + $patches = array(); + $patches[] = $patch; + $patchRequest = new PatchRequest(); + $patchRequest->setPatches($patches); + $result = $agreement->update($patchRequest, null, $this->mockPPRestCall); + $this->assertTrue($result); + } + + /** + * @depends testGet + * @param $agreement Agreement + * @return Agreement + */ + public function testSetBalance($agreement) + { + $this->markTestSkipped('Skipped as the fix is on the way.'); + $currency = new Currency($this->operation['request']['body']); + $result = $agreement->setBalance($currency, null, $this->mockPPRestCall); + $this->assertTrue($result); + return $agreement; + } + + /** + * @depends testGet + * @param $agreement Agreement + * @return Agreement + */ + public function testBillBalance($agreement) + { + $this->markTestSkipped('Skipped as the fix is on the way.'); + $agreementStateDescriptor = new AgreementStateDescriptor($this->operation['request']['body']); + $result = $agreement->billBalance($agreementStateDescriptor, null, $this->mockPPRestCall); + $this->assertTrue($result); + return $agreement; + } + + /** + * @depends testGet + * @param $agreement Agreement + * @return Agreement + */ + public function testGetTransactions($agreement) + { + $this->markTestSkipped('Skipped as the fix is on the way.'); + $result = Agreement::transactions($agreement->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + } + + /** + * @depends testGet + * @param $agreement Agreement + * @return Agreement + */ + public function testSuspend($agreement) + { + $agreementStateDescriptor = new AgreementStateDescriptor($this->operation['request']['body']); + $result = $agreement->suspend($agreementStateDescriptor, null, $this->mockPPRestCall); + $this->setupTest($this->getClassName(), 'testGetSuspended'); + $get = $this->testGet($agreement); + $this->assertTrue($result); + $this->assertEquals('Suspended', $get->getState()); + return $get; + } + + /** + * @depends testSuspend + * @param $agreement Agreement + * @return Agreement + */ + public function testReactivate($agreement) + { + $agreementStateDescriptor = new AgreementStateDescriptor($this->operation['request']['body']); + $result = $agreement->reActivate($agreementStateDescriptor, null, $this->mockPPRestCall); + $this->assertTrue($result); + $this->setupTest($this->getClassName(), 'testGet'); + $get = $this->testGet($agreement); + $this->assertEquals('Active', $get->getState()); + return $get; + } + + /** + * @depends testReactivate + * @param $agreement Agreement + * @return Agreement + */ + public function testCancel($agreement) + { + $agreementStateDescriptor = new AgreementStateDescriptor($this->operation['request']['body']); + $result = $agreement->cancel($agreementStateDescriptor, null, $this->mockPPRestCall); + $this->assertTrue($result); + $this->setupTest($this->getClassName(), 'testGetCancelled'); + $get = $this->testGet($agreement); + $this->assertEquals('Cancelled', $get->getState()); + return $get; + } + +} diff --git a/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php b/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php new file mode 100644 index 0000000..0accf6f --- /dev/null +++ b/tests/PayPal/Test/Functional/Api/BillingPlansFunctionalTest.php @@ -0,0 +1,217 @@ +getClassName(); + $testName = $this->getName(); + $this->setupTest($className, $testName); + } + + public function setupTest($className, $testName) + { + $operationString = file_get_contents(__DIR__ . "/../resources/$className/$testName.json"); + $this->operation = json_decode($operationString, true); + $this->response = true; + if (array_key_exists('body', $this->operation['response'])) { + $this->response = json_encode($this->operation['response']['body']); + } + + $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; + if ($this->mode != 'sandbox') { + + // Mock PPRest Caller if mode set to mock + $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $this->mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + $this->response + )); + } + } + + /** + * Helper function to get a Plan object in Active State + * + * @return Plan + */ + public static function getPlan() + { + if (!self::$obj) { + $test = new self(); + // Creates a Plan + $test->setupTest($test->getClassName(), 'testCreate'); + self::$obj = $test->testCreate(); + // Updates the Status to Active + $test->setupTest($test->getClassName(), 'testUpdateChangingState'); + self::$obj = $test->testUpdateChangingState(self::$obj); + } + return self::$obj; + } + + /** + * Returns just the classname of the test you are executing. It removes the namespaces. + * @return string + */ + public function getClassName() + { + return join('', array_slice(explode('\\', get_class($this)), -1)); + } + + public function testCreate() + { + $request = $this->operation['request']['body']; + $obj = new Plan($request); + $result = $obj->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + self::$obj = $result; + return $result; + } + + public function testCreateWithNOChargeModel() + { + $request = $this->operation['request']['body']; + $obj = new Plan($request); + $result = $obj->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } + + /** + * @depends testCreate + * @param $plan Plan + * @return Plan + */ + public function testGet($plan) + { + $result = Plan::get($plan->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals($plan->getId(), $result->getId()); + $this->assertEquals($plan, $result, "", 0, 10, true); + return $result; + } + + /** + * @depends testGet + * @param $plan Plan + */ + public function testGetList($plan) + { + $result = Plan::all(array('page_size' => '20', 'total_required' => 'yes'), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $totalPages = $result->getTotalPages(); + $found = false; + $foundObject = null; + do { + foreach ($result->getPlans() as $obj) { + if ($obj->getId() == $plan->getId()) { + $found = true; + $foundObject = $obj; + break; + } + } + if (!$found) { + $result = Plan::all(array('page' => --$totalPages, 'page_size' => '20', 'total_required' => 'yes'), null, $this->mockPPRestCall); + + } + } while ($totalPages > 0 && $found == false); + $this->assertTrue($found, "The Created Plan was not found in the get list"); + $this->assertEquals($plan->getId(), $foundObject->getId()); + + } + + /** + * @depends testGet + * @param $plan Plan + */ + public function testUpdateChangingMerchantPreferences($plan) + { + /** @var Patch[] $request */ + $request = $this->operation['request']['body'][0]; + $patch = new Patch(); + $patch->setOp($request['op']); + $patch->setPath($request['path']); + $patch->setValue($request['value']); + $patches = array(); + $patches[] = $patch; + $patchRequest = new PatchRequest(); + $patchRequest->setPatches($patches); + $result = $plan->update($patchRequest, null, $this->mockPPRestCall); + $this->assertTrue($result); + } + + /** + * @depends testGet + * @param $plan Plan + */ + public function testUpdateChangingPD($plan) + { + /** @var Patch[] $request */ + $request = $this->operation['request']['body'][0]; + $patch = new Patch(); + $patch->setOp($request['op']); + $paymentDefinitions = $plan->getPaymentDefinitions(); + $patch->setPath('/payment-definitions/' . $paymentDefinitions[0]->getId()); + $patch->setValue($request['value']); + $patches = array(); + $patches[] = $patch; + $patchRequest = new PatchRequest(); + $patchRequest->setPatches($patches); + $result = $plan->update($patchRequest, null, $this->mockPPRestCall); + $this->assertTrue($result); + } + + /** + * @depends testGet + * @param $plan Plan + * @return Plan + */ + public function testUpdateChangingState($plan) + { + /** @var Patch[] $request */ + $request = $this->operation['request']['body'][0]; + $patch = new Patch(); + $patch->setOp($request['op']); + $patch->setPath($request['path']); + $patch->setValue($request['value']); + $patches = array(); + $patches[] = $patch; + $patchRequest = new PatchRequest(); + $patchRequest->setPatches($patches); + $result = $plan->update($patchRequest, null, $this->mockPPRestCall); + $this->assertTrue($result); + return Plan::get($plan->getId(), null, $this->mockPPRestCall); + } +} diff --git a/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php b/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php new file mode 100644 index 0000000..ef82c23 --- /dev/null +++ b/tests/PayPal/Test/Functional/Api/PaymentsFunctionalTest.php @@ -0,0 +1,146 @@ +getClassName(); + $testName = $this->getName(); + $operationString = file_get_contents(__DIR__ . "/../resources/$className/$testName.json"); + $this->operation = json_decode($operationString, true); + $this->response = true; + if (array_key_exists('body', $this->operation['response'])) { + $this->response = json_encode($this->operation['response']['body']); + } + + $this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock'; + if ($this->mode != 'sandbox') { + + // Mock PPRest Caller if mode set to mock + $this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall') + ->disableOriginalConstructor() + ->getMock(); + + $this->mockPPRestCall->expects($this->any()) + ->method('execute') + ->will($this->returnValue( + $this->response + )); + } + } + + /** + * Returns just the classname of the test you are executing. It removes the namespaces. + * @return string + */ + public function getClassName() + { + return join('', array_slice(explode('\\', get_class($this)), -1)); + } + + public function testCreate() + { + $request = $this->operation['request']['body']; + $obj = new Payment($request); + $result = $obj->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } + + public function testCreateWallet() + { + $request = $this->operation['request']['body']; + $obj = new Payment($request); + $result = $obj->create(null, $this->mockPPRestCall); + $this->assertNotNull($result); + return $result; + } + + /** + * @depends testCreate + * @param $payment Payment + * @return Payment + */ + public function testGet($payment) + { + $result = Payment::get($payment->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals($payment->getId(), $result->getId()); + $this->assertEquals($payment, $result, "", 0, 10, true); + return $result; + } + + /** + * @depends testGet + * @param $payment Payment + * @return Sale + */ + public function testGetSale($payment) + { + $transactions = $payment->getTransactions(); + $transaction = $transactions[0]; + $relatedResources = $transaction->getRelatedResources(); + $resource = $relatedResources[0]; + $result = Sale::get($resource->getSale()->getId(), null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals($resource->getSale()->getId(), $result->getId()); + return $result; + } + + /** + * @depends testGetSale + * @param $sale Sale + * @return Sale + */ + public function testRefundSale($sale) + { + $refund = new Refund($this->operation['request']['body']); + $result = $sale->refund($refund, null, $this->mockPPRestCall); + $this->assertNotNull($result); + $this->assertEquals('completed', $result->getState()); + $this->assertEquals($sale->getId(), $result->getSaleId()); + $this->assertEquals($sale->getParentPayment(), $result->getParentPayment()); + } + + /** + * @depends testGet + * @param $payment Payment + * @return Payment + */ + public function testExecute($payment) + { + if ($this->mode == 'sandbox') { + $this->markTestSkipped('Not executable on sandbox environment. Needs human interaction'); + } + } +} diff --git a/tests/PayPal/Test/Functional/Api/WebProfileTest.php b/tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php similarity index 99% rename from tests/PayPal/Test/Functional/Api/WebProfileTest.php rename to tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php index 3663edc..6424fc6 100644 --- a/tests/PayPal/Test/Functional/Api/WebProfileTest.php +++ b/tests/PayPal/Test/Functional/Api/WebProfileFunctionalTest.php @@ -1,6 +1,6 @@ add('PayPal\\Test', __DIR__); if (!defined("PP_CONFIG_PATH")) { define("PP_CONFIG_PATH", __DIR__); -} \ No newline at end of file +} diff --git a/tests/sdk_config.ini b/tests/sdk_config.ini index a2b2537..d7e0947 100644 --- a/tests/sdk_config.ini +++ b/tests/sdk_config.ini @@ -1,7 +1,7 @@ ;Account credentials from developer portal [Account] -acct1.ClientId = EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM -acct1.ClientSecret = EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM +acct1.ClientId = AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS +acct1.ClientSecret = EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL acct2.ClientId = TestClientId acct2.ClientSecret = TestClientSecret @@ -44,4 +44,4 @@ log.LogLevel=FINE ; 'log' : logs the error message to logger only (default) ; 'strict' : throws a php notice message ; 'disable' : disable the validation -validation.level=strict \ No newline at end of file +validation.level=strict