@pybara/pybara-js 0.4.0 → 0.6.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.
package/README.md CHANGED
@@ -67,6 +67,7 @@ The code above is all an AI builder needs. The one thing code can't do: the site
67
67
  | `siteName` | `string` | ✓ | Display name — shown in the checkout and stored on subscriptions |
68
68
  | `currency` | `string` | | Default currency for `open()`, ISO 4217 uppercase (`'EUR'`) — no default of its own |
69
69
  | `thankYouMessage` | `string` | | Success-screen title override |
70
+ | `locale` | `string` | | The checkout's language, a BCP 47 tag (`'fr'`, `'de-DE'`), usually your site's; otherwise the payer's own |
70
71
  | `thankYouRedirectUrl` | `string` | | Redirect after the payer closes the success screen |
71
72
  | `siteCountry` | `string` | | ISO 3166-1 alpha-2 |
72
73
  | `notifyEmail` | `string` | | Operator email — terms warnings, payment notifications |
@@ -74,6 +75,7 @@ The code above is all an AI builder needs. The one thing code can't do: the site
74
75
  | `platform` | `string` | | Your integration's slug in the payment log, `a-z 0-9 -` (default `'pybara-js'`) |
75
76
  | `pluginVersion` | `string` | | Set by plugins — skips the autonomous-embed terms gate |
76
77
  | `staging` / `debug` | `boolean` | | Staging canisters + wallet / console logging |
78
+ | `onAvailability(availability)` | `function` | | Whether a payment would go through right now, before any click — see [Availability](#availability) |
77
79
 
78
80
  ### `checkout.open(payment)` → `Promise<void>`
79
81
 
@@ -90,6 +92,27 @@ The code above is all an AI builder needs. The one thing code can't do: the site
90
92
  | `onSuccess(result)` | `function` | Payment confirmed — `result` carries block height, token, principals |
91
93
  | `onError(err)` `onClose()` | `function` | Checkout refusals (`EmbeddedError`, `err.code`) / modal closed |
92
94
 
95
+ ### Availability
96
+
97
+ With `onAvailability` set, Pybara tells the page — before any click — whether a payment would go through, so you show the option only when it works:
98
+
99
+ ```js
100
+ const pybara = Pybara.checkout({
101
+ recipientPrincipal, siteUrl, siteName, currency: 'EUR',
102
+ onAvailability: ({ status, message }) => {
103
+ payButton.hidden = status === 'unavailable'; // the site isn't set up, or the currency isn't served
104
+ payButton.disabled = status === 'below-minimum'; // message: "Minimum €0.70", in the payer's language
105
+ hint.textContent = status === 'below-minimum' ? message : '';
106
+ },
107
+ });
108
+ amountInput.addEventListener('input', () => pybara.precheck({ amount: amountInput.value }));
109
+ ```
110
+
111
+ - **Called once on its own** when the checkout is ready (the site and its currency), then after each `checkout.precheck({ amount, currency })`. Call `precheck()` whenever the amount or currency changes; only the latest is answered.
112
+ - **Act on `status`:** `available`; `unavailable` (hide Pybara: nothing on the page can fix it); `below-minimum` (keep it, disable the button, show `message`; `minimum` is `{ amount, currency }`); `retry-later` (keep it: the click tries again).
113
+ - **`message`** is in the payer's language, ready to show. **`detail`**, in English, says what's missing and who fixes it — e.g. the site owner's DNS record or terms — and is printed to the console. **`reason`** is for debugging only: never branch on it.
114
+ - Without `onAvailability`, nothing changes: `open()` checks everything at the click, as always.
115
+
93
116
  ### Errors
94
117
 
95
118
  `open()` rejects with a `PybaraError` (`err.code`) when the checkout can't open:
@@ -51,6 +51,13 @@
51
51
  "type": "string",
52
52
  "description": "Replaces the success screen's default title."
53
53
  },
