Introducing our brand new Rules Engine —
Read the docs
LogoLogo
Core APIOther APIsChangelog
How-tos
How-tos
  • Introduction
  • Product discovery
    • Product listing page
    • Product page
  • Placing orders
    • Shopping cart
      • Creating a shopping cart
      • Adding products to cart
      • Updating cart quantities
      • Removing products from cart
      • Displaying the cart summary
    • Checkout
      • Adding the customer
      • Adding a billing address
      • Adding a shipping address
      • Selecting a shipping method
      • Selecting a payment method
      • Adding a payment source
      • Adding a gift card or coupon
      • Placing the order
    • Subscriptions
      • Configuring a subscription model
      • Selecting the source order
      • Generating the subscriptions
      • Updating the subscriptions
    • Payments
      • Adyen
        • Adding the payment source
        • Sending back the payment details
        • Configuring the notification webhooks
        • Reusing the payment source
      • Axerve
        • Adding the payment source
        • Updating the payment intent
      • Braintree
        • Adding the payment source
        • Sending back the payment method nonce
        • Accepting local payments
        • Reusing the payment source
      • Checkout.com
        • Adding the payment source
        • Getting the payment details
        • Refreshing pending transactions
        • Reusing the payment source
      • Klarna
        • Adding the payment source
        • Sending back the authorization token
        • Reusing the payment source
      • PayPal
        • Adding the payment source
        • Preparing the payment for execution
      • Stripe
        • Adding the payment source
        • Refreshing the payment source
        • Reusing the payment source
      • Manual payments
        • Adding a wire transfer payment source
      • External payments
        • Adding the payment source
        • Reusing the payment source
    • Auto-capture
      • Enabling the auto-capture
      • Limiting the auto-capture amount
  • inventory
    • Inventory strategies
      • No split
      • Split shipments
      • Split by line items
      • Ship from first available (or primary)
      • Ship from primary
  • FAQ
    • Environments and initial setup
    • Authentication and access tokens
On this page
  • Problem
  • Solution
  • Example
  • More to read
  1. Placing orders
  2. Payments
  3. Adyen

Reusing the payment source

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

PreviousConfiguring the notification webhooksNextAxerve

Last updated 3 years ago

Problem

You want to save an Adyen 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 need to ensure that the payment_request_data are already set, then 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.

To return the recurringDetailReference additional data into the payment response, you need to configure your Adyen account as described , otherwise the saving into the wallet will fail.

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

Example

1. Save the payment source into the customer wallet

The following request save the Adyen 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
    }
  }
}'

On success, the API responds with a 200 OK status code, returning the updated order object:

{
  "data": {
    "id": "qaMAhZkZvd",
    "type": "orders",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd"
    },
    "attributes": {...},
    "relationships": {
      "market": {
        "links": {...}
      },
      "customer": {
        "links": {...}
      },
      "shipping_address": {
        "links": {...}
      },
      "billing_address": {
        "links": {...}
      },
      "available_payment_methods": {
        "links": {...}
      },
      "available_customer_payment_sources": {
        "links": {...},
        "data": [
          {
            "type": "customer_payment_sources",
            "id": "QgDXpwsqDx"
          }
        ]
      },
      "payment_method": {
        "links": {...}
      },
      "payment_source": {
        "links": {...}
      },
      "line_items": {
        "links": {...}
      },
      "shipments": {
        "links": {...}
      }
    },
    "meta": {
      "mode": "test"
    }
  },
  "included": [
    {
      "id": "QgDXpwsqDx",
      "type": "customer_payment_sources",
      "links": {
        "self": "https://yourdomain.commercelayer.io/api/customer_payment_sources/QgDXpwsqDx"
      },
      "attributes": {
        "customer_token": "1",
        "name": "XXXX-XXXX-XXXX-1111",
        "payment_source_token": "7RxGd2HUyY1Yc2Tghw5N453piFs",
        "created_at": "2018-01-01T12:00:00.000Z",
        "updated_at": "2018-01-01T12:00:00.000Z",
        "reference": null,
        "metadata": {}
      },
      "relationships": {
        "customer": {
          "links": {...}
        },
        "payment_source": {
          "links": {...}
        }
      },
      "meta": {
        "mode": "test"
      }
    }
  ]
}

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"
    }
  }
}'

On success, the API responds with a 200 OK status code, returning the updated order object:

{
  "data": {
    "id": "qaMAhZkZvd",
    "type": "orders",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/orders/qaMAhZkZvd"
    },
    "attributes": {...},
    "relationships": {
      "market": {
        "links": {...}
      },
      "customer": {
        "links": {...}
      },
      "shipping_address": {
        "links": {...}
      },
      "billing_address": {
        "links": {...}
      },
      "available_payment_methods": {
        "links": {...}
      },
      "available_customer_payment_sources": {
        "links": {...}
      },
      "payment_method": {
        "links": {...}
      },
      "payment_source": {
        "links": {...}
      },
      "line_items": {
        "links": {...}
      },
      "shipments": {
        "links": {...}
      }
    },
    "meta": {
      "mode": "test"
    }
  }
}

More to read

See our documentation if you need more information on how to or deal with .

update an order
customer payment sources
here
request (1)