# Remember a payer's account details using a Payer Token
source: https://developer.mastercard.com/ob-accept-payments/documentation/features/return-user-experience/remember-payers-account-details/index.md

Mastercard Open Finance Pay offers Integrators the ability to create Payer Tokens after successful payments. With this, Mastercard Open Finance Pay will remember the account details that the payer used during the initial successful payment. The Integrator can then generate a Payer Token that can be passed in future payment requests for that specific payer. When your customer returns to make a subsequent payment via Mastercard Open Finance Pay, you can pass their associated Payer Token in the Create payment request, and in turn, your customers will have a streamlined user experience where they will not be required to select their bank account again.
Note: The ability to capture and store a payer's source account details for use with Payer Tokens depends on the details returned to Mastercard Open Finance Pay by the ASPSP. This can vary by market and ASPSP so it is recommended that you discuss it with your implementations contacts at Mastercard Open Finance Pay before you start to use Payer Tokens.

### How it works {#how-it-works}

When the `rememberPayer` flag is set to `true` in the Create payment request, Mastercard Open Finance Pay will capture and store the payer's account details that were used during the successful payment initiation. After this, the Integrator can call the `/payer-tokens` endpoint and pass in the `paymentId` from a successful payment initiation. This will return the `payerTokenId` that can be passed in future payment requests to streamline your customers return experience by removing the need to select a bank during the payment flow.

When the `payerTokenId` is passed in the payment request, you can control the amount of flexibility given to the user in the flow by setting the `allowAccountChange` field.

For a strict use case where you only want the user to pay from the account associated with the `payerTokenId` you can set `allowAccountChange` to `false`. This will only allow the user to complete the payment flow using the account associated with the `payerTokenId`.

For a use case where you want to give the user the flexibility to pay from an account other than the one associated with the `payerTokenId` you can set `allowAccountChange` to `true`. This will allow the user to navigate to our provider selector during the payment flow and choose to continue the payment journey using a different provider.

By default, `allowAccountChange` is set to `false`.

Below you can see how this will look and feel for your customers.

#### First time user journey where rememberPayer was set to true {#first-time-user-journey-where-rememberpayer-was-set-to-true}

1. **Mastercard Open Finance Pay**   
   The Consumer searches for their bank, selects their bank, gives consent and proceeds with the Payment authorisation journey.
2. **Bank**   
   The Consumer authenticates themselves using the bank's existing authentication methods.
3. **Mastercard Open Finance Pay**   
   The Consumer is automatically redirected to Mastercard Open Finance Pay where they can see that the payment was initiated successfully and that the account they used has been stored.
This Figma diagram shows the user flow for making a payment and storing the account used for future payment.

For the best viewing experience, click the **full screen** option.

### What does the Payer Token flow look like for an End User? {#what-does-the-payer-token-flow-look-like-for-an-end-user}

For the best viewing experience of app to app, click the **full screen** option or **zoom** using the controls located on the right.

#### Return user journey using a Payer Token: {#return-user-journey-using-a-payer-token}

1. **Mastercard Open Finance Pay**   

   The Consumer reviews the payment details as well as their preselected bank details and gives permission to the PISP to initiate the payment with the bank.

2. **Bank**   

   The Consumer authenticates themselves using the bank's existing authentication methods.

3. **Mastercard Open Finance Pay**   

   The Consumer is automatically redirected to Mastercard Open Finance Pay where they can see that the payment was initiated successfully and that the account they used has been stored.

This Figma diagram shows the user flow for making a payment using a stored account.

For the best viewing experience, click the **full screen** option.

### Data Flow {#data-flow}

Diagram remember_payer_flow

1. As a prerequisite step for creating a Payer Token, you will need to create a payment where you set `rememberPayer` to `true`. When you do this, you should inform the PSU that their account will be stored for use in future payments. You should get the PSU to opt in to this and get their consent for storing their account details for use in future payments. See our page on [Single Immediate Payments](https://developer.mastercard.com/ob-accept-payments/documentation/payments/single-immediate-payments/single-immediate-payments/index.md) for more information on creating a payment.
2. After a successful payment where `rememberPayer` was set to `true`, the merchant can request a new Payer Token.
3. The Integrator will then submit a Create payer token request using the `POST /payer-tokens endpoint`. Inside the request, you will need to include the paymentId from the successful payment in step 1.
4. Mastercard Open Finance Pay will return the `payerTokenId` as well as the `displayAccountNumber` which can be used in the user interface so that the PSU knows which account they are choosing.
5. The Integrator stores and returns the `payerTokenId` and any other information that will be useful for the Merchant.
6. The Merchant stores the `payerTokenId` and any other information that will be useful for them in the future. The `payerTokenId` will be passed in future payments to give the PSU an improved user experience.
7. The Merchant advises the PSU that their account details have been stored for use in future payments.
8. The PSU returns to the Merchant to make a subsequent payment. This time, the PSU is given the option to choose the previously stored account for use in the payment.
9. The Merchant asks the Integrator to create a payment, this time they will pass the `payerTokenId` to the Integrator.
10. The integrator submits a Create payment request to Mastercard Open Finance Pay using the `POST /payments` endpoint. This time, the Integrator will need to pass the `payerTokenId` inside the `preselectedSource` object in the payment request body.
11. Mastercard Open Finance Pay validates that the payerTokenId is correct and returns the flowURL to the Integrator.
12. The Merchant should redirect the PSU to the **flowURL**.
13. The PSU is redirected to Mastercard Open Finance Pay to complete the payment. This time, because the `payerTokenId` was used, the PSU will experience a more streamlined user experience.

### Endpoints Used {#endpoints-used}

The initial payment is created using the `/payments endpoint`. If you are using the Payer Tokens, you must set `rememberPayer` to `true` at this point. This instructs Mastercard Open Finance Pay to store the PSU's account details so that a Payer Token can be created at a later stage. If `rememberPayer` is not set to `true`, Mastercard Open Finance Pay will not store the account details and it will not be possible to create a Payer Token using this `paymentId`.

API Reference: `POST /payments`

The Payer Token is created using the `/payer-tokens` endpoint. Mastercard will return the payerTokenId and other information related to the Payer Token. Refer to the [API reference](https://developer.mastercard.com/ob-accept-payments/documentation/api-reference/index.md) for full details of the fields.

The payerToken returned will be valid for 15 months. If you would like to extend the expiry date of a Payer Token, you should set rememberPayer to true when you pass a payerTokenId in the preselectedSource object in the payment request body.

API Reference: `POST /payer-tokens`

You can use the /payer-tokens/{payer_token_id} endpoint (API Reference) to fetch all the details for a Payer Token.

This endpoint can return:

* The `paymentRail` that the Payer Token can be used with.
* The `providerId` that the Payer Token is associated with.
* The `displayAccountNumber` for the Payer Token. This can be used in the User Interface so that the user knows the account that they will be using in the payment flow.
* The `expiresAt` value. This can be extended by setting `rememberPayer` to `true` when you pass a `payerTokenId` in the `preselectedSource` object in the payment request body.
* The `destinationId` associated with the Payer Token.


API Reference: `GET /payer-tokens/{payer_token_id}`

You can use the `/payer-tokens/{payer_token_id}` endpoint to delete a specific Payer Token. Once you call this endpoint and get a 200 response, it will no longer be possible to use this payerTokenId in future payment requests.

API Reference: `DELETE /payer-tokens/{payer_token_id}`

