1 | import window from "window"
|
2 | import forEach from "lodash-es/forEach"
|
3 | import dataLayerPush from "./helpers/dataLayerPush"
|
4 |
|
5 | function klarnaCheckout(klarnaCheckoutCallback) {
|
6 | if (window._klarnaCheckout) {
|
7 | let klarnaEvents = ["change", "shipping_address_change", "order_total_change", "can_not_complete_order"]
|
8 | let callBackObj = {}
|
9 | forEach(klarnaEvents, function (klarnaEvent) {
|
10 | callBackObj[klarnaEvent] = function (data) {
|
11 | let dlObj = {
|
12 | "klarna": data
|
13 | }
|
14 | klarnaCheckoutCallback(dlObj)
|
15 | dataLayerPush("Klarna Checkout",dlObj)
|
16 | }
|
17 | })
|
18 | console.log(callBackObj)
|
19 | window._klarnaCheckout(function (api) {
|
20 | console.log("Klarna mounted")
|
21 | console.log(api)
|
22 | api.on(callBackObj)
|
23 | })
|
24 | } else {
|
25 | console.log("no klarna")
|
26 | }
|
27 | }
|
28 |
|
29 | export default klarnaCheckout |
\ | No newline at end of file |