Adyen / adyen-node-api-library

Adyen API Library for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Cannot read property 'MessageHeader' of undefined at TerminalLocalAPI.request

19hours opened this issue · comments

Describe the bug
I am testing out the local terminals api, and I am passing in an object as my SaleToPOIRequest, but I am getting this error. I am not using Typescript.

Node version: 13.14

TypeError: Cannot read property 'MessageHeader' of undefined at TerminalLocalAPI.request

To Reproduce

terminalLocalAPI.request({
  SaleToPOIRequest: {
    MessageHeader: {
      ProtocolVersion: "3.0",
      MessageClass: "Service",
      MessageCategory: "Payment",
      MessageType: "Request",
      SaleID: "Test1",
      ServiceID: "1",
      POIID: "", // removed
    },
    PaymentRequest: {
      SaleData: {
        SaleTransactionID: {
          TransactionID: "1",
          TimeStamp: "2022-02-17T14:00:00+00:00",
        },
      },
      PaymentTransaction: {
        AmountsReq: {
          Currency: "USD",
          RequestedAmount: 5,
        },
      },
    },
  },
}, securityKey)

Expected behavior
The terminal receives the instruction.

Fixed by changing passphrase to Passphrase: https://docs.adyen.com/point-of-sale/choose-your-architecture/local/protect-with-library?tab=node_3.

Now I am facing a invalid x-api-key error of status code 401

Hi @19hours,

Thank you for raising this issue.
I'm glad to hear you resolved your initial issue, yet it seems our Library feedback could do with some improvement perhaps.

The second issue you're getting implies your Merchant account was not configured correctly. Please make sure it is set up correctly for the POS transaction you are trying to make and retry.
If this results in more problems please contact our Tech Support

Hi @wboereboom

Thanks for the swift reply. I am following the docs, are these the configuration I have to provide and are they correct?

config.merchantAccount = "";
config.certificatePath = "/Users/x/Desktop/certificates/adyen-terminalfleet-test.pem";
config.terminalApiLocalEndpoint = "";
config.apiKey = ""; // obtained from instructions here: https://docs.adyen.com/point-of-sale/terminal-api-fundamentals#api-key
config.username = ""; 

@wboereboom

Steps I have done so far but still no dice

  • Enabled Terminal API under Integration for the specific POS
  • Regenerated an API key under my merchant account
  • Made sure roles are all enabled

Hi @19hours,
If the above did not fix it for you I recommend to contact our support as indicated above. They'll know how to resolve account-related issues like these.

Kind Regards,
Wouter
Adyen

Hi @wboereboom

I have contacted the Adyen support and they got back to me saying that API KEY and web service account is not necessary for local cloud terminal integration:
https://docs.adyen.com/point-of-sale/choose-your-architecture/local

I followed the documentation and I am still getting the same X-API-KEY error, even when I am using terminalLocalAPI to request payment.

Here is a sample code to replicate this error. I have removed the important details like merchantAccount, terminalApiLocalEndpoint, keyIdenfier and Passphase and POIID.

Is there a sample code I can compare against for local cloud terminal pos? Or is there anything I'm missing out below?

const adyen = require("@adyen/api-library");
const config = require("./config");

const adConfig = new adyen.Config();
adConfig.merchantAccount = "";
adConfig.certificatePath = "adyen-terminalfleet-test.pem";
adConfig.terminalApiLocalEndpoint = "";

const client = new adyen.Client({
  adConfig,
});
client.setEnvironment("TEST");
const terminalLocalAPI = new adyen.TerminalLocalAPI(client);

const securityKey = {
  adyenCryptoVersion: 1,
  keyIdentifier: "",
  keyVersion: 1,
  Passphrase: "",
};

terminalLocalAPI
  .request(
    {
      SaleToPOIRequest: {
        MessageHeader: {
          ProtocolVersion: "3.0",
          MessageClass: "Service",
          MessageCategory: "Payment",
          MessageType: "Request",
          SaleID: "Test123",
          ServiceID: "12",
          POIID: "",
        },
        PaymentRequest: {
          SaleData: {
            SaleTransactionID: {
              TransactionID: "1",
              TimeStamp: "2022-02-17T14:00:00+00:00",
            },
          },
          PaymentTransaction: {
            AmountsReq: {
              Currency: "USD",
              RequestedAmount: 5.0,
            },
          },
        },
      },
    },
    securityKey
  )
  .then((r) => {
    console.log(r);
  })
  .catch((e) => {
    console.log(e);
  });

Hi @19hours ,

Noticing 2 things you might be able to try here:

  1. Remove the merchant account from the request.
  2. I'm noticing all fields but Passphrase in the security key object are not capitalized. They should all start with an upper case.

Hope this will resolve any issues you are experiencing.

Kind Regards,
Wouter
Adyen

I fixed this by setting terminalLocalAPI.localRequest.service.client.config to the config I created earlier. API_KEY is also necessary