Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vue-storefront/checkout-com

Package Overview
Dependencies
Maintainers
8
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vue-storefront/checkout-com - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

2

lib/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=(e=require("axios"))&&"object"==typeof e&&"default"in e?e.default:e,t=require("@vue-storefront/core"),r=require("@vue/composition-api"),a=function(){return(a=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)};function o(e,n,t,r){return new(t||(t=Promise))((function(a,o){function u(e){try{s(r.next(e))}catch(e){o(e)}}function i(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){e.done?a(e.value):new t((function(n){n(e.value)})).then(u,i)}s((r=r.apply(e,n||[])).next())}))}function u(e,n){var t,r,a,o,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(a=u.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){u.label=o[1];break}if(6===o[0]&&u.label<a[1]){u.label=a[1],a=o;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(o);break}a[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(e,u)}catch(e){o=[6,e],r=0}finally{t=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var i,s,l,c=a({},{publicKey:null,ctApiUrl:"https://play-commercetools.cko-playground.ckotech.co/api",tokenizedCardKey:"temporary-tokenized-card",saveInstrumentKey:"save-instrument",card:{style:{},localization:null},klarna:{containerSelector:"#klarna_container"},channels:{},currentChannel:null,ckoSCAenabled:!1}),d={"card-number":{color:"red"},base:{color:"#72757e",fontSize:"19px",minWidth:"60px"},invalid:{color:"red"},placeholder:{base:{color:"black",fontSize:"19px"}}},v=function(e){var n,t,r;if(c.channels[e]){var a=c.channels[e];c.publicKey=a.publicKey,c.card.style=(null===(n=a.card)||void 0===n?void 0:n.style)||d,c.card.localization=(null===(t=a.card)||void 0===t?void 0:t.localization)||null,c.klarna.containerSelector=(null===(r=a.klarna)||void 0===r?void 0:r.containerSelector)||c.klarna.containerSelector,c.tokenizedCardKey=a.tokenizedCardKey||c.tokenizedCardKey,c.saveInstrumentKey=a.saveInstrumentKey||c.saveInstrumentKey,c.ctApiUrl=a.ctApiUrl||c.ctApiUrl,c.currentChannel=e,c.ckoSCAenabled=!!a.ckoSCAenabled}else console.error("[CKO] Requested channel does not exist in the config")},m=function(){return c.publicKey},f=function(){return c.currentChannel},p=function(){return c.tokenizedCardKey},y=function(){return c.saveInstrumentKey},_=function(){return c.ctApiUrl},h=function(){return window.location.origin+"/cko-api"},k=function(){return c.card.style},C=function(){return{crossDomain:!0,headers:{authorization:m()}}},P=function(e){var t=e.reference,r=e.email,i=void 0===r?null:r,s=e.products,l=void 0===s?null:s;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,n.post(_()+"/api/contexts",a(a({reference:t},i?{customer_email:i}:{}),l?{products:l}:{}),C())]}))}))},b=function(e){return o(void 0,void 0,void 0,(function(){return u(this,(function(t){return[2,n.post(_()+"/api/payments",e,C())]}))}))},T=function(e){var t=e.customer_id;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,n.post(h()+"/payment-instruments",{customer_id:t,channel:f()})]}))}))},A=function(e){var t=e.customer_id,r=e.payment_instrument_id;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,n.delete(h()+"/payment-instruments/"+t+"/"+r+"/"+f())]}))}))};(s=exports.CkoPaymentType||(exports.CkoPaymentType={}))[s.NOT_SELECTED=0]="NOT_SELECTED",s[s.CREDIT_CARD=1]="CREDIT_CARD",s[s.SAVED_CARD=2]="SAVED_CARD",s[s.KLARNA=3]="KLARNA",s[s.PAYPAL=4]="PAYPAL",s[s.SOFORT=5]="SOFORT",(l=exports.CkoChallengeIndicatorType||(exports.CkoChallengeIndicatorType={})).NO_PREFERENCE="no_preference",l.NO_CHALLENGE_REQUESTED="no_challenge_requested",l.CHALLENGE_REQUESTED="challenge_requested",l.CHALLENGE_REQUESTED_MANDATE="challenge_requested_mandate";var E=function(e){var n=e.context_id,t=e.save_payment_instrument,r=e.secure3d,o=e.attempt_n3d,u=e.success_url,i=e.failure_url,s=e.cvv,l=e.reference,c=e.challenge_indicator3d,d=a(a(a({},r?{enabled:r}:{}),o?{attempt_n3d:o}:{}),c?{challenge_indicator:c}:{});return a(a(a(a(a(a({context_id:n},s?{cvv:s}:{}),t?{save_payment_instrument:t}:{}),0!==Object.keys(d).length?{"3ds":a({},d)}:{}),u?{success_url:u}:{}),i?{failure_url:i}:{}),l?{reference:l}:{})},x=((i={})[exports.CkoPaymentType.CREDIT_CARD]=function(e){return a(a({},E(e)),{type:"token",token:e.token})},i[exports.CkoPaymentType.SAVED_CARD]=function(e){return a(a({},E(e)),{type:"id",token:e.token})},i[exports.CkoPaymentType.KLARNA]=function(e){return a(a({},E(e)),{type:"klarna",token:e.token})},i[exports.CkoPaymentType.PAYPAL]=function(e){return a(a({},E(e)),{type:"paypal"})},i[exports.CkoPaymentType.SOFORT]=function(e){return a(a({},E(e)),{type:"sofort"})},i),w=function(e,n){return x[e](n)},g=function(){return sessionStorage.getItem(p())},I=function(e){return sessionStorage.setItem(p(),e)},R=function(){return sessionStorage.removeItem(p())},D=function(e){var n=t.sharedRef(!1,"useCkoCard-isCardValid"),i=t.sharedRef(null,"useCkoCard-error"),s=t.sharedRef([],"useCkoCard-storedPaymentInstruments"),l=r.computed((function(){return e.value===exports.CkoPaymentType.CREDIT_CARD&&!n.value}));return{error:i,submitDisabled:l,storedPaymentInstruments:s,selectedCardPaymentMethod:r.computed((function(){return e.value})),submitForm:function(){return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,Frames.submitCard()]}))}))},makePayment:function(n){var t=n.cartId,r=n.email,a=n.secure3d,s=n.attempt_n3d,l=n.cvv,d=void 0===l?null:l,v=n.contextDataId,m=void 0===v?null:v,f=n.savePaymentInstrument,p=void 0!==f&&f,y=n.success_url,_=void 0===y?null:y,h=n.failure_url,k=void 0===h?null:h,C=n.reference,T=void 0===C?null:C;return o(void 0,void 0,void 0,(function(){var n,o,l,v,f,y;return u(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,4,,5]),!(n=g()))throw new Error("There is no payment token");return o=void 0,m?[3,2]:[4,P({reference:t,email:r})];case 1:if(o=u.sent(),e.value===exports.CkoPaymentType.SAVED_CARD&&o.data.payment_settings&&o.data.payment_settings.cvv_required&&!d)throw new Error("CVV is required");u.label=2;case 2:return l=e.value===exports.CkoPaymentType.CREDIT_CARD&&p,v=l&&c.ckoSCAenabled?exports.CkoChallengeIndicatorType.CHALLENGE_REQUESTED_MANDATE:null,[4,b(w(e.value,{token:n,secure3d:a,attempt_n3d:s,cvv:d,reference:T,context_id:m||o.data.id,save_payment_instrument:l,challenge_indicator3d:v,success_url:_||window.location.origin+"/cko/payment-success",failure_url:k||window.location.origin+"/cko/payment-error"}))];case 3:if(f=u.sent(),R(),![200,202].includes(f.status))throw new Error(f.data.error_type);return i.value=null,[2,f];case 4:return y=u.sent(),R(),i.value=y,[2,null];case 5:return[2]}}))}))},initCardForm:function(e){var t=(null==e?void 0:e.localization)||c.card.localization;Frames.init(a(a({publicKey:m(),style:(null==e?void 0:e.style)||k()},t?{localization:t}:{}),{cardValidationChanged:function(){n.value=Frames.isCardValid()},cardTokenized:function(e){var n=e.token;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return I(n),[2]}))}))},cardTokenizationFailed:function(e){i.value=e,n.value=!1}}))},setTransactionToken:I,loadStoredPaymentInstruments:function(e){return o(void 0,void 0,void 0,(function(){var n,t;return u(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,T({customer_id:e})];case 1:return n=r.sent().data,s.value=n.payment_instruments,[3,3];case 2:return t=r.sent(),i.value=t,[3,3];case 3:return[2]}}))}))},removePaymentInstrument:function(n,t){return o(void 0,void 0,void 0,(function(){var r,a;return u(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,A({customer_id:n,payment_instrument_id:t})];case 1:return o.sent(),r=s.value.find((function(e){return e.payment_instrument_id===t})).id,s.value=s.value.filter((function(e){return e.payment_instrument_id!==t})),r===g()&&(e.value=exports.CkoPaymentType.CREDIT_CARD,R()),[3,3];case 2:return a=o.sent(),i.value=a,[3,3];case 3:return[2]}}))}))},setPaymentInstrument:function(n){I(n),e.value=exports.CkoPaymentType.SAVED_CARD},removeTransactionToken:R}},S=function(){var e=t.sharedRef(null,"useCkoKlarna-error");return{makePayment:function(n){var t=n.contextDataId,r=n.secure3d,a=n.savePaymentInstrument,i=n.reference,s=void 0===i?null:i,l=n.success_url,c=void 0===l?null:l,d=n.failure_url,v=void 0===d?null:d;return o(void 0,void 0,void 0,(function(){var n,o,i;return u(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,2,,3]),!(n=g()))throw new Error("There is no payment token");return[4,b(w(exports.CkoPaymentType.KLARNA,{token:n,context_id:t,secure3d:r,reference:s,save_payment_instrument:a,success_url:c||window.location.origin+"/cko/payment-success",failure_url:v||window.location.origin+"/cko/payment-error"}))];case 1:if(o=u.sent(),R(),![200,202].includes(o.status))throw new Error(o.data.error_type);return e.value=null,[2,o];case 2:return i=u.sent(),R(),e.value=i,[2,null];case 3:return[2]}}))}))},initKlarnaForm:function(e,n,t){Klarna.Payments.init({client_token:n.metadata.details.client_token});var r={options:{container:(null==e?void 0:e.containerSelector)||c.klarna.containerSelector,payment_method_categories:n.metadata.details.payment_method_category.map((function(e){return e.identifier})),instance_id:t},data:n.metadata.session},o=(null==e?void 0:e.beforeLoad)?e.beforeLoad(a({apm:n},r)):r,u=o.options,i=o.data;Klarna.Payments.load(u,i)},submitForm:function(e){return new Promise((function(n,t){try{Klarna.Payments.authorize({instance_id:e},{},(function(e){I(e.authorization_token),n(e)}))}catch(e){t(e)}}))},error:e}},K=function(e){localStorage.setItem(y(),JSON.stringify(e))},O=function(){var e=localStorage.getItem(y());return!!e&&JSON.parse(e)};exports.getApiUrl=_,exports.getFramesStyles=k,exports.getPublicKey=m,exports.setChannel=v,exports.setup=function(e){var n=e.channels,t=e.defaultChannel;n[t]?(c.channels=n,v(t)):console.error("[CKO] Bad config provided")},exports.useCko=function(){var e=t.sharedRef(null,"useCko-error"),n=t.sharedRef([],"useCko-availableMethods"),a=t.sharedRef(null,"useCko-contextId"),i=t.sharedRef(!1,"useCko-requiresCvv"),s=t.sharedRef(exports.CkoPaymentType.NOT_SELECTED,"useCko-selectedPaymentMethod"),l=D(s),c=l.initCardForm,d=l.makePayment,v=l.error,m=l.submitForm,f=l.setPaymentInstrument,p=l.removePaymentInstrument,y=l.loadStoredPaymentInstruments,_=l.removeTransactionToken,h=l.storedPaymentInstruments,k=l.submitDisabled,C=S(),T=C.initKlarnaForm,A=C.submitForm,E=C.makePayment,x=C.error,g=function(){var e=t.sharedRef(null,"useCkoPaypal-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,a=n.secure3d,i=n.contextDataId,s=void 0===i?null:i,l=n.savePaymentInstrument,c=void 0!==l&&l,d=n.success_url,v=void 0===d?null:d,m=n.failure_url,f=void 0===m?null:m,p=n.reference,y=void 0===p?null:p;return o(void 0,void 0,void 0,(function(){var n,o,i;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),n=void 0,s?[3,2]:[4,P({reference:t,email:r})];case 1:n=u.sent(),u.label=2;case 2:return[4,b(w(exports.CkoPaymentType.PAYPAL,{secure3d:a,reference:y,context_id:s||n.data.id,save_payment_instrument:c,success_url:v||window.location.origin+"/cko/payment-success",failure_url:f||window.location.origin+"/cko/payment-error"}))];case 3:if(o=u.sent(),![200,202].includes(o.status))throw new Error(o.data.error_type);return e.value=null,[2,o];case 4:return i=u.sent(),e.value=i,[2,null];case 5:return[2]}}))}))}}}(),I=g.makePayment,R=g.error,L=function(){var e=t.sharedRef(null,"useCkoSofort-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,a=n.contextDataId,i=void 0===a?null:a,s=n.success_url,l=void 0===s?null:s,c=n.failure_url,d=void 0===c?null:c,v=n.reference,m=void 0===v?null:v;return o(void 0,void 0,void 0,(function(){var n,a,o;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),n=void 0,i?[3,2]:[4,P({reference:t,email:r})];case 1:n=u.sent(),u.label=2;case 2:return[4,b(w(exports.CkoPaymentType.SOFORT,{reference:m,context_id:i||n.data.id,success_url:l||window.location.origin+"/cko/payment-success",failure_url:d||window.location.origin+"/cko/payment-error"}))];case 3:if(a=u.sent(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 4:return o=u.sent(),e.value=o,[2,null];case 5:return[2]}}))}))}}}(),F=L.makePayment,N=L.error;return{availableMethods:n,error:e,selectedPaymentMethod:s,storedPaymentInstruments:h,submitDisabled:k,storedContextId:r.computed((function(){return a.value})),isCvvRequired:r.computed((function(){return i.value})),loadAvailableMethods:function(t,r,s){return o(void 0,void 0,void 0,(function(){var o,l;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,P({reference:t,email:r,products:s})];case 1:return o=u.sent(),n.value=function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),a=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,i=o.length;u<i;u++,a++)r[a]=o[u];return r}(o.data.apms,[{name:"card"}]),a.value=o.data.id,o.data.payment_settings&&"cvv_required"in o.data.payment_settings&&(i.value=o.data.payment_settings.cvv_required),[2,o.data];case 2:return l=u.sent(),e.value=l,[2,null];case 3:return[2]}}))}))},initForm:function(e,t){if(void 0===e&&(e=null),void 0===t&&(t={}),!e||0!==Object.keys(e).length)for(var r=e&&Object.keys(e).length>0,o=0,u=n.value;o<u.length;o++){var i=u[o];if(!r||e[i.name]){var s=t[i.name];switch(i.name){case"card":c(s);break;case"klarna":T(s,i,a.value)}}}},submitCardForm:m,submitKlarnaForm:function(e){return A(e||a.value)},makePayment:function(n){var t=void 0===n?{}:n,r=t.cartId,l=void 0===r?null:r,c=t.email,m=void 0===c?null:c,f=t.contextDataId,p=void 0===f?null:f,y=t.success_url,_=void 0===y?null:y,h=t.failure_url,k=void 0===h?null:h,C=t.secure3d,P=void 0===C||C,b=t.attempt_n3d,T=void 0!==b&&b,A=t.cvv,w=void 0===A?null:A,g=t.reference,D=void 0===g?null:g;return o(void 0,void 0,void 0,(function(){var n,t,r;return u(this,(function(o){switch(o.label){case 0:if(!s.value)return e.value=new Error("Payment method not selected"),[2];if([exports.CkoPaymentType.CREDIT_CARD,exports.CkoPaymentType.SAVED_CARD].includes(s.value)){if(s.value===exports.CkoPaymentType.SAVED_CARD&&i.value&&!w)return e.value=new Error("CVV is required"),[2];n=d,t=v}else if(s.value===exports.CkoPaymentType.KLARNA)n=E,t=x;else if(s.value===exports.CkoPaymentType.PAYPAL)n=I,t=R;else{if(s.value!==exports.CkoPaymentType.SOFORT)return e.value=new Error("Not supported payment method"),[2];n=F,t=N}return e.value=null,[4,n({cartId:l,email:m,success_url:_,failure_url:k,secure3d:P,attempt_n3d:T,cvv:w,reference:D,contextDataId:p||a.value,savePaymentInstrument:O()})];case 1:return r=o.sent(),t.value&&(e.value=t.value),[2,r]}}))}))},setPaymentInstrument:f,setSavePaymentInstrument:K,loadSavePaymentInstrument:O,removePaymentInstrument:p,loadStoredPaymentInstruments:y,removeTransactionToken:_}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=(e=require("axios"))&&"object"==typeof e&&"default"in e?e.default:e,t=require("@vue-storefront/core"),r=require("@vue/composition-api"),a=function(){return(a=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)};function o(e,n,t,r){return new(t||(t=Promise))((function(a,o){function u(e){try{s(r.next(e))}catch(e){o(e)}}function i(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){e.done?a(e.value):new t((function(n){n(e.value)})).then(u,i)}s((r=r.apply(e,n||[])).next())}))}function u(e,n){var t,r,a,o,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(a=u.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){u.label=o[1];break}if(6===o[0]&&u.label<a[1]){u.label=a[1],a=o;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(o);break}a[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(e,u)}catch(e){o=[6,e],r=0}finally{t=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var i,s,l,c=a({},{publicKey:null,ctApiUrl:"https://play-commercetools.cko-playground.ckotech.co/api",tokenizedCardKey:"temporary-tokenized-card",saveInstrumentKey:"save-instrument",card:{style:{},localization:null},klarna:{containerSelector:"#klarna_container"},channels:{},currentChannel:null,ckoSCAenabled:!1}),d={"card-number":{color:"red"},base:{color:"#72757e",fontSize:"19px",minWidth:"60px"},invalid:{color:"red"},placeholder:{base:{color:"black",fontSize:"19px"}}},v=function(e){var n,t,r;if(c.channels[e]){var a=c.channels[e];c.publicKey=a.publicKey,c.card.style=(null===(n=a.card)||void 0===n?void 0:n.style)||d,c.card.localization=(null===(t=a.card)||void 0===t?void 0:t.localization)||null,c.klarna.containerSelector=(null===(r=a.klarna)||void 0===r?void 0:r.containerSelector)||c.klarna.containerSelector,c.tokenizedCardKey=a.tokenizedCardKey||c.tokenizedCardKey,c.saveInstrumentKey=a.saveInstrumentKey||c.saveInstrumentKey,c.ctApiUrl=a.ctApiUrl||c.ctApiUrl,c.currentChannel=e,c.ckoSCAenabled=!!a.ckoSCAenabled}else console.error("[CKO] Requested channel does not exist in the config")},m=function(){return c.publicKey},f=function(){return c.currentChannel},p=function(){return c.tokenizedCardKey},y=function(){return c.saveInstrumentKey},_=function(){return c.ctApiUrl},h=function(){return window.location.origin+"/cko-api"},k=function(){return c.card.style},C=function(){return{crossDomain:!0,headers:{authorization:m()}}},P=function(e){var t=e.reference,r=e.email,i=void 0===r?null:r,s=e.products,l=void 0===s?null:s;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,n.post(_()+"/api/contexts",a(a({reference:t},i?{customer_email:i}:{}),l?{products:l}:{}),C())]}))}))},b=function(e){return o(void 0,void 0,void 0,(function(){return u(this,(function(t){return[2,n.post(_()+"/api/payments",e,C())]}))}))},T=function(e){var t=e.customer_id;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,n.post(h()+"/payment-instruments",{customer_id:t,channel:f()})]}))}))},A=function(e){var t=e.customer_id,r=e.payment_instrument_id;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,n.delete(h()+"/payment-instruments/"+t+"/"+r+"/"+f())]}))}))};(s=exports.CkoPaymentType||(exports.CkoPaymentType={}))[s.NOT_SELECTED=0]="NOT_SELECTED",s[s.CREDIT_CARD=1]="CREDIT_CARD",s[s.SAVED_CARD=2]="SAVED_CARD",s[s.KLARNA=3]="KLARNA",s[s.PAYPAL=4]="PAYPAL",s[s.SOFORT=5]="SOFORT",(l=exports.CkoChallengeIndicatorType||(exports.CkoChallengeIndicatorType={})).NO_PREFERENCE="no_preference",l.NO_CHALLENGE_REQUESTED="no_challenge_requested",l.CHALLENGE_REQUESTED="challenge_requested",l.CHALLENGE_REQUESTED_MANDATE="challenge_requested_mandate";var E=function(e){var n=e.context_id,t=e.save_payment_instrument,r=e.secure3d,o=e.attempt_n3d,u=e.success_url,i=e.failure_url,s=e.cvv,l=e.reference,c=e.challenge_indicator3d,d=a(a(a({},r?{enabled:r}:{}),o?{attempt_n3d:o}:{}),c?{challenge_indicator:c}:{});return a(a(a(a(a(a({context_id:n},s?{cvv:s}:{}),t?{save_payment_instrument:t}:{}),0!==Object.keys(d).length?{"3ds":a({},d)}:{}),u?{success_url:u}:{}),i?{failure_url:i}:{}),l?{reference:l}:{})},x=((i={})[exports.CkoPaymentType.CREDIT_CARD]=function(e){return a(a({},E(e)),{type:"token",token:e.token})},i[exports.CkoPaymentType.SAVED_CARD]=function(e){return a(a({},E(e)),{type:"id",token:e.token})},i[exports.CkoPaymentType.KLARNA]=function(e){return a(a({},E(e)),{type:"klarna",token:e.token})},i[exports.CkoPaymentType.PAYPAL]=function(e){return a(a({},E(e)),{type:"paypal"})},i[exports.CkoPaymentType.SOFORT]=function(e){return a(a({},E(e)),{type:"sofort"})},i),w=function(e,n){return x[e](n)},g=function(){return sessionStorage.getItem(p())},I=function(e){return sessionStorage.setItem(p(),e)},R=function(){return sessionStorage.removeItem(p())},D=function(e){var n=t.sharedRef(!1,"useCkoCard-isCardValid"),i=t.sharedRef(null,"useCkoCard-error"),s=t.sharedRef([],"useCkoCard-storedPaymentInstruments"),l=r.computed((function(){return e.value===exports.CkoPaymentType.CREDIT_CARD&&!n.value}));return{error:i,submitDisabled:l,storedPaymentInstruments:s,selectedCardPaymentMethod:r.computed((function(){return e.value})),submitForm:function(){return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return[2,Frames.submitCard()]}))}))},makePayment:function(n){var t=n.cartId,r=n.email,a=n.secure3d,s=n.attempt_n3d,l=n.cvv,d=void 0===l?null:l,v=n.contextDataId,m=void 0===v?null:v,f=n.savePaymentInstrument,p=void 0!==f&&f,y=n.success_url,_=void 0===y?null:y,h=n.failure_url,k=void 0===h?null:h,C=n.reference,T=void 0===C?null:C;return o(void 0,void 0,void 0,(function(){var n,o,l,v,f,y;return u(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,4,,5]),!(n=g()))throw new Error("There is no payment token");return o=void 0,m?[3,2]:[4,P({reference:t,email:r})];case 1:if(o=u.sent(),e.value===exports.CkoPaymentType.SAVED_CARD&&o.data.payment_settings&&o.data.payment_settings.cvv_required&&!d)throw new Error("CVV is required");u.label=2;case 2:return l=e.value===exports.CkoPaymentType.CREDIT_CARD&&p,v=l&&c.ckoSCAenabled?exports.CkoChallengeIndicatorType.CHALLENGE_REQUESTED_MANDATE:null,[4,b(w(e.value,{token:n,secure3d:a,attempt_n3d:s,cvv:d,reference:T,context_id:m||o.data.id,save_payment_instrument:l,challenge_indicator3d:v,success_url:_||window.location.origin+"/cko/payment-success",failure_url:k||window.location.origin+"/cko/payment-error"}))];case 3:if(f=u.sent(),R(),![200,202].includes(f.status))throw new Error(f.data.error_type);return i.value=null,[2,f];case 4:return y=u.sent(),R(),i.value=y,[2,null];case 5:return[2]}}))}))},initCardForm:function(e){var t=(null==e?void 0:e.localization)||c.card.localization;Frames.init(a(a({publicKey:m(),style:(null==e?void 0:e.style)||k()},t?{localization:t}:{}),{cardValidationChanged:function(){n.value=Frames.isCardValid()},cardTokenized:function(e){var n=e.token;return o(void 0,void 0,void 0,(function(){return u(this,(function(e){return I(n),[2]}))}))},cardTokenizationFailed:function(e){i.value=e,n.value=!1}}))},setTransactionToken:I,loadStoredPaymentInstruments:function(e){return o(void 0,void 0,void 0,(function(){var n,t;return u(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,T({customer_id:e})];case 1:return n=r.sent().data,s.value=n.payment_instruments,[3,3];case 2:return t=r.sent(),i.value=t,[3,3];case 3:return[2]}}))}))},removePaymentInstrument:function(n,t){return o(void 0,void 0,void 0,(function(){var r,a;return u(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,A({customer_id:n,payment_instrument_id:t})];case 1:return o.sent(),r=s.value.find((function(e){return e.payment_instrument_id===t})).id,s.value=s.value.filter((function(e){return e.payment_instrument_id!==t})),r===g()&&(e.value=exports.CkoPaymentType.CREDIT_CARD,R()),[3,3];case 2:return a=o.sent(),i.value=a,[3,3];case 3:return[2]}}))}))},setPaymentInstrument:function(n){I(n),e.value=exports.CkoPaymentType.SAVED_CARD},removeTransactionToken:R}},S=function(){var e=t.sharedRef(null,"useCkoKlarna-error");return{makePayment:function(n){var t=n.contextDataId,r=n.secure3d,a=n.savePaymentInstrument,i=n.reference,s=void 0===i?null:i,l=n.success_url,c=void 0===l?null:l,d=n.failure_url,v=void 0===d?null:d;return o(void 0,void 0,void 0,(function(){var n,o,i;return u(this,(function(u){switch(u.label){case 0:if(u.trys.push([0,2,,3]),!(n=g()))throw new Error("There is no payment token");return[4,b(w(exports.CkoPaymentType.KLARNA,{token:n,context_id:t,secure3d:r,reference:s,save_payment_instrument:a,success_url:c||window.location.origin+"/cko/payment-success",failure_url:v||window.location.origin+"/cko/payment-error"}))];case 1:if(o=u.sent(),R(),![200,202].includes(o.status))throw new Error(o.data.error_type);return e.value=null,[2,o];case 2:return i=u.sent(),R(),e.value=i,[2,null];case 3:return[2]}}))}))},initKlarnaForm:function(e,n,t){Klarna.Payments.init({client_token:n.metadata.details.client_token});var r={options:{container:(null==e?void 0:e.containerSelector)||c.klarna.containerSelector,payment_method_categories:n.metadata.details.payment_method_category.map((function(e){return e.identifier})),instance_id:t},data:n.metadata.session},o=(null==e?void 0:e.beforeLoad)?e.beforeLoad(a({apm:n},r)):r,u=o.options,i=o.data;Klarna.Payments.load(u,i)},submitForm:function(e){return new Promise((function(n,t){try{Klarna.Payments.authorize({instance_id:e},{},(function(e){I(e.authorization_token),n(e)}))}catch(e){t(e)}}))},error:e}},K=function(e){localStorage.setItem(y(),JSON.stringify(e))},O=function(){var e=localStorage.getItem(y());return!!e&&JSON.parse(e)};exports.getApiUrl=_,exports.getFramesStyles=k,exports.getPublicKey=m,exports.setChannel=v,exports.setup=function(e){var n=e.channels,t=e.defaultChannel;n[t]?(c.channels=n,v(t)):console.error("[CKO] Bad config provided")},exports.useCko=function(){var e=t.sharedRef(null,"useCko-error"),n=t.sharedRef([],"useCko-availableMethods"),a=t.sharedRef(null,"useCko-contextId"),i=t.sharedRef(!1,"useCko-requiresCvv"),s=t.sharedRef(exports.CkoPaymentType.NOT_SELECTED,"useCko-selectedPaymentMethod"),l=D(s),c=l.initCardForm,d=l.makePayment,v=l.error,m=l.submitForm,f=l.setPaymentInstrument,p=l.removePaymentInstrument,y=l.loadStoredPaymentInstruments,_=l.removeTransactionToken,h=l.storedPaymentInstruments,k=l.submitDisabled,C=S(),T=C.initKlarnaForm,A=C.submitForm,E=C.makePayment,x=C.error,g=function(){var e=t.sharedRef(null,"useCkoPaypal-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,a=n.secure3d,i=n.contextDataId,s=void 0===i?null:i,l=n.savePaymentInstrument,c=void 0!==l&&l,d=n.success_url,v=void 0===d?null:d,m=n.failure_url,f=void 0===m?null:m,p=n.reference,y=void 0===p?null:p;return o(void 0,void 0,void 0,(function(){var n,o,i;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),n=void 0,s?[3,2]:[4,P({reference:t,email:r})];case 1:n=u.sent(),u.label=2;case 2:return[4,b(w(exports.CkoPaymentType.PAYPAL,{secure3d:a,reference:y,context_id:s||n.data.id,save_payment_instrument:c,success_url:v||window.location.origin+"/cko/payment-success",failure_url:f||window.location.origin+"/cko/payment-error"}))];case 3:if(o=u.sent(),![200,202].includes(o.status))throw new Error(o.data.error_type);return e.value=null,[2,o];case 4:return i=u.sent(),e.value=i,[2,null];case 5:return[2]}}))}))}}}(),I=g.makePayment,R=g.error,L=function(){var e=t.sharedRef(null,"useCkoSofort-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,a=n.contextDataId,i=void 0===a?null:a,s=n.success_url,l=void 0===s?null:s,c=n.failure_url,d=void 0===c?null:c,v=n.reference,m=void 0===v?null:v;return o(void 0,void 0,void 0,(function(){var n,a,o;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,4,,5]),n=void 0,i?[3,2]:[4,P({reference:t,email:r})];case 1:n=u.sent(),u.label=2;case 2:return[4,b(w(exports.CkoPaymentType.SOFORT,{reference:m,context_id:i||n.data.id,success_url:l||window.location.origin+"/cko/payment-success",failure_url:d||window.location.origin+"/cko/payment-error"}))];case 3:if(a=u.sent(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 4:return o=u.sent(),e.value=o,[2,null];case 5:return[2]}}))}))}}}(),F=L.makePayment,N=L.error;return{availableMethods:n,error:r.computed((function(){return e.value||v.value||null})),selectedPaymentMethod:s,storedPaymentInstruments:h,submitDisabled:k,storedContextId:r.computed((function(){return a.value})),isCvvRequired:r.computed((function(){return i.value})),loadAvailableMethods:function(t,r,s){return o(void 0,void 0,void 0,(function(){var o,l;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,2,,3]),[4,P({reference:t,email:r,products:s})];case 1:return o=u.sent(),n.value=function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),a=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,i=o.length;u<i;u++,a++)r[a]=o[u];return r}(o.data.apms,[{name:"card"}]),a.value=o.data.id,o.data.payment_settings&&"cvv_required"in o.data.payment_settings&&(i.value=o.data.payment_settings.cvv_required),[2,o.data];case 2:return l=u.sent(),e.value=l,[2,null];case 3:return[2]}}))}))},initForm:function(e,t){if(void 0===e&&(e=null),void 0===t&&(t={}),!e||0!==Object.keys(e).length)for(var r=e&&Object.keys(e).length>0,o=0,u=n.value;o<u.length;o++){var i=u[o];if(!r||e[i.name]){var s=t[i.name];switch(i.name){case"card":c(s);break;case"klarna":T(s,i,a.value)}}}},submitCardForm:m,submitKlarnaForm:function(e){return A(e||a.value)},makePayment:function(n){var t=void 0===n?{}:n,r=t.cartId,l=void 0===r?null:r,c=t.email,m=void 0===c?null:c,f=t.contextDataId,p=void 0===f?null:f,y=t.success_url,_=void 0===y?null:y,h=t.failure_url,k=void 0===h?null:h,C=t.secure3d,P=void 0===C||C,b=t.attempt_n3d,T=void 0!==b&&b,A=t.cvv,w=void 0===A?null:A,g=t.reference,D=void 0===g?null:g;return o(void 0,void 0,void 0,(function(){var n,t,r;return u(this,(function(o){switch(o.label){case 0:if(!s.value)return e.value=new Error("Payment method not selected"),[2];if([exports.CkoPaymentType.CREDIT_CARD,exports.CkoPaymentType.SAVED_CARD].includes(s.value)){if(s.value===exports.CkoPaymentType.SAVED_CARD&&i.value&&!w)return e.value=new Error("CVV is required"),[2];n=d,t=v}else if(s.value===exports.CkoPaymentType.KLARNA)n=E,t=x;else if(s.value===exports.CkoPaymentType.PAYPAL)n=I,t=R;else{if(s.value!==exports.CkoPaymentType.SOFORT)return e.value=new Error("Not supported payment method"),[2];n=F,t=N}return e.value=null,[4,n({cartId:l,email:m,success_url:_,failure_url:k,secure3d:P,attempt_n3d:T,cvv:w,reference:D,contextDataId:p||a.value,savePaymentInstrument:O()})];case 1:return r=o.sent(),t.value&&(e.value=t.value),[2,r]}}))}))},setPaymentInstrument:f,setSavePaymentInstrument:K,loadSavePaymentInstrument:O,removePaymentInstrument:p,loadStoredPaymentInstruments:y,removeTransactionToken:_}};
//# sourceMappingURL=index.cjs.js.map