54
+ "locale": {
55
+ "type": "string",
56
+ "description": "The checkout's language, a BCP 47 tag ('fr', 'de-DE', 'zh-CN'), usually the site's: shown when Pybara has it, otherwise the payer's own language."
57
+ },
58
+ "onAvailability": {
59
+ "description": "function (Availability) => void — whether a payment would go through right now, before any click: called once the checkout is ready, then after each precheck({ amount, currency }). Act on availability.status: 'available' (show Pybara), 'unavailable' (hide it: nothing on the page can fix it), 'below-minimum' (disable the button and show availability.message, e.g. 'Minimum €0.70'), 'retry-later' (keep it). availability.detail, in English, says what is missing and who fixes it, and is also printed to the console. Never branch on availability.reason. Not expressible in JSON."
60
+ },
54
61
  "thankYouRedirectUrl": {
55
62
  "type": "string",
56
63
  "format": "uri",
@@ -18,7 +18,19 @@ export declare class PybaraCheckout {
18
18
  private activePayment;
19
19
  /** All async binding work — open() awaits it so the gate and the iframe prewarm are resolved first. */
20
20
  readonly ready: Promise<void>;
21
+ /** The latest precheck()'s amount and currency, sent again to each rebuilt checkout frame. */
22
+ private lastPrecheck;
21
23
  constructor(userConfig: CheckoutConfig);
24
+ /**
25
+ * Ask whether a payment of this amount would go through right now; the answer arrives on the config's onAvailability.
26
+ * Call it again whenever the form's amount or currency changes: only the latest is answered.
27
+ * It changes nothing open() does, which checks everything again at the click.
28
+ */
29
+ precheck(params?: {
30
+ amount?: string | number;
31
+ currency?: string;
32
+ }): void;
33
+ private sendPrecheck;
22
34
  /** The autonomous-embed gate outcome once `ready` resolves — null while pending or under plugin terms (a plugin's host checks its own). */
23
35
  get gate(): WidgetGate | null;
24
36
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,aAAa,EAEnB,MAAM,SAAS,CAAC;AAcjB;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,KAAK,CAA8B;IAC3C,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,MAAM,CAAS;IACvB,gIAAgI;IAChI,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,aAAa,CAA8B;IACnD,uGAAuG;IACvG,SAAgB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBAEzB,UAAU,EAAE,cAAc;IAKtC,2IAA2I;IAC3I,IAAI,IAAI,IAAI,UAAU,GAAG,IAAI,CAE5B;IAED;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA8EjD,4EAA4E;IAC5E,KAAK,IAAI,IAAI;YAIC,IAAI;IA8ClB,O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}
package/dist/gate.d.ts CHANGED
@@ -6,9 +6,11 @@
6
6
  */
7
7
  /** The widget terms version this release requires: raised only by a release that needs new terms, so most updates keep showing on sites that accepted older ones. */
8
8
  export declare const REQUIRED_WIDGET_TERMS_VERSION = "1-0";
9
+ /** A refusal's `cause`: the configuration could not be read (transient), Pybara switched embeds off, or the site's terms are missing or outdated (the owner fixes it in Pybara Wallet). */
9
10
  export type WidgetGate = {
10
11
  show: false;
11
12
  reason: string;
13
+ cause: 'unreadable' | 'switched-off' | 'terms';
12
14
  } | {
13
15
  show: true;
14
16
  recurring: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,qKAAqK;AACrK,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAKnD,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAW9F,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAS1E;AAQD,mIAAmI;AACnI,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,UAAU,CAAC,CAkCrB"}
1
+ {"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,qKAAqK;AACrK,eAAO,MAAM,6BAA6B,QAAQ,CAAC;AAKnD,2LAA2L;AAC3L,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,YAAY,GAAG,cAAc,GAAG,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAW9I,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAS1E;AAQD,mIAAmI;AACnI,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,GACzB,OAAO,CAAC,UAAU,CAAC,CAqCrB"}
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare const Pybara: {
9
9
  checkout: typeof checkout;
10
10
  };
11
11
  export { PybaraCheckout } from './checkout';
12
+ export { type Availability } from './modal/modal';
12
13
  export { type WidgetGate } from './gate';
13
14
  export { type CheckoutConfig, type CheckoutResult, type Frequency, type PaymentParams, PybaraError, type PybaraErrorCode, } from './types';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAE/D;AAID,eAAO,MAAM,MAAM;;CAAe,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAE/D;AAID,eAAO,MAAM,MAAM;;CAAe,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,WAAW,EACX,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC"}
@@ -11,5 +11,5 @@
11
11
  * This was `@pybara/pybara-ux` — absorbed into pybara-js so the SDK and its
12
12
  * modal kit version together.
13
13
  */
14
- export { CheckoutModal, EmbeddedError, type Checkout, type CheckoutModalConfig, type ModalData, type PaymentData, } from './modal.js';
14
+ export { CheckoutModal, EmbeddedError, type Availability, type Checkout, type CheckoutModalConfig, type ModalData, type PaymentData, type Precheck, } from './modal.js';
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,aAAa,EACb,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,QAAQ,GACd,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- export { t as CheckoutModal, n as EmbeddedError } from "../modal-DCwwkKZ7.js";
1
+ export { t as CheckoutModal, n as EmbeddedError } from "../modal-CvQ7qr5d.js";
@@ -22,6 +22,8 @@ export interface CheckoutModalConfig {
22
22
  context: 'payment' | 'donation';
23
23
  /** Replaces the success screen's default title ("You're all set!"), e.g. pybara-donate's "Thank you message" setting. Plain text; the frame escapes it. */
24
24
  thankYouMessage?: string;
25
+ /** The checkout's language, a BCP 47 tag ('fr', 'de-DE'), usually the page's: the frame shows it when the wallet has it, else the buyer's own. */
26
+ locale?: string;
25
27
  /** The payment is complete: the frame's success screen has appeared, and the modal stays open until the buyer closes it (onClose). The moment to confirm the payment server-side. */
26
28
  onSuccess?: (data: {
27
29
  blockIndex: string;
@@ -33,6 +35,34 @@ export interface CheckoutModalConfig {
33
35
  onError?: (error: Error) => void;
34
36
  /** The modal has closed: a cancellation before any onSuccess, or the buyer leaving the success screen after one. */
35
37
  onClose?: () => void;
38
+ /** The frame's answer to each precheck(): whether a payment would go through right now. Called again after each new precheck(). */
39
+ onAvailability?: (availability: Availability) => void;
40
+ }
41
+ /**
42
+ * Whether a payment would go through right now, as the checkout frame answers a precheck().
43
+ * `status` is stable, and the one to act on: `available`; `unavailable`, which nothing on the page can fix (hide the option); `below-minimum`, with `minimum` in the precheck's currency (keep the option, disable its button, show the minimum); `retry-later`, transient (keep the option).
44
+ * `reason` is a code for debugging, which may be added to or renamed at any time: never branch on it.
45
+ * `message` is for the payer, in the checkout's language, ready to show as-is; `detail` is for the integrator, in English, and is also printed to the console.
46
+ */
47
+ export interface Availability {
48
+ status: 'available' | 'unavailable' | 'below-minimum' | 'retry-later';
49
+ reason?: string;
50
+ message?: string;
51
+ detail?: string;
52
+ minimum?: {
53
+ amount: string;
54
+ currency: string;
55
+ };
56
+ }
57
+ /** What a precheck() asks about. The site is always the page's own origin, as the browser reports it. */
58
+ export interface Precheck {
59
+ beneficiary: string;
60
+ /** The site URL the checkout will declare, which must sit on the page's origin. */
61
+ siteUrl?: string;
62
+ /** A decimal string in the currency's major units, as the checkout's amount. Without one, the minimum is not checked. */
63
+ amount?: string;
64
+ /** ISO 4217. Without one, neither the currency nor the minimum is checked. */
65
+ currency?: string;
36
66
  }
37
67
  /** What show() needs that only exists once the order or donation does — unlike CheckoutModalConfig, known at construction. */
38
68
  export interface PaymentData {
@@ -174,9 +204,18 @@ export declare class CheckoutModal {
174
204
  private iframeLoaded;
175
205
  /** Held by show() when it runs before `load`; the `load` handler sends it. */
176
206
  private pendingPaymentData;
207
+ /** Held by precheck() when it runs before `load`; the `load` handler sends the latest. */
208
+ private pendingPrecheck;
177
209
  constructor(config: CheckoutModalConfig);
178
210
  /** Backdrop and iframe, built at construction and hidden until open() — see the file header for why. */
179
211
  private createIframe;
212
+ /**
213
+ * Ask the frame whether a payment would go through right now; the answer arrives on onAvailability.
214
+ * Send it again whenever the amount changes: the frame answers the latest, at a rate it sets.
215
+ * It authorises nothing and changes nothing the checkout does: show() is checked again in full.
216
+ */
217
+ precheck(precheck: Precheck): void;
218
+ private sendPrecheck;
180
219
  private sendInitMessage;
181
220
  /**
182
221
  * Show the backdrop and its spinner now, before the payment data exists: a platform calls it on the buyer's click, while it still creates the order, so one overlay covers the whole sequence.
@@ -1 +1 @@
1
- {"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../src/modal/modal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,MAAM,WAAW,SAAS;IACtB,sJAAsJ;IACtJ,WAAW,EAAE,MAAM,CAAC;IACpB,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAC;IACb,+JAA+J;IAC/J,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAChC,yFAAyF;IACzF,SAAS,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O,CAA4B;IAC3C,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAgD;IACrE,OAAO,CAAC,eAAe,CAA6C;IACpE,kKAAkK;IAClK,OAAO,CAAC,QAAQ,CAAQ;IACxB,+EAA+E;IAC/E,OAAO,CAAC,YAAY,CAAS;IAC7B,8EAA8E;IAC9E,OAAO,CAAC,kBAAkB,CAA4B;IACtD,0FAA0F;IAC1F,OAAO,CAAC,eAAe,CAAyB;gBAEpC,MAAM,EAAE,mBAAmB;IAMvC,wGAAwG;IACxG,OAAO,CAAC,YAAY;IA4IpB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAKlC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,eAAe;IAevB;;;OAGG;IACH,IAAI,IAAI,IAAI;IASZ,uIAAuI;IACvI,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAS7B;;;OAGG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IA2C1C;;;OAGG;IACH,KAAK,IAAI,IAAI;CAqChB"}
@@ -62,7 +62,7 @@ function h(e) {
62
62
  }
63
63
  var g = class {
64
64
  constructor(e) {
65
- this.overlay = null, this.iframe = null, this.spinner = null, this.handleMessage = null, this.handleEscapeKey = null, this.closable = !0, this.iframeLoaded = !1, this.pendingPaymentData = null, this.config = e, this.walletOrigin = new URL(e.walletUrl).origin, this.createIframe();
65
+ this.overlay = null, this.iframe = null, this.spinner = null, this.handleMessage = null, this.handleEscapeKey = null, this.closable = !0, this.iframeLoaded = !1, this.pendingPaymentData = null, this.pendingPrecheck = null, this.config = e, this.walletOrigin = new URL(e.walletUrl).origin, this.createIframe();
66
66
  }
67
67
  createIframe() {
68
68
  let n = document.createElement("div");
@@ -87,7 +87,7 @@ var g = class {
87
87
  duration: 1e3,
88
88
  iterations: Infinity
89
89
  }), r.addEventListener("load", () => {
90
- this.iframeLoaded = !0, this.pendingPaymentData &&= (this.sendInitMessage(this.pendingPaymentData), null);
90
+ this.iframeLoaded = !0, this.pendingPrecheck &&= (this.sendPrecheck(this.pendingPrecheck), null), this.pendingPaymentData &&= (this.sendInitMessage(this.pendingPaymentData), null);
91
91
  }, { once: !0 }), this.handleMessage = (e) => {
92
92
  if (e.origin === this.walletOrigin && e.source === r.contentWindow && h(e.data)) switch (e.data.type) {
93
93
  case "pybara_embedded_result":
@@ -116,12 +116,30 @@ var g = class {
116
116
  easing: "ease"
117
117
  }));
118
118
  break;
119
- case "pybara_embedded_closable": this.closable = e.data.closable;
119
+ case "pybara_embedded_closable":
120
+ this.closable = e.data.closable;
121
+ break;
122
+ case "pybara_embedded_availability": {
123
+ let { type: t, v: n, ...r } = e.data;
124
+ r.status !== "available" && r.detail && console.warn(r.detail), this.config.onAvailability?.(r);
125
+ break;
126
+ }
120
127
  }
121
128
  }, window.addEventListener("message", this.handleMessage), this.handleEscapeKey = (e) => {
122
129
  e.key === "Escape" && this.closable && (this.close(), this.config.onClose?.());
123
130
  }, document.addEventListener("keydown", this.handleEscapeKey), n.appendChild(i), n.appendChild(r), document.body.appendChild(n), this.overlay = n, this.iframe = r, this.spinner = i;
124
131
  }
132
+ precheck(e) {
133
+ this.iframeLoaded ? this.sendPrecheck(e) : this.pendingPrecheck = e;
134
+ }
135
+ sendPrecheck(e) {
136
+ this.iframe?.contentWindow?.postMessage({
137
+ type: "pybara_embedded_precheck",
138
+ v: 1,
139
+ context: this.config.context,
140
+ ...e
141
+ }, this.walletOrigin);
142
+ }
125
143
  sendInitMessage(e) {
126
144
  let t = {
127
145
  type: "pybara_embedded_init",
@@ -131,7 +149,8 @@ var g = class {
131
149
  context: this.config.context,
132
150
  ...e.recurring ? { recurring: e.recurring } : {},
133
151
  checkout: e.checkout,
134
- ...this.config.thankYouMessage ? { thankYouMessage: this.config.thankYouMessage } : {}
152
+ ...this.config.thankYouMessage ? { thankYouMessage: this.config.thankYouMessage } : {},
153
+ ...this.config.locale ? { locale: this.config.locale } : {}
135
154
  };
136
155
  this.iframe?.contentWindow?.postMessage(t, this.walletOrigin);
137
156
  }
@@ -168,7 +187,7 @@ var g = class {
168
187
  close() {
169
188
  this.handleMessage &&= (window.removeEventListener("message", this.handleMessage), null), this.handleEscapeKey &&= (document.removeEventListener("keydown", this.handleEscapeKey), null), u();
170
189
  let e = this.overlay, n = this.iframe;
171
- this.overlay = null, this.iframe = null, this.spinner = null, this.iframeLoaded = !1, this.pendingPaymentData = null, this.closable = !0, e && (e.style.display === "none" || d() ? e.remove() : (e.style.pointerEvents = "none", n?.animate([{
190
+ this.overlay = null, this.iframe = null, this.spinner = null, this.iframeLoaded = !1, this.pendingPaymentData = null, this.pendingPrecheck = null, this.closable = !0, e && (e.style.display === "none" || d() ? e.remove() : (e.style.pointerEvents = "none", n?.animate([{
172
191
  transform: "scale(1)",
173
192
  opacity: 1
174
193
  }, {