# E-Commerce Payments
source: https://developer.mastercard.com/open-finance-europe/documentation/tutorials-and-guides/e-commerce-payments-tutorial/index.md

Mastercard's Open Finance E-Commerce Payments service allows Third-Party Providers (TPPs) to seamlessly integrate payment initiation into the online checkout experience. This tutorial will guide you through the process of initiating payments using Mastercard's Open Finance API, providing increased payment options for both TPPs and their customers.

Prerequisites

1. Mastercard Open Finance Account: Ensure that you have registered for a Mastercard Open Finance account and obtained the necessary API credentials.
2. Integration Environment: Set up your development environment and obtain the required API keys, secrets, and endpoints from Mastercard Open Finance.

### Step 1 - Choose ASPSP or PSU Selection {#step-1---choose-aspsp-or-psu-selection}

TPPs have the flexibility to choose the Account Servicing Payment Service Provider (ASPSP) for payment receipt or allow the Payment Service User (PSU) to choose the ASPSP. Refer to the Payment Initiation guide for detailed information on these options.


    ## Step 2 - Create Payment​

    1.	PSU (Payment Service User) Initiates Checkout and payment process on the merchant's website.
    2.	PSU Redirected to TPP (PISP): The merchant forwards the PSU to the TPP (Payment Initiation Service Provider) to complete the checkout. Provide the amount to be paid and a transaction reference.
    3.	TPP Submits Payment Initiation Request and use the create endpoint to submit a Payment Initiation request to Mastercard Open Finance.

    ```shell
    https://api.nordicapigateway.com/v1/payments/create

Example

```shell
{
  "issuePayerToken": true,
  "payerToken": "<payer-token>",
  "providerId": "DemoBank",
  "providers": [
    "DK"
  ],
  "excludeProviders": [
    "SE"
  ],
  "userHash": "<user-hash>",
  "keyServerToken": "<key-server-token>",
  "request": {
    "sourceAccountId": "5d5bcLTPv-HH-pV26cT67lrIY8kwz59whYjEJasHyUc.5ef85601bc3b",
    "destination": {
      "bban": {
        "bankCode": "1234",
        "accountNumber": "1234567890"
      },
      "iban": {
        "ibanNumber": "DK1234567890123456"
      },
      "ownAccount": {
        "accountId": "5d5bcLTPv-HH-pV26cT67lrIY8kwz59whYjEJasHyUc.5ef85601bc3b"
      },
      "inpaymentForm": {
        "type": "DK_FI71",
        "creditorNumber": "12345678"
      },
      "name": "John Doe",
      "address": {
        "street": "Street Name",
        "buildingNumber": "42",
        "postalCode": "1234",
        "city": "Copenhagen",
        "country": "DK"
      }
    },
    "amount": {
      "value": 1,
      "currency": "DKK"
    },
    "execution": {
      "type": "SpecificDate",
      "date": "2023-02-21"
    },
    "message": "Example message",
    "transactionText": "Example transaction text",
    "endToEndId": "A123JD12EJ123456BDE",
    "reference": {
      "value": "00000000000001234561"
    },
    "identifiers": {
      "creditorReference": "RF18539007547034",
      "endToEndId": "B2HGCDTE34PXRU4F6K7EY6TN2VWMX9BJS1C",
      "finnishReference": "00000000000001234561",
      "norwegianKid": "123456701123453",
      "estonianReference": "1234567011234539",
      "ocr": "12345678"
    },
    "paymentMethod": "Domestic"
  },
  "redirectUrl": "https://httpbin.org/anything",
  "language": "en",
  "state": "<state>",
  "displayInfo": {
    "sourceAccount": {
      "name": "John Doe",
      "iban": "DK12000403302021",
      "bbanParsed": {
        "bankCode": "0400",
        "accountNumber": "3302021"
      }
    },
    "destinationAccount": {
      "owner": "John Doe",
      "logoUrl": "https://httpbin.org/anything.svg"
    }
  }
}
```

Response

```shell
{
  "redirectUrl": "https://app.nordicapigateway.com/start/payment?startToken=<start-token>&paymentId=20220926.azdfqj71oefw3k5hiys7zuk1xr",
  "paymentId": "20190824.xrrksqlmngnw3xisfq8uqd1ijh"
}
```

### Step 3 - Payment initiation status {#step-3---payment-initiation-status}

Mastercard Authenticates PSU and Initiates Payment andprocesses the payment with the chosen ASPSP (PSU's bank) by authenticating the PSU and initiating the payment.
ASPSP Initiates Money Transfer to the merchant's account through the requested payment scheme.
ASPSP returns the payment initiation status to Mastercard Open Finance.

Mastercard retrieves the payment status using the endpoint below.

```shell
https://api.nordicapigateway.com/v1/payments/{paymentId}/refresh-status
```

```shell
{
  "payment": {
    "paymentId": "20190824.xrrksqlmngnw3xisfq8uqd1ijh",
    "userHash": "<user-hash>",
    "providerId": "DemoBank",
    "providerPaymentId": "<provider-payment-id>",
    "request": {
      "sourceAccountId": "5d5bcLTPv-HH-pV26cT67lrIY8kwz59whYjEJasHyUc.5ef85601bc3b",
      "destination": {
        "bban": {
          "bankCode": "1234",
          "accountNumber": "1234567890"
        },
        "iban": {
          "ibanNumber": "DK1234567890123456"
        },
        "ownAccount": {
          "accountId": "5d5bcLTPv-HH-pV26cT67lrIY8kwz59whYjEJasHyUc.5ef85601bc3b"
        },
        "inpaymentForm": {
          "type": "DK_FI71",
          "creditorNumber": "12345678"
        },
        "name": "John Doe",
        "address": {
          "street": "Street Name",
          "buildingNumber": "42",
          "postalCode": "1234",
          "city": "Copenhagen",
          "country": "DK"
        }
      },
      "amount": {
        "value": 1,
        "currency": "DKK"
      },
      "execution": {
        "type": "SpecificDate",
        "date": "2023-02-21"
      },
      "message": "Example message",
      "transactionText": "Example transaction text",
      "endToEndId": "A123JD12EJ123456BDE",
      "reference": {
        "value": "00000000000001234561"
      },
      "identifiers": {
        "creditorReference": "RF18539007547034",
        "endToEndId": "B2HGCDTE34PXRU4F6K7EY6TN2VWMX9BJS1C",
        "finnishReference": "00000000000001234561",
        "norwegianKid": "123456701123453",
        "estonianReference": "1234567011234539",
        "ocr": "12345678"
      },
      "paymentMethod": "Domestic"
    },
    "status": {
      "terminal": true,
      "code": "Preparing",
      "lastUpdated": "2019-08-24T14:15:22.223+00:00",
      "details": {
        "providerStatusCode": "RJCD",
        "reason": "UnknownError",
        "providerMessage": "Payment initiation rejected",
        "errorType": "PaymentErrorType",
        "errorCode": "MaximumAmountExceeded"
      }
    },
    "state": "Preparing",
    "created": "2019-08-24T14:15:22.223+00:00",
    "source": {
      "bban": {
        "bankCode": "1234",
        "accountNumber": "1234567890"
      },
      "iban": {
        "ibanNumber": "DK1234567890123456"
      },
      "ownAccount": {
        "accountId": "5d5bcLTPv-HH-pV26cT67lrIY8kwz59whYjEJasHyUc.5ef85601bc3b"
      },
      "inpaymentForm": {
        "type": "DK_FI71",
        "creditorNumber": "12345678"
      },
      "name": "John Doe",
      "address": {
        "street": "Street Name",
        "buildingNumber": "42",
        "postalCode": "1234",
        "city": "Copenhagen",
        "country": "DK"
      }
    },
    "execution": {
      "type": "SpecificDate",
      "date": "2019-08-24T14:15:22Z",
      "fee": "HasFee",
      "feeAmount": {
        "value": 1,
        "currency": "DKK"
      }
    },
    "message": "Example message",
    "transactionText": "Example transaction text",
    "identifiers": {
      "finnishArchiveId": "57509530547841",
      "creditorReference": "RF18539007547034",
      "endToEndId": "B2HGCDTE34PXRU4F6K7EY6TN2VWMX9BJS1C",
      "finnishReference": "00000000000001234561",
      "norwegianKid": "123456701123453",
      "estonianReference": "1234567011234539",
      "ocr": "12345678"
    }
  }
}
```

### Step 4 - Settles the payment {#step-4---settles-the-payment}

Mastercard returns the payment status to the TPP (PISP).
The merchant receives confirmation of payment initiation from their TPP (PISP).
The merchant's account receives the payment with the transaction reference.
The merchant reconciles and settles the payment.

In case of an invalid request, missing parameters, or failed request processing, information is returned in the status.details property of the payment response. Refer to the Error Handling documentation for additional information and steps on how to proceed.
