#  Accepting Payments 
source: https://developer.mastercard.com/open-finance-europe/documentation/unlicensed/aiia-pay/tutorials/accepting-payments-tutorial/index.md

This guide walks you through creating a payment request, authorizing the payment and getting the payment status.

#### 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 initiate a payment, 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 request {#step-2---create-a-payment-request}

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

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

#### 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.

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

#### Response {#response}

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

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

* Record the `paymentId` 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 using the Get accept payment endpoint.

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

#### Request {#request-1}

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

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

#### Response {#response-1}

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

```json
{
  "destinationId": "string",
  "schemeId": "string",
  "amount": 0,
  "currency": "string",
  "createdAt": "2019-06-04T11:57:01.7632527Z",
  "id": "string",
  "reference": "string",
  "identifier": "string",
  "status": {
    "code": "Executed",
    "lastUpdated": "2019-08-24T14:15:22Z"
  },
  "date": {
    "requestedDate": "2019-06-04",
    "actualDate": "2019-06-04"
  }
}
```

Handle different payment outcomes based on the returned payment status code and reason code.

You can also receive payment status updates through webhooks.
Note: Status only reflects if the payment order was accepted for execution at the ASPSP, not the actual settlement of the payment.
