Search in sources :

Example 26 with Plan

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

the class PlanTest method testPlanCreateMetered.

@Test
public void testPlanCreateMetered() throws StripeException {
    Map<String, Object> productParams = new HashMap<String, Object>();
    productParams.put("name", "Bar");
    Map<String, Object> params = getUniquePlanParams();
    params.remove("name");
    params.put("nickname", "Foo");
    params.put("product", productParams);
    params.put("usage_type", "metered");
    Plan plan = Plan.create(params);
    assertEquals("metered", plan.getUsageType());
}
Also used : HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) DeletedPlan(com.stripe.model.DeletedPlan) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 27 with Plan

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

the class PlanTest method testPlanCreateWithStatementDescriptor.

@Test
public void testPlanCreateWithStatementDescriptor() throws StripeException {
    Map<String, Object> planParamsWithStatementDescriptor = getUniquePlanParams();
    planParamsWithStatementDescriptor.put("statement_descriptor", "Stripe");
    Plan plan = Plan.create(planParamsWithStatementDescriptor);
    assertEquals(plan.getStatementDescriptor(), "Stripe");
}
Also used : Plan(com.stripe.model.Plan) DeletedPlan(com.stripe.model.DeletedPlan) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 28 with Plan

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

the class PlanTest method testPlanCreateWithTiers.

@Test
public void testPlanCreateWithTiers() throws StripeException {
    Map<String, Object> productParams = new HashMap<String, Object>();
    productParams.put("name", "Bar");
    Map<String, Object> params = getUniquePlanParams();
    params.remove("amount");
    params.remove("name");
    params.put("nickname", "Foo");
    params.put("product", productParams);
    Map<String, Object> tier1 = new HashMap<>();
    tier1.put("up_to", 1000);
    tier1.put("amount", 1000);
    Map<String, Object> tier2 = new HashMap<>();
    tier2.put("up_to", "inf");
    tier2.put("amount", 2000);
    List<Map<String, Object>> tiers = new ArrayList<>();
    tiers.add(tier1);
    tiers.add(tier2);
    params.put("tiers", tiers);
    params.put("tiers_mode", "volume");
    params.put("billing_scheme", "tiered");
    Plan plan = Plan.create(params);
    assertEquals(null, plan.getAmount());
    assertEquals("volume", plan.getTiersMode());
    List<PlanTier> tierConfig = plan.getTiers();
    assertEquals(2, tierConfig.size());
    assertEquals(new Long(1000), tierConfig.get(0).getAmount());
    assertEquals(new Long(1000), tierConfig.get(0).getUpTo());
    assertEquals(null, tierConfig.get(1).getUpTo());
    assertEquals(new Long(2000), tierConfig.get(1).getAmount());
}
Also used : PlanTier(com.stripe.model.PlanTier) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Plan(com.stripe.model.Plan) DeletedPlan(com.stripe.model.DeletedPlan) HashMap(java.util.HashMap) Map(java.util.Map) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 29 with Plan

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

the class PlanTest method testPlanUpdate.

@Test
public void testPlanUpdate() throws StripeException {
    Plan createdPlan = Plan.create(getUniquePlanParams());
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("name", "Updated Plan Name");
    Plan updatedplan = createdPlan.update(updateParams);
    assertEquals(updatedplan.getName(), "Updated Plan Name");
}
Also used : HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) DeletedPlan(com.stripe.model.DeletedPlan) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 30 with Plan

use of com.stripe.model.Plan 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)

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