Created
December 7, 2013 09:15
-
-
Save jimdanz/7838912 to your computer and use it in GitHub Desktop.
Java multi-subs example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testNewStyleSubscriptionAPI() throws StripeException { | |
Plan plan = Plan.create(getUniquePlanParams(), MULTI_SUBS_API_KEY); | |
Plan plan2 = Plan.create(getUniquePlanParams(), MULTI_SUBS_API_KEY); | |
Customer customer = Customer.create(defaultCustomerParams, MULTI_SUBS_API_KEY); | |
// Create | |
Map<String, Object> subCreateParams = new HashMap<String, Object>(); | |
subCreateParams.put("plan", plan.getId()); | |
Subscription sub = customer.createSubscription(subCreateParams, MULTI_SUBS_API_KEY); | |
assertEquals(plan.getId(), sub.getPlan().getId()); | |
customer = Customer.retrieve(customer.getId(), MULTI_SUBS_API_KEY); | |
assertEquals(1, customer.getSubscriptions().getCount().intValue()); | |
assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId()); | |
// Retrieve | |
Subscription retrievedSub = customer.getSubscriptions().retrieve(sub.getId(), MULTI_SUBS_API_KEY); | |
assertEquals(sub.getId(), retrievedSub.getId()); | |
// List | |
CustomerSubscriptionCollection list = customer.getSubscriptions().all(null, MULTI_SUBS_API_KEY); | |
assertEquals(1, list.getCount().intValue()); | |
assertEquals(sub.getId(), list.getData().get(0).getId()); | |
// Update | |
Map<String, Object> subUpdateParams = new HashMap<String, Object>(); | |
subUpdateParams.put("plan", plan2.getId()); | |
sub = sub.update(subUpdateParams, MULTI_SUBS_API_KEY); | |
assertEquals(plan2.getId(), sub.getPlan().getId()); | |
// Cancel | |
sub = sub.cancel(null, MULTI_SUBS_API_KEY); | |
assertNotNull(sub.getCanceledAt()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment