我正在我的webapp中实现Klarna Checkout。使用aws无服务器的后端。前端: react。我在创建订单方面遇到了麻烦。它在postman中运行良好,但我无法获得基本的身份验证工作axios。
出于测试目的,我从我的react应用程序中发布了订单。一旦我让它工作,它将被移动到后端。
我的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错误。

我得到的回应是。

我已经用邮递员试过了,效果很好。
发布于 2019-12-24 06:08:59
总结一下:Klarna的API不能从浏览器调用,只能从服务器端调用。我从我的aws lambda调用了相同的代码,它工作得很好。
https://stackoverflow.com/questions/59398713
复制相似问题