Search in sources :

Example 16 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method testTopLevelSubscriptionAPI.

@Test
public void testTopLevelSubscriptionAPI() 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());
    subCreateParams.put("customer", customer.getId());
    Subscription sub = Subscription.create(subCreateParams);
    assertEquals(plan.getId(), sub.getPlan().getId());
    assertEquals(customer.getId(), sub.getCustomer());
    customer = Customer.retrieve(customer.getId());
    assertEquals(1, customer.getSubscriptions().getData().size());
    assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
    // Retrieve
    Subscription retrievedSub = Subscription.retrieve(sub.getId());
    assertEquals(sub.getId(), retrievedSub.getId());
    // List
    Map<String, Object> subAllParams = new HashMap<String, Object>();
    subAllParams.put("plan", plan.getId());
    subAllParams.put("customer", customer.getId());
    SubscriptionCollection list = Subscription.all(subAllParams);
    assertEquals(1, list.getData().size());
    assertEquals(sub.getId(), list.getData().get(0).getId());
    assertEquals(customer.getId(), list.getData().get(0).getCustomer());
    assertEquals(plan.getId(), list.getData().get(0).getPlan().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 : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) SubscriptionCollection(com.stripe.model.SubscriptionCollection) CustomerSubscriptionCollection(com.stripe.model.CustomerSubscriptionCollection) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 17 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method getSubscriptionParams.

static Map<String, Object> getSubscriptionParams() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    Map<String, Object> subscriptionParams = new HashMap<String, Object>();
    subscriptionParams.put("plan", plan.getId());
    return subscriptionParams;
}
Also used : HashMap(java.util.HashMap) Plan(com.stripe.model.Plan)

Example 18 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method testCancelSubscriptionAtPeriodEnd.

@Test
public void testCancelSubscriptionAtPeriodEnd() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    Customer customer = createDefaultCustomerWithPlan(plan);
    assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
    Map<String, Object> cancelParams = new HashMap<String, Object>();
    cancelParams.put("at_period_end", true);
    Subscription canceledSubscription = customer.cancelSubscription(cancelParams);
    assertEquals(canceledSubscription.getStatus(), "active");
    assertEquals(canceledSubscription.getCancelAtPeriodEnd(), true);
}
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 19 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method testUpdateSubscriptionPerCallAPIKey.

@Test
public void testUpdateSubscriptionPerCallAPIKey() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
    Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey);
    Map<String, Object> subscriptionParams = new HashMap<String, Object>();
    subscriptionParams.put("plan", plan.getId());
    Subscription sub = customer.updateSubscription(subscriptionParams, Stripe.apiKey);
    assertEquals(sub.getPlan().getId(), plan.getId());
    assertEquals(sub.getCustomer(), customer.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 20 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method testCancelSubscriptionAtPeriodEndPerCallAPIKey.

@Test
public void testCancelSubscriptionAtPeriodEndPerCallAPIKey() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
    Customer customer = createDefaultCustomerWithPlan(plan);
    assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
    Map<String, Object> cancelParams = new HashMap<String, Object>();
    cancelParams.put("at_period_end", true);
    Subscription canceledSubscription = customer.cancelSubscription(cancelParams, Stripe.apiKey);
    assertEquals(canceledSubscription.getStatus(), "active");
    assertEquals(canceledSubscription.getCancelAtPeriodEnd(), true);
}
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)

Aggregations

Plan (com.stripe.model.Plan)34 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)31 Test (org.junit.Test)31 HashMap (java.util.HashMap)21 Customer (com.stripe.model.Customer)16 DeletedPlan (com.stripe.model.DeletedPlan)14 Subscription (com.stripe.model.Subscription)11 Invoice (com.stripe.model.Invoice)5 CustomerSubscriptionCollection (com.stripe.model.CustomerSubscriptionCollection)2 DeletedCustomer (com.stripe.model.DeletedCustomer)1 DeletedInvoiceItem (com.stripe.model.DeletedInvoiceItem)1 InvoiceItem (com.stripe.model.InvoiceItem)1 InvoiceLineItemCollection (com.stripe.model.InvoiceLineItemCollection)1 PlanTier (com.stripe.model.PlanTier)1 PlanTransformUsage (com.stripe.model.PlanTransformUsage)1 SubscriptionCollection (com.stripe.model.SubscriptionCollection)1 SubscriptionItem (com.stripe.model.SubscriptionItem)1 UsageRecord (com.stripe.model.UsageRecord)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1