Save a card during payment

Save customer's card details on Checkout page, can help customers to pay more quickly in their next payments.

1. Create a Customer

Create a corresponding Customer object for your customer in MoneyCollect.

// Use your private key
MoneyCollect.apiKey = "test_pr_NWZsa******";

CustomerCreateParams customerCreateParams =
            CustomerCreateParams.builder()
                    .setEmail("test@moneycollect.com").build();
Customer customer = Customer.create(customerCreateParams);

2. Create Checkout Session

When creating the Checkout Session, you can specify the customerparameter to automatically attach the created payment method to an existing customer.

// Use your private key
MoneyCollect.apiKey = "test_pr_NWZsa******";

SessionCreateParams params =
          SessionCreateParams.builder()
                    .setReturnUrl("http://localhost:4242/success.html")
                    .setCancelUrl("http://localhost:4242/cancel.html")
                    .setNotifyUrl("http://localhost:4242/success.html")
                    .setAmountTotal(18*100L)
                    .setCurrency("USD")
                    .setOrderNo("C"+System.currentTimeMillis())
                    .setWebsite("https://www.localhost.com")
                    .setBillingDetails(getBillingDetails())
                    .setCustomer(customer.getId())
                    .setStatementDescriptor("Mc122").build();
Session session = Session.create(params); 

3. Customer selects "save this card" during payment

  1. Select "Save this card for future purchase" on the Checkout page.

  2. Click "Pay".

  3. After pay will save the card details to customer.

4. Customer selects the saved card to make payment

Last updated