Skip to content

Commit

Permalink
Merge pull request #22 from jtompkins/master
Browse files Browse the repository at this point in the history
Resolves #21 - Add method to cancel a single sub.
  • Loading branch information
paulirwin committed Jan 15, 2015
2 parents 866b884 + 4dc264e commit c299bc5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/StripeClient.Subscriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,20 @@ public StripeObject CancelCustomersSubscription(string customerId, bool? atPerio

return ExecuteObject(request);
}

public StripeObject CancelCustomersSubscription(string customerId, string subscriptionId, bool? atPeriodEnd = null) {
Require.Argument("customerId", customerId);

var request = new RestRequest();
request.Method = Method.DELETE;
request.Resource = "customers/{customerId}/subscriptions/{subscriptionId}";

request.AddUrlSegment("customerId", customerId);
request.AddUrlSegment("subscriptionId", subscriptionId);

if (atPeriodEnd.HasValue) request.AddParameter("at_period_end", atPeriodEnd.Value);

return ExecuteObject(request);
}
}
}
17 changes: 17 additions & 0 deletions test/Stripe.Tests/SubscriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,22 @@ public void CancelCustomersSubscription_Test()
Assert.NotNull(response.CanceledAt);
Assert.NotNull(response.EndedAt);
}

[Fact]
public void CancelSingleCustomersSubscription_Test() {
dynamic subscriptionResponse = _client.UpdateCustomersSubscription(_customer.Id, _plan.Id);

Assert.NotNull(subscriptionResponse);
Assert.False(subscriptionResponse.IsError);

var subId = subscriptionResponse["id"];

dynamic response = _client.CancelCustomersSubscription(_customer.Id, subId);

Assert.NotNull(response);
Assert.False(response.IsError);
Assert.NotNull(response.CanceledAt);
Assert.NotNull(response.EndedAt);
}
}
}

0 comments on commit c299bc5

Please sign in to comment.