Skip to content

Commit

Permalink
Merge pull request #55 from WellingGuzman/dev
Browse files Browse the repository at this point in the history
Ability to cancel subscriptions at the end of its period
  • Loading branch information
delatbabel authored Sep 14, 2016
2 parents f2c5b48 + eaa9949 commit 6eab75f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Message/CancelSubscriptionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,50 @@ public function getSubscriptionReference()
/**
* Set the set subscription reference.
*
* @param string $value
*
* @return CancelSubscriptionRequest provides a fluent interface.
*/
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;
}

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 6eab75f

Please sign in to comment.