Home > Magento 2 – Mastercard Payment Gateway Services > Headless API Integration > REST API

Magento 2 – Mastercard Payment Gateway Services

Created date: 14-03-23   |   Updated date: 10-12-24   |   Plugin version: 2.4.2  |   API version: 84

REST API

Mastercard Magento Plugin helps to connect with Mastercard Payment Service APIs and process the payments. The plugin enables both frontend (website) and backend (admin portal) screens to perform the following functions.

The frontend screens support the following features

  • Hosted Session
  • Hosted Checkout
  • ACH

Whereas the backend screen enables the merchant and developer to perform the following functions

  • Configure the Payment Integrations
    • Mastercard API Credentials
    • 3DS enable / disable
    • Other Settings
  • Option to Full Refund and Partial Refund
Solution for integrating Mastercard Plugin in Headless Magento

Headless Magento integration decouples the website parts which would give flexibility to customize. In this scenario we consider that the front-end is developed in any front-end technology React / Angular and the for backend Magento built in admin module is utilized.

The below solution helps the developer to utilize the plugin that would bring up all the backend screens that has been explained above giving a room to create the front-end payment screens from scratch.

Step 1: Create Payment Session – The plugin has REST API endpoints which can be triggered to create the session
API URL : /rest/V1/tns/hc/session/create
Method : POST
Request Data :

{
 "cartId": cartId,
 "paymentMethod":
 {
  "method":"tns_hpf"
 }
}

Response Data :

[
"SESSION0002126146914M82601030I0",
"3f5759cc01"
]

Use the session id [ Example : “SESSION0002126146914M82601030I0” ] for adding the card details

Step 2: Custom form should be created in the frontend and pass the form data to Mastercard API

Sample URL : https://test.gateway.spring.citi.com/form/version/63/merchant/TESTCITITEST_CA/session/
SESSION0002126146914M82601030I0
Mastercard API URL : https://test.gateway.spring.citi.com

API username : TESTCITITEST_CA
API version : 63

Request Data 1 :

[{"field":"number","value":"5123450000000008"},{"field":"sourceOfFundsType","value":"card"}]

Request Data 2 :

[{"field":"expiryMonth","value":"2"},{"field":"sourceOfFundsType","value":"card"}]

Request Data 3 :

[{"field":"expiryYear","value":"2025"},{"field":"sourceOfFundsType","value":"card"}]

Request Data 4 :

[{"field":"securityCode","value":"123"},{"field":"sourceOfFundsType","value":"card"}]

Step 3: After the card details are added successfully, Magento’s default order placing APIs can be used to complete the Order

URL : /rest/V1/carts/mine/payment-information
Method : POST

Request data:

{
 "paymentMethod": {
 "method": "tns_hpf",
 "Additional_data":
 {
  "session": "SESSION0002126146914M82601030I0"
 }
}