Search in sources :

Example 31 with Plan

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());
}
Also used : 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)

Example 32 with Plan

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");
}
Also used : Customer(com.stripe.model.Customer) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 33 with Plan

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");
}
Also used : Customer(com.stripe.model.Customer) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 34 with Plan

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());
}
Also used : SubscriptionItem(com.stripe.model.SubscriptionItem) HashMap(java.util.HashMap) UsageRecord(com.stripe.model.UsageRecord) 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