Search in sources :

Example 1 with BankAccount

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

the class CustomerTest method testCustomerBankAccountAddition.

@Test
public void testCustomerBankAccountAddition() throws StripeException {
    Customer createdCustomer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    final String originalDefaultCard = createdCustomer.getDefaultCard();
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("bank_account", defaultBankAccountParams);
    final BankAccount addedBankAccount = createdCustomer.createBankAccount(creationParams);
    createdCustomer.createCard("tok_visa");
    Customer updatedCustomer = Customer.retrieve(createdCustomer.getId(), supportedRequestOptions);
    assertEquals((Integer) updatedCustomer.getSources().getData().size(), (Integer) 3);
    assertEquals(updatedCustomer.getDefaultCard(), originalDefaultCard);
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("default_source", addedBankAccount.getId());
    Customer customerAfterDefaultSourceUpdate = updatedCustomer.update(updateParams, supportedRequestOptions);
    assertEquals((Integer) customerAfterDefaultSourceUpdate.getSources().getData().size(), (Integer) 3);
    assertEquals(customerAfterDefaultSourceUpdate.getDefaultSource(), addedBankAccount.getId());
}
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) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 2 with BankAccount

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

the class CustomerTest method testCustomerBankAccountDelete.

@Test
public void testCustomerBankAccountDelete() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("bank_account", defaultBankAccountParams);
    BankAccount addedBankAccount = customer.createBankAccount(creationParams);
    DeletedBankAccount deletedBankAccount = addedBankAccount.delete();
    Customer retrievedCustomer = Customer.retrieve(customer.getId(), supportedRequestOptions);
    assertTrue(deletedBankAccount.getDeleted());
    assertEquals(deletedBankAccount.getId(), addedBankAccount.getId());
    for (ExternalAccount retrievedSource : retrievedCustomer.getSources().getData()) {
        assertFalse("Card was not actually deleted: " + addedBankAccount.getId(), addedBankAccount.getId().equals(retrievedSource.getId()));
    }
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) HashMap(java.util.HashMap) DeletedBankAccount(com.stripe.model.DeletedBankAccount) DeletedBankAccount(com.stripe.model.DeletedBankAccount) BankAccount(com.stripe.model.BankAccount) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 3 with BankAccount

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

Aggregations

BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)3 BankAccount (com.stripe.model.BankAccount)3 Customer (com.stripe.model.Customer)3 DeletedBankAccount (com.stripe.model.DeletedBankAccount)3 DeletedCustomer (com.stripe.model.DeletedCustomer)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 DeletedExternalAccount (com.stripe.model.DeletedExternalAccount)2 ExternalAccount (com.stripe.model.ExternalAccount)2 Card (com.stripe.model.Card)1