Search in sources :

Example 11 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class PlanTest method testPlanUpdatePerCallAPIKey.

@Test
public void testPlanUpdatePerCallAPIKey() throws StripeException {
    Plan createdPlan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("name", "Updated Plan Name");
    Plan updatedplan = createdPlan.update(updateParams, Stripe.apiKey);
    assertEquals(updatedplan.getName(), "Updated Plan Name");
}
Also used : HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) DeletedPlan(com.stripe.model.DeletedPlan) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 12 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionItemTest method createDefaultSubscription.

static Subscription createDefaultSubscription(Customer customer) throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    HashMap<String, Object> item = new HashMap<String, Object>();
    item.put("plan", plan.getId());
    item.put("quantity", 1);
    HashMap<String, Object> items = new HashMap<String, Object>();
    items.put("0", item);
    Map<String, Object> subCreateParams = new HashMap<String, Object>();
    subCreateParams.put("items", items);
    subCreateParams.put("customer", customer.getId());
    return Subscription.create(subCreateParams);
}
Also used : HashMap(java.util.HashMap) Plan(com.stripe.model.Plan)

Example 13 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionItemTest method createDefaultSubscriptionItem.

static SubscriptionItem createDefaultSubscriptionItem(Subscription subscription) throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    Map<String, Object> subItemParams = new HashMap<String, Object>();
    subItemParams.put("plan", plan.getId());
    subItemParams.put("subscription", subscription.getId());
    return SubscriptionItem.create(subItemParams);
}
Also used : HashMap(java.util.HashMap) Plan(com.stripe.model.Plan)

Example 14 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method testUpdateSubscription.

@Test
public void testUpdateSubscription() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    Customer customer = Customer.create(defaultCustomerParams);
    Map<String, Object> subscriptionParams = new HashMap<String, Object>();
    subscriptionParams.put("plan", plan.getId());
    Subscription sub = customer.updateSubscription(subscriptionParams);
    assertEquals(sub.getPlan().getId(), plan.getId());
    assertEquals(sub.getCustomer(), customer.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 15 with Plan

use of com.stripe.model.Plan in project stripe-java by stripe.

the class SubscriptionTest method testInvoicingSubscription.

@Test
public void testInvoicingSubscription() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    defaultCustomerParams.put("email", "test@stripe.com");
    Customer customer = Customer.create(defaultCustomerParams);
    Map<String, Object> subscriptionParams = new HashMap<String, Object>();
    subscriptionParams.put("plan", plan.getId());
    subscriptionParams.put("billing", "send_invoice");
    subscriptionParams.put("days_until_due", 30);
    subscriptionParams.put("customer", customer.getId());
    Subscription sub = Subscription.create(subscriptionParams);
    assertEquals(plan.getId(), sub.getPlan().getId());
    assertEquals("send_invoice", sub.getBilling());
    assertEquals((Integer) 30, sub.getDaysUntilDue());
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("days_until_due", 10);
    Subscription subUpdated = sub.update(updateParams);
    assertEquals((Integer) 10, subUpdated.getDaysUntilDue());
}
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)

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