Skip to content

Commit

Permalink
Tests for oxxo recurrent source. (#122)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vicentemendoza authored and Eduardo Enriquez committed Mar 26, 2018
1 parent 2901eb3 commit 300908f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down
22 changes: 22 additions & 0 deletions lib/Conekta/PaymentSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}
36 changes: 36 additions & 0 deletions test/Conekta-2.0/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 300908f

Please sign in to comment.