cancel
Showing results for 
Search instead for 
Did you mean: 

How to make Credit card payment in Magento 2 using Rest API?

How to make Credit card payment in Magento 2 using Rest API?

I am working on Magento 2.3 REST API for a Roku application. Our client wants to give payment option on Roku device for his customers.

I have followed these APIs step by step:

1. http://10.1.1.5/demo/rest/V1/integration/customer/token

2. http://10.1.1.5/demo/rest/V1/carts/mine

3. http://10.1.1.5/demo/rest/V1/carts/mine/items

4. http://10.1.1.5/demo/rest/V1/carts/mine/shipping-information

It returns payment method:

"payment_methods": [
        {
            "code": "pmclain_authorizenetcim_vault",
            "title": "Stored Cards (Authorize.net CIM)"
        },
        {
            "code": "pmclain_authorizenetcim",
            "title": "Credit Cards (CIM)"
        },
        {
            "code": "braintree_cc_vault",
            "title": "Stored Cards (Braintree)"
        },
        {
            "code": "braintree",
            "title": "Credit Card (Braintree)"
        },
        {
            "code": "checkmo",
            "title": "Check / Money order"
        }
    ],

5. http://10.1.1.5/demo/rest/V1/carts/mine/payment-information

And payload for this api is:

{
 "email": "test@gmail.com",
 "cart_id": 180,
 "billing_address": {
              "email": "test@gmail.com",
             "region": "New York",
             "region_id": 43,
             "region_code": "NY",
                 "country_id": "US",
                 "street": ["123 Oak Ave"],
                 "postcode": "10577",
                 "city": "Purchase",
                 "telephone": "512-555-1111",
                 "firstname": "Jane",
                 "lastname": "Doe"
      },
 "paymentMethod": {
    "method": "pmclain_authorizenetcim",
    "additional_data":{  
        "cc_cid":"123",
        "cc_type":"VI",
        "cc_exp_year":"2021",
        "cc_exp_month":"3",
        "cc_number":"4111111111111111"
    }
 }
}

And response I am getting:

{
    "message": "Opaque Data requires Data Value."
}

 

I think this is happens due to invalid payload or I am not doing this in right direction. Since I am new for Magento so unable to figure out this problem.


Could i directly send credit card details to API "rest/V1/carts/mine/payment-information" or need to something like payment token? If i need payment token then what will be magento api for this? 
could anyone please suggest me how to do this or am I doing in incorrect way?

I have configured Authorize.Net in magento backend and also want to use this payment option in Roku device but not sure is this possible or not for Roku device?

Thank you!

2 REPLIES 2

Re: How to make Credit card payment in Magento 2 using Rest API?

Do this request before the set-payment-method 

 
export const doApiRequest = async (payload: {
    "securePaymentContainerRequest": {
        "merchantAuthentication": {
            "name": string,
            "clientKey": string
        },
        "data": {
            "type": string,
            "id": string,
            "token": {
                "cardNumber": string,
                "expirationDate": string,
                "cardCode": string
            }
        }
    }

}) => {
    return await axios.post("https://api2.authorize.net/xml/v1/request.api", payload)
}
 
And in the response you will get this 
{
  "opaqueData": {
      "dataDescriptor": "",
      "dataValue": ""
  },
  "messages": {
      "resultCode": "Ok",
      "message": [
          {
              "code": "I00001",
              "text": "Successful."
          }
      ]
  }
}
And then do the set-payment-method api call with this payload
 {
      "method": "authnetcim",
      "additional_data": {
          "acceptjs_key": "opaqueData?.dataDescriptor",
          "acceptjs_value": "opaqueData?.dataValue",
          "cc_bin": "424242",
          "cc_cid": "164",
          "cc_exp_month": "03",
          "cc_exp_year": "2029",
          "cc_last4": "4242",
          "save": false
      },
      "extension_attributes": {
          "agreement_ids": [
              "1"
          ]
      }
  
}

Hopefully this will resolve your issue

Re: How to make Credit card payment in Magento 2 using Rest API?

To make a credit card payment in Magento 2 using the REST API, follow these steps:

  1. Authentication: Obtain an admin token by calling the /V1/integration/admin/token endpoint with admin credentials.

  2. Create Order: Use the /V1/carts/mine/payment-information endpoint to place an order. You'll need to provide customer and payment details, including the credit card information (card number, expiration date, CVV).

  3. Payment Information: Include the payment method as part of the payload, such as "method": "credit_card" or any applicable method specific to your Magento setup.

  4. Capture Payment: Ensure that your payment integration (e.g., PayPal, Stripe) is correctly configured in Magento to process the credit card transactions.

Each API call must be done with proper headers and authentication, following Magento's API documentation.