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());
}
Aggregations