const request = require('request');

const options = {
  method: 'PUT',
  url: 'https://api.betterez.com/sales/cancellations',
  headers: {
    authorization: 'Bearer {{jwtToken}}',
    'Content-Type': 'application/json;charset=UTF-8',
    Accept: 'application/json, text/plain, */*',
    'x-api-key': '{{x-api-key}}'
  },
  body: {
    _id: '507f191e810c19729de860ea',
    cancellation: {
      trxId: '507f191e810c19729de860ee',
      transactionId: 'ABCDFG12',
      customerNumber: '123-456-789',
      tickets: [
        {
          _id: '507f191e810c19729de860ea',
          trxId: '507f191e810c19729de860ee',
          accountId: '507f191e810c19729de86000',
          ticketNumber: 'ABCDEF',
          ticketId: '507f191e810c19729de860ea',
          productFamily: 'ticket',
          productType: 'ticket',
          productId: '507f191e810c19729de860ea',
          totalRefundable: 6150000,
          displayTotalRefundable: 6150000,
          rounding: {policy: 'default', decimals: '2'},
          fareClassId: null,
          fees: [],
          taxes: [],
          status: 'paid',
          ratios: [{type: 'cash', total: 6260000, displayTotal: 6260000, extraInfo: null}],
          cancelFees: [
            {
              calculated: 615000,
              _id: '507f191e810c19729de860ea',
              userId: '507f191e810c19729de860ea',
              accountId: '507f191e810c19729de860ea',
              internalId: 'Example cancel fee',
              name: 'Example cancel fee',
              valueType: '%',
              value: 10000,
              taxable: true,
              isRefundable: true,
              valueToDisplay: '10',
              displayCalculated: 615000,
              taxes: [
                {
                  name: 'ontax',
                  value: 5000,
                  province: 'Ontario',
                  calculated: 28000,
                  displayCalculated: 28000
                },
                {
                  name: 'Universal all state tax',
                  value: 5000,
                  province: 'all',
                  calculated: 28000,
                  displayCalculated: 28000
                }
              ],
              taxesTotal: 56000,
              displayTaxesTotal: 56000
            }
          ],
          expirationDate: {},
          expiryDate: null,
          price: 4590000,
          total: 6260000,
          displayPrice: 4590000,
          displayTotal: 6260000,
          subTotal: 0,
          totalTaxes: 560000,
          displaySubTotal: 0,
          displayTotalTaxes: 560000,
          flexPassOptions: {},
          currentScansPerDay: {},
          availableUses: 1,
          totalCancelFees: 615000,
          displayTotalCancelFees: 615000,
          createdFromFlexpassId: null,
          payment: [
            {
              provider: 'inperson',
              type: 'cash',
              ticketNumber: 'ABCDEF',
              amount: 5535000,
              acceptedCurrencyAmount: 5535000,
              percentage: 100
            }
          ],
          refunded: 5535000,
          displayRefunded: 5535000,
          itemType: 'reservation',
          totalRefundablePreTax: 5590000,
          displayTotalRefundablePreTax: 5590000
        }
      ],
      reservations: [],
      soldItems: [],
      flexPasses: [],
      redeemableItems: [],
      giftCertificates: [],
      parcels: [],
      insurances: [],
      trxFees: [],
      cancelFees: [
        {
          internalId: 'cExample ancel fee',
          name: 'Example cancel fee',
          calculated: 616000,
          displayCalculated: 616000,
          taxesTotal: 56000,
          value: 10000,
          valueType: '%'
        }
      ],
      overridedCancelFees: [],
      displayCurrency: {isocode: 'USD', symbol: '$', buy: 1, sell: 1, channels: ['backoffice']},
      penalty: {amount: 0, acceptedAmount: 0, reason: ''},
      payments: [
        {
          _id: 'a1b2c3d4-abdc-abcd-1234-a1b2c3d4f555',
          method: 'cash',
          provider: 'inperson',
          displayName: 'cash',
          firstName: 'FirstName',
          lastName: 'LastName',
          currency: 'USD',
          card: '',
          authorization: '',
          amount: '55.44',
          acceptedCurrencyAmount: '55.44',
          feesAndPenaltyAmount: '6.16',
          displayFeesAndPenaltyAmount: '6.16',
          feesAndPenaltyAmountValue: 616000,
          displayFeesAndPenaltyAmountValue: 616000,
          amountValue: 5544000,
          acceptedCurrencyAmountValue: 5544000
        }
      ]
    },
    signature: '86734655de9f997daddb61927f1a4111918d777493d748300689c0b0a55a87c899cad21b0b08c80a3c534b687cedf5ff'
  },
  json: true
};

request(options, function (error, response, body) {
	if (error) throw new Error(error);

	console.log(body);
});