# Create Payment Using a Mandate
source: https://developer.mastercard.com/ob-accept-payments/documentation/tutorials-and-guides/create-payment-tutorial/index.md

This guide walks you through creating a payment request using an authorized mandate and getting the payment status.

Refer to [Pay with mandate](https://developer.mastercard.com/ob-accept-payments/documentation/payments/vrp/index.md#pay-with-mandate) for additional details.

## Prerequisites {#prerequisites}

* You have previously [created a mandate](https://developer.mastercard.com/ob-accept-payments/documentation/tutorials-and-guides/create-mandate-tutorial/index.md) and it has been authorized by the PSU (Payment Services User) by going through an SCA with the bank.
* You have successfully authenticated with the API (refer to the [Authentication](https://developer.mastercard.com/ob-accept-payments/documentation/api-basics/index.md) guide).

## Step 1 - Identify the Mandate {#step-1---identify-the-mandate}

First you need to identify the mandate that will be used for creating payments. Check the `mandateId` that you obtained when the mandate has been created.

This needs to be used as `mandate_id` path parameter.

## Step 2 - Specify the Scheme / Payment Rail {#step-2---specify-the-scheme--payment-rail}

To initiate a payment through Open Finance, you need to specify which scheme / payment rail will be used for processing the payment. This should be the same Scheme / Payment Rail that was used to create the mandate.

Refer to [Supported Payment Rails](https://developer.mastercard.com/ob-accept-payments/documentation/production/supported-payments-rails/index.md) to learn more about the payment rails in different regions.

Identify the payment rail that you will use and record the `paymentRail` and `currency` associated with it for next step.

## Step 3 - Define and Validate Payment Attributes {#step-3---define-and-validate-payment-attributes}

Determine if the payment is created by the PSU online (set `endUser.present = true`) or the Merchant initiates the payment while the PSU is out of session (set `endUser.present = false`).

Define a unique identifier for the payment, `endToEndId`. This is mandatory for UKFasterPayments scheme / payment rail.

Determine the `amount` of the payment and ensure that it aligns with the limits set up by the PSU on the mandate (limit per amount, limit per month) and ensure that the mandate has not expired.

For this, you may want to use the following values from mandate details (see the Get Mandate in Create Mandate Tutorial):

* `limits.validTo`
* `limits.maxAmountPerPayment`
* `limits.maxAmountPerMonth`

## Step 4 - Create Payment Request {#step-4---create-payment-request}

Once you have identified the scheme / payment rail from the previous step and collected the parameters needed for it, you can initiate the payment.

API Reference: `POST /mandates/{mandate_id}/payments`

### Request {#request}

* Use the `mandateId` as `mandate_id` path parameter
* Use the `paymentRail` and `currency` identified during previous step. Note that scheme rules will be applied automatically to the fields in the message
* Use the `endUser.present` flag defined at previous step to show if payment was initiated by the user online.
* Use the `endToEndId` you assigned at previous step
* Specify the `amount` of the payment that is aligned with mandate parameters / limits.

### Response {#response}

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

```json
{
  "paymentId": "472e651e-5a1e-424d-8098-23858bf03ad7"
}
```

Record the `paymentId` for the next steps.

## Step 5 - Payment Results {#step-5---payment-results}

After you have created the payment request and obtained the paymentId, you can use it to retrieve the latest payment state using the Get Payment endpoint.

API Reference: `GET /payments/{payment_id}`

### Request {#request-1}

Use the `paymentId` retrieved from the previous step to get the payment status.

### Response {#response-1}

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

```json
{
  "paymentId": "472e651e-5a1e-424d-8098-23858bf03ad7",
  "mandateId": "c61f1e0e-3f3e-459d-a4f1-5fa6c52b1921",
  "destinationId": "472e651e-5a1e-424d-8098-23858bf03ad7",
  "paymentRail": "UkFasterPayments",
  "amount": 123.5,
  "currency": "GBP",
  "status": {
    "code": "string",
    "lastUpdated": "2023-10-30T10:10:00.7539418+00:00",
    "events": [
      {
        "event": "Requested",
        "timestamp": "2024-01-17T12:29:36.919957+00:00"
      }
    ],
    "details": {
      "code": "AcceptedSettlementCompleted",
      "reason": "Reason"
    }
  },
  "reference": "Example Reference",
  "identifier": "Example ID",
  "endToEndId": "Example ID",
  "providerId": "GB_TestBank",
  "date": {
    "requestedDate": "2024-02-21",
    "actualDate": "2024-02-22"
  },
  "context": {
    "contextCode": "BillingGoodsAndServicesInAdvance",
    "purposeCode": "GDSV",
    "deliveryAddress": {
      "addressLines": [
        "string"
      ],
      "street": "Street Name",
      "buildingNumber": "42",
      "postalCode": "1234",
      "city": "London",
      "countrySubDivision": "Greater London",
      "country": "GB"
    }
  },
  "providerPaymentId": "472e651e-5a1e-424d-8098-23858bf03ad7",
  "endUser": {
    "id": "0001789937234"
  },
  "clientAssignedReference": "Example client assigned reference"
}
```

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

You can also receive payment status updates through [Webhooks](https://developer.mastercard.com/ob-accept-payments/documentation/event-notifications/index.md).
