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
7
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.0.7 to 0.0.8-lc.8

lib/useCkoSofort.d.ts

3

lib/helpers.d.ts

@@ -42,5 +42,6 @@ interface PaymentPropeties {

KLARNA = 3,
PAYPAL = 4
PAYPAL = 4,
SOFORT = 5
}
declare const getCurrentPaymentMethodPayload: (paymentMethod: CkoPaymentType, payload: PaymentPropeties) => any;
export { CkoPaymentType, getCurrentPaymentMethodPayload, PaymentPropeties, PaymentMethodPayload, PaymentInstrument };

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

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

import e from"axios";import{ref as n,computed as t}from"@vue/composition-api";
import e from"axios";import{computed as n,ref as t}from"@vue/composition-api";
/*! *****************************************************************************

@@ -15,3 +15,3 @@ Copyright (c) Microsoft Corporation. All rights reserved.

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

@@ -6,3 +6,2 @@ import path from 'path';

cc: true,
paypal: true,
klarna: false

@@ -9,0 +8,0 @@ };

@@ -30,3 +30,3 @@ const axios = require('axios');

const { data } = await axios.get(
`${getChannelCtApiUrl(channel)}/merchants/${getChannelPublicKey(channel)}/customers/${customerId}`,
`${getChannelCtApiUrl(channel)}/api/merchants/${getChannelPublicKey(channel)}/customers/${customerId}`,
apiRequestHeaders(channel)

@@ -46,3 +46,3 @@ );

return await axios.delete(
`${getChannelCtApiUrl(channel)}/merchants/${getChannelPublicKey(channel)}/customers/${customerId}/payment-instruments/${paymentInstrumentId}`,
`${getChannelCtApiUrl(channel)}/api/merchants/${getChannelPublicKey(channel)}/customers/${customerId}/payment-instruments/${paymentInstrumentId}`,
apiRequestHeaders(channel)

@@ -49,0 +49,0 @@ );

{
"name": "@vue-storefront/checkout-com",
"version": "0.0.7",
"version": "0.0.8-lc.8",
"sideEffects": false,

@@ -11,6 +11,7 @@ "main": "lib/index.cjs.js",

"dev": "rollup -c -w",
"test": "jest"
"test": "jest",
"prepublish": "yarn build"
},
"dependencies": {
"@vue/composition-api": "1.0.0-beta.14",
"@vue/composition-api": "1.0.0-beta.19",
"axios": "^0.19.2",

@@ -17,0 +18,0 @@ "express": "^4.17.1",

@@ -124,3 +124,3 @@ # Checkout.com Nuxt module

```
5. Execute `initForm`. It mounts different payment handlers depends on arguments (check details below). If you are calling it after load component - **use `onMounted` to make sure DOM Element where it should be mounted already exists**. Card's Frames will be mounted in DOM element with class `card-frame`. Caution: PayPal does not need any SDK, we just redirect to their's website like in 3DS redirection process for credit cards. So if you are interested only in this payment method you could omit this step.
5. Execute `initForm`. It mounts different payment handlers depends on arguments (check details below). If you are calling it after load component - **use `onMounted` to make sure DOM Element where it should be mounted already exists**. Card's Frames will be mounted in DOM element with class `card-frame`. Caution: PayPal and Sofort do not need any SDK, we just redirect to their's website like in 3DS redirection process for credit cards. So if you are interested only in this payment method you could omit this step.

@@ -131,3 +131,2 @@ ```ts

klarna?: boolean;
paypal?: boolean;
}

@@ -138,3 +137,2 @@

klarna?: any;
paypal?: any;
}

@@ -198,3 +196,3 @@

12. `payment.data.redirect_url` contains 3DS Auth redirect url for Credit Card if it requires it and it always contain redirect url for the PayPal. You have to support it:
12. `payment.data.redirect_url` contains 3DS Auth redirect url for Credit Card if it requires it and it always contain redirect url for the PayPal and Sofort. You have to support it:
```js

@@ -207,3 +205,3 @@ if (payment.data.redirect_url) {

13. After 3DS Auth/PayPal Auth, user will be redirected to one of these urls. They are being created inside `makePayment` method:
13. After 3DS Auth/PayPal Auth/Sofort Auth, user will be redirected to one of these urls. They are being created inside `makePayment` method:
```js

@@ -274,3 +272,4 @@ success_url: `${window.location.origin}/cko/payment-success`,

KLARNA, // Not supported yet
PAYPAL
PAYPAL,
SOFORT
}

@@ -320,3 +319,3 @@ ```

## Autoloading SDK
Checkout.com supports 3 payment methods - Credit Card, Klarna & Paypal. By default, module fetches SDK only for Credit Card (Frames). You can customize it with module's config `paymentMethods` attribute. E.g:
Checkout.com supports many payment methods, only a few have own SDKs - Credit Card & Klarna. By default, module fetches SDK only for Credit Card (Frames). You can customize it with module's config `paymentMethods` attribute. E.g:
```js

@@ -327,3 +326,2 @@ ['@vue-storefront/checkout-com/nuxt', {

cc: true,
paypal: false,
klarna: true

@@ -330,0 +328,0 @@ }

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