Guides • Accept Payments
Charge a customer's saved payment method
doc

Charge a customer's saved payment method

In this tutorial you can learn how to save and charge your customer's payment methods using the Revolut Checkout Widget. To do that, you have to:

  1. Save a customer's payment details
  2. Charge the customer's saved payment method

Customer and merchant initiated payments

Familiarizing yourself with this process can be helpful to take advantage of saved payment methods. There are two types of payments:

  • Customer initiated payments: These are useful to improve your customer experience. Your customers can save their card details and choose from saved payment methods on their future checkouts without providing their card details again. For more information, see: Save cards and speed up checkout.
  • Merchant initiated payments: These payments are useful to manage subscriptions. Your customers can save their card details, and you can initiate recurring payments on that card. For more information, see: Manage subscriptions.

1. Save a customer's payment details

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

Create a customer first

Use this approach when your customer already has an account on your site at checkout. The payment method is attached to the customer after the payment is made.

  1. Create a customer and save the id of the customer object in the response.

  2. Create an order with the amount, currency, and customer.id parameters in the request body.

  3. Initialise the Revolut Checkout Widget with the savePaymentMethodFor parameter set to either customer or merchant. If you want to use Revolut Pay, initialise the widget by passing the savePaymentMethodForMerchant parameter as true.

    note

    If you created the customer object without an email, you need to provide it when initialising the SDKs. Otherwise, an error is returned.

    See an example with the createCardField instance:

    RevolutCheckout("<token>").then(function (instance) {
    var card = instance.createCardField({
    target: document.getElementById("card-field"),
    onSuccess() {
    window.alert("Payment was successful. Thank you!");
    },
    onError(message) {
    window.alert("Something went wrong.");
    },
    });

    document
    .getElementById("button-submit")
    .addEventListener("click", function () {
    card.submit({
    savePaymentMethodFor: "merchant",
    email: "example.customer@email.com",
    });
    });
    });
    note

    You can also use the payWithPopup instance of the Revolut Checkout Widget to save a customer's payment method.

  4. Make the payment via the widget.

  5. The payment method is created and attached to the customer. To check a customer's saved payment methods, use the: Merchant API: Retrieve all payment methods of a customer endpoint.

Create an order first

Use this approach when your customer starts the checkout as a guest user on your site. The payment method is attached to the customer after the payment is made.

  1. Create an order with the amount, currency, and at least on of the following:

    • customer.email, or
    • customer.phone, or
    • customer.full_name parameters.

    As a general best practice, it's recommended to additionally provide any further information you have (email, phone, full_name) when you wish to create a new customer object.

    Unless you provide customer.id at order creation, we always create a new customer, irrespective of another, existing customer having the same details (email, phone, full_name).

  2. Initialise the widget with savePaymentMethodFor parameter set to either customer or merchant. If you want to use Revolut Pay, initialise the widget by passing the savePaymentMethodForMerchant parameter as true.

    note

    If you created the customer object without an email, you need to provide it when initialising the SDKs. Otherwise, an error is returned.

    See an example with the createCardField instance:

    RevolutCheckout("<token>").then(function (instance) {
    var card = instance.createCardField({
    target: document.getElementById("card-field"),
    onSuccess() {
    window.alert("Payment was successful. Thank you!");
    },
    onError(message) {
    window.alert("Something went wrong.");
    },
    });

    document
    .getElementById("button-submit")
    .addEventListener("click", function () {
    card.submit({
    savePaymentMethodFor: "merchant",
    email: "example.customer@email.com",
    });
    });
    });
    note

    You can also use the payWithPopup instance of the Revolut Checkout Widget to save a customer's payment method.

  3. Make the payment via the widget.

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

  5. The payment method is associated with the customer, and the customer object is attached to the order automatically. To check a customer's saved payment methods, use the: Merchant API: Retrieve all payment methods of a customer endpoint.

2. Charge the saved payment method

Once the customer is created and their payment method is saved, you can charge the payment method even when the customer is not on the checkout page. This can be useful for taking recurring payments.

You can also use this approach to provide a faster checkout experience for customers, for example, a 1-click buy flow.

To charge a customer's saved payment method, follow these steps:

  1. Create an order with the amount, currency and customer.id parameters in the body of the request. Where the customer.id corresponds to a customer with a saved payment method.

  2. Pay for the order using the Merchant API: Pay for an order endpoint to initiate the payment using a customer's saved payment method.

    Use the following JSON object as the payload of the request:

    {
    "saved_payment_method": {
    "type": "<type of the saved payment method>",
    "id": "<ID of the saved payment method>",
    "initiator": "<initiator of the payment>"
    }
    }

    To retrieve the required information, use the order paid initially in Step 1. Retrieve the payment method ID and type from the order response using payments.payment_method.id and payments.payment_method.type.

    The following table shows who can initiate payments on saved payment methods (initiator parameter in payment request), depending on if the payment method was saved for the customer or the merchant (savedPaymentMethodFor parameter in the widget configuration):

    savePaymentMethodFor: customersavePaymentMethodFor: merchant
    initiator: customerAllowedAllowed
    initiator: merchantNot allowedAllowed
    note

    Only merchant initiated transactions are supported with Revolut Pay on the Pay for an order endpoint.

  3. If the payment is successfully captured, the following JSON is returned:

    {
    "id": "6407402d-cf34-ac35-9be4-f1448708811b",
    "order_id": "64073e7b-41af-a715-8a37-9d73cd01fa9f",
    "payment_method": {
    "type": "card",
    "id": "6513122e-877b-aa8d-9d26-4d1a805c7841",
    "brand": "mastercard_credit",
    "last_four": "1234"
    },
    "state": "captured"
    }

    You can handle captured payments as completed, it takes around 24 hours to settle payments on your Merchant Account.

success

Congratulations! You've successfully charged one of your customer's saved payment methods.

What's next

Was this page helpful?