use of com.stripe.model.Subscription in project stripe-java by stripe.
the class SubscriptionItemTest method testSubscriptionItemRetrieve.
@Test
public void testSubscriptionItemRetrieve() throws StripeException {
Customer customer = Customer.create(defaultCustomerParams);
Subscription subscription = createDefaultSubscription(customer);
SubscriptionItem subscriptionItem = createDefaultSubscriptionItem(subscription);
SubscriptionItem retrievedSubscriptionItem = SubscriptionItem.retrieve(subscriptionItem.getId());
assertEquals(subscriptionItem.getId(), retrievedSubscriptionItem.getId());
}
use of com.stripe.model.Subscription in project stripe-java by stripe.
the class SubscriptionTest method testNewStyleSubscriptionAPI.
@Test
public void testNewStyleSubscriptionAPI() throws StripeException {
final Plan plan = Plan.create(getUniquePlanParams());
final Plan plan2 = Plan.create(getUniquePlanParams());
Customer customer = Customer.create(defaultCustomerParams);
// Create
Map<String, Object> subCreateParams = new HashMap<String, Object>();
subCreateParams.put("plan", plan.getId());
Subscription sub = customer.createSubscription(subCreateParams);
assertEquals(plan.getId(), sub.getPlan().getId());
customer = Customer.retrieve(customer.getId());
assertEquals(1, customer.getSubscriptions().getData().size());
assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
// Retrieve
Subscription retrievedSub = customer.getSubscriptions().retrieve(sub.getId());
assertEquals(sub.getId(), retrievedSub.getId());
// List
CustomerSubscriptionCollection list = customer.getSubscriptions().all(null);
assertEquals(1, list.getData().size());
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);
assertEquals(plan2.getId(), sub.getPlan().getId());
// Cancel
sub = sub.cancel(null);
assertNotNull(sub.getCanceledAt());
}
use of com.stripe.model.Subscription in project stripe-java by stripe.
the class SubscriptionTest method testCreateSubscriptionThroughCollection.
@Test
public void testCreateSubscriptionThroughCollection() throws StripeException {
Plan plan = Plan.create(getUniquePlanParams());
Customer customer = Customer.create(defaultCustomerParams);
// Create
Map<String, Object> subCreateParams = new HashMap<String, Object>();
subCreateParams.put("plan", plan.getId());
Subscription sub = customer.getSubscriptions().create(subCreateParams);
assertEquals(plan.getId(), sub.getPlan().getId());
// Verify
customer = Customer.retrieve(customer.getId());
assertEquals(1, customer.getSubscriptions().getData().size());
assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
}
use of com.stripe.model.Subscription in project stripe-java by stripe.
the class SubscriptionTest method testCancelSubscriptionPerCallAPIKey.
@Test
public void testCancelSubscriptionPerCallAPIKey() throws StripeException {
Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
Customer customer = createDefaultCustomerWithPlan(plan);
assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
Subscription canceledSubscription = customer.cancelSubscription(Stripe.apiKey);
assertEquals(canceledSubscription.getStatus(), "canceled");
}
use of com.stripe.model.Subscription in project stripe-java by stripe.
the class SubscriptionTest method testCancelSubscription.
@Test
public void testCancelSubscription() throws StripeException {
Plan plan = Plan.create(getUniquePlanParams());
Customer customer = createDefaultCustomerWithPlan(plan);
assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
Subscription canceledSubscription = customer.cancelSubscription();
assertEquals(canceledSubscription.getStatus(), "canceled");
}
Aggregations