@lightspeed/online-payments-sdk 1.8.0 → 1.9.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.
Files changed (39) hide show
  1. package/README.md +37 -0
  2. package/dist/cjs/index.js +4 -1
  3. package/dist/cjs/v1/EventBroadcaster.js +1 -0
  4. package/dist/cjs/v1/adyen/widget.js +4 -13
  5. package/dist/cjs/v1/stripe/localizedText.js +32 -0
  6. package/dist/cjs/v1/stripe/session.js +9 -0
  7. package/dist/cjs/v1/stripe/shared.js +55 -14
  8. package/dist/cjs/v1/stripe/terms.js +1 -1
  9. package/dist/cjs/v1/stripe/themes.js +2 -2
  10. package/dist/cjs/v1/stripe/widget.js +64 -25
  11. package/dist/cjs/v1/stripe/widgets/deferredMoto.js +203 -0
  12. package/dist/cjs/v1/widget.js +32 -4
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.js +3 -0
  16. package/dist/v1/EventBroadcaster.d.ts +18 -1
  17. package/dist/v1/EventBroadcaster.js +1 -0
  18. package/dist/v1/adyen/widget.js +4 -13
  19. package/dist/v1/common.d.ts +8 -2
  20. package/dist/v1/index.d.ts +2 -2
  21. package/dist/v1/stripe/localizedText.d.ts +3 -0
  22. package/dist/v1/stripe/localizedText.js +28 -0
  23. package/dist/v1/stripe/session.d.ts +29 -6
  24. package/dist/v1/stripe/session.js +7 -1
  25. package/dist/v1/stripe/shared.d.ts +8 -5
  26. package/dist/v1/stripe/shared.js +55 -15
  27. package/dist/v1/stripe/terms.d.ts +1 -1
  28. package/dist/v1/stripe/terms.js +1 -1
  29. package/dist/v1/stripe/themes.js +2 -2
  30. package/dist/v1/stripe/widget.js +62 -23
  31. package/dist/v1/stripe/widgets/deferredMoto.d.ts +5 -0
  32. package/dist/v1/stripe/widgets/deferredMoto.js +200 -0
  33. package/dist/v1/stripe/widgets/moto.d.ts +2 -2
  34. package/dist/v1/stripe/widgets/payment.d.ts +2 -2
  35. package/dist/v1/widget.js +32 -4
  36. package/dist/version.d.ts +1 -1
  37. package/dist/version.js +1 -1
  38. package/package.json +8 -3
  39. package/styles/lightspeed-global-styles.css +81 -1
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.mountDeferredMotoWidget = mountDeferredMotoWidget;
40
+ var error_1 = require("../../error");
41
+ var ResultBuilder_1 = require("../ResultBuilder");
42
+ var localizedText_1 = require("../localizedText");
43
+ var shared_1 = require("../shared");
44
+ function publishStripeError(error, eventBroadcaster) {
45
+ return eventBroadcaster.publish(ResultBuilder_1.EventBuilder.fromStripeError(error));
46
+ }
47
+ function mountDeferredMotoWidget(mountElement, session, eventBroadcaster, defaultValues, theme) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var _a, stripe, elements, paymentOptions, _b, paymentElement, paymentContainer, customTermsContainer, finalizationError, savePaymentMethod, revision, unmounted, completedSubmission, clearFinalizationError, invalidateSubmission, hasSaveOption, updateSaveCheckboxState, savePaymentMethodContainer, submission, failSubmission, submit;
50
+ var _this = this;
51
+ return __generator(this, function (_c) {
52
+ switch (_c.label) {
53
+ case 0: return [4 /*yield*/, (0, shared_1.initStripe)(session.context, theme)];
54
+ case 1:
55
+ _a = _c.sent(), stripe = _a.stripe, elements = _a.elements;
56
+ paymentOptions = (0, shared_1.createPaymentElementOptions)(defaultValues, theme, false, session.context.businessName);
57
+ _b = (0, shared_1.createPaymentElement)(elements, paymentOptions, mountElement, eventBroadcaster), paymentElement = _b.element, paymentContainer = _b.container, customTermsContainer = _b.customTermsContainer;
58
+ finalizationError = document.createElement('p');
59
+ finalizationError.className = 'stripe-finalization-error';
60
+ finalizationError.setAttribute('role', 'alert');
61
+ finalizationError.hidden = true;
62
+ paymentContainer.insertAdjacentElement('afterend', finalizationError);
63
+ savePaymentMethod = false;
64
+ revision = 0;
65
+ unmounted = false;
66
+ clearFinalizationError = function () {
67
+ finalizationError.hidden = true;
68
+ finalizationError.textContent = '';
69
+ };
70
+ invalidateSubmission = function () {
71
+ revision += 1;
72
+ completedSubmission = undefined;
73
+ clearFinalizationError();
74
+ };
75
+ hasSaveOption = session.metadata.sessionType === 'moto-with-save';
76
+ updateSaveCheckboxState = (0, shared_1.setupChangeEventHandler)(paymentElement, eventBroadcaster, null, invalidateSubmission, hasSaveOption ? false : undefined);
77
+ if (hasSaveOption) {
78
+ savePaymentMethodContainer = (0, shared_1.createSavePaymentMethodElement)(mountElement, function (checked) {
79
+ savePaymentMethod = checked;
80
+ invalidateSubmission();
81
+ updateSaveCheckboxState(savePaymentMethod);
82
+ }, session.context.locale);
83
+ }
84
+ failSubmission = function (message) {
85
+ eventBroadcaster.publish({ status: 'Error', code: 'Processing' });
86
+ throw new error_1.ProcessingError(message);
87
+ };
88
+ submit = function () {
89
+ if (unmounted) {
90
+ eventBroadcaster.publish({ status: 'Error', code: 'Processing' });
91
+ return Promise.reject(new error_1.ProcessingError('The payment widget has been unmounted'));
92
+ }
93
+ if ((completedSubmission === null || completedSubmission === void 0 ? void 0 : completedSubmission.revision) === revision) {
94
+ return Promise.resolve(completedSubmission.result);
95
+ }
96
+ if (submission) {
97
+ if (submission.revision === revision) {
98
+ return submission.promise;
99
+ }
100
+ return submission.promise.then(submit, submit);
101
+ }
102
+ var submissionRevision = revision;
103
+ var submissionSavePaymentMethod = savePaymentMethod;
104
+ clearFinalizationError();
105
+ var assertSubmissionIsCurrent = function () {
106
+ if (unmounted) {
107
+ return failSubmission('The payment widget was unmounted during submission');
108
+ }
109
+ if (revision !== submissionRevision) {
110
+ return failSubmission('Payment details or save consent changed during submission');
111
+ }
112
+ };
113
+ var promise = (function () { return __awaiter(_this, void 0, void 0, function () {
114
+ var submitResult, paymentMethodResult, result;
115
+ var _a;
116
+ return __generator(this, function (_b) {
117
+ switch (_b.label) {
118
+ case 0: return [4 /*yield*/, elements.submit()];
119
+ case 1:
120
+ submitResult = _b.sent();
121
+ assertSubmissionIsCurrent();
122
+ if (submitResult.error) {
123
+ return [2 /*return*/, publishStripeError(submitResult.error, eventBroadcaster)];
124
+ }
125
+ return [4 /*yield*/, stripe.createPaymentMethod({ elements: elements })];
126
+ case 2:
127
+ paymentMethodResult = _b.sent();
128
+ assertSubmissionIsCurrent();
129
+ if (paymentMethodResult.error) {
130
+ return [2 /*return*/, publishStripeError(paymentMethodResult.error, eventBroadcaster)];
131
+ }
132
+ if (!((_a = paymentMethodResult.paymentMethod) === null || _a === void 0 ? void 0 : _a.id)) {
133
+ eventBroadcaster.publish({ status: 'Error', code: 'Unexpected' });
134
+ throw new error_1.ProcessingError('Stripe did not return a PaymentMethod ID');
135
+ }
136
+ result = {
137
+ status: 'RequiresFinalization',
138
+ code: 'RequiresFinalization',
139
+ finalizationRequest: {
140
+ paymentData: {
141
+ type: 'payment-method',
142
+ id: paymentMethodResult.paymentMethod.id,
143
+ },
144
+ options: {
145
+ savePaymentMethod: submissionSavePaymentMethod,
146
+ },
147
+ },
148
+ };
149
+ completedSubmission = { revision: submissionRevision, result: result };
150
+ return [2 /*return*/, result];
151
+ }
152
+ });
153
+ }); })();
154
+ var currentSubmission = { revision: submissionRevision, promise: promise };
155
+ submission = currentSubmission;
156
+ var clearSubmission = function () {
157
+ if (submission === currentSubmission) {
158
+ submission = undefined;
159
+ }
160
+ };
161
+ promise.then(clearSubmission, clearSubmission);
162
+ return promise;
163
+ };
164
+ return [2 /*return*/, {
165
+ unmount: function () {
166
+ if (unmounted) {
167
+ return;
168
+ }
169
+ unmounted = true;
170
+ revision += 1;
171
+ completedSubmission = undefined;
172
+ (0, shared_1.cleanupElements)(paymentElement, null, paymentContainer, null, customTermsContainer);
173
+ finalizationError.remove();
174
+ savePaymentMethodContainer === null || savePaymentMethodContainer === void 0 ? void 0 : savePaymentMethodContainer.remove();
175
+ },
176
+ submit: submit,
177
+ reportFinalizationDecline: function (result, message) {
178
+ if (unmounted ||
179
+ (completedSubmission === null || completedSubmission === void 0 ? void 0 : completedSubmission.revision) !== revision ||
180
+ completedSubmission.result.finalizationRequest.paymentData.type !==
181
+ result.finalizationRequest.paymentData.type ||
182
+ completedSubmission.result.finalizationRequest.paymentData.id !==
183
+ result.finalizationRequest.paymentData.id ||
184
+ completedSubmission.result.finalizationRequest.options
185
+ .savePaymentMethod !==
186
+ result.finalizationRequest.options.savePaymentMethod) {
187
+ return;
188
+ }
189
+ invalidateSubmission();
190
+ var trimmedMessage = message.trim();
191
+ finalizationError.textContent =
192
+ trimmedMessage === 'Payment declined.' || !trimmedMessage
193
+ ? (0, localizedText_1.getCardDeclinedText)(session.context.locale)
194
+ : trimmedMessage;
195
+ finalizationError.hidden = false;
196
+ paymentElement.focus();
197
+ eventBroadcaster.publish({ status: 'Declined', code: 'Generic' });
198
+ },
199
+ }];
200
+ }
201
+ });
202
+ });
203
+ }
@@ -45,9 +45,19 @@ var error_1 = require("./error");
45
45
  var logger_1 = require("./logging/logger");
