Search in sources :

Example 61 with Customer

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

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

the class SubscriptionTest method testSubscriptionMetadata.

@Test
public void testSubscriptionMetadata() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    testMetadata(customer.createSubscription(getSubscriptionParams()));
}
Also used : Customer(com.stripe.model.Customer) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 63 with Customer

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

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

the class ExternalAccountTest method testVerify.

@Test
public void testVerify() 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 bankAccount = cus.getSources().getData().get(0);
    assertEquals(true, bankAccount instanceof ExternalAccount);
    stubNetwork(ExternalAccount.class, "{\"id\": \"extacct_123\", \"object\": \"unknown_external_account\"}");
    Map params = new HashMap<String, Object>();
    Integer[] amounts = { 32, 45 };
    params.put("amounts", amounts);
    bankAccount.verify(params);
    verifyPost(ExternalAccount.class, "https://api.stripe.com/v1/customers/cus_123/sources/extacct_123/verify", params);
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) ExternalAccount(com.stripe.model.ExternalAccount) HashMap(java.util.HashMap) Map(java.util.Map) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 65 with Customer

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

the class ExternalAccountTest method testUnknownExternalAccountDeletion.

@Test
public void testUnknownExternalAccountDeletion() 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);
    stubNetwork(DeletedExternalAccount.class, "{\"id\": \"extacct_123\", \"object\": \"unknown_external_account\"}");
    ea.delete();
    verifyRequest(APIResource.RequestMethod.DELETE, DeletedExternalAccount.class, "https://api.stripe.com/v1/customers/cus_123/sources/extacct_123", null, APIResource.RequestType.NORMAL, RequestOptions.getDefault());
}
Also used : Customer(com.stripe.model.Customer) 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