UNPKG

@shashank.koppunoori-gokwik/payment-sdk

Version:

Platform-agnostic payment components

2 lines (1 loc) 28.4 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PaymentSDK={})}(this,function(e){"use strict";function t(){}function n(e){return e()}function o(){return Object.create(null)}function s(e){e.forEach(n)}function i(e){return"function"==typeof e}function a(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function r(e,...n){if(null==e){for(const e of n)e(void 0);return t}const o=e.subscribe(...n);return o.unsubscribe?()=>o.unsubscribe():o}function c(e){let t;return r(e,e=>t=e)(),t}function l(e,t){e.appendChild(t)}function u(e,t,n){const o=function(e){if(!e)return document;const t=e.getRootNode?e.getRootNode():e.ownerDocument;if(t&&t.host)return t;return e.ownerDocument}(e);if(!o.getElementById(t)){const e=h("style");e.id=t,e.textContent=n,function(e,t){l(e.head||e,t),t.sheet}(o,e)}}function d(e,t,n){e.insertBefore(t,n||null)}function p(e){e.parentNode&&e.parentNode.removeChild(e)}function h(e){return document.createElement(e)}function m(e){return document.createTextNode(e)}function y(){return m(" ")}function f(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function $(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function b(e,t){t=""+t,e.data!==t&&(e.data=t)}function g(e,t,n){e.classList.toggle(t,!!n)}let v;function w(e){v=e}function P(){if(!v)throw new Error("Function called outside component initialization");return v}function x(){const e=P();return(t,n,{cancelable:o=!1}={})=>{const s=e.$$.callbacks[t];if(s){const i=function(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}(t,n,{cancelable:o});return s.slice().forEach(t=>{t.call(e,i)}),!i.defaultPrevented}return!0}}const k=[],_=[];let I=[];const O=[],L=Promise.resolve();let A=!1;function S(e){I.push(e)}const N=new Set;let M=0;function F(){if(0!==M)return;const e=v;do{try{for(;M<k.length;){const e=k[M];M++,w(e),j(e.$$)}}catch(e){throw k.length=0,M=0,e}for(w(null),k.length=0,M=0;_.length;)_.pop()();for(let e=0;e<I.length;e+=1){const t=I[e];N.has(t)||(N.add(t),t())}I.length=0}while(k.length);for(;O.length;)O.pop()();A=!1,N.clear(),w(e)}function j(e){if(null!==e.fragment){e.update(),s(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(S)}}const D=new Set;let T,C;function E(){T={r:0,c:[],p:T}}function B(){T.r||s(T.c),T=T.p}function W(e,t){e&&e.i&&(D.delete(e),e.i(t))}function U(e,t,n,o){if(e&&e.o){if(D.has(e))return;D.add(e),T.c.push(()=>{D.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function J(e){return void 0!==e?.length?e:Array.from(e)}function q(e,t){U(e,1,1,()=>{t.delete(e.key)})}function z(e,t,o){const{fragment:a,after_update:r}=e.$$;a&&a.m(t,o),S(()=>{const t=e.$$.on_mount.map(n).filter(i);e.$$.on_destroy?e.$$.on_destroy.push(...t):s(t),e.$$.on_mount=[]}),r.forEach(S)}function R(e,t){const n=e.$$;null!==n.fragment&&(!function(e){const t=[],n=[];I.forEach(o=>-1===e.indexOf(o)?t.push(o):n.push(o)),n.forEach(e=>e()),I=t}(n.after_update),s(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function K(e,t){-1===e.$$.dirty[0]&&(k.push(e),A||(A=!0,L.then(F)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function G(e,n,i,a,r,c,l=null,u=[-1]){const d=v;w(e);const h=e.$$={fragment:null,ctx:[],props:c,update:t,not_equal:r,bound:o(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(n.context||(d?d.$$.context:[])),callbacks:o(),dirty:u,skip_bound:!1,root:n.target||d.$$.root};l&&l(h.root);let m=!1;if(h.ctx=i?i(e,n.props||{},(t,n,...o)=>{const s=o.length?o[0]:n;return h.ctx&&r(h.ctx[t],h.ctx[t]=s)&&(!h.skip_bound&&h.bound[t]&&h.bound[t](s),m&&K(e,t)),n}):[],h.update(),m=!0,s(h.before_update),h.fragment=!!a&&a(h.ctx),n.target){if(n.hydrate){const e=function(e){return Array.from(e.childNodes)}(n.target);h.fragment&&h.fragment.l(e),e.forEach(p)}else h.fragment&&h.fragment.c();n.intro&&W(e.$$.fragment),z(e,n.target,n.anchor),F()}w(d)}function H(e,t,n,o){const s=n[e]?.type;if(t="Boolean"===s&&"boolean"!=typeof t?null!=t:t,!o||!n[e])return t;if("toAttribute"===o)switch(s){case"Object":case"Array":return null==t?null:JSON.stringify(t);case"Boolean":return t?"":null;case"Number":return null==t?null:t;default:return t}else switch(s){case"Object":case"Array":return t&&JSON.parse(t);case"Boolean":default:return t;case"Number":return null!=t?+t:t}}function X(e,t,n,o,s,i){let a=class extends C{constructor(){super(e,n,s),this.$$p_d=t}static get observedAttributes(){return Object.keys(t).map(e=>(t[e].attribute||e).toLowerCase())}};return Object.keys(t).forEach(e=>{Object.defineProperty(a.prototype,e,{get(){return this.$$c&&e in this.$$c?this.$$c[e]:this.$$d[e]},set(n){n=H(e,n,t),this.$$d[e]=n,this.$$c?.$set({[e]:n})}})}),o.forEach(e=>{Object.defineProperty(a.prototype,e,{get(){return this.$$c?.[e]}})}),i&&(a=i(a)),e.element=a,a}"function"==typeof HTMLElement&&(C=class extends HTMLElement{$$ctor;$$s;$$c;$$cn=!1;$$d={};$$r=!1;$$p_d={};$$l={};$$l_u=new Map;constructor(e,t,n){super(),this.$$ctor=e,this.$$s=t,n&&this.attachShadow({mode:"open"})}addEventListener(e,t,n){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){const n=this.$$c.$on(e,t);this.$$l_u.set(t,n)}super.addEventListener(e,t,n)}removeEventListener(e,t,n){if(super.removeEventListener(e,t,n),this.$$c){const e=this.$$l_u.get(t);e&&(e(),this.$$l_u.delete(t))}if(this.$$l[e]){const n=this.$$l[e].indexOf(t);n>=0&&this.$$l[e].splice(n,1)}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){if(await Promise.resolve(),!this.$$cn||this.$$c)return;function e(e){return()=>{let t;return{c:function(){t=h("slot"),"default"!==e&&$(t,"name",e)},m:function(e,n){d(e,t,n)},d:function(e){e&&p(t)}}}}const t={},n=function(e){const t={};return e.childNodes.forEach(e=>{t[e.slot||"default"]=!0}),t}(this);for(const s of this.$$s)s in n&&(t[s]=[e(s)]);for(const i of this.attributes){const a=this.$$g_p(i.name);a in this.$$d||(this.$$d[a]=H(a,i.value,this.$$p_d,"toProp"))}for(const r in this.$$p_d)r in this.$$d||void 0===this[r]||(this.$$d[r]=this[r],delete this[r]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const o=()=>{this.$$r=!0;for(const e in this.$$p_d)if(this.$$d[e]=this.$$c.$$.ctx[this.$$c.$$.props[e]],this.$$p_d[e].reflect){const t=H(e,this.$$d[e],this.$$p_d,"toAttribute");null==t?this.removeAttribute(this.$$p_d[e].attribute||e):this.setAttribute(this.$$p_d[e].attribute||e,t)}this.$$r=!1};this.$$c.$$.after_update.push(o),o();for(const c in this.$$l)for(const l of this.$$l[c]){const u=this.$$c.$on(c,l);this.$$l_u.set(l,u)}this.$$l={}}}attributeChangedCallback(e,t,n){this.$$r||(e=this.$$g_p(e),this.$$d[e]=H(e,n,this.$$p_d,"toProp"),this.$$c?.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{!this.$$cn&&this.$$c&&(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});class Q{$$=void 0;$$set=void 0;$destroy(){R(this,1),this.$destroy=t}$on(e,n){if(!i(n))return t;const o=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return o.push(n),()=>{const e=o.indexOf(n);-1!==e&&o.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function V(e){u(e,"svelte-1wd7k9m",".payment-option.svelte-1wd7k9m.svelte-1wd7k9m{width:100%;background:white;border:1px solid #ddd;border-radius:8px;padding:12px;cursor:pointer;font-family:inherit;text-align:left}.payment-option.svelte-1wd7k9m.svelte-1wd7k9m:hover{border-color:#999}.payment-option.selected.svelte-1wd7k9m.svelte-1wd7k9m{border-color:#333}.option-content.svelte-1wd7k9m.svelte-1wd7k9m{display:flex;align-items:center;justify-content:space-between;width:100%}.option-text.svelte-1wd7k9m.svelte-1wd7k9m{display:flex;flex-direction:column}.title.svelte-1wd7k9m.svelte-1wd7k9m{font-weight:600;font-size:16px;color:#333;margin-bottom:4px}.subtitle.svelte-1wd7k9m.svelte-1wd7k9m{font-size:12px;color:#666}.arrow.svelte-1wd7k9m.svelte-1wd7k9m{color:#666;font-size:18px}.payment-option.selected.svelte-1wd7k9m .arrow.svelte-1wd7k9m{color:#333}")}function Z(e){let t,n;return{c(){t=h("div"),n=m(e[1]),$(t,"class","subtitle svelte-1wd7k9m")},m(e,o){d(e,t,o),l(t,n)},p(e,t){2&t&&b(n,e[1])},d(e){e&&p(t)}}}function Y(e){let n,o,s,i,a,r,c,u,v,w,P=e[1]&&Z(e);return{c(){n=h("button"),o=h("div"),s=h("div"),i=h("div"),a=m(e[0]),r=y(),P&&P.c(),c=y(),u=h("div"),u.textContent="→",$(i,"class","title svelte-1wd7k9m"),$(s,"class","option-text svelte-1wd7k9m"),$(u,"class","arrow svelte-1wd7k9m"),$(o,"class","option-content svelte-1wd7k9m"),$(n,"class","payment-option svelte-1wd7k9m"),g(n,"selected",e[2])},m(t,p){d(t,n,p),l(n,o),l(o,s),l(s,i),l(i,a),l(s,r),P&&P.m(s,null),l(o,c),l(o,u),v||(w=f(n,"click",e[3]),v=!0)},p(e,[t]){1&t&&b(a,e[0]),e[1]?P?P.p(e,t):(P=Z(e),P.c(),P.m(s,null)):P&&(P.d(1),P=null),4&t&&g(n,"selected",e[2])},i:t,o:t,d(e){e&&p(n),P&&P.d(),v=!1,w()}}}function ee(e,t,n){let{title:o=""}=t,{subtitle:s=""}=t,{name:i=""}=t,{selected:a=!1}=t;const r=x();return e.$$set=e=>{"title"in e&&n(0,o=e.title),"subtitle"in e&&n(1,s=e.subtitle),"name"in e&&n(4,i=e.name),"selected"in e&&n(2,a=e.selected)},[o,s,a,()=>{r("select",{name:i})},i]}"undefined"!=typeof window&&(window.__svelte||(window.__svelte={v:new Set})).v.add("4");class te extends Q{constructor(e){super(),G(this,e,ee,Y,a,{title:0,subtitle:1,name:4,selected:2},V)}get title(){return this.$$.ctx[0]}set title(e){this.$$set({title:e}),F()}get subtitle(){return this.$$.ctx[1]}set subtitle(e){this.$$set({subtitle:e}),F()}get name(){return this.$$.ctx[4]}set name(e){this.$$set({name:e}),F()}get selected(){return this.$$.ctx[2]}set selected(e){this.$$set({selected:e}),F()}}X(te,{title:{},subtitle:{},name:{},selected:{type:"Boolean"}},[],[],!0);const ne=[];function oe(e,n=t){let o;const s=new Set;function i(t){if(a(e,t)&&(e=t,o)){const t=!ne.length;for(const t of s)t[1](),ne.push(t,e);if(t){for(let e=0;e<ne.length;e+=2)ne[e][0](ne[e+1]);ne.length=0}}}function r(t){i(t(e))}return{set:i,update:r,subscribe:function(a,c=t){const l=[a,c];return s.add(l),1===s.size&&(o=n(i,r)||t),a(e),()=>{s.delete(l),0===s.size&&o&&(o(),o=null)}}}}const se=oe("eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..WWBIB-vtElLp8Slk.bo9LHpgK8_Fne4iLXLn9pMTJxBKhrGVc6uOwGANlM9PIgHAQvOkanlx_sneoj1AQw-JWsI19WM54PLa9XNV9jXzp0bLaOFU-5Bm8SDnLZ8Sc6Tq26wwNFBjLiclI.LSplu1Bfv4uy9n5vRLIXqw"),ie=oe({merchantId:"19g6ilix86if5",phoneNumber:9890330939,requestId:"5ce31837-cfb2-4d0a-a1b8-a88b313bbdfc",accessToken:"eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..WWBIB-vtElLp8Slk.bo9LHpgK8_Fne4iLXLn9pMTJxBKhrGVc6uOwGANlM9PIgHAQvOkanlx_sneoj1AQw-JWsI19WM54PLa9XNV9jXzp0bLaOFU-5Bm8SDnLZ8Sc6Tq26wwNFBjLiclI.LSplu1Bfv4uy9n5vRLIXqw",aid:"30428",cartId:276194,cart_sub_total:16e4,device:"mobile",isAbandonCart:!1,loader:!0}),ae=oe({orig_referrer:"https://qatwo-gokwik.myshopify.com/",referer:"https://qatwo.pdp.gokwik.co/",shopifysessionid:"f19d139b-2781-48d9-94f2-c518616fa535","x-gokwik-token":"eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..WWBIB-vtElLp8Slk.bo9LHpgK8_Fne4iLXLn9pMTJxBKhrGVc6uOwGANlM9PIgHAQvOkanlx_sneoj1AQw-JWsI19WM54PLa9XNV9jXzp0bLaOFU-5Bm8SDnLZ8Sc6Tq26wwNFBjLiclI.LSplu1Bfv4uy9n5vRLIXqw","x-gokwik-initiator":"core_shopify"}),re=oe(""),ce=oe(),le=oe(!1);async function ue(e,t={}){const n=c(se),o=c(ae)||{};if(!n)throw new Error("API_NOT_INITIALIZED");try{const s=await fetch(`https://api-gw-v4.dev.gokwik.io/qa/replica${e}`,{...t,headers:{"Content-Type":"application/json","x-gokwik-token":n,"x-gokwik-initiator":"core_shopify",...o}}),i=await s.json();if(!s.ok)throw new Error("error");return i}catch(e){throw new Error("UNKNOWN_ERROR")}}let de={onPaymentInitiate:void 0,onPaymentSuccess:void 0,onPaymentFailure:void 0,onPaymentCancel:void 0,onMethodSelect:void 0};const pe=e=>{console.log({uLink:e}),e.replace("upi://pay?","phonepe://pay?"),window.location.href=e},he=e=>{console.log({redirectUrl:e});const t=window.open();t?(console.log("Opened a new tab"),t.location=e):console.log("Failed to open a new tab")},me=(e,t=1e4,n={})=>{(async function(e={}){const{phoneNumber:t}=c(ie);let n={auth_token:c(se),order_type:c(re),phone:t,gokwik_oid:c(ce)};e?.gokwik_oid&&(n=e);return await ue("/v1/payment/capture",{method:"POST",body:JSON.stringify(n)}).then(e=>e)})(n).then(e=>{console.log("capture response - ",e),200===e.statusCode?ye(e):405!==e.statusCode&&400!==e.statusCode||console.log({name:"payment_capture_failed_status_code",eventType:"click",type:"event"})}).catch(()=>{console.log({eventName:"CAPTURE FAILURE"})})};const ye=e=>{e.data&&("order_retry"===e.data?.order_state&&console.log("processCatpureData: Order Retry"),"PAID"===e.data.payment_status?(de?.onPaymentSuccess&&de?.onPaymentSuccess({message:"payment-success",data:e}),console.log("processCatpureData: PAID")):"PENDING"===e.data.payment_status?console.log("processCatpureData: PENDING"):"PAYMENT FAILED"===e.data.payment_status&&console.log("processCatpureData: PAYMENT FAILED"))};function fe(e){u(e,"svelte-1nuc85y",'.payment-page.svelte-1nuc85y.svelte-1nuc85y{font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,\n sans-serif;max-width:480px;position:relative;border-radius:8px;overflow:hidden}.loading.svelte-1nuc85y.svelte-1nuc85y,.error.svelte-1nuc85y.svelte-1nuc85y{padding:40px;text-align:center}.spinner.svelte-1nuc85y.svelte-1nuc85y{width:40px;height:40px;margin:0 auto 20px;border:3px solid #f3f3f3;border-top:3px solid #333;border-radius:50%;animation:svelte-1nuc85y-spin 1s linear infinite}@keyframes svelte-1nuc85y-spin{to{transform:rotate(360deg)}}.error.svelte-1nuc85y button.svelte-1nuc85y{margin-top:16px;padding:8px 24px;background:#333;color:white;border:none;border-radius:4px;cursor:pointer}.methods-section.svelte-1nuc85y h3.svelte-1nuc85y{margin:0 0 16px;font-size:16px;font-weight:600;color:#333}.payment-methods.svelte-1nuc85y.svelte-1nuc85y{display:flex;flex-direction:column;gap:8px}.action-section.svelte-1nuc85y.svelte-1nuc85y{margin-top:24px;padding-top:24px;border-top:1px solid #eee}.pay-button.svelte-1nuc85y.svelte-1nuc85y{width:100%;padding:16px;background:#333;color:white;border:none;border-radius:8px;font-size:16px;font-weight:600;cursor:pointer;transition:background 0.2s}.pay-button.svelte-1nuc85y.svelte-1nuc85y:hover:not(:disabled){background:#222}.pay-button.svelte-1nuc85y.svelte-1nuc85y:disabled{background:#ccc;cursor:not-allowed}.processing-overlay.svelte-1nuc85y.svelte-1nuc85y{position:absolute;inset:0;background:rgba(255, 255, 255, 0.95);display:flex;align-items:center;justify-content:center;z-index:100}.processing-content.svelte-1nuc85y.svelte-1nuc85y{text-align:center}.processing-content.svelte-1nuc85y p.svelte-1nuc85y{margin:16px 0 8px;font-weight:500}.processing-content.svelte-1nuc85y small.svelte-1nuc85y{color:#666}')}function $e(e,t,n){const o=e.slice();return o[27]=t[n],o}function be(e){let t,n,o,i,a,r,c,u=[],m=new Map,f=J(e[6]);const b=e=>e[27].name;for(let t=0;t<f.length;t+=1){let n=$e(e,f,t),o=b(n);m.set(o,u[t]=we(o,n))}let g=e[1]&&Pe(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Select Payment Method",i=y(),a=h("div");for(let e=0;e<u.length;e+=1)u[e].c();r=y(),g&&g.c(),$(o,"class","svelte-1nuc85y"),$(a,"class","payment-methods svelte-1nuc85y"),$(n,"class","methods-section svelte-1nuc85y"),$(t,"class","payment-container svelte-1nuc85y")},m(e,s){d(e,t,s),l(t,n),l(n,o),l(n,i),l(n,a);for(let e=0;e<u.length;e+=1)u[e]&&u[e].m(a,null);l(t,r),g&&g.m(t,null),c=!0},p(e,n){322&n&&(f=J(e[6]),E(),u=function(e,t,n,o,i,a,r,c,l,u,d,p){let h=e.length,m=a.length,y=h;const f={};for(;y--;)f[e[y].key]=y;const $=[],b=new Map,g=new Map,v=[];for(y=m;y--;){const e=p(i,a,y),s=n(e);let c=r.get(s);c?o&&v.push(()=>c.p(e,t)):(c=u(s,e),c.c()),b.set(s,$[y]=c),s in f&&g.set(s,Math.abs(y-f[s]))}const w=new Set,P=new Set;function x(e){W(e,1),e.m(c,d),r.set(e.key,e),d=e.first,m--}for(;h&&m;){const t=$[m-1],n=e[h-1],o=t.key,s=n.key;t===n?(d=t.first,h--,m--):b.has(s)?!r.has(o)||w.has(o)?x(t):P.has(s)?h--:g.get(o)>g.get(s)?(P.add(o),x(t)):(w.add(s),h--):(l(n,r),h--)}for(;h--;){const t=e[h];b.has(t.key)||l(t,r)}for(;m;)x($[m-1]);return s(v),$}(u,n,b,1,e,f,m,a,q,we,null,$e),B()),e[1]?g?g.p(e,n):(g=Pe(e),g.c(),g.m(t,null)):g&&(g.d(1),g=null)},i(e){if(!c){for(let e=0;e<f.length;e+=1)W(u[e]);c=!0}},o(e){for(let e=0;e<u.length;e+=1)U(u[e]);c=!1},d(e){e&&p(t);for(let e=0;e<u.length;e+=1)u[e].d();g&&g.d()}}}function ge(e){let n,o,s,i,a,r,c,u;return{c(){n=h("div"),o=h("p"),s=m("⚠️ "),i=m(e[4]),a=y(),r=h("button"),r.textContent="Retry",$(r,"class","svelte-1nuc85y"),$(n,"class","error svelte-1nuc85y")},m(t,p){d(t,n,p),l(n,o),l(o,s),l(o,i),l(n,a),l(n,r),c||(u=f(r,"click",e[7]),c=!0)},p(e,t){16&t&&b(i,e[4])},i:t,o:t,d(e){e&&p(n),c=!1,u()}}}function ve(e){let n;return{c(){n=h("div"),n.innerHTML='<div class="spinner svelte-1nuc85y"></div> <p>Loading payment methods...</p>',$(n,"class","loading svelte-1nuc85y")},m(e,t){d(e,n,t)},p:t,i:t,o:t,d(e){e&&p(n)}}}function we(e,t){let n,o,s;return o=new te({props:{name:t[27].name,title:t[27].buttonText,subtitle:t[27].subtext||t[27].badgeText,selected:t[1]===t[27].name}}),o.$on("select",t[8]),{key:e,first:null,c(){var e;n=m(""),(e=o.$$.fragment)&&e.c(),this.first=n},m(e,t){d(e,n,t),z(o,e,t),s=!0},p(e,n){t=e;const s={};2&n&&(s.selected=t[1]===t[27].name),o.$set(s)},i(e){s||(W(o.$$.fragment,e),s=!0)},o(e){U(o.$$.fragment,e),s=!1},d(e){e&&p(n),R(o,e)}}}function Pe(e){let t,n,o,s;function i(e,t){return e[3]?ke:xe}let a=i(e),r=a(e);return{c(){t=h("div"),n=h("button"),r.c(),$(n,"class","pay-button svelte-1nuc85y"),n.disabled=e[3],$(t,"class","action-section svelte-1nuc85y")},m(i,a){d(i,t,a),l(t,n),r.m(n,null),o||(s=f(n,"click",e[0]),o=!0)},p(e,t){a===(a=i(e))&&r?r.p(e,t):(r.d(1),r=a(e),r&&(r.c(),r.m(n,null))),8&t&&(n.disabled=e[3])},d(e){e&&p(t),r.d(),o=!1,s()}}}function xe(e){let t,n,o=e[5].subTotal+"";return{c(){t=m("Pay ₹"),n=m(o)},m(e,o){d(e,t,o),d(e,n,o)},p(e,t){32&t&&o!==(o=e[5].subTotal+"")&&b(n,o)},d(e){e&&(p(t),p(n))}}}function ke(e){let n;return{c(){n=m("Processing...")},m(e,t){d(e,n,t)},p:t,d(e){e&&p(n)}}}function _e(e){let t;return{c(){t=h("div"),t.innerHTML='<div class="processing-content svelte-1nuc85y"><div class="spinner svelte-1nuc85y"></div> <p class="svelte-1nuc85y">Processing payment...</p> <small class="svelte-1nuc85y">Please do not close this window</small></div>',$(t,"class","processing-overlay svelte-1nuc85y")},m(e,n){d(e,t,n)},d(e){e&&p(t)}}}function Ie(e){let t,n,o,s,i;const a=[ve,ge,be],r=[];function c(e,t){return e[2]?0:e[4]?1:2}n=c(e),o=r[n]=a[n](e);let u=e[3]&&_e();return{c(){t=h("div"),o.c(),s=y(),u&&u.c(),$(t,"class","payment-page svelte-1nuc85y"),$(t,"data-id","sdfsddfq232131sada2131312")},m(e,o){d(e,t,o),r[n].m(t,null),l(t,s),u&&u.m(t,null),i=!0},p(e,[i]){let l=n;n=c(e),n===l?r[n].p(e,i):(E(),U(r[l],1,1,()=>{r[l]=null}),B(),o=r[n],o?o.p(e,i):(o=r[n]=a[n](e),o.c()),W(o,1),o.m(t,s)),e[3]?u||(u=_e(),u.c(),u.m(t,null)):u&&(u.d(1),u=null)},i(e){i||(W(o),i=!0)},o(e){U(o),i=!1},d(e){e&&p(t),r[n].d(),u&&u.d()}}}function Oe(e,t,n){let o;var s,i;s=ie,i=e=>n(5,o=e),e.$$.on_destroy.push(r(s,i));let{aid:a=0}=t,{amount:l=0}=t,{cartId:u=0}=t,{phone:d=""}=t,{requestId:p=""}=t,{mid:h=""}=t,{osType:m=""}=t,{credParams:y={}}=t,{shipping:f={}}=t,{source:$="direct"}=t,{onPaymentInitiate:b}=t,{onPaymentSuccess:g}=t,{onPaymentFailure:v}=t,{onPaymentCancel:w}=t,{onMethodSelect:k}=t,_=[{discountForBadge:0,prepaidDiscount:0,name:"netbanking",methodType:"netbanking",status:!0,services:[],methodPrice:2420,capped_value:0,prepaidFreebieFound:!1,partnerAcquisitionOfferAmount:600,comparedPrice:0,price:2420,icon:"/assets/icons/new-netbanking.svg",buttonText:"Netbanking",badgeText:"",showAmount:!0,subtext:""},{discountForBadge:0,prepaidDiscount:0,charges:0,name:"upi",methodType:"upi",status:!0,services:[],methodPrice:2420,capped_value:0,prepaidFreebieFound:!1,partnerAcquisitionOfferAmount:600,isCollectFlowSupported:!0,hidePaymentLink:!1,upiData:{preferredPanel:[{logo:"",name:"paytm",prefix:"paytmmp://pay?",btnLabel:"Paytm",enableFor:"All",eventName:"Paytm",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"phonepe",prefix:"phonepe://pay?",btnLabel:"PhonePe",enableFor:"All",eventName:"Phonepe",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"tez",prefix:"tez://upi/pay?",btnLabel:"G Pay",enableFor:"All",eventName:"Google Pay",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"amazonpay",prefix:"amazonpay://upi/pay?",btnLabel:"Amazon Pay",enableFor:"All",eventName:"Amazon Pay",showOnlyWhenDetected:!1},{logo:"",name:"supermoney",prefix:"super://pay?",btnLabel:"Super Money",enableFor:"All",eventName:"Super Money",showOnlyWhenDetected:!1},{logo:"",name:"mobikwik",prefix:"mobikwik://upi/pay?",btnLabel:"MobiKwik UPI",enableFor:"All",eventName:"MobiKwik UPI",showOnlyWhenDetected:!1},{logo:"",name:"bajaj",prefix:"//pay?",btnLabel:"Bajaj Pay UPI",enableFor:"All",eventName:"Bajaj Pay UPI",iOSPrefix:"BajajPayUPI://upi://pay?",showOnlyWhenDetected:!1},{logo:"",name:"credpay",prefix:"//pay?",btnLabel:"CRED UPI",enableFor:"All",eventName:"CRED",iOSPrefix:"credpay://upi/pay?",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"jupiterUpi",prefix:"jupiter://pay?",btnLabel:"Jupiter UPI",enableFor:"All",eventName:"Jupiter UPI",iOSPrefix:"jupiter://pay?",showOnlyWhenDetected:!1},{logo:"",name:"kiwi",prefix:"kiwi://upi/pay?",btnLabel:"Kiwi UPI",enableFor:"All",eventName:"Kiwi UPI",iOSPrefix:"kiwi://upi/pay?",showOnlyWhenDetected:!1},{logo:"",name:"bhim",prefix:"bhim://upi://pay?",btnLabel:"BHIM",enableFor:"iOS",eventName:"BHIM",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"other",prefix:"",btnLabel:"Pay by any UPI app",enableFor:"Android",eventName:"Others",defaultApp:!0,showOnlyWhenDetected:!1}],upiSection:[{logo:"",name:"paytm",prefix:"paytmmp://pay?",btnLabel:"Paytm",enableFor:"All",eventName:"Paytm",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"phonepe",prefix:"phonepe://pay?",btnLabel:"PhonePe",enableFor:"All",eventName:"Phonepe",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"tez",prefix:"tez://upi/pay?",btnLabel:"G Pay",enableFor:"All",eventName:"Google Pay",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"amazonpay",prefix:"amazonpay://upi/pay?",btnLabel:"Amazon Pay",enableFor:"All",eventName:"Amazon Pay",showOnlyWhenDetected:!1},{logo:"",name:"supermoney",prefix:"super://pay?",btnLabel:"Super Money",enableFor:"All",eventName:"Super Money",showOnlyWhenDetected:!1},{logo:"",name:"mobikwik",prefix:"mobikwik://upi/pay?",btnLabel:"MobiKwik UPI",enableFor:"All",eventName:"MobiKwik UPI",showOnlyWhenDetected:!1},{logo:"",name:"bajaj",prefix:"//pay?",btnLabel:"Bajaj Pay UPI",enableFor:"All",eventName:"Bajaj Pay UPI",iOSPrefix:"BajajPayUPI://upi://pay?",showOnlyWhenDetected:!1},{logo:"",name:"credpay",prefix:"//pay?",btnLabel:"CRED UPI",enableFor:"All",eventName:"CRED",iOSPrefix:"credpay://upi/pay?",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"jupiterUpi",prefix:"jupiter://pay?",btnLabel:"Jupiter UPI",enableFor:"All",eventName:"Jupiter UPI",iOSPrefix:"jupiter://pay?",showOnlyWhenDetected:!1},{logo:"",name:"kiwi",prefix:"kiwi://upi/pay?",btnLabel:"Kiwi UPI",enableFor:"All",eventName:"Kiwi UPI",iOSPrefix:"kiwi://upi/pay?",showOnlyWhenDetected:!1},{logo:"",name:"bhim",prefix:"bhim://upi://pay?",btnLabel:"BHIM",enableFor:"iOS",eventName:"BHIM",defaultApp:!0,showOnlyWhenDetected:!1},{logo:"",name:"other",prefix:"",btnLabel:"Pay by any UPI app",enableFor:"Android",eventName:"Others",defaultApp:!0,showOnlyWhenDetected:!1}]},maxUpiFailureClicks:2,shouldTriggerPaymentLink:!0,upiIntentRedirectionWaitTime:1500,comparedPrice:0,price:2420,icon:"/assets/icons/new-upi.svg",buttonText:"UPI",badgeText:"Get cashback",showAmount:!0,subtext:""}],I="",O=!1,L=!1,A="";const S=x();async function N(){n(2,O=!0),n(4,A="")}var M;return M=()=>{},P().$$.on_mount.push(M),e.$$set=e=>{"aid"in e&&n(9,a=e.aid),"amount"in e&&n(10,l=e.amount),"cartId"in e&&n(11,u=e.cartId),"phone"in e&&n(12,d=e.phone),"requestId"in e&&n(13,p=e.requestId),"mid"in e&&n(14,h=e.mid),"osType"in e&&n(15,m=e.osType),"credParams"in e&&n(16,y=e.credParams),"shipping"in e&&n(17,f=e.shipping),"source"in e&&n(18,$=e.source),"onPaymentInitiate"in e&&n(19,b=e.onPaymentInitiate),"onPaymentSuccess"in e&&n(20,g=e.onPaymentSuccess),"onPaymentFailure"in e&&n(21,v=e.onPaymentFailure),"onPaymentCancel"in e&&n(22,w=e.onPaymentCancel),"onMethodSelect"in e&&n(23,k=e.onMethodSelect)},e.$$.update=()=>{var t;16252928&e.$$.dirty&&(t={onPaymentInitiate:b,onPaymentSuccess:g,onPaymentFailure:v,onPaymentCancel:w,onMethodSelect:k},de={...t}),e.$$.dirty,11264&e.$$.dirty&&p&&l&&u&&N()},[async function(){if(!I){const e={code:"NO_METHOD",message:"Please select a payment method"};return void v?.(e)}(async e=>{const t=c(le);t&&(e.gokwik_oid=c(ce));const n=await ue(t?"/v1/order/create/back":"/v1/user/merchant/order/create",{method:"POST",body:JSON.stringify(e)});if(console.log({createOrderRes:n}),de?.onPaymentInitiate&&de.onPaymentInitiate({message:"payment-initiated",data:n}),n&&200===n?.statusCode){le.set(!0);const t=e?.payment_method||"";re.set(t),ce.set(n?.data?.gokwik_oid),"upi"===t?pe(n?.data?.u_link):he(n?.data?.redirect_url),me()}})({cart_id:o.cartId,mid:o.merchantId,os_type:"Mac OS",request_id:o.requestId,aid:o.aid,isAbandonCart:!1,note_attributes:[],source:"direct",notify_customer:!0,cashback_offer_applicable:!1,phone:o.phoneNumber,abc:{},platform:"web",device:"desktop",os:"Mac OS",apps_present:[],cart_sub_total:o.subTotal,order_type:"upi"===I?.toLowerCase()?"upi":"netbanking",payment_method:"upi"===I?.toLowerCase()?"upi":"netbanking",..."upi"===I?{psp_app:"Phonepe"}:{bank_code:"nb-axis"},rto_intervention:{}}),n(3,L=!0);try{if(!_.find(e=>e.buttonText===I))throw new Error("Invalid payment method")}catch(e){n(3,L=!1)}},I,O,L,A,o,_,N,function(e){n(1,I=e.detail.name);const t=_.find(e=>e.name===I);t&&(S("method-selected",{method:t.name}),k?.(t.name))},a,l,u,d,p,h,m,y,f,$,b,g,v,w,k,function(){const e=_.find(e=>e.name===I);return e?.name||null}]}customElements.define("payment-widget",X(class extends Q{constructor(e){super(),G(this,e,Oe,Ie,a,{aid:9,amount:10,cartId:11,phone:12,requestId:13,mid:14,osType:15,credParams:16,shipping:17,source:18,onPaymentInitiate:19,onPaymentSuccess:20,onPaymentFailure:21,onPaymentCancel:22,onMethodSelect:23,processPayment:0,getSelectedMethod:24},fe)}get aid(){return this.$$.ctx[9]}set aid(e){this.$$set({aid:e}),F()}get amount(){return this.$$.ctx[10]}set amount(e){this.$$set({amount:e}),F()}get cartId(){return this.$$.ctx[11]}set cartId(e){this.$$set({cartId:e}),F()}get phone(){return this.$$.ctx[12]}set phone(e){this.$$set({phone:e}),F()}get requestId(){return this.$$.ctx[13]}set requestId(e){this.$$set({requestId:e}),F()}get mid(){return this.$$.ctx[14]}set mid(e){this.$$set({mid:e}),F()}get osType(){return this.$$.ctx[15]}set osType(e){this.$$set({osType:e}),F()}get credParams(){return this.$$.ctx[16]}set credParams(e){this.$$set({credParams:e}),F()}get shipping(){return this.$$.ctx[17]}set shipping(e){this.$$set({shipping:e}),F()}get source(){return this.$$.ctx[18]}set source(e){this.$$set({source:e}),F()}get onPaymentInitiate(){return this.$$.ctx[19]}set onPaymentInitiate(e){this.$$set({onPaymentInitiate:e}),F()}get onPaymentSuccess(){return this.$$.ctx[20]}set onPaymentSuccess(e){this.$$set({onPaymentSuccess:e}),F()}get onPaymentFailure(){return this.$$.ctx[21]}set onPaymentFailure(e){this.$$set({onPaymentFailure:e}),F()}get onPaymentCancel(){return this.$$.ctx[22]}set onPaymentCancel(e){this.$$set({onPaymentCancel:e}),F()}get onMethodSelect(){return this.$$.ctx[23]}set onMethodSelect(e){this.$$set({onMethodSelect:e}),F()}get processPayment(){return this.$$.ctx[0]}get getSelectedMethod(){return this.$$.ctx[24]}},{aid:{},amount:{},cartId:{},phone:{},requestId:{},mid:{},osType:{},credParams:{},shipping:{},source:{},onPaymentInitiate:{},onPaymentSuccess:{},onPaymentFailure:{},onPaymentCancel:{},onMethodSelect:{}},[],["processPayment","getSelectedMethod"],!0));const Le={init:async function(e){const{accessToken:t="",headers:n={}}=e;ie.set(e),se.set(t),ae.set(n),console.log("SDK Initiated")}};e.default=Le,Object.defineProperty(e,"__esModule",{value:!0})});