@lightspeed/online-payments-sdk 1.1.5 → 1.2.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.
@@ -22,6 +22,7 @@ var EventBroadcaster = /** @class */ (function () {
22
22
  Pending: (listeners === null || listeners === void 0 ? void 0 : listeners.onPending) || noOpListener,
23
23
  Error: (listeners === null || listeners === void 0 ? void 0 : listeners.onError) || noOpListener,
24
24
  Ready: (listeners === null || listeners === void 0 ? void 0 : listeners.onReady) || noOpListener,
25
+ Change: (listeners === null || listeners === void 0 ? void 0 : listeners.onChange) || noOpListener,
25
26
  };
26
27
  }
27
28
  EventBroadcaster.prototype.convertInternalEventToExternal = function (event) {
@@ -181,11 +181,7 @@ function createCustomTermsElement() {
181
181
  /**
182
182
  * Create and mount payment element
183
183
  */
184
- function createPaymentElement(elements, options, mountElement, eventBroadcaster, theme) {
185
- // Apply theme class to mount element (generic approach)
186
- if (theme) {
187
- mountElement.classList.add("lsp-theme-".concat(theme));
188
- }
184
+ function createPaymentElement(elements, options, mountElement, eventBroadcaster) {
189
185
  var paymentElement = elements.create('payment', options);
190
186
  paymentElement.on('ready', function () {
191
187
  return eventBroadcaster.publish({ status: 'Ready', code: 'Ready' });
@@ -197,9 +193,18 @@ function createPaymentElement(elements, options, mountElement, eventBroadcaster,
197
193
  // Create custom terms element for US Bank Account
198
194
  var customTermsElement = createCustomTermsElement();
199
195
  mountElement.appendChild(customTermsElement);
200
- // Listen for payment method changes to show/hide custom terms
196
+ // Track previous complete state to only emit onChange event on state transitions
197
+ var previousComplete = null;
201
198
  paymentElement.on('change', function (event) {
202
199
  var _a;
200
+ // Emit onChange event only when "complete" status transitions
201
+ if (event.complete !== previousComplete) {
202
+ previousComplete = event.complete;
203
+ eventBroadcaster.publish({
204
+ status: 'Change',
205
+ code: event.complete ? 'Complete' : 'Incomplete',
206
+ });
207
+ }
203
208
  // Show custom terms only when US Bank Account is selected
204
209
  if (((_a = event.value) === null || _a === void 0 ? void 0 : _a.type) === 'us_bank_account') {
205
210
  customTermsElement.style.display = 'block';
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.THEME_COLORS = void 0;
4
+ exports.applyThemeClass = applyThemeClass;
5
+ exports.removeThemeClass = removeThemeClass;
4
6
  exports.getThemeConfig = getThemeConfig;
5
7
  /**
6
8
  * Theme color constants for styling containers
@@ -16,6 +18,20 @@ exports.THEME_COLORS = {
16
18
  * ID for the injected theme stylesheet element
17
19
  */
18
20
  var THEME_STYLESHEET_ID = 'lsp-theme-styles';
21
+ /**
22
+ * Apply theme class to an element
23
+ */
24
+ function applyThemeClass(element, theme) {
25
+ element.classList.add("lsp-theme-".concat(theme));
26
+ }
27
+ /**
28
+ * Remove theme class from an element
29
+ */
30
+ function removeThemeClass(element, theme) {
31
+ if (theme) {
32
+ element.classList.remove("lsp-theme-".concat(theme));
33
+ }
34
+ }
19
35
  /**
20
36
  * Inject theme stylesheets into the document head
21
37
  * Each theme can define its own container styling
@@ -26,7 +42,7 @@ function ensureThemeStylesheet() {
26
42
  }
27
43
  var styleElement = document.createElement('style');
28
44
  styleElement.id = THEME_STYLESHEET_ID;
29
- styleElement.textContent = "\n /* Dark theme styles for the mount element */\n .lsp-theme-dark {\n background-color: ".concat(exports.THEME_COLORS.DARK.BACKGROUND, " !important;\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n /* Dark theme styles for Stripe custom terms elements */\n .lsp-theme-dark .stripe-terms-triangle {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-custom-terms-text {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-expandable-terms-content p {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n \n /* Invoicing theme - no container styling needed */\n /* .lsp-theme-invoicing { } */\n ");
45
+ styleElement.textContent = "\n /* Dark theme styles for the mount element */\n .lsp-theme-dark {\n background-color: ".concat(exports.THEME_COLORS.DARK.BACKGROUND, " !important;\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n /* Dark theme styles for Stripe custom terms elements */\n .lsp-theme-dark .stripe-terms-triangle {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-custom-terms-text {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-expandable-terms-content p {\n color: ").concat(exports.THEME_COLORS.DARK.TEXT, " !important;\n }\n ");
30
46
  document.head.appendChild(styleElement);
31
47
  }
32
48
  /**
@@ -40,6 +40,7 @@ exports.StripeWidget = void 0;
40
40
  exports.mount = mount;
41
41
  var payment_1 = require("./widgets/payment");
42
42
  var moto_1 = require("./widgets/moto");
43
+ var themes_1 = require("./themes");
43
44
  /**
44
45
  * Main mount function that delegates to appropriate widget based on session type
45
46
  */
@@ -49,6 +50,10 @@ function mount(mountElement, session, eventBroadcaster, defaultValues, theme) {
49
50
  return __generator(this, function (_b) {
50
51
  switch (_b.label) {
51
52
  case 0:
53
+ // Apply theme class to mount element
54
+ if (theme) {
55
+ (0, themes_1.applyThemeClass)(mountElement, theme);
56
+ }
52
57
  sessionType = session.metadata.sessionType;
53
58
  _b.label = 1;
54
59
  case 1:
@@ -75,19 +80,14 @@ function mount(mountElement, session, eventBroadcaster, defaultValues, theme) {
75
80
  case 7:
76
81
  originalUnmount_1 = widgetController.unmount;
77
82
  widgetController.unmount = function () {
78
- // Remove theme class on unmount (generic cleanup)
79
- if (theme) {
80
- mountElement.classList.remove("lsp-theme-".concat(theme));
81
- }
83
+ (0, themes_1.removeThemeClass)(mountElement, theme);
82
84
  originalUnmount_1();
83
85
  };
84
86
  return [2 /*return*/, widgetController];
85
87
  case 8:
86
88
  error_1 = _b.sent();
87
89
  // Clean up theme class if mounting fails
88
- if (theme) {
89
- mountElement.classList.remove("lsp-theme-".concat(theme));
90
- }
90
+ (0, themes_1.removeThemeClass)(mountElement, theme);
91
91
  throw error_1;
92
92
  case 9: return [2 /*return*/];
93
93
  }
@@ -51,7 +51,7 @@ function mountMotoWidget(mountElement, session, eventBroadcaster, defaultValues,
51
51
  case 1:
52
52
  _a = _c.sent(), stripe = _a.stripe, elements = _a.elements;
53
53
  paymentOptions = (0, shared_1.createPaymentElementOptions)(defaultValues, theme);
54
- _b = (0, shared_1.createPaymentElement)(elements, paymentOptions, mountElement, eventBroadcaster, theme), paymentElement = _b.element, paymentContainer = _b.container, customTermsContainer = _b.customTermsContainer;
54
+ _b = (0, shared_1.createPaymentElement)(elements, paymentOptions, mountElement, eventBroadcaster), paymentElement = _b.element, paymentContainer = _b.container, customTermsContainer = _b.customTermsContainer;
55
55
  return [2 /*return*/, {
56
56
  unmount: function () {
57
57
  (0, shared_1.cleanupElements)(paymentElement, null, paymentContainer, null, customTermsContainer);
@@ -52,7 +52,7 @@ function mountPaymentWidget(mountElement, session, eventBroadcaster, defaultValu
52
52
  addressOptions = (0, shared_1.createAddressElementOptions)(defaultValues);
53
53
  _b = (0, shared_1.createAddressElement)(elements, addressOptions, mountElement), addressElement = _b.element, addressContainer = _b.container;
54
54
  paymentOptions = (0, shared_1.createPaymentElementOptions)(defaultValues, theme, true);
55
- _c = (0, shared_1.createPaymentElement)(elements, paymentOptions, mountElement, eventBroadcaster, theme), paymentElement = _c.element, paymentContainer = _c.container, customTermsContainer = _c.customTermsContainer;
55
+ _c = (0, shared_1.createPaymentElement)(elements, paymentOptions, mountElement, eventBroadcaster), paymentElement = _c.element, paymentContainer = _c.container, customTermsContainer = _c.customTermsContainer;
56
56
  return [2 /*return*/, {
57
57
  unmount: function () {
58
58
  (0, shared_1.cleanupElements)(paymentElement, addressElement, paymentContainer, addressContainer, customTermsContainer);
@@ -1,5 +1,5 @@
1
1
  import { SupportedErrorCodes } from './error';
2
- export type Status = 'Succeeded' | 'Declined' | 'Pending' | 'Error' | 'Ready';
2
+ export type Status = 'Succeeded' | 'Declined' | 'Pending' | 'Error' | 'Ready' | 'Change';
3
3
  export type BaseEvent = {
4
4
  loggingEnrichment?: object;
5
5
  };
@@ -19,11 +19,15 @@ export type ReadyEvent = BaseEvent & {
19
19
  status: 'Ready';
20
20
  code: 'Ready';
21
21
  };
22
+ export type ChangeEvent = BaseEvent & {
23
+ status: 'Change';
24
+ code: 'Complete' | 'Incomplete';
25
+ };
22
26
  export type ErrorResultEvent = BaseEvent & {
23
27
  code: SupportedErrorCodes;
24
28
  status: 'Error';
25
29
  };
26
- export type InternalEvent = SucceededResultEvent | PendingResultEvent | DeclinedResultEvent | ErrorResultEvent | ReadyEvent;
30
+ export type InternalEvent = SucceededResultEvent | PendingResultEvent | DeclinedResultEvent | ErrorResultEvent | ReadyEvent | ChangeEvent;
27
31
  export type Event = Omit<InternalEvent, 'loggingEnrichment'>;
28
32
  export type EventHandler = (result: Event) => void;
29
33
  export type EventMiddleware = (event: InternalEvent) => InternalEvent | void;
@@ -19,6 +19,7 @@ var EventBroadcaster = /** @class */ (function () {
19
19
  Pending: (listeners === null || listeners === void 0 ? void 0 : listeners.onPending) || noOpListener,
20
20
  Error: (listeners === null || listeners === void 0 ? void 0 : listeners.onError) || noOpListener,
21
21
  Ready: (listeners === null || listeners === void 0 ? void 0 : listeners.onReady) || noOpListener,
22
+ Change: (listeners === null || listeners === void 0 ? void 0 : listeners.onChange) || noOpListener,
22
23
  };
23
24
  }
24
25
  EventBroadcaster.prototype.convertInternalEventToExternal = function (event) {
@@ -30,7 +30,7 @@ export declare function createAddressElementOptions(defaultValues?: DefaultValue
30
30
  /**
31
31
  * Create and mount payment element
32
32
  */
33
- export declare function createPaymentElement(elements: StripeElements, options: StripePaymentElementOptions, mountElement: HTMLElement, eventBroadcaster: EventBroadcaster, theme?: PaymentWidgetTheme): {
33
+ export declare function createPaymentElement(elements: StripeElements, options: StripePaymentElementOptions, mountElement: HTMLElement, eventBroadcaster: EventBroadcaster): {
34
34
  element: StripePaymentElement;
35
35
  container: HTMLElement;
36
36
  customTermsContainer: HTMLElement;
@@ -170,11 +170,7 @@ function createCustomTermsElement() {
170
170
  /**
171
171
  * Create and mount payment element
172
172
  */
173
- export function createPaymentElement(elements, options, mountElement, eventBroadcaster, theme) {
174
- // Apply theme class to mount element (generic approach)
175
- if (theme) {
176
- mountElement.classList.add("lsp-theme-".concat(theme));
177
- }
173
+ export function createPaymentElement(elements, options, mountElement, eventBroadcaster) {
178
174
  var paymentElement = elements.create('payment', options);
179
175
  paymentElement.on('ready', function () {
180
176
  return eventBroadcaster.publish({ status: 'Ready', code: 'Ready' });
@@ -186,9 +182,18 @@ export function createPaymentElement(elements, options, mountElement, eventBroad
186
182
  // Create custom terms element for US Bank Account
187
183
  var customTermsElement = createCustomTermsElement();
188
184
  mountElement.appendChild(customTermsElement);
189
- // Listen for payment method changes to show/hide custom terms
185
+ // Track previous complete state to only emit onChange event on state transitions
186
+ var previousComplete = null;
190
187
  paymentElement.on('change', function (event) {
191
188
  var _a;
189
+ // Emit onChange event only when "complete" status transitions
190
+ if (event.complete !== previousComplete) {
191
+ previousComplete = event.complete;
192
+ eventBroadcaster.publish({
193
+ status: 'Change',
194
+ code: event.complete ? 'Complete' : 'Incomplete',
195
+ });
196
+ }
192
197
  // Show custom terms only when US Bank Account is selected
193
198
  if (((_a = event.value) === null || _a === void 0 ? void 0 : _a.type) === 'us_bank_account') {
194
199
  customTermsElement.style.display = 'block';
@@ -10,6 +10,14 @@ export declare const THEME_COLORS: {
10
10
  readonly TEXT: "#ffffff";
11
11
  };
12
12
  };
13
+ /**
14
+ * Apply theme class to an element
15
+ */
16
+ export declare function applyThemeClass(element: HTMLElement, theme: PaymentWidgetTheme): void;
17
+ /**
18
+ * Remove theme class from an element
19
+ */
20
+ export declare function removeThemeClass(element: HTMLElement, theme?: PaymentWidgetTheme): void;
13
21
  /**
14
22
  * Theme configuration for Stripe Elements appearance
15
23
  */
@@ -12,6 +12,20 @@ export var THEME_COLORS = {
12
12
  * ID for the injected theme stylesheet element
13
13
  */
14
14
  var THEME_STYLESHEET_ID = 'lsp-theme-styles';
15
+ /**
16
+ * Apply theme class to an element
17
+ */
18
+ export function applyThemeClass(element, theme) {
19
+ element.classList.add("lsp-theme-".concat(theme));
20
+ }
21
+ /**
22
+ * Remove theme class from an element
23
+ */
24
+ export function removeThemeClass(element, theme) {
25
+ if (theme) {
26
+ element.classList.remove("lsp-theme-".concat(theme));
27
+ }
28
+ }
15
29
  /**
16
30
  * Inject theme stylesheets into the document head
17
31
  * Each theme can define its own container styling
@@ -22,7 +36,7 @@ function ensureThemeStylesheet() {
22
36
  }
23
37
  var styleElement = document.createElement('style');
24
38
  styleElement.id = THEME_STYLESHEET_ID;
25
- styleElement.textContent = "\n /* Dark theme styles for the mount element */\n .lsp-theme-dark {\n background-color: ".concat(THEME_COLORS.DARK.BACKGROUND, " !important;\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n /* Dark theme styles for Stripe custom terms elements */\n .lsp-theme-dark .stripe-terms-triangle {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-custom-terms-text {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-expandable-terms-content p {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n \n /* Invoicing theme - no container styling needed */\n /* .lsp-theme-invoicing { } */\n ");
39
+ styleElement.textContent = "\n /* Dark theme styles for the mount element */\n .lsp-theme-dark {\n background-color: ".concat(THEME_COLORS.DARK.BACKGROUND, " !important;\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n /* Dark theme styles for Stripe custom terms elements */\n .lsp-theme-dark .stripe-terms-triangle {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-custom-terms-text {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n .lsp-theme-dark .stripe-expandable-terms-content p {\n color: ").concat(THEME_COLORS.DARK.TEXT, " !important;\n }\n ");
26
40
  document.head.appendChild(styleElement);
27
41
  }
28
42
  /**
@@ -36,6 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  };
37
37
  import { mountPaymentWidget } from './widgets/payment';
38
38
  import { mountMotoWidget } from './widgets/moto';
39
+ import { applyThemeClass, removeThemeClass } from './themes';
39
40
  /**
40
41
  * Main mount function that delegates to appropriate widget based on session type
41
42
  */
@@ -45,6 +46,10 @@ export function mount(mountElement, session, eventBroadcaster, defaultValues, th
45
46
  return __generator(this, function (_b) {
46
47
  switch (_b.label) {
47
48
  case 0:
49
+ // Apply theme class to mount element
50
+ if (theme) {
51
+ applyThemeClass(mountElement, theme);
52
+ }
48
53
  sessionType = session.metadata.sessionType;
49
54
  _b.label = 1;
50
55
  case 1:
@@ -71,19 +76,14 @@ export function mount(mountElement, session, eventBroadcaster, defaultValues, th
71
76
  case 7:
72
77
  originalUnmount_1 = widgetController.unmount;
73
78
  widgetController.unmount = function () {
74
- // Remove theme class on unmount (generic cleanup)
75
- if (theme) {
76
- mountElement.classList.remove("lsp-theme-".concat(theme));
77
- }
79
+ removeThemeClass(mountElement, theme);
78
80
  originalUnmount_1();
79
81
  };
80
82
  return [2 /*return*/, widgetController];
81
83
  case 8:
82
84
  error_1 = _b.sent();
83
85
  // Clean up theme class if mounting fails
84
- if (theme) {
85
- mountElement.classList.remove("lsp-theme-".concat(theme));
86
- }
86
+ removeThemeClass(mountElement, theme);
87
87
  throw error_1;
88
88
  case 9: return [2 /*return*/];
89
89
  }
@@ -48,7 +48,7 @@ export function mountMotoWidget(mountElement, session, eventBroadcaster, default
48
48
  case 1:
49
49
  _a = _c.sent(), stripe = _a.stripe, elements = _a.elements;
50
50
  paymentOptions = createPaymentElementOptions(defaultValues, theme);
51
- _b = createPaymentElement(elements, paymentOptions, mountElement, eventBroadcaster, theme), paymentElement = _b.element, paymentContainer = _b.container, customTermsContainer = _b.customTermsContainer;
51
+ _b = createPaymentElement(elements, paymentOptions, mountElement, eventBroadcaster), paymentElement = _b.element, paymentContainer = _b.container, customTermsContainer = _b.customTermsContainer;
52
52
  return [2 /*return*/, {
53
53
  unmount: function () {
54
54
  cleanupElements(paymentElement, null, paymentContainer, null, customTermsContainer);
@@ -49,7 +49,7 @@ export function mountPaymentWidget(mountElement, session, eventBroadcaster, defa
49
49
  addressOptions = createAddressElementOptions(defaultValues);
50
50
  _b = createAddressElement(elements, addressOptions, mountElement), addressElement = _b.element, addressContainer = _b.container;
51
51
  paymentOptions = createPaymentElementOptions(defaultValues, theme, true);
52
- _c = createPaymentElement(elements, paymentOptions, mountElement, eventBroadcaster, theme), paymentElement = _c.element, paymentContainer = _c.container, customTermsContainer = _c.customTermsContainer;
52
+ _c = createPaymentElement(elements, paymentOptions, mountElement, eventBroadcaster), paymentElement = _c.element, paymentContainer = _c.container, customTermsContainer = _c.customTermsContainer;
53
53
  return [2 /*return*/, {
54
54
  unmount: function () {
55
55
  cleanupElements(paymentElement, addressElement, paymentContainer, addressContainer, customTermsContainer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed/online-payments-sdk",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Process online-payments with Lightspeed Payments",
5
5
  "author": "Lightspeed Commerce Inc.",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -20,10 +20,6 @@
20
20
  text-decoration: underline;
21
21
  }
22
22
 
23
- .stripe-custom-terms-text a:hover {
24
- color: #0a2540;
25
- }
26
-
27
23
  /* Expandable terms toggle */
28
24
  .stripe-expandable-terms-toggle {
29
25
  color: #635bff;
@@ -31,10 +27,6 @@
31
27
  text-decoration: underline;
32
28
  }
33
29
 
34
- .stripe-expandable-terms-toggle:hover {
35
- color: #0a2540;
36
- }
37
-
38
30
  .stripe-terms-triangle {
39
31
  display: inline-block;
40
32
  font-size: 10px;