OmAiR KH
OmAiR KH

Reputation: 71

2checkout-nodejs Error Parsing JSON from 2Checkout API

I was trying to implement 2checkout-nodejs as a payment method for an e-commerce website but I kept on getting this error:

Error: Error parsing JSON response from 2Checkout API.
`const tco = new Twocheckout({   
apiUser: "my-username",   
apiPass: "my-password",   
sellerId: "my-seller-id",   
secretKey: "my-secret-word",   
privateKey: "my-private-key",   
secretWord: "secret-word",   
demo: false,   
sandbox: true, 
})`;

using this method:

const params = { privateKey: "my-private-key", mode: "2CO", li_0_name: "data", li_0_price: "price", first_name: "client-name", last_name: "client-lastname", email: "client-email", address1: "client-address", address2: "", phone: "client-phone", country: "country", city: "city", state: "state", zip: "zip", qty: "quantity", currency_code: "currency code", };

I tried to log every step and everything but I kept getting the same error all the time and everything seems right except the outcome.

await tco.checkout.authorize(JSON.stringify(params), (error, data) => { if (error) { console.log({ error }); res.status(301).json({ param: error, data: data }); // console.log(error); } else { do something }

Upvotes: 0

Views: 103

Answers (1)

mhmmdamiwn
mhmmdamiwn

Reputation: 334

I dont know that is going to solve your problem but use double cot ("") for your keys too :

`const tco = new Twocheckout({   
"apiUser": "my-username",   
...
})`;

Upvotes: 0

Related Questions