Skip to content

Commit

Permalink
fix updates for submodels
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Murga committed Feb 2, 2017
1 parent ab0af43 commit c282ec5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/Conekta/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public function update($params = null)

public function createPaymentSource($params = null)
{
return parent::_createMember('payment_sources', $params);
return parent::_createMemberWithRelation('payment_sources', $params, $this);
}

public function createFiscalEntity($params = null)
{
return parent::_createMember('fiscal_entities', $params);
return parent::_createMemberWithRelation('fiscal_entities', $params, $this);
}

public function createCard($params = null)
{
return parent::_createMember('cards', $params);
return parent::_createMemberWithRelation('cards', $params, $this);
}

public function createSubscription($params = null)
Expand All @@ -133,7 +133,7 @@ public function createSubscription($params = null)

public function createShippingContact($params = null)
{
return parent::_createMember('shipping_contacts', $params);
return parent::_createMemberWithRelation('shipping_contacts', $params, $this);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/Conekta/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,22 @@ public function capture()

public function createTaxLine($params = null)
{
return parent::_createMember('tax_lines', $params);
return parent::_createMemberWithRelation('tax_lines', $params, $this);
}

public function createShippingLine($params = null)
{
return parent::_createMember('shipping_lines', $params);
return parent::_createMemberWithRelation('shipping_lines', $params, $this);
}

public function createDiscountLine($params = null)
{
return parent::_createMember('discount_lines', $params);
return parent::_createMemberWithRelation('discount_lines', $params, $this);
}

public function createLineItem($params = null)
{
return parent::_createMember('line_items', $params);
return parent::_createMemberWithRelation('line_items', $params, $this);
}

public function createFiscalEntity($params = null)
Expand Down
8 changes: 8 additions & 0 deletions lib/Conekta/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ protected function _customAction($method = 'post', $action = null, $params = nul

return $this;
}

protected function _createMemberWithRelation($member, $params, $parent)
{
$parent_class = strtolower((new \ReflectionClass($parent))->getShortName());
$child = self::_createMember($member, $params);
$child->$parent_class = $parent;
return $child;
}
}
2 changes: 1 addition & 1 deletion test/Conekta-2.0/FiscalEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSuccessfulFiscalEntityUpdate()
$customer = \Conekta\Customer::create(self::$valid_customer);

$customer->fiscal_entities[0]->update(array(
'ame' => 'Another name'
'name' => 'Another name'
));

$this->assertTrue($customer->fiscal_entities[0]->name == 'Another name');
Expand Down
2 changes: 1 addition & 1 deletion test/Conekta-2.0/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OrderTest extends UnitTestCase

public static $valid_return = array(
'amount' => 20000,
'reason' => 'Reason return',
'reason' => 'requested_by_client',
'currency' => 'MXN',
);

Expand Down

0 comments on commit c282ec5

Please sign in to comment.