0

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 }

1 Answer 1

0

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",   
...
})`;
Sign up to request clarification or add additional context in comments.

1 Comment

I already tried it. Nothing changed I received the same error again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.