I try to integrate klarna payments for opencart.
I get an client_token from klarna, so the iframe is shown.
next step is to authorize the testdata.
unfortunately I get { "show_form": false, "approved": false }
back as result.
I send the following testscript:
<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: "[email protected]",
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>
It should work, because its official testdata from klarna. did someone know, why it does not work?
greetings
The above can be changed to:
The init and load functions are to be called in klarnaAsyncCallback. I have noticed that the authorize function always return { "show_form": false, "approved": false } and the popup does not appear if it is called inside the init function or not inside an event.
For Example, the authorize function can be triggered by a button click and it appears to create the popup and return authorization token after the flow.
Something like this should help: