Skip to main content

Charge a customer’s saved payment method

You can save your customers’ card details to be able to charge them at a later time. This is useful in the following use cases:

  • When you charge for subscriptions, or recurring transactions.
  • When you want to simplify the checkout experience for your customers, so that they can select a previously used card instead of having to enter its details again.

To do that, you:

  1. Save the card details of a customer.
  2. Charge the customer’s saved payment method.

1. Save the card details of a customer#

There are two approaches to save the card details of a customer:

  • Create a customer first and attach the payment method to the customer after the payment is made.
  • Create an order first and attach the payment method to the customer created after the order is completed.

Create a customer first#

  1. Create a customer and note down the id of the customer object.
  2. Create an order with the amount, currency, and customer_id parameters in the body of the request.
  3. Make the payment via the Revolut Checkout Widget with savePaymentMethodFor = customer or merchant. For example:
RevolutCheckout("<PUBLIC_ID>").then(function (instance) {  var card = instance.createCardField({    target: document.getElementById("card-field"),    onSuccess() {      window.alert("Thank you!");    },    onError(message) {      window.alert("Oh no :(");    },  });

  document    .getElementById("button-submit")    .addEventListener("click", function () {      card.submit({        savePaymentMethodFor: "merchant",      });    });});
  1. Payment method is created and attached to the customer.

Create an order first#

  1. Create an order with the `amount` and `currency` parameters.
  2. Make the payment via the Revolut Checkout Widget with savePaymentMethodFor = customer or merchant. (See example above)

    note

    email must be provided when you create an order or when the customer is making the payment; otherwise, an error is returned.

  3. When the payment is successful, a customer is created with the email.

  4. Payment method is associated with the customer and customer_id is attached to the order automatically.

2. Charge the saved payment method#

When you’ve created a customer and saved the customer’s payment method successfully, you can charge this payment method later without the customer being on the checkout page, for example, to charge for recurring transactions. You can also use this approach to speed up the checkout process when the customer is on the checkout page, for example, for 1-click buy flow.

Complete the following steps:

  1. Create an order with the amount, currency and customer_id parameters in the body of the request:
curl -X "POST" "https://merchant.revolut.com/api/1.0/orders" \    -H 'Authorization: Bearer [yourApiKey]' \    -H 'Content-Type: application/json; charset=utf-8' \    -d $'{          "amount": 100,          "currency": "GBP",          "customer_id": "6c7c97a8-cfc1-4cf3-8b38-26a74fdf1fae"        }'
  1. Confirm the order to take payment from this customer using the saved payment method:
curl -X "POST" "https://merchant.revolut.com/api/1.0/orders/{:orderId}/confirm" \    -H 'Authorization: Bearer [yourApiKey]' \    -H 'Content-Type: application/json; charset=utf-8' \
note
  • If payment_method_id is specified in the body of the order confirmation request, the value of this parameter is used to make the payment for the order.
  • If payment_method_id is not specified, the value of this parameter is taken from the payment method that was last saved for the customer with saved_for= MERCHANT.
success

Congratulations! You’ve successfully charged a saved payment method from one of your customers.

Was this section helpful?