@lightspeed/online-payments-sdk 1.0.5 → 1.1.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/dist/cjs/v1/adyen/widget.js +2 -2
- package/dist/cjs/v1/stripe/index.js +32 -0
- package/dist/cjs/v1/stripe/shared.js +266 -0
- package/dist/cjs/v1/stripe/themes.js +43 -0
- package/dist/cjs/v1/stripe/widget.js +20 -142
- package/dist/cjs/v1/stripe/widgets/moto.js +64 -0
- package/dist/cjs/v1/stripe/widgets/payment.js +65 -0
- package/dist/cjs/v1/widget.js +2 -2
- package/dist/v1/adyen/session.d.ts +2 -1
- package/dist/v1/adyen/widget.d.ts +2 -2
- package/dist/v1/adyen/widget.js +2 -2
- package/dist/v1/common.d.ts +5 -2
- package/dist/v1/index.d.ts +2 -2
- package/dist/v1/session.d.ts +6 -3
- package/dist/v1/stripe/index.d.ts +7 -0
- package/dist/v1/stripe/index.js +12 -0
- package/dist/v1/stripe/session.d.ts +4 -2
- package/dist/v1/stripe/shared.d.ts +56 -0
- package/dist/v1/stripe/shared.js +255 -0
- package/dist/v1/stripe/themes.d.ts +18 -0
- package/dist/v1/stripe/themes.js +40 -0
- package/dist/v1/stripe/widget.d.ts +7 -3
- package/dist/v1/stripe/widget.js +20 -142
- package/dist/v1/stripe/widgets/moto.d.ts +9 -0
- package/dist/v1/stripe/widgets/moto.js +61 -0
- package/dist/v1/stripe/widgets/payment.d.ts +8 -0
- package/dist/v1/stripe/widgets/payment.js +62 -0
- package/dist/v1/widget.d.ts +2 -0
- package/dist/v1/widget.js +2 -2
- package/package.json +1 -1
package/dist/cjs/v1/widget.js
CHANGED
|
@@ -70,11 +70,11 @@ function mountPaymentWidget(session, config) {
|
|
|
70
70
|
case 'STRIPE': return [3 /*break*/, 4];
|
|
71
71
|
}
|
|
72
72
|
return [3 /*break*/, 6];
|
|
73
|
-
case 2: return [4 /*yield*/, widget_1.AdyenWidget.mount(config.mountPoint, decodedSession
|
|
73
|
+
case 2: return [4 /*yield*/, widget_1.AdyenWidget.mount(config.mountPoint, decodedSession, eventBroadcaster)];
|
|
74
74
|
case 3:
|
|
75
75
|
widgetController = _b.sent();
|
|
76
76
|
return [3 /*break*/, 7];
|
|
77
|
-
case 4: return [4 /*yield*/, widget_2.StripeWidget.mount(config.mountPoint, decodedSession
|
|
77
|
+
case 4: return [4 /*yield*/, widget_2.StripeWidget.mount(config.mountPoint, decodedSession, eventBroadcaster, config.defaultValues, config.theme)];
|
|
78
78
|
case 5:
|
|
79
79
|
widgetController = _b.sent();
|
|
80
80
|
return [3 /*break*/, 7];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AdyenSession } from './session';
|
|
2
2
|
import { WidgetInterface } from '../common';
|
|
3
|
-
export declare const AdyenWidget: WidgetInterface<
|
|
3
|
+
export declare const AdyenWidget: WidgetInterface<AdyenSession>;
|
package/dist/v1/adyen/widget.js
CHANGED
|
@@ -36,13 +36,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
import { AdyenCheckout, Dropin, Card, GooglePay, ApplePay, } from '@adyen/adyen-web';
|
|
38
38
|
import { ResultBuilder } from './ResultBuilder';
|
|
39
|
-
function mount(mountElement,
|
|
39
|
+
function mount(mountElement, session, eventBroadcaster) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function () {
|
|
41
41
|
var checkoutConfig, checkout, dropinConfiguration, dropIn;
|
|
42
42
|
return __generator(this, function (_a) {
|
|
43
43
|
switch (_a.label) {
|
|
44
44
|
case 0:
|
|
45
|
-
checkoutConfig = createAdyenConfiguration(context, eventBroadcaster);
|
|
45
|
+
checkoutConfig = createAdyenConfiguration(session.context, eventBroadcaster);
|
|
46
46
|
return [4 /*yield*/, AdyenCheckout(checkoutConfig)];
|
|
47
47
|
case 1:
|
|
48
48
|
checkout = _a.sent();
|
package/dist/v1/common.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { EventBroadcaster, Event } from './EventBroadcaster';
|
|
2
|
+
import { Session } from './session';
|
|
3
|
+
import { PaymentWidgetTheme } from './widget';
|
|
4
|
+
export type SessionType = 'payment' | 'payment-with-save' | 'moto' | 'moto-with-save' | 'save';
|
|
2
5
|
export type WidgetController = {
|
|
3
6
|
unmount: () => void;
|
|
4
7
|
submit: () => Promise<Event>;
|
|
@@ -7,6 +10,6 @@ export type DefaultValues = {
|
|
|
7
10
|
country?: string;
|
|
8
11
|
postalCode?: string;
|
|
9
12
|
};
|
|
10
|
-
export interface WidgetInterface<T> {
|
|
11
|
-
mount: (mountElement: HTMLElement,
|
|
13
|
+
export interface WidgetInterface<T extends Session> {
|
|
14
|
+
mount: (mountElement: HTMLElement, session: T, eventBroadcaster: EventBroadcaster, defaultValues?: DefaultValues, theme?: PaymentWidgetTheme) => Promise<WidgetController>;
|
|
12
15
|
}
|
package/dist/v1/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { WidgetController } from './common';
|
|
8
8
|
import { PaymentWidgetConfiguration } from './widget';
|
|
9
|
-
export type { WidgetController } from './common';
|
|
9
|
+
export type { WidgetController, SessionType } from './common';
|
|
10
10
|
export type { Event } from './EventBroadcaster';
|
|
11
11
|
export { UnsupportedLocationError, InvalidSessionPayloadError, InvalidSessionError, ProcessingError, } from './error';
|
|
12
|
-
export type { PaymentWidgetConfiguration } from './widget';
|
|
12
|
+
export type { PaymentWidgetConfiguration, PaymentWidgetTheme } from './widget';
|
|
13
13
|
export type LightspeedPaymentsV1 = {
|
|
14
14
|
/**
|
|
15
15
|
* Mounts the payment widget to the specified mount point.
|
package/dist/v1/session.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { LoggingConfig } from './logging/logger';
|
|
2
2
|
import { AdyenSession } from './adyen/session';
|
|
3
|
+
import { SessionType } from './common';
|
|
3
4
|
import { StripeSession } from './stripe/session';
|
|
4
|
-
type
|
|
5
|
-
|
|
5
|
+
export type SessionMetadata = {
|
|
6
|
+
sessionType?: SessionType;
|
|
7
|
+
} & Record<string, string>;
|
|
8
|
+
export type BaseSession = {
|
|
9
|
+
metadata: SessionMetadata;
|
|
6
10
|
logging?: LoggingConfig;
|
|
7
11
|
};
|
|
8
12
|
export type Session = BaseSession & (AdyenSession | StripeSession);
|
|
9
13
|
export declare function decodePaymentSessionToContext(paymentSession: string): Session;
|
|
10
14
|
export declare function isTokenValid(token: unknown): token is Session;
|
|
11
|
-
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { StripeWidget } from './widget';
|
|
2
|
+
export { mountPaymentWidget } from './widgets/payment';
|
|
3
|
+
export { mountMotoWidget } from './widgets/moto';
|
|
4
|
+
export * from './shared';
|
|
5
|
+
export * from './themes';
|
|
6
|
+
export * from './session';
|
|
7
|
+
export * from './ResultBuilder';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Main widget interface
|
|
2
|
+
export { StripeWidget } from './widget';
|
|
3
|
+
// Individual widget modules
|
|
4
|
+
export { mountPaymentWidget } from './widgets/payment';
|
|
5
|
+
export { mountMotoWidget } from './widgets/moto';
|
|
6
|
+
// Shared utilities
|
|
7
|
+
export * from './shared';
|
|
8
|
+
// Theme configurations
|
|
9
|
+
export * from './themes';
|
|
10
|
+
// Session and types
|
|
11
|
+
export * from './session';
|
|
12
|
+
export * from './ResultBuilder';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StripeElementLocale } from
|
|
2
|
-
|
|
1
|
+
import { StripeElementLocale } from '@stripe/stripe-js';
|
|
2
|
+
import { BaseSession } from '../session';
|
|
3
|
+
export type StripeSession = BaseSession & {
|
|
3
4
|
psp: 'STRIPE';
|
|
4
5
|
context: StripeContext;
|
|
5
6
|
};
|
|
@@ -9,4 +10,5 @@ export type StripeContext = {
|
|
|
9
10
|
customerSessionClientSecret?: string;
|
|
10
11
|
intent: 'save-card' | 'payment';
|
|
11
12
|
locale?: StripeElementLocale;
|
|
13
|
+
redirectUrl?: string;
|
|
12
14
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { StripePaymentElementOptions, StripeAddressElementOptions } from '@stripe/stripe-js';
|
|
2
|
+
import type { StripeElements, Stripe, StripeAddressElement, StripePaymentElement } from '@stripe/stripe-js';
|
|
3
|
+
import { StripeContext, StripeSession } from './session';
|
|
4
|
+
import { DefaultValues } from '../common';
|
|
5
|
+
import { EventBroadcaster } from '../EventBroadcaster';
|
|
6
|
+
import { PaymentWidgetTheme } from '../widget';
|
|
7
|
+
export interface StripeInitResult {
|
|
8
|
+
stripe: Stripe;
|
|
9
|
+
elements: StripeElements;
|
|
10
|
+
}
|
|
11
|
+
export interface ElementContainers {
|
|
12
|
+
addressContainer: HTMLElement | null;
|
|
13
|
+
paymentContainer: HTMLElement;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Initialize Stripe with the given context
|
|
17
|
+
*/
|
|
18
|
+
export declare function initStripe(context: StripeContext, theme?: PaymentWidgetTheme): Promise<StripeInitResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Create payment element options with default wallet settings
|
|
21
|
+
*/
|
|
22
|
+
export declare function createPaymentElementOptions(defaultValues?: DefaultValues, theme?: PaymentWidgetTheme): StripePaymentElementOptions;
|
|
23
|
+
/**
|
|
24
|
+
* Create address element options
|
|
25
|
+
*/
|
|
26
|
+
export declare function createAddressElementOptions(defaultValues?: DefaultValues): StripeAddressElementOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Create and mount payment element
|
|
29
|
+
*/
|
|
30
|
+
export declare function createPaymentElement(elements: StripeElements, options: StripePaymentElementOptions, mountElement: HTMLElement, eventBroadcaster: EventBroadcaster): {
|
|
31
|
+
element: StripePaymentElement;
|
|
32
|
+
container: HTMLElement;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Create and mount address element
|
|
36
|
+
*/
|
|
37
|
+
export declare function createAddressElement(elements: StripeElements, options: StripeAddressElementOptions, mountElement: HTMLElement): {
|
|
38
|
+
element: StripeAddressElement;
|
|
39
|
+
container: HTMLElement;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Clean up elements and containers
|
|
43
|
+
*/
|
|
44
|
+
export declare function cleanupElements(paymentElement: StripePaymentElement, addressElement: StripeAddressElement | null, paymentContainer: HTMLElement, addressContainer: HTMLElement | null): void;
|
|
45
|
+
/**
|
|
46
|
+
* Handle save card operation
|
|
47
|
+
*/
|
|
48
|
+
export declare function handleSaveCard(stripe: Stripe, elements: StripeElements, session: StripeSession): Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").RefusedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
|
|
49
|
+
/**
|
|
50
|
+
* Handle payment operation
|
|
51
|
+
*/
|
|
52
|
+
export declare function handlePayment(stripe: Stripe, elements: StripeElements, session: StripeSession): Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").RefusedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
|
|
53
|
+
/**
|
|
54
|
+
* Create common submit handler for widgets
|
|
55
|
+
*/
|
|
56
|
+
export declare function createSubmitHandler(stripe: Stripe, elements: StripeElements, session: StripeSession, eventBroadcaster: EventBroadcaster): () => Promise<import("../EventBroadcaster").SucceededResultEvent | import("../EventBroadcaster").PendingResultEvent | import("../EventBroadcaster").RefusedResultEvent | import("../EventBroadcaster").ErrorResultEvent>;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
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);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { loadStripe, } from '@stripe/stripe-js';
|
|
49
|
+
import { EventBuilder } from './ResultBuilder';
|
|
50
|
+
import { InvalidSessionPayloadError, ProcessingError } from '../error';
|
|
51
|
+
import { getThemeConfig } from './themes';
|
|
52
|
+
/**
|
|
53
|
+
* Initialize Stripe with the given context
|
|
54
|
+
*/
|
|
55
|
+
export function initStripe(context, theme) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var publishableKey, clientSecret, customerSessionClientSecret, loadedStripe, stripe, themeConfig, elementsOptions, elements;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
publishableKey = context.publishableKey, clientSecret = context.clientSecret, customerSessionClientSecret = context.customerSessionClientSecret;
|
|
62
|
+
return [4 /*yield*/, loadStripe(publishableKey)];
|
|
63
|
+
case 1:
|
|
64
|
+
loadedStripe = _a.sent();
|
|
65
|
+
if (!loadedStripe) {
|
|
66
|
+
throw new Error('Failed to initialize Stripe');
|
|
67
|
+
}
|
|
68
|
+
stripe = loadedStripe;
|
|
69
|
+
themeConfig = getThemeConfig(theme);
|
|
70
|
+
elementsOptions = __assign(__assign(__assign({ clientSecret: clientSecret, customerSessionClientSecret: customerSessionClientSecret }, (context.locale && { locale: context.locale })), (themeConfig && { appearance: themeConfig.appearance })), (themeConfig && { fonts: themeConfig.fonts }));
|
|
71
|
+
elements = stripe.elements(elementsOptions);
|
|
72
|
+
return [2 /*return*/, { stripe: stripe, elements: elements }];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create payment element options with default wallet settings
|
|
79
|
+
*/
|
|
80
|
+
export function createPaymentElementOptions(defaultValues, theme) {
|
|
81
|
+
var options = {
|
|
82
|
+
wallets: {
|
|
83
|
+
applePay: 'never',
|
|
84
|
+
googlePay: 'never',
|
|
85
|
+
link: 'never',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
if (defaultValues) {
|
|
89
|
+
options.defaultValues = {
|
|
90
|
+
billingDetails: {
|
|
91
|
+
address: {
|
|
92
|
+
country: defaultValues.country,
|
|
93
|
+
postal_code: defaultValues.postalCode,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Apply theme layout configuration
|
|
99
|
+
if (theme) {
|
|
100
|
+
var themeConfig = getThemeConfig(theme);
|
|
101
|
+
if (themeConfig === null || themeConfig === void 0 ? void 0 : themeConfig.layout) {
|
|
102
|
+
options.layout = themeConfig.layout;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return options;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create address element options
|
|
109
|
+
*/
|
|
110
|
+
export function createAddressElementOptions(defaultValues) {
|
|
111
|
+
var addressOptions = {
|
|
112
|
+
mode: 'billing',
|
|
113
|
+
};
|
|
114
|
+
if (defaultValues === null || defaultValues === void 0 ? void 0 : defaultValues.country) {
|
|
115
|
+
addressOptions.defaultValues = {
|
|
116
|
+
address: {
|
|
117
|
+
country: defaultValues.country,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return addressOptions;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create and mount payment element
|
|
125
|
+
*/
|
|
126
|
+
export function createPaymentElement(elements, options, mountElement, eventBroadcaster) {
|
|
127
|
+
var paymentElement = elements.create('payment', options);
|
|
128
|
+
paymentElement.on('ready', function () {
|
|
129
|
+
return eventBroadcaster.publish({ status: 'Ready', code: 'Ready' });
|
|
130
|
+
});
|
|
131
|
+
var paymentContainer = document.createElement('div');
|
|
132
|
+
paymentContainer.className = 'stripe-payment-element-container';
|
|
133
|
+
mountElement.appendChild(paymentContainer);
|
|
134
|
+
paymentElement.mount(paymentContainer);
|
|
135
|
+
return { element: paymentElement, container: paymentContainer };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create and mount address element
|
|
139
|
+
*/
|
|
140
|
+
export function createAddressElement(elements, options, mountElement) {
|
|
141
|
+
var addressElement = elements.create('address', options);
|
|
142
|
+
var addressContainer = document.createElement('div');
|
|
143
|
+
addressContainer.className = 'stripe-address-element-container';
|
|
144
|
+
mountElement.appendChild(addressContainer);
|
|
145
|
+
addressElement.mount(addressContainer);
|
|
146
|
+
return { element: addressElement, container: addressContainer };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Clean up elements and containers
|
|
150
|
+
*/
|
|
151
|
+
export function cleanupElements(paymentElement, addressElement, paymentContainer, addressContainer) {
|
|
152
|
+
paymentElement.unmount();
|
|
153
|
+
if (addressElement) {
|
|
154
|
+
addressElement.unmount();
|
|
155
|
+
}
|
|
156
|
+
// Clean up created containers
|
|
157
|
+
if (addressContainer) {
|
|
158
|
+
addressContainer.remove();
|
|
159
|
+
}
|
|
160
|
+
if (paymentContainer) {
|
|
161
|
+
paymentContainer.remove();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Handle save card operation
|
|
166
|
+
*/
|
|
167
|
+
export function handleSaveCard(stripe, elements, session) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var _a, error, setupIntent;
|
|
170
|
+
return __generator(this, function (_b) {
|
|
171
|
+
switch (_b.label) {
|
|
172
|
+
case 0: return [4 /*yield*/, stripe.confirmSetup({
|
|
173
|
+
elements: elements,
|
|
174
|
+
redirect: 'if_required',
|
|
175
|
+
confirmParams: {
|
|
176
|
+
return_url: session.context.redirectUrl || window.location.href,
|
|
177
|
+
},
|
|
178
|
+
})];
|
|
179
|
+
case 1:
|
|
180
|
+
_a = _b.sent(), error = _a.error, setupIntent = _a.setupIntent;
|
|
181
|
+
return [2 /*return*/, error
|
|
182
|
+
? EventBuilder.fromStripeError(error)
|
|
183
|
+
: EventBuilder.fromSetupIntent(setupIntent)];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Handle payment operation
|
|
190
|
+
*/
|
|
191
|
+
export function handlePayment(stripe, elements, session) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var _a, error, paymentIntent;
|
|
194
|
+
return __generator(this, function (_b) {
|
|
195
|
+
switch (_b.label) {
|
|
196
|
+
case 0: return [4 /*yield*/, stripe.confirmPayment({
|
|
197
|
+
elements: elements,
|
|
198
|
+
redirect: 'if_required',
|
|
199
|
+
confirmParams: {
|
|
200
|
+
return_url: session.context.redirectUrl || window.location.href,
|
|
201
|
+
},
|
|
202
|
+
})];
|
|
203
|
+
case 1:
|
|
204
|
+
_a = _b.sent(), error = _a.error, paymentIntent = _a.paymentIntent;
|
|
205
|
+
return [2 /*return*/, error
|
|
206
|
+
? EventBuilder.fromStripeError(error)
|
|
207
|
+
: EventBuilder.fromPaymentIntent(paymentIntent)];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create common submit handler for widgets
|
|
214
|
+
*/
|
|
215
|
+
export function createSubmitHandler(stripe, elements, session, eventBroadcaster) {
|
|
216
|
+
var _this = this;
|
|
217
|
+
return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
218
|
+
var result;
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
switch (_a.label) {
|
|
221
|
+
case 0:
|
|
222
|
+
result = undefined;
|
|
223
|
+
if (!['save-card', 'payment'].includes(session.context.intent)) {
|
|
224
|
+
eventBroadcaster.publish({
|
|
225
|
+
status: 'Error',
|
|
226
|
+
code: 'InvalidSessionPayload',
|
|
227
|
+
loggingEnrichment: {
|
|
228
|
+
message: "context has an unexpected intent of ".concat(session.context.intent),
|
|
229
|
+
intent: session.context.intent,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
throw new InvalidSessionPayloadError();
|
|
233
|
+
}
|
|
234
|
+
if (!(session.context.intent === 'save-card')) return [3 /*break*/, 2];
|
|
235
|
+
return [4 /*yield*/, handleSaveCard(stripe, elements, session)];
|
|
236
|
+
case 1:
|
|
237
|
+
result = _a.sent();
|
|
238
|
+
_a.label = 2;
|
|
239
|
+
case 2:
|
|
240
|
+
if (!(session.context.intent === 'payment')) return [3 /*break*/, 4];
|
|
241
|
+
return [4 /*yield*/, handlePayment(stripe, elements, session)];
|
|
242
|
+
case 3:
|
|
243
|
+
result = _a.sent();
|
|
244
|
+
_a.label = 4;
|
|
245
|
+
case 4:
|
|
246
|
+
if (!result) {
|
|
247
|
+
eventBroadcaster.publish({ status: 'Error', code: 'Unexpected' });
|
|
248
|
+
throw new ProcessingError();
|
|
249
|
+
}
|
|
250
|
+
eventBroadcaster.publish(result);
|
|
251
|
+
return [2 /*return*/, result];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}); };
|
|
255
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Appearance } from '@stripe/stripe-js';
|
|
2
|
+
import { PaymentWidgetTheme } from '../widget';
|
|
3
|
+
/**
|
|
4
|
+
* Theme configuration for Stripe Elements appearance
|
|
5
|
+
*/
|
|
6
|
+
export interface ThemeConfig {
|
|
7
|
+
appearance: Appearance;
|
|
8
|
+
fonts: Array<{
|
|
9
|
+
cssSrc: string;
|
|
10
|
+
}>;
|
|
11
|
+
layout: {
|
|
12
|
+
type: 'tabs' | 'accordion';
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get theme configuration based on theme name
|
|
17
|
+
*/
|
|
18
|
+
export declare function getThemeConfig(theme?: PaymentWidgetTheme): ThemeConfig | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get theme configuration based on theme name
|
|
3
|
+
*/
|
|
4
|
+
export function getThemeConfig(theme) {
|
|
5
|
+
if (!theme) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
switch (theme) {
|
|
9
|
+
case 'invoicing':
|
|
10
|
+
return {
|
|
11
|
+
appearance: {
|
|
12
|
+
theme: 'stripe',
|
|
13
|
+
variables: {
|
|
14
|
+
fontFamily: 'Inter, system-ui, sans-serif',
|
|
15
|
+
fontWeightNormal: 'normal',
|
|
16
|
+
fontSizeBase: '1rem',
|
|
17
|
+
fontLineHeight: '24px',
|
|
18
|
+
borderRadius: '12px',
|
|
19
|
+
},
|
|
20
|
+
labels: 'floating',
|
|
21
|
+
rules: {
|
|
22
|
+
'.Label, .Label--floating': {
|
|
23
|
+
color: '#00071b',
|
|
24
|
+
opacity: '0.5',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
fonts: [
|
|
29
|
+
{
|
|
30
|
+
cssSrc: 'https://fonts.googleapis.com/css?family=Inter',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
layout: {
|
|
34
|
+
type: 'tabs',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
default:
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StripeSession } from './session';
|
|
2
2
|
import { DefaultValues, WidgetController, WidgetInterface } from '../common';
|
|
3
3
|
import { EventBroadcaster } from '../EventBroadcaster';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { PaymentWidgetTheme } from '../widget';
|
|
5
|
+
/**
|
|
6
|
+
* Main mount function that delegates to appropriate widget based on session type
|
|
7
|
+
*/
|
|
8
|
+
export declare function mount(mountElement: HTMLElement, session: StripeSession, eventBroadcaster: EventBroadcaster, defaultValues?: DefaultValues, theme?: PaymentWidgetTheme): Promise<WidgetController>;
|
|
9
|
+
export declare const StripeWidget: WidgetInterface<StripeSession>;
|