Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Tests/Recurly/Subscription_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,20 @@ public function testPauseSubscription() {
$this->assertEquals($subscription->remaining_pause_cycles, 1);
}

public function testCancelSubscriptionWithoutTimeframe() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/cancel', 'subscriptions/show-200.xml');
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
$subscription->cancel();
}

public function testCancelSubscriptionWithTimeframe() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/cancel?timeframe=term_end', 'subscriptions/show-200.xml');
$subscription = Recurly_Subscription::get('012345678901234567890123456789ab', $this->client);
$subscription->cancel('term_end');
}

public function testResumeSubscription() {
$this->client->addResponse('GET', '/subscriptions/012345678901234567890123456789ab', 'subscriptions/show-200.xml');
$this->client->addResponse('PUT', 'https://api.recurly.com/v2/subscriptions/012345678901234567890123456789ab/resume', 'subscriptions/show-200.xml');
Expand Down
15 changes: 11 additions & 4 deletions lib/recurly/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @property DateTime $current_term_ends_at End date of the subscription’s current term. Will be null if subscription has future start date.
* @property Recurly_CustomFieldList $custom_fields Optional custom fields for the subscription.
* @property string $uuid Subscription's unique identifier.
* @property string $timeframe now for immediate, renewal to perform when the subscription renews. Defaults to now.
* @property string $timeframe now for immediate, renewal to perform when the subscription renews. This must be one of 'now', 'bill_date', or 'term_end'. Defaults to 'now'
* @property string $gateway_code The unique identifier of a payment gateway used to specify which payment gateway you wish to process this subscriptions’ payments
* @property string $shipping_method_code The unique identifier of the shipping method for this subscription.
* @property integer $shipping_amount_in_cents The amount charged for shipping in cents.
Expand Down Expand Up @@ -88,12 +88,17 @@ public function preview() {
}

/**
* Cancel the subscription; it will remain active until it renews.
* Cancel the subscription
*
* @param string $timeframe The timeframe to apply the cancellation. This must be one of: 'bill_date' or 'term_end'.
* @throws Recurly_Error
*/
public function cancel() {
$this->_save(Recurly_Client::PUT, $this->uri() . '/cancel');
public function cancel($timeframe = null) {
$path = '/cancel';
if ($timeframe != null) {
$path = $path . '?timeframe=' . $timeframe;
}
$this->_save(Recurly_Client::PUT, $this->uri() . $path);
}

/**
Expand All @@ -118,7 +123,9 @@ public function updateImmediately() {

/**
* Make an update that applies when the subscription renews.
* timeframe = 'renewal' was deprecated in API version 2.22.
*
* @deprecated
* @throws Recurly_Error
*/
public function updateAtRenewal() {
Expand Down