Search in sources :

Example 1 with PlanTier

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

Aggregations

BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)1 DeletedPlan (com.stripe.model.DeletedPlan)1 Plan (com.stripe.model.Plan)1 PlanTier (com.stripe.model.PlanTier)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1