From 243cfa680b9d70e4e86911a0ca1f773bce6ce2fc Mon Sep 17 00:00:00 2001 From: brunoric Date: Fri, 22 Aug 2014 16:58:54 -0300 Subject: [PATCH 01/10] Adding .idea project folder to gitignore file. This will be usefull for PhpStorm users. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e9c37ab..437354b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ build *.log # IDE +.idea .project .settings .buildpath From cc67faf8224f0c6b71a54afcb294ee1375a2571a Mon Sep 17 00:00:00 2001 From: brunoric Date: Fri, 22 Aug 2014 16:59:42 -0300 Subject: [PATCH 02/10] Adding the missing get and setter tests. --- tests/PayPal/Test/Api/AuthorizationTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/AuthorizationTest.php b/tests/PayPal/Test/Api/AuthorizationTest.php index 73b2f25..287abc8 100644 --- a/tests/PayPal/Test/Api/AuthorizationTest.php +++ b/tests/PayPal/Test/Api/AuthorizationTest.php @@ -19,9 +19,11 @@ use PayPal\Exception\PPConnectionException; class AuthorizationTest extends \PHPUnit_Framework_TestCase { private $authorizations = array(); public static $create_time = "2013-02-28T00:00:00Z"; + public static $update_time = "2013-03-28T00:00:00Z"; public static $id = "AUTH-123"; public static $state = "Created"; public static $parent_payment = "PAY-12345"; + public static $valid_until = "2013-04-28T00:00:00Z"; public static $currency = "USD"; public static $total = "1.12"; public static $href = "USD"; @@ -90,20 +92,24 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase { public function setup() { $authorization = new Authorization(); $authorization->setCreateTime(self::$create_time); + $authorization->setUpdateTime(self::$update_time); $authorization->setId(self::$id); $authorization->setState(self::$state); $authorization->setParentPayment(self::$parent_payment); + $authorization->setValidUntil(self::$valid_until); $this->authorizations['partial'] = $authorization; $this->authorizations['full'] = self::createAuthorization(); } - public function testGetterSetter() { + public function testGetterSetter() { $authorization = $this->authorizations['partial']; $this->assertEquals(self::$create_time, $authorization->getCreateTime()); + $this->assertEquals(self::$update_time, $authorization->getUpdateTime()); $this->assertEquals(self::$id, $authorization->getId()); $this->assertEquals(self::$state, $authorization->getState()); $this->assertEquals(self::$parent_payment, $authorization->getParentPayment()); + $this->assertEquals(self::$valid_until, $authorization->getValidUntil()); $authorization = $this->authorizations['full']; $this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency()); From bcd0b80e8568bab7a039a0e6365dfd26b6e9e169 Mon Sep 17 00:00:00 2001 From: brunoric Date: Fri, 22 Aug 2014 17:49:30 -0300 Subject: [PATCH 03/10] Adding \InvalidArgumentException tests to void() and reauthorize(). --- tests/PayPal/Test/Api/AuthorizationTest.php | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/PayPal/Test/Api/AuthorizationTest.php b/tests/PayPal/Test/Api/AuthorizationTest.php index 287abc8..64d45a1 100644 --- a/tests/PayPal/Test/Api/AuthorizationTest.php +++ b/tests/PayPal/Test/Api/AuthorizationTest.php @@ -143,9 +143,15 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase { $void = $auth->void(); $this->assertNotNull($void->getId()); + $auth->setId(null); + try { + $auth->void(); + } catch (\InvalidArgumentException $ex) { + $this->assertEquals($ex->getMessage(), "Id cannot be null"); + } } - public function testReauthorize(){ + public function testReauthorize() { $authorization = Authorization::get('7GH53639GA425732B'); $amount = new Amount(); @@ -153,10 +159,18 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase { $amount->setTotal("1.00"); $authorization->setAmount($amount); - try{ - $reauthorization = $authorization->reauthorize(); - }catch (PPConnectionException $ex){ + try { + $authorization->reauthorize(); + } catch (PPConnectionException $ex){ + var_dump($ex->getMessage()); $this->assertEquals(strpos($ex->getMessage(),"500"), false); } + + $authorization->setId(null); + try { + $authorization->reauthorize(); + } catch (\InvalidArgumentException $ex) { + $this->assertEquals($ex->getMessage(), "Id cannot be null"); + } } } From 93f44d01f5439866132fef23717b853868f01c13 Mon Sep 17 00:00:00 2001 From: OJ Tibi Date: Tue, 26 Aug 2014 12:22:39 +0800 Subject: [PATCH 04/10] Added editorconfig to help contributors with indentation rules --- .editorconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4b3c2b7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# EditorConfig: Manage project indentation rules. http://EditorConfig.org + +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.php] +indent_style = space +indent_size = 4 \ No newline at end of file From 0da7a1b64a03cef47a15a6c2b99758cf8cf5fa62 Mon Sep 17 00:00:00 2001 From: OJ Tibi Date: Tue, 26 Aug 2014 13:49:41 +0800 Subject: [PATCH 05/10] Added Order class for proper parsing within PPModel::fromArray() --- lib/PayPal/Api/Order.php | 231 ++++++++++++++++++++++++++++ tests/PayPal/Test/Api/OrderTest.php | 61 ++++++++ 2 files changed, 292 insertions(+) create mode 100644 lib/PayPal/Api/Order.php create mode 100644 tests/PayPal/Test/Api/OrderTest.php diff --git a/lib/PayPal/Api/Order.php b/lib/PayPal/Api/Order.php new file mode 100644 index 0000000..22f203c --- /dev/null +++ b/lib/PayPal/Api/Order.php @@ -0,0 +1,231 @@ +id = $id; + + return $this; + } + + /** + * Get the identifier of the order transaction. + * + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Set the time the resource was created. + * + * @param string $create_time + * + * @return $this + */ + public function setCreateTime($create_time) + { + $this->create_time = $create_time; + + return $this; + } + + /** + * Get the time the resource was created. + * + * @return string + */ + public function getCreateTime() + { + return $this->create_time; + } + + /** + * Set the time the resource was last updated. + * + * @param string $update_time + * + * @return $this + */ + public function setUpdateTime($update_time) + { + $this->update_time = $update_time; + + return $this; + } + + /** + * Get the time the resource was last updated. + * + * @return string + */ + public function getUpdateTime() + { + return $this->update_time; + } + + /** + * Set the state of the order transaction. + * + * Allowed values are: `PENDING`, `COMPLETED`, `REFUNDED` or `PARTIALLY_REFUNDED`. + * + * @param string $state + * + * @return $this + */ + public function setState($state) + { + $this->state = $state; + + return $this; + } + + /** + * Get the state of the order transaction. + * + * Allowed values are: `PENDING`, `COMPLETED`, `REFUNDED` or `PARTIALLY_REFUNDED`. + * + * @return string + */ + public function getState() + { + return $this->state; + } + + /** + * Set the amount being collected. + * + * @param \PayPal\Api\Amount $amount + * + * @return $this + */ + public function setAmount($amount) + { + $this->amount = $amount; + + return $this; + } + + /** + * Get the amount being collected. + * + * @return \PayPal\Api\Amount + */ + public function getAmount() + { + return $this->amount; + } + + /** + * Set ID of the payment resource on which this transaction is based. + * + * @param string $parent_payment + * + * @return $this + */ + public function setParentPayment($parent_payment) + { + $this->parent_payment = $parent_payment; + + return $this; + } + + /** + * Get ID of the payment resource on which this transaction is based. + * + * @return string + */ + public function getParentPayment() + { + return $this->parent_payment; + } + + /** + * Set Links + * + * @param array|\PayPal\Api\Links $links + * + * @return $this + */ + public function setLinks($links) + { + $this->links = $links; + + return $this; + } + + /** + * Get Links + * + * @return array|\PayPal\Api\Links + */ + public function getLinks() + { + return $this->links; + } + + /** + * Reason code for the transaction state being Pending or Reversed. Assigned in response. + * + * Allowed values: `CHARGEBACK`, `GUARANTEE`, `BUYER_COMPLAINT`, `REFUND`, + * `UNCONFIRMED_SHIPPING_ADDRESS`, + * `ECHECK`, `INTERNATIONAL_WITHDRAWAL`, + * `RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION`, `PAYMENT_REVIEW`, + * `REGULATORY_REVIEW`, `UNILATERAL`, or `VERIFICATION_REQUIRED` + * (`ORDER` can also be set in the response). + * + * @param string $reason_code + * + * @return $this + */ + public function setReasonCode($reason_code) + { + $this->reason_code = $reason_code; + + return $this; + } + + /** + * Reason code for the transaction state being Pending or Reversed. Assigned in response. + * + * Allowed values: `CHARGEBACK`, `GUARANTEE`, `BUYER_COMPLAINT`, `REFUND`, + * `UNCONFIRMED_SHIPPING_ADDRESS`, + * `ECHECK`, `INTERNATIONAL_WITHDRAWAL`, + * `RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION`, `PAYMENT_REVIEW`, + * `REGULATORY_REVIEW`, `UNILATERAL`, or `VERIFICATION_REQUIRED` + * (`ORDER` can also be set in the response). + * + * @return string + */ + public function getReasonCode() + { + return $this->reason_code; + } +} diff --git a/tests/PayPal/Test/Api/OrderTest.php b/tests/PayPal/Test/Api/OrderTest.php new file mode 100644 index 0000000..1b28343 --- /dev/null +++ b/tests/PayPal/Test/Api/OrderTest.php @@ -0,0 +1,61 @@ +setId(self::$id); + $order->setCreateTime(self::$createTime); + $order->setUpdateTime(self::$updateTime); + $order->setState(self::$state); + $order->setAmount(AmountTest::createAmount()); + $order->setParentPayment(self::$parentPayment); + $order->setLinks(array($links)); + $order->setReasonCode(self::$reasonCode); + + return $order; + } + + public function setup() { + $this->order = self::createOrder(); + } + + public function testGetterSetter() { + $this->assertEquals(self::$id, $this->order->getId()); + $this->assertEquals(self::$createTime, $this->order->getCreateTime()); + $this->assertEquals(self::$updateTime, $this->order->getUpdateTime()); + $this->assertEquals(self::$state, $this->order->getState()); + $this->assertEquals(AmountTest::$currency, $this->order->getAmount()->getCurrency()); + $this->assertEquals(self::$parentPayment, $this->order->getParentPayment()); + $this->assertEquals(LinksTest::$href, $this->order->getLinks()[0]->getHref()); + $this->assertEquals(self::$reasonCode, $this->order->getReasonCode()); + } + + public function testSerializeDeserialize() { + $o1 = $this->order; + + $o2 = new Order(); + $o2->fromJson($this->o1->toJson()); + + $this->assertEquals($o1, $o2); + } +} From 72d2380df6ad46c859674857dcfe5d3586ef919a Mon Sep 17 00:00:00 2001 From: OJ Tibi Date: Tue, 26 Aug 2014 16:01:07 +0800 Subject: [PATCH 06/10] Added Order property to RelatedResources --- lib/PayPal/Api/RelatedResources.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/PayPal/Api/RelatedResources.php b/lib/PayPal/Api/RelatedResources.php index 5dcee4b..e9ba963 100644 --- a/lib/PayPal/Api/RelatedResources.php +++ b/lib/PayPal/Api/RelatedResources.php @@ -114,4 +114,28 @@ class RelatedResources extends PPModel { return $this->refund; } + + /** + * Set Order + * + * @param \PayPal\Api\Order $order + * + * @return $this + */ + public function setOrder($order) + { + $this->order = $order; + + return $this; + } + + /** + * Get Order + * + * @return \PayPal\Api\Order + */ + public function getOrder() + { + return $this->order; + } } From c1241998b846872d42e3f635668977f61f0529fe Mon Sep 17 00:00:00 2001 From: OJ Tibi Date: Tue, 26 Aug 2014 16:23:53 +0800 Subject: [PATCH 07/10] Fixed classname resolution of Links property in Order class for PPReflectionUtil --- lib/PayPal/Api/Order.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/PayPal/Api/Order.php b/lib/PayPal/Api/Order.php index 22f203c..ab760e7 100644 --- a/lib/PayPal/Api/Order.php +++ b/lib/PayPal/Api/Order.php @@ -14,7 +14,7 @@ use PayPal\Rest\ApiContext; * @property string state * @property \PayPal\Api\Amount amount * @property string parentPayment - * @property array|\PayPal\Api\Links links + * @property \PayPal\Api\Links links * @property string reasonCode */ class Order extends PPModel @@ -170,7 +170,7 @@ class Order extends PPModel /** * Set Links * - * @param array|\PayPal\Api\Links $links + * @param \PayPal\Api\Links $links * * @return $this */ @@ -184,7 +184,7 @@ class Order extends PPModel /** * Get Links * - * @return array|\PayPal\Api\Links + * @return \PayPal\Api\Links */ public function getLinks() { From 948c6f73d8fba35bf1a27a89912d30faa123e338 Mon Sep 17 00:00:00 2001 From: OJ Tibi Date: Tue, 26 Aug 2014 16:33:36 +0800 Subject: [PATCH 08/10] Added test for Order property in RelatedResources --- tests/PayPal/Test/Api/RelatedResourcesTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/RelatedResourcesTest.php b/tests/PayPal/Test/Api/RelatedResourcesTest.php index c977395..18a4e2c 100644 --- a/tests/PayPal/Test/Api/RelatedResourcesTest.php +++ b/tests/PayPal/Test/Api/RelatedResourcesTest.php @@ -12,6 +12,7 @@ class RelatedResourcesTest extends \PHPUnit_Framework_TestCase { $relatedResources = new RelatedResources(); $relatedResources->setAuthorization(AuthorizationTest::createAuthorization()); $relatedResources->setCapture(CaptureTest::createCapture()); + $relatedResources->setOrder(OrderTest::createOrder()); return $relatedResources; } @@ -22,6 +23,7 @@ class RelatedResourcesTest extends \PHPUnit_Framework_TestCase { public function testGetterSetter() { $this->assertEquals(AuthorizationTest::$create_time, $this->relatedResources->getAuthorization()->getCreateTime()); $this->assertEquals(CaptureTest::$create_time, $this->relatedResources->getCapture()->getCreateTime()); + $this->assertEquals(OrderTest::$id, $this->relatedResources->getOrder()->getId()); } public function testSerializeDeserialize() { @@ -32,4 +34,4 @@ class RelatedResourcesTest extends \PHPUnit_Framework_TestCase { $this->assertEquals($s1, $s2); } -} \ No newline at end of file +} From c5fec7ce7f8fb4b157d9074caed21d3f057a924c Mon Sep 17 00:00:00 2001 From: Avi Das Date: Tue, 26 Aug 2014 12:04:06 -0500 Subject: [PATCH 09/10] update typo in test --- tests/PayPal/Test/Api/OrderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/OrderTest.php b/tests/PayPal/Test/Api/OrderTest.php index 1b28343..946852d 100644 --- a/tests/PayPal/Test/Api/OrderTest.php +++ b/tests/PayPal/Test/Api/OrderTest.php @@ -54,7 +54,7 @@ class OrderTest extends \PHPUnit_Framework_TestCase { $o1 = $this->order; $o2 = new Order(); - $o2->fromJson($this->o1->toJson()); + $o2->fromJson($o1->toJson()); $this->assertEquals($o1, $o2); } From 2cdce05002ec1b8012344366e96b4be08fe1a3ec Mon Sep 17 00:00:00 2001 From: Avi Das Date: Tue, 26 Aug 2014 15:59:32 -0500 Subject: [PATCH 10/10] Remove var_dump --- tests/PayPal/Test/Api/AuthorizationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PayPal/Test/Api/AuthorizationTest.php b/tests/PayPal/Test/Api/AuthorizationTest.php index 64d45a1..2661b12 100644 --- a/tests/PayPal/Test/Api/AuthorizationTest.php +++ b/tests/PayPal/Test/Api/AuthorizationTest.php @@ -162,7 +162,7 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase { try { $authorization->reauthorize(); } catch (PPConnectionException $ex){ - var_dump($ex->getMessage()); + //var_dump($ex->getMessage()); $this->assertEquals(strpos($ex->getMessage(),"500"), false); }