use of com.stripe.model.Plan in project stripe-java by stripe.
the class SubscriptionTest method testCreateSubscriptionThroughCollection.
@Test
public void testCreateSubscriptionThroughCollection() throws StripeException {
Plan plan = 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.getSubscriptions().create(subCreateParams);
assertEquals(plan.getId(), sub.getPlan().getId());
// Verify
customer = Customer.retrieve(customer.getId());
assertEquals(1, customer.getSubscriptions().getData().size());
assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
}
use of com.stripe.model.Plan in project stripe-java by stripe.
the class SubscriptionTest method testCancelSubscriptionPerCallAPIKey.
@Test
public void testCancelSubscriptionPerCallAPIKey() throws StripeException {
Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
Customer customer = createDefaultCustomerWithPlan(plan);
assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
Subscription canceledSubscription = customer.cancelSubscription(Stripe.apiKey);
assertEquals(canceledSubscription.getStatus(), "canceled");
}
use of com.stripe.model.Plan in project stripe-java by stripe.
the class SubscriptionTest method testCancelSubscription.
@Test
public void testCancelSubscription() throws StripeException {
Plan plan = Plan.create(getUniquePlanParams());
Customer customer = createDefaultCustomerWithPlan(plan);
assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
Subscription canceledSubscription = customer.cancelSubscription();
assertEquals(canceledSubscription.getStatus(), "canceled");
}
use of com.stripe.model.Plan in project stripe-java by stripe.
the class UsageRecordTest method testUsageRecordCreate.
@Test
public void testUsageRecordCreate() throws StripeException {
Plan plan = createMeteredPlan();
Subscription sub = createSubscription(plan);
SubscriptionItem subItem = sub.getSubscriptionItems().getData().get(0);
Map<String, Object> params = new HashMap<>();
params.put("quantity", 1000);
long unixTime = System.currentTimeMillis() / 1000L;
params.put("timestamp", unixTime);
params.put("subscription_item", subItem.getId());
UsageRecord ur = UsageRecord.create(params, null);
assertEquals(new Long(1000), ur.getQuantity());
assertEquals(new Long(unixTime), ur.getTimestamp());
}
Aggregations