craftgate/craftgate-node-client

Payment with other test cards is stacking as pending request

enesozturk opened this issue · 6 comments

Hi, I am testing payments in sandbox. It is fine so far. Payments are successfully made. But when I want to use test cards that returns error codes given in your docs, requests are stacking in pending state, not returning.

What I do is changing only cardNumber of the example card number given here. Not sure if I am doing right.

const paymentDetails = {
  ...
  card: {
    ....
    cardNumber: "4102190000000008", // Just changing this, others are same with example object.
    ...
  },
};

The reason I want to test with others is to see and handle error states in my application. This is happening in only card numbers that return errors. Example card;

4102190000000008: (10005) Do not honour hata kodu döner.

Request Details

Request URL: http://localhost:3000/api/payment
Referrer Policy: strict-origin-when-cross-origin
Accept: /
Accept-Encoding: gzip, deflate, br
Accept-Language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7
Connection: keep-alive
Content-Length: 69
Content-Type: text/plain;charset=UTF-8
Host: localhost:3000
Origin: http://localhost:3000
Referer: http://localhost:3000/checkout
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
{items: [{name: "Docker", price: 14}, {name: "Next JS", price: 2}]}
items: [{name: "Docker", price: 14}, {name: "Next JS", price: 2}]

Thanks in advance

Hi @enesozturk,
We tested it on our Runkit with card 4102190000000008 and we couldn't see any issue. You can test it at https://developer.craftgate.io/api/odeme/odeme-alma.

I tested with different approaches on my Next.js project but could not solved. There must be something I am missing like previous issue #52. Did not have enough time to check more. Will check it later and let you know about changes. Thanks for the response.

Hi @enesozturk,
Are there any updates for this issue?
Thanks

Hi @sotuzun, sorry for late response, unfortunately I did not able to check different ways to solve it yet. I was using it in my side project so I may be slow to make it.

There exists nothing to do for now. I am closing the issue. Please create a new issue if you have new questions or problems. Thanks.

Hi, it might be good to write the solution for the future visitors. It was because of my use of API Routes in Next.js. We need to return the response with the res object to get a response on the front-end side.

✅ Here is an example for future followers:

export default (req, res) => {
  const { items } = JSON.parse(req.body);

  const totalPrice = items.reduce((acc, item) => acc + item.price, 0);

  craftgate
    .payment()
    .createPayment({
      ...paymentDetails,
      price: totalPrice,
      paidPrice: totalPrice,
      items,
    })
    .then(function (result) {
      res.status(200).json(result);
    })
    .catch(function (err) {
      res.send(err);
    });
};