Search in sources :

Example 26 with Customer

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

the class SubscriptionItemTest method testSubscriptionItemList.

@Test
public void testSubscriptionItemList() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    Subscription subscription = createDefaultSubscription(customer);
    createDefaultSubscriptionItem(subscription);
    Map<String, Object> listParams = new HashMap<String, Object>();
    listParams.put("subscription", subscription.getId());
    SubscriptionItemCollection subscriptionItems = SubscriptionItem.list(listParams);
    List<SubscriptionItem> subscriptionItemsData = subscriptionItems.getData();
    assertEquals(subscriptionItemsData.size(), 2);
}
Also used : DeletedSubscriptionItem(com.stripe.model.DeletedSubscriptionItem) SubscriptionItem(com.stripe.model.SubscriptionItem) Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) Subscription(com.stripe.model.Subscription) SubscriptionItemCollection(com.stripe.model.SubscriptionItemCollection) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 27 with Customer

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

the class SubscriptionItemTest method testSubscriptionItemUpdate.

@Test
public void testSubscriptionItemUpdate() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    Subscription subscription = createDefaultSubscription(customer);
    SubscriptionItem subscriptionItem = createDefaultSubscriptionItem(subscription);
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("quantity", 4);
    SubscriptionItem updatedSubscriptionItem = subscriptionItem.update(updateParams);
    assertTrue(updatedSubscriptionItem.getQuantity() == 4);
}
Also used : DeletedSubscriptionItem(com.stripe.model.DeletedSubscriptionItem) SubscriptionItem(com.stripe.model.SubscriptionItem) Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 28 with Customer

use of com.stripe.model.Customer 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 29 with Customer

use of com.stripe.model.Customer 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)

Example 30 with Customer

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

the class SubscriptionTest method testTopLevelSubscriptionAPI.

@Test
public void testTopLevelSubscriptionAPI() 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());
    subCreateParams.put("customer", customer.getId());
    Subscription sub = Subscription.create(subCreateParams);
    assertEquals(plan.getId(), sub.getPlan().getId());
    assertEquals(customer.getId(), sub.getCustomer());
    customer = Customer.retrieve(customer.getId());
    assertEquals(1, customer.getSubscriptions().getData().size());
    assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
    // Retrieve
    Subscription retrievedSub = Subscription.retrieve(sub.getId());
    assertEquals(sub.getId(), retrievedSub.getId());
    // List
    Map<String, Object> subAllParams = new HashMap<String, Object>();
    subAllParams.put("plan", plan.getId());
    subAllParams.put("customer", customer.getId());
    SubscriptionCollection list = Subscription.all(subAllParams);
    assertEquals(1, list.getData().size());
    assertEquals(sub.getId(), list.getData().get(0).getId());
    assertEquals(customer.getId(), list.getData().get(0).getCustomer());
    assertEquals(plan.getId(), list.getData().get(0).getPlan().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());
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) SubscriptionCollection(com.stripe.model.SubscriptionCollection) CustomerSubscriptionCollection(com.stripe.model.CustomerSubscriptionCollection) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

Customer (com.stripe.model.Customer)65 Test (org.junit.Test)63 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)60 HashMap (java.util.HashMap)40 DeletedCustomer (com.stripe.model.DeletedCustomer)24 ExternalAccount (com.stripe.model.ExternalAccount)16 Plan (com.stripe.model.Plan)16 Subscription (com.stripe.model.Subscription)15 DeletedExternalAccount (com.stripe.model.DeletedExternalAccount)13 DeletedInvoiceItem (com.stripe.model.DeletedInvoiceItem)10 InvoiceItem (com.stripe.model.InvoiceItem)10 Invoice (com.stripe.model.Invoice)7 Card (com.stripe.model.Card)6 DeletedSubscriptionItem (com.stripe.model.DeletedSubscriptionItem)5 SubscriptionItem (com.stripe.model.SubscriptionItem)5 BaseStripeTest (com.stripe.BaseStripeTest)3 BankAccount (com.stripe.model.BankAccount)3 DeletedBankAccount (com.stripe.model.DeletedBankAccount)3 ExternalAccountCollection (com.stripe.model.ExternalAccountCollection)3 Coupon (com.stripe.model.Coupon)2