mercredi 9 novembre 2016

When creating transaction with fake-valid-nonce in test, the transaction result shows me the message: "Gateway Rejected: duplicate”

There is a problem when I trying to create a transaction with fake-valid-nonce in my test.

Here’s the code about create transaction:

const createTransaction = (price, nonceFromTheClient, customerBrainTreeId) => {
  const transactionToken = new Promise((resolve, reject) => {
    gateway.transaction.sale(
      {
        amount: price,
        customerId: customerBrainTreeId,
        paymentMethodNonce: nonceFromTheClient,
        options: {
          submitForSettlement: true
        }
      },
      (error, result) => {
        if (error) {
          logger.error(`create transaction error: ${error}`);
          reject(error);
        } else {
          resolve(result);
        }
      });
  });

  return transactionToken;
};

And here is the code about test:

it(‘**************************', () => {
  return PaymentService.createTransaction("104.0", 'fake-valid-nonce', null)
    .then(result => {
      expect(result.success).to.be.true;
      expect(result.transaction.status).to.be.equals('submitted_for_settlement');
      expect(result.transaction.type).to.be.equals('sale');
    });
});

When I run the test for the first time, this test will pass. But, if I run this test multiple times, this test will not pass, and the transaction result shows me the message: "Gateway Rejected: duplicate”.

How can I solve this problem?

Aucun commentaire:

Enregistrer un commentaire