Search in sources :

Example 11 with ExternalAccount

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

the class CustomerTest method testCustomerCreate.

@Test
public void testCustomerCreate() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    assertEquals(customer.getDescription(), "J Bindings Customer");
    List<ExternalAccount> customerSources = customer.getSources().getData();
    assertEquals(1, customerSources.size());
    assertThat(customerSources.get(0), instanceOf(Card.class));
    assertEquals("4242", ((Card) customerSources.get(0)).getLast4());
}
Also used : 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 12 with ExternalAccount

use of com.stripe.model.ExternalAccount 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 13 with ExternalAccount

use of com.stripe.model.ExternalAccount 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 14 with ExternalAccount

use of com.stripe.model.ExternalAccount 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 15 with ExternalAccount

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

ExternalAccount (com.stripe.model.ExternalAccount)17 Customer (com.stripe.model.Customer)16 Test (org.junit.Test)16 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)13 DeletedCustomer (com.stripe.model.DeletedCustomer)13 DeletedExternalAccount (com.stripe.model.DeletedExternalAccount)13 HashMap (java.util.HashMap)13 Card (com.stripe.model.Card)6 BaseStripeTest (com.stripe.BaseStripeTest)3 ExternalAccountCollection (com.stripe.model.ExternalAccountCollection)3 BankAccount (com.stripe.model.BankAccount)2 DeletedBankAccount (com.stripe.model.DeletedBankAccount)2 StripeException (com.stripe.exception.StripeException)1 Charge (com.stripe.model.Charge)1 RequestOptions (com.stripe.net.RequestOptions)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1