Search in sources :

Example 11 with Subscription

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());
}
Also used : DeletedSubscriptionItem(com.stripe.model.DeletedSubscriptionItem) SubscriptionItem(com.stripe.model.SubscriptionItem) Customer(com.stripe.model.Customer) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 12 with Subscription

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());
}
Also used : CustomerSubscriptionCollection(com.stripe.model.CustomerSubscriptionCollection) Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 13 with Subscription

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());
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 14 with Subscription

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");
}
Also used : Customer(com.stripe.model.Customer) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 15 with Subscription

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");
}
Also used : Customer(com.stripe.model.Customer) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)16 Subscription (com.stripe.model.Subscription)16 Test (org.junit.Test)16 Customer (com.stripe.model.Customer)15 Plan (com.stripe.model.Plan)11 HashMap (java.util.HashMap)11 SubscriptionItem (com.stripe.model.SubscriptionItem)6 DeletedSubscriptionItem (com.stripe.model.DeletedSubscriptionItem)5 CustomerSubscriptionCollection (com.stripe.model.CustomerSubscriptionCollection)2 SubscriptionCollection (com.stripe.model.SubscriptionCollection)1 SubscriptionItemCollection (com.stripe.model.SubscriptionItemCollection)1 UsageRecord (com.stripe.model.UsageRecord)1