@lightspeed/online-payments-sdk 1.1.6 → 1.2.1

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) {
@@ -193,9 +193,18 @@ function createPaymentElement(elements, options, mountElement, eventBroadcaster)
193
193
  // Create custom terms element for US Bank Account
194
194
  var customTermsElement = createCustomTermsElement();
195
195
  mountElement.appendChild(customTermsElement);
196
- // 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;
197
198
  paymentElement.on('change', function (event) {
198
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
+ }
199
208
  // Show custom terms only when US Bank Account is selected
200
209
  if (((_a = event.value) === null || _a === void 0 ? void 0 : _a.type) === 'us_bank_account') {
201
210
  customTermsElement.style.display = 'block';
@@ -88,10 +88,7 @@ function getThemeConfig(theme) {
88
88
  appearance: {
89
89
  theme: 'night',
90
90
  },
91
- fonts: [],
92
- layout: {
93
- type: 'tabs',
94
- },
91
+ fonts: []
95
92
  };
96
93
  default:
97
94
  return undefined;
@@ -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) {
@@ -182,9 +182,18 @@ export function createPaymentElement(elements, options, mountElement, eventBroad
182
182
  // Create custom terms element for US Bank Account
183
183
  var customTermsElement = createCustomTermsElement();
184
184
  mountElement.appendChild(customTermsElement);
185
- // 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;
186
187
  paymentElement.on('change', function (event) {
187
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
+ }
188
197
  // Show custom terms only when US Bank Account is selected
189
198
  if (((_a = event.value) === null || _a === void 0 ? void 0 : _a.type) === 'us_bank_account') {
190
199
  customTermsElement.style.display = 'block';
@@ -26,7 +26,7 @@ export interface ThemeConfig {
26
26
  fonts: Array<{
27
27
  cssSrc: string;
28
28
  }>;
29
- layout: {
29
+ layout?: {
30
30
  type: 'tabs' | 'accordion';
31
31
  };
32
32
  }
@@ -82,10 +82,7 @@ export function getThemeConfig(theme) {
82
82
  appearance: {
83
83
  theme: 'night',
84
84
  },
85
- fonts: [],
86
- layout: {
87
- type: 'tabs',
88
- },
85
+ fonts: []
89
86
  };
90
87
  default:
91
88
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed/online-payments-sdk",
3
- "version": "1.1.6",
3
+ "version": "1.2.1",
4
4
  "description": "Process online-payments with Lightspeed Payments",
5
5
  "author": "Lightspeed Commerce Inc.",
6
6
  "license": "SEE LICENSE IN LICENSE.md",