我试图整合klarna对opencart的支付。
我从克拉纳得到一个client_token,所以iframe显示出来了。
下一步是授权测试数据。
不幸的是,我得到{ "show_form":false,“已批准”:false }
结果回来了。
我发送以下测试脚本:
<script>
try {
Klarna.Payments.init({
"client_token":"<?php echo $klarna_client_token ?>"
})
} catch (e) {
// Fehler anzeigen
alert(e);
}
Klarna.Payments.load({
container: '#klarna-payments-container',
payment_method_category: 'pay_later'
}, function (res) {
console.log(JSON.stringify(res, null, 4));
})
Klarna.Payments.authorize({
payment_method_category: "pay_later"
}, {
billing_address: {
given_name: "Omer",
family_name: "Heberstreit",
email: "omer@Heberstreit.com",
title: "Herr",
street_address: "Hermannstraße 64",
street_address2: "",
postal_code: "53225",
city: "Bonn",
phone: "+491522113356",
country: "DE"
},
order_amount: 10,
order_tax_amount: 0,
order_lines: [{
type: "physical",
reference: "19-402",
name: "Battery Power Pack",
quantity: 1,
unit_price: 10,
tax_rate: 0,
total_amount: 10,
total_discount_amount: 0,
total_tax_amount: 0,
product_url: "https://www.estore.com/products/f2a8d7e34",
image_url: "https://www.exampleobjects.com/logo.png"
}],
customer: {
date_of_birth: "1970-01-01",
}
}, function(res2) {
console.log(JSON.stringify(res2, null, 4));
})
</script>
<div id="klarna-payments-container"></div>它应该能工作,因为它的官方测试数据来自克拉纳。有人知道吗,为什么不起作用?
问候
发布于 2022-02-15 13:51:54
try {
Klarna.Payments.init({
"client_token":"<?php echo $klarna_client_token ?>"
})
} catch (e) {
// Fehler anzeigen
alert(e);
}
Klarna.Payments.load({
container: '#klarna-payments-container',
payment_method_category: 'pay_later'
}, function (res) {
console.log(JSON.stringify(res, null, 4));
})上述内容可改为:
//The following method initializes the Klarna Payments JS library
window.klarnaAsyncCallback = function () {
Klarna.Payments.init({
client_token: '<?php echo $klarna_client_token ?>'
});
console.log("Payments initialized");
//The following method loads the payment_method_category in the container with the id of 'klarna_container'
Klarna.Payments.load({
container: '#klarna_container',
payment_method_category: 'pay_later'
}, function (res) {
console.log("Load function called")
console.debug(res);
});
};init和load函数将在klarnaAsyncCallback中调用。我已经注意到,授权函数总是返回{ "show_form":false、“已批准”:false },如果它在init函数中调用或不在事件中调用,则弹出窗口不会出现。
/*The following is the authorize function, which triggers Klarna to perform a risk assessment of the purchase
The successful response of this risk assessment is an authorization token, which in this example is logged in the console
*/
$(function(){
$("button.authorize").on('click', function(){
Klarna.Payments.authorize({
payment_method_category: "pay_later"
}, {
billing_address: {
given_name: "Omer",
family_name: "Heberstreit",
email: "omer@Heberstreit.com",
title: "Herr",
street_address: "Hermannstraße 64",
street_address2: "",
postal_code: "53225",
city: "Bonn",
phone: "+491522113356",
country: "DE"
},
order_amount: 10,
order_tax_amount: 0,
order_lines: [{
type: "physical",
reference: "19-402",
name: "Battery Power Pack",
quantity: 1,
unit_price: 10,
tax_rate: 0,
total_amount: 10,
total_discount_amount: 0,
total_tax_amount: 0,
product_url: "https://www.estore.com/products/f2a8d7e34",
image_url: "https://www.exampleobjects.com/logo.png"
}],
customer: {
date_of_birth: "1970-01-01",
}
}, function(res2) {
console.log(JSON.stringify(res2, null, 4));
})
})
})例如,可以通过单击按钮触发授权函数,并在流之后创建弹出并返回授权令牌。
像这样的东西应该会有帮助:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://x.klarnacdn.net/kp/lib/v1/api.js" async></script>
</head>
<body>
<script type="text/javascript">
//The following method initializes the Klarna Payments JS library
window.klarnaAsyncCallback = function() {
Klarna.Payments.init({
client_token: '< client-token >'
});
console.log("Payments initialized");
//The following method loads the payment_method_category in the container with the id of 'klarna_container'
Klarna.Payments.load({
container: '#klarna_container',
payment_method_category: '< pay_later | pay_over_time >'
}, function(res) {
console.log("Load function called")
console.debug(res);
});
//Multiple widgets can be loaded by calling the load function again
/* Klarna.Payments.load({
container: '#klarna_container',
payment_method_category: '< pay_later | pay_over_time >'
}, function(res) {
console.log("Load function called")
console.debug(res);
}); */
};
/*The following is the authorize function, which triggers Klarna to perform a risk assessment of the purchase
The successful response of this risk assessment is an authorization token, which in this example is logged in the console
*/
$(function() {
$("button.authorize").on('click', function() {
Klarna.Payments.authorize({
payment_method_category: "< pay_later | pay_over_time >"
}, {
purchase_country: "GB",
purchase_currency: "GBP",
locale: "en-GB",
billing_address: {
given_name: "Test",
family_name: "Person-uk",
email: "customer@email.uk",
street_address: "13 New Burlington St",
street_address2: "Apt 214",
postal_code: "W13 3BG",
city: "London",
region: "",
phone: "01895808221",
country: "GB"
},
order_amount: 1000,
order_tax_amount: 0,
order_lines: [{
type: "physical",
reference: "19-402",
name: "Battery Power Pack",
quantity: 1,
unit_price: 1000,
tax_rate: 0,
total_amount: 1000,
total_discount_amount: 0,
total_tax_amount: 0,
product_url: "https://www.estore.com/products/f2a8d7e34",
image_url: "https://www.exampleobjects.com/logo.png"
}],
// customer: {
// date_of_birth: "1970-01-01",
// },
}, function(res) {
console.log("Response from the authorize call:")
console.log(res)
})
})
})
</script>
<div style="width: 500px; margin: auto; padding-top: 150px; padding-bottom: 30px;">
<img src="https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg" style="width: 500px; margin: auto;">
</div>
<!--Klarna container-->
<div id="klarna_container" style="width: 500px; margin: auto;"></div>
<div style="width: 500px; margin: auto;">
<!--Button to trigger authorize call-->
<button class="authorize" style="width: 500px; height: 50px; margin: auto;">Buy Now</button>
</div>
</script>
</body>
</html>https://stackoverflow.com/questions/62873551
复制相似问题