Search in sources :

Example 1 with ExternalAccount

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

the class CustomerTest method testCustomerCreatePerCallAPIKey.

@Test
public void testCustomerCreatePerCallAPIKey() 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 2 with ExternalAccount

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

the class CustomerTest method testCustomerCardUpdate.

@Test
public void testCustomerCardUpdate() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    ExternalAccount originalCard = customer.getSources().getData().get(0);
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("name", "J Bindings Cardholder, Jr.");
    ExternalAccount updatedCard = originalCard.update(updateParams);
    assertThat(updatedCard, instanceOf(Card.class));
    assertEquals(((Card) updatedCard).getName(), "J Bindings Cardholder, Jr.");
}
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) Card(com.stripe.model.Card) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 3 with ExternalAccount

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

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

the class CustomerTest method testCustomerCardDelete.

@Test
public void testCustomerCardDelete() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("source", "tok_visa");
    customer.createCard(creationParams);
    ExternalAccount card = customer.getSources().getData().get(0);
    DeletedExternalAccount deletedCard = card.delete();
    Customer retrievedCustomer = Customer.retrieve(customer.getId(), supportedRequestOptions);
    assertTrue(deletedCard.getDeleted());
    assertEquals(deletedCard.getId(), card.getId());
    for (ExternalAccount retrievedCard : retrievedCustomer.getSources().getData()) {
        assertFalse("Card was not actually deleted: " + card.getId(), card.getId().equals(retrievedCard.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) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 5 with ExternalAccount

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

the class CustomerTest method testCreateCardThroughCollection.

@Test
public void testCreateCardThroughCollection() throws StripeException {
    Customer createdCustomer = Customer.create(defaultCustomerParams, supportedRequestOptions);
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("source", "tok_visa");
    ExternalAccount addedCard = createdCustomer.getSources().create(creationParams);
    assertEquals(createdCustomer.getId(), addedCard.getCustomer());
    Customer updatedCustomer = Customer.retrieve(createdCustomer.getId(), supportedRequestOptions);
    assertEquals(2, updatedCustomer.getSources().getData().size());
}
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)

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