Search in sources :

Example 6 with Card

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

use of com.stripe.model.Card 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 8 with Card

use of com.stripe.model.Card 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 9 with Card

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

the class DisputeTest method testRetrieveDisputeWithExpand.

@Test
public void testRetrieveDisputeWithExpand() throws StripeException, InterruptedException {
    int chargeValueCents = 100;
    Charge disputedCharge = createDisputedCharge(chargeValueCents, null);
    Dispute dispute = disputedCharge.getDisputeObject();
    List<String> expandList = new LinkedList<String>();
    expandList.add("charge");
    Map<String, Object> retrieveParams = new HashMap<String, Object>();
    retrieveParams.put("expand", expandList);
    Dispute retrievedDispute = Dispute.retrieve(dispute.getId(), retrieveParams, null);
    assertEquals(dispute.getId(), retrievedDispute.getId());
    Charge expandedCharge = retrievedDispute.getChargeObject();
    assertNotNull(expandedCharge);
    assertEquals(disputedCharge.getId(), expandedCharge.getId());
    Card card = (Card) expandedCharge.getSource();
    assertEquals("0259", card.getLast4());
}
Also used : HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) Dispute(com.stripe.model.Dispute) EvidenceSubObject(com.stripe.model.EvidenceSubObject) LinkedList(java.util.LinkedList) Card(com.stripe.model.Card) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 10 with Card

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

the class RecipientTest method testRecipientCardAddition.

@Test
public void testRecipientCardAddition() throws StripeException {
    Recipient createdRecipient = Recipient.create(defaultRecipientParams);
    final String originalDefaultCard = createdRecipient.getDefaultCard();
    Map<String, Object> creationParams = new HashMap<String, Object>();
    creationParams.put("card", "tok_visa_debit");
    final Card addedCard = createdRecipient.createCard(creationParams);
    createdRecipient.createCard("tok_visa_debit");
    Recipient updatedRecipient = Recipient.retrieve(createdRecipient.getId());
    assertEquals((Integer) 3, (Integer) updatedRecipient.getCards().getData().size());
    assertEquals(updatedRecipient.getDefaultCard(), originalDefaultCard);
    Map<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("default_card", addedCard.getId());
    Recipient recipientAfterDefaultCardUpdate = updatedRecipient.update(updateParams);
    assertEquals((Integer) recipientAfterDefaultCardUpdate.getCards().getData().size(), (Integer) 3);
    assertEquals(recipientAfterDefaultCardUpdate.getDefaultCard(), addedCard.getId());
    assertEquals(recipientAfterDefaultCardUpdate.getCards().retrieve(originalDefaultCard).getId(), originalDefaultCard);
    assertEquals(recipientAfterDefaultCardUpdate.getCards().retrieve(addedCard.getId()).getId(), addedCard.getId());
}
Also used : HashMap(java.util.HashMap) DeletedRecipient(com.stripe.model.DeletedRecipient) Recipient(com.stripe.model.Recipient) DeletedCard(com.stripe.model.DeletedCard) Card(com.stripe.model.Card) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)14 Card (com.stripe.model.Card)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)10 Customer (com.stripe.model.Customer)6 DeletedCustomer (com.stripe.model.DeletedCustomer)6 DeletedExternalAccount (com.stripe.model.DeletedExternalAccount)6 ExternalAccount (com.stripe.model.ExternalAccount)6 Charge (com.stripe.model.Charge)5 DeletedCard (com.stripe.model.DeletedCard)3 DeletedRecipient (com.stripe.model.DeletedRecipient)3 Recipient (com.stripe.model.Recipient)3 BankAccount (com.stripe.model.BankAccount)1 DeletedBankAccount (com.stripe.model.DeletedBankAccount)1 Dispute (com.stripe.model.Dispute)1 EvidenceSubObject (com.stripe.model.EvidenceSubObject)1 ExternalAccountCollection (com.stripe.model.ExternalAccountCollection)1 LinkedList (java.util.LinkedList)1