@@ -15,3 +15,3 @@ import e from"axios";import{sharedRef as n}from"@vue-storefront/core";import{computed as t}from"@vue/composition-api";

and limitations under the License.
***************************************************************************** */var r=function(){return(r=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)};function a(e,n,t,r){return new(t||(t=Promise))((function(a,o){function u(e){try{l(r.next(e))}catch(e){o(e)}}function i(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){e.done?a(e.value):new t((function(n){n(e.value)})).then(u,i)}l((r=r.apply(e,n||[])).next())}))}function o(e,n){var t,r,a,o,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(a=u.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){u.label=o[1];break}if(6===o[0]&&u.label<a[1]){u.label=a[1],a=o;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(o);break}a[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(e,u)}catch(e){o=[6,e],r=0}finally{t=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var u,i,l,c=r({},{publicKey:null,ctApiUrl:"https://play-commercetools.cko-playground.ckotech.co/api",tokenizedCardKey:"temporary-tokenized-card",saveInstrumentKey:"save-instrument",card:{style:{},localization:null},klarna:{containerSelector:"#klarna_container"},channels:{},currentChannel:null,ckoSCAenabled:!1}),s={"card-number":{color:"red"},base:{color:"#72757e",fontSize:"19px",minWidth:"60px"},invalid:{color:"red"},placeholder:{base:{color:"black",fontSize:"19px"}}},d=function(e){var n,t,r;if(c.channels[e]){var a=c.channels[e];c.publicKey=a.publicKey,c.card.style=(null===(n=a.card)||void 0===n?void 0:n.style)||s,c.card.localization=(null===(t=a.card)||void 0===t?void 0:t.localization)||null,c.klarna.containerSelector=(null===(r=a.klarna)||void 0===r?void 0:r.containerSelector)||c.klarna.containerSelector,c.tokenizedCardKey=a.tokenizedCardKey||c.tokenizedCardKey,c.saveInstrumentKey=a.saveInstrumentKey||c.saveInstrumentKey,c.ctApiUrl=a.ctApiUrl||c.ctApiUrl,c.currentChannel=e,c.ckoSCAenabled=!!a.ckoSCAenabled}else console.error("[CKO] Requested channel does not exist in the config")},v=function(e){var n=e.channels,t=e.defaultChannel;n[t]?(c.channels=n,d(t)):console.error("[CKO] Bad config provided")},m=function(){return c.publicKey},f=function(){return c.currentChannel},y=function(){return c.tokenizedCardKey},p=function(){return c.saveInstrumentKey},_=function(){return c.ctApiUrl},h=function(){return window.location.origin+"/cko-api"},k=function(){return c.card.style},C=function(){return{crossDomain:!0,headers:{authorization:m()}}},b=function(n){var t=n.reference,u=n.email,i=void 0===u?null:u,l=n.products,c=void 0===l?null:l;return a(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,e.post(_()+"/api/contexts",r(r({reference:t},i?{customer_email:i}:{}),c?{products:c}:{}),C())]}))}))},A=function(n){return a(void 0,void 0,void 0,(function(){return o(this,(function(t){return[2,e.post(_()+"/api/payments",n,C())]}))}))},E=function(n){var t=n.customer_id;return a(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,e.post(h()+"/payment-instruments",{customer_id:t,channel:f()})]}))}))},w=function(n){var t=n.customer_id,r=n.payment_instrument_id;return a(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,e.delete(h()+"/payment-instruments/"+t+"/"+r+"/"+f())]}))}))};!function(e){e[e.NOT_SELECTED=0]="NOT_SELECTED",e[e.CREDIT_CARD=1]="CREDIT_CARD",e[e.SAVED_CARD=2]="SAVED_CARD",e[e.KLARNA=3]="KLARNA",e[e.PAYPAL=4]="PAYPAL",e[e.SOFORT=5]="SOFORT"}(i||(i={})),function(e){e.NO_PREFERENCE="no_preference",e.NO_CHALLENGE_REQUESTED="no_challenge_requested",e.CHALLENGE_REQUESTED="challenge_requested",e.CHALLENGE_REQUESTED_MANDATE="challenge_requested_mandate"}(l||(l={}));var P=function(e){var n=e.context_id,t=e.save_payment_instrument,a=e.secure3d,o=e.attempt_n3d,u=e.success_url,i=e.failure_url,l=e.cvv,c=e.reference,s=e.challenge_indicator3d,d=r(r(r({},a?{enabled:a}:{}),o?{attempt_n3d:o}:{}),s?{challenge_indicator:s}:{});return r(r(r(r(r(r({context_id:n},l?{cvv:l}:{}),t?{save_payment_instrument:t}:{}),0!==Object.keys(d).length?{"3ds":r({},d)}:{}),u?{success_url:u}:{}),i?{failure_url:i}:{}),c?{reference:c}:{})},I=((u={})[i.CREDIT_CARD]=function(e){return r(r({},P(e)),{type:"token",token:e.token})},u[i.SAVED_CARD]=function(e){return r(r({},P(e)),{type:"id",token:e.token})},u[i.KLARNA]=function(e){return r(r({},P(e)),{type:"klarna",token:e.token})},u[i.PAYPAL]=function(e){return r(r({},P(e)),{type:"paypal"})},u[i.SOFORT]=function(e){return r(r({},P(e)),{type:"sofort"})},u),D=function(e,n){return I[e](n)},g=function(){return sessionStorage.getItem(y())},S=function(e){return sessionStorage.setItem(y(),e)},R=function(){return sessionStorage.removeItem(y())},T=function(e){var u=n(!1,"useCkoCard-isCardValid"),s=n(null,"useCkoCard-error"),d=n([],"useCkoCard-storedPaymentInstruments"),v=t((function(){return e.value===i.CREDIT_CARD&&!u.value}));return{error:s,submitDisabled:v,storedPaymentInstruments:d,selectedCardPaymentMethod:t((function(){return e.value})),submitForm:function(){return a(void 0,void 0,void 0,(function(){return o(this,(function(e){return[2,Frames.submitCard()]}))}))},makePayment:function(n){var t=n.cartId,r=n.email,u=n.secure3d,d=n.attempt_n3d,v=n.cvv,m=void 0===v?null:v,f=n.contextDataId,y=void 0===f?null:f,p=n.savePaymentInstrument,_=void 0!==p&&p,h=n.success_url,k=void 0===h?null:h,C=n.failure_url,E=void 0===C?null:C,w=n.reference,P=void 0===w?null:w;return a(void 0,void 0,void 0,(function(){var n,a,v,f,p,h;return o(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,4,,5]),!(n=g()))throw new Error("There is no payment token");return a=void 0,y?[3,2]:[4,b({reference:t,email:r})];case 1:if(a=o.sent(),e.value===i.SAVED_CARD&&a.data.payment_settings&&a.data.payment_settings.cvv_required&&!m)throw new Error("CVV is required");o.label=2;case 2:return v=e.value===i.CREDIT_CARD&&_,f=v&&c.ckoSCAenabled?l.CHALLENGE_REQUESTED_MANDATE:null,[4,A(D(e.value,{token:n,secure3d:u,attempt_n3d:d,cvv:m,reference:P,context_id:y||a.data.id,save_payment_instrument:v,challenge_indicator3d:f,success_url:k||window.location.origin+"/cko/payment-success",failure_url:E||window.location.origin+"/cko/payment-error"}))];case 3:if(p=o.sent(),R(),![200,202].includes(p.status))throw new Error(p.data.error_type);return s.value=null,[2,p];case 4:return h=o.sent(),R(),s.value=h,[2,null];case 5:return[2]}}))}))},initCardForm:function(e){var n=(null==e?void 0:e.localization)||c.card.localization;Frames.init(r(r({publicKey:m(),style:(null==e?void 0:e.style)||k()},n?{localization:n}:{}),{cardValidationChanged:function(){u.value=Frames.isCardValid()},cardTokenized:function(e){var n=e.token;return a(void 0,void 0,void 0,(function(){return o(this,(function(e){return S(n),[2]}))}))},cardTokenizationFailed:function(e){s.value=e,u.value=!1}}))},setTransactionToken:S,loadStoredPaymentInstruments:function(e){return a(void 0,void 0,void 0,(function(){var n,t;return o(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,E({customer_id:e})];case 1:return n=r.sent().data,d.value=n.payment_instruments,[3,3];case 2:return t=r.sent(),s.value=t,[3,3];case 3:return[2]}}))}))},removePaymentInstrument:function(n,t){return a(void 0,void 0,void 0,(function(){var r,a;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,w({customer_id:n,payment_instrument_id:t})];case 1:return o.sent(),r=d.value.find((function(e){return e.payment_instrument_id===t})).id,d.value=d.value.filter((function(e){return e.payment_instrument_id!==t})),r===g()&&(e.value=i.CREDIT_CARD,R()),[3,3];case 2:return a=o.sent(),s.value=a,[3,3];case 3:return[2]}}))}))},setPaymentInstrument:function(n){S(n),e.value=i.SAVED_CARD},removeTransactionToken:R}},K=function(){var e=n(null,"useCkoKlarna-error");return{makePayment:function(n){var t=n.contextDataId,r=n.secure3d,u=n.savePaymentInstrument,l=n.reference,c=void 0===l?null:l,s=n.success_url,d=void 0===s?null:s,v=n.failure_url,m=void 0===v?null:v;return a(void 0,void 0,void 0,(function(){var n,a,l;return o(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,2,,3]),!(n=g()))throw new Error("There is no payment token");return[4,A(D(i.KLARNA,{token:n,context_id:t,secure3d:r,reference:c,save_payment_instrument:u,success_url:d||window.location.origin+"/cko/payment-success",failure_url:m||window.location.origin+"/cko/payment-error"}))];case 1:if(a=o.sent(),R(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 2:return l=o.sent(),R(),e.value=l,[2,null];case 3:return[2]}}))}))},initKlarnaForm:function(e,n,t){Klarna.Payments.init({client_token:n.metadata.details.client_token});var a={options:{container:(null==e?void 0:e.containerSelector)||c.klarna.containerSelector,payment_method_categories:n.metadata.details.payment_method_category.map((function(e){return e.identifier})),instance_id:t},data:n.metadata.session},o=(null==e?void 0:e.beforeLoad)?e.beforeLoad(r({apm:n},a)):a,u=o.options,i=o.data;Klarna.Payments.load(u,i)},submitForm:function(e){return new Promise((function(n,t){try{Klarna.Payments.authorize({instance_id:e},{},(function(e){S(e.authorization_token),n(e)}))}catch(e){t(e)}}))},error:e}},x=function(e){localStorage.setItem(p(),JSON.stringify(e))},O=function(){var e=localStorage.getItem(p());return!!e&&JSON.parse(e)},L=function(){var e=n(null,"useCko-error"),r=n([],"useCko-availableMethods"),u=n(null,"useCko-contextId"),l=n(!1,"useCko-requiresCvv"),c=n(i.NOT_SELECTED,"useCko-selectedPaymentMethod"),s=T(c),d=s.initCardForm,v=s.makePayment,m=s.error,f=s.submitForm,y=s.setPaymentInstrument,p=s.removePaymentInstrument,_=s.loadStoredPaymentInstruments,h=s.removeTransactionToken,k=s.storedPaymentInstruments,C=s.submitDisabled,E=K(),w=E.initKlarnaForm,P=E.submitForm,I=E.makePayment,g=E.error,S=function(){var e=n(null,"useCkoPaypal-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,u=n.secure3d,l=n.contextDataId,c=void 0===l?null:l,s=n.savePaymentInstrument,d=void 0!==s&&s,v=n.success_url,m=void 0===v?null:v,f=n.failure_url,y=void 0===f?null:f,p=n.reference,_=void 0===p?null:p;return a(void 0,void 0,void 0,(function(){var n,a,l;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),n=void 0,c?[3,2]:[4,b({reference:t,email:r})];case 1:n=o.sent(),o.label=2;case 2:return[4,A(D(i.PAYPAL,{secure3d:u,reference:_,context_id:c||n.data.id,save_payment_instrument:d,success_url:m||window.location.origin+"/cko/payment-success",failure_url:y||window.location.origin+"/cko/payment-error"}))];case 3:if(a=o.sent(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 4:return l=o.sent(),e.value=l,[2,null];case 5:return[2]}}))}))}}}(),R=S.makePayment,L=S.error,F=function(){var e=n(null,"useCkoSofort-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,u=n.contextDataId,l=void 0===u?null:u,c=n.success_url,s=void 0===c?null:c,d=n.failure_url,v=void 0===d?null:d,m=n.reference,f=void 0===m?null:m;return a(void 0,void 0,void 0,(function(){var n,a,u;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),n=void 0,l?[3,2]:[4,b({reference:t,email:r})];case 1:n=o.sent(),o.label=2;case 2:return[4,A(D(i.SOFORT,{reference:f,context_id:l||n.data.id,success_url:s||window.location.origin+"/cko/payment-success",failure_url:v||window.location.origin+"/cko/payment-error"}))];case 3:if(a=o.sent(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 4:return u=o.sent(),e.value=u,[2,null];case 5:return[2]}}))}))}}}(),N=F.makePayment,z=F.error;return{availableMethods:r,error:e,selectedPaymentMethod:c,storedPaymentInstruments:k,submitDisabled:C,storedContextId:t((function(){return u.value})),isCvvRequired:t((function(){return l.value})),loadAvailableMethods:function(n,t,i){return a(void 0,void 0,void 0,(function(){var a,c;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,b({reference:n,email:t,products:i})];case 1:return a=o.sent(),r.value=function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),a=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,i=o.length;u<i;u++,a++)r[a]=o[u];return r}(a.data.apms,[{name:"card"}]),u.value=a.data.id,a.data.payment_settings&&"cvv_required"in a.data.payment_settings&&(l.value=a.data.payment_settings.cvv_required),[2,a.data];case 2:return c=o.sent(),e.value=c,[2,null];case 3:return[2]}}))}))},initForm:function(e,n){if(void 0===e&&(e=null),void 0===n&&(n={}),!e||0!==Object.keys(e).length)for(var t=e&&Object.keys(e).length>0,a=0,o=r.value;a<o.length;a++){var i=o[a];if(!t||e[i.name]){var l=n[i.name];switch(i.name){case"card":d(l);break;case"klarna":w(l,i,u.value)}}}},submitCardForm:f,submitKlarnaForm:function(e){return P(e||u.value)},makePayment:function(n){var t=void 0===n?{}:n,r=t.cartId,s=void 0===r?null:r,d=t.email,f=void 0===d?null:d,y=t.contextDataId,p=void 0===y?null:y,_=t.success_url,h=void 0===_?null:_,k=t.failure_url,C=void 0===k?null:k,b=t.secure3d,A=void 0===b||b,E=t.attempt_n3d,w=void 0!==E&&E,P=t.cvv,D=void 0===P?null:P,S=t.reference,T=void 0===S?null:S;return a(void 0,void 0,void 0,(function(){var n,t,r;return o(this,(function(a){switch(a.label){case 0:if(!c.value)return e.value=new Error("Payment method not selected"),[2];if([i.CREDIT_CARD,i.SAVED_CARD].includes(c.value)){if(c.value===i.SAVED_CARD&&l.value&&!D)return e.value=new Error("CVV is required"),[2];n=v,t=m}else if(c.value===i.KLARNA)n=I,t=g;else if(c.value===i.PAYPAL)n=R,t=L;else{if(c.value!==i.SOFORT)return e.value=new Error("Not supported payment method"),[2];n=N,t=z}return e.value=null,[4,n({cartId:s,email:f,success_url:h,failure_url:C,secure3d:A,attempt_n3d:w,cvv:D,reference:T,contextDataId:p||u.value,savePaymentInstrument:O()})];case 1:return r=a.sent(),t.value&&(e.value=t.value),[2,r]}}))}))},setPaymentInstrument:y,setSavePaymentInstrument:x,loadSavePaymentInstrument:O,removePaymentInstrument:p,loadStoredPaymentInstruments:_,removeTransactionToken:h}};export{l as CkoChallengeIndicatorType,i as CkoPaymentType,_ as getApiUrl,k as getFramesStyles,m as getPublicKey,d as setChannel,v as setup,L as useCko};
***************************************************************************** */var r=function(){return(r=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)};function a(e,n,t,r){return new(t||(t=Promise))((function(a,o){function u(e){try{l(r.next(e))}catch(e){o(e)}}function i(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){e.done?a(e.value):new t((function(n){n(e.value)})).then(u,i)}l((r=r.apply(e,n||[])).next())}))}function o(e,n){var t,r,a,o,u={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(a=u.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){u.label=o[1];break}if(6===o[0]&&u.label<a[1]){u.label=a[1],a=o;break}if(a&&u.label<a[2]){u.label=a[2],u.ops.push(o);break}a[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(e,u)}catch(e){o=[6,e],r=0}finally{t=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,i])}}}var u,i,l,c=r({},{publicKey:null,ctApiUrl:"https://play-commercetools.cko-playground.ckotech.co/api",tokenizedCardKey:"temporary-tokenized-card",saveInstrumentKey:"save-instrument",card:{style:{},localization:null},klarna:{containerSelector:"#klarna_container"},channels:{},currentChannel:null,ckoSCAenabled:!1}),s={"card-number":{color:"red"},base:{color:"#72757e",fontSize:"19px",minWidth:"60px"},invalid:{color:"red"},placeholder:{base:{color:"black",fontSize:"19px"}}},d=function(e){var n,t,r;if(c.channels[e]){var a=c.channels[e];c.publicKey=a.publicKey,c.card.style=(null===(n=a.card)||void 0===n?void 0:n.style)||s,c.card.localization=(null===(t=a.card)||void 0===t?void 0:t.localization)||null,c.klarna.containerSelector=(null===(r=a.klarna)||void 0===r?void 0:r.containerSelector)||c.klarna.containerSelector,c.tokenizedCardKey=a.tokenizedCardKey||c.tokenizedCardKey,c.saveInstrumentKey=a.saveInstrumentKey||c.saveInstrumentKey,c.ctApiUrl=a.ctApiUrl||c.ctApiUrl,c.currentChannel=e,c.ckoSCAenabled=!!a.ckoSCAenabled}else console.error("[CKO] Requested channel does not exist in the config")},v=function(e){var n=e.channels,t=e.defaultChannel;n[t]?(c.channels=n,d(t)):console.error("[CKO] Bad config provided")},m=function(){return c.publicKey},f=function(){return c.currentChannel},y=function(){return c.tokenizedCardKey},p=function(){return c.saveInstrumentKey},_=function(){return c.ctApiUrl},h=function(){return window.location.origin+"/cko-api"},k=function(){return c.card.style},C=function(){return{crossDomain:!0,headers:{authorization:m()}}},b=function(n){var t=n.reference,u=n.email,i=void 0===u?null:u,l=n.products,c=void 0===l?null:l;return a(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,e.post(_()+"/api/contexts",r(r({reference:t},i?{customer_email:i}:{}),c?{products:c}:{}),C())]}))}))},A=function(n){return a(void 0,void 0,void 0,(function(){return o(this,(function(t){return[2,e.post(_()+"/api/payments",n,C())]}))}))},E=function(n){var t=n.customer_id;return a(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,e.post(h()+"/payment-instruments",{customer_id:t,channel:f()})]}))}))},w=function(n){var t=n.customer_id,r=n.payment_instrument_id;return a(void 0,void 0,void 0,(function(){return o(this,(function(n){return[2,e.delete(h()+"/payment-instruments/"+t+"/"+r+"/"+f())]}))}))};!function(e){e[e.NOT_SELECTED=0]="NOT_SELECTED",e[e.CREDIT_CARD=1]="CREDIT_CARD",e[e.SAVED_CARD=2]="SAVED_CARD",e[e.KLARNA=3]="KLARNA",e[e.PAYPAL=4]="PAYPAL",e[e.SOFORT=5]="SOFORT"}(i||(i={})),function(e){e.NO_PREFERENCE="no_preference",e.NO_CHALLENGE_REQUESTED="no_challenge_requested",e.CHALLENGE_REQUESTED="challenge_requested",e.CHALLENGE_REQUESTED_MANDATE="challenge_requested_mandate"}(l||(l={}));var P=function(e){var n=e.context_id,t=e.save_payment_instrument,a=e.secure3d,o=e.attempt_n3d,u=e.success_url,i=e.failure_url,l=e.cvv,c=e.reference,s=e.challenge_indicator3d,d=r(r(r({},a?{enabled:a}:{}),o?{attempt_n3d:o}:{}),s?{challenge_indicator:s}:{});return r(r(r(r(r(r({context_id:n},l?{cvv:l}:{}),t?{save_payment_instrument:t}:{}),0!==Object.keys(d).length?{"3ds":r({},d)}:{}),u?{success_url:u}:{}),i?{failure_url:i}:{}),c?{reference:c}:{})},I=((u={})[i.CREDIT_CARD]=function(e){return r(r({},P(e)),{type:"token",token:e.token})},u[i.SAVED_CARD]=function(e){return r(r({},P(e)),{type:"id",token:e.token})},u[i.KLARNA]=function(e){return r(r({},P(e)),{type:"klarna",token:e.token})},u[i.PAYPAL]=function(e){return r(r({},P(e)),{type:"paypal"})},u[i.SOFORT]=function(e){return r(r({},P(e)),{type:"sofort"})},u),D=function(e,n){return I[e](n)},g=function(){return sessionStorage.getItem(y())},S=function(e){return sessionStorage.setItem(y(),e)},R=function(){return sessionStorage.removeItem(y())},T=function(e){var u=n(!1,"useCkoCard-isCardValid"),s=n(null,"useCkoCard-error"),d=n([],"useCkoCard-storedPaymentInstruments"),v=t((function(){return e.value===i.CREDIT_CARD&&!u.value}));return{error:s,submitDisabled:v,storedPaymentInstruments:d,selectedCardPaymentMethod:t((function(){return e.value})),submitForm:function(){return a(void 0,void 0,void 0,(function(){return o(this,(function(e){return[2,Frames.submitCard()]}))}))},makePayment:function(n){var t=n.cartId,r=n.email,u=n.secure3d,d=n.attempt_n3d,v=n.cvv,m=void 0===v?null:v,f=n.contextDataId,y=void 0===f?null:f,p=n.savePaymentInstrument,_=void 0!==p&&p,h=n.success_url,k=void 0===h?null:h,C=n.failure_url,E=void 0===C?null:C,w=n.reference,P=void 0===w?null:w;return a(void 0,void 0,void 0,(function(){var n,a,v,f,p,h;return o(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,4,,5]),!(n=g()))throw new Error("There is no payment token");return a=void 0,y?[3,2]:[4,b({reference:t,email:r})];case 1:if(a=o.sent(),e.value===i.SAVED_CARD&&a.data.payment_settings&&a.data.payment_settings.cvv_required&&!m)throw new Error("CVV is required");o.label=2;case 2:return v=e.value===i.CREDIT_CARD&&_,f=v&&c.ckoSCAenabled?l.CHALLENGE_REQUESTED_MANDATE:null,[4,A(D(e.value,{token:n,secure3d:u,attempt_n3d:d,cvv:m,reference:P,context_id:y||a.data.id,save_payment_instrument:v,challenge_indicator3d:f,success_url:k||window.location.origin+"/cko/payment-success",failure_url:E||window.location.origin+"/cko/payment-error"}))];case 3:if(p=o.sent(),R(),![200,202].includes(p.status))throw new Error(p.data.error_type);return s.value=null,[2,p];case 4:return h=o.sent(),R(),s.value=h,[2,null];case 5:return[2]}}))}))},initCardForm:function(e){var n=(null==e?void 0:e.localization)||c.card.localization;Frames.init(r(r({publicKey:m(),style:(null==e?void 0:e.style)||k()},n?{localization:n}:{}),{cardValidationChanged:function(){u.value=Frames.isCardValid()},cardTokenized:function(e){var n=e.token;return a(void 0,void 0,void 0,(function(){return o(this,(function(e){return S(n),[2]}))}))},cardTokenizationFailed:function(e){s.value=e,u.value=!1}}))},setTransactionToken:S,loadStoredPaymentInstruments:function(e){return a(void 0,void 0,void 0,(function(){var n,t;return o(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,E({customer_id:e})];case 1:return n=r.sent().data,d.value=n.payment_instruments,[3,3];case 2:return t=r.sent(),s.value=t,[3,3];case 3:return[2]}}))}))},removePaymentInstrument:function(n,t){return a(void 0,void 0,void 0,(function(){var r,a;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,w({customer_id:n,payment_instrument_id:t})];case 1:return o.sent(),r=d.value.find((function(e){return e.payment_instrument_id===t})).id,d.value=d.value.filter((function(e){return e.payment_instrument_id!==t})),r===g()&&(e.value=i.CREDIT_CARD,R()),[3,3];case 2:return a=o.sent(),s.value=a,[3,3];case 3:return[2]}}))}))},setPaymentInstrument:function(n){S(n),e.value=i.SAVED_CARD},removeTransactionToken:R}},K=function(){var e=n(null,"useCkoKlarna-error");return{makePayment:function(n){var t=n.contextDataId,r=n.secure3d,u=n.savePaymentInstrument,l=n.reference,c=void 0===l?null:l,s=n.success_url,d=void 0===s?null:s,v=n.failure_url,m=void 0===v?null:v;return a(void 0,void 0,void 0,(function(){var n,a,l;return o(this,(function(o){switch(o.label){case 0:if(o.trys.push([0,2,,3]),!(n=g()))throw new Error("There is no payment token");return[4,A(D(i.KLARNA,{token:n,context_id:t,secure3d:r,reference:c,save_payment_instrument:u,success_url:d||window.location.origin+"/cko/payment-success",failure_url:m||window.location.origin+"/cko/payment-error"}))];case 1:if(a=o.sent(),R(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 2:return l=o.sent(),R(),e.value=l,[2,null];case 3:return[2]}}))}))},initKlarnaForm:function(e,n,t){Klarna.Payments.init({client_token:n.metadata.details.client_token});var a={options:{container:(null==e?void 0:e.containerSelector)||c.klarna.containerSelector,payment_method_categories:n.metadata.details.payment_method_category.map((function(e){return e.identifier})),instance_id:t},data:n.metadata.session},o=(null==e?void 0:e.beforeLoad)?e.beforeLoad(r({apm:n},a)):a,u=o.options,i=o.data;Klarna.Payments.load(u,i)},submitForm:function(e){return new Promise((function(n,t){try{Klarna.Payments.authorize({instance_id:e},{},(function(e){S(e.authorization_token),n(e)}))}catch(e){t(e)}}))},error:e}},x=function(e){localStorage.setItem(p(),JSON.stringify(e))},O=function(){var e=localStorage.getItem(p());return!!e&&JSON.parse(e)},L=function(){var e=n(null,"useCko-error"),r=n([],"useCko-availableMethods"),u=n(null,"useCko-contextId"),l=n(!1,"useCko-requiresCvv"),c=n(i.NOT_SELECTED,"useCko-selectedPaymentMethod"),s=T(c),d=s.initCardForm,v=s.makePayment,m=s.error,f=s.submitForm,y=s.setPaymentInstrument,p=s.removePaymentInstrument,_=s.loadStoredPaymentInstruments,h=s.removeTransactionToken,k=s.storedPaymentInstruments,C=s.submitDisabled,E=K(),w=E.initKlarnaForm,P=E.submitForm,I=E.makePayment,g=E.error,S=function(){var e=n(null,"useCkoPaypal-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,u=n.secure3d,l=n.contextDataId,c=void 0===l?null:l,s=n.savePaymentInstrument,d=void 0!==s&&s,v=n.success_url,m=void 0===v?null:v,f=n.failure_url,y=void 0===f?null:f,p=n.reference,_=void 0===p?null:p;return a(void 0,void 0,void 0,(function(){var n,a,l;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),n=void 0,c?[3,2]:[4,b({reference:t,email:r})];case 1:n=o.sent(),o.label=2;case 2:return[4,A(D(i.PAYPAL,{secure3d:u,reference:_,context_id:c||n.data.id,save_payment_instrument:d,success_url:m||window.location.origin+"/cko/payment-success",failure_url:y||window.location.origin+"/cko/payment-error"}))];case 3:if(a=o.sent(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 4:return l=o.sent(),e.value=l,[2,null];case 5:return[2]}}))}))}}}(),R=S.makePayment,L=S.error,F=function(){var e=n(null,"useCkoSofort-error");return{error:e,makePayment:function(n){var t=n.cartId,r=n.email,u=n.contextDataId,l=void 0===u?null:u,c=n.success_url,s=void 0===c?null:c,d=n.failure_url,v=void 0===d?null:d,m=n.reference,f=void 0===m?null:m;return a(void 0,void 0,void 0,(function(){var n,a,u;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),n=void 0,l?[3,2]:[4,b({reference:t,email:r})];case 1:n=o.sent(),o.label=2;case 2:return[4,A(D(i.SOFORT,{reference:f,context_id:l||n.data.id,success_url:s||window.location.origin+"/cko/payment-success",failure_url:v||window.location.origin+"/cko/payment-error"}))];case 3:if(a=o.sent(),![200,202].includes(a.status))throw new Error(a.data.error_type);return e.value=null,[2,a];case 4:return u=o.sent(),e.value=u,[2,null];case 5:return[2]}}))}))}}}(),N=F.makePayment,z=F.error;return{availableMethods:r,error:t((function(){return e.value||m.value||null})),selectedPaymentMethod:c,storedPaymentInstruments:k,submitDisabled:C,storedContextId:t((function(){return u.value})),isCvvRequired:t((function(){return l.value})),loadAvailableMethods:function(n,t,i){return a(void 0,void 0,void 0,(function(){var a,c;return o(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,b({reference:n,email:t,products:i})];case 1:return a=o.sent(),r.value=function(){for(var e=0,n=0,t=arguments.length;n<t;n++)e+=arguments[n].length;var r=Array(e),a=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,i=o.length;u<i;u++,a++)r[a]=o[u];return r}(a.data.apms,[{name:"card"}]),u.value=a.data.id,a.data.payment_settings&&"cvv_required"in a.data.payment_settings&&(l.value=a.data.payment_settings.cvv_required),[2,a.data];case 2:return c=o.sent(),e.value=c,[2,null];case 3:return[2]}}))}))},initForm:function(e,n){if(void 0===e&&(e=null),void 0===n&&(n={}),!e||0!==Object.keys(e).length)for(var t=e&&Object.keys(e).length>0,a=0,o=r.value;a<o.length;a++){var i=o[a];if(!t||e[i.name]){var l=n[i.name];switch(i.name){case"card":d(l);break;case"klarna":w(l,i,u.value)}}}},submitCardForm:f,submitKlarnaForm:function(e){return P(e||u.value)},makePayment:function(n){var t=void 0===n?{}:n,r=t.cartId,s=void 0===r?null:r,d=t.email,f=void 0===d?null:d,y=t.contextDataId,p=void 0===y?null:y,_=t.success_url,h=void 0===_?null:_,k=t.failure_url,C=void 0===k?null:k,b=t.secure3d,A=void 0===b||b,E=t.attempt_n3d,w=void 0!==E&&E,P=t.cvv,D=void 0===P?null:P,S=t.reference,T=void 0===S?null:S;return a(void 0,void 0,void 0,(function(){var n,t,r;return o(this,(function(a){switch(a.label){case 0:if(!c.value)return e.value=new Error("Payment method not selected"),[2];if([i.CREDIT_CARD,i.SAVED_CARD].includes(c.value)){if(c.value===i.SAVED_CARD&&l.value&&!D)return e.value=new Error("CVV is required"),[2];n=v,t=m}else if(c.value===i.KLARNA)n=I,t=g;else if(c.value===i.PAYPAL)n=R,t=L;else{if(c.value!==i.SOFORT)return e.value=new Error("Not supported payment method"),[2];n=N,t=z}return e.value=null,[4,n({cartId:s,email:f,success_url:h,failure_url:C,secure3d:A,attempt_n3d:w,cvv:D,reference:T,contextDataId:p||u.value,savePaymentInstrument:O()})];case 1:return r=a.sent(),t.value&&(e.value=t.value),[2,r]}}))}))},setPaymentInstrument:y,setSavePaymentInstrument:x,loadSavePaymentInstrument:O,removePaymentInstrument:p,loadStoredPaymentInstruments:_,removeTransactionToken:h}};export{l as CkoChallengeIndicatorType,i as CkoPaymentType,_ as getApiUrl,k as getFramesStyles,m as getPublicKey,d as setChannel,v as setup,L as useCko};
//# sourceMappingURL=index.es.js.map

@@ -13,3 +13,3 @@ import { CardConfiguration, KlarnaConfiguration } from './configuration';

availableMethods: Ref<any>;
error: Ref<any>;
error: import("@vue/composition-api").ComputedRef<any>;
selectedPaymentMethod: Ref<any>;

@@ -16,0 +16,0 @@ storedPaymentInstruments: Ref<any>;

{
"name": "@vue-storefront/checkout-com",
"version": "0.2.0",
"version": "0.3.0",
"sideEffects": false,

@@ -5,0 +5,0 @@ "main": "lib/index.cjs.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc