diff --git a/src/Message/CancelSubscriptionRequest.php b/src/Message/CancelSubscriptionRequest.php index 30de0819..beb362e2 100644 --- a/src/Message/CancelSubscriptionRequest.php +++ b/src/Message/CancelSubscriptionRequest.php @@ -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; } diff --git a/tests/Message/CancelSubscriptionRequestTest.php b/tests/Message/CancelSubscriptionRequestTest.php index 6d5f047e..015197f4 100644 --- a/tests/Message/CancelSubscriptionRequestTest.php +++ b/tests/Message/CancelSubscriptionRequestTest.php @@ -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()