#  Pay by Link  
source: https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-pay/tutorials/pay-by-link-tutorial/index.md

This guide will walk you through the steps to seamlessly integrate Pay-by-Link extension into your interactive application, allowing you to create long-lived links for receiving single payments. Follow these steps to enhance your payment capabilities and offer a convenient payment experience for your customers.

This guide walks you through the steps to seamlessly integrate Pay-by-Link extension into your interactive application, allowing you to create long-lived links for receiving single payments. Follow these steps to enhance your payment capabilities and offer a convenient payment experience for your customers.

#### Prerequisites: {#prerequisites}

* You created a destination and retrieved a `DESTINATION_ID` to receive the payments (check other tutorials).
* Your `REDIRECT_URL` must be whitelisted for your project.
* This tutorial uses `curl` in order to send requests and receive responses.

### Step 1 - Specify Schema {#step-1---specify-schema}

In order to create a payment link, you need to specify which scheme will be used for processing the payment.

You can learn more about the payment schemes in [different regions here](https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-pay/production/supported-providers/index.md).

Identify the payment schema you will use and record the `schemeId` and `currencyCode` associated with it for next step. You will need to apply the scheme rules for `reference` and `identifier`.

### Step 2 - Create a payment link request {#step-2---create-a-payment-link-request}

Once you have identified the scheme from the previous step and collected the parameters needed for it, you can create a payment link and retrieve the link url that will be sent to users to initiate the payment.

API Reference: `POST /v2/payments/accept/links`

#### Request {#request}

* Use the `DESTINATION_ID` that you onboarded.
* Specify the `AMOUNT`, use `CURRENCY_CODE`, `SCHEMA_ID`, `REFERENCE` and `IDENTIFIER`collected from previous step.
* Specify a `REDIRECT_URL` where the user will be redirected after finishing the payment flow.
* Specify an `EXPIRY_DATE` for when the link will no longer be valid.

```shell
curl -X POST \ 
https://api.aiia.eu/v2/payments/accept/links \ 
-H 'Content-Type: application/json' \ 
-u <CLIENT_ID>:<CLIENT_SECRET> \ 
-d '{
  "paymentRequest": {
    "amount": <AMOUNT>,
    "currency": <CURRENCY_CODE>,
    "schemeId": <SCHEMA_ID>,
    "reference": <REFERENCE>,
    "identifier": <IDENTIFIER>",
    "destinationId": <DESTINATION_ID>,
    "redirectUrl": <REDIRECT_URL>
  },
  expiryDate": <EXPIRY_DATE>
}'
```

#### Response {#response}

If the request is successful, the response will look like:

```json
{
  "authorizationUrl": "https://app.aiia.eu/#/pay/20220601.caz1kwu9n1hw5drqph1",
  "paymentLinkId": "20190824.xrrksqlmngnw3xisfq8uqd1ijh"
}
```

* Record the `paymentLinkId` for next steps.
* Redirect the user to the `authorizationUrl` to start the payment flow.

### Step 3 - User Payment Flow​ {#step-3---user-payment-flow}

Redirect the user to the `authorizationUrl` received in the previous step to authorize the payment.
Note: The Authorization URL must not be presented in an iframe, and it cannot be reused.

Depending on the parameters passed in the payment request, a flow will be displayed to the user where they will be able to select their provider (if not specified), login, select the account to pay from and complete the payment.

The flow will look like:

![Payment Flow](https://static.developer.mastercard.com/content/open-finance-europe/uploads/tutorials/enterprise-payment-flow.png)

### Step 4 - Payment Result {#step-4---payment-result}

After the payment flow is completed, the user is redirected back to the application using the `redirectUrl`. Retrieve the latest state of the payment link using the Get payment link endpoint.

API Reference: `GET /v2/payments/accept/links/{paymentLinkId}`

#### Request {#request-1}

* Use the `PAYMENT_LINK_ID` retrieved from the second step to get the payment status.

```shell
curl -X GET https://api.aiia.eu/v2/payments/accept/links/<PAYMENT_LINK_ID> \ 
    -u <CLIENT_ID>:<CLIENT_SECRET>
```

#### Response {#response-1}

If the request is successful, the response will look like:

```json
{
  "id": "string",
  "authorizationUrl": "string",
  "status": "Received",
  "expiryDate": "2019-06-04",
  "paymentAttempts": [
    "PAYMENT_ID"
  ],
  "paymentRequest": {
    "amount": 0,
    "currency": "string",
    "reference": "string",
    "receiveDate": "2019-06-04",
    "schemeId": "string"
  }
}
```

Ensure that the payment link status is `Received` and handle other payment status. You will also receive a list of attempted payments in the `paymentAttempts` array. You can retrieve every payment attempt results using the Get accept payment endpoint.

API Reference: `GET /v2/payments/accept/{paymentId}`

You can also receive payment status updates through webhooks.
