Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .build.vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# These vars are public and will be used for the example page
# They should match vars in wrangler.toml
CHECKOUT_HOST_ENDPOINT = "https://pay.tebex.io"
HEADLESS_API_ENDPOINT = "https://headless.tebex.io"
ACCOUNT_ID = "t6c9-0927595131662ac732bf5f1d9bd5570482db5316"
PACKAGE_IDS = "5987844,5987895"
USERNAME = "notch"
18 changes: 15 additions & 3 deletions dist/tebex.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12508,7 +12508,7 @@
return html;
};

var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_resolveLocale, _Checkout_resolveTheme, _Checkout_resolveColors, _Checkout_resolvePopupOnMobile, _Checkout_resolveEndpoint, _Checkout_resolveCloseOnClickOutside, _Checkout_resolveCloseOnEsc, _Checkout_resolveDefaultPaymentMethod, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_resolveLocale, _Checkout_resolveTheme, _Checkout_resolveColors, _Checkout_resolvePopupOnMobile, _Checkout_resolveEndpoint, _Checkout_resolveCloseOnClickOutside, _Checkout_resolveCloseOnEsc, _Checkout_resolveCloseOnPaymentComplete, _Checkout_resolveDefaultPaymentMethod, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
const DEFAULT_WIDTH = "800px";
const DEFAULT_HEIGHT = "760px";
const THEME_NAMES = [
Expand Down Expand Up @@ -12549,6 +12549,7 @@
this.colors = [];
this.closeOnClickOutside = false;
this.closeOnEsc = false;
this.closeOnPaymentComplete = false;
this.defaultPaymentMethod = undefined;
this.popupOnMobile = false;
this.endpoint = "https://pay.tebex.io";
Expand Down Expand Up @@ -12577,6 +12578,7 @@
this.endpoint = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveEndpoint).call(this, options) ?? this.endpoint;
this.closeOnClickOutside = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnClickOutside).call(this, options) ?? this.closeOnClickOutside;
this.closeOnEsc = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnEsc).call(this, options) ?? this.closeOnEsc;
this.closeOnPaymentComplete = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnPaymentComplete).call(this, options) ?? this.closeOnPaymentComplete;
this.defaultPaymentMethod = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveDefaultPaymentMethod).call(this, options) ?? this.defaultPaymentMethod;
}
/**
Expand Down Expand Up @@ -12743,6 +12745,14 @@
return null;
}
return options.closeOnEsc;
}, _Checkout_resolveCloseOnPaymentComplete = function _Checkout_resolveCloseOnPaymentComplete(options) {
if (isNullOrUndefined(options.closeOnPaymentComplete))
return null;
if (!isBoolean(options.closeOnPaymentComplete)) {
warn(`invalid closeOnPaymentComplete option "${options.closeOnPaymentComplete}" - must be a boolean`);
return null;
}
return options.closeOnPaymentComplete;
}, _Checkout_resolveDefaultPaymentMethod = function _Checkout_resolveDefaultPaymentMethod(options) {
if (isNullOrUndefined(options.defaultPaymentMethod))
return null;
Expand Down Expand Up @@ -12790,6 +12800,7 @@
colors: this.colors,
closeOnClickOutside: this.closeOnClickOutside,
closeOnEsc: this.closeOnEsc,
closeOnPaymentComplete: this.closeOnPaymentComplete,
defaultPaymentMethod: this.defaultPaymentMethod,
theme: this.theme,
onOpenWindow: (url) => {
Expand All @@ -12814,7 +12825,7 @@
origin: url.origin,
path: url.pathname,
params: url.search,
version: "1.8.1",
version: "1.9.0",
});
await this.zoid.renderTo(window, container, popup ? "popup" : "iframe");
__classPrivateFieldSet(this, _Checkout_didRender, true, "f");
Expand Down Expand Up @@ -12973,6 +12984,7 @@
colors: colors,
closeOnClickOutside: getAttribute(this, "close-on-click-outside") !== null,
closeOnEsc: getAttribute(this, "close-on-esc") !== null,
closeOnPaymentComplete: getAttribute(this, "close-on-payment-complete") !== null,
defaultPaymentMethod: getAttribute(this, "default-payment-method"),
popupOnMobile: getAttribute(this, "popup-on-mobile") !== null,
endpoint: getAttribute(this, "endpoint"),
Expand Down Expand Up @@ -13024,7 +13036,7 @@
/**
* Current Tebex.js package version
*/
const version = "1.8.1";
const version = "1.9.0";
/**
* Tebex checkout API
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/tebex.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tebex.min.js.map

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions dist/tebex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12502,7 +12502,7 @@ const spinnerRender = ({ doc, props }) => {
return html;
};

var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_resolveLocale, _Checkout_resolveTheme, _Checkout_resolveColors, _Checkout_resolvePopupOnMobile, _Checkout_resolveEndpoint, _Checkout_resolveCloseOnClickOutside, _Checkout_resolveCloseOnEsc, _Checkout_resolveDefaultPaymentMethod, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
var _Checkout_instances, _Checkout_didRender, _Checkout_onRender, _Checkout_resolveLocale, _Checkout_resolveTheme, _Checkout_resolveColors, _Checkout_resolvePopupOnMobile, _Checkout_resolveEndpoint, _Checkout_resolveCloseOnClickOutside, _Checkout_resolveCloseOnEsc, _Checkout_resolveCloseOnPaymentComplete, _Checkout_resolveDefaultPaymentMethod, _Checkout_onRequestLightboxClose, _Checkout_showLightbox, _Checkout_buildComponent, _Checkout_renderComponent;
const DEFAULT_WIDTH = "800px";
const DEFAULT_HEIGHT = "760px";
const THEME_NAMES = [
Expand Down Expand Up @@ -12543,6 +12543,7 @@ class Checkout {
this.colors = [];
this.closeOnClickOutside = false;
this.closeOnEsc = false;
this.closeOnPaymentComplete = false;
this.defaultPaymentMethod = undefined;
this.popupOnMobile = false;
this.endpoint = "https://pay.tebex.io";
Expand Down Expand Up @@ -12571,6 +12572,7 @@ class Checkout {
this.endpoint = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveEndpoint).call(this, options) ?? this.endpoint;
this.closeOnClickOutside = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnClickOutside).call(this, options) ?? this.closeOnClickOutside;
this.closeOnEsc = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnEsc).call(this, options) ?? this.closeOnEsc;
this.closeOnPaymentComplete = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveCloseOnPaymentComplete).call(this, options) ?? this.closeOnPaymentComplete;
this.defaultPaymentMethod = __classPrivateFieldGet(this, _Checkout_instances, "m", _Checkout_resolveDefaultPaymentMethod).call(this, options) ?? this.defaultPaymentMethod;
}
/**
Expand Down Expand Up @@ -12737,6 +12739,14 @@ _Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checko
return null;
}
return options.closeOnEsc;
}, _Checkout_resolveCloseOnPaymentComplete = function _Checkout_resolveCloseOnPaymentComplete(options) {
if (isNullOrUndefined(options.closeOnPaymentComplete))
return null;
if (!isBoolean(options.closeOnPaymentComplete)) {
warn(`invalid closeOnPaymentComplete option "${options.closeOnPaymentComplete}" - must be a boolean`);
return null;
}
return options.closeOnPaymentComplete;
}, _Checkout_resolveDefaultPaymentMethod = function _Checkout_resolveDefaultPaymentMethod(options) {
if (isNullOrUndefined(options.defaultPaymentMethod))
return null;
Expand Down Expand Up @@ -12784,6 +12794,7 @@ _Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checko
colors: this.colors,
closeOnClickOutside: this.closeOnClickOutside,
closeOnEsc: this.closeOnEsc,
closeOnPaymentComplete: this.closeOnPaymentComplete,
defaultPaymentMethod: this.defaultPaymentMethod,
theme: this.theme,
onOpenWindow: (url) => {
Expand All @@ -12808,7 +12819,7 @@ _Checkout_didRender = new WeakMap(), _Checkout_onRender = new WeakMap(), _Checko
origin: url.origin,
path: url.pathname,
params: url.search,
version: "1.8.1",
version: "1.9.0",
});
await this.zoid.renderTo(window, container, popup ? "popup" : "iframe");
__classPrivateFieldSet(this, _Checkout_didRender, true, "f");
Expand Down Expand Up @@ -12967,6 +12978,7 @@ const defineTebexCheckout = () => {
colors: colors,
closeOnClickOutside: getAttribute(this, "close-on-click-outside") !== null,
closeOnEsc: getAttribute(this, "close-on-esc") !== null,
closeOnPaymentComplete: getAttribute(this, "close-on-payment-complete") !== null,
defaultPaymentMethod: getAttribute(this, "default-payment-method"),
popupOnMobile: getAttribute(this, "popup-on-mobile") !== null,
endpoint: getAttribute(this, "endpoint"),
Expand Down Expand Up @@ -13018,7 +13030,7 @@ if (isEnvBrowser())
/**
* Current Tebex.js package version
*/
const version = "1.8.1";
const version = "1.9.0";
/**
* Tebex checkout API
*/
Expand Down
7 changes: 7 additions & 0 deletions dist/types/checkout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export type CheckoutOptions = {
* @default false
*/
closeOnEsc?: boolean;
/**
* Whether to automatically close the Tebex.js popup as soon as the payment is completed; `payment:complete` and `close` events will still be emitted.
* @default false
*/
closeOnPaymentComplete?: boolean;
/**
* Select a payment method to highlight on the checkout by passing its ident.
* @default undefined
Expand Down Expand Up @@ -89,6 +94,7 @@ export type CheckoutZoidProps = {
colors: CheckoutColorDefinition[];
closeOnClickOutside: boolean;
closeOnEsc: boolean;
closeOnPaymentComplete: boolean;
defaultPaymentMethod?: string;
theme: CheckoutTheme;
onOpenWindow: (url: string) => void;
Expand All @@ -114,6 +120,7 @@ export default class Checkout {
colors: CheckoutColorDefinition[];
closeOnClickOutside: boolean;
closeOnEsc: boolean;
closeOnPaymentComplete: boolean;
defaultPaymentMethod?: string;
popupOnMobile: boolean;
endpoint: string;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tebexio/tebex.js",
"version": "1.8.1",
"version": "1.9.0",
"description": "Integrate Tebex Checkout directly into your own website or game using our embedded checkout experience.",
"type": "module",
"main": "dist/tebex.cjs",
Expand Down
10 changes: 5 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import copy from "rollup-plugin-copy";
import dev from "rollup-plugin-dev";
import dotenv from "dotenv";

dotenv.config({ path: ".dev.vars" });

const build = process.env.BUILD ?? "browser";
const isBrowser = build === "browser";
const isNpm = build === "npm";
const isServer = process.env.SERVER ?? false;
const isDevServer = process.env.SERVER ?? false;

dotenv.config({ path: isDevServer ? ".dev.vars" : ".build.vars" });

const bannerMessage = readFileSync("./LICENSE")
.toString()
Expand All @@ -35,7 +35,7 @@ const banner = `/**!
${bannerMessage}
*/`;

const exampleDist = isServer ? "example/.dist" : "example/dist";
const exampleDist = isDevServer ? "example/.dist" : "example/dist";

export default [
// Main Tebex.js build
Expand Down Expand Up @@ -155,7 +155,7 @@ export default [
target: `${exampleDist}/components.html`,
attrs: ["defer"],
}),
isServer &&
isDevServer &&
dev({
silent: true,
host: "localhost",
Expand Down
21 changes: 21 additions & 0 deletions src/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export type CheckoutOptions = {
* @default false
*/
closeOnEsc?: boolean;
/**
* Whether to automatically close the Tebex.js popup as soon as the payment is completed; `payment:complete` and `close` events will still be emitted.
* @default false
*/
closeOnPaymentComplete?: boolean;
/**
* Select a payment method to highlight on the checkout by passing its ident.
* @default undefined
Expand Down Expand Up @@ -147,6 +152,7 @@ export type CheckoutZoidProps = {
colors: CheckoutColorDefinition[];
closeOnClickOutside: boolean;
closeOnEsc: boolean;
closeOnPaymentComplete: boolean;
defaultPaymentMethod?: string;
theme: CheckoutTheme;
onOpenWindow: (url: string) => void;
Expand All @@ -173,6 +179,7 @@ export default class Checkout {
colors: CheckoutColorDefinition[] = [];
closeOnClickOutside = false;
closeOnEsc = false;
closeOnPaymentComplete = false;
defaultPaymentMethod?: string = undefined;
popupOnMobile = false;
endpoint = "https://pay.tebex.io";
Expand Down Expand Up @@ -200,6 +207,7 @@ export default class Checkout {
this.endpoint = this.#resolveEndpoint(options) ?? this.endpoint;
this.closeOnClickOutside = this.#resolveCloseOnClickOutside(options) ?? this.closeOnClickOutside;
this.closeOnEsc = this.#resolveCloseOnEsc(options) ?? this.closeOnEsc;
this.closeOnPaymentComplete = this.#resolveCloseOnPaymentComplete(options) ?? this.closeOnPaymentComplete;
this.defaultPaymentMethod = this.#resolveDefaultPaymentMethod(options) ?? this.defaultPaymentMethod;
}

Expand Down Expand Up @@ -414,6 +422,18 @@ export default class Checkout {
return options.closeOnEsc;
}

#resolveCloseOnPaymentComplete(options: CheckoutOptions) {
if (isNullOrUndefined(options.closeOnPaymentComplete))
return null;

if (!isBoolean(options.closeOnPaymentComplete)) {
warn(`invalid closeOnPaymentComplete option "${ options.closeOnPaymentComplete }" - must be a boolean`);
return null;
}

return options.closeOnPaymentComplete;
}

#resolveDefaultPaymentMethod(options: CheckoutOptions) {
if (isNullOrUndefined(options.defaultPaymentMethod))
return null;
Expand Down Expand Up @@ -480,6 +500,7 @@ export default class Checkout {
colors: this.colors,
closeOnClickOutside: this.closeOnClickOutside,
closeOnEsc: this.closeOnEsc,
closeOnPaymentComplete: this.closeOnPaymentComplete,
defaultPaymentMethod: this.defaultPaymentMethod,
theme: this.theme,
onOpenWindow: (url) => {
Expand Down
1 change: 1 addition & 0 deletions src/webComponents/TebexCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export const defineTebexCheckout = () => {
colors: colors,
closeOnClickOutside: getAttribute(this, "close-on-click-outside") !== null,
closeOnEsc: getAttribute(this, "close-on-esc") !== null,
closeOnPaymentComplete: getAttribute(this, "close-on-payment-complete") !== null,
defaultPaymentMethod: getAttribute(this, "default-payment-method"),
popupOnMobile: getAttribute(this, "popup-on-mobile") !== null,
endpoint: getAttribute(this, "endpoint"),
Expand Down
21 changes: 21 additions & 0 deletions tests/checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,27 @@ describe("Checkout", () => {
});
});

describe("closeOnPaymentComplete option", () => {

test("Can set closeOnPaymentComplete, which defaults to false", () => {
checkout.init({ ident: "test" });
expect(checkout.closeOnPaymentComplete).toBe(false);
checkout.init({ ident: "test", closeOnPaymentComplete: true });
expect(checkout.closeOnPaymentComplete).toBe(true);
});

test("Warns if closeOnPaymentComplete option isn't valid, and falls back to default", () => {
const spy = vi.spyOn(console, "warn").mockImplementation(() => {});
checkout.init({
ident: "test",
closeOnPaymentComplete: 123 as any
});
expect(spy).toHaveBeenCalledOnce();
expect(spy.mock.lastCall[0]).toContain("invalid closeOnPaymentComplete option");
expect(checkout.closeOnPaymentComplete).toBe(false);
});
});

describe("defaultPaymentMethod option", () => {

test("Can set defaultPaymentMethod, which defaults to undefined", () => {
Expand Down
3 changes: 3 additions & 0 deletions tests/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("Typechecks", () => {
theme?: "light" | "dark" | "default" | "auto";
closeOnClickOutside?: boolean;
closeOnEsc?: boolean;
closeOnPaymentComplete?: boolean;
colors?: {
name: "primary" | "secondary" | "background" | "surface" | "surface-variant" | "success" | "warning" | "error" | "green" | "red" | "fields" | "field-border",
color: string
Expand Down Expand Up @@ -92,6 +93,7 @@ describe("Typechecks", () => {
}[];
closeOnClickOutside: boolean;
closeOnEsc: boolean;
closeOnPaymentComplete: boolean;
defaultPaymentMethod?: string;
theme: "light" | "dark" | "default" | "auto";
onOpenWindow: (url: string) => void;
Expand Down Expand Up @@ -143,6 +145,7 @@ describe("Typechecks", () => {
theme?: "light" | "dark" | "default" | "auto";
closeOnClickOutside?: boolean;
closeOnEsc?: boolean;
closeOnPaymentComplete?: boolean;
colors?: {
name: "primary" | "secondary" | "background" | "surface" | "surface-variant" | "success" | "warning" | "error" | "green" | "red" | "fields" | "field-border",
color: string
Expand Down
4 changes: 3 additions & 1 deletion tests/webComponents/TebexCheckout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ describe("<tebex-checkout> Web component", () => {
expect(el.checkout.theme).toEqual("dark");
});

test("Close behavior can be set with the close-on-click-outside and close-on-esc attributes", () => {
test("Close behavior can be set with the close-on-click-outside, close-on-esc, and close-on-payment-complete attributes", () => {
const el = document.createElement("tebex-checkout") as TebexCheckout;
document.body.append(el);
el.setAttribute("close-on-click-outside", "aaaa");
el.setAttribute("close-on-esc", "aaaa");
el.setAttribute("close-on-payment-complete", "aaaa");
el.setAttribute("ident", __TEST_BASKET_IDENT__);

expect(el.checkout.closeOnClickOutside).toEqual(true);
expect(el.checkout.closeOnEsc).toEqual(true);
expect(el.checkout.closeOnPaymentComplete).toEqual(true);
});

test("Default payment method can be set with the default-payment-method attribute", () => {
Expand Down