From 300908f856eba04ce8a758d1c5ae1e5b1a5d3d5c Mon Sep 17 00:00:00 2001 From: vicentemendoza Date: Mon, 26 Mar 2018 10:33:51 -0600 Subject: [PATCH] Tests for oxxo recurrent source. (#122) Why is this change neccesary? For the php version is needed support to oxxo recurrent. How does it address the issue? Validate oxxo recurrent is working. What side effects does this change have? Nothing. --- CHANGELOG.md | 4 ++++ composer.json | 4 ++-- lib/Conekta/PaymentSource.php | 22 +++++++++++++++++++ test/Conekta-2.0/CustomerTest.php | 36 +++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9987ff0..db4d61c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.0.2](https://github.com/conekta/conekta-php/releases/tag/v4.0.1) - 2018-03-22 +### Feature +- Support to Oxxo recurrent + ## [4.0.1](https://github.com/conekta/conekta-php/releases/tag/v4.0.1) - 2017-12-29 ### Feature - Implement void action for orders diff --git a/composer.json b/composer.json index f9af095..6d62991 100644 --- a/composer.json +++ b/composer.json @@ -15,13 +15,13 @@ } ], "require": { - "php": ">=5.3", + "php": "~7.0", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "*" + "phpunit/phpunit": "~6.1" }, "autoload": { "classmap": ["lib/Conekta/"] diff --git a/lib/Conekta/PaymentSource.php b/lib/Conekta/PaymentSource.php index 7432394..d437506 100644 --- a/lib/Conekta/PaymentSource.php +++ b/lib/Conekta/PaymentSource.php @@ -9,6 +9,9 @@ class PaymentSource extends ConektaResource { + const TYPE_CARD = 'card'; + const TYPE_OXXO_RECURRENT = 'oxxo_recurrent'; + public function instanceUrl() { $this->apiVersion = Conekta::$apiVersion; @@ -31,4 +34,23 @@ public function delete() { return parent::_delete('customer', 'payment_sources'); } + + /** + * Method for determine if is card + * @return boolean + */ + public function isCard() + { + return $this['type'] == self::TYPE_CARD; + } + + /** + * Method for determine if is oxxo recurrent + * @return boolean + */ + public function isOxxoRecurrent() + { + return $this['type'] == self::TYPE_OXXO_RECURRENT; + } + } diff --git a/test/Conekta-2.0/CustomerTest.php b/test/Conekta-2.0/CustomerTest.php index e4b777e..5bbff61 100644 --- a/test/Conekta-2.0/CustomerTest.php +++ b/test/Conekta-2.0/CustomerTest.php @@ -12,6 +12,13 @@ class CustomerTest extends BaseTest 'email' => 'hola@hola.com', 'names' => 'John Constantine' ); + public static $validRecurrentCustomer = array( + 'name' => 'John Constantine', + 'email' => 'john_constantine@conekta.com', + 'payment_sources' => array(array( + 'type' => 'oxxo_recurrent', + )) + ); public function testSuccesfulCustomerCreate() { @@ -57,9 +64,11 @@ public function testSuccesfulSourceCreate() 'type' => 'card' )); $this->assertTrue(strpos(get_class($source), 'PaymentSource') !== false); + $this->assertTrue($source->isCard()); $this->assertTrue(strpos(get_class($customer->payment_sources), 'ConektaList') !== false); $this->assertTrue($customer->payment_sources->total == 1); } + public function testSuccessfulSourceDelete() { $this->setApiKey(); @@ -97,4 +106,31 @@ public function testSuccesfulShippingContactCreate() $this->assertTrue(strpos(get_class($customer->shipping_contacts), 'ConektaList') !== false); $this->assertTrue($customer->shipping_contacts->total == 1); } + + public function testOfflineRecurrentSourceIsCreated() + { + $this->setApiKey(); + $customer = Customer::create(self::$validCustomer); + $source = $customer->createPaymentSource(array( + 'type' => 'oxxo_recurrent' + )); + $this->assertTrue(strpos(get_class($source), 'PaymentSource') !== false); + $this->assertTrue(strpos(get_class($customer->payment_sources), 'ConektaList') !== false); + $this->assertTrue($customer->payment_sources->total == 1); + $this->assertEquals($source['type'], 'oxxo_recurrent'); + $this->assertTrue(strlen($source['reference']) == 14); + } + + public function testCustomerWithOfflineRecurrentSourceIsCreated() + { + $this->setApiKey(); + $customer = Customer::create(self::$validRecurrentCustomer); + $source = $customer->payment_sources[0]; + $this->assertTrue(strpos(get_class($source), 'PaymentSource') !== false); + $this->assertTrue(strpos(get_class($customer->payment_sources), 'ConektaList') !== false); + $this->assertTrue($customer->payment_sources->total == 1); + $this->assertEquals($source['type'], 'oxxo_recurrent'); + $this->assertTrue($source->isOxxoRecurrent()); + $this->assertTrue(strlen($source['reference']) == 14); + } }