Skip to content

Commit

Permalink
Fix boolean value issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Aug 31, 2016
1 parent 1611673 commit dd1884b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Message/CancelSubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ public function getData()
{
$this->validate('customerReference', 'subscriptionReference');

$data = array(
'at_period_end' => $this->getAtPeriodEnd()
);
$data = array();

// NOTE: Boolean must be passed as string
// Otherwise it will be converted as numeric 1 or 2
// Causing an error with the API
if ($this->getAtPeriodEnd()) {
$data['at_period_end'] = 'true';
}

return $data;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Message/CancelSubscriptionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ public function setUp()
$this->request = new CancelSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->setCustomerReference('cus_7lfqk3Om3t4xSU');
$this->request->setSubscriptionReference('sub_7mU0FokE8GQZFW');
$this->request->setAtPeriodEnd(true);
}

public function testEndpoint()
{
$this->assertSame('https://api.stripe.com/v1/customers/cus_7lfqk3Om3t4xSU/subscriptions/sub_7mU0FokE8GQZFW', $this->request->getEndpoint());
$this->assertSame(true, $this->request->getAtPeriodEnd());

$data = $this->request->getData();
$this->assertSame('true', $data['at_period_end']);
}

public function testSendSuccess()
Expand Down

0 comments on commit dd1884b

Please sign in to comment.