SagePay-400-请求格式不正确

时间:2019-01-24 17:24:01

标签: sagepay

我正在尝试使用request-promise库通过Node.js制定付款方式。我收到此错误:

400 - {"description":"Incorrect request format","code":1000}

当前使用沙箱,我的代码如下:

    const postData = JSON.stringify({
      "transactionType": "Payment",
      "paymentMethod": {
        "card": {
          "merchantSessionKey": merchantSessionKey,
          "cardIdentifier": cardIdentifier
        }
      },
      "vendorTxCode": `demotransaction-${time}`,
      "amount": parseInt(baseGrandTotal, 10),
      "currency": baseCurrencyCode,
      "description": "Demo transaction",
      "customerFirstName": customer.address_billing.firstname,
      "customerLastName": customer.address_billing.lastname,
      "billingAddress": {
        "address1": customer.address_billing.street[0],
        "city": customer.address_billing.city,
        "postalCode": customer.address_billing.postcode,
        "country": customer.address_billing.country_id
      }
    });

    const SagePayment = new Promise((resolve, reject) => {
      const requestOptions = {
        method: 'POST',
        uri: 'https://pi-test.sagepay.com/api/v1/transactions',
        headers: {
          'Cache-Control': 'no-cache',
          'Content-Type': 'application/json',
          Authorization: 'Basic aEpZeHN3N0hMYmo0MGNCOHVkRVM4Q0RSRkxodUo4RzU0TzZyRHBVWHZFNmhZRHJyaWE6bzJpSFNyRnliWU1acG1XT1FNdWhzWFA1MlY0ZkJ0cHVTRHNocktEU1dzQlkxT2lONmh3ZDlLYjEyejRqNVVzNXU='
        },
        body: postData,
        json: true
      };

      rp(requestOptions)
        .then(data => {
          resolve(data);
        })
        .catch(err => {
          reject(err);
        });
    });

在完整的响应中,我可以看到我正在将有效的JSON插入正文中。所以我很困惑问题所在。我也已经针对API文档检查了我提供的JSON,因此看不到明显的问题。

JSON正文示例:

{
    "transactionType": "Payment",
    "paymentMethod": {
        "card": {
            "merchantSessionKey": "365636356",
            "cardIdentifier": "365636356"
        }
    },
    "vendorTxCode": "demotransaction-1548349070589",
    "amount": 142,
    "currency": "GBP",
    "description": "Demo transaction",
    "customerFirstName": "Name",
    "customerLastName": "Lastname",
    "billingAddress": {
        "address1": "street",
        "city": "city",
        "postalCode": "postcode",
        "country": "GB"
    }
}

0 个答案:

没有答案