Reusing the payment source

How to save the payment source into the customer wallet so that it can be reused

Problem

You want to save an external payment source already used to complete a purchase into the customer wallet and eventually reuse it for future payments.

Solution

  1. To save the payment source into the customer wallet you have to send a PATCH request to the /api/orders/:id endpoint, setting the _save_payment_source_to_customer_wallet attribute to true.

  2. To reuse the stored payment source you need to associate it with the related order. To do that send a PATCH request to the /api/orders/:id endpoint, using the ID of the selected customer payment source to properly set the _customer_payment_source_id attribute.

A call to the token_url endpoint you've specified when configuring your external payment gateway is performed in order to fetch the customer_token and the payment_source_token attributes. Please check the related guide for more details.

To get a list of the customer's available payment sources, include the available_customer_payment_sourcesrelationship in the request (1).

Example

1. Save the payment source into the customer wallet

The following request save the external payment source to the customer wallet for the order identified by the "qaMAhZkZvd" ID:

curl -g -X PATCH \
  'http://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd?include=available_customer_payment_sources' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "orders",
    "id": "qaMAhZkZvd",
    "attributes": {
      "_save_payment_source_to_customer_wallet": true
    }
  }
}'

2. Reuse the payment source stored in the customer wallet

The following request associates the payment source saved into the customer wallet and identified by the ID "QgDXpwsqDx" with the order identified by the "qaMAhZkZvd" ID:

curl -g -X PATCH \
  'http://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "orders",
    "id": "qaMAhZkZvd",
    "attributes": {
      "_customer_payment_source_id": "QgDXpwsqDx"
    }
  }
}'

More to read

See our documentation if you need more information on how to update an order or deal with customer payment sources.

Last updated