diff --git a/src/Message/CancelSubscriptionRequest.php b/src/Message/CancelSubscriptionRequest.php index da5abb01..b1c38819 100644 --- a/src/Message/CancelSubscriptionRequest.php +++ b/src/Message/CancelSubscriptionRequest.php @@ -26,6 +26,8 @@ public function getSubscriptionReference() /** * Set the set subscription reference. * + * @param string $value + * * @return CancelSubscriptionRequest provides a fluent interface. */ public function setSubscriptionReference($value) @@ -33,12 +35,41 @@ public function setSubscriptionReference($value) return $this->setParameter('subscriptionReference', $value); } + /** + * Set whether or not to cancel the subscription at period end. + * + * @param bool $value + * + * @return CancelSubscriptionRequest provides a fluent interface. + */ + public function setAtPeriodEnd($value) + { + return $this->setParameter('atPeriodEnd', $value); + } + + /** + * Get whether or not to cancel the subscription at period end. + * + * @return bool + */ + public function getAtPeriodEnd() + { + return $this->getParameter('atPeriodEnd'); + } + public function getData() { $this->validate('customerReference', 'subscriptionReference'); $data = array(); + // NOTE: Boolean must be passed as string + // Otherwise it will be converted to numeric 0 or 1 + // 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()