@getruba/checkout 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};((e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})})(o,{EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM:()=>d,RubaEmbedPaymentMethod:()=>m}),module.exports=(e=o,((e,o,r,i)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let d of a(o))s.call(e,d)||d===r||t(e,d,{get:()=>o[d],enumerable:!(i=n(o,d))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r="RUBA_PAYMENT_METHOD",i="/embed/payment-method",d="ruba_payment_method_status",l=()=>{const e="http://127.0.0.1:3000".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},c=()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},m=class e{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,n){this.iframe=e,this.mode=t,this.loader=n,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:r},t)}static create(t){const{sessionToken:n,theme:a,setAsDefault:s,returnUrl:o,locale:r,onLoaded:d}=t,m=document.createElement("style");m.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===a?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===a?"#fff":"#000"};\n animation: ruba-loader-spinner-animation 1s infinite;\n }\n @keyframes ruba-loader-spinner-animation {\n 100% {box-shadow: 0 0 0 30px #0000}\n }\n body.ruba-no-scroll {\n overflow: hidden;\n }\n `,document.head.appendChild(m);const h=document.createElement("div");h.style.position="absolute",h.style.top="50%",h.style.left="50%",h.style.transform="translate(-50%, -50%)",h.style.zIndex="2147483647",h.style.colorScheme="auto";const u=document.createElement("div");u.className="ruba-loader-spinner",h.appendChild(u),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(h);const b=new URL(i,l());b.searchParams.set("session_token",n),b.searchParams.set("embed","true"),b.searchParams.set("embed_origin",window.location.origin),b.searchParams.set("mode","modal"),b.searchParams.set("embed_return_url",o??window.location.href),a&&b.searchParams.set("theme",a),!1===s&&b.searchParams.set("set_default","false"),r&&b.searchParams.set("locale",r);const p=document.createElement("iframe");p.src=b.toString(),p.style.position="fixed",p.style.top="0",p.style.left="0",p.style.width="100%",p.style.height="100%",p.style.border="none",p.style.zIndex="2147483647",p.style.backgroundColor="rgba(0, 0, 0, 0.5)",p.style.colorScheme="auto",p.allow=c(),document.body.appendChild(p);const f=new e(p,"modal",h);return d&&f.addEventListener("loaded",d,{once:!0}),new Promise(e=>{f.addEventListener("loaded",()=>e(f),{once:!0})})}static createInline(t){const{sessionToken:n,element:a,theme:s,setAsDefault:o,locale:r,onLoaded:d}=t,m=new URL(i,l());m.searchParams.set("session_token",n),m.searchParams.set("embed","true"),m.searchParams.set("embed_origin",window.location.origin),m.searchParams.set("mode","inline"),s&&m.searchParams.set("theme",s),!1===o&&m.searchParams.set("set_default","false"),r&&m.searchParams.set("locale",r);const h=document.createElement("iframe");h.src=m.toString(),h.style.display="block",h.style.width="100%",h.style.height="0",h.style.border="none",h.style.colorScheme="auto",h.allow=c(),a.replaceChildren(h);const u=new e(h,"inline",null);return d&&u.addEventListener("loaded",d,{once:!0}),u}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(d);if("succeeded"!==t&&"failed"!==t)return null;e.delete(d);const n=e.toString();return window.history.replaceState({},"",`${window.location.pathname}${n?`?${n}`:""}${window.location.hash}`),{status:t}}close(){window.removeEventListener("message",this.windowMessageListener),this.iframe.remove(),"modal"===this.mode&&document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-payment-method");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("data-ruba-payment-method");if(!a)return;const s=n.getAttribute("data-ruba-payment-method-theme"),o=n.getAttribute("data-ruba-payment-method-set-as-default"),r=n.getAttribute("data-ruba-payment-method-return-url"),i=n.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:a,theme:s??void 0,setAsDefault:null===o?void 0:"false"!==o,returnUrl:r??void 0,locale:i??void 0})}handleLoaded(){this.loaded||(this.loader&&document.body.contains(this.loader)&&document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(){"inline"!==this.mode&&(this.closable=!0,this.close())}handleError(){this.closable=!0}handleWindowMessage({data:e,origin:t}){if(!"http://127.0.0.1:3000".split(",").includes(t))return;if(e.type!==r)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const n=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(n),!n.defaultPrevented)switch(e.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess();break;case"error":this.handleError()}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedPaymentMethod:m}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{m.init()})}
@@ -0,0 +1,86 @@
1
+ declare const REDIRECT_STATUS_PARAM = "ruba_payment_method_status";
2
+ interface EmbedPaymentMethodMessageLoaded {
3
+ event: 'loaded';
4
+ }
5
+ interface EmbedPaymentMethodMessageClose {
6
+ event: 'close';
7
+ }
8
+ interface EmbedPaymentMethodMessageConfirmed {
9
+ event: 'confirmed';
10
+ }
11
+ interface EmbedPaymentMethodMessageSuccess {
12
+ event: 'success';
13
+ paymentMethodId: string;
14
+ }
15
+ type EmbedPaymentMethodErrorCode = 'invalid_request' | 'unauthorized' | 'processing_failed' | 'unknown';
16
+ interface EmbedPaymentMethodRedirectResult {
17
+ status: 'succeeded' | 'failed';
18
+ }
19
+ interface EmbedPaymentMethodMessageError {
20
+ event: 'error';
21
+ code: EmbedPaymentMethodErrorCode;
22
+ }
23
+ interface EmbedPaymentMethodMessageResize {
24
+ event: 'resize';
25
+ height: number;
26
+ }
27
+ type EmbedPaymentMethodMessage = EmbedPaymentMethodMessageLoaded | EmbedPaymentMethodMessageClose | EmbedPaymentMethodMessageConfirmed | EmbedPaymentMethodMessageSuccess | EmbedPaymentMethodMessageError | EmbedPaymentMethodMessageResize;
28
+ interface EmbedPaymentMethodCreateOptions {
29
+ sessionToken: string;
30
+ theme?: 'light' | 'dark';
31
+ setAsDefault?: boolean;
32
+ returnUrl?: string;
33
+ locale?: string;
34
+ onLoaded?: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void;
35
+ }
36
+ interface EmbedPaymentMethodCreateInlineOptions {
37
+ sessionToken: string;
38
+ element: HTMLElement;
39
+ theme?: 'light' | 'dark';
40
+ setAsDefault?: boolean;
41
+ locale?: string;
42
+ onLoaded?: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void;
43
+ }
44
+ declare class EmbedPaymentMethod {
45
+ private iframe;
46
+ private mode;
47
+ private loader;
48
+ private loaded;
49
+ private closable;
50
+ private eventTarget;
51
+ private windowMessageListener;
52
+ constructor(iframe: HTMLIFrameElement, mode: 'modal' | 'inline', loader: HTMLDivElement | null);
53
+ static postMessage(message: EmbedPaymentMethodMessage, targetOrigin: string): void;
54
+ static create(options: EmbedPaymentMethodCreateOptions): Promise<EmbedPaymentMethod>;
55
+ static createInline(options: EmbedPaymentMethodCreateInlineOptions): EmbedPaymentMethod;
56
+ static init(): void;
57
+ static getRedirectResult(): EmbedPaymentMethodRedirectResult | null;
58
+ close(): void;
59
+ addEventListener(type: 'loaded', listener: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void, options?: AddEventListenerOptions | boolean): void;
60
+ addEventListener(type: 'close', listener: (event: CustomEvent<EmbedPaymentMethodMessageClose>) => void, options?: AddEventListenerOptions | boolean): void;
61
+ addEventListener(type: 'confirmed', listener: (event: CustomEvent<EmbedPaymentMethodMessageConfirmed>) => void, options?: AddEventListenerOptions | boolean): void;
62
+ addEventListener(type: 'success', listener: (event: CustomEvent<EmbedPaymentMethodMessageSuccess>) => void, options?: AddEventListenerOptions | boolean): void;
63
+ addEventListener(type: 'error', listener: (event: CustomEvent<EmbedPaymentMethodMessageError>) => void, options?: AddEventListenerOptions | boolean): void;
64
+ removeEventListener(type: 'loaded', listener: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void): void;
65
+ removeEventListener(type: 'close', listener: (event: CustomEvent<EmbedPaymentMethodMessageClose>) => void): void;
66
+ removeEventListener(type: 'confirmed', listener: (event: CustomEvent<EmbedPaymentMethodMessageConfirmed>) => void): void;
67
+ removeEventListener(type: 'success', listener: (event: CustomEvent<EmbedPaymentMethodMessageSuccess>) => void): void;
68
+ removeEventListener(type: 'error', listener: (event: CustomEvent<EmbedPaymentMethodMessageError>) => void): void;
69
+ private static elementClickHandler;
70
+ private handleLoaded;
71
+ private handleClose;
72
+ private handleConfirmed;
73
+ private handleSuccess;
74
+ private handleError;
75
+ private handleWindowMessage;
76
+ }
77
+ declare global {
78
+ interface RubaWindow {
79
+ EmbedPaymentMethod: typeof EmbedPaymentMethod;
80
+ }
81
+ interface Window {
82
+ Ruba: Partial<RubaWindow>;
83
+ }
84
+ }
85
+
86
+ export { REDIRECT_STATUS_PARAM as EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM, type EmbedPaymentMethodErrorCode, type EmbedPaymentMethodRedirectResult, EmbedPaymentMethod as RubaEmbedPaymentMethod };
@@ -0,0 +1,86 @@
1
+ declare const REDIRECT_STATUS_PARAM = "ruba_payment_method_status";
2
+ interface EmbedPaymentMethodMessageLoaded {
3
+ event: 'loaded';
4
+ }
5
+ interface EmbedPaymentMethodMessageClose {
6
+ event: 'close';
7
+ }
8
+ interface EmbedPaymentMethodMessageConfirmed {
9
+ event: 'confirmed';
10
+ }
11
+ interface EmbedPaymentMethodMessageSuccess {
12
+ event: 'success';
13
+ paymentMethodId: string;
14
+ }
15
+ type EmbedPaymentMethodErrorCode = 'invalid_request' | 'unauthorized' | 'processing_failed' | 'unknown';
16
+ interface EmbedPaymentMethodRedirectResult {
17
+ status: 'succeeded' | 'failed';
18
+ }
19
+ interface EmbedPaymentMethodMessageError {
20
+ event: 'error';
21
+ code: EmbedPaymentMethodErrorCode;
22
+ }
23
+ interface EmbedPaymentMethodMessageResize {
24
+ event: 'resize';
25
+ height: number;
26
+ }
27
+ type EmbedPaymentMethodMessage = EmbedPaymentMethodMessageLoaded | EmbedPaymentMethodMessageClose | EmbedPaymentMethodMessageConfirmed | EmbedPaymentMethodMessageSuccess | EmbedPaymentMethodMessageError | EmbedPaymentMethodMessageResize;
28
+ interface EmbedPaymentMethodCreateOptions {
29
+ sessionToken: string;
30
+ theme?: 'light' | 'dark';
31
+ setAsDefault?: boolean;
32
+ returnUrl?: string;
33
+ locale?: string;
34
+ onLoaded?: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void;
35
+ }
36
+ interface EmbedPaymentMethodCreateInlineOptions {
37
+ sessionToken: string;
38
+ element: HTMLElement;
39
+ theme?: 'light' | 'dark';
40
+ setAsDefault?: boolean;
41
+ locale?: string;
42
+ onLoaded?: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void;
43
+ }
44
+ declare class EmbedPaymentMethod {
45
+ private iframe;
46
+ private mode;
47
+ private loader;
48
+ private loaded;
49
+ private closable;
50
+ private eventTarget;
51
+ private windowMessageListener;
52
+ constructor(iframe: HTMLIFrameElement, mode: 'modal' | 'inline', loader: HTMLDivElement | null);
53
+ static postMessage(message: EmbedPaymentMethodMessage, targetOrigin: string): void;
54
+ static create(options: EmbedPaymentMethodCreateOptions): Promise<EmbedPaymentMethod>;
55
+ static createInline(options: EmbedPaymentMethodCreateInlineOptions): EmbedPaymentMethod;
56
+ static init(): void;
57
+ static getRedirectResult(): EmbedPaymentMethodRedirectResult | null;
58
+ close(): void;
59
+ addEventListener(type: 'loaded', listener: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void, options?: AddEventListenerOptions | boolean): void;
60
+ addEventListener(type: 'close', listener: (event: CustomEvent<EmbedPaymentMethodMessageClose>) => void, options?: AddEventListenerOptions | boolean): void;
61
+ addEventListener(type: 'confirmed', listener: (event: CustomEvent<EmbedPaymentMethodMessageConfirmed>) => void, options?: AddEventListenerOptions | boolean): void;
62
+ addEventListener(type: 'success', listener: (event: CustomEvent<EmbedPaymentMethodMessageSuccess>) => void, options?: AddEventListenerOptions | boolean): void;
63
+ addEventListener(type: 'error', listener: (event: CustomEvent<EmbedPaymentMethodMessageError>) => void, options?: AddEventListenerOptions | boolean): void;
64
+ removeEventListener(type: 'loaded', listener: (event: CustomEvent<EmbedPaymentMethodMessageLoaded>) => void): void;
65
+ removeEventListener(type: 'close', listener: (event: CustomEvent<EmbedPaymentMethodMessageClose>) => void): void;
66
+ removeEventListener(type: 'confirmed', listener: (event: CustomEvent<EmbedPaymentMethodMessageConfirmed>) => void): void;
67
+ removeEventListener(type: 'success', listener: (event: CustomEvent<EmbedPaymentMethodMessageSuccess>) => void): void;
68
+ removeEventListener(type: 'error', listener: (event: CustomEvent<EmbedPaymentMethodMessageError>) => void): void;
69
+ private static elementClickHandler;
70
+ private handleLoaded;
71
+ private handleClose;
72
+ private handleConfirmed;
73
+ private handleSuccess;
74
+ private handleError;
75
+ private handleWindowMessage;
76
+ }
77
+ declare global {
78
+ interface RubaWindow {
79
+ EmbedPaymentMethod: typeof EmbedPaymentMethod;
80
+ }
81
+ interface Window {
82
+ Ruba: Partial<RubaWindow>;
83
+ }
84
+ }
85
+
86
+ export { REDIRECT_STATUS_PARAM as EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM, type EmbedPaymentMethodErrorCode, type EmbedPaymentMethodRedirectResult, EmbedPaymentMethod as RubaEmbedPaymentMethod };
@@ -0,0 +1 @@
1
+ import{EmbedPaymentMethod as E,REDIRECT_STATUS_PARAM as A}from"./chunk-FSZEYAE6.js";export{A as EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM,E as RubaEmbedPaymentMethod};