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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations