square / square-nodejs-sdk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CreatePaymentResponse returning a trailing 'n' after the amount value

chinesehemp opened this issue · comments

Hi,

I'm getting a weird response in the https://github.com/square/square-nodejs-sdk/blob/master/doc/models/create-payment-response.md when I use the createPayment API.

Here's what I'm getting...

>      totalMoney: { amount: 1000n, currency: 'GBP' },
>      approvedMoney: { amount: 1000n, currency: 'GBP' },

Here's what I'm expecting as per the CreatePaymentResponse type definition.

      "amount": 1000,
      "currency": "USD"
    },
    "app_fee_money": {
      "amount": 10,
      "currency": "USD"
    },

As you can see, there is a weird n trailing the amount. This is causing a JSON parsing error when I try to return the result to my application. Am I doing something wrong here?

For ref, here's my request code

    const {result} = await client.paymentsApi.createPayment({
      sourceId: "cnon:card-nonce-ok",
      idempotencyKey: uuidv4(),
      amountMoney: {
        amount: BigInt(1000),
        currency: "GBP",
      },
    });
    console.log(result);
    res.send(result);
  } catch (error) {
    if (error instanceof ApiError) {
      console.log(error);
      res.status(500).send(error);
    }
  }

Okay, I figured it out.

Had to install https://github.com/sidorares/json-bigint and then use JSONbig.stringify(result); to fix it.

    const promise = await client.paymentsApi.createPayment({
      sourceId: "cnon:card-nonce-ok",
      idempotencyKey: uuidv4(),
      amountMoney: {
        amount: BigInt(8888),
        currency: "GBP",
      },
    });
    return JSON.parse(JSONbig.stringify(promise));
  } catch (error) {
    if (error instanceof ApiError) {
      console.error;
      return error;
    }
    return error;
  }```