@shashank.koppunoori-gokwik/payment-sdk
Version:
Platform-agnostic payment components
2 lines (1 loc) • 28.1 kB
JavaScript
function e(){}function t(e){return e()}function n(){return Object.create(null)}function o(e){e.forEach(t)}function s(e){return"function"==typeof e}function i(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function a(t,...n){if(null==t){for(const e of n)e(void 0);return e}const o=t.subscribe(...n);return o.unsubscribe?()=>o.unsubscribe():o}function r(e){let t;return a(e,e=>t=e)(),t}function c(e,t){e.appendChild(t)}function l(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=p("style");e.id=t,e.textContent=n,function(e,t){c(e.head||e,t),t.sheet}(o,e)}}function u(e,t,n){e.insertBefore(t,n||null)}function d(e){e.parentNode&&e.parentNode.removeChild(e)}function p(e){return document.createElement(e)}function h(e){return document.createTextNode(e)}function m(){return h(" ")}function y(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 f(e,t){t=""+t,e.data!==t&&(e.data=t)}function b(e,t,n){e.classList.toggle(t,!!n)}let g;function v(e){g=e}function w(){if(!g)throw new Error("Function called outside component initialization");return g}function P(){const e=w();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 x=[],k=[];let I=[];const _=[],O=Promise.resolve();let L=!1;function A(e){I.push(e)}const S=new Set;let N=0;function F(){if(0!==N)return;const e=g;do{try{for(;N<x.length;){const e=x[N];N++,v(e),M(e.$$)}}catch(e){throw x.length=0,N=0,e}for(v(null),x.length=0,N=0;k.length;)k.pop()();for(let e=0;e<I.length;e+=1){const t=I[e];S.has(t)||(S.add(t),t())}I.length=0}while(x.length);for(;_.length;)_.pop()();L=!1,S.clear(),v(e)}function M(e){if(null!==e.fragment){e.update(),o(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(A)}}const D=new Set;let j,C;function E(){j={r:0,c:[],p:j}}function T(){j.r||o(j.c),j=j.p}function B(e,t){e&&e.i&&(D.delete(e),e.i(t))}function W(e,t,n,o){if(e&&e.o){if(D.has(e))return;D.add(e),j.c.push(()=>{D.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function U(e){return void 0!==e?.length?e:Array.from(e)}function J(e,t){W(e,1,1,()=>{t.delete(e.key)})}function q(e,n,i){const{fragment:a,after_update:r}=e.$$;a&&a.m(n,i),A(()=>{const n=e.$$.on_mount.map(t).filter(s);e.$$.on_destroy?e.$$.on_destroy.push(...n):o(n),e.$$.on_mount=[]}),r.forEach(A)}function z(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),o(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function R(e,t){-1===e.$$.dirty[0]&&(x.push(e),L||(L=!0,O.then(F)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function G(t,s,i,a,r,c,l=null,u=[-1]){const p=g;v(t);const h=t.$$={fragment:null,ctx:[],props:c,update:e,not_equal:r,bound:n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(s.context||(p?p.$$.context:[])),callbacks:n(),dirty:u,skip_bound:!1,root:s.target||p.$$.root};l&&l(h.root);let m=!1;if(h.ctx=i?i(t,s.props||{},(e,n,...o)=>{const s=o.length?o[0]:n;return h.ctx&&r(h.ctx[e],h.ctx[e]=s)&&(!h.skip_bound&&h.bound[e]&&h.bound[e](s),m&&R(t,e)),n}):[],h.update(),m=!0,o(h.before_update),h.fragment=!!a&&a(h.ctx),s.target){if(s.hydrate){const e=function(e){return Array.from(e.childNodes)}(s.target);h.fragment&&h.fragment.l(e),e.forEach(d)}else h.fragment&&h.fragment.c();s.intro&&B(t.$$.fragment),q(t,s.target,s.anchor),F()}v(p)}function K(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 H(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=K(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=p("slot"),"default"!==e&&$(t,"name",e)},m:function(e,n){u(e,t,n)},d:function(e){e&&d(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]=K(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=K(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 h=this.$$c.$on(c,l);this.$$l_u.set(l,h)}this.$$l={}}}attributeChangedCallback(e,t,n){this.$$r||(e=this.$$g_p(e),this.$$d[e]=K(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 X{$$=void 0;$$set=void 0;$destroy(){z(this,1),this.$destroy=e}$on(t,n){if(!s(n))return e;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);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 Q(e){l(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 V(e){let t,n;return{c(){t=p("div"),n=h(e[1]),$(t,"class","subtitle svelte-1wd7k9m")},m(e,o){u(e,t,o),c(t,n)},p(e,t){2&t&&f(n,e[1])},d(e){e&&d(t)}}}function Z(t){let n,o,s,i,a,r,l,g,v,w,P=t[1]&&V(t);return{c(){n=p("button"),o=p("div"),s=p("div"),i=p("div"),a=h(t[0]),r=m(),P&&P.c(),l=m(),g=p("div"),g.textContent="→",$(i,"class","title svelte-1wd7k9m"),$(s,"class","option-text svelte-1wd7k9m"),$(g,"class","arrow svelte-1wd7k9m"),$(o,"class","option-content svelte-1wd7k9m"),$(n,"class","payment-option svelte-1wd7k9m"),b(n,"selected",t[2])},m(e,d){u(e,n,d),c(n,o),c(o,s),c(s,i),c(i,a),c(s,r),P&&P.m(s,null),c(o,l),c(o,g),v||(w=y(n,"click",t[3]),v=!0)},p(e,[t]){1&t&&f(a,e[0]),e[1]?P?P.p(e,t):(P=V(e),P.c(),P.m(s,null)):P&&(P.d(1),P=null),4&t&&b(n,"selected",e[2])},i:e,o:e,d(e){e&&d(n),P&&P.d(),v=!1,w()}}}function Y(e,t,n){let{title:o=""}=t,{subtitle:s=""}=t,{name:i=""}=t,{selected:a=!1}=t;const r=P();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 ee extends X{constructor(e){super(),G(this,e,Y,Z,i,{title:0,subtitle:1,name:4,selected:2},Q)}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()}}H(ee,{title:{},subtitle:{},name:{},selected:{type:"Boolean"}},[],[],!0);const te=[];function ne(t,n=e){let o;const s=new Set;function a(e){if(i(t,e)&&(t=e,o)){const e=!te.length;for(const e of s)e[1](),te.push(e,t);if(e){for(let e=0;e<te.length;e+=2)te[e][0](te[e+1]);te.length=0}}}function r(e){a(e(t))}return{set:a,update:r,subscribe:function(i,c=e){const l=[i,c];return s.add(l),1===s.size&&(o=n(a,r)||e),i(t),()=>{s.delete(l),0===s.size&&o&&(o(),o=null)}}}}const oe=ne("eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..WWBIB-vtElLp8Slk.bo9LHpgK8_Fne4iLXLn9pMTJxBKhrGVc6uOwGANlM9PIgHAQvOkanlx_sneoj1AQw-JWsI19WM54PLa9XNV9jXzp0bLaOFU-5Bm8SDnLZ8Sc6Tq26wwNFBjLiclI.LSplu1Bfv4uy9n5vRLIXqw"),se=ne({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}),ie=ne({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"}),ae=ne(""),re=ne(),ce=ne(!1);async function le(e,t={}){const n=r(oe),o=r(ie)||{};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 ue={onPaymentInitiate:void 0,onPaymentSuccess:void 0,onPaymentFailure:void 0,onPaymentCancel:void 0,onMethodSelect:void 0};const de=e=>{console.log({uLink:e}),e.replace("upi://pay?","phonepe://pay?"),window.location.href=e},pe=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")},he=(e,t=1e4,n={})=>{(async function(e={}){const{phoneNumber:t}=r(se);let n={auth_token:r(oe),order_type:r(ae),phone:t,gokwik_oid:r(re)};e?.gokwik_oid&&(n=e);return await le("/v1/payment/capture",{method:"POST",body:JSON.stringify(n)}).then(e=>e)})(n).then(e=>{console.log("capture response - ",e),200===e.statusCode?me(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 me=e=>{e.data&&("order_retry"===e.data?.order_state&&console.log("processCatpureData: Order Retry"),"PAID"===e.data.payment_status?(ue?.onPaymentSuccess&&ue?.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 ye(e){l(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 fe(e){let t,n,s,i,a,r,l,h=[],y=new Map,f=U(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);y.set(o,h[t]=ve(o,n))}let g=e[1]&&we(e);return{c(){t=p("div"),n=p("div"),s=p("h3"),s.textContent="Select Payment Method",i=m(),a=p("div");for(let e=0;e<h.length;e+=1)h[e].c();r=m(),g&&g.c(),$(s,"class","svelte-1nuc85y"),$(a,"class","payment-methods svelte-1nuc85y"),$(n,"class","methods-section svelte-1nuc85y"),$(t,"class","payment-container svelte-1nuc85y")},m(e,o){u(e,t,o),c(t,n),c(n,s),c(n,i),c(n,a);for(let e=0;e<h.length;e+=1)h[e]&&h[e].m(a,null);c(t,r),g&&g.m(t,null),l=!0},p(e,n){322&n&&(f=U(e[6]),E(),h=function(e,t,n,s,i,a,r,c,l,u,d,p){let h=e.length,m=a.length,y=h;const $={};for(;y--;)$[e[y].key]=y;const f=[],b=new Map,g=new Map,v=[];for(y=m;y--;){const e=p(i,a,y),o=n(e);let c=r.get(o);c?s&&v.push(()=>c.p(e,t)):(c=u(o,e),c.c()),b.set(o,f[y]=c),o in $&&g.set(o,Math.abs(y-$[o]))}const w=new Set,P=new Set;function x(e){B(e,1),e.m(c,d),r.set(e.key,e),d=e.first,m--}for(;h&&m;){const t=f[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(f[m-1]);return o(v),f}(h,n,b,1,e,f,y,a,J,ve,null,$e),T()),e[1]?g?g.p(e,n):(g=we(e),g.c(),g.m(t,null)):g&&(g.d(1),g=null)},i(e){if(!l){for(let e=0;e<f.length;e+=1)B(h[e]);l=!0}},o(e){for(let e=0;e<h.length;e+=1)W(h[e]);l=!1},d(e){e&&d(t);for(let e=0;e<h.length;e+=1)h[e].d();g&&g.d()}}}function be(t){let n,o,s,i,a,r,l,b;return{c(){n=p("div"),o=p("p"),s=h("⚠️ "),i=h(t[4]),a=m(),r=p("button"),r.textContent="Retry",$(r,"class","svelte-1nuc85y"),$(n,"class","error svelte-1nuc85y")},m(e,d){u(e,n,d),c(n,o),c(o,s),c(o,i),c(n,a),c(n,r),l||(b=y(r,"click",t[7]),l=!0)},p(e,t){16&t&&f(i,e[4])},i:e,o:e,d(e){e&&d(n),l=!1,b()}}}function ge(t){let n;return{c(){n=p("div"),n.innerHTML='<div class="spinner svelte-1nuc85y"></div> <p>Loading payment methods...</p>',$(n,"class","loading svelte-1nuc85y")},m(e,t){u(e,n,t)},p:e,i:e,o:e,d(e){e&&d(n)}}}function ve(e,t){let n,o,s;return o=new ee({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=h(""),(e=o.$$.fragment)&&e.c(),this.first=n},m(e,t){u(e,n,t),q(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||(B(o.$$.fragment,e),s=!0)},o(e){W(o.$$.fragment,e),s=!1},d(e){e&&d(n),z(o,e)}}}function we(e){let t,n,o,s;function i(e,t){return e[3]?xe:Pe}let a=i(e),r=a(e);return{c(){t=p("div"),n=p("button"),r.c(),$(n,"class","pay-button svelte-1nuc85y"),n.disabled=e[3],$(t,"class","action-section svelte-1nuc85y")},m(i,a){u(i,t,a),c(t,n),r.m(n,null),o||(s=y(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&&d(t),r.d(),o=!1,s()}}}function Pe(e){let t,n,o=e[5].subTotal+"";return{c(){t=h("Pay ₹"),n=h(o)},m(e,o){u(e,t,o),u(e,n,o)},p(e,t){32&t&&o!==(o=e[5].subTotal+"")&&f(n,o)},d(e){e&&(d(t),d(n))}}}function xe(t){let n;return{c(){n=h("Processing...")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function ke(e){let t;return{c(){t=p("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){u(e,t,n)},d(e){e&&d(t)}}}function Ie(e){let t,n,o,s,i;const a=[ge,be,fe],r=[];function l(e,t){return e[2]?0:e[4]?1:2}n=l(e),o=r[n]=a[n](e);let h=e[3]&&ke();return{c(){t=p("div"),o.c(),s=m(),h&&h.c(),$(t,"class","payment-page svelte-1nuc85y"),$(t,"data-id","sdfsddfq232131sada2131312")},m(e,o){u(e,t,o),r[n].m(t,null),c(t,s),h&&h.m(t,null),i=!0},p(e,[i]){let c=n;n=l(e),n===c?r[n].p(e,i):(E(),W(r[c],1,1,()=>{r[c]=null}),T(),o=r[n],o?o.p(e,i):(o=r[n]=a[n](e),o.c()),B(o,1),o.m(t,s)),e[3]?h||(h=ke(),h.c(),h.m(t,null)):h&&(h.d(1),h=null)},i(e){i||(B(o),i=!0)},o(e){W(o),i=!1},d(e){e&&d(t),r[n].d(),h&&h.d()}}}function _e(e,t,n){let o;var s,i;s=se,i=e=>n(5,o=e),e.$$.on_destroy.push(a(s,i));let{aid:c=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:$={}}=t,{source:f="direct"}=t,{onPaymentInitiate:b}=t,{onPaymentSuccess:g}=t,{onPaymentFailure:v}=t,{onPaymentCancel:x}=t,{onMethodSelect:k}=t,I=[{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:""}],_="",O=!1,L=!1,A="";const S=P();async function N(){n(2,O=!0),n(4,A="")}var F;return F=()=>{},w().$$.on_mount.push(F),e.$$set=e=>{"aid"in e&&n(9,c=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,$=e.shipping),"source"in e&&n(18,f=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,x=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:x,onMethodSelect:k},ue={...t}),e.$$.dirty,11264&e.$$.dirty&&p&&l&&u&&N()},[async function(){if(!_){const e={code:"NO_METHOD",message:"Please select a payment method"};return void v?.(e)}(async e=>{const t=r(ce);t&&(e.gokwik_oid=r(re));const n=await le(t?"/v1/order/create/back":"/v1/user/merchant/order/create",{method:"POST",body:JSON.stringify(e)});if(console.log({createOrderRes:n}),ue?.onPaymentInitiate&&ue.onPaymentInitiate({message:"payment-initiated",data:n}),n&&200===n?.statusCode){ce.set(!0);const t=e?.payment_method||"";ae.set(t),re.set(n?.data?.gokwik_oid),"upi"===t?de(n?.data?.u_link):pe(n?.data?.redirect_url),he()}})({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"===_?.toLowerCase()?"upi":"netbanking",payment_method:"upi"===_?.toLowerCase()?"upi":"netbanking",..."upi"===_?{psp_app:"Phonepe"}:{bank_code:"nb-axis"},rto_intervention:{}}),n(3,L=!0);try{if(!I.find(e=>e.buttonText===_))throw new Error("Invalid payment method")}catch(e){n(3,L=!1)}},_,O,L,A,o,I,N,function(e){n(1,_=e.detail.name);const t=I.find(e=>e.name===_);t&&(S("method-selected",{method:t.name}),k?.(t.name))},c,l,u,d,p,h,m,y,$,f,b,g,v,x,k,function(){const e=I.find(e=>e.name===_);return e?.name||null}]}customElements.define("payment-widget",H(class extends X{constructor(e){super(),G(this,e,_e,Ie,i,{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},ye)}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 Oe={init:async function(e){const{accessToken:t="",headers:n={}}=e;se.set(e),oe.set(t),ie.set(n),console.log("SDK Initiated")}};export{Oe as default};