From 16116730a5080dd36fc1d6858517bd656f8bd5a5 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Tue, 30 Aug 2016 16:09:43 -0400 Subject: [PATCH 1/3] add CancelSubscription at_period_end parameter --- src/Message/CancelSubscriptionRequest.php | 28 ++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Message/CancelSubscriptionRequest.php b/src/Message/CancelSubscriptionRequest.php index da5abb01..30de0819 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,11 +35,35 @@ 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(); + $data = array( + 'at_period_end' => $this->getAtPeriodEnd() + ); return $data; } From dd1884bbb92c19701aa4ea2fce43528f1f53c333 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Tue, 30 Aug 2016 21:34:39 -0400 Subject: [PATCH 2/3] Fix boolean value issue --- src/Message/CancelSubscriptionRequest.php | 11 ++++++++--- tests/Message/CancelSubscriptionRequestTest.php | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) 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() From eaa99493c468030aa7fc603e0ca3e38645396ec5 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Wed, 31 Aug 2016 12:29:26 -0400 Subject: [PATCH 3/3] fix comment note typo --- src/Message/CancelSubscriptionRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/CancelSubscriptionRequest.php b/src/Message/CancelSubscriptionRequest.php index beb362e2..b1c38819 100644 --- a/src/Message/CancelSubscriptionRequest.php +++ b/src/Message/CancelSubscriptionRequest.php @@ -64,7 +64,7 @@ public function getData() $data = array(); // NOTE: Boolean must be passed as string - // Otherwise it will be converted as numeric 1 or 2 + // Otherwise it will be converted to numeric 0 or 1 // Causing an error with the API if ($this->getAtPeriodEnd()) { $data['at_period_end'] = 'true';