Search in sources :

Example 6 with ExternalAccount

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

the class CustomerTest method testCustomerSourceDelete.

@Test
public void testCustomerSourceDelete() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    ExternalAccountCollection customerSources = customer.getSources();
    ExternalAccount paymentSource = customerSources.getData().get(0);
    paymentSource.delete();
    HashMap<String, Object> listParams = new HashMap<String, Object>();
    assertEquals(0, customerSources.all(listParams).getData().size());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) HashMap(java.util.HashMap) ExternalAccountCollection(com.stripe.model.ExternalAccountCollection) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 7 with ExternalAccount

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

the class ExternalAccountTest method testUnknownExternalAccountRetrieval.

@Test
public void testUnknownExternalAccountRetrieval() throws StripeException, IOException {
    stubNetwork(Customer.class, resource("customer_with_external_account.json"));
    Customer cus = Customer.retrieve("cus_123");
    verifyGet(Customer.class, "https://api.stripe.com/v1/customers/cus_123");
    ExternalAccount ea = cus.getSources().getData().get(0);
    assertEquals(true, ea instanceof ExternalAccount);
    assertEquals("unknown_external_account", ea.getObject());
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("mdkey", "mdvalue");
    assertEquals(metadata, ea.getMetadata());
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) ExternalAccount(com.stripe.model.ExternalAccount) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 8 with ExternalAccount

use of com.stripe.model.ExternalAccount in project cryptonomica by Cryptonomica.

the class StripeTestServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    /* --- request*/
    String requestDataStr = ServletUtils.getAllRequestData(request);
    String responseStr = "{\"paymentData\":" + requestDataStr + ",";
    // Get the credit card details submitted by the form
    String token = request.getParameter("stripeToken");
    @SuppressWarnings("unused") String cardHolderName = request.getParameter("cardHolderName");
    /* -- see example on: https://github.com/stripe/stripe-java#usage */
    // 
    RequestOptions requestOptions = (new RequestOptions.RequestOptionsBuilder()).setApiKey(STRIPE_SECRET_KEY).build();
    // 
    // -- Card options:
    // ------------ // Map<String, Object> cardMap = new HashMap<>();
    // cardMap.put("name", cardHolderName);// - "Received both card and source parameters. Please pass in only one."
    /*
        cardMap.put("number", "4242424242424242");
        cardMap.put("exp_month", 12);
        cardMap.put("exp_year", 2020);
        */
    // -- Charge options:
    Map<String, Object> chargeMap = new HashMap<>();
    // -- this is ONE dollar
    chargeMap.put("amount", 100);
    chargeMap.put("currency", "usd");
    // see: https://stripe.com/docs/charges (Java)
    // chargeParams.put("source", token);
    // chargeParams.put("description", "Example charge");
    chargeMap.put("source", token);
    chargeMap.put("description", "Example charge: " + token);
    // 
    // ------------ // chargeMap.put("card", cardMap);
    // -- make charge:
    responseStr += "\"charge\":";
    try {
        Charge charge = Charge.create(chargeMap, requestOptions);
        // System.out.println(charge);
        responseStr += GSON.toJson(charge);
        LOG.warning(GSON.toJson(charge));
        ExternalAccount source = charge.getSource();
        LOG.warning("source: " + GSON.toJson(source));
        // -- "succeeded"
        charge.getStatus();
        // - boolean: true or false
        charge.getPaid();
    // 
    // String customerStr = source.getCustomer();
    // LOG.warning("customerStr: " + customerStr); //
    // responseStr += "," + "\"customerStr\":" + GSON.toJson(charge); // - same as source
    } catch (StripeException e) {
        String errorMessage = e.getMessage();
        responseStr += "\"";
        responseStr += errorMessage;
        responseStr += "\"";
        LOG.warning(errorMessage);
    }
    responseStr += "}";
    ServletUtils.sendJsonResponse(response, responseStr);
}
Also used : StripeException(com.stripe.exception.StripeException) RequestOptions(com.stripe.net.RequestOptions) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) ExternalAccount(com.stripe.model.ExternalAccount)

Example 9 with ExternalAccount

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

the class CustomerTest method testCustomerSourceUpdate.

@Test
public void testCustomerSourceUpdate() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    ExternalAccountCollection customerSources = customer.getSources();
    ExternalAccount paymentSource = customerSources.getData().get(0);
    assert (paymentSource instanceof Card);
    Card card = (Card) paymentSource;
    HashMap<String, Object> updateParams = new HashMap<String, Object>();
    updateParams.put("address_line1", "some address details");
    Card updatedCard = card.update(updateParams);
    assertEquals("some address details", updatedCard.getAddressLine1());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) HashMap(java.util.HashMap) ExternalAccountCollection(com.stripe.model.ExternalAccountCollection) ExternalAccount(com.stripe.model.ExternalAccount) DeletedExternalAccount(com.stripe.model.DeletedExternalAccount) Card(com.stripe.model.Card) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 10 with ExternalAccount

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

the class CustomerTest method testCustomerSourceRetrieveCard.

@Test
public void testCustomerSourceRetrieveCard() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    ExternalAccountCollection customerSources = customer.getSources();
    String paymentSourceId = customerSources.getData().get(0).getId();
    ExternalAccount paymentSource = customerSources.retrieve(paymentSourceId);
    assertNotNull(paymentSource);
    assertEquals(paymentSourceId, paymentSource.getId());
}
Also used : Customer(com.stripe.model.Customer) DeletedCustomer(com.stripe.model.DeletedCustomer) ExternalAccountCollection(com.stripe.model.ExternalAccountCollection) 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