adyen-node-api-library icon indicating copy to clipboard operation
adyen-node-api-library copied to clipboard

[BUG]Payment Request Missing Error with Local Communication Using adyen-node-api-library

Open praveenkumar-foodhub opened this issue 1 year ago • 1 comments

Describe the bug: We are encountering an error when trying to make a payment using local communication with the adyen-node-api-library. The error message indicates that the payment request is missing, even though we are sending the payment request in the payload which is encrypted in Nexoblob.

Error Message received: adyen error

To Reproduce: PAYLOAD: { "MessageHeader": { "MessageCategory": "Payment", "MessageClass": "Service", "MessageType": "Request", "POIID": "123", "ProtocolVersion": "3.0", "SaleID": "1144506", "ServiceID": "1144506" }, "NexoBlob": "c0HqQlaWEjvG+SPutg2lDI7SR8oe0lygKSV9eLn5YrGKkl2DMxkdAeNk6zdQT2o+2cGx3uYQHOXuW6nGe/LK+raypSsSXJ17KlDhabmA4FM5Ws9ptjr2iyKG0Dcs8pvPfdDm9jYsIcXatPvdr5T+uDHqVbN+1OS+J1axcyUb0xn5EZ24WHBlhJkrMrtaMYs/HYZG6R5h4VgNWwzJxrDFsEkaL4dWngz1aC+8uFOKF47qs21zfPLfDsmmdIpMc2tdd6vcBFXofi8MN0rT4vNPGv2vXGPuHXwRhIRZ+MtVxEct5uwINU+lj0XmUm6njYgfoyve3CSKK7Txuat2qxU9L+eWHhEZzFvAQ21MjzauegHjpPoJPyoSfJZ8X4F9gUK64mqNA7W+ZcHNsB0hhM2uMU6udqQTyBs26+zMldOshPoFSHPEER1viq7igBefazV0Om13muSQF5WfTeAPCJboWvf8gjdmboQ1tAMS2kw5IF7J/Hz3PptRvh81XKAcZTkgxcFlj9quiULB7mwEz26ayQQXm0XW89t5tIqIJzXDPVtyrP5IXtRsmKDUGqPesa61CQzdDtrtRSWYd0hENHD074ac4L8kodneajFW5iWiiuyKgD1x4ELGzaifeOHBpA5PMItJ+pbUa8RQiEG8+eGjJT2TL1BOmJrEduZ14HiHoBhtDrtpwBmP5m2qRiaO2tbc9F/tpceLXedNo2n655D6AgMIcf+Msn+XhKoBd8ruMmamO4QbrBnnQjmc08ZqD0lEgEmpcDSd0Ywmhx3fD1nZkdKjqpRR4HqymcNrTxGPI8vKN5aZPdjbhkZncGyfKrxT", "SecurityTrailer": { "AdyenCryptoVersion": 1, "Hmac": "UYSdo5A3nv2DED7rLuLvDgmDyAY+Bw7N/G3m29+10pw=", "KeyIdentifier": "adyen-test", "KeyVersion": 1, "Nonce": "QcABehfViTcOafBgBq6EMQ==" } }`

CODE: ` import { Client, Config, TerminalLocalAPI } from "@adyen/api-library" import { TerminalApiRequest, MessageHeader, SaleToPOIRequest, PaymentTransaction, PaymentRequest, AmountsReq, SaleData, TransactionIdentification, MessageCategoryType, MessageClassType, MessageType, SecurityKey, } from "@adyen/api-library/lib/src/typings/terminal/models"

const id = Math.floor(Math.random() * Math.floor(10000000)).toString() const getMessageHeader = ({ messageCategory = MessageCategoryType.Payment }: { messageCategory?: MessageCategoryType } = {}): MessageHeader => ({ MessageCategory: messageCategory, MessageClass: MessageClassType.Service, MessageType: MessageType.Request, POIID: '123', ProtocolVersion: "3.0", SaleID: id, ServiceID: id, })

const timestamp = (): string => new Date().toISOString() const transactionIdentification: TransactionIdentification = { TimeStamp: timestamp(), TransactionID: id, }

const saleData: SaleData = { SaleTransactionID: transactionIdentification, SaleToAcquirerData: { applicationInfo: { merchantApplication: { version: "1", name: "test", }, }, metadata: { someMetaDataKey1: "YOUR_VALUE", someMetaDataKey2: "YOUR_VALUE", }, }, }

const amountsReq: AmountsReq = { Currency: "CAD", RequestedAmount: 1, } const paymentTransaction: PaymentTransaction = { AmountsReq: amountsReq, }

const paymentRequest: PaymentRequest = { PaymentTransaction: paymentTransaction, SaleData: saleData, }

const getSaleToPOIRequest = (messageHeader: MessageHeader, request: Partial<SaleToPOIRequest>): SaleToPOIRequest => ({ MessageHeader: messageHeader, ...request, })

const createTerminalAPIPaymentRequest = (): TerminalApiRequest => { const messageHeader = getMessageHeader() const saleToPOIRequest = getSaleToPOIRequest(messageHeader, { PaymentRequest: paymentRequest }) return { SaleToPOIRequest: saleToPOIRequest } }

const terminalAPIPaymentRequest = createTerminalAPIPaymentRequest()

const securityKey: SecurityKey = { AdyenCryptoVersion: 1, KeyIdentifier: "adyen-test", KeyVersion: 1, Passphrase: "foodhubadyen", }

export const createClient = (apiKey = process.env.ADYEN_API_KEY): Client => { const config: Config = new Config() config.apiKey = "+5HzctViMSCJMYAc=-wzf2rXM6UC/OdvRbqTVok0piJmjMOOEnKjUVwyQ+Qoo=-i1i73^7nLgd&28e,}.k" // config. = "FoodHubLimited_Pos-terminals_TEST"

// const terminalId = [TERMINAL_ID]
config.terminalApiLocalEndpoint = "https://192.168.29.63"

config.certificatePath = "./adyen.pem"

const client = new Client({ config })
client.setEnvironment("TEST")

return client

}

const client = createClient() const terminalLocalAPI = new TerminalLocalAPI(client)

const run = async () => { try { await terminalLocalAPI.request(terminalAPIPaymentRequest, securityKey) } catch (e) { console.log(e) } }

run() `

praveenkumar-foodhub avatar Jun 13 '24 11:06 praveenkumar-foodhub

Hi @praveenkumar-foodhub,

Thanks for reaching out here and apologies for the delayed response. Did you try setting the DeviceID parameter in the MessageHeader? This is required for the nexo request.

Best, Jilling Adyen

jillingk avatar Oct 03 '24 11:10 jillingk

This issue has been automatically marked as stale due to inactivity and will be closed in 7 days if no further activity occurs.

github-actions[bot] avatar Nov 12 '24 08:11 github-actions[bot]

This issue was closed due to inactivity. Please reopen if you still encounter this problem or have more information to add.

github-actions[bot] avatar Nov 19 '24 08:11 github-actions[bot]