46
46
  var common_1 = require("./logging/common");
47
47
  var EventBroadcaster_1 = require("./EventBroadcaster");
48
+ var version_1 = require("../version");
49
+ // Exposes the running SDK version on the mount point so it can be inspected
50
+ // in browser devtools (e.g. `document.querySelector('[data-lightspeed-payments-sdk-version]')`).
51
+ var SDK_VERSION_ATTRIBUTE = 'data-lightspeed-payments-sdk-version';
52
+ function markMountPointWithSdkVersion(mountPoint) {
53
+ mountPoint.setAttribute(SDK_VERSION_ATTRIBUTE, version_1.SDK_VERSION);
54
+ }
55
+ function unmarkMountPointWithSdkVersion(mountPoint) {
56
+ mountPoint.removeAttribute(SDK_VERSION_ATTRIBUTE);
57
+ }
48
58
  function mountPaymentWidget(session, config) {
49
59
  return __awaiter(this, void 0, void 0, function () {
50
- var eventBroadcaster, decodedSession, logger_2, configSummary, widgetController, _a, error_2;
60
+ var eventBroadcaster, decodedSession, logger_2, configSummary, widgetController, _a, unmount_1, error_2;
51
61
  return __generator(this, function (_b) {
52
62
  switch (_b.label) {
53
63
  case 0:
@@ -86,8 +96,17 @@ function mountPaymentWidget(session, config) {
86
96
  return [3 /*break*/, 7];
87
97
  case 6: throw new error_1.UnsupportedLocationError();
88
98
  case 7:
99
+ markMountPointWithSdkVersion(config.mountPoint);
89
100
  widgetController.submit = (0, common_1.withLogging)(logger_2, 'Submit', widgetController.submit);
90
- widgetController.unmount = (0, common_1.withLogging)(logger_2, 'Unmount', widgetController.unmount);
101
+ unmount_1 = widgetController.unmount;
102
+ widgetController.unmount = (0, common_1.withLogging)(logger_2, 'Unmount', function () {
103
+ try {
104
+ unmount_1();
105
+ }
106
+ finally {
107
+ unmarkMountPointWithSdkVersion(config.mountPoint);
108
+ }
109
+ });
91
110
  return [2 /*return*/, widgetController];
92
111
  case 8:
93
112
  error_2 = _b.sent();
@@ -104,7 +123,7 @@ function mountPaymentWidget(session, config) {
104
123
  // Internal impl of v1.mountMultiStepWidget (additive; event-based flows unchanged).
105
124
  function mountMultiStepWidget(session, config) {
106
125
  return __awaiter(this, void 0, void 0, function () {
107
- var eventBroadcaster, decodedSession, logger_3, controller, _a, error_3;
126
+ var eventBroadcaster, decodedSession, logger_3, controller, _a, unmount_2, error_3;
108
127
  return __generator(this, function (_b) {
109
128
  switch (_b.label) {
110
129
  case 0:
@@ -137,9 +156,18 @@ function mountMultiStepWidget(session, config) {
137
156
  return [3 /*break*/, 5];
138
157
  case 4: throw new error_1.UnsupportedLocationError();
139
158
  case 5:
159
+ markMountPointWithSdkVersion(config.mountPoint);
140
160
  controller.submit = (0, common_1.withLogging)(logger_3, 'Submit', controller.submit);
141
161
  controller.handleNextAction = (0, common_1.withLogging)(logger_3, 'HandleNextAction', controller.handleNextAction);
142
- controller.unmount = (0, common_1.withLogging)(logger_3, 'Unmount', controller.unmount);
162
+ unmount_2 = controller.unmount;
163
+ controller.unmount = (0, common_1.withLogging)(logger_3, 'Unmount', function () {
164
+ try {
165
+ unmount_2();
166
+ }
167
+ finally {
168
+ unmarkMountPointWithSdkVersion(config.mountPoint);
169
+ }
170
+ });
143
171
  return [2 /*return*/, controller];
144
172
  case 6:
145
173
  error_3 = _b.sent();
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
4
  // This file is auto-generated during the build process
5
5
  // DO NOT EDIT MANUALLY - Version is extracted from package.json
6
- exports.SDK_VERSION = '1.8.0';
6
+ exports.SDK_VERSION = '1.9.1';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ import { SDK_VERSION } from './version';
1
2
  export type * from './v1';
2
3
  export { THEME_COLORS } from './v1';
4
+ export { SDK_VERSION };
3
5
  export declare const LightspeedPayments: {
4
6
  v1: import("./v1").LightspeedPaymentsV1;
7
+ version: string;
5
8
  };
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { v1 } from './v1';
2
+ import { SDK_VERSION } from './version';
2
3
  export { THEME_COLORS } from './v1';
4
+ export { SDK_VERSION };
3
5
  export var LightspeedPayments = {
4
6
  v1: v1,
7
+ version: SDK_VERSION,
5
8
  };
@@ -25,6 +25,23 @@ export type ChangeEvent = BaseEvent & {
25
25
  paymentMethodType?: string;
26
26
  saveCheckboxChecked?: boolean;
27
27
  };
28
+ export type RequiresFinalizationResult = {
29
+ status: 'RequiresFinalization';
30
+ code: 'RequiresFinalization';
31
+ /**
32
+ * Provider-neutral backend command. Integrations should forward this object
33
+ * unchanged to their Processing Service finalization endpoint.
34
+ */
35
+ finalizationRequest: {
36
+ paymentData: {
37
+ type: 'payment-method';
38
+ id: string;
39
+ };
40
+ options: {
41
+ savePaymentMethod: boolean;
42
+ };
43
+ };
44
+ };
28
45
  export type ErrorResultEvent = BaseEvent & {
29
46
  code: SupportedErrorCodes;
30
47
  status: 'Error';
@@ -42,6 +59,6 @@ export declare class EventBroadcaster {
42
59
  private convertInternalEventToExternal;
43
60
  registerMiddleware(middleware: EventMiddleware): void;
44
61
  applyMiddlewares(event: InternalEvent): Event;
45
- publish(event: InternalEvent): void;
62
+ publish(event: InternalEvent): Event;
46
63
  }
47
64
  export {};
@@ -63,6 +63,7 @@ var EventBroadcaster = /** @class */ (function () {
63
63
  var processedEvent = this.applyMiddlewares(event);
64
64
  var eventListener = this.listenersRegistry[event.status];
65
65
  eventListener(processedEvent);
66
+ return processedEvent;
66
67
  };
67
68
  return EventBroadcaster;
68
69
  }());
@@ -83,7 +83,7 @@ function mountSessionsFlow(mountElement, context, eventBroadcaster) {
83
83
  }
84
84
  // Multi-step Advanced flow: submit() surfaces the encrypted payment data for
85
85
  // the host to POST; handleNextAction() feeds the server response back to drive
86
- // native 3DS2. See MultiStepController in common.ts.
86
+ // 3DS actions. See MultiStepController in common.ts.
87
87
  function mountAdvancedFlow(mountElement, context, eventBroadcaster, onRequiresFinalization) {
88
88
  return __awaiter(this, void 0, void 0, function () {
89
89
  var stashedActions, pendingResolve, isValid, checkoutConfig, checkout, dropinConfiguration, dropIn;
@@ -164,7 +164,7 @@ function mountAdvancedFlow(mountElement, context, eventBroadcaster, onRequiresFi
164
164
  case 1:
165
165
  checkout = _b.sent();
166
166
  dropinConfiguration = {
167
- paymentMethodComponents: [Card, ApplePay, GooglePay, Bancontact],
167
+ paymentMethodComponents: [Card, ApplePay, GooglePay, Bancontact, Redirect],
168
168
  showStoredPaymentMethods: false,
169
169
  paymentMethodsConfiguration: {
170
170
  card: {
@@ -206,17 +206,8 @@ function mountAdvancedFlow(mountElement, context, eventBroadcaster, onRequiresFi
206
206
  var _a;
207
207
  var response = (serverResponse !== null && serverResponse !== void 0 ? serverResponse : {});
208
208
  if (response.action) {
209
- // 3DS1 (redirect) is out of scope: surface as an error so the host can
210
- // ask the shopper for a different card.
211
- if (response.action.type === 'redirect') {
212
- resolve({
213
- status: 'Error',
214
- error: { code: 'RedirectNotSupported', resultCode: response.resultCode },
215
- });
216
- return;
217
- }
218
- // Native 3DS2 step: let the component perform it, then resolve once
219
- // onAdditionalDetails hands us the next payload for the host to POST.
209
+ // Let Adyen Web perform the action. Native challenges call
210
+ // onAdditionalDetails; redirect actions navigate away to the issuer.
220
211
  pendingResolve = resolve;
221
212
  stashedActions === null || stashedActions === void 0 ? void 0 : stashedActions.resolve(response);
222
213
  return;
@@ -1,10 +1,16 @@
1
- import { EventBroadcaster, Event } from './EventBroadcaster';
1
+ import { EventBroadcaster, Event, RequiresFinalizationResult } from './EventBroadcaster';
2
2
  import { Session } from './session';
3
3
  import { PaymentWidgetTheme } from './widget';
4
4
  export type SessionType = 'payment' | 'payment-with-save' | 'moto' | 'moto-with-save' | 'save';
5
+ export type WidgetSubmitResult = Event | RequiresFinalizationResult;
5
6
  export type WidgetController = {
6
7
  unmount: () => void;
7
- submit: () => Promise<Event>;
8
+ submit: () => Promise<WidgetSubmitResult>;
9
+ /**
10
+ * Deferred MOTO only. Reports a definitive backend decline so the widget can
11
+ * present it and collect a fresh PaymentMethod on the next submission.
12
+ */
13
+ reportFinalizationDecline?: (result: RequiresFinalizationResult, message: string) => void;
8
14
  };
9
15
  export type MultiStepResult = {
10
16
  status: 'RequiresFinalization';
@@ -6,8 +6,8 @@
6
6
  */
7
7
  import { WidgetController, MultiStepController } from './common';
8
8
  import { PaymentWidgetConfiguration } from './widget';
9
- export type { WidgetController, MultiStepController, MultiStepResult, SessionType, DefaultValues, } from './common';
10
- export type { Event } from './EventBroadcaster';
9
+ export type { WidgetController, MultiStepController, MultiStepResult, SessionType, DefaultValues, WidgetSubmitResult, } from './common';
10
+ export type { Event, RequiresFinalizationResult } from './EventBroadcaster';
11
11
  export { UnsupportedLocationError, InvalidSessionPayloadError, InvalidSessionError, ProcessingError, } from './error';
12
12
  export type { PaymentWidgetConfiguration, PaymentWidgetTheme } from './widget';
13
13
  export { THEME_COLORS } from './stripe/themes';
@@ -0,0 +1,3 @@
1
+ /** Locale-selected UI text rendered alongside Stripe Elements. */
2
+ export declare function getSavePaymentMethodText(locale?: string): string;
3
+ export declare function getCardDeclinedText(locale?: string): string;
@@ -0,0 +1,28 @@
1
+ /** Locale-selected UI text rendered alongside Stripe Elements. */
2
+ var SAVE_PAYMENT_METHOD_TEXT = {
3
+ de: 'Zahlungsinformationen für zukünftige Einkäufe speichern',
4
+ en: 'Save payment details for future purchases',
5
+ fr: 'Enregistrer les informations de paiement pour vos prochains achats',
6
+ nl: 'Betaalgegevens opslaan voor toekomstige aankopen',
7
+ };
8
+ var CARD_DECLINED_TEXT = {
9
+ de: 'Ihre Karte wurde abgelehnt.',
10
+ en: 'Your card was declined.',
11
+ fr: 'Votre carte a été refusée.',
12
+ nl: 'Uw kaart is geweigerd.',
13
+ };
14
+ function getLanguage(locale) {
15
+ var _a;
16
+ var resolvedLocale = !locale || locale === 'auto'
17
+ ? ((_a = globalThis.navigator) === null || _a === void 0 ? void 0 : _a.language) || 'en'
18
+ : locale;
19
+ return resolvedLocale.toLowerCase().split('-')[0];
20
+ }
21
+ export function getSavePaymentMethodText(locale) {
22
+ var language = getLanguage(locale);
23
+ return SAVE_PAYMENT_METHOD_TEXT[language] || SAVE_PAYMENT_METHOD_TEXT.en;
24
+ }
25
+ export function getCardDeclinedText(locale) {
26
+ var language = getLanguage(locale);
27
+ return CARD_DECLINED_TEXT[language] || CARD_DECLINED_TEXT.en;
28
+ }
@@ -1,15 +1,38 @@
1
1
  import { StripeElementLocale } from '@stripe/stripe-js';
2
2
  import { BaseSession } from '../session';
3
- export type StripeSession = BaseSession & {
3
+ export type StripeBaseSession = BaseSession & {
4
4
  psp: 'STRIPE';
5
- context: StripeContext;
6
5
  };
7
- export type StripeContext = {
8
- clientSecret: string;
6
+ type StripeContextBase = {
9
7
  publishableKey: string;
8
+ locale?: StripeElementLocale;
9
+ businessName?: string;
10
+ };
11
+ export type IntentBoundStripeContext = StripeContextBase & {
12
+ intentMode?: 'intent-bound';
13
+ clientSecret: string;
10
14
  customerSessionClientSecret?: string;
11
15
  intent: 'save-card' | 'payment';
12
- locale?: StripeElementLocale;
13
16
  redirectUrl?: string;
14
- businessName?: string;
15
17
  };
18
+ export type DeferredStripeContext = StripeContextBase & {
19
+ intentMode: 'deferred';
20
+ intent: 'payment';
21
+ amount: number;
22
+ currency: string;
23
+ paymentMethodTypes: string[];
24
+ onBehalfOf: string;
25
+ clientSecret?: never;
26
+ customerSessionClientSecret?: never;
27
+ };
28
+ export type StripeContext = IntentBoundStripeContext | DeferredStripeContext;
29
+ export type IntentBoundStripeSession = StripeBaseSession & {
30
+ context: IntentBoundStripeContext;
31
+ };
32
+ export type DeferredStripeSession = StripeBaseSession & {
33
+ context: DeferredStripeContext;
34
+ };
35
+ export type StripeSession = IntentBoundStripeSession | DeferredStripeSession;
36
+ export declare function isDeferredStripeSession(session: StripeSession): session is DeferredStripeSession;
37
+ export declare function isIntentBoundStripeSession(session: StripeSession): session is IntentBoundStripeSession;
38
+ export {};
@@ -1 +1,7 @@
1
- export {};
1
+ export function isDeferredStripeSession(session) {
2
+ return session.context.intentMode === 'deferred';
3
+ }
4
+ export function isIntentBoundStripeSession(session) {
5
+ return (session.context.intentMode === undefined ||
6
+ session.context.intentMode === 'intent-bound');
7
+ }
@@ -1,6 +1,6 @@
1
1
  import { StripePaymentElementOptions, StripeAddressElementOptions } from '@stripe/stripe-js';
2
2
  import type { StripeElements, Stripe, StripeAddressElement, StripePaymentElement } from '@stripe/stripe-js';
3
- import { StripeContext, StripeSession } from './session';
3
+ import { IntentBoundStripeSession, StripeContext } from './session';
4
4
  import { DefaultValues } from '../common';
5
5
  import { EventBroadcaster } from '../EventBroadcaster';
6
6
  import { PaymentWidgetTheme } from '../widget';
@@ -45,6 +45,7 @@ export declare function buildCardConsentText(businessName: string, reason: strin
45
45
  * text.
46
46
  */
47
47
  export declare function createCardConsentElement(consentText: string): HTMLElement;
48
+ export declare function createSavePaymentMethodElement(mountElement: HTMLElement, onChange: (checked: boolean) => void, locale?: string): HTMLElement;
48
49
  /**
49
50
  * Create and mount payment element
50
51
  */
@@ -61,7 +62,9 @@ export declare function createPaymentElement(elements: StripeElements, options:
61
62
  * Also includes the current save-payment-method checkbox state (when present) on every Change event,
62
63
  * and emits a Change event when that checkbox state changes.
63
64
  */
64
- export declare function setupChangeEventHandler(paymentElement: StripePaymentElement, eventBroadcaster: EventBroadcaster, addressElement?: StripeAddressElement | null): void;
65
+ export declare function setupChangeEventHandler(paymentElement: StripePaymentElement, eventBroadcaster: EventBroadcaster, addressElement?: StripeAddressElement | null, onPaymentValueChange?: (value: {
66
+ savePaymentMethod?: boolean;
67
+ }) => void, initialSaveCheckboxState?: boolean): (saveCheckboxChecked: boolean) => void;
65
68
  /**
66
69
  * Create and mount address element
67
70
  */
@@ -76,12 +79,12 @@ export declare function cleanupElements(paymentElement: StripePaymentElement, ad
76
79
  /**
77
80
  * Handle save card operation
78
81
  */
79
- export declare function handleSaveCard(stripe: Stripe, elements: StripeElements, session: StripeSession, addressElement?: StripeAddressElement | null): Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").DeclinedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
82
+ export declare function handleSaveCard(stripe: Stripe, elements: StripeElements, session: IntentBoundStripeSession, addressElement?: StripeAddressElement | null): Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").DeclinedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
80
83
  /**
81
84
  * Handle payment operation
82
85
  */
83
- export declare function handlePayment(stripe: Stripe, elements: StripeElements, session: StripeSession, addressElement?: StripeAddressElement | null): Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").DeclinedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
86
+ export declare function handlePayment(stripe: Stripe, elements: StripeElements, session: IntentBoundStripeSession, addressElement?: StripeAddressElement | null): Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").DeclinedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
84
87
  /**
85
88
  * Create common submit handler for widgets
86
89
  */
87
- export declare function createSubmitHandler(stripe: Stripe, elements: StripeElements, session: StripeSession, eventBroadcaster: EventBroadcaster, addressElement?: StripeAddressElement | null): () => Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").DeclinedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
90
+ export declare function createSubmitHandler(stripe: Stripe, elements: StripeElements, session: IntentBoundStripeSession, eventBroadcaster: EventBroadcaster, addressElement?: StripeAddressElement | null): () => Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").DeclinedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;