@lightspeed/online-payments-sdk 0.2.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/v1/EventBroadcaster.js +61 -0
- package/dist/cjs/v1/adyen/ResultBuilder.js +47 -0
- package/dist/cjs/v1/adyen/widget.js +14 -30
- package/dist/cjs/v1/common.js +0 -36
- package/dist/cjs/v1/error.js +45 -1
- package/dist/cjs/v1/index.js +6 -7
- package/dist/cjs/v1/logging/common.js +36 -0
- package/dist/cjs/v1/logging/datadog/logger.js +6 -3
- package/dist/cjs/v1/logging/noop-logger.js +1 -1
- package/dist/cjs/v1/session.js +3 -3
- package/dist/cjs/v1/stripe/ResultBuilder.js +59 -0
- package/dist/cjs/v1/stripe/widget.js +68 -43
- package/dist/cjs/v1/widget.js +44 -32
- package/dist/v1/EventBroadcaster.d.ts +39 -0
- package/dist/v1/EventBroadcaster.js +58 -0
- package/dist/v1/adyen/ResultBuilder.d.ts +7 -0
- package/dist/v1/adyen/ResultBuilder.js +44 -0
- package/dist/v1/adyen/widget.d.ts +1 -3
- package/dist/v1/adyen/widget.js +14 -29
- package/dist/v1/common.d.ts +5 -17
- package/dist/v1/common.js +1 -35
- package/dist/v1/error.d.ts +18 -2
- package/dist/v1/error.js +44 -0
- package/dist/v1/index.d.ts +4 -4
- package/dist/v1/index.js +1 -2
- package/dist/v1/logging/common.d.ts +2 -1
- package/dist/v1/logging/common.js +35 -0
- package/dist/v1/logging/datadog/logger.d.ts +1 -1
- package/dist/v1/logging/datadog/logger.js +6 -3
- package/dist/v1/logging/noop-logger.d.ts +1 -1
- package/dist/v1/logging/noop-logger.js +1 -1
- package/dist/v1/session.js +2 -2
- package/dist/v1/stripe/ResultBuilder.d.ts +7 -0
- package/dist/v1/stripe/ResultBuilder.js +56 -0
- package/dist/v1/stripe/widget.d.ts +3 -4
- package/dist/v1/stripe/widget.js +68 -42
- package/dist/v1/widget.d.ts +5 -3
- package/dist/v1/widget.js +44 -32
- package/package.json +1 -1
- package/dist/cjs/v1/session.error.js +0 -43
- package/dist/cjs/v1/widget.error.js +0 -43
- package/dist/v1/session.error.d.ts +0 -15
- package/dist/v1/session.error.js +0 -40
- package/dist/v1/widget.error.d.ts +0 -15
- package/dist/v1/widget.error.js +0 -40
package/dist/cjs/v1/widget.js
CHANGED
|
@@ -38,46 +38,58 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.mountPaymentWidget = mountPaymentWidget;
|
|
40
40
|
var widget_1 = require("./adyen/widget");
|
|
41
|
-
var common_1 = require("./common");
|
|
42
41
|
var widget_2 = require("./stripe/widget");
|
|
43
42
|
var session_1 = require("./session");
|
|
44
|
-
var
|
|
43
|
+
var error_1 = require("./error");
|
|
45
44
|
var logger_1 = require("./logging/logger");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
var common_1 = require("./logging/common");
|
|
46
|
+
var EventBroadcaster_1 = require("./EventBroadcaster");
|
|
47
|
+
function mountPaymentWidget(session, config) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var eventBroadcaster, decodedSession, logger_2, widgetController, _a, error_2;
|
|
50
|
+
return __generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
52
52
|
case 0:
|
|
53
|
+
eventBroadcaster = new EventBroadcaster_1.EventBroadcaster(config.listeners);
|
|
54
|
+
_b.label = 1;
|
|
55
|
+
case 1:
|
|
56
|
+
_b.trys.push([1, 8, , 9]);
|
|
53
57
|
decodedSession = (0, session_1.decodePaymentSessionToContext)(session);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
switch (
|
|
64
|
-
case 'ADYEN': return [3 /*break*/,
|
|
65
|
-
case 'STRIPE': return [3 /*break*/,
|
|
58
|
+
logger_2 = (0, logger_1.getLogger)(decodedSession.logging);
|
|
59
|
+
logger_2.setSessionMetadata(decodedSession.metadata);
|
|
60
|
+
eventBroadcaster.registerMiddleware(function (event) {
|
|
61
|
+
logger_2.log('info', event.status, event);
|
|
62
|
+
return event;
|
|
63
|
+
});
|
|
64
|
+
logger_2.log('info', 'Mount');
|
|
65
|
+
widgetController = void 0;
|
|
66
|
+
_a = decodedSession.psp;
|
|
67
|
+
switch (_a) {
|
|
68
|
+
case 'ADYEN': return [3 /*break*/, 2];
|
|
69
|
+
case 'STRIPE': return [3 /*break*/, 4];
|
|
66
70
|
}
|
|
67
|
-
return [3 /*break*/, 5];
|
|
68
|
-
case 1: return [4 /*yield*/, widget_1.AdyenWidget.mount(mountPoint, decodedSession.context, handlers)];
|
|
69
|
-
case 2:
|
|
70
|
-
widgetController = _d.sent();
|
|
71
71
|
return [3 /*break*/, 6];
|
|
72
|
-
case
|
|
73
|
-
case
|
|
74
|
-
widgetController =
|
|
75
|
-
return [3 /*break*/,
|
|
76
|
-
case
|
|
77
|
-
case
|
|
78
|
-
widgetController
|
|
79
|
-
|
|
72
|
+
case 2: return [4 /*yield*/, widget_1.AdyenWidget.mount(config.mountPoint, decodedSession.context, eventBroadcaster)];
|
|
73
|
+
case 3:
|
|
74
|
+
widgetController = _b.sent();
|
|
75
|
+
return [3 /*break*/, 7];
|
|
76
|
+
case 4: return [4 /*yield*/, widget_2.StripeWidget.mount(config.mountPoint, decodedSession.context, eventBroadcaster, config.defaultValues)];
|
|
77
|
+
case 5:
|
|
78
|
+
widgetController = _b.sent();
|
|
79
|
+
return [3 /*break*/, 7];
|
|
80
|
+
case 6: throw new error_1.UnsupportedLocationError();
|
|
81
|
+
case 7:
|
|
82
|
+
widgetController.submit = (0, common_1.withLogging)(logger_2, 'Submit', widgetController.submit);
|
|
83
|
+
widgetController.unmount = (0, common_1.withLogging)(logger_2, 'Unmount', widgetController.unmount);
|
|
80
84
|
return [2 /*return*/, widgetController];
|
|
85
|
+
case 8:
|
|
86
|
+
error_2 = _b.sent();
|
|
87
|
+
eventBroadcaster.publish({
|
|
88
|
+
code: 'Unexpected',
|
|
89
|
+
status: 'Error',
|
|
90
|
+
});
|
|
91
|
+
throw error_2;
|
|
92
|
+
case 9: return [2 /*return*/];
|
|
81
93
|
}
|
|
82
94
|
});
|
|
83
95
|
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SupportedErrorCodes } from './error';
|
|
2
|
+
export type Status = 'Succeeded' | 'Refused' | 'Pending' | 'Error' | 'Ready';
|
|
3
|
+
export type BaseEvent = {
|
|
4
|
+
loggingEnrichment?: object;
|
|
5
|
+
};
|
|
6
|
+
export type SucceededResultEvent = BaseEvent & {
|
|
7
|
+
code: 'Authorized';
|
|
8
|
+
status: 'Succeeded';
|
|
9
|
+
};
|
|
10
|
+
export type PendingResultEvent = BaseEvent & {
|
|
11
|
+
code: 'Processing';
|
|
12
|
+
status: 'Pending';
|
|
13
|
+
};
|
|
14
|
+
export type RefusedResultEvent = BaseEvent & {
|
|
15
|
+
status: 'Refused';
|
|
16
|
+
code: 'CardValidation' | 'Generic';
|
|
17
|
+
};
|
|
18
|
+
export type ReadyEvent = BaseEvent & {
|
|
19
|
+
status: 'Ready';
|
|
20
|
+
code: 'Ready';
|
|
21
|
+
};
|
|
22
|
+
export type ErrorResultEvent = BaseEvent & {
|
|
23
|
+
code: SupportedErrorCodes;
|
|
24
|
+
status: 'Error';
|
|
25
|
+
};
|
|
26
|
+
export type InternalEvent = SucceededResultEvent | PendingResultEvent | RefusedResultEvent | ErrorResultEvent | ReadyEvent;
|
|
27
|
+
export type Event = Omit<InternalEvent, 'loggingEnrichment'>;
|
|
28
|
+
export type EventHandler = (result: Event) => void;
|
|
29
|
+
export type EventMiddleware = (event: InternalEvent) => InternalEvent | void;
|
|
30
|
+
export type EventListeners = Partial<Record<`on${Status}`, EventHandler>>;
|
|
31
|
+
export declare class EventBroadcaster {
|
|
32
|
+
private listenersRegistry;
|
|
33
|
+
private middleware;
|
|
34
|
+
constructor(listeners?: EventListeners);
|
|
35
|
+
private convertInternalEventToExternal;
|
|
36
|
+
registerMiddleware(middleware: EventMiddleware): void;
|
|
37
|
+
applyMiddlewares(event: InternalEvent): Event;
|
|
38
|
+
publish(event: InternalEvent): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
var noOpListener = function () { };
|
|
13
|
+
var EventBroadcaster = /** @class */ (function () {
|
|
14
|
+
function EventBroadcaster(listeners) {
|
|
15
|
+
this.middleware = [];
|
|
16
|
+
this.listenersRegistry = {
|
|
17
|
+
Succeeded: (listeners === null || listeners === void 0 ? void 0 : listeners.onSucceeded) || noOpListener,
|
|
18
|
+
Refused: (listeners === null || listeners === void 0 ? void 0 : listeners.onRefused) || noOpListener,
|
|
19
|
+
Pending: (listeners === null || listeners === void 0 ? void 0 : listeners.onPending) || noOpListener,
|
|
20
|
+
Error: (listeners === null || listeners === void 0 ? void 0 : listeners.onError) || noOpListener,
|
|
21
|
+
Ready: (listeners === null || listeners === void 0 ? void 0 : listeners.onReady) || noOpListener,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
EventBroadcaster.prototype.convertInternalEventToExternal = function (event) {
|
|
25
|
+
return { status: event.status, code: event.code };
|
|
26
|
+
};
|
|
27
|
+
EventBroadcaster.prototype.registerMiddleware = function (middleware) {
|
|
28
|
+
this.middleware.push(middleware);
|
|
29
|
+
};
|
|
30
|
+
EventBroadcaster.prototype.applyMiddlewares = function (event) {
|
|
31
|
+
var e_1, _a;
|
|
32
|
+
var processedEvent = event;
|
|
33
|
+
try {
|
|
34
|
+
for (var _b = __values(this.middleware), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
35
|
+
var mw = _c.value;
|
|
36
|
+
var result = mw(processedEvent);
|
|
37
|
+
if (result !== undefined) {
|
|
38
|
+
processedEvent = result;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
43
|
+
finally {
|
|
44
|
+
try {
|
|
45
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
46
|
+
}
|
|
47
|
+
finally { if (e_1) throw e_1.error; }
|
|
48
|
+
}
|
|
49
|
+
return this.convertInternalEventToExternal(processedEvent);
|
|
50
|
+
};
|
|
51
|
+
EventBroadcaster.prototype.publish = function (event) {
|
|
52
|
+
var processedEvent = this.applyMiddlewares(event);
|
|
53
|
+
var eventListener = this.listenersRegistry[event.status];
|
|
54
|
+
eventListener(processedEvent);
|
|
55
|
+
};
|
|
56
|
+
return EventBroadcaster;
|
|
57
|
+
}());
|
|
58
|
+
export { EventBroadcaster };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorResultEvent, SucceededResultEvent, PendingResultEvent, RefusedResultEvent } from '../EventBroadcaster';
|
|
2
|
+
import { PaymentCompletedData, PaymentFailedData } from '@adyen/adyen-web';
|
|
3
|
+
export declare class ResultBuilder {
|
|
4
|
+
static fromPaymentCompletedData(paymentCompleteData: PaymentCompletedData): SucceededResultEvent | PendingResultEvent;
|
|
5
|
+
static fromPaymentFailedData(paymentFailedData: PaymentFailedData): RefusedResultEvent | ErrorResultEvent;
|
|
6
|
+
static generatePendingEvent(): PendingResultEvent;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var ResultBuilder = /** @class */ (function () {
|
|
2
|
+
function ResultBuilder() {
|
|
3
|
+
}
|
|
4
|
+
ResultBuilder.fromPaymentCompletedData = function (paymentCompleteData) {
|
|
5
|
+
switch (paymentCompleteData.resultCode) {
|
|
6
|
+
case 'Authorised':
|
|
7
|
+
return {
|
|
8
|
+
status: 'Succeeded',
|
|
9
|
+
code: 'Authorized',
|
|
10
|
+
};
|
|
11
|
+
case 'PartiallyAuthorised':
|
|
12
|
+
case 'Received':
|
|
13
|
+
case 'Pending':
|
|
14
|
+
default:
|
|
15
|
+
return {
|
|
16
|
+
status: 'Pending',
|
|
17
|
+
code: 'Processing',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
ResultBuilder.fromPaymentFailedData = function (paymentFailedData) {
|
|
22
|
+
switch (paymentFailedData.resultCode) {
|
|
23
|
+
case 'Refused':
|
|
24
|
+
return {
|
|
25
|
+
status: 'Refused',
|
|
26
|
+
code: 'Generic',
|
|
27
|
+
};
|
|
28
|
+
case 'Error':
|
|
29
|
+
default:
|
|
30
|
+
return {
|
|
31
|
+
status: 'Error',
|
|
32
|
+
code: 'Unexpected',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
ResultBuilder.generatePendingEvent = function () {
|
|
37
|
+
return {
|
|
38
|
+
status: 'Pending',
|
|
39
|
+
code: 'Processing',
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
return ResultBuilder;
|
|
43
|
+
}());
|
|
44
|
+
export { ResultBuilder };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ResultCode as AdyenResultCode } from '@adyen/adyen-web';
|
|
2
1
|
import { AdyenContext } from './session';
|
|
3
|
-
import { WidgetInterface
|
|
4
|
-
export declare function mapAdyenResultCode(code: AdyenResultCode): ResultCode;
|
|
2
|
+
import { WidgetInterface } from '../common';
|
|
5
3
|
export declare const AdyenWidget: WidgetInterface<AdyenContext>;
|
package/dist/v1/adyen/widget.js
CHANGED
|
@@ -35,24 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import { AdyenCheckout, Dropin, Card, GooglePay, ApplePay, } from '@adyen/adyen-web';
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
switch (code) {
|
|
41
|
-
case 'Authorised':
|
|
42
|
-
return 'Authorized';
|
|
43
|
-
case 'Refused':
|
|
44
|
-
return 'Refused';
|
|
45
|
-
default:
|
|
46
|
-
return 'Unexpected';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function mount(mountElement, context, listeners) {
|
|
38
|
+
import { ResultBuilder } from './ResultBuilder';
|
|
39
|
+
function mount(mountElement, context, eventBroadcaster) {
|
|
50
40
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
41
|
var checkoutConfig, checkout, dropinConfiguration, dropIn;
|
|
52
42
|
return __generator(this, function (_a) {
|
|
53
43
|
switch (_a.label) {
|
|
54
44
|
case 0:
|
|
55
|
-
checkoutConfig = createAdyenConfiguration(context,
|
|
45
|
+
checkoutConfig = createAdyenConfiguration(context, eventBroadcaster);
|
|
56
46
|
return [4 /*yield*/, AdyenCheckout(checkoutConfig)];
|
|
57
47
|
case 1:
|
|
58
48
|
checkout = _a.sent();
|
|
@@ -63,10 +53,9 @@ function mount(mountElement, context, listeners) {
|
|
|
63
53
|
submit: function () {
|
|
64
54
|
return new Promise(function (resolve) {
|
|
65
55
|
dropIn.submit();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
56
|
+
var pendingEvent = ResultBuilder.generatePendingEvent();
|
|
57
|
+
eventBroadcaster.publish(pendingEvent);
|
|
58
|
+
resolve(pendingEvent);
|
|
70
59
|
});
|
|
71
60
|
},
|
|
72
61
|
}];
|
|
@@ -74,7 +63,7 @@ function mount(mountElement, context, listeners) {
|
|
|
74
63
|
});
|
|
75
64
|
});
|
|
76
65
|
}
|
|
77
|
-
function createAdyenConfiguration(context,
|
|
66
|
+
function createAdyenConfiguration(context, eventBroadcaster) {
|
|
78
67
|
return {
|
|
79
68
|
clientKey: context.clientKey,
|
|
80
69
|
session: {
|
|
@@ -92,21 +81,17 @@ function createAdyenConfiguration(context, listeners) {
|
|
|
92
81
|
enabled: false,
|
|
93
82
|
},
|
|
94
83
|
onPaymentCompleted: function (data) {
|
|
95
|
-
|
|
96
|
-
(_a = listeners === null || listeners === void 0 ? void 0 : listeners.onComplete) === null || _a === void 0 ? void 0 : _a.call(listeners, {
|
|
97
|
-
code: mapAdyenResultCode(data.resultCode),
|
|
98
|
-
status: 'Complete',
|
|
99
|
-
});
|
|
84
|
+
eventBroadcaster.publish(ResultBuilder.fromPaymentCompletedData(data));
|
|
100
85
|
},
|
|
101
86
|
onPaymentFailed: function (data) {
|
|
102
|
-
|
|
103
|
-
(_a = listeners === null || listeners === void 0 ? void 0 : listeners.onFail) === null || _a === void 0 ? void 0 : _a.call(listeners, {
|
|
104
|
-
status: 'Complete',
|
|
105
|
-
code: mapAdyenResultCode(data.resultCode),
|
|
106
|
-
});
|
|
87
|
+
eventBroadcaster.publish(ResultBuilder.fromPaymentFailedData(data));
|
|
107
88
|
},
|
|
108
89
|
onError: function (error) {
|
|
109
|
-
|
|
90
|
+
eventBroadcaster.publish({
|
|
91
|
+
status: 'Error',
|
|
92
|
+
code: 'Processing',
|
|
93
|
+
loggingEnrichment: error,
|
|
94
|
+
});
|
|
110
95
|
},
|
|
111
96
|
paymentMethodsResponse: context.paymentMethods,
|
|
112
97
|
};
|
package/dist/v1/common.d.ts
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type ResultCode = 'Authorized' | 'Success' | 'Failure' | 'Refused' | 'Unexpected';
|
|
3
|
-
export type Status = 'Pending' | 'Complete';
|
|
4
|
-
export type Result = {
|
|
5
|
-
status: Status;
|
|
6
|
-
code: ResultCode;
|
|
7
|
-
};
|
|
1
|
+
import { EventBroadcaster, Event } from './EventBroadcaster';
|
|
8
2
|
export type WidgetController = {
|
|
9
3
|
unmount: () => void;
|
|
10
|
-
submit: () => Promise<
|
|
11
|
-
};
|
|
12
|
-
export type Callbacks = {
|
|
13
|
-
onComplete?(result: Result): void;
|
|
14
|
-
onFail?(result: Result): void;
|
|
15
|
-
onReady?(): void;
|
|
4
|
+
submit: () => Promise<Event>;
|
|
16
5
|
};
|
|
17
6
|
export type DefaultValues = {
|
|
18
7
|
country?: string;
|
|
19
8
|
postalCode?: string;
|
|
20
9
|
};
|
|
21
|
-
export
|
|
22
|
-
mount: (mountElement: HTMLElement, context: T,
|
|
23
|
-
}
|
|
24
|
-
export declare function withLogging<T extends object, Args extends unknown[], R>(logger: Logger<T>, event: string, handler: (...args: Args) => R): (...args: Args) => R;
|
|
10
|
+
export interface WidgetInterface<T> {
|
|
11
|
+
mount: (mountElement: HTMLElement, context: T, eventBroadcaster: EventBroadcaster, defaultValues?: DefaultValues) => Promise<WidgetController>;
|
|
12
|
+
}
|
package/dist/v1/common.js
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
-
if (ar || !(i in from)) {
|
|
20
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
-
ar[i] = from[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
-
};
|
|
26
|
-
export function withLogging(logger, event, handler) {
|
|
27
|
-
return function () {
|
|
28
|
-
var args = [];
|
|
29
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
30
|
-
args[_i] = arguments[_i];
|
|
31
|
-
}
|
|
32
|
-
logger.log('info', event, { args: args });
|
|
33
|
-
return handler.apply(void 0, __spreadArray([], __read(args), false));
|
|
34
|
-
};
|
|
35
|
-
}
|
|
1
|
+
export {};
|
package/dist/v1/error.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
export type SupportedErrorCodes = 'Unexpected' | 'InvalidSession' | 'InvalidSessionPayload' | 'UnsupportedLocation' | 'Processing';
|
|
1
2
|
export declare class BaseError extends Error {
|
|
2
|
-
code:
|
|
3
|
-
constructor(code:
|
|
3
|
+
code: SupportedErrorCodes;
|
|
4
|
+
constructor(code: SupportedErrorCodes, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class UnexpectedError extends BaseError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class InvalidSessionError extends BaseError {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class InvalidSessionPayloadError extends BaseError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class UnsupportedLocationError extends BaseError {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
export declare class ProcessingError extends BaseError {
|
|
19
|
+
constructor(message?: string);
|
|
4
20
|
}
|
package/dist/v1/error.js
CHANGED
|
@@ -23,3 +23,47 @@ var BaseError = /** @class */ (function (_super) {
|
|
|
23
23
|
return BaseError;
|
|
24
24
|
}(Error));
|
|
25
25
|
export { BaseError };
|
|
26
|
+
var UnexpectedError = /** @class */ (function (_super) {
|
|
27
|
+
__extends(UnexpectedError, _super);
|
|
28
|
+
function UnexpectedError(message) {
|
|
29
|
+
if (message === void 0) { message = 'An unexpected error occurred'; }
|
|
30
|
+
return _super.call(this, 'Unexpected', message) || this;
|
|
31
|
+
}
|
|
32
|
+
return UnexpectedError;
|
|
33
|
+
}(BaseError));
|
|
34
|
+
export { UnexpectedError };
|
|
35
|
+
var InvalidSessionError = /** @class */ (function (_super) {
|
|
36
|
+
__extends(InvalidSessionError, _super);
|
|
37
|
+
function InvalidSessionError(message) {
|
|
38
|
+
if (message === void 0) { message = 'The session could not be decoded'; }
|
|
39
|
+
return _super.call(this, 'InvalidSession', message) || this;
|
|
40
|
+
}
|
|
41
|
+
return InvalidSessionError;
|
|
42
|
+
}(BaseError));
|
|
43
|
+
export { InvalidSessionError };
|
|
44
|
+
var InvalidSessionPayloadError = /** @class */ (function (_super) {
|
|
45
|
+
__extends(InvalidSessionPayloadError, _super);
|
|
46
|
+
function InvalidSessionPayloadError(message) {
|
|
47
|
+
if (message === void 0) { message = 'The session was decoded but the payload is invalid'; }
|
|
48
|
+
return _super.call(this, 'InvalidSessionPayload', message) || this;
|
|
49
|
+
}
|
|
50
|
+
return InvalidSessionPayloadError;
|
|
51
|
+
}(BaseError));
|
|
52
|
+
export { InvalidSessionPayloadError };
|
|
53
|
+
var UnsupportedLocationError = /** @class */ (function (_super) {
|
|
54
|
+
__extends(UnsupportedLocationError, _super);
|
|
55
|
+
function UnsupportedLocationError() {
|
|
56
|
+
return _super.call(this, 'UnsupportedLocation', 'The location you are attempting to process with is not supported') || this;
|
|
57
|
+
}
|
|
58
|
+
return UnsupportedLocationError;
|
|
59
|
+
}(BaseError));
|
|
60
|
+
export { UnsupportedLocationError };
|
|
61
|
+
var ProcessingError = /** @class */ (function (_super) {
|
|
62
|
+
__extends(ProcessingError, _super);
|
|
63
|
+
function ProcessingError(message) {
|
|
64
|
+
if (message === void 0) { message = 'The PSP experienced an error while processing the payment'; }
|
|
65
|
+
return _super.call(this, 'Processing', message) || this;
|
|
66
|
+
}
|
|
67
|
+
return ProcessingError;
|
|
68
|
+
}(BaseError));
|
|
69
|
+
export { ProcessingError };
|
package/dist/v1/index.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { WidgetController } from './common';
|
|
8
8
|
import { PaymentWidgetConfiguration } from './widget';
|
|
9
|
-
export type {
|
|
10
|
-
export {
|
|
11
|
-
export { UnsupportedLocationError,
|
|
9
|
+
export type { WidgetController } from './common';
|
|
10
|
+
export type { Event } from './EventBroadcaster';
|
|
11
|
+
export { UnsupportedLocationError, InvalidSessionPayloadError, InvalidSessionError, ProcessingError, } from './error';
|
|
12
12
|
export type { PaymentWidgetConfiguration } from './widget';
|
|
13
13
|
export type LightspeedPaymentsV1 = {
|
|
14
14
|
/**
|
|
@@ -17,6 +17,6 @@ export type LightspeedPaymentsV1 = {
|
|
|
17
17
|
* @param {string} session - The session ID for the payment session.
|
|
18
18
|
* @param {PaymentWidgetConfiguration} config - The configuration options for the payment widget.
|
|
19
19
|
*/
|
|
20
|
-
mountPaymentWidget(session: string,
|
|
20
|
+
mountPaymentWidget(session: string, config: PaymentWidgetConfiguration): Promise<WidgetController>;
|
|
21
21
|
};
|
|
22
22
|
export declare const v1: LightspeedPaymentsV1;
|
package/dist/v1/index.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* Don't use * for exports. Be specific to prevent leaking internal APIs.
|
|
6
6
|
*/
|
|
7
7
|
import { mountPaymentWidget } from './widget';
|
|
8
|
-
export {
|
|
9
|
-
export { UnsupportedLocationError, PaymentProcessingError } from './widget.error';
|
|
8
|
+
export { UnsupportedLocationError, InvalidSessionPayloadError, InvalidSessionError, ProcessingError, } from './error';
|
|
10
9
|
export var v1 = {
|
|
11
10
|
mountPaymentWidget: mountPaymentWidget,
|
|
12
11
|
};
|
|
@@ -9,7 +9,8 @@ export type LoggerConfig<P extends string, C extends object> = {
|
|
|
9
9
|
};
|
|
10
10
|
export interface Logger<T extends object> {
|
|
11
11
|
init: (config: LoggerConfig<string, T>['params']) => void;
|
|
12
|
-
|
|
12
|
+
setSessionMetadata: (metadata: Record<string, string>) => void;
|
|
13
13
|
log: (status: LogLevel, message: string, context?: Record<string, unknown>) => void;
|
|
14
14
|
}
|
|
15
|
+
export declare function withLogging<T extends object, Args extends unknown[], R>(logger: Logger<T>, event: string, handler: (...args: Args) => R): (...args: Args) => R;
|
|
15
16
|
export {};
|
|
@@ -1 +1,36 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
1
26
|
export var SERVICE_NAME = 'lsp-online-payments-sdk';
|
|
27
|
+
export function withLogging(logger, event, handler) {
|
|
28
|
+
return function () {
|
|
29
|
+
var args = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
args[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
logger.log('info', event, { args: args });
|
|
34
|
+
return handler.apply(void 0, __spreadArray([], __read(args), false));
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -7,7 +7,7 @@ export type DatadogLoggerConfig = LoggerConfig<'datadog', {
|
|
|
7
7
|
export type LoggerConfigParams = DatadogLoggerConfig['params'];
|
|
8
8
|
export declare class Logger implements ILogger<LoggerConfigParams> {
|
|
9
9
|
init(config: LoggerConfigParams): void;
|
|
10
|
-
|
|
10
|
+
setSessionMetadata(metadata: Record<string, string>): void;
|
|
11
11
|
log(status: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
12
12
|
}
|
|
13
13
|
export declare const getLogger: () => Logger;
|
|
@@ -10,11 +10,14 @@ var Logger = /** @class */ (function () {
|
|
|
10
10
|
service: 'lsp-online-payments-sdk',
|
|
11
11
|
env: env,
|
|
12
12
|
};
|
|
13
|
-
datadogLogs.
|
|
13
|
+
var initConfig = datadogLogs.getInitConfiguration();
|
|
14
|
+
if (!initConfig) {
|
|
15
|
+
datadogLogs.init(logsConfig);
|
|
16
|
+
}
|
|
14
17
|
};
|
|
15
|
-
Logger.prototype.
|
|
18
|
+
Logger.prototype.setSessionMetadata = function (metadata) {
|
|
16
19
|
// setting global context removes all existing context
|
|
17
|
-
datadogLogs.setGlobalContext(
|
|
20
|
+
datadogLogs.setGlobalContext({ metadata: metadata });
|
|
18
21
|
};
|
|
19
22
|
Logger.prototype.log = function (status, message, context) {
|
|
20
23
|
datadogLogs.logger.log(message, context, status);
|
|
@@ -4,7 +4,7 @@ var NoopLogger = /** @class */ (function () {
|
|
|
4
4
|
NoopLogger.prototype.init = function () {
|
|
5
5
|
// No operation
|
|
6
6
|
};
|
|
7
|
-
NoopLogger.prototype.
|
|
7
|
+
NoopLogger.prototype.setSessionMetadata = function () {
|
|
8
8
|
// No operation
|
|
9
9
|
};
|
|
10
10
|
NoopLogger.prototype.log = function () {
|
package/dist/v1/session.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidSessionPayloadError, InvalidSessionError } from './error';
|
|
2
2
|
export function decodePaymentSessionToContext(paymentSession) {
|
|
3
3
|
try {
|
|
4
4
|
var decoded = atob(paymentSession);
|
|
@@ -6,7 +6,7 @@ export function decodePaymentSessionToContext(paymentSession) {
|
|
|
6
6
|
if (jsonToken && isTokenValid(jsonToken)) {
|
|
7
7
|
return jsonToken;
|
|
8
8
|
}
|
|
9
|
-
throw new
|
|
9
|
+
throw new InvalidSessionPayloadError();
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
12
|
throw new InvalidSessionError();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StripeError, SetupIntent, PaymentIntent } from '@stripe/stripe-js';
|
|
2
|
+
import { ErrorResultEvent, RefusedResultEvent, SucceededResultEvent, PendingResultEvent } from '../EventBroadcaster';
|
|
3
|
+
export declare class EventBuilder {
|
|
4
|
+
static fromSetupIntent(setupIntent: SetupIntent): SucceededResultEvent | PendingResultEvent;
|
|
5
|
+
static fromStripeError(stripeError: StripeError): RefusedResultEvent | ErrorResultEvent;
|
|
6
|
+
static fromPaymentIntent(paymentIntent: PaymentIntent): SucceededResultEvent | PendingResultEvent;
|
|
7
|
+
}
|