Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
praveenkumar-foodhub opened this issue Jun 13, 2024 · 2 comments
Labels
bug Something isn't working Stale

Comments

@praveenkumar-foodhub
Copy link

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 => ({
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 praveenkumar-foodhub added the bug Something isn't working label Jun 13, 2024
@jillingk
Copy link
Contributor

jillingk commented Oct 3, 2024

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

Copy link

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 github-actions bot added the Stale label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

3 participants