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