Search in sources :

Example 31 with Customer

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

the class SubscriptionTest method testCancelSubscriptionAtPeriodEnd.

@Test
public void testCancelSubscriptionAtPeriodEnd() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    Customer customer = createDefaultCustomerWithPlan(plan);
    assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
    Map<String, Object> cancelParams = new HashMap<String, Object>();
    cancelParams.put("at_period_end", true);
    Subscription canceledSubscription = customer.cancelSubscription(cancelParams);
    assertEquals(canceledSubscription.getStatus(), "active");
    assertEquals(canceledSubscription.getCancelAtPeriodEnd(), true);
}
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 Customer

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

the class SubscriptionTest method testUpdateSubscriptionPerCallAPIKey.

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

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

the class SubscriptionTest method testCancelSubscriptionAtPeriodEndPerCallAPIKey.

@Test
public void testCancelSubscriptionAtPeriodEndPerCallAPIKey() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
    Customer customer = createDefaultCustomerWithPlan(plan);
    assertEquals(customer.getSubscriptions().getData().get(0).getStatus(), "active");
    Map<String, Object> cancelParams = new HashMap<String, Object>();
    cancelParams.put("at_period_end", true);
    Subscription canceledSubscription = customer.cancelSubscription(cancelParams, Stripe.apiKey);
    assertEquals(canceledSubscription.getStatus(), "active");
    assertEquals(canceledSubscription.getCancelAtPeriodEnd(), true);
}
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 34 with Customer

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

the class UsageRecordTest method createSubscription.

private Subscription createSubscription(Plan plan) throws StripeException {
    final Customer customer = Customer.create(defaultCustomerParams);
    Map<String, Object> subscriptionParams = new HashMap<String, Object>();
    Map<String, Object> planEntry = new HashMap<>();
    planEntry.put("plan", plan.getId());
    List<Map<String, Object>> subItems = new ArrayList<>();
    subItems.add(planEntry);
    subscriptionParams.put("items", subItems);
    subscriptionParams.put("customer", customer.getId());
    return Subscription.create(subscriptionParams);
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with Customer

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

the class ExternalAccountTest method testUnknownExternalAccountRetrieval.

@Test
public void testUnknownExternalAccountRetrieval() throws StripeException, IOException {
    stubNetwork(Customer.class, resource("customer_with_external_account.json"));
    Customer cus = Customer.retrieve("cus_123");
    verifyGet(Customer.class, "https://api.stripe.com/v1/customers/cus_123");
    ExternalAccount ea = cus.getSources().getData().get(0);
    assertEquals(true, ea instanceof ExternalAccount);
    assertEquals("unknown_external_account", ea.getObject());
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("mdkey", "mdvalue");
    assertEquals(metadata, ea.getMetadata());
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) ExternalAccount(com.stripe.model.ExternalAccount) BaseStripeTest(com.stripe.BaseStripeTest) 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