From 6e14f51aa5fc25b7e07dcf7b9b8a21d6339f451d Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Sun, 21 Sep 2014 20:37:34 -0500 Subject: [PATCH 1/5] Updated Testing Framework fixing Travis Builds - Added Group and Catching errors --- phpunit.xml | 8 +++ tests/PayPal/Test/Api/AddressTest.php | 2 +- tests/PayPal/Test/Api/AuthorizationTest.php | 11 +++- tests/PayPal/Test/Api/CaptureTest.php | 59 ++++++++++++--------- tests/PayPal/Test/Api/CreditCardTest.php | 3 ++ tests/PayPal/Test/Api/PaymentTest.php | 3 ++ tests/PayPal/Test/Api/SaleTest.php | 44 +++++++++------ 7 files changed, 85 insertions(+), 45 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 3738b96..8aec30d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,6 +15,14 @@ + + + + integration + + + + assertEquals(self::$countryCode, $this->address->getCountryCode()); $this->assertEquals(self::$phone, $this->address->getPhone()); } - + public function testSerializeDeserialize() { $a1 = $this->address; diff --git a/tests/PayPal/Test/Api/AuthorizationTest.php b/tests/PayPal/Test/Api/AuthorizationTest.php index 3f3ea9b..a575044 100644 --- a/tests/PayPal/Test/Api/AuthorizationTest.php +++ b/tests/PayPal/Test/Api/AuthorizationTest.php @@ -122,6 +122,10 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase { $a2->fromJson($a1->toJson()); $this->assertEquals($a1, $a2); } + + /** + * @group integration + */ public function testOperations() { try { $authId = self::authorize(); @@ -150,13 +154,16 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase { } catch (\InvalidArgumentException $ex) { $this->assertEquals($ex->getMessage(), "Id cannot be null"); } - } catch (\PayPal\Exception\PPConnectionException $ex) { + } catch (PPConnectionException $ex) { $this->markTestSkipped( 'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage() ); } } - + + /** + * @group integration + */ public function testReauthorize() { $authorization = Authorization::get('7GH53639GA425732B'); diff --git a/tests/PayPal/Test/Api/CaptureTest.php b/tests/PayPal/Test/Api/CaptureTest.php index a1162fd..7991e44 100644 --- a/tests/PayPal/Test/Api/CaptureTest.php +++ b/tests/PayPal/Test/Api/CaptureTest.php @@ -55,33 +55,42 @@ class CaptureTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($c1, $c2); } - + + /** + * @group integration + */ public function testOperations() { - $authId = AuthorizationTest::authorize(); - $auth = Authorization::get($authId); - - $amount = new Amount(); - $amount->setCurrency("USD"); - $amount->setTotal("1.00"); - - $captr = new Capture(); - $captr->setId($authId); - $captr->setAmount($amount); - - $capt = $auth->capture($captr); - $captureId = $capt->getId(); - $this->assertNotNull($captureId); - - $refund = new Refund(); - $refund->setId($captureId); - $refund->setAmount($amount); - - $capture = Capture::get($captureId); - $this->assertNotNull($capture->getId()); - - $retund = $capture->refund($refund); - $this->assertNotNull($retund->getId()); + try { + $authId = AuthorizationTest::authorize(); + $auth = Authorization::get($authId); + + $amount = new Amount(); + $amount->setCurrency("USD"); + $amount->setTotal("1.00"); + + $captr = new Capture(); + $captr->setId($authId); + $captr->setAmount($amount); + + $capt = $auth->capture($captr); + $captureId = $capt->getId(); + $this->assertNotNull($captureId); + + $refund = new Refund(); + $refund->setId($captureId); + $refund->setAmount($amount); + + $capture = Capture::get($captureId); + $this->assertNotNull($capture->getId()); + + $retund = $capture->refund($refund); + $this->assertNotNull($retund->getId()); + } 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/CreditCardTest.php b/tests/PayPal/Test/Api/CreditCardTest.php index 84cb96b..fd0bb03 100644 --- a/tests/PayPal/Test/Api/CreditCardTest.php +++ b/tests/PayPal/Test/Api/CreditCardTest.php @@ -71,6 +71,9 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($c1, $c2); } + /** + * @group integration + */ public function testOperations() { $c1 = $this->cards['full']; diff --git a/tests/PayPal/Test/Api/PaymentTest.php b/tests/PayPal/Test/Api/PaymentTest.php index 6e92d23..fd0ce9d 100644 --- a/tests/PayPal/Test/Api/PaymentTest.php +++ b/tests/PayPal/Test/Api/PaymentTest.php @@ -66,6 +66,9 @@ class PaymentTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($p2, $this->payments['full']); } + /** + * @group integration + */ public function testOperations() { $p1 = $this->payments['new']; diff --git a/tests/PayPal/Test/Api/SaleTest.php b/tests/PayPal/Test/Api/SaleTest.php index b4c6972..1794725 100644 --- a/tests/PayPal/Test/Api/SaleTest.php +++ b/tests/PayPal/Test/Api/SaleTest.php @@ -7,6 +7,7 @@ use PayPal\Test\Constants; use PayPal\Test\Api\AmountTest; use PayPal\Test\Api\PaymentTest; use PayPal\Test\Api\LinksTest; +use PayPal\Exception\PPConnectionException; class SaleTest extends \PHPUnit_Framework_TestCase { @@ -51,23 +52,32 @@ class SaleTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($s1, $s2); } - + + /** + * @group integration + */ public function testOperations() { - $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); + 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 From ff5dd2461f6818307f080bc66d2f652be3173188 Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Sun, 21 Sep 2014 21:01:53 -0500 Subject: [PATCH 2/5] Updated Testing Framework fixing Travis Builds - Created separate PHPUnit Test for Integration --- .travis.yml | 3 +++ phpunit.integration.xml | 32 ++++++++++++++++++++++++++++++++ phpunit.xml | 4 +--- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 phpunit.integration.xml diff --git a/.travis.yml b/.travis.yml index a0c7ff0..31f16bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,9 @@ php: - 5.5 - 5.6 - hhvm +env: + - CONFIGURATION_FILE=phpunit.xml + - CONFIGURATION_FILE=phpunit.integration.xml matrix: allow_failures: - php: hhvm diff --git a/phpunit.integration.xml b/phpunit.integration.xml new file mode 100644 index 0000000..3738b96 --- /dev/null +++ b/phpunit.integration.xml @@ -0,0 +1,32 @@ + + + + + + tests + + + + + + + + + + + + ./lib + + + + + \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 8aec30d..d298fb2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,9 +17,7 @@ - - integration - + integration From e7afb497bb197dd61b89d3c78f882710c24b0228 Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Sun, 21 Sep 2014 21:02:48 -0500 Subject: [PATCH 3/5] Updated Testing Framework fixing Travis Builds - Created separate PHPUnit Test for Integration --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31f16bc..3510004 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_script: script: - mkdir build - mkdir build/coverage - - phpunit + - phpunit -c $CONFIGURATION_FILE after_success: - php vendor/bin/coveralls -v -c .coveralls.yml notifications: From 0ed9c26d02f95ee7fb0bcc2e71ecbe2e0fca0ea9 Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Wed, 24 Sep 2014 13:41:32 -0500 Subject: [PATCH 4/5] Updated version of SDK Core - Updated version - Fixed Testing Bugs - Updated README - Updated Release note --- .gitignore | 1 + .travis.yml | 5 +-- README.md | 18 +++++++- composer.json | 4 +- release_notes.md | 12 ++++++ sample/composer.json | 2 +- sample/payments/CreatePayment.php | 68 ++++++++++++++++--------------- tests/sdk_config.ini | 14 +++---- 8 files changed, 77 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 437354b..bac603c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ build .project .settings .buildpath +atlassian-ide-plugin.xml *.bak # Composer diff --git a/.travis.yml b/.travis.yml index 3510004..a0c7ff0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,6 @@ php: - 5.5 - 5.6 - hhvm -env: - - CONFIGURATION_FILE=phpunit.xml - - CONFIGURATION_FILE=phpunit.integration.xml matrix: allow_failures: - php: hhvm @@ -18,7 +15,7 @@ before_script: script: - mkdir build - mkdir build/coverage - - phpunit -c $CONFIGURATION_FILE + - phpunit after_success: - php vendor/bin/coveralls -v -c .coveralls.yml notifications: diff --git a/README.md b/README.md index 26915e0..0b065a8 100644 --- a/README.md +++ b/README.md @@ -104,10 +104,26 @@ use PayPal\Api\Payment; ## SDK Configuration The samples in this repo pick the SDK configuration from the `sdk_config.ini` file. If you do not want to use an ini file or want to pick your configuration dynamically, you can use the `$apiContext->setConfig()` method to pass in the configuration as a hashmap. See the `sample/bootstrap.php` file for an example. - + +## Testing + +There are two kinds of tests that we include in our sdk package. Unit tests, and Integration Tests. + +* **Unit Tests** + * Unit tests can be executed by running this command `phpunit` at Paypal SDK root location. + * It executes the tests with configuration stored in `phpunit.xml` file. +* **Integration Tests** + * Integration tests make curl requests to sandbox environments by default. It would test both unit as well as integration tests. To execute, run this command `phpunit -c phpunit.integration.xml` at Paypal SDK root location. + * It executes the tests with configuration stored in `phpunit.integration.xml` file. + * The configurations could be changed from `tests\sdk_config.ini` file. ## 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. +* 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/). + ## More help * [API Reference](https://developer.paypal.com/webapps/developer/docs/api/) diff --git a/composer.json b/composer.json index 4f89af9..c48fc9f 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": ">=5.3.0", "ext-curl": "*", "ext-json": "*", - "paypal/sdk-core-php": "2.4.*" + "paypal/sdk-core-php": "2.5.*" }, "require-dev": { "phpunit/phpunit": "3.7.*" @@ -24,5 +24,5 @@ "psr-0": { "PayPal": "lib/" } - } + } } diff --git a/release_notes.md b/release_notes.md index 3bd67e0..d7b9089 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,6 +1,18 @@ PayPal PHP SDK release notes ============================ +v0.11.0 +---- +* Ability for PUT and PATCH requests +* Invoice number, custom and soft descriptor +* Order API and tests, more Authorization tests +* remove references to sdk-packages +* patch for retrieving paid invoices +* Shipping address docs patch +* Remove @array annotation +* Validate return cancel url +* type hinting, comment cleaning, and getters and setters for Shipping + v0.8.0 ----- * Invoicing API support added diff --git a/sample/composer.json b/sample/composer.json index a743c50..305f340 100644 --- a/sample/composer.json +++ b/sample/composer.json @@ -9,6 +9,6 @@ "php": ">=5.3.0", "ext-curl": "*", "ext-json": "*", - "paypal/rest-api-sdk-php" : "0.8.*" + "paypal/rest-api-sdk-php" : "0.11.*" } } diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php index 34ed64b..36ec3d8 100644 --- a/sample/payments/CreatePayment.php +++ b/sample/payments/CreatePayment.php @@ -24,12 +24,12 @@ use PayPal\Api\Transaction; // used to fund a payment. $card = new CreditCard(); $card->setType("visa") - ->setNumber("4417119669820331") - ->setExpireMonth("11") - ->setExpireYear("2019") - ->setCvv2("012") - ->setFirstName("Joe") - ->setLastName("Shopper"); + ->setNumber("4417119669820331") + ->setExpireMonth("11") + ->setExpireYear("2019") + ->setCvv2("012") + ->setFirstName("Joe") + ->setLastName("Shopper"); // ### FundingInstrument // A resource representing a Payer's funding instrument. @@ -44,21 +44,25 @@ $fi->setCreditCard($card); // to 'credit_card' and add an array of funding instruments. $payer = new Payer(); $payer->setPaymentMethod("credit_card") - ->setFundingInstruments(array($fi)); + ->setFundingInstruments(array($fi)); // ### Itemized information // (Optional) Lets you specify item wise // information $item1 = new Item(); $item1->setName('Ground Coffee 40 oz') - ->setCurrency('USD') - ->setQuantity(1) - ->setPrice('7.50'); + ->setDescription('Ground Coffee 40 oz') + ->setCurrency('USD') + ->setQuantity(1) + ->setTax('0.30') + ->setPrice('7.50'); $item2 = new Item(); $item2->setName('Granola bars') - ->setCurrency('USD') - ->setQuantity(5) - ->setPrice('2.00'); + ->setDescription('Granola Bars with Peanuts') + ->setCurrency('USD') + ->setQuantity(5) + ->setTax('0.20') + ->setPrice('2.00'); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2)); @@ -69,8 +73,8 @@ $itemList->setItems(array($item1, $item2)); // charges etc. $details = new Details(); $details->setShipping('1.20') - ->setTax('1.30') - ->setSubtotal('17.50'); + ->setTax('1.30') + ->setSubtotal('17.50'); // ### Amount // Lets you specify a payment amount. @@ -78,8 +82,8 @@ $details->setShipping('1.20') // such as shipping, tax. $amount = new Amount(); $amount->setCurrency("USD") - ->setTotal("20.00") - ->setDetails($details); + ->setTotal("20.00") + ->setDetails($details); // ### Transaction // A transaction defines the contract of a @@ -87,39 +91,39 @@ $amount->setCurrency("USD") // is fulfilling it. $transaction = new Transaction(); $transaction->setAmount($amount) - ->setItemList($itemList) - ->setDescription("Payment description"); + ->setItemList($itemList) + ->setDescription("Payment description"); // ### Payment // A Payment Resource; create one using // the above types and intent set to sale 'sale' $payment = new Payment(); $payment->setIntent("sale") - ->setPayer($payer) - ->setTransactions(array($transaction)); + ->setPayer($payer) + ->setTransactions(array($transaction)); // ### Create Payment // Create a payment by calling the payment->create() method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // The return object contains the state. try { - $payment->create($apiContext); + $payment->create($apiContext); } catch (PayPal\Exception\PPConnectionException $ex) { - echo "Exception: " . $ex->getMessage() . PHP_EOL; - var_dump($ex->getData()); - exit(1); + echo "Exception: " . $ex->getMessage() . PHP_EOL; + var_dump($ex->getData()); + exit(1); } ?> - Direct Credit card payments + Direct Credit card payments -
- Created payment: - getId();?> -
+
+ Created payment: + getId();?> +
toArray());?>
- Back + Back - + \ No newline at end of file diff --git a/tests/sdk_config.ini b/tests/sdk_config.ini index f73b92a..10bcb6e 100644 --- a/tests/sdk_config.ini +++ b/tests/sdk_config.ini @@ -23,13 +23,13 @@ service.EndPoint="https://api.sandbox.paypal.com" log.LogEnabled=true -# When using a relative path, the log file is created -# relative to the .php file that is the entry point -# for this request. You can also provide an absolute -# path here +; When using a relative path, the log file is created +; relative to the .php file that is the entry point +; for this request. You can also provide an absolute +; path here log.FileName=PayPal.log -# Logging level can be one of FINE, INFO, WARN or ERROR -# Logging is most verbose in the 'FINE' level and -# decreases as you proceed towards ERROR +; Logging level can be one of FINE, INFO, WARN or ERROR +; Logging is most verbose in the 'FINE' level and +; decreases as you proceed towards ERROR log.LogLevel=FINE From 72ddeccc0ae7dd10e4b22d93733af11afcb544c1 Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Wed, 24 Sep 2014 15:03:08 -0500 Subject: [PATCH 5/5] Updated version of SDK Core - Updated sample to not use its own composer.json --- sample/README.md | 4 ++-- sample/bootstrap.php | 7 +++++-- sample/composer.json | 14 -------------- 3 files changed, 7 insertions(+), 18 deletions(-) delete mode 100644 sample/composer.json diff --git a/sample/README.md b/sample/README.md index 70e1a9b..bda3407 100644 --- a/sample/README.md +++ b/sample/README.md @@ -1,9 +1,9 @@ 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. -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 samples folder and you are all set. - +To try out the sample, run `composer update --no-dev` from the rest-api-sdk-php 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 diff --git a/sample/bootstrap.php b/sample/bootstrap.php index 48ead06..d253e9c 100644 --- a/sample/bootstrap.php +++ b/sample/bootstrap.php @@ -4,12 +4,15 @@ */ // Include the composer autoloader +// The location of your project's vendor autoloader. $composerAutoload = dirname(dirname(dirname(__DIR__))) . '/autoload.php'; if (!file_exists($composerAutoload)) { - $composerAutoload = __DIR__ .'/vendor/autoload.php'; + //If the project is used as its own project, it would use rest-api-sdk-php composer autoloader. + $composerAutoload = dirname(__DIR__) .'/vendor/autoload.php'; - if(!file_exists(__DIR__ .'/vendor/autoload.php')) { + + if(!file_exists($composerAutoload)) { echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n"; exit(1); } diff --git a/sample/composer.json b/sample/composer.json deleted file mode 100644 index 305f340..0000000 --- a/sample/composer.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "paypal/rest-api-sdk-sample-php", - "description": "Samples using PayPal's REST API SDK for PHP", - "homepage": "https://github.com/paypal/rest-api-sdk-php", - "config": { - "require-all": true - }, - "require": { - "php": ">=5.3.0", - "ext-curl": "*", - "ext-json": "*", - "paypal/rest-api-sdk-php" : "0.11.*" - } -}