基本认证axios-klarna结帐

问题描述 投票:0回答:1

我正在我的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错误。

enter image description here

我得到的答复。

enter image description here

我已经与邮递员尝试过,效果很好。

javascript json axios klarna
1个回答
0
投票

总结评论:不能仅从服务器端从浏览器调用Klarna的API。我从aws lambda调用了相同的代码,效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.