0

我正在我的 web 应用程序中实现 Klarna Checkout。后端使用 aws 无服务器。前端:反应。我被困在创建订单上。它在邮递员内部工作正常,但我无法获得基本的身份验证工作 axios。

出于测试目的,我从我的反应应用程序发布订单。一旦我让它工作,它将被移动到后端。

我的 axios 代码如下所示。

axios
  .post(
    "https://api.playground.klarna.com/checkout/v3/orders",
    {
      purchase_country: "DE",
      purchase_currency: "EUR",
      locale: "de-DE",
      order_amount: 3,
      order_tax_amount: 0,
      order_lines: [
        {
          type: "digital",
          reference: "Test",
          name: "Test Subscription",
          quantity: 1,
          quantity_unit: "pcs",
          unit_price: 3,
          tax_rate: 0,
          total_amount: 3,
          total_discount_amount: 0,
          total_tax_amount: 0
        }
      ],
      merchant_urls: {
        terms: "https://www.example.com/terms.html",
        checkout: "https://www.example.com/checkout.html",
        confirmation: "https://www.example.com/confirmation.html",
        push: "https://www.example.com/api/push"
      }
    },
    {
      auth: {
        username: "xxx",
        password: "xxx"
      },
      headers: {
        "Content-Type": "application/json"
      }
    }
  )
  .then(result => console.dir(result));

我在 OPTIONS 收到 401 错误。

在此处输入图像描述

我得到的回应。

在此处输入图像描述

我用邮递员试过了,效果很好。

4

1 回答 1

0

总结评论:不能仅从服务器端从浏览器调用 Klarna 的 API。我从我的 aws lambda 中调用了相同的代码,它运行良好。

于 2019-12-23T22:08:59.390 回答