@funnelfox/billing 0.1.1 → 0.3.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/README.md +62 -49
- package/dist/chunk-index.cjs.js +178 -0
- package/dist/chunk-index.es.js +176 -0
- package/dist/funnelfox-billing.cjs.js +992 -1365
- package/dist/funnelfox-billing.esm.js +993 -1365
- package/dist/funnelfox-billing.js +1239 -1439
- package/dist/funnelfox-billing.min.js +1 -1
- package/package.json +22 -13
- package/src/types.d.ts +176 -38
- package/dist/funnelfox-billing.cjs.d.ts +0 -2
- package/dist/funnelfox-billing.d.ts +0 -204
- package/dist/funnelfox-billing.esm.d.ts +0 -2
- package/types.d.ts +0 -203
|
@@ -6,1518 +6,1318 @@
|
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
8
|
(function (global, factory) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
10
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
11
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.FunnelfoxSDK = {}));
|
|
12
12
|
})(this, (function (exports) { 'use strict';
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
* @fileoverview Custom error classes for Funnefox SDK
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Base error class for all Funnefox SDK errors
|
|
20
|
-
*/
|
|
21
|
-
class FunnefoxSDKError extends Error {
|
|
22
|
-
/**
|
|
23
|
-
* @param {string} message - Error message
|
|
24
|
-
* @param {string} [code='SDK_ERROR'] - Error code
|
|
25
|
-
* @param {*} [details=null] - Additional error details
|
|
26
|
-
*/
|
|
27
|
-
constructor(message, code = 'SDK_ERROR', details = null) {
|
|
28
|
-
super(message);
|
|
29
|
-
this.name = 'FunnefoxSDKError';
|
|
30
|
-
this.code = code;
|
|
31
|
-
this.details = details;
|
|
32
|
-
if (Error.captureStackTrace) {
|
|
33
|
-
Error.captureStackTrace(this, FunnefoxSDKError);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Error thrown when input validation fails
|
|
40
|
-
*/
|
|
41
|
-
class ValidationError extends FunnefoxSDKError {
|
|
42
|
-
/**
|
|
43
|
-
* @param {string} field - Field that failed validation
|
|
44
|
-
* @param {string} message - Validation error message
|
|
45
|
-
* @param {*} [value] - Invalid value that caused the error
|
|
46
|
-
*/
|
|
47
|
-
constructor(field, message, value = null) {
|
|
48
|
-
super(`Invalid ${field}: ${message}`, 'VALIDATION_ERROR');
|
|
49
|
-
this.name = 'ValidationError';
|
|
50
|
-
this.field = field;
|
|
51
|
-
this.value = value;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Error thrown when API calls fail
|
|
57
|
-
*/
|
|
58
|
-
class APIError extends FunnefoxSDKError {
|
|
59
|
-
/**
|
|
60
|
-
* @param {string} message - API error message
|
|
61
|
-
* @param {number} [statusCode] - HTTP status code
|
|
62
|
-
* @param {Object} [options] - Additional error details
|
|
63
|
-
* @param {string} [options.errorCode] - API error code (e.g., 'double_purchase')
|
|
64
|
-
* @param {string} [options.errorType] - API error type (e.g., 'api_exception')
|
|
65
|
-
* @param {string} [options.requestId] - Request ID for tracking
|
|
66
|
-
* @param {*} [options.response] - Full API response data
|
|
67
|
-
*/
|
|
68
|
-
constructor(message, statusCode = null, options = {}) {
|
|
69
|
-
super(message, options.errorCode || 'API_ERROR');
|
|
70
|
-
this.name = 'APIError';
|
|
71
|
-
this.statusCode = statusCode;
|
|
72
|
-
this.errorCode = options.errorCode || null;
|
|
73
|
-
this.errorType = options.errorType || null;
|
|
74
|
-
this.requestId = options.requestId || null;
|
|
75
|
-
this.response = options.response || null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Error thrown when Primer SDK integration fails
|
|
81
|
-
*/
|
|
82
|
-
class PrimerError extends FunnefoxSDKError {
|
|
83
|
-
/**
|
|
84
|
-
* @param {string} message - Primer error message
|
|
85
|
-
* @param {*} [primerError] - Original Primer error object
|
|
86
|
-
*/
|
|
87
|
-
constructor(message, primerError = null) {
|
|
88
|
-
super(message, 'PRIMER_ERROR');
|
|
89
|
-
this.name = 'PrimerError';
|
|
90
|
-
this.primerError = primerError;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Error thrown when checkout operations fail
|
|
96
|
-
*/
|
|
97
|
-
class CheckoutError extends FunnefoxSDKError {
|
|
98
|
-
/**
|
|
99
|
-
* @param {string} message - Checkout error message
|
|
100
|
-
* @param {string} [phase] - Checkout phase where error occurred
|
|
101
|
-
*/
|
|
102
|
-
constructor(message, phase = null) {
|
|
103
|
-
super(message, 'CHECKOUT_ERROR');
|
|
104
|
-
this.name = 'CheckoutError';
|
|
105
|
-
this.phase = phase;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Error thrown when SDK configuration is invalid
|
|
111
|
-
*/
|
|
112
|
-
class ConfigurationError extends FunnefoxSDKError {
|
|
113
|
-
/**
|
|
114
|
-
* @param {string} message - Configuration error message
|
|
115
|
-
*/
|
|
116
|
-
constructor(message) {
|
|
117
|
-
super(message, 'CONFIGURATION_ERROR');
|
|
118
|
-
this.name = 'ConfigurationError';
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Error thrown when network requests fail
|
|
124
|
-
*/
|
|
125
|
-
class NetworkError extends FunnefoxSDKError {
|
|
126
|
-
/**
|
|
127
|
-
* @param {string} message - Network error message
|
|
128
|
-
* @param {*} [originalError] - Original network error
|
|
129
|
-
*/
|
|
130
|
-
constructor(message, originalError = null) {
|
|
131
|
-
super(message, 'NETWORK_ERROR');
|
|
132
|
-
this.name = 'NetworkError';
|
|
133
|
-
this.originalError = originalError;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @fileoverview Constants for Funnefox SDK
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* SDK version
|
|
143
|
-
*/
|
|
144
|
-
const SDK_VERSION = '0.1.1';
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Default configuration values
|
|
148
|
-
*/
|
|
149
|
-
const DEFAULTS = {
|
|
150
|
-
BASE_URL: 'https://billing.funnelfox.com',
|
|
151
|
-
REGION: 'default',
|
|
152
|
-
SANDBOX: false,
|
|
153
|
-
REQUEST_TIMEOUT: 30000,
|
|
154
|
-
RETRY_ATTEMPTS: 3,
|
|
155
|
-
RETRY_BASE_DELAY: 1000
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Checkout states
|
|
160
|
-
*/
|
|
161
|
-
const CHECKOUT_STATES = {
|
|
162
|
-
INITIALIZING: 'initializing',
|
|
163
|
-
READY: 'ready',
|
|
164
|
-
PROCESSING: 'processing',
|
|
165
|
-
ACTION_REQUIRED: 'action_required',
|
|
166
|
-
UPDATING: 'updating',
|
|
167
|
-
COMPLETED: 'completed',
|
|
168
|
-
ERROR: 'error',
|
|
169
|
-
DESTROYED: 'destroyed'
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Event names
|
|
174
|
-
*/
|
|
175
|
-
const EVENTS = {
|
|
176
|
-
SUCCESS: 'success',
|
|
177
|
-
ERROR: 'error',
|
|
178
|
-
STATUS_CHANGE: 'status-change',
|
|
179
|
-
DESTROY: 'destroy'
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Error codes
|
|
184
|
-
*/
|
|
185
|
-
const ERROR_CODES = {
|
|
186
|
-
SDK_ERROR: 'SDK_ERROR',
|
|
187
|
-
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
188
|
-
API_ERROR: 'API_ERROR',
|
|
189
|
-
PRIMER_ERROR: 'PRIMER_ERROR',
|
|
190
|
-
CHECKOUT_ERROR: 'CHECKOUT_ERROR',
|
|
191
|
-
CONFIGURATION_ERROR: 'CONFIGURATION_ERROR',
|
|
192
|
-
NETWORK_ERROR: 'NETWORK_ERROR'
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @fileoverview Lightweight event emitter for Funnefox SDK
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Simple event emitter for checkout instances
|
|
201
|
-
*/
|
|
202
|
-
class EventEmitter {
|
|
203
|
-
constructor() {
|
|
204
|
-
this._events = new Map();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Add an event listener
|
|
209
|
-
* @param {string} eventName - Name of the event
|
|
210
|
-
* @param {function} handler - Event handler function
|
|
211
|
-
* @returns {EventEmitter} Returns this for chaining
|
|
212
|
-
*/
|
|
213
|
-
on(eventName, handler) {
|
|
214
|
-
if (typeof handler !== 'function') {
|
|
215
|
-
throw new Error('Event handler must be a function');
|
|
216
|
-
}
|
|
217
|
-
if (!this._events.has(eventName)) {
|
|
218
|
-
this._events.set(eventName, []);
|
|
219
|
-
}
|
|
220
|
-
this._events.get(eventName).push(handler);
|
|
221
|
-
return this;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Add a one-time event listener
|
|
226
|
-
* @param {string} eventName - Name of the event
|
|
227
|
-
* @param {function} handler - Event handler function
|
|
228
|
-
* @returns {EventEmitter} Returns this for chaining
|
|
229
|
-
*/
|
|
230
|
-
once(eventName, handler) {
|
|
231
|
-
if (typeof handler !== 'function') {
|
|
232
|
-
throw new Error('Event handler must be a function');
|
|
233
|
-
}
|
|
234
|
-
const onceWrapper = (...args) => {
|
|
235
|
-
this.off(eventName, onceWrapper);
|
|
236
|
-
handler.apply(this, args);
|
|
237
|
-
};
|
|
238
|
-
return this.on(eventName, onceWrapper);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Remove an event listener
|
|
243
|
-
* @param {string} eventName - Name of the event
|
|
244
|
-
* @param {function} [handler] - Specific handler to remove. If not provided, removes all handlers for the event
|
|
245
|
-
* @returns {EventEmitter} Returns this for chaining
|
|
246
|
-
*/
|
|
247
|
-
off(eventName, handler = null) {
|
|
248
|
-
if (!this._events.has(eventName)) {
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
if (handler === null) {
|
|
252
|
-
this._events.delete(eventName);
|
|
253
|
-
return this;
|
|
254
|
-
}
|
|
255
|
-
const handlers = this._events.get(eventName);
|
|
256
|
-
const index = handlers.indexOf(handler);
|
|
257
|
-
if (index !== -1) {
|
|
258
|
-
handlers.splice(index, 1);
|
|
259
|
-
if (handlers.length === 0) {
|
|
260
|
-
this._events.delete(eventName);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return this;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Emit an event to all registered handlers
|
|
268
|
-
* @param {string} eventName - Name of the event to emit
|
|
269
|
-
* @param {...*} args - Arguments to pass to event handlers
|
|
270
|
-
* @returns {boolean} Returns true if event had listeners, false otherwise
|
|
271
|
-
*/
|
|
272
|
-
emit(eventName, ...args) {
|
|
273
|
-
if (!this._events.has(eventName)) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
const handlers = this._events.get(eventName).slice();
|
|
277
|
-
for (const handler of handlers) {
|
|
278
|
-
try {
|
|
279
|
-
handler.apply(this, args);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
// Don't let handler errors break the emission chain
|
|
282
|
-
// eslint-disable-next-line no-console
|
|
283
|
-
console.warn(`Error in event handler for "${eventName}":`, error);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return true;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Get the number of listeners for an event
|
|
291
|
-
* @param {string} eventName - Name of the event
|
|
292
|
-
* @returns {number} Number of listeners
|
|
293
|
-
*/
|
|
294
|
-
listenerCount(eventName) {
|
|
295
|
-
return this._events.has(eventName) ? this._events.get(eventName).length : 0;
|
|
296
|
-
}
|
|
297
|
-
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
298
15
|
/**
|
|
299
|
-
*
|
|
300
|
-
* @returns {string[]} Array of event names
|
|
16
|
+
* @fileoverview Lightweight event emitter for Funnefox SDK
|
|
301
17
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
18
|
+
class EventEmitter {
|
|
19
|
+
constructor() {
|
|
20
|
+
this._events = new Map();
|
|
21
|
+
}
|
|
22
|
+
on(eventName, handler) {
|
|
23
|
+
if (typeof handler !== 'function') {
|
|
24
|
+
throw new Error('Event handler must be a function');
|
|
25
|
+
}
|
|
26
|
+
if (!this._events.has(eventName)) {
|
|
27
|
+
this._events.set(eventName, []);
|
|
28
|
+
}
|
|
29
|
+
this._events.get(eventName).push(handler);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
once(eventName, handler) {
|
|
33
|
+
if (typeof handler !== 'function') {
|
|
34
|
+
throw new Error('Event handler must be a function');
|
|
35
|
+
}
|
|
36
|
+
const onceWrapper = (...args) => {
|
|
37
|
+
this.off(eventName, onceWrapper);
|
|
38
|
+
handler.apply(this, args);
|
|
39
|
+
};
|
|
40
|
+
return this.on(eventName, onceWrapper);
|
|
41
|
+
}
|
|
42
|
+
off(eventName, handler = null) {
|
|
43
|
+
if (!this._events.has(eventName)) {
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
if (handler === null) {
|
|
47
|
+
this._events.delete(eventName);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
const handlers = this._events.get(eventName);
|
|
51
|
+
const index = handlers.indexOf(handler);
|
|
52
|
+
if (index !== -1) {
|
|
53
|
+
handlers.splice(index, 1);
|
|
54
|
+
if (handlers.length === 0) {
|
|
55
|
+
this._events.delete(eventName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
emit(eventName, ...args) {
|
|
61
|
+
if (!this._events.has(eventName)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const handlers = this._events.get(eventName).slice();
|
|
65
|
+
for (const handler of handlers) {
|
|
66
|
+
try {
|
|
67
|
+
handler.apply(this, args);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
// eslint-disable-next-line no-console
|
|
71
|
+
console.warn(`Error in event handler for "${String(eventName)}":`, error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
listenerCount(eventName) {
|
|
77
|
+
return this._events.has(eventName)
|
|
78
|
+
? this._events.get(eventName).length
|
|
79
|
+
: 0;
|
|
80
|
+
}
|
|
81
|
+
eventNames() {
|
|
82
|
+
return Array.from(this._events.keys());
|
|
83
|
+
}
|
|
84
|
+
removeAllListeners() {
|
|
85
|
+
this._events.clear();
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
listeners(eventName) {
|
|
89
|
+
return this._events.has(eventName)
|
|
90
|
+
? this._events.get(eventName).slice()
|
|
91
|
+
: [];
|
|
92
|
+
}
|
|
313
93
|
}
|
|
314
94
|
|
|
315
95
|
/**
|
|
316
|
-
*
|
|
317
|
-
* @param {string} eventName - Name of the event
|
|
318
|
-
* @returns {function[]} Array of handler functions
|
|
96
|
+
* @fileoverview Custom error classes for Funnefox SDK
|
|
319
97
|
*/
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Merges multiple objects into a new object
|
|
332
|
-
* @param {...Object} objects - Objects to merge
|
|
333
|
-
* @returns {Object} Merged object
|
|
334
|
-
*/
|
|
335
|
-
function merge(...objects) {
|
|
336
|
-
const result = {};
|
|
337
|
-
for (const obj of objects) {
|
|
338
|
-
if (obj && typeof obj === 'object') {
|
|
339
|
-
for (const key in obj) {
|
|
340
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
341
|
-
if (typeof obj[key] === 'object' && !Array.isArray(obj[key]) && obj[key] !== null) {
|
|
342
|
-
result[key] = merge(result[key] || {}, obj[key]);
|
|
343
|
-
} else {
|
|
344
|
-
result[key] = obj[key];
|
|
98
|
+
class FunnefoxSDKError extends Error {
|
|
99
|
+
constructor(message, code = ERROR_CODES.SDK_ERROR, details = null) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.name = 'FunnefoxSDKError';
|
|
102
|
+
this.code = code;
|
|
103
|
+
this.details = details;
|
|
104
|
+
if (Error.captureStackTrace) {
|
|
105
|
+
Error.captureStackTrace(this, FunnefoxSDKError);
|
|
345
106
|
}
|
|
346
|
-
}
|
|
347
107
|
}
|
|
348
|
-
}
|
|
349
108
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
*/
|
|
358
|
-
function generateId(prefix = '') {
|
|
359
|
-
const timestamp = Date.now().toString(36);
|
|
360
|
-
const random = Math.random().toString(36).substr(2, 5);
|
|
361
|
-
return `${prefix}${timestamp}_${random}`;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Waits for a specified amount of time
|
|
366
|
-
* @param {number} ms - Milliseconds to wait
|
|
367
|
-
* @returns {Promise} Promise that resolves after the specified time
|
|
368
|
-
*/
|
|
369
|
-
function sleep(ms) {
|
|
370
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Retries a function with exponential backoff
|
|
375
|
-
* @param {function} fn - Function to retry
|
|
376
|
-
* @param {number} [maxAttempts=3] - Maximum number of attempts
|
|
377
|
-
* @param {number} [baseDelay=1000] - Base delay in milliseconds
|
|
378
|
-
* @returns {Promise} Promise that resolves with the function result
|
|
379
|
-
*/
|
|
380
|
-
async function retry(fn, maxAttempts = 3, baseDelay = 1000) {
|
|
381
|
-
let lastError;
|
|
382
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
383
|
-
try {
|
|
384
|
-
return await fn();
|
|
385
|
-
} catch (error) {
|
|
386
|
-
lastError = error;
|
|
387
|
-
if (attempt === maxAttempts) {
|
|
388
|
-
throw lastError;
|
|
389
|
-
}
|
|
390
|
-
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
391
|
-
await sleep(delay);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
throw lastError;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Creates a promise that rejects after a timeout
|
|
399
|
-
* @param {Promise} promise - Promise to wrap
|
|
400
|
-
* @param {number} timeoutMs - Timeout in milliseconds
|
|
401
|
-
* @param {string} [message='Operation timed out'] - Timeout error message
|
|
402
|
-
* @returns {Promise} Promise that rejects if timeout is reached
|
|
403
|
-
*/
|
|
404
|
-
function withTimeout(promise, timeoutMs, message = 'Operation timed out') {
|
|
405
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
406
|
-
setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
407
|
-
});
|
|
408
|
-
return Promise.race([promise, timeoutPromise]);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* @fileoverview Primer SDK integration wrapper
|
|
413
|
-
*
|
|
414
|
-
* @typedef {import('@primer-io/checkout-web').IPrimerHeadlessUniversalCheckout} PrimerCheckout
|
|
415
|
-
* @typedef {import('@primer-io/checkout-web').ITokenizationHandler} PrimerTokenizationHandler
|
|
416
|
-
* @typedef {import('@primer-io/checkout-web').IResumeHandler} PrimerResumeHandler
|
|
417
|
-
* @typedef {import('@primer-io/checkout-web').PaymentMethodTokenData} PaymentMethodTokenData
|
|
418
|
-
* @typedef {import('@primer-io/checkout-web').ResumeTokenData} ResumeTokenData
|
|
419
|
-
* @typedef {import('@primer-io/checkout-web').UniversalCheckoutOptions} UniversalCheckoutOptions
|
|
420
|
-
*/
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Wrapper class for Primer SDK integration
|
|
425
|
-
*/
|
|
426
|
-
class PrimerWrapper {
|
|
427
|
-
constructor() {
|
|
428
|
-
this.currentCheckout = null;
|
|
429
|
-
this.isInitialized = false;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Checks if Primer SDK is available
|
|
434
|
-
* @returns {boolean} True if Primer is available
|
|
435
|
-
*/
|
|
436
|
-
isPrimerAvailable() {
|
|
437
|
-
return typeof window !== 'undefined' && window.Primer && typeof window.Primer.showUniversalCheckout === 'function';
|
|
109
|
+
class ValidationError extends FunnefoxSDKError {
|
|
110
|
+
constructor(field, message, value = null) {
|
|
111
|
+
super(`Invalid ${field}: ${message}`, ERROR_CODES.VALIDATION_ERROR);
|
|
112
|
+
this.name = 'ValidationError';
|
|
113
|
+
this.field = field;
|
|
114
|
+
this.value = value;
|
|
115
|
+
}
|
|
438
116
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
117
|
+
class APIError extends FunnefoxSDKError {
|
|
118
|
+
constructor(message, statusCode = null, options = {}) {
|
|
119
|
+
super(message, options.errorCode || ERROR_CODES.API_ERROR);
|
|
120
|
+
this.name = 'APIError';
|
|
121
|
+
this.statusCode = statusCode;
|
|
122
|
+
this.errorCode = options.errorCode || null;
|
|
123
|
+
this.errorType = options.errorType || null;
|
|
124
|
+
this.requestId = options.requestId || null;
|
|
125
|
+
this.response = options.response || null;
|
|
126
|
+
}
|
|
448
127
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
*/
|
|
456
|
-
async showUniversalCheckout(clientToken, options) {
|
|
457
|
-
this.ensurePrimerAvailable();
|
|
458
|
-
|
|
459
|
-
// Extract SDK-managed handlers
|
|
460
|
-
const {
|
|
461
|
-
onTokenizeSuccess,
|
|
462
|
-
onResumeSuccess,
|
|
463
|
-
container,
|
|
464
|
-
...userPrimerOptions
|
|
465
|
-
} = options;
|
|
466
|
-
|
|
467
|
-
// Merge defaults with user's Primer options
|
|
468
|
-
/** @type {UniversalCheckoutOptions} */
|
|
469
|
-
const primerOptions = merge({
|
|
470
|
-
clientToken,
|
|
471
|
-
container,
|
|
472
|
-
paymentHandling: 'MANUAL',
|
|
473
|
-
apiVersion: '2.4',
|
|
474
|
-
paypal: {
|
|
475
|
-
buttonColor: 'blue',
|
|
476
|
-
paymentFlow: 'PREFER_VAULT'
|
|
477
|
-
}
|
|
478
|
-
}, userPrimerOptions);
|
|
479
|
-
|
|
480
|
-
// Add the required event handlers (must override any user-provided ones)
|
|
481
|
-
primerOptions.onTokenizeSuccess = this._wrapTokenizeHandler(onTokenizeSuccess);
|
|
482
|
-
primerOptions.onResumeSuccess = this._wrapResumeHandler(onResumeSuccess);
|
|
483
|
-
try {
|
|
484
|
-
const checkout = await window.Primer.showUniversalCheckout(clientToken, primerOptions);
|
|
485
|
-
this.currentCheckout = checkout;
|
|
486
|
-
this.isInitialized = true;
|
|
487
|
-
return checkout;
|
|
488
|
-
} catch (error) {
|
|
489
|
-
throw new PrimerError('Failed to initialize Primer checkout', error);
|
|
490
|
-
}
|
|
128
|
+
class PrimerError extends FunnefoxSDKError {
|
|
129
|
+
constructor(message, primerError = null) {
|
|
130
|
+
super(message, ERROR_CODES.PRIMER_ERROR);
|
|
131
|
+
this.name = 'PrimerError';
|
|
132
|
+
this.primerError = primerError;
|
|
133
|
+
}
|
|
491
134
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
*/
|
|
499
|
-
_wrapTokenizeHandler(handler) {
|
|
500
|
-
return async (paymentMethodTokenData, primerHandler) => {
|
|
501
|
-
try {
|
|
502
|
-
await handler(paymentMethodTokenData, primerHandler);
|
|
503
|
-
} catch (error) {
|
|
504
|
-
console.error('Error in tokenize handler:', error);
|
|
505
|
-
primerHandler.handleFailure('Payment processing failed. Please try again.');
|
|
506
|
-
}
|
|
507
|
-
};
|
|
135
|
+
class CheckoutError extends FunnefoxSDKError {
|
|
136
|
+
constructor(message, phase = null) {
|
|
137
|
+
super(message, ERROR_CODES.CHECKOUT_ERROR);
|
|
138
|
+
this.name = 'CheckoutError';
|
|
139
|
+
this.phase = phase;
|
|
140
|
+
}
|
|
508
141
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
* @returns {function(ResumeTokenData, PrimerResumeHandler): Promise<void>}
|
|
515
|
-
*/
|
|
516
|
-
_wrapResumeHandler(handler) {
|
|
517
|
-
return async (resumeTokenData, primerHandler) => {
|
|
518
|
-
try {
|
|
519
|
-
await handler(resumeTokenData, primerHandler);
|
|
520
|
-
} catch (error) {
|
|
521
|
-
console.error('Error in resume handler:', error);
|
|
522
|
-
primerHandler.handleFailure('Payment processing failed. Please try again.');
|
|
523
|
-
}
|
|
524
|
-
};
|
|
142
|
+
class ConfigurationError extends FunnefoxSDKError {
|
|
143
|
+
constructor(message) {
|
|
144
|
+
super(message, ERROR_CODES.CONFIGURATION_ERROR);
|
|
145
|
+
this.name = 'ConfigurationError';
|
|
146
|
+
}
|
|
525
147
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
async updateClientToken(newClientToken) {
|
|
533
|
-
if (!this.currentCheckout) {
|
|
534
|
-
throw new PrimerError('No active checkout to update');
|
|
535
|
-
}
|
|
536
|
-
try {
|
|
537
|
-
// Primer SDK doesn't have a direct update method, so we need to destroy and recreate
|
|
538
|
-
// This is handled at the checkout level
|
|
539
|
-
throw new PrimerError('Client token updates require checkout recreation');
|
|
540
|
-
} catch (error) {
|
|
541
|
-
throw new PrimerError('Failed to update client token', error);
|
|
542
|
-
}
|
|
148
|
+
class NetworkError extends FunnefoxSDKError {
|
|
149
|
+
constructor(message, originalError = null) {
|
|
150
|
+
super(message, ERROR_CODES.NETWORK_ERROR);
|
|
151
|
+
this.name = 'NetworkError';
|
|
152
|
+
this.originalError = originalError;
|
|
153
|
+
}
|
|
543
154
|
}
|
|
544
155
|
|
|
156
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
545
157
|
/**
|
|
546
|
-
*
|
|
547
|
-
* @returns {Promise<void>}
|
|
158
|
+
* @fileoverview Helper utilities for Funnefox SDK
|
|
548
159
|
*/
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
160
|
+
function merge(...objects) {
|
|
161
|
+
const result = {};
|
|
162
|
+
for (const obj of objects) {
|
|
163
|
+
if (obj && typeof obj === 'object') {
|
|
164
|
+
for (const key in obj) {
|
|
165
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
166
|
+
if (typeof obj[key] === 'object' &&
|
|
167
|
+
!Array.isArray(obj[key]) &&
|
|
168
|
+
obj[key] !== null) {
|
|
169
|
+
result[key] = merge(result[key] || {}, obj[key]);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
result[key] = obj[key];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
560
176
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
console.warn('Error destroying Primer checkout:', error);
|
|
564
|
-
} finally {
|
|
565
|
-
this.currentCheckout = null;
|
|
566
|
-
this.isInitialized = false;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Creates standardized Primer handler helpers
|
|
573
|
-
* @param {Object} handlers - Handler functions
|
|
574
|
-
* @param {function} handlers.onSuccess - Success callback
|
|
575
|
-
* @param {function} handlers.onError - Error callback
|
|
576
|
-
* @param {function} handlers.onActionRequired - Action required callback
|
|
577
|
-
* @returns {Object} Primer-compatible handler functions
|
|
578
|
-
*/
|
|
579
|
-
createHandlers(handlers) {
|
|
580
|
-
return {
|
|
581
|
-
/**
|
|
582
|
-
* Handle successful tokenization
|
|
583
|
-
*/
|
|
584
|
-
handleSuccess: () => {
|
|
585
|
-
if (handlers.onSuccess) {
|
|
586
|
-
handlers.onSuccess();
|
|
587
|
-
}
|
|
588
|
-
},
|
|
589
|
-
/**
|
|
590
|
-
* Handle payment failure
|
|
591
|
-
*/
|
|
592
|
-
handleFailure: message => {
|
|
593
|
-
if (handlers.onError) {
|
|
594
|
-
handlers.onError(new Error(message));
|
|
595
|
-
}
|
|
596
|
-
},
|
|
597
|
-
/**
|
|
598
|
-
* Continue with new client token (for 3DS flows)
|
|
599
|
-
*/
|
|
600
|
-
continueWithNewClientToken: newClientToken => {
|
|
601
|
-
if (handlers.onActionRequired) {
|
|
602
|
-
handlers.onActionRequired(newClientToken);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Gets the current checkout state
|
|
610
|
-
* @returns {PrimerCheckout|null} Current checkout instance or null
|
|
611
|
-
*/
|
|
612
|
-
getCurrentCheckout() {
|
|
613
|
-
return this.currentCheckout;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Checks if checkout is currently active
|
|
618
|
-
* @returns {boolean} True if checkout is active
|
|
619
|
-
*/
|
|
620
|
-
isActive() {
|
|
621
|
-
return this.isInitialized && this.currentCheckout !== null;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Validates that a container element exists and is suitable for Primer
|
|
626
|
-
* @param {string} selector - DOM selector
|
|
627
|
-
* @returns {Element} The container element
|
|
628
|
-
* @throws {PrimerError} If container is invalid
|
|
629
|
-
*/
|
|
630
|
-
validateContainer(selector) {
|
|
631
|
-
const element = document.querySelector(selector);
|
|
632
|
-
if (!element) {
|
|
633
|
-
throw new PrimerError(`Checkout container not found: ${selector}`);
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// Check if container is suitable (visible, not already in use, etc.)
|
|
637
|
-
const computedStyle = window.getComputedStyle(element);
|
|
638
|
-
if (computedStyle.display === 'none') {
|
|
639
|
-
console.warn('Checkout container is hidden, this may cause display issues');
|
|
640
|
-
}
|
|
641
|
-
return element;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
var primerWrapper = /*#__PURE__*/Object.freeze({
|
|
646
|
-
__proto__: null,
|
|
647
|
-
default: PrimerWrapper
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* @fileoverview Input validation utilities for Funnefox SDK
|
|
652
|
-
*/
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
/**
|
|
656
|
-
* Sanitizes a string input
|
|
657
|
-
* @param {*} input - Input to sanitize
|
|
658
|
-
* @returns {string} Sanitized string
|
|
659
|
-
*/
|
|
660
|
-
function sanitizeString(input) {
|
|
661
|
-
if (input === null || input === undefined) {
|
|
662
|
-
return '';
|
|
663
|
-
}
|
|
664
|
-
return String(input).trim();
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* Validates that a value is a non-empty string
|
|
669
|
-
* @param {*} value - Value to validate
|
|
670
|
-
* @param {string} fieldName - Name of the field for error reporting
|
|
671
|
-
* @returns {boolean} True if valid
|
|
672
|
-
* @throws {ValidationError} If validation fails
|
|
673
|
-
*/
|
|
674
|
-
function requireString(value, fieldName) {
|
|
675
|
-
const sanitized = sanitizeString(value);
|
|
676
|
-
if (sanitized.length === 0) {
|
|
677
|
-
throw new ValidationError(fieldName, 'must be a non-empty string', value);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
678
179
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
* Validates that a container element exists in the DOM
|
|
684
|
-
* @param {string} selector - DOM selector
|
|
685
|
-
* @returns {Element} The found element
|
|
686
|
-
* @throws {ValidationError} If element not found
|
|
687
|
-
*/
|
|
688
|
-
function validateContainer(selector) {
|
|
689
|
-
requireString(selector, 'container');
|
|
690
|
-
const element = document.querySelector(selector);
|
|
691
|
-
if (!element) {
|
|
692
|
-
throw new ValidationError('container', `element not found: ${selector}`, selector);
|
|
180
|
+
function generateId(prefix = '') {
|
|
181
|
+
const timestamp = Date.now().toString(36);
|
|
182
|
+
const random = Math.random().toString(36).substr(2, 5);
|
|
183
|
+
return `${prefix}${timestamp}_${random}`;
|
|
693
184
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* @fileoverview API client for Funnefox backend integration
|
|
699
|
-
*/
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* HTTP client for Funnefox API requests
|
|
704
|
-
*/
|
|
705
|
-
class APIClient {
|
|
706
|
-
/**
|
|
707
|
-
* @param {Object} config - API client configuration
|
|
708
|
-
* @param {string} config.baseUrl - Base URL for API calls
|
|
709
|
-
* @param {string} config.orgId - Organization identifier
|
|
710
|
-
* @param {number} [config.timeout=30000] - Request timeout in milliseconds
|
|
711
|
-
* @param {number} [config.retryAttempts=3] - Number of retry attempts
|
|
712
|
-
*/
|
|
713
|
-
constructor(config) {
|
|
714
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
715
|
-
this.orgId = config.orgId;
|
|
716
|
-
this.timeout = config.timeout || 30000;
|
|
717
|
-
this.retryAttempts = config.retryAttempts || 3;
|
|
185
|
+
function sleep(ms) {
|
|
186
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
718
187
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
},
|
|
735
|
-
...options
|
|
736
|
-
};
|
|
737
|
-
try {
|
|
738
|
-
return await retry(async () => {
|
|
739
|
-
return await withTimeout(this._makeRequest(url, requestOptions), this.timeout, 'Request timed out');
|
|
740
|
-
}, this.retryAttempts);
|
|
741
|
-
} catch (error) {
|
|
742
|
-
if (error.name === 'APIError') {
|
|
743
|
-
throw error;
|
|
744
|
-
}
|
|
745
|
-
throw new NetworkError('Network request failed', error);
|
|
746
|
-
}
|
|
188
|
+
async function retry(fn, maxAttempts = 3, baseDelay = 1000) {
|
|
189
|
+
let lastError;
|
|
190
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
191
|
+
try {
|
|
192
|
+
return await fn();
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
lastError = error;
|
|
196
|
+
if (attempt === maxAttempts)
|
|
197
|
+
throw lastError;
|
|
198
|
+
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
199
|
+
await sleep(delay);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
throw lastError;
|
|
747
203
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
* @private
|
|
752
|
-
*/
|
|
753
|
-
async _makeRequest(url, options) {
|
|
754
|
-
let response;
|
|
755
|
-
try {
|
|
756
|
-
response = await fetch(url, options);
|
|
757
|
-
} catch (error) {
|
|
758
|
-
throw new NetworkError('Network request failed', error);
|
|
759
|
-
}
|
|
760
|
-
let data;
|
|
761
|
-
try {
|
|
762
|
-
data = await response.json();
|
|
763
|
-
} catch (error) {
|
|
764
|
-
throw new APIError('Invalid JSON response', response.status, {});
|
|
765
|
-
}
|
|
766
|
-
if (!response.ok) {
|
|
767
|
-
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
768
|
-
throw new APIError(message, response.status, {
|
|
769
|
-
response: data
|
|
204
|
+
function withTimeout(promise, timeoutMs, message = 'Operation timed out') {
|
|
205
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
206
|
+
setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
770
207
|
});
|
|
771
|
-
|
|
772
|
-
return data;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
/**
|
|
776
|
-
* Creates a client session for checkout
|
|
777
|
-
* @param {Object} params - Session parameters
|
|
778
|
-
* @param {string} params.priceId - Price point identifier
|
|
779
|
-
* @param {string} params.externalId - External user identifier
|
|
780
|
-
* @param {string} params.email - Customer email
|
|
781
|
-
* @param {Object} [params.clientMetadata] - Additional metadata
|
|
782
|
-
* @param {string} [params.region='default'] - Checkout region
|
|
783
|
-
* @param {string} [params.countryCode] - Optional ISO country code
|
|
784
|
-
* @returns {Promise<Object>} Client session response
|
|
785
|
-
*/
|
|
786
|
-
async createClientSession(params) {
|
|
787
|
-
const payload = {
|
|
788
|
-
region: params.region || 'default',
|
|
789
|
-
integration_type: 'primer',
|
|
790
|
-
pp_ident: params.priceId,
|
|
791
|
-
external_id: params.externalId,
|
|
792
|
-
email_address: params.email,
|
|
793
|
-
client_metadata: params.clientMetadata || {}
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
// Add country_code if provided (nullable field per Swagger spec)
|
|
797
|
-
if (params.countryCode !== undefined) {
|
|
798
|
-
payload.country_code = params.countryCode;
|
|
799
|
-
}
|
|
800
|
-
return await this.request('/v1/checkout/create_client_session', {
|
|
801
|
-
method: 'POST',
|
|
802
|
-
body: JSON.stringify(payload)
|
|
803
|
-
});
|
|
208
|
+
return Promise.race([promise, timeoutPromise]);
|
|
804
209
|
}
|
|
805
210
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
*/
|
|
814
|
-
async updateClientSession(params) {
|
|
815
|
-
const payload = {
|
|
816
|
-
order_id: params.orderId,
|
|
817
|
-
client_token: params.clientToken,
|
|
818
|
-
pp_ident: params.priceId
|
|
819
|
-
};
|
|
820
|
-
return await this.request('/v1/checkout/update_client_session', {
|
|
821
|
-
method: 'POST',
|
|
822
|
-
body: JSON.stringify(payload)
|
|
823
|
-
});
|
|
824
|
-
}
|
|
211
|
+
var PaymentMethod;
|
|
212
|
+
(function (PaymentMethod) {
|
|
213
|
+
PaymentMethod["GOOGLE_PAY"] = "GOOGLE_PAY";
|
|
214
|
+
PaymentMethod["APPLE_PAY"] = "APPLE_PAY";
|
|
215
|
+
PaymentMethod["PAYPAL"] = "PAYPAL";
|
|
216
|
+
PaymentMethod["PAYMENT_CARD"] = "PAYMENT_CARD";
|
|
217
|
+
})(PaymentMethod || (PaymentMethod = {}));
|
|
825
218
|
|
|
826
219
|
/**
|
|
827
|
-
*
|
|
828
|
-
* @param {Object} params - Payment parameters
|
|
829
|
-
* @param {string} params.orderId - Order identifier
|
|
830
|
-
* @param {string} params.paymentMethodToken - Payment method token from Primer
|
|
831
|
-
* @returns {Promise<Object>} Payment response
|
|
220
|
+
* @fileoverview Constants for Funnefox SDK
|
|
832
221
|
*/
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
222
|
+
const SDK_VERSION = '0.3.0';
|
|
223
|
+
const DEFAULTS = {
|
|
224
|
+
BASE_URL: 'https://billing.funnelfox.com',
|
|
225
|
+
REGION: 'default',
|
|
226
|
+
SANDBOX: false,
|
|
227
|
+
REQUEST_TIMEOUT: 30000,
|
|
228
|
+
RETRY_ATTEMPTS: 3,
|
|
229
|
+
RETRY_BASE_DELAY: 1000,
|
|
230
|
+
};
|
|
231
|
+
const CHECKOUT_STATES = {
|
|
232
|
+
INITIALIZING: 'initializing',
|
|
233
|
+
READY: 'ready',
|
|
234
|
+
PROCESSING: 'processing',
|
|
235
|
+
ACTION_REQUIRED: 'action_required',
|
|
236
|
+
UPDATING: 'updating',
|
|
237
|
+
COMPLETED: 'completed',
|
|
238
|
+
ERROR: 'error',
|
|
239
|
+
DESTROYED: 'destroyed',
|
|
240
|
+
};
|
|
241
|
+
const EVENTS = {
|
|
242
|
+
SUCCESS: 'success',
|
|
243
|
+
ERROR: 'error',
|
|
244
|
+
STATUS_CHANGE: 'status-change',
|
|
245
|
+
DESTROY: 'destroy',
|
|
246
|
+
INPUT_ERROR: 'input-error',
|
|
247
|
+
LOADER_CHANGE: 'loader-change',
|
|
248
|
+
METHOD_RENDER: 'method-render',
|
|
249
|
+
START_PURCHASE: 'start-purchase',
|
|
250
|
+
PURCHASE_FAILURE: 'purchase-failure',
|
|
251
|
+
PURCHASE_COMPLETED: 'purchase-completed',
|
|
252
|
+
};
|
|
253
|
+
const API_ENDPOINTS = {
|
|
254
|
+
CREATE_CLIENT_SESSION: '/v1/checkout/create_client_session',
|
|
255
|
+
UPDATE_CLIENT_SESSION: '/v1/checkout/update_client_session',
|
|
256
|
+
CREATE_PAYMENT: '/v1/checkout/create_payment',
|
|
257
|
+
RESUME_PAYMENT: '/v1/checkout/resume_payment',
|
|
258
|
+
};
|
|
259
|
+
const ERROR_CODES = {
|
|
260
|
+
SDK_ERROR: 'SDK_ERROR',
|
|
261
|
+
VALIDATION_ERROR: 'VALIDATION_ERROR',
|
|
262
|
+
API_ERROR: 'API_ERROR',
|
|
263
|
+
PRIMER_ERROR: 'PRIMER_ERROR',
|
|
264
|
+
CHECKOUT_ERROR: 'CHECKOUT_ERROR',
|
|
265
|
+
CONFIGURATION_ERROR: 'CONFIGURATION_ERROR',
|
|
266
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
267
|
+
};
|
|
268
|
+
const ALLOWED_BUTTON_PAYMENT_METHODS = [
|
|
269
|
+
PaymentMethod.GOOGLE_PAY,
|
|
270
|
+
PaymentMethod.APPLE_PAY,
|
|
271
|
+
PaymentMethod.PAYPAL,
|
|
272
|
+
];
|
|
273
|
+
const ALLOWED_CARD_PAYMENT_METHODS = [
|
|
274
|
+
PaymentMethod.PAYMENT_CARD,
|
|
275
|
+
];
|
|
276
|
+
const ALLOWED_PAYMENT_METHODS = [
|
|
277
|
+
...ALLOWED_BUTTON_PAYMENT_METHODS,
|
|
278
|
+
...ALLOWED_CARD_PAYMENT_METHODS,
|
|
279
|
+
];
|
|
280
|
+
const inputStyle = {
|
|
281
|
+
input: {
|
|
282
|
+
error: {
|
|
283
|
+
borderColor: 'rgb(227, 47, 65)',
|
|
284
|
+
},
|
|
285
|
+
base: {
|
|
286
|
+
borderWidth: '1px',
|
|
287
|
+
borderStyle: 'solid',
|
|
288
|
+
borderColor: 'rgb(0 0 0 / 10%)',
|
|
289
|
+
height: '36px',
|
|
290
|
+
paddingHorizontal: 10,
|
|
291
|
+
borderRadius: '6px',
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
({
|
|
296
|
+
paddingLeft: inputStyle.input.base.paddingHorizontal + 'px',
|
|
297
|
+
paddingRight: inputStyle.input.base.paddingHorizontal + 'px'});
|
|
907
298
|
|
|
908
299
|
/**
|
|
909
|
-
*
|
|
910
|
-
* @param {Object} response - Raw API response
|
|
911
|
-
* @returns {Object} Processed payment data
|
|
912
|
-
* @throws {APIError} If response indicates an error
|
|
300
|
+
* @fileoverview Primer SDK integration wrapper
|
|
913
301
|
*/
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
302
|
+
class PrimerWrapper {
|
|
303
|
+
constructor() {
|
|
304
|
+
this.isInitialized = false;
|
|
305
|
+
this.destroyCallbacks = [];
|
|
306
|
+
this.headless = null;
|
|
307
|
+
this.availableMethods = [];
|
|
308
|
+
}
|
|
309
|
+
isPrimerAvailable() {
|
|
310
|
+
return (typeof window !== 'undefined' &&
|
|
311
|
+
window.Primer &&
|
|
312
|
+
typeof window.Primer?.createHeadless === 'function');
|
|
313
|
+
}
|
|
314
|
+
ensurePrimerAvailable() {
|
|
315
|
+
if (!this.isPrimerAvailable()) {
|
|
316
|
+
throw new PrimerError('Primer SDK not found. Please include the Primer SDK script before initializing FunnefoxSDK.');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async createHeadlessCheckout(clientToken, options) {
|
|
320
|
+
if (this.headless) {
|
|
321
|
+
return this.headless;
|
|
322
|
+
}
|
|
323
|
+
this.ensurePrimerAvailable();
|
|
324
|
+
const primerOptions = merge({
|
|
325
|
+
paymentHandling: 'MANUAL',
|
|
326
|
+
apiVersion: '2.4',
|
|
327
|
+
paypal: {
|
|
328
|
+
buttonColor: 'blue',
|
|
329
|
+
paymentFlow: 'PREFER_VAULT',
|
|
330
|
+
},
|
|
331
|
+
}, options);
|
|
332
|
+
try {
|
|
333
|
+
const headless = await window.Primer.createHeadless(clientToken, primerOptions);
|
|
334
|
+
await headless.start();
|
|
335
|
+
this.headless = headless;
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
throw new PrimerError('Failed to create Primer headless checkout', error);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
initializeCardElements(selectors) {
|
|
342
|
+
const { cardNumber, expiryDate, cvv, cardholderName, button } = selectors;
|
|
941
343
|
return {
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
344
|
+
cardNumber: document.querySelector(cardNumber),
|
|
345
|
+
expiryDate: document.querySelector(expiryDate),
|
|
346
|
+
cvv: document.querySelector(cvv),
|
|
347
|
+
cardholderName: document.querySelector(cardholderName),
|
|
348
|
+
button: document.querySelector(button),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
disableButtons(disabled) {
|
|
352
|
+
if (!this.paymentMethodsInterfaces)
|
|
353
|
+
return;
|
|
354
|
+
for (const method in this.paymentMethodsInterfaces) {
|
|
355
|
+
this.paymentMethodsInterfaces[method].setDisabled(disabled);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async renderCardCheckout({ onSubmitError, onSubmit, cardSelectors, onInputChange, }) {
|
|
359
|
+
try {
|
|
360
|
+
const elements = this.initializeCardElements(cardSelectors);
|
|
361
|
+
const pmManager = await this.headless.createPaymentMethodManager('PAYMENT_CARD');
|
|
362
|
+
if (!pmManager) {
|
|
363
|
+
throw new Error('Payment method manager is not available');
|
|
364
|
+
}
|
|
365
|
+
const { cardNumberInput, expiryInput, cvvInput } = pmManager.createHostedInputs();
|
|
366
|
+
const validateForm = async () => {
|
|
367
|
+
if (!pmManager)
|
|
368
|
+
return false;
|
|
369
|
+
const { valid, validationErrors } = await pmManager.validate();
|
|
370
|
+
const cardHolderError = validationErrors.find(v => v.name === 'cardholderName');
|
|
371
|
+
dispatchError('cardholderName', cardHolderError?.message || null);
|
|
372
|
+
return valid;
|
|
373
|
+
};
|
|
374
|
+
const dispatchError = (inputName, error) => {
|
|
375
|
+
onInputChange(inputName, error);
|
|
376
|
+
};
|
|
377
|
+
const onHostedInputChange = (name) => (event) => {
|
|
378
|
+
const input = event;
|
|
379
|
+
if (input.submitted) {
|
|
380
|
+
dispatchError(name, input.error);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const cardHolderOnChange = async (e) => {
|
|
384
|
+
pmManager.setCardholderName(e.target.value);
|
|
385
|
+
dispatchError('cardholderName', null);
|
|
386
|
+
};
|
|
387
|
+
elements.cardholderName?.addEventListener('input', cardHolderOnChange);
|
|
388
|
+
cardNumberInput.addEventListener('change', onHostedInputChange('cardNumber'));
|
|
389
|
+
expiryInput.addEventListener('change', onHostedInputChange('expiryDate'));
|
|
390
|
+
cvvInput.addEventListener('change', onHostedInputChange('cvv'));
|
|
391
|
+
const onSubmitHandler = async () => {
|
|
392
|
+
if (!(await validateForm())) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
onSubmit(true);
|
|
397
|
+
await pmManager.submit();
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
const primerError = new PrimerError('Failed to submit payment', error);
|
|
401
|
+
onSubmitError(primerError);
|
|
402
|
+
throw primerError;
|
|
403
|
+
}
|
|
404
|
+
finally {
|
|
405
|
+
onSubmit(false);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
elements.button.addEventListener('click', onSubmitHandler);
|
|
409
|
+
await Promise.all([
|
|
410
|
+
cardNumberInput.render(elements.cardNumber, {
|
|
411
|
+
placeholder: '1234 1234 1234 1234',
|
|
412
|
+
ariaLabel: 'Card number',
|
|
413
|
+
style: inputStyle,
|
|
414
|
+
}),
|
|
415
|
+
expiryInput.render(elements.expiryDate, {
|
|
416
|
+
placeholder: 'MM/YY',
|
|
417
|
+
ariaLabel: 'Expiry date',
|
|
418
|
+
style: inputStyle,
|
|
419
|
+
}),
|
|
420
|
+
cvvInput.render(elements.cvv, {
|
|
421
|
+
placeholder: '123',
|
|
422
|
+
ariaLabel: 'CVV',
|
|
423
|
+
style: inputStyle,
|
|
424
|
+
}),
|
|
425
|
+
]);
|
|
426
|
+
this.destroyCallbacks.push(() => {
|
|
427
|
+
pmManager.removeHostedInputs();
|
|
428
|
+
elements.cardholderName.removeEventListener('change', cardHolderOnChange);
|
|
429
|
+
});
|
|
430
|
+
return {
|
|
431
|
+
setDisabled: (disabled) => {
|
|
432
|
+
cardNumberInput.setDisabled(disabled);
|
|
433
|
+
expiryInput.setDisabled(disabled);
|
|
434
|
+
cvvInput.setDisabled(disabled);
|
|
435
|
+
elements.button.disabled = disabled;
|
|
436
|
+
},
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
throw new PrimerError('Failed to initialize Primer checkout', error);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async renderButton(allowedPaymentMethod, { container, }) {
|
|
444
|
+
const containerEl = this.validateContainer(container);
|
|
445
|
+
let button;
|
|
446
|
+
this.ensurePrimerAvailable();
|
|
447
|
+
if (!this.headless) {
|
|
448
|
+
throw new PrimerError('Headless checkout not found');
|
|
449
|
+
}
|
|
450
|
+
try {
|
|
451
|
+
const pmManager = await this.headless.createPaymentMethodManager(allowedPaymentMethod);
|
|
452
|
+
if (!pmManager) {
|
|
453
|
+
throw new Error('Payment method manager is not available');
|
|
454
|
+
}
|
|
455
|
+
button = pmManager.createButton();
|
|
456
|
+
await button.render(containerEl, {});
|
|
457
|
+
this.destroyCallbacks.push(() => button.clean());
|
|
458
|
+
}
|
|
459
|
+
catch (error) {
|
|
460
|
+
throw new PrimerError('Failed to initialize Primer checkout', error);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
async renderCheckout(clientToken, options) {
|
|
464
|
+
const { cardSelectors, paymentButtonSelectors, container, onTokenizeSuccess, onResumeSuccess, onSubmit, onInputChange, onMethodRender, onSubmitError, ...restPrimerOptions } = options;
|
|
465
|
+
await this.createHeadlessCheckout(clientToken, {
|
|
466
|
+
...restPrimerOptions,
|
|
467
|
+
onTokenizeSuccess: this.wrapTokenizeHandler(onTokenizeSuccess),
|
|
468
|
+
onResumeSuccess: this.wrapResumeHandler(onResumeSuccess),
|
|
469
|
+
onAvailablePaymentMethodsLoad: (items) => {
|
|
470
|
+
this.availableMethods = ALLOWED_PAYMENT_METHODS.filter(method => items.some((item) => item.type === method));
|
|
471
|
+
if (this.availableMethods.length === 0) {
|
|
472
|
+
throw new PrimerError('No allowed payment methods found');
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
onCheckoutFail: error => {
|
|
476
|
+
// eslint-disable-next-line no-console
|
|
477
|
+
console.error(error);
|
|
478
|
+
},
|
|
479
|
+
onTokenizeError: error => {
|
|
480
|
+
// eslint-disable-next-line no-console
|
|
481
|
+
console.error(error);
|
|
482
|
+
},
|
|
483
|
+
});
|
|
484
|
+
const methodOptions = {
|
|
485
|
+
cardSelectors,
|
|
486
|
+
container,
|
|
487
|
+
onSubmit,
|
|
488
|
+
onInputChange,
|
|
489
|
+
onSubmitError,
|
|
490
|
+
};
|
|
491
|
+
this.availableMethods.forEach(async (method) => {
|
|
492
|
+
if (method === PaymentMethod.PAYMENT_CARD) {
|
|
493
|
+
await this.renderCardCheckout(methodOptions);
|
|
494
|
+
onMethodRender(PaymentMethod.PAYMENT_CARD);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
const container = method === PaymentMethod.PAYPAL
|
|
498
|
+
? paymentButtonSelectors.paypal
|
|
499
|
+
: method === PaymentMethod.GOOGLE_PAY
|
|
500
|
+
? paymentButtonSelectors.googlePay
|
|
501
|
+
: paymentButtonSelectors.applePay;
|
|
502
|
+
await this.renderButton(method, { container });
|
|
503
|
+
onMethodRender(method);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
this.isInitialized = true;
|
|
507
|
+
}
|
|
508
|
+
wrapTokenizeHandler(handler) {
|
|
509
|
+
return async (paymentMethodTokenData, primerHandler) => {
|
|
510
|
+
try {
|
|
511
|
+
await handler(paymentMethodTokenData, primerHandler);
|
|
512
|
+
}
|
|
513
|
+
catch (error) {
|
|
514
|
+
// eslint-disable-next-line no-console
|
|
515
|
+
console.error('Error in tokenize handler:', error);
|
|
516
|
+
primerHandler.handleFailure('Payment processing failed. Please try again.');
|
|
517
|
+
}
|
|
946
518
|
};
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
519
|
+
}
|
|
520
|
+
wrapResumeHandler(handler) {
|
|
521
|
+
return async (resumeTokenData, primerHandler) => {
|
|
522
|
+
try {
|
|
523
|
+
await handler(resumeTokenData, primerHandler);
|
|
524
|
+
}
|
|
525
|
+
catch (error) {
|
|
526
|
+
// eslint-disable-next-line no-console
|
|
527
|
+
console.error('Error in resume handler:', error);
|
|
528
|
+
primerHandler.handleFailure('Payment processing failed. Please try again.');
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
async destroy() {
|
|
533
|
+
if (this.destroyCallbacks) {
|
|
534
|
+
try {
|
|
535
|
+
Promise.all(this.destroyCallbacks.map(destroy => destroy()));
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
// eslint-disable-next-line no-console
|
|
539
|
+
console.warn('Error destroying Primer checkout:', error);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
this.destroyCallbacks = [];
|
|
543
|
+
this.isInitialized = false;
|
|
544
|
+
}
|
|
545
|
+
createHandlers(handlers) {
|
|
952
546
|
return {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
547
|
+
handleSuccess: () => {
|
|
548
|
+
if (handlers.onSuccess)
|
|
549
|
+
handlers.onSuccess();
|
|
550
|
+
},
|
|
551
|
+
handleFailure: (message) => {
|
|
552
|
+
if (handlers.onError)
|
|
553
|
+
handlers.onError(new Error(message));
|
|
554
|
+
},
|
|
555
|
+
continueWithNewClientToken: (newClientToken) => {
|
|
556
|
+
if (handlers.onActionRequired)
|
|
557
|
+
handlers.onActionRequired(newClientToken);
|
|
558
|
+
},
|
|
956
559
|
};
|
|
957
|
-
default:
|
|
958
|
-
throw new APIError(`Unhandled checkout status: ${data.checkout_status}`, null, data);
|
|
959
560
|
}
|
|
960
|
-
|
|
961
|
-
|
|
561
|
+
getCurrentCheckout() {
|
|
562
|
+
return this.destroyCallbacks;
|
|
563
|
+
}
|
|
564
|
+
isActive() {
|
|
565
|
+
return this.isInitialized && this.destroyCallbacks.length > 0;
|
|
566
|
+
}
|
|
567
|
+
validateContainer(selector) {
|
|
568
|
+
const element = document.querySelector(selector);
|
|
569
|
+
if (!element) {
|
|
570
|
+
throw new PrimerError(`Checkout container not found: ${selector}`);
|
|
571
|
+
}
|
|
572
|
+
const computedStyle = window.getComputedStyle(element);
|
|
573
|
+
if (computedStyle.display === 'none') {
|
|
574
|
+
// eslint-disable-next-line no-console
|
|
575
|
+
console.warn('Checkout container is hidden, this may cause display issues');
|
|
576
|
+
}
|
|
577
|
+
return element;
|
|
578
|
+
}
|
|
962
579
|
}
|
|
963
580
|
|
|
964
581
|
/**
|
|
965
|
-
*
|
|
966
|
-
* @deprecated Use processSessionResponse() or processPaymentResponse() instead
|
|
967
|
-
* @param {Object} response - Raw API response
|
|
968
|
-
* @returns {Object} Processed response data
|
|
969
|
-
* @throws {APIError} If response indicates an error
|
|
582
|
+
* @fileoverview Input validation utilities for Funnefox SDK
|
|
970
583
|
*/
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
const data = response.data || response;
|
|
974
|
-
if (data.client_token && data.order_id && !data.checkout_status) {
|
|
975
|
-
return this.processSessionResponse(response);
|
|
976
|
-
}
|
|
977
|
-
if (data.checkout_status || data.action_required_token) {
|
|
978
|
-
return this.processPaymentResponse(response);
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
// Fallback for unknown response types
|
|
982
|
-
throw new APIError('Unknown response format', null, response);
|
|
584
|
+
function sanitizeString(input) {
|
|
585
|
+
return input?.trim() || '';
|
|
983
586
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
/**
|
|
992
|
-
* Checkout instance that manages the complete checkout lifecycle
|
|
993
|
-
* @typedef {import('./types').CheckoutInstance} CheckoutInstance
|
|
994
|
-
* @typedef {import('./types').CheckoutConfig} CheckoutConfig
|
|
995
|
-
* @typedef {import('./types').CheckoutConfigWithCallbacks} CheckoutConfigWithCallbacks
|
|
996
|
-
* @typedef {import('./types').PaymentResult} PaymentResult
|
|
997
|
-
* @typedef {import('./types').CheckoutState} CheckoutState
|
|
998
|
-
* @typedef {import('@primer-io/checkout-web').PaymentMethodTokenData} PaymentMethodTokenData
|
|
999
|
-
* @typedef {import('@primer-io/checkout-web').ResumeTokenData} ResumeTokenData
|
|
1000
|
-
* @typedef {import('@primer-io/checkout-web').ITokenizationHandler} PrimerHandler
|
|
1001
|
-
* @typedef {import('@primer-io/checkout-web').UniversalCheckoutOptions} UniversalCheckoutOptions
|
|
1002
|
-
*/
|
|
1003
|
-
class CheckoutInstance extends EventEmitter {
|
|
1004
|
-
/**
|
|
1005
|
-
* @param {Object} config - Checkout configuration
|
|
1006
|
-
* @param {string} config.orgId - Organization ID
|
|
1007
|
-
* @param {string} [config.baseUrl] - API base URL
|
|
1008
|
-
* @param {string} [config.region] - Region
|
|
1009
|
-
* @param {CheckoutConfig | CheckoutConfigWithCallbacks} config.checkoutConfig - Checkout configuration
|
|
1010
|
-
*/
|
|
1011
|
-
constructor(config) {
|
|
1012
|
-
super();
|
|
1013
|
-
this.id = generateId('checkout_');
|
|
1014
|
-
this.orgId = config.orgId;
|
|
1015
|
-
this.baseUrl = config.baseUrl;
|
|
1016
|
-
this.region = config.region;
|
|
1017
|
-
this.checkoutConfig = {
|
|
1018
|
-
...config.checkoutConfig
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
|
-
// Extract callbacks from config
|
|
1022
|
-
this.callbacks = {
|
|
1023
|
-
onSuccess: this.checkoutConfig.onSuccess,
|
|
1024
|
-
onError: this.checkoutConfig.onError,
|
|
1025
|
-
onStatusChange: this.checkoutConfig.onStatusChange,
|
|
1026
|
-
onDestroy: this.checkoutConfig.onDestroy
|
|
1027
|
-
};
|
|
1028
|
-
|
|
1029
|
-
// Clean callbacks from config to avoid sending to API
|
|
1030
|
-
delete this.checkoutConfig.onSuccess;
|
|
1031
|
-
delete this.checkoutConfig.onError;
|
|
1032
|
-
delete this.checkoutConfig.onStatusChange;
|
|
1033
|
-
delete this.checkoutConfig.onDestroy;
|
|
1034
|
-
|
|
1035
|
-
// Internal state
|
|
1036
|
-
this.state = 'initializing';
|
|
1037
|
-
this.orderId = null;
|
|
1038
|
-
this.clientToken = null;
|
|
1039
|
-
this.primerWrapper = new PrimerWrapper();
|
|
1040
|
-
this.isDestroyed = false;
|
|
1041
|
-
|
|
1042
|
-
// Set up callback bridges if provided
|
|
1043
|
-
this._setupCallbackBridges();
|
|
1044
|
-
|
|
1045
|
-
// Bind methods to preserve context
|
|
1046
|
-
this._handleTokenizeSuccess = this._handleTokenizeSuccess.bind(this);
|
|
1047
|
-
this._handleResumeSuccess = this._handleResumeSuccess.bind(this);
|
|
587
|
+
function requireString(value, fieldName) {
|
|
588
|
+
const sanitized = sanitizeString(value);
|
|
589
|
+
if (sanitized.length === 0) {
|
|
590
|
+
throw new ValidationError(fieldName, 'must be a non-empty string', value);
|
|
591
|
+
}
|
|
592
|
+
return true;
|
|
1048
593
|
}
|
|
1049
594
|
|
|
1050
595
|
/**
|
|
1051
|
-
*
|
|
1052
|
-
* @private
|
|
596
|
+
* @fileoverview API client for Funnefox backend integration
|
|
1053
597
|
*/
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
598
|
+
class APIClient {
|
|
599
|
+
constructor(config) {
|
|
600
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, '');
|
|
601
|
+
this.orgId = config.orgId;
|
|
602
|
+
this.timeout = config.timeout || 30000;
|
|
603
|
+
this.retryAttempts = config.retryAttempts || 3;
|
|
604
|
+
}
|
|
605
|
+
async request(endpoint, options = {}) {
|
|
606
|
+
const url = `${this.baseUrl}/${this.orgId}${endpoint}`;
|
|
607
|
+
const requestOptions = {
|
|
608
|
+
method: 'GET',
|
|
609
|
+
headers: {
|
|
610
|
+
'Content-Type': 'application/json',
|
|
611
|
+
...(options.headers || {}),
|
|
612
|
+
},
|
|
613
|
+
...options,
|
|
614
|
+
};
|
|
615
|
+
try {
|
|
616
|
+
return await retry(async () => {
|
|
617
|
+
return await withTimeout(this._makeRequest(url, requestOptions), this.timeout, 'Request timed out');
|
|
618
|
+
}, this.retryAttempts);
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
if (error instanceof Error && error.name === 'APIError') {
|
|
622
|
+
throw error;
|
|
623
|
+
}
|
|
624
|
+
throw new NetworkError('Network request failed', error);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
async _makeRequest(url, options) {
|
|
628
|
+
let response;
|
|
629
|
+
try {
|
|
630
|
+
response = await fetch(url, options);
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
if (error instanceof Error && error.name === 'NetworkError') {
|
|
634
|
+
throw error;
|
|
635
|
+
}
|
|
636
|
+
throw new NetworkError('Network request failed', error);
|
|
637
|
+
}
|
|
638
|
+
let data;
|
|
639
|
+
try {
|
|
640
|
+
data = await response.json();
|
|
641
|
+
}
|
|
642
|
+
catch {
|
|
643
|
+
throw new APIError('Invalid JSON response', response.status, {});
|
|
644
|
+
}
|
|
645
|
+
if (!response.ok) {
|
|
646
|
+
const d = data;
|
|
647
|
+
const message = d.message instanceof Array
|
|
648
|
+
? d.message[0].msg
|
|
649
|
+
: d.message || d.error || `HTTP ${response.status}`;
|
|
650
|
+
throw new APIError(message, response.status, {
|
|
651
|
+
response: data,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
return data;
|
|
655
|
+
}
|
|
656
|
+
async createClientSession(params) {
|
|
657
|
+
const payload = {
|
|
658
|
+
region: params.region || 'default',
|
|
659
|
+
integration_type: 'primer',
|
|
660
|
+
pp_ident: params.priceId,
|
|
661
|
+
external_id: params.externalId,
|
|
662
|
+
email_address: params.email,
|
|
663
|
+
client_metadata: params.clientMetadata || {},
|
|
664
|
+
};
|
|
665
|
+
if (params.countryCode !== undefined) {
|
|
666
|
+
payload.country_code = params.countryCode;
|
|
667
|
+
}
|
|
668
|
+
return (await this.request(API_ENDPOINTS.CREATE_CLIENT_SESSION, {
|
|
669
|
+
method: 'POST',
|
|
670
|
+
body: JSON.stringify(payload),
|
|
671
|
+
}));
|
|
672
|
+
}
|
|
673
|
+
async updateClientSession(params) {
|
|
674
|
+
const payload = {
|
|
675
|
+
order_id: params.orderId,
|
|
676
|
+
client_token: params.clientToken,
|
|
677
|
+
pp_ident: params.priceId,
|
|
678
|
+
};
|
|
679
|
+
return await this.request(API_ENDPOINTS.UPDATE_CLIENT_SESSION, {
|
|
680
|
+
method: 'POST',
|
|
681
|
+
body: JSON.stringify(payload),
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
async createPayment(params) {
|
|
685
|
+
const payload = {
|
|
686
|
+
order_id: params.orderId,
|
|
687
|
+
payment_method_token: params.paymentMethodToken,
|
|
688
|
+
};
|
|
689
|
+
return (await this.request(API_ENDPOINTS.CREATE_PAYMENT, {
|
|
690
|
+
method: 'POST',
|
|
691
|
+
body: JSON.stringify(payload),
|
|
692
|
+
}));
|
|
693
|
+
}
|
|
694
|
+
async resumePayment(params) {
|
|
695
|
+
const payload = {
|
|
696
|
+
order_id: params.orderId,
|
|
697
|
+
resume_token: params.resumeToken,
|
|
698
|
+
};
|
|
699
|
+
return (await this.request(API_ENDPOINTS.RESUME_PAYMENT, {
|
|
700
|
+
method: 'POST',
|
|
701
|
+
body: JSON.stringify(payload),
|
|
702
|
+
}));
|
|
703
|
+
}
|
|
704
|
+
processSessionResponse(response) {
|
|
705
|
+
if (response.status === 'error') {
|
|
706
|
+
const firstError = response.error?.[0];
|
|
707
|
+
const message = firstError?.msg || 'Session creation failed';
|
|
708
|
+
throw new APIError(message, null, {
|
|
709
|
+
errorCode: firstError?.code,
|
|
710
|
+
errorType: firstError?.type,
|
|
711
|
+
requestId: response.req_id,
|
|
712
|
+
response,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
const data = response.data;
|
|
716
|
+
return {
|
|
717
|
+
type: 'session_created',
|
|
718
|
+
orderId: data.order_id,
|
|
719
|
+
clientToken: data.client_token,
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
processPaymentResponse(response) {
|
|
723
|
+
if (response.status === 'error') {
|
|
724
|
+
const firstError = response.error?.[0];
|
|
725
|
+
const message = firstError?.msg || 'Payment request failed';
|
|
726
|
+
throw new APIError(message, null, {
|
|
727
|
+
errorCode: firstError?.code,
|
|
728
|
+
errorType: firstError?.type,
|
|
729
|
+
response,
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
const data = response.data;
|
|
733
|
+
if (data.action_required_token) {
|
|
734
|
+
return {
|
|
735
|
+
type: 'action_required',
|
|
736
|
+
orderId: data.order_id,
|
|
737
|
+
clientToken: data.action_required_token,
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
if (data.checkout_status) {
|
|
741
|
+
switch (data.checkout_status) {
|
|
742
|
+
case 'succeeded':
|
|
743
|
+
return {
|
|
744
|
+
type: 'success',
|
|
745
|
+
orderId: data.order_id,
|
|
746
|
+
status: 'succeeded',
|
|
747
|
+
};
|
|
748
|
+
case 'failed':
|
|
749
|
+
throw new APIError(data.failed_message_for_user || 'Payment failed', null, { response });
|
|
750
|
+
case 'cancelled':
|
|
751
|
+
throw new APIError('Payment was cancelled by user', null, {
|
|
752
|
+
response,
|
|
753
|
+
});
|
|
754
|
+
case 'processing':
|
|
755
|
+
return {
|
|
756
|
+
type: 'processing',
|
|
757
|
+
orderId: data.order_id,
|
|
758
|
+
status: 'processing',
|
|
759
|
+
};
|
|
760
|
+
default:
|
|
761
|
+
throw new APIError(`Unhandled checkout status: ${data.checkout_status}`, null, { response });
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
throw new APIError('Invalid payment response format', null, { response });
|
|
765
|
+
}
|
|
1067
766
|
}
|
|
1068
767
|
|
|
1069
768
|
/**
|
|
1070
|
-
*
|
|
1071
|
-
* @returns {Promise<CheckoutInstance>} Returns this instance for chaining
|
|
769
|
+
* @fileoverview Checkout instance manager for Funnefox SDK
|
|
1072
770
|
*/
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
771
|
+
class CheckoutInstance extends EventEmitter {
|
|
772
|
+
constructor(config) {
|
|
773
|
+
super();
|
|
774
|
+
this.counter = 0;
|
|
775
|
+
this.handleInputChange = (inputName, error) => {
|
|
776
|
+
this.emit(EVENTS.INPUT_ERROR, { name: inputName, error });
|
|
777
|
+
};
|
|
778
|
+
this.handleMethodRender = (method) => {
|
|
779
|
+
this.emit(EVENTS.METHOD_RENDER, method);
|
|
780
|
+
};
|
|
781
|
+
this.handleSubmit = (isSubmitting) => {
|
|
782
|
+
if (isSubmitting) {
|
|
783
|
+
// Clear any previous errors
|
|
784
|
+
this.emit(EVENTS.ERROR, undefined);
|
|
785
|
+
this.emit(EVENTS.START_PURCHASE, PaymentMethod.PAYMENT_CARD);
|
|
786
|
+
}
|
|
787
|
+
this.onLoaderChangeWithRace(isSubmitting);
|
|
788
|
+
this._setState(isSubmitting ? 'processing' : 'ready');
|
|
789
|
+
};
|
|
790
|
+
this.handleTokenizeSuccess = async (paymentMethodTokenData, primerHandler) => {
|
|
791
|
+
try {
|
|
792
|
+
this.emit(EVENTS.START_PURCHASE, paymentMethodTokenData.paymentInstrumentType);
|
|
793
|
+
this.onLoaderChangeWithRace(true);
|
|
794
|
+
this._setState('processing');
|
|
795
|
+
const paymentResponse = await this.apiClient.createPayment({
|
|
796
|
+
orderId: this.orderId,
|
|
797
|
+
paymentMethodToken: paymentMethodTokenData.token,
|
|
798
|
+
});
|
|
799
|
+
const result = this.apiClient.processPaymentResponse(paymentResponse);
|
|
800
|
+
await this._processPaymentResult(result, primerHandler);
|
|
801
|
+
}
|
|
802
|
+
catch (error) {
|
|
803
|
+
this._setState('error');
|
|
804
|
+
this.emit(EVENTS.PURCHASE_FAILURE, error);
|
|
805
|
+
primerHandler.handleFailure(error.message || 'Payment processing failed');
|
|
806
|
+
}
|
|
807
|
+
finally {
|
|
808
|
+
this.onLoaderChangeWithRace(false);
|
|
809
|
+
this._setState('ready');
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
this.handleResumeSuccess = async (resumeTokenData, primerHandler) => {
|
|
813
|
+
try {
|
|
814
|
+
this.onLoaderChangeWithRace(true);
|
|
815
|
+
this._setState('processing');
|
|
816
|
+
const resumeResponse = await this.apiClient.resumePayment({
|
|
817
|
+
orderId: this.orderId,
|
|
818
|
+
resumeToken: resumeTokenData.resumeToken,
|
|
819
|
+
});
|
|
820
|
+
const result = this.apiClient.processPaymentResponse(resumeResponse);
|
|
821
|
+
await this._processPaymentResult(result, primerHandler);
|
|
822
|
+
}
|
|
823
|
+
catch (error) {
|
|
824
|
+
this._setState('error');
|
|
825
|
+
this.emit(EVENTS.PURCHASE_FAILURE, error);
|
|
826
|
+
primerHandler.handleFailure(error.message || 'Payment processing failed');
|
|
827
|
+
}
|
|
828
|
+
finally {
|
|
829
|
+
this.emit(EVENTS.PURCHASE_COMPLETED);
|
|
830
|
+
this.onLoaderChangeWithRace(false);
|
|
831
|
+
this._setState('ready');
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
this.onLoaderChangeWithRace = (state) => {
|
|
835
|
+
const isLoading = !!(state ? ++this.counter : --this.counter);
|
|
836
|
+
this.emit(EVENTS.LOADER_CHANGE, isLoading);
|
|
837
|
+
};
|
|
838
|
+
this.id = generateId('checkout_');
|
|
839
|
+
this.orgId = config.orgId;
|
|
840
|
+
this.baseUrl = config.baseUrl;
|
|
841
|
+
this.region = config.region;
|
|
842
|
+
this.checkoutConfig = { ...config.checkoutConfig };
|
|
843
|
+
this.callbacks = {
|
|
844
|
+
onSuccess: this.checkoutConfig.onSuccess,
|
|
845
|
+
onError: this.checkoutConfig.onError,
|
|
846
|
+
onStatusChange: this.checkoutConfig.onStatusChange,
|
|
847
|
+
onDestroy: this.checkoutConfig.onDestroy,
|
|
848
|
+
};
|
|
849
|
+
delete this.checkoutConfig?.onSuccess;
|
|
850
|
+
delete this.checkoutConfig?.onError;
|
|
851
|
+
delete this.checkoutConfig?.onStatusChange;
|
|
852
|
+
delete this.checkoutConfig?.onDestroy;
|
|
853
|
+
this.state = 'initializing';
|
|
854
|
+
this.orderId = null;
|
|
855
|
+
this.clientToken = null;
|
|
856
|
+
this.primerWrapper = new PrimerWrapper();
|
|
857
|
+
this.isDestroyed = false;
|
|
858
|
+
this._setupCallbackBridges();
|
|
859
|
+
}
|
|
860
|
+
_setupCallbackBridges() {
|
|
861
|
+
if (this.callbacks.onSuccess) {
|
|
862
|
+
this.on(EVENTS.SUCCESS, this.callbacks.onSuccess);
|
|
863
|
+
}
|
|
864
|
+
if (this.callbacks.onError) {
|
|
865
|
+
this.on(EVENTS.ERROR, this.callbacks.onError);
|
|
866
|
+
}
|
|
867
|
+
if (this.callbacks.onStatusChange) {
|
|
868
|
+
this.on(EVENTS.STATUS_CHANGE, this.callbacks.onStatusChange);
|
|
869
|
+
}
|
|
870
|
+
if (this.callbacks.onDestroy) {
|
|
871
|
+
this.on(EVENTS.DESTROY, this.callbacks.onDestroy);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
removeAllListeners() {
|
|
875
|
+
return super.removeAllListeners();
|
|
876
|
+
}
|
|
877
|
+
async initialize() {
|
|
878
|
+
try {
|
|
879
|
+
this._setState('initializing');
|
|
880
|
+
this.apiClient = new APIClient({
|
|
881
|
+
baseUrl: this.baseUrl || DEFAULTS.BASE_URL,
|
|
882
|
+
orgId: this.orgId,
|
|
883
|
+
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
884
|
+
retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
|
|
885
|
+
});
|
|
886
|
+
const sessionResponse = await this.apiClient.createClientSession({
|
|
887
|
+
priceId: this.checkoutConfig.priceId,
|
|
888
|
+
externalId: this.checkoutConfig.customer.externalId,
|
|
889
|
+
email: this.checkoutConfig.customer.email,
|
|
890
|
+
region: this.region || DEFAULTS.REGION,
|
|
891
|
+
clientMetadata: this.checkoutConfig.clientMetadata,
|
|
892
|
+
countryCode: this.checkoutConfig.customer.countryCode,
|
|
893
|
+
});
|
|
894
|
+
const sessionData = this.apiClient.processSessionResponse(sessionResponse);
|
|
895
|
+
this.orderId = sessionData.orderId;
|
|
896
|
+
this.clientToken = sessionData.clientToken;
|
|
897
|
+
await this._initializePrimerCheckout();
|
|
898
|
+
this._setState('ready');
|
|
899
|
+
return this;
|
|
900
|
+
}
|
|
901
|
+
catch (error) {
|
|
902
|
+
this._setState('error');
|
|
903
|
+
this.emit(EVENTS.ERROR, error);
|
|
904
|
+
throw error;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
async _initializePrimerCheckout() {
|
|
908
|
+
const checkoutOptions = {
|
|
909
|
+
...this.checkoutConfig,
|
|
910
|
+
onTokenizeSuccess: this.handleTokenizeSuccess,
|
|
911
|
+
onResumeSuccess: this.handleResumeSuccess,
|
|
912
|
+
onSubmit: this.handleSubmit,
|
|
913
|
+
onInputChange: this.handleInputChange,
|
|
914
|
+
onMethodRender: this.handleMethodRender,
|
|
915
|
+
onSubmitError: (error) => this.emit(EVENTS.PURCHASE_FAILURE, error),
|
|
916
|
+
};
|
|
917
|
+
if (!this.checkoutConfig.cardSelectors ||
|
|
918
|
+
!this.checkoutConfig.paymentButtonSelectors) {
|
|
919
|
+
const cardSelectors = await this.createCardElements();
|
|
920
|
+
const paymentButtonSelectors = {
|
|
921
|
+
paypal: '#paypalButton',
|
|
922
|
+
googlePay: '#googlePayButton',
|
|
923
|
+
applePay: '#applePayButton',
|
|
924
|
+
};
|
|
925
|
+
checkoutOptions.cardSelectors = cardSelectors;
|
|
926
|
+
checkoutOptions.paymentButtonSelectors = paymentButtonSelectors;
|
|
927
|
+
checkoutOptions.card = {
|
|
928
|
+
cardholderName: {
|
|
929
|
+
required: false,
|
|
930
|
+
},
|
|
931
|
+
};
|
|
932
|
+
checkoutOptions.applePay = {
|
|
933
|
+
buttonStyle: 'black',
|
|
934
|
+
};
|
|
935
|
+
checkoutOptions.paypal = {
|
|
936
|
+
buttonColor: 'gold',
|
|
937
|
+
buttonShape: 'pill',
|
|
938
|
+
};
|
|
939
|
+
checkoutOptions.googlePay = {
|
|
940
|
+
buttonColor: 'black',
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
await this.primerWrapper.renderCheckout(this.clientToken, checkoutOptions);
|
|
944
|
+
}
|
|
945
|
+
async _processPaymentResult(result, primerHandler) {
|
|
946
|
+
if (result.orderId) {
|
|
947
|
+
this.orderId = result.orderId;
|
|
948
|
+
}
|
|
949
|
+
switch (result.type) {
|
|
950
|
+
case 'success':
|
|
951
|
+
this._setState('completed');
|
|
952
|
+
this.emit(EVENTS.SUCCESS, {
|
|
953
|
+
orderId: result.orderId,
|
|
954
|
+
status: result.status,
|
|
955
|
+
});
|
|
956
|
+
primerHandler.handleSuccess();
|
|
957
|
+
break;
|
|
958
|
+
case 'action_required':
|
|
959
|
+
this._setState('action_required');
|
|
960
|
+
this.clientToken = result.clientToken;
|
|
961
|
+
primerHandler.continueWithNewClientToken(result.clientToken);
|
|
962
|
+
break;
|
|
963
|
+
case 'processing':
|
|
964
|
+
this._setState('processing');
|
|
965
|
+
setTimeout(() => {
|
|
966
|
+
primerHandler.handleFailure('Payment is still processing. Please check back later.');
|
|
967
|
+
}, 30000);
|
|
968
|
+
break;
|
|
969
|
+
default:
|
|
970
|
+
throw new CheckoutError(`Unknown payment result type: ${result.type}`);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
async updatePrice(newPriceId) {
|
|
974
|
+
this._ensureNotDestroyed();
|
|
975
|
+
requireString(newPriceId, 'priceId');
|
|
976
|
+
if (this.state === 'processing') {
|
|
977
|
+
throw new CheckoutError('Cannot update price while payment is processing');
|
|
978
|
+
}
|
|
979
|
+
try {
|
|
980
|
+
this._setState('updating');
|
|
981
|
+
await this.apiClient.updateClientSession({
|
|
982
|
+
orderId: this.orderId,
|
|
983
|
+
clientToken: this.clientToken,
|
|
984
|
+
priceId: newPriceId,
|
|
985
|
+
});
|
|
986
|
+
this.checkoutConfig.priceId = newPriceId;
|
|
987
|
+
this._setState('ready');
|
|
988
|
+
}
|
|
989
|
+
catch (error) {
|
|
990
|
+
this._setState('error');
|
|
991
|
+
this.emit(EVENTS.ERROR, error);
|
|
992
|
+
throw error;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
getStatus() {
|
|
996
|
+
return {
|
|
997
|
+
id: this.id,
|
|
998
|
+
state: this.state,
|
|
999
|
+
orderId: this.orderId,
|
|
1000
|
+
priceId: this.checkoutConfig.priceId,
|
|
1001
|
+
isDestroyed: this.isDestroyed,
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
async destroy() {
|
|
1005
|
+
if (this.isDestroyed)
|
|
1006
|
+
return;
|
|
1007
|
+
try {
|
|
1008
|
+
await this.primerWrapper.destroy();
|
|
1009
|
+
this._setState('destroyed');
|
|
1010
|
+
this.orderId = null;
|
|
1011
|
+
this.clientToken = null;
|
|
1012
|
+
this.isDestroyed = true;
|
|
1013
|
+
this.emit(EVENTS.DESTROY);
|
|
1014
|
+
this.removeAllListeners();
|
|
1015
|
+
}
|
|
1016
|
+
catch (error) {
|
|
1017
|
+
// eslint-disable-next-line no-console
|
|
1018
|
+
console.warn('Error during checkout cleanup:', error);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
_setState(newState) {
|
|
1022
|
+
if (this.state !== newState) {
|
|
1023
|
+
const oldState = this.state;
|
|
1024
|
+
this.state = newState;
|
|
1025
|
+
this.emit(EVENTS.STATUS_CHANGE, newState, oldState);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
_ensureNotDestroyed() {
|
|
1029
|
+
if (this.isDestroyed) {
|
|
1030
|
+
throw new CheckoutError('Checkout instance has been destroyed');
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
getContainer() {
|
|
1034
|
+
return document.querySelector(this.checkoutConfig.container);
|
|
1035
|
+
}
|
|
1036
|
+
isInState(state) {
|
|
1037
|
+
return this.state === state;
|
|
1038
|
+
}
|
|
1039
|
+
isReady() {
|
|
1040
|
+
return this.state === 'ready' && !this.isDestroyed;
|
|
1041
|
+
}
|
|
1042
|
+
isProcessing() {
|
|
1043
|
+
return ['processing', 'action_required'].includes(this.state);
|
|
1044
|
+
}
|
|
1045
|
+
// Creates containers to render hosted inputs with labels and error messages,
|
|
1046
|
+
// a card holder input with label and error, and a submit button.
|
|
1047
|
+
async createCardElements() {
|
|
1048
|
+
const skinFactory = (await Promise.resolve().then(function () { return index; }))
|
|
1049
|
+
.default;
|
|
1050
|
+
const skin = await skinFactory(this.primerWrapper, this.checkoutConfig.container);
|
|
1051
|
+
this.on(EVENTS.INPUT_ERROR, skin.onInputError);
|
|
1052
|
+
this.on(EVENTS.STATUS_CHANGE, skin.onStatusChange);
|
|
1053
|
+
this.on(EVENTS.ERROR, (error) => skin.onError(error));
|
|
1054
|
+
this.on(EVENTS.LOADER_CHANGE, skin.onLoaderChange);
|
|
1055
|
+
this.on(EVENTS.DESTROY, skin.onDestroy);
|
|
1056
|
+
this.on(EVENTS.METHOD_RENDER, skin.onMethodRender);
|
|
1057
|
+
this.on(EVENTS.SUCCESS, skin.onSuccess);
|
|
1058
|
+
this.on(EVENTS.START_PURCHASE, skin.onStartPurchase);
|
|
1059
|
+
this.on(EVENTS.PURCHASE_FAILURE, skin.onPurchaseFailure);
|
|
1060
|
+
this.on(EVENTS.PURCHASE_COMPLETED, skin.onPurchaseCompleted);
|
|
1061
|
+
return skin.getCardInputSelectors();
|
|
1062
|
+
}
|
|
1108
1063
|
}
|
|
1109
1064
|
|
|
1110
1065
|
/**
|
|
1111
|
-
*
|
|
1112
|
-
* @private
|
|
1066
|
+
* @fileoverview Public API with configuration and orchestration logic
|
|
1113
1067
|
*/
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
container: this.checkoutConfig.container,
|
|
1118
|
-
onTokenizeSuccess: this._handleTokenizeSuccess,
|
|
1119
|
-
onResumeSuccess: this._handleResumeSuccess,
|
|
1120
|
-
...(this.checkoutConfig.universalCheckoutOptions || {})
|
|
1121
|
-
};
|
|
1122
|
-
await this.primerWrapper.showUniversalCheckout(this.clientToken, checkoutOptions);
|
|
1068
|
+
let defaultConfig = null;
|
|
1069
|
+
function configure(config) {
|
|
1070
|
+
defaultConfig = config;
|
|
1123
1071
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
});
|
|
1138
|
-
const result = this.apiClient.processPaymentResponse(paymentResponse);
|
|
1139
|
-
await this._processPaymentResult(result, primerHandler);
|
|
1140
|
-
} catch (error) {
|
|
1141
|
-
this._setState('error');
|
|
1142
|
-
this.emit('error', error);
|
|
1143
|
-
primerHandler.handleFailure(error.message || 'Payment processing failed');
|
|
1144
|
-
}
|
|
1072
|
+
function resolveConfig(options, functionName) {
|
|
1073
|
+
const { orgId, apiConfig } = options || {};
|
|
1074
|
+
const finalOrgId = orgId || defaultConfig?.orgId;
|
|
1075
|
+
if (!finalOrgId) {
|
|
1076
|
+
throw new Error(`orgId is required. Pass it to ${functionName}() or call configure() first.`);
|
|
1077
|
+
}
|
|
1078
|
+
const finalBaseUrl = apiConfig?.baseUrl || defaultConfig?.baseUrl || DEFAULTS.BASE_URL;
|
|
1079
|
+
const finalRegion = apiConfig?.region || defaultConfig?.region || DEFAULTS.REGION;
|
|
1080
|
+
return {
|
|
1081
|
+
orgId: finalOrgId,
|
|
1082
|
+
baseUrl: finalBaseUrl,
|
|
1083
|
+
region: finalRegion,
|
|
1084
|
+
};
|
|
1145
1085
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
try {
|
|
1155
|
-
this._setState('processing');
|
|
1156
|
-
const resumeResponse = await this.apiClient.resumePayment({
|
|
1157
|
-
orderId: this.orderId,
|
|
1158
|
-
resumeToken: resumeTokenData.resumeToken
|
|
1086
|
+
async function createCheckout(options) {
|
|
1087
|
+
const { ...checkoutConfig } = options;
|
|
1088
|
+
const primerWrapper = new PrimerWrapper();
|
|
1089
|
+
primerWrapper.ensurePrimerAvailable();
|
|
1090
|
+
const config = resolveConfig(options, 'createCheckout');
|
|
1091
|
+
const checkout = new CheckoutInstance({
|
|
1092
|
+
...config,
|
|
1093
|
+
checkoutConfig,
|
|
1159
1094
|
});
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
} catch (error) {
|
|
1163
|
-
this._setState('error');
|
|
1164
|
-
this.emit('error', error);
|
|
1165
|
-
primerHandler.handleFailure(error.message || 'Payment processing failed');
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
/**
|
|
1170
|
-
* Process payment result and handle different scenarios
|
|
1171
|
-
* @private
|
|
1172
|
-
*/
|
|
1173
|
-
async _processPaymentResult(result, primerHandler) {
|
|
1174
|
-
// Update order ID if it changed
|
|
1175
|
-
if (result.orderId) {
|
|
1176
|
-
this.orderId = result.orderId;
|
|
1177
|
-
}
|
|
1178
|
-
switch (result.type) {
|
|
1179
|
-
case 'success':
|
|
1180
|
-
this._setState('completed');
|
|
1181
|
-
this.emit('success', {
|
|
1182
|
-
orderId: result.orderId,
|
|
1183
|
-
status: result.status,
|
|
1184
|
-
transactionId: result.transactionId,
|
|
1185
|
-
metadata: result.metadata
|
|
1186
|
-
});
|
|
1187
|
-
primerHandler.handleSuccess();
|
|
1188
|
-
break;
|
|
1189
|
-
case 'action_required':
|
|
1190
|
-
this._setState('action_required');
|
|
1191
|
-
// Update client token and continue
|
|
1192
|
-
this.clientToken = result.clientToken;
|
|
1193
|
-
primerHandler.continueWithNewClientToken(result.clientToken);
|
|
1194
|
-
break;
|
|
1195
|
-
case 'processing':
|
|
1196
|
-
this._setState('processing');
|
|
1197
|
-
// Let the payment process - usually requires polling or webhook
|
|
1198
|
-
setTimeout(() => {
|
|
1199
|
-
primerHandler.handleFailure('Payment is still processing. Please check back later.');
|
|
1200
|
-
}, 30000);
|
|
1201
|
-
break;
|
|
1202
|
-
default:
|
|
1203
|
-
throw new CheckoutError(`Unknown payment result type: ${result.type}`);
|
|
1204
|
-
}
|
|
1095
|
+
await checkout.initialize();
|
|
1096
|
+
return checkout;
|
|
1205
1097
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
requireString(newPriceId, 'priceId');
|
|
1215
|
-
if (this.state === 'processing') {
|
|
1216
|
-
throw new CheckoutError('Cannot update price while payment is processing');
|
|
1217
|
-
}
|
|
1218
|
-
try {
|
|
1219
|
-
this._setState('updating');
|
|
1220
|
-
|
|
1221
|
-
// Update client session with new price
|
|
1222
|
-
await this.apiClient.updateClientSession({
|
|
1223
|
-
orderId: this.orderId,
|
|
1224
|
-
clientToken: this.clientToken,
|
|
1225
|
-
priceId: newPriceId
|
|
1098
|
+
async function createClientSession(params) {
|
|
1099
|
+
const { priceId, externalId, email, clientMetadata, countryCode } = params;
|
|
1100
|
+
const config = resolveConfig(params, 'createClientSession');
|
|
1101
|
+
const apiClient = new APIClient({
|
|
1102
|
+
baseUrl: config.baseUrl,
|
|
1103
|
+
orgId: config.orgId,
|
|
1104
|
+
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
1105
|
+
retryAttempts: DEFAULTS.RETRY_ATTEMPTS,
|
|
1226
1106
|
});
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
* Get current checkout status
|
|
1239
|
-
* @returns {Object} Status information
|
|
1240
|
-
*/
|
|
1241
|
-
getStatus() {
|
|
1242
|
-
return {
|
|
1243
|
-
id: this.id,
|
|
1244
|
-
state: this.state,
|
|
1245
|
-
orderId: this.orderId,
|
|
1246
|
-
priceId: this.checkoutConfig.priceId,
|
|
1247
|
-
isDestroyed: this.isDestroyed
|
|
1248
|
-
};
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
/**
|
|
1252
|
-
* Destroy the checkout instance and clean up resources
|
|
1253
|
-
* @returns {Promise<void>}
|
|
1254
|
-
*/
|
|
1255
|
-
async destroy() {
|
|
1256
|
-
if (this.isDestroyed) {
|
|
1257
|
-
return;
|
|
1258
|
-
}
|
|
1259
|
-
try {
|
|
1260
|
-
// Clean up Primer checkout
|
|
1261
|
-
await this.primerWrapper.destroy();
|
|
1262
|
-
|
|
1263
|
-
// Clear state
|
|
1264
|
-
this._setState('destroyed');
|
|
1265
|
-
this.orderId = null;
|
|
1266
|
-
this.clientToken = null;
|
|
1267
|
-
this.isDestroyed = true;
|
|
1268
|
-
|
|
1269
|
-
// Emit destroy event
|
|
1270
|
-
this.emit('destroy');
|
|
1271
|
-
|
|
1272
|
-
// Remove all listeners
|
|
1273
|
-
this.removeAllListeners();
|
|
1274
|
-
} catch (error) {
|
|
1275
|
-
console.warn('Error during checkout cleanup:', error);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
/**
|
|
1280
|
-
* Set internal state and emit change events
|
|
1281
|
-
* @private
|
|
1282
|
-
*/
|
|
1283
|
-
_setState(newState) {
|
|
1284
|
-
if (this.state !== newState) {
|
|
1285
|
-
const oldState = this.state;
|
|
1286
|
-
this.state = newState;
|
|
1287
|
-
this.emit('status-change', newState, oldState);
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
/**
|
|
1292
|
-
* Ensure checkout is not destroyed
|
|
1293
|
-
* @private
|
|
1294
|
-
*/
|
|
1295
|
-
_ensureNotDestroyed() {
|
|
1296
|
-
if (this.isDestroyed) {
|
|
1297
|
-
throw new CheckoutError('Checkout instance has been destroyed');
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
/**
|
|
1302
|
-
* Get the container element
|
|
1303
|
-
* @returns {Element} Container element
|
|
1304
|
-
*/
|
|
1305
|
-
getContainer() {
|
|
1306
|
-
return document.querySelector(this.checkoutConfig.container);
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
/**
|
|
1310
|
-
* Check if checkout is in a given state
|
|
1311
|
-
* @param {string} state - State to check
|
|
1312
|
-
* @returns {boolean} True if in the specified state
|
|
1313
|
-
*/
|
|
1314
|
-
isInState(state) {
|
|
1315
|
-
return this.state === state;
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
/**
|
|
1319
|
-
* Check if checkout is ready for user interaction
|
|
1320
|
-
* @returns {boolean} True if ready
|
|
1321
|
-
*/
|
|
1322
|
-
isReady() {
|
|
1323
|
-
return this.state === 'ready' && !this.isDestroyed;
|
|
1107
|
+
const sessionResponse = await apiClient.createClientSession({
|
|
1108
|
+
priceId,
|
|
1109
|
+
externalId,
|
|
1110
|
+
email,
|
|
1111
|
+
region: config.region,
|
|
1112
|
+
clientMetadata,
|
|
1113
|
+
countryCode,
|
|
1114
|
+
});
|
|
1115
|
+
return apiClient.processSessionResponse(sessionResponse);
|
|
1324
1116
|
}
|
|
1325
1117
|
|
|
1326
1118
|
/**
|
|
1327
|
-
*
|
|
1328
|
-
* @returns {boolean} True if processing
|
|
1119
|
+
* @fileoverview Main entry point for @funnelfox/billing
|
|
1329
1120
|
*/
|
|
1330
|
-
|
|
1331
|
-
|
|
1121
|
+
const Billing = {
|
|
1122
|
+
configure: configure,
|
|
1123
|
+
createCheckout: createCheckout,
|
|
1124
|
+
createClientSession: createClientSession,
|
|
1125
|
+
};
|
|
1126
|
+
if (typeof window !== 'undefined') {
|
|
1127
|
+
window.Billing = Billing;
|
|
1332
1128
|
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
/**
|
|
1336
|
-
* @fileoverview Public API with configuration and orchestration logic
|
|
1337
|
-
*/
|
|
1338
1129
|
|
|
1339
|
-
let defaultConfig = null;
|
|
1130
|
+
var template = "<div class=\"ff-skin-default\">\n <!-- Apple Pay Section -->\n <div class=\"ff-payment-method-card ff-payment-method-apple-pay\">\n <label class=\"ff-payment-method-label\">\n <input type=\"radio\" name=\"payment-method\" value=\"apple-pay\" class=\"ff-payment-method-radio\">\n <div class=\"ff-payment-method-header\">\n <div class=\"ff-payment-logo ff-apple-pay-logo\">\n <svg class=\"payment-method-icon\" height=\"26\" viewBox=\"0 0 63 26\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M8.41022 4.82398C9.5916 4.92293 10.773 4.23026 11.5113 3.35205C12.2374 2.4491 12.7173 1.23692 12.5943 0C11.5483 0.0494767 10.2561 0.692674 9.51777 1.59562C8.84093 2.37488 8.26255 3.63654 8.41022 4.82398ZM22.4638 20.7555V1.47193H29.6628C33.3793 1.47193 35.9758 4.04471 35.9758 7.80494C35.9758 11.5652 33.33 14.1627 29.5644 14.1627H25.4418V20.7555H22.4638ZM12.5819 5.05898C11.5411 4.99877 10.5914 5.37358 9.82438 5.67633C9.33075 5.87116 8.91274 6.03614 8.59472 6.03614C8.23784 6.03614 7.80257 5.86234 7.31387 5.66719C6.6735 5.4115 5.94138 5.11916 5.17364 5.13319C3.41387 5.15793 1.77716 6.15983 0.878819 7.75545C-0.967091 10.9467 0.398882 15.6717 2.18326 18.2693C3.05699 19.5556 4.10301 20.9657 5.48129 20.9163C6.08765 20.8933 6.52383 20.7072 6.97524 20.5147C7.49492 20.293 8.0348 20.0628 8.87776 20.0628C9.69151 20.0628 10.2078 20.287 10.7033 20.5023C11.1746 20.707 11.6271 20.9036 12.2989 20.8915C13.7264 20.8668 14.6247 19.6051 15.4984 18.3187C16.4413 16.9381 16.8557 15.5906 16.9186 15.3861C16.9222 15.3745 16.9246 15.3665 16.9259 15.3625C16.9244 15.361 16.9128 15.3556 16.8922 15.3462C16.577 15.2011 14.1679 14.0926 14.1448 11.1199C14.1216 8.62473 16.0556 7.36054 16.3601 7.16153C16.3786 7.14944 16.3911 7.14125 16.3968 7.137C15.1662 5.30636 13.2464 5.10845 12.5819 5.05898ZM41.4153 20.9039C43.2858 20.9039 45.0209 19.9515 45.8085 18.4424H45.8701V20.7555H48.6266V11.157C48.6266 8.37393 46.4115 6.5804 43.0027 6.5804C39.8401 6.5804 37.5019 8.39866 37.4158 10.8972H40.0985C40.32 9.70979 41.4153 8.93054 42.9166 8.93054C44.7379 8.93054 45.7593 9.78401 45.7593 11.3549V12.4186L42.0429 12.6413C38.5849 12.8516 36.7143 14.274 36.7143 16.7479C36.7143 19.2464 38.6464 20.9039 41.4153 20.9039ZM42.215 18.6156C40.6275 18.6156 39.6184 17.8487 39.6184 16.6736C39.6184 15.4615 40.5906 14.7564 42.4488 14.6451L45.7591 14.4348V15.5233C45.7591 17.3292 44.2332 18.6156 42.215 18.6156ZM57.7699 21.51C56.5762 24.8868 55.2103 26 52.306 26C52.0845 26 51.3461 25.9753 51.1739 25.9258V23.6127C51.3585 23.6375 51.8138 23.6622 52.0476 23.6622C53.3643 23.6622 54.1027 23.1056 54.558 21.6584L54.8288 20.8049L49.7833 6.76594H52.8967L56.4039 18.1579H56.4655L59.9727 6.76594H63L57.7699 21.51ZM25.4416 3.99524H28.875C31.4592 3.99524 32.936 5.38059 32.936 7.81731C32.936 10.254 31.4592 11.6518 28.8627 11.6518H25.4416V3.99524Z\" fill=\"currentColor\"/>\n </svg>\n </div>\n </div>\n </label>\n <div class=\"ff-payment-method-content\">\n <div class=\"ff-apple-pay-button-container ff-payment-container\" id=\"applePayButton\"></div>\n <div class=\"loader-container payment-button-loader\">\n <div class=\"loader\"></div>\n </div>\n <p class=\"ff-security-message\">\n Your payment information is secure with Apple Pay encryption\n </p>\n </div>\n </div>\n\n <!-- Google Pay Section -->\n <div class=\"ff-payment-method-card ff-payment-method-google-pay\">\n <label class=\"ff-payment-method-label\">\n <input type=\"radio\" name=\"payment-method\" value=\"google-pay\" class=\"ff-payment-method-radio\" checked=\"checked\">\n <div class=\"ff-payment-method-header\">\n <div class=\"ff-payment-logo ff-google-pay-logo\">\n <svg class=\"payment-method-icon\" height=\"26\" viewBox=\"0 0 59 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M27.3601 11.6862V18.4674H25.208V1.72177H30.9132C32.3591 1.72177 33.592 2.20374 34.6008 3.16768C35.632 4.13162 36.1476 5.30852 36.1476 6.69838C36.1476 8.12187 35.632 9.29877 34.6008 10.2515C33.6032 11.2042 32.3703 11.675 30.9132 11.675H27.3601V11.6862ZM27.3601 3.78415V9.62382H30.958C31.8099 9.62382 32.5272 9.3324 33.0876 8.76076C33.6593 8.18912 33.9507 7.49419 33.9507 6.70959C33.9507 5.9362 33.6593 5.25248 33.0876 4.68084C32.5272 4.08678 31.8211 3.79536 30.958 3.79536H27.3601V3.78415Z\" fill=\"currentColor\"/>\n <path d=\"M41.7742 6.63107C43.3658 6.63107 44.6212 7.057 45.5403 7.90885C46.4594 8.7607 46.9189 9.9264 46.9189 11.4059V18.4673H44.8677V16.8757H44.7781C43.8926 18.1871 42.7045 18.8372 41.225 18.8372C39.9584 18.8372 38.9048 18.4673 38.0529 17.7164C37.2011 16.9654 36.7751 16.0351 36.7751 14.9142C36.7751 13.7261 37.2235 12.7846 38.1202 12.0896C39.0169 11.3835 40.2162 11.036 41.7069 11.036C42.9847 11.036 44.0383 11.2714 44.8565 11.7422V11.249C44.8565 10.498 44.5651 9.87035 43.9711 9.34355C43.377 8.81674 42.6821 8.55895 41.8863 8.55895C40.6869 8.55895 39.7342 9.06333 39.0393 10.0833L37.145 8.8952C38.1874 7.38205 39.7342 6.63107 41.7742 6.63107ZM38.9944 14.9478C38.9944 15.5083 39.2298 15.979 39.7118 16.3489C40.1826 16.7188 40.743 16.9093 41.3819 16.9093C42.2898 16.9093 43.0968 16.5731 43.8029 15.9006C44.5091 15.228 44.8677 14.4435 44.8677 13.5356C44.1952 13.0088 43.2649 12.7397 42.0656 12.7397C41.1913 12.7397 40.4628 12.9527 39.8799 13.3674C39.2859 13.8046 38.9944 14.3314 38.9944 14.9478Z\" fill=\"currentColor\"/>\n <path d=\"M58.6207 7.00095L51.4472 23.5H49.2279L51.8955 17.7276L47.1655 7.00095H49.5081L52.9155 15.228H52.9604L56.2781 7.00095H58.6207Z\" fill=\"currentColor\"/>\n <path d=\"M18.8001 10.3187C18.8001 9.61709 18.7373 8.94569 18.6208 8.30008H9.6001V11.9989L14.7953 12C14.5846 13.2307 13.9064 14.2799 12.8674 14.9793V17.379H15.9598C17.7655 15.7078 18.8001 13.2375 18.8001 10.3187Z\" fill=\"#4285F4\"/>\n <path d=\"M12.8685 14.9793C12.0076 15.5599 10.8991 15.8995 9.60228 15.8995C7.09717 15.8995 4.97202 14.2115 4.21096 11.9361H1.021V14.411C2.60141 17.5472 5.84965 19.6992 9.60228 19.6992C12.1959 19.6992 14.3749 18.8462 15.9609 17.3779L12.8685 14.9793Z\" fill=\"#34A853\"/>\n <path d=\"M3.91043 10.1002C3.91043 9.46129 4.01691 8.8437 4.21082 8.26309V5.78824H1.02086C0.367396 7.08507 -0.000244141 8.54891 -0.000244141 10.1002C-0.000244141 11.6514 0.368516 13.1153 1.02086 14.4121L4.21082 11.9373C4.01691 11.3567 3.91043 10.7391 3.91043 10.1002Z\" fill=\"#FABB05\"/>\n <path d=\"M9.60228 4.29974C11.0179 4.29974 12.2856 4.78731 13.2865 5.74004L16.027 3.00179C14.3626 1.45164 12.1926 0.500031 9.60228 0.500031C5.85077 0.500031 2.60141 2.65208 1.021 5.78824L4.21096 8.26309C4.97202 5.98775 7.09717 4.29974 9.60228 4.29974Z\" fill=\"#E94235\"/>\n </svg>\n </div>\n </div>\n </label>\n <div class=\"ff-payment-method-content\">\n <ul class=\"ff-payment-features\">\n <li class=\"ff-payment-feature\">\n <svg class=\"ff-checkmark-icon\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n <span>Easy and private payments with Face/Touch ID</span>\n </li>\n <li class=\"ff-payment-feature\">\n <svg class=\"ff-checkmark-icon\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n <span>Keeps your financial info safe with end-to-end encryption</span>\n </li>\n <li class=\"ff-payment-feature\">\n <svg class=\"ff-checkmark-icon\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n <span>Protected by Google Pay's unique Device Account Number</span>\n </li>\n </ul>\n <div class=\"ff-google-pay-button-container ff-payment-container\" id=\"googlePayButton\"></div>\n <p class=\"ff-security-message\">\n Your payment information is secure with SSL/TLS encryption\n </p>\n <div class=\"loader-container payment-button-loader\">\n <div class=\"loader\"></div>\n </div>\n </div>\n </div>\n <!-- PayPal Section -->\n <div class=\"ff-payment-method-card ff-payment-method-paypal\">\n <label class=\"ff-payment-method-label\">\n <input type=\"radio\" name=\"payment-method\" value=\"paypal\" class=\"ff-payment-method-radio\">\n <div class=\"ff-payment-method-header\">\n <div class=\"ff-payment-logo ff-paypal-logo\">\n <img class=\"payment-method-icon\" style=\"max-height: 22px\" src=\"https://assets.fnlfx.com/common/checkout/paypal.webp\" alt=\"PayPal logo\">\n </div>\n </div>\n </label>\n <div class=\"ff-payment-method-content\">\n <ul class=\"ff-payment-features\">\n <li class=\"ff-payment-feature\">\n <svg class=\"ff-checkmark-icon\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n <span> Fast, convenient payment option </span>\n </li>\n <li class=\"ff-payment-feature\">\n <svg class=\"ff-checkmark-icon\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n <span>\n Keeps your financial info safe with end-to-end encryption\n </span>\n </li>\n <li class=\"ff-payment-feature\">\n <svg class=\"ff-checkmark-icon\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M20 6L9 17L4 12\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>\n <span> Backed by PayPal’s industry-leading fraud protection </span>\n </li>\n </ul>\n <div class=\"ff-paypal-button-container ff-payment-container\" id=\"paypalButton\"></div>\n <div class=\"loader-container payment-button-loader\">\n <div class=\"loader\"></div>\n </div>\n </div>\n </div>\n\n <!-- Card Payments Section -->\n <div class=\"ff-payment-method-card ff-payment-method-payment-card\">\n <label class=\"ff-payment-method-label\">\n <input type=\"radio\" name=\"payment-method\" value=\"card\" class=\"ff-payment-method-radio\">\n <div class=\"ff-payment-method-header\">\n <div class=\"ff-card-logos\">\n <img class=\"payment-method-icon\" style=\"max-height: 30px\" src=\"https://assets.fnlfx.com/common/checkout/cards.webp\" alt=\"visa, mastercard\">\n </div>\n </div>\n </label>\n <div class=\"ff-payment-method-content\">\n <div class=\"ff-card-form-container ff-payment-container\" id=\"cardForm\">\n <div class=\"loader-container\">\n <div class=\"loader\"></div>\n </div>\n <div>\n <label class=\"ff-card-form-label\" for=\"cardNumberInput\">Card number</label>\n <div id=\"cardNumberInput\"></div>\n <div class=\"errorContainer\"></div>\n </div>\n <div class=\"card-form-row\">\n <div>\n <label class=\"ff-card-form-label\" for=\"expiryInput\">Expiration date</label>\n <div id=\"expiryInput\"></div>\n <div class=\"errorContainer\"></div>\n </div>\n <div>\n <label class=\"ff-card-form-label\" for=\"cvvInput\">Security code</label>\n <div id=\"cvvInput\">\n <svg width=\"200\" height=\"200\" viewBox=\"0 0 200 200\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <rect width=\"200\" height=\"200\" fill=\"transparent\"/>\n <g clip-path=\"url(#clip0_0_1)\">\n <path d=\"M157.555 23C168.279 23.0002 177 31.7394 177 42.4854V80.5889C171.946 72.0151 164.749 64.8558 156.146 59.8457H166.394V42.4854C166.393 37.6004 162.43 33.6291 157.555 33.6289H27.4453C22.5704 33.6291 18.6066 37.6004 18.6064 42.4854V59.8457H97.8535C88.9153 65.0512 81.4954 72.5771 76.4189 81.5986H18.6064V127.515C18.6066 132.4 22.5704 136.371 27.4453 136.371H75.3281C77.2742 140.177 79.6285 143.739 82.333 147H27.4453C16.7215 147 8.00019 138.261 8 127.515V42.4854C8.0002 31.7394 16.7215 23.0002 27.4453 23H157.555Z\" fill=\"#93939A\"/>\n <mask id=\"path-2-outside-1_0_1\" maskUnits=\"userSpaceOnUse\" x=\"68.5012\" y=\"52.0311\" width=\"135\" height=\"135\" fill=\"black\">\n <rect fill=\"white\" x=\"68.5012\" y=\"52.0311\" width=\"135\" height=\"135\"/>\n <path d=\"M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z\"/>\n </mask>\n <path d=\"M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z\" fill=\"#93939A\"/>\n <path d=\"M190.242 160.457L170.136 140.351C166.533 145.552 162.023 150.063 156.821 153.666L176.927 173.772C178.693 175.538 181.088 176.53 183.585 176.53C186.082 176.53 188.477 175.538 190.242 173.772C192.008 172.007 193 169.612 193 167.115C193 164.618 192.008 162.223 190.242 160.457ZM126.436 157.901C116.955 157.901 107.688 155.089 99.8048 149.822C91.922 144.555 85.7781 137.069 82.15 128.31C78.5219 119.551 77.5727 109.913 79.4222 100.614C81.2718 91.3158 85.8371 82.7746 92.5409 76.0708C99.2447 69.367 107.786 64.8017 117.084 62.9521C126.383 61.1026 136.021 62.0518 144.78 65.6799C153.539 69.308 161.025 75.4519 166.292 83.3347C171.559 91.2175 174.371 100.485 174.371 109.966C174.371 122.679 169.32 134.871 160.331 143.861C151.341 152.85 139.149 157.901 126.436 157.901ZM163.719 109.966C163.719 102.592 161.532 95.3838 157.435 89.2527C153.339 83.1216 147.516 78.343 140.703 75.5212C133.891 72.6994 126.395 71.9611 119.162 73.3996C111.93 74.8382 105.287 78.389 100.073 83.6031C94.8591 88.8171 91.3083 95.4602 89.8697 102.692C88.4312 109.924 89.1695 117.421 91.9913 124.233C94.8131 131.046 99.5918 136.869 105.723 140.965C111.854 145.062 119.062 147.248 126.436 147.248C136.324 147.248 145.807 143.32 152.799 136.329C159.791 129.337 163.719 119.854 163.719 109.966ZM133.645 102.757C133.398 102.51 133.104 102.313 132.781 102.179C132.458 102.046 132.112 101.977 131.762 101.977C131.412 101.977 131.066 102.046 130.743 102.179C130.42 102.313 130.126 102.51 129.879 102.757L126.436 106.2L122.993 102.757C122.49 102.272 121.818 102.003 121.119 102.01C120.421 102.016 119.753 102.296 119.26 102.789C118.766 103.283 118.486 103.951 118.48 104.649C118.474 105.348 118.742 106.02 119.227 106.523L122.67 109.966L119.227 113.409C118.973 113.655 118.77 113.949 118.63 114.274C118.491 114.598 118.417 114.948 118.414 115.301C118.411 115.655 118.479 116.006 118.612 116.333C118.746 116.66 118.944 116.958 119.194 117.208C119.444 117.458 119.741 117.655 120.069 117.789C120.396 117.923 120.747 117.991 121.1 117.988C121.454 117.985 121.803 117.911 122.128 117.771C122.453 117.632 122.747 117.429 122.993 117.175L126.436 113.732L129.879 117.175C130.382 117.66 131.054 117.928 131.752 117.922C132.451 117.916 133.119 117.636 133.612 117.142C134.106 116.648 134.386 115.981 134.392 115.282C134.398 114.584 134.13 113.911 133.645 113.409L130.202 109.966L133.645 106.523C133.892 106.275 134.088 105.982 134.222 105.659C134.356 105.336 134.425 104.989 134.425 104.64C134.425 104.29 134.356 103.944 134.222 103.621C134.088 103.298 133.892 103.004 133.645 102.757ZM112.34 102.757C112.093 102.51 111.8 102.313 111.477 102.179C111.154 102.046 110.807 101.977 110.458 101.977C110.108 101.977 109.762 102.046 109.439 102.179C109.116 102.313 108.822 102.51 108.575 102.757L105.132 106.2L101.688 102.757C101.186 102.272 100.513 102.003 99.8151 102.01C99.1169 102.016 98.4489 102.296 97.9552 102.789C97.4614 103.283 97.1814 103.951 97.1753 104.649C97.1692 105.348 97.4377 106.02 97.9227 106.523L101.366 109.966L97.9227 113.409C97.6684 113.655 97.4655 113.949 97.326 114.274C97.1864 114.598 97.1129 114.948 97.1098 115.301C97.1068 115.655 97.1742 116.006 97.3081 116.333C97.442 116.66 97.6397 116.958 97.8897 117.208C98.1398 117.458 98.4371 117.655 98.7644 117.789C99.0917 117.923 99.4423 117.991 99.7959 117.988C100.15 117.985 100.499 117.911 100.824 117.771C101.149 117.632 101.443 117.429 101.688 117.175L105.132 113.732L108.575 117.175C109.077 117.66 109.75 117.928 110.448 117.922C111.146 117.916 111.814 117.636 112.308 117.142C112.802 116.648 113.082 115.981 113.088 115.282C113.094 114.584 112.826 113.911 112.34 113.409L108.897 109.966L112.34 106.523C112.588 106.275 112.784 105.982 112.918 105.659C113.052 105.336 113.121 104.989 113.121 104.64C113.121 104.29 113.052 103.944 112.918 103.621C112.784 103.298 112.588 103.004 112.34 102.757ZM151.506 109.966L154.949 106.523C155.434 106.02 155.703 105.348 155.697 104.649C155.691 103.951 155.41 103.283 154.917 102.789C154.423 102.296 153.755 102.016 153.057 102.01C152.359 102.003 151.686 102.272 151.184 102.757L147.74 106.2L144.297 102.757C143.795 102.272 143.122 102.003 142.424 102.01C141.726 102.016 141.058 102.296 140.564 102.789C140.07 103.283 139.79 103.951 139.784 104.649C139.778 105.348 140.046 106.02 140.531 106.523L143.974 109.966L140.531 113.409C140.277 113.655 140.074 113.949 139.935 114.274C139.795 114.598 139.722 114.948 139.719 115.301C139.715 115.655 139.783 116.006 139.917 116.333C140.051 116.66 140.248 116.958 140.498 117.208C140.748 117.458 141.046 117.655 141.373 117.789C141.7 117.923 142.051 117.991 142.405 117.988C142.758 117.985 143.108 117.911 143.433 117.771C143.757 117.632 144.051 117.429 144.297 117.175L147.74 113.732L151.184 117.175C151.686 117.66 152.359 117.928 153.057 117.922C153.755 117.916 154.423 117.636 154.917 117.142C155.41 116.648 155.691 115.981 155.697 115.282C155.703 114.584 155.434 113.911 154.949 113.409L151.506 109.966Z\" stroke=\"transparent\" stroke-width=\"20\" mask=\"url(#path-2-outside-1_0_1)\"/>\n </g>\n <defs>\n <clipPath id=\"clip0_0_1\">\n <rect width=\"200\" height=\"200\" fill=\"white\"/>\n </clipPath>\n </defs>\n </svg>\n </div>\n <div class=\"errorContainer\"></div>\n </div>\n </div>\n <div class=\"payment-errors-container\"></div>\n <button class=\"ff-card-form-submit-button\" id=\"submitButton\">\n Continue\n </button>\n </div>\n </div>\n </div>\n <div id=\"success-screen\" style=\"display: none\">\n <div class=\"success\">\n <img alt=\"Loading\" src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAiIGhlaWdodD0iNTAiIHZpZXdCb3g9IjAgMCA1MCA1MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTI1IDAuMTExMzI4QzIwLjA3NzQgMC4xMTEzMjggMTUuMjY1NCAxLjU3MTA0IDExLjE3MjUgNC4zMDU4NkM3LjA3OTUyIDcuMDQwNjkgMy44ODk0NSAxMC45Mjc4IDIuMDA1NjYgMTUuNDc1N0MwLjEyMTg4MyAyMC4wMjM1IC0wLjM3MSAyNS4wMjc4IDAuNTg5MzQzIDI5Ljg1NThDMS41NDk2OSAzNC42ODM4IDMuOTIwMTIgMzkuMTE4NSA3LjQwMDkgNDIuNTk5M0MxMC44ODE3IDQ2LjA4MDEgMTUuMzE2NCA0OC40NTA1IDIwLjE0NDQgNDkuNDEwOUMyNC45NzI0IDUwLjM3MTIgMjkuOTc2NyA0OS44NzgzIDM0LjUyNDYgNDcuOTk0NkMzOS4wNzI0IDQ2LjExMDggNDIuOTU5NSA0Mi45MjA3IDQ1LjY5NDQgMzguODI3N0M0OC40MjkyIDM0LjczNDggNDkuODg4OSAyOS45MjI4IDQ5Ljg4ODkgMjUuMDAwMkM0OS44ODg5IDE4LjM5OTMgNDcuMjY2NyAxMi4wNjg3IDQyLjU5OTEgNy40MDExMkMzNy45MzE1IDIuNzMzNTQgMzEuNjAwOSAwLjExMTMyOCAyNSAwLjExMTMyOFpNNDEuMjU1NiAxNi42NDY5TDIwLjgxNTYgMzcuMDcxM0w4Ljc0NDQ0IDI1LjAwMDJDOC4zMzE4OCAyNC41ODc3IDguMTAwMTEgMjQuMDI4MSA4LjEwMDExIDIzLjQ0NDdDOC4xMDAxMSAyMi44NjEyIDguMzMxODggMjIuMzAxNyA4Ljc0NDQ0IDIxLjg4OTFDOS4xNTcgMjEuNDc2NSA5LjcxNjU1IDIxLjI0NDggMTAuMyAyMS4yNDQ4QzEwLjg4MzQgMjEuMjQ0OCAxMS40NDMgMjEuNDc2NSAxMS44NTU2IDIxLjg4OTFMMjAuODQ2NyAzMC44ODAyTDM4LjE3NTYgMTMuNTY2OUMzOC4zNzk4IDEzLjM2MjYgMzguNjIyMyAxMy4yMDA2IDM4Ljg4OTIgMTMuMDlDMzkuMTU2MiAxMi45Nzk1IDM5LjQ0MjIgMTIuOTIyNiAzOS43MzExIDEyLjkyMjZDNDAuMDIgMTIuOTIyNiA0MC4zMDYxIDEyLjk3OTUgNDAuNTczIDEzLjA5QzQwLjgzOTkgMTMuMjAwNiA0MS4wODI0IDEzLjM2MjYgNDEuMjg2NyAxMy41NjY5QzQxLjQ5MDkgMTMuNzcxMiA0MS42NTMgMTQuMDEzNyA0MS43NjM1IDE0LjI4MDZDNDEuODc0MSAxNC41NDc1IDQxLjkzMSAxNC44MzM1IDQxLjkzMSAxNS4xMjI0QzQxLjkzMSAxNS40MTEzIDQxLjg3NDEgMTUuNjk3NCA0MS43NjM1IDE1Ljk2NDNDNDEuNjUzIDE2LjIzMTIgNDEuNDkwOSAxNi40NzM3IDQxLjI4NjcgMTYuNjc4TDQxLjI1NTYgMTYuNjQ2OVoiIGZpbGw9IiM4RURGQzIiLz4KPC9zdmc+Cg==\">\n <div>Payment completed successfully</div>\n </div>\n </div>\n</div>\n";
|
|
1340
1131
|
|
|
1341
|
-
|
|
1342
|
-
* Configure global SDK settings
|
|
1343
|
-
* @param {import('./types').SDKConfig} config - SDK configuration
|
|
1344
|
-
*/
|
|
1345
|
-
function configure(config) {
|
|
1346
|
-
defaultConfig = config;
|
|
1347
|
-
}
|
|
1132
|
+
if(typeof document!=="undefined")document.head.appendChild(document.createElement("style")).textContent="/* Main container */\n.ff-skin-default {\n display: flex;\n flex-direction: column;\n gap: 16px;\n width: 100%;\n max-width: 400px;\n margin: 0 auto;\n}\n\n/* Payment method cards */\n.ff-payment-method-card {\n display: none;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n background-color: #ffffff;\n padding: 20px;\n transition: border-color 0.2s ease;\n height: auto;\n}\n\n.ff-payment-method-card.visible {\n display: block;\n}\n\n.ff-payment-method-card:hover {\n border-color: #b0b0b0;\n}\n\n.payment-errors-container {\n background-color: #d1000033;\n color: #d10000;\n font-size: 14px;\n padding: 16px 12px;\n border-radius: 8px;\n}\n.payment-errors-container:empty {\n display: none;\n}\n\n/* Label wrapper */\n.ff-payment-method-label {\n display: flex;\n align-items: flex-start;\n gap: 16px;\n cursor: pointer;\n width: 100%;\n}\n\n/* Custom radio button styling */\n.ff-payment-method-radio {\n appearance: none;\n -webkit-appearance: none;\n -moz-appearance: none;\n width: 24px;\n height: 24px;\n min-width: 24px;\n min-height: 24px;\n border: 1px solid #9e9e9e;\n border-radius: 50%;\n background-color: #ffffff;\n cursor: pointer;\n position: relative;\n margin: 0;\n flex-shrink: 0;\n transition: border-color 0.2s ease;\n}\n\n.ff-card-form-submit-button {\n display: block;\n cursor: pointer;\n width: 100%;\n padding: 16px 0;\n border-radius: 16px;\n background-color: #000000;\n color: #ffffff;\n border: none;\n font-size: 16px;\n margin-top: 16px;\n}\n\n.ff-payment-method-radio:checked {\n border-color: #e32f41;\n background-color: #ffffff;\n}\n\n.ff-payment-method-radio:checked::after {\n content: '';\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 16px;\n height: 16px;\n border-radius: 50%;\n background-color: #e32f41;\n}\n\n/* Payment method content */\n.ff-payment-method-content {\n flex: 1;\n display: flex;\n flex-direction: column;\n gap: 16px;\n max-height: 0;\n height: 0;\n overflow: hidden;\n opacity: 0;\n transition:\n opacity 0.3s ease,\n margin-top 0.3s ease;\n margin-top: 0;\n}\n\n.ff-payment-method-card.expanded .ff-payment-method-content {\n max-height: 2000px;\n height: auto;\n opacity: 1;\n margin-top: 16px;\n}\n.ff-payment-method-card.expanded .ff-payment-method-label {\n margin-bottom: 16px;\n}\n\n/* Payment method header */\n.ff-payment-method-header {\n display: flex;\n align-items: center;\n}\n\n/* Google Pay Logo */\n.ff-google-pay-logo {\n display: flex;\n align-items: center;\n gap: 4px;\n font-weight: 500;\n font-size: 18px;\n}\n\n/* Payment features list */\n.ff-payment-features {\n list-style: none;\n padding: 0;\n margin: 0;\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.ff-payment-feature {\n display: flex;\n align-items: flex-start;\n gap: 8px;\n}\n\n.ff-checkmark-icon {\n width: 20px;\n height: 20px;\n min-width: 20px;\n color: #e32f41;\n flex-shrink: 0;\n margin-top: 2px;\n}\n\n.ff-payment-feature span {\n color: #333333;\n font-size: 14px;\n line-height: 1.5;\n}\n\n/* Google Pay button container */\n.ff-google-pay-button-container {\n display: flex;\n justify-content: center;\n margin: 8px 0;\n}\n\n/* Security message */\n.ff-security-message {\n text-align: center;\n color: #757575;\n font-size: 12px;\n margin: 8px 0 0 0;\n padding: 0;\n}\n\n/* Card logos container */\n.ff-card-logos {\n display: flex;\n align-items: center;\n gap: 12px;\n flex-wrap: wrap;\n}\n\n/* Card form container */\n.ff-card-form-container {\n position: relative;\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.ff-card-form-label {\n display: block;\n font-size: 16px;\n margin-bottom: 5px;\n}\n\n.card-form-row {\n display: flex;\n flex-direction: row;\n gap: 10px;\n}\n\n.ff-card-form-cardholder-input {\n padding-left: 10px;\n padding-right: 10px;\n box-sizing: border-box;\n height: 36px;\n width: 100%;\n font-size: 1rem;\n background-color: transparent;\n border: 1px solid rgb(0 0 0 / 10%);\n border-radius: 6px;\n transition: all 0.3s ease;\n box-shadow: none;\n}\n.ff-card-form-cardholder-input.error {\n border-color: #e32f41;\n}\n\n.errorContainer {\n color: #d10000;\n font-size: 16px;\n}\n\n.loader-container {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n background-color: rgba(255, 255, 255);\n z-index: 2;\n}\n\n.payment-button-loader {\n position: relative;\n height: 50px;\n}\n\n.loader {\n width: 24px;\n height: 24px;\n border: 4px solid #e32f41;\n border-top: 4px solid transparent;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n}\n\n@keyframes spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n/* Responsive adjustments */\n@media (max-width: 768px) {\n .ff-payment-method-card {\n padding: 16px;\n }\n\n .ff-payment-method-label {\n gap: 12px;\n }\n\n .ff-card-logos {\n gap: 8px;\n }\n}\n\n.ff-payment-container {\n position: relative;\n}\n\n.success {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 16px;\n}\n\n#cvvInput {\n position: relative;\n}\n\n#cvvInput > svg {\n z-index: 1;\n position: absolute;\n top: 5px;\n right: 5px;\n width: 26px;\n height: 26px;\n}\n";
|
|
1348
1133
|
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1134
|
+
class DefaultSkin {
|
|
1135
|
+
constructor(primerWrapper, containerSelector) {
|
|
1136
|
+
this.onLoaderChange = (isLoading) => {
|
|
1137
|
+
this.primerWrapper.disableButtons(isLoading);
|
|
1138
|
+
document
|
|
1139
|
+
.querySelectorAll(`${this.containerSelector} .loader-container`)
|
|
1140
|
+
?.forEach(loaderEl => {
|
|
1141
|
+
loaderEl.style.display = isLoading ? 'flex' : 'none';
|
|
1142
|
+
});
|
|
1143
|
+
};
|
|
1144
|
+
this.onError = (error, paymentMethod) => {
|
|
1145
|
+
let errorContainer = this.containerEl.querySelector('.payment-errors-container');
|
|
1146
|
+
if (paymentMethod) {
|
|
1147
|
+
const methodKey = paymentMethod.replace('_', '-').toLowerCase();
|
|
1148
|
+
errorContainer = this.containerEl.querySelector(`.ff-payment-method-${methodKey} .payment-errors-container`);
|
|
1149
|
+
}
|
|
1150
|
+
if (errorContainer) {
|
|
1151
|
+
errorContainer.textContent = error?.message || '';
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
this.onStatusChange = (state, oldState) => {
|
|
1155
|
+
const isLoading = ['initializing'].includes(state);
|
|
1156
|
+
if (!isLoading && oldState === 'initializing') {
|
|
1157
|
+
this.onLoaderChange(false);
|
|
1158
|
+
}
|
|
1159
|
+
if (state === 'updating') {
|
|
1160
|
+
this.onLoaderChange(true);
|
|
1161
|
+
}
|
|
1162
|
+
if (state === 'ready' && oldState === 'updating') {
|
|
1163
|
+
this.onLoaderChange(false);
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
this.onSuccess = () => {
|
|
1167
|
+
const successScreenString = document.querySelector('#success-screen')?.innerHTML;
|
|
1168
|
+
const containers = document.querySelectorAll('.ff-payment-container');
|
|
1169
|
+
containers.forEach(container => {
|
|
1170
|
+
container.innerHTML = successScreenString;
|
|
1171
|
+
});
|
|
1172
|
+
this.onLoaderChange(false);
|
|
1173
|
+
};
|
|
1174
|
+
this.onDestroy = () => {
|
|
1175
|
+
this.containerEl.remove();
|
|
1176
|
+
};
|
|
1177
|
+
this.onInputError = (event) => {
|
|
1178
|
+
const { name, error } = event;
|
|
1179
|
+
const cardInputElements = this.getCardInputElements();
|
|
1180
|
+
const elementsMap = {
|
|
1181
|
+
cardNumber: cardInputElements.cardNumber.parentElement,
|
|
1182
|
+
expiryDate: cardInputElements.expiryDate.parentElement,
|
|
1183
|
+
cvv: cardInputElements.cvv.parentElement,
|
|
1184
|
+
};
|
|
1185
|
+
const errorContainer = elementsMap[name]?.querySelector('.errorContainer');
|
|
1186
|
+
if (errorContainer) {
|
|
1187
|
+
errorContainer.textContent = error || '';
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
this.onMethodRender = (paymentMethod) => {
|
|
1191
|
+
const methodKey = paymentMethod.replace('_', '-').toLowerCase();
|
|
1192
|
+
const methodContainer = this.containerEl.querySelector(`.ff-payment-method-${methodKey}`);
|
|
1193
|
+
if (methodContainer) {
|
|
1194
|
+
methodContainer.classList.add('visible');
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
this.onStartPurchase = (paymentMethod) => {
|
|
1198
|
+
this.currentPurchaseMethod = paymentMethod;
|
|
1199
|
+
};
|
|
1200
|
+
this.onPurchaseFailure = (error) => {
|
|
1201
|
+
this.onError(error, this.currentPurchaseMethod);
|
|
1202
|
+
this.currentPurchaseMethod = null;
|
|
1203
|
+
};
|
|
1204
|
+
this.onPurchaseCompleted = () => {
|
|
1205
|
+
this.currentPurchaseMethod = null;
|
|
1206
|
+
};
|
|
1207
|
+
this.containerSelector = containerSelector;
|
|
1208
|
+
const containerEl = document.querySelector(containerSelector);
|
|
1209
|
+
if (!containerEl) {
|
|
1210
|
+
throw new Error(`Container element not found for selector: ${containerSelector}`);
|
|
1211
|
+
}
|
|
1212
|
+
this.containerEl = containerEl;
|
|
1213
|
+
// Initialize with placeholders; real nodes will be wired in `init`.
|
|
1214
|
+
this.cardInputElements = {
|
|
1215
|
+
cardNumber: document.createElement('div'),
|
|
1216
|
+
expiryDate: document.createElement('div'),
|
|
1217
|
+
cvv: document.createElement('div'),
|
|
1218
|
+
button: document.createElement('button'),
|
|
1219
|
+
};
|
|
1220
|
+
this.primerWrapper = primerWrapper;
|
|
1221
|
+
}
|
|
1222
|
+
initAccordion() {
|
|
1223
|
+
const paymentMethodCards = this.containerEl.querySelectorAll('.ff-payment-method-card');
|
|
1224
|
+
const radioButtons = this.containerEl.querySelectorAll('.ff-payment-method-radio');
|
|
1225
|
+
const handleAccordion = (checkedRadio) => {
|
|
1226
|
+
paymentMethodCards.forEach(card => {
|
|
1227
|
+
const radio = card.querySelector('.ff-payment-method-radio');
|
|
1228
|
+
if (radio === checkedRadio && radio?.checked) {
|
|
1229
|
+
card.classList.add('expanded');
|
|
1230
|
+
}
|
|
1231
|
+
else {
|
|
1232
|
+
card.classList.remove('expanded');
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
};
|
|
1236
|
+
const checkedRadio = Array.from(radioButtons).find(radio => radio.checked);
|
|
1237
|
+
setTimeout(() => {
|
|
1238
|
+
handleAccordion(checkedRadio || null);
|
|
1239
|
+
}, 0);
|
|
1240
|
+
radioButtons.forEach(radio => {
|
|
1241
|
+
radio.addEventListener('change', () => {
|
|
1242
|
+
if (radio.checked) {
|
|
1243
|
+
handleAccordion(radio);
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
wireCardInputs() {
|
|
1249
|
+
const cardNumber = this.containerEl.querySelector('#cardNumberInput');
|
|
1250
|
+
const expiryDate = this.containerEl.querySelector('#expiryInput');
|
|
1251
|
+
const cvv = this.containerEl.querySelector('#cvvInput');
|
|
1252
|
+
const button = this.containerEl.querySelector('#submitButton');
|
|
1253
|
+
if (!cardNumber || !expiryDate || !cvv || !button) {
|
|
1254
|
+
throw new Error('One or more card input elements are missing in the default skin');
|
|
1255
|
+
}
|
|
1256
|
+
this.cardInputElements = {
|
|
1257
|
+
cardNumber,
|
|
1258
|
+
expiryDate,
|
|
1259
|
+
cvv,
|
|
1260
|
+
button,
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
async init() {
|
|
1264
|
+
this.containerEl.innerHTML = template;
|
|
1265
|
+
document.body.appendChild(this.containerEl);
|
|
1266
|
+
this.initAccordion();
|
|
1267
|
+
this.wireCardInputs();
|
|
1268
|
+
}
|
|
1269
|
+
renderCardForm() {
|
|
1270
|
+
// Card form is part of the base template; no-op for default skin.
|
|
1271
|
+
}
|
|
1272
|
+
renderButton(paymentMethod) {
|
|
1273
|
+
const methodKey = paymentMethod.replace('_', '-').toLowerCase();
|
|
1274
|
+
const methodContainer = this.containerEl.querySelector(`.ff-payment-method-${methodKey}`);
|
|
1275
|
+
if (methodContainer) {
|
|
1276
|
+
methodContainer.classList.add('visible');
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
getCardInputSelectors() {
|
|
1280
|
+
return {
|
|
1281
|
+
cardNumber: '#cardNumberInput',
|
|
1282
|
+
expiryDate: '#expiryInput',
|
|
1283
|
+
cvv: '#cvvInput',
|
|
1284
|
+
cardholderName: '#cardHolderInput',
|
|
1285
|
+
button: '#submitButton',
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
getCardInputElements() {
|
|
1289
|
+
return this.cardInputElements;
|
|
1290
|
+
}
|
|
1366
1291
|
}
|
|
1367
|
-
const
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
baseUrl: finalBaseUrl,
|
|
1372
|
-
region: finalRegion
|
|
1292
|
+
const createDefaultSkin = async (primerWrapper, containerSelector) => {
|
|
1293
|
+
const skin = new DefaultSkin(primerWrapper, containerSelector);
|
|
1294
|
+
await skin['init']();
|
|
1295
|
+
return skin;
|
|
1373
1296
|
};
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
/**
|
|
1377
|
-
* Create a checkout instance - supports both events and callbacks
|
|
1378
|
-
* @param {import('./types').CreateCheckoutOptions} options - Checkout options with optional SDK config
|
|
1379
|
-
* @returns {Promise<import('./types').CheckoutInstance>} Checkout instance
|
|
1380
|
-
*/
|
|
1381
|
-
async function createCheckout(options) {
|
|
1382
|
-
const {
|
|
1383
|
-
...checkoutConfig
|
|
1384
|
-
} = options;
|
|
1385
|
-
|
|
1386
|
-
// Verify Primer SDK is available
|
|
1387
|
-
const primerWrapper = new PrimerWrapper();
|
|
1388
|
-
primerWrapper.ensurePrimerAvailable();
|
|
1389
|
-
|
|
1390
|
-
// Resolve configuration with fallback chain
|
|
1391
|
-
const config = resolveConfig(options, 'createCheckout');
|
|
1392
|
-
const checkout = new CheckoutInstance({
|
|
1393
|
-
...config,
|
|
1394
|
-
checkoutConfig
|
|
1395
|
-
});
|
|
1396
|
-
await checkout.initialize();
|
|
1397
|
-
return checkout;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* Direct checkout creation with Primer (legacy compatible)
|
|
1402
|
-
* @param {string} clientToken - Pre-created client token
|
|
1403
|
-
* @param {Object} options - Primer options
|
|
1404
|
-
* @returns {Promise<Object>} Primer checkout instance
|
|
1405
|
-
*/
|
|
1406
|
-
async function showUniversalCheckout(clientToken, options) {
|
|
1407
|
-
// Import dynamically to avoid circular dependencies
|
|
1408
|
-
const {
|
|
1409
|
-
default: PrimerWrapper
|
|
1410
|
-
} = await Promise.resolve().then(function () { return primerWrapper; });
|
|
1411
|
-
const primerWrapper$1 = new PrimerWrapper();
|
|
1412
|
-
return await primerWrapper$1.showUniversalCheckout(clientToken, options);
|
|
1413
|
-
}
|
|
1414
1297
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
* @param {string} params.priceId - Price identifier
|
|
1419
|
-
* @param {string} params.externalId - Customer external ID
|
|
1420
|
-
* @param {string} params.email - Customer email
|
|
1421
|
-
* @param {string} [params.orgId] - Organization ID (optional if configured)
|
|
1422
|
-
* @param {import('./types').APIConfig} [params.apiConfig] - Optional API config override
|
|
1423
|
-
* @param {Object} [params.clientMetadata] - Optional client metadata
|
|
1424
|
-
* @param {string} [params.countryCode] - Optional country code
|
|
1425
|
-
* @returns {Promise<{clientToken: string, orderId: string, type: string}>} Session data
|
|
1426
|
-
*/
|
|
1427
|
-
async function createClientSession(params) {
|
|
1428
|
-
const {
|
|
1429
|
-
priceId,
|
|
1430
|
-
externalId,
|
|
1431
|
-
email,
|
|
1432
|
-
clientMetadata,
|
|
1433
|
-
countryCode
|
|
1434
|
-
} = params;
|
|
1435
|
-
|
|
1436
|
-
// Resolve configuration with fallback chain
|
|
1437
|
-
const config = resolveConfig(params, 'createClientSession');
|
|
1438
|
-
|
|
1439
|
-
// Create API client and session
|
|
1440
|
-
const apiClient = new APIClient({
|
|
1441
|
-
baseUrl: config.baseUrl,
|
|
1442
|
-
orgId: config.orgId,
|
|
1443
|
-
timeout: DEFAULTS.REQUEST_TIMEOUT,
|
|
1444
|
-
retryAttempts: DEFAULTS.RETRY_ATTEMPTS
|
|
1445
|
-
});
|
|
1446
|
-
const sessionResponse = await apiClient.createClientSession({
|
|
1447
|
-
priceId,
|
|
1448
|
-
externalId,
|
|
1449
|
-
email,
|
|
1450
|
-
region: config.region,
|
|
1451
|
-
clientMetadata,
|
|
1452
|
-
countryCode
|
|
1298
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
1299
|
+
__proto__: null,
|
|
1300
|
+
default: createDefaultSkin
|
|
1453
1301
|
});
|
|
1454
|
-
return apiClient.processSessionResponse(sessionResponse);
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
/**
|
|
1458
|
-
* @fileoverview Main entry point for @funnelfox/billing
|
|
1459
|
-
*
|
|
1460
|
-
* Modern functional SDK for subscription payments with Primer integration
|
|
1461
|
-
*
|
|
1462
|
-
* @example
|
|
1463
|
-
* // Functional style (simple)
|
|
1464
|
-
* import { configure, createCheckout } from '@funnelfox/billing';
|
|
1465
|
-
*
|
|
1466
|
-
* configure({
|
|
1467
|
-
* orgId: 'your-org-id'
|
|
1468
|
-
* });
|
|
1469
|
-
*
|
|
1470
|
-
* const checkout = await createCheckout({
|
|
1471
|
-
* priceId: 'price_123',
|
|
1472
|
-
* customer: {
|
|
1473
|
-
* externalId: 'user_456',
|
|
1474
|
-
* email: 'user@example.com'
|
|
1475
|
-
* },
|
|
1476
|
-
* container: '#checkout-container'
|
|
1477
|
-
* });
|
|
1478
|
-
*
|
|
1479
|
-
* @example
|
|
1480
|
-
* // Namespace style
|
|
1481
|
-
* import { Billing } from '@funnelfox/billing';
|
|
1482
|
-
*
|
|
1483
|
-
* Billing.configure({ orgId: 'your-org-id' });
|
|
1484
|
-
* const checkout = await Billing.createCheckout({ ... });
|
|
1485
|
-
*
|
|
1486
|
-
* // Handle events
|
|
1487
|
-
* checkout.on('success', (result) => {
|
|
1488
|
-
* console.log('Payment completed:', result.orderId);
|
|
1489
|
-
* });
|
|
1490
|
-
*/
|
|
1491
|
-
|
|
1492
|
-
const Billing = {
|
|
1493
|
-
configure: configure,
|
|
1494
|
-
createCheckout: createCheckout,
|
|
1495
|
-
showUniversalCheckout: showUniversalCheckout,
|
|
1496
|
-
createClientSession: createClientSession
|
|
1497
|
-
};
|
|
1498
|
-
if (typeof window !== 'undefined') {
|
|
1499
|
-
window.Billing = Billing;
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
exports.APIError = APIError;
|
|
1503
|
-
exports.Billing = Billing;
|
|
1504
|
-
exports.CHECKOUT_STATES = CHECKOUT_STATES;
|
|
1505
|
-
exports.CheckoutError = CheckoutError;
|
|
1506
|
-
exports.ConfigurationError = ConfigurationError;
|
|
1507
|
-
exports.DEFAULTS = DEFAULTS;
|
|
1508
|
-
exports.ERROR_CODES = ERROR_CODES;
|
|
1509
|
-
exports.EVENTS = EVENTS;
|
|
1510
|
-
exports.FunnefoxSDKError = FunnefoxSDKError;
|
|
1511
|
-
exports.NetworkError = NetworkError;
|
|
1512
|
-
exports.PrimerError = PrimerError;
|
|
1513
|
-
exports.SDK_VERSION = SDK_VERSION;
|
|
1514
|
-
exports.ValidationError = ValidationError;
|
|
1515
|
-
exports.configure = configure;
|
|
1516
|
-
exports.createCheckout = createCheckout;
|
|
1517
|
-
exports.createClientSession = createClientSession;
|
|
1518
|
-
exports.default = Billing;
|
|
1519
|
-
exports.showUniversalCheckout = showUniversalCheckout;
|
|
1520
1302
|
|
|
1521
|
-
|
|
1303
|
+
exports.APIError = APIError;
|
|
1304
|
+
exports.Billing = Billing;
|
|
1305
|
+
exports.CHECKOUT_STATES = CHECKOUT_STATES;
|
|
1306
|
+
exports.CheckoutError = CheckoutError;
|
|
1307
|
+
exports.ConfigurationError = ConfigurationError;
|
|
1308
|
+
exports.DEFAULTS = DEFAULTS;
|
|
1309
|
+
exports.ERROR_CODES = ERROR_CODES;
|
|
1310
|
+
exports.EVENTS = EVENTS;
|
|
1311
|
+
exports.FunnefoxSDKError = FunnefoxSDKError;
|
|
1312
|
+
exports.NetworkError = NetworkError;
|
|
1313
|
+
exports.PrimerError = PrimerError;
|
|
1314
|
+
exports.SDK_VERSION = SDK_VERSION;
|
|
1315
|
+
exports.ValidationError = ValidationError;
|
|
1316
|
+
exports.configure = configure;
|
|
1317
|
+
exports.createCheckout = createCheckout;
|
|
1318
|
+
exports.createClientSession = createClientSession;
|
|
1319
|
+
exports.default = Billing;
|
|
1320
|
+
|
|
1321
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1522
1322
|
|
|
1523
1323
|
}));
|