Search in sources :

Example 41 with Customer

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

the class CustomerTest method testCustomerSourceList.

@Test
public void testCustomerSourceList() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("bank_account", defaultBankAccountParams);
    customer.createBankAccount(creationParams);
    HashMap<String, Object> listParams = new HashMap<String, Object>();
    List<ExternalAccount> customerSourceList = customer.getSources().all(listParams).getData();
    assertEquals(2, customerSourceList.size());
    assert (customerSourceList.get(0) instanceof Card);
    assertEquals("4242", ((Card) customerSourceList.get(0)).getLast4());
    assert (customerSourceList.get(1) instanceof BankAccount);
    assertEquals("6789", ((BankAccount) customerSourceList.get(1)).getLast4());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) HashMap(java.util.HashMap) DeletedBankAccount(com.stripe.model.DeletedBankAccount) BankAccount(com.stripe.model.BankAccount) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) Card(com.stripe.model.Card) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 42 with Customer

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

the class CustomerTest method testCustomerCreateWithSource.

@Test
public void testCustomerCreateWithSource() throws StripeException {
    HashMap<String, Object> customerCreationParams = new HashMap<String, Object>();
    customerCreationParams.put("source", "tok_visa");
    Customer customer = Customer.create(customerCreationParams);
    assertNotNull(customer);
    assertNotNull(customer.getId());
    assertNotNull(customer.getSources());
    assert (customer.getSources().getData().get(0) instanceof Card);
    assertNotNull(customer.getDefaultSource());
    ExternalAccount card = customer.getSources().retrieve(customer.getDefaultSource());
    assertEquals(card.getId(), customer.getDefaultSource());
}
Also used : HashMap(java.util.HashMap) Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) Card(com.stripe.model.Card) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 43 with Customer

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

the class CustomerTest method testCustomerCardAddition.

@Test
public void testCustomerCardAddition() throws StripeException {
    Customer createdCustomer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    final String originalDefaultSource = createdCustomer.getDefaultSource();
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("source", "tok_visa");
    final ExternalAccount addedCard = createdCustomer.getSources().create(creationParams);
    createdCustomer.createCard("tok_visa");
    Customer updatedCustomer = Customer.retrieve(createdCustomer.getId(), supportedRequestOptions);
    assertEquals(3, updatedCustomer.getSources().getData().size());
    assertEquals(updatedCustomer.getDefaultSource(), originalDefaultSource);
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("default_card", addedCard.getId());
    Customer customerAfterDefaultCardUpdate = updatedCustomer.update(updateParams, supportedRequestOptions);
    assertEquals(3, updatedCustomer.getSources().getData().size());
    assertEquals(customerAfterDefaultCardUpdate.getDefaultSource(), addedCard.getId());
    assertEquals(customerAfterDefaultCardUpdate.getSources().retrieve(originalDefaultSource).getId(), originalDefaultSource);
    assertEquals(customerAfterDefaultCardUpdate.getSources().retrieve(addedCard.getId()).getId(), addedCard.getId());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) HashMap(java.util.HashMap) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 44 with Customer

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

the class CustomerTest method testCustomerRetrievePerCallAPIKey.

@Test
public void testCustomerRetrievePerCallAPIKey() throws StripeException {
    Customer createdCustomer = Customer.create(defaultCustomerParams, Stripe.apiKey);
    Customer retrievedCustomer = Customer.retrieve(createdCustomer.getId());
    assertEquals(createdCustomer.getCreated(), retrievedCustomer.getCreated());
    assertEquals(createdCustomer.getId(), retrievedCustomer.getId());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 45 with Customer

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

the class CustomerTest method testCustomerSourceRetrieveWithExpand.

@Test
public void testCustomerSourceRetrieveWithExpand() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    List<String> expandList = new LinkedList<String>();
    expandList.add("default_source");
    Map<String, Object> retrieveParams = new HashMap<String, Object>();
    retrieveParams.put("expand", expandList);
    Customer retrievedCustomer = Customer.retrieve(customer.getId(), retrieveParams, null);
    ExternalAccount defaultSource = retrievedCustomer.getDefaultSourceObject();
    assertNotNull(defaultSource);
    assertEquals("4242", ((Card) defaultSource).getLast4());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) HashMap(java.util.HashMap) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) LinkedList(java.util.LinkedList) 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