@lightspeed/online-payments-sdk 0.2.1 → 0.2.3-rc1
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/{AdyenWidget.js → adyen/widget.js} +6 -6
- package/dist/cjs/v1/common.js +36 -0
- package/dist/cjs/v1/error.js +28 -0
- package/dist/cjs/v1/index.js +8 -5
- package/dist/cjs/v1/logging/common.js +4 -0
- package/dist/cjs/v1/logging/datadog/logger.js +30 -0
- package/dist/cjs/v1/logging/logger.js +13 -0
- package/dist/cjs/v1/logging/noop-logger.js +20 -0
- package/dist/cjs/v1/session.error.js +43 -0
- package/dist/cjs/v1/session.js +25 -0
- package/dist/cjs/v1/{StripeWidget.js → stripe/widget.js} +23 -16
- package/dist/cjs/v1/widget.error.js +43 -0
- package/dist/cjs/v1/widget.js +80 -43
- package/dist/v1/{AdyenWidget.d.ts → adyen/widget.d.ts} +2 -2
- package/dist/v1/{AdyenWidget.js → adyen/widget.js} +3 -3
- package/dist/v1/common.d.ts +3 -0
- package/dist/v1/common.js +35 -1
- package/dist/v1/error.d.ts +4 -0
- package/dist/v1/error.js +25 -0
- package/dist/v1/index.d.ts +3 -1
- package/dist/v1/index.js +3 -1
- package/dist/v1/logging/common.d.ts +15 -0
- package/dist/v1/logging/common.js +1 -0
- package/dist/v1/logging/datadog/logger.d.ts +13 -0
- package/dist/v1/logging/datadog/logger.js +26 -0
- package/dist/v1/logging/logger.d.ts +4 -0
- package/dist/v1/logging/logger.js +10 -0
- package/dist/v1/logging/noop-logger.d.ts +8 -0
- package/dist/v1/logging/noop-logger.js +16 -0
- package/dist/v1/session.d.ts +11 -0
- package/dist/v1/session.error.d.ts +15 -0
- package/dist/v1/session.error.js +40 -0
- package/dist/v1/session.js +21 -0
- package/dist/v1/{StripeWidget.d.ts → stripe/widget.d.ts} +2 -2
- package/dist/v1/{StripeWidget.js → stripe/widget.js} +20 -13
- package/dist/v1/widget.d.ts +2 -10
- package/dist/v1/widget.error.d.ts +15 -0
- package/dist/v1/widget.error.js +40 -0
- package/dist/v1/widget.js +79 -39
- package/package.json +5 -4
- package/dist/cjs/v1/errors.js +0 -82
- package/dist/v1/errors.d.ts +0 -42
- package/dist/v1/errors.js +0 -79
- /package/dist/cjs/{AdyenSession.js → v1/adyen/session.js} +0 -0
- /package/dist/cjs/{StripeSession.js → v1/stripe/session.js} +0 -0
- /package/dist/{AdyenSession.d.ts → v1/adyen/session.d.ts} +0 -0
- /package/dist/{AdyenSession.js → v1/adyen/session.js} +0 -0
- /package/dist/{StripeSession.d.ts → v1/stripe/session.d.ts} +0 -0
- /package/dist/{StripeSession.js → v1/stripe/session.js} +0 -0
package/dist/v1/error.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var BaseError = /** @class */ (function (_super) {
|
|
17
|
+
__extends(BaseError, _super);
|
|
18
|
+
function BaseError(code, message) {
|
|
19
|
+
var _this = _super.call(this, message) || this;
|
|
20
|
+
_this.code = code;
|
|
21
|
+
return _this;
|
|
22
|
+
}
|
|
23
|
+
return BaseError;
|
|
24
|
+
}(Error));
|
|
25
|
+
export { BaseError };
|
package/dist/v1/index.d.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* @fileoverview Entry point for version 1 of the LSP Online Payments SDK.
|
|
3
3
|
* This module exports the necessary functions and types for mounting the payment widget
|
|
4
4
|
* and handling errors related to payment sessions.
|
|
5
|
+
* Don't use * for exports. Be specific to prevent leaking internal APIs.
|
|
5
6
|
*/
|
|
6
7
|
import { WidgetController } from './common';
|
|
7
8
|
import { PaymentWidgetConfiguration } from './widget';
|
|
8
9
|
export type { Result, WidgetController } from './common';
|
|
9
|
-
export { InvalidSessionStructureError,
|
|
10
|
+
export { InvalidSessionStructureError, InvalidSessionError, } from './session.error';
|
|
11
|
+
export { UnsupportedLocationError, PaymentProcessingError } from './widget.error';
|
|
10
12
|
export type { PaymentWidgetConfiguration } from './widget';
|
|
11
13
|
export type LightspeedPaymentsV1 = {
|
|
12
14
|
/**
|
package/dist/v1/index.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* @fileoverview Entry point for version 1 of the LSP Online Payments SDK.
|
|
3
3
|
* This module exports the necessary functions and types for mounting the payment widget
|
|
4
4
|
* and handling errors related to payment sessions.
|
|
5
|
+
* Don't use * for exports. Be specific to prevent leaking internal APIs.
|
|
5
6
|
*/
|
|
6
7
|
import { mountPaymentWidget } from './widget';
|
|
7
|
-
export { InvalidSessionStructureError,
|
|
8
|
+
export { InvalidSessionStructureError, InvalidSessionError, } from './session.error';
|
|
9
|
+
export { UnsupportedLocationError, PaymentProcessingError } from './widget.error';
|
|
8
10
|
export var v1 = {
|
|
9
11
|
mountPaymentWidget: mountPaymentWidget,
|
|
10
12
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const SERVICE_NAME = "lsp-online-payments-sdk";
|
|
2
|
+
export type LogLevel = 'info' | 'warn' | 'error' | 'debug';
|
|
3
|
+
type BaseLoggingContext = {
|
|
4
|
+
env: string;
|
|
5
|
+
};
|
|
6
|
+
export type LoggerConfig<P extends string, C extends object> = {
|
|
7
|
+
provider: P;
|
|
8
|
+
params: C & BaseLoggingContext;
|
|
9
|
+
};
|
|
10
|
+
export interface Logger<T extends object> {
|
|
11
|
+
init: (config: LoggerConfig<string, T>['params']) => void;
|
|
12
|
+
setSessionContext: (context: Record<string, string>) => void;
|
|
13
|
+
log: (status: LogLevel, message: string, context?: Record<string, unknown>) => void;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var SERVICE_NAME = 'lsp-online-payments-sdk';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Logger as ILogger, LoggerConfig, LogLevel } from '../common';
|
|
2
|
+
import { LogsInitConfiguration } from '@datadog/browser-logs';
|
|
3
|
+
export type DatadogLoggerConfig = LoggerConfig<'datadog', {
|
|
4
|
+
site: LogsInitConfiguration['site'];
|
|
5
|
+
token: string;
|
|
6
|
+
}>;
|
|
7
|
+
export type LoggerConfigParams = DatadogLoggerConfig['params'];
|
|
8
|
+
export declare class Logger implements ILogger<LoggerConfigParams> {
|
|
9
|
+
init(config: LoggerConfigParams): void;
|
|
10
|
+
setSessionContext(context: Record<string, string>): void;
|
|
11
|
+
log(status: LogLevel, message: string, context?: Record<string, unknown>): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const getLogger: () => Logger;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { datadogLogs } from '@datadog/browser-logs';
|
|
2
|
+
var Logger = /** @class */ (function () {
|
|
3
|
+
function Logger() {
|
|
4
|
+
}
|
|
5
|
+
Logger.prototype.init = function (config) {
|
|
6
|
+
var site = config.site, token = config.token, env = config.env;
|
|
7
|
+
var logsConfig = {
|
|
8
|
+
clientToken: token,
|
|
9
|
+
site: site,
|
|
10
|
+
service: 'lsp-online-payments-sdk',
|
|
11
|
+
env: env,
|
|
12
|
+
};
|
|
13
|
+
datadogLogs.init(logsConfig);
|
|
14
|
+
};
|
|
15
|
+
Logger.prototype.setSessionContext = function (context) {
|
|
16
|
+
// setting global context removes all existing context
|
|
17
|
+
datadogLogs.setGlobalContext(context);
|
|
18
|
+
};
|
|
19
|
+
Logger.prototype.log = function (status, message, context) {
|
|
20
|
+
datadogLogs.logger.log(message, context, status);
|
|
21
|
+
};
|
|
22
|
+
return Logger;
|
|
23
|
+
}());
|
|
24
|
+
export { Logger };
|
|
25
|
+
var datadogLogger = new Logger();
|
|
26
|
+
export var getLogger = function () { return datadogLogger; };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getLogger as getDatadogLogger, } from './datadog/logger';
|
|
2
|
+
import { getLogger as getNoopLogger } from './noop-logger';
|
|
3
|
+
export function getLogger(config) {
|
|
4
|
+
if ((config === null || config === void 0 ? void 0 : config.provider) === 'datadog') {
|
|
5
|
+
var ddLogger = getDatadogLogger();
|
|
6
|
+
ddLogger.init(config.params);
|
|
7
|
+
return ddLogger;
|
|
8
|
+
}
|
|
9
|
+
return getNoopLogger();
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var NoopLogger = /** @class */ (function () {
|
|
2
|
+
function NoopLogger() {
|
|
3
|
+
}
|
|
4
|
+
NoopLogger.prototype.init = function () {
|
|
5
|
+
// No operation
|
|
6
|
+
};
|
|
7
|
+
NoopLogger.prototype.setSessionContext = function () {
|
|
8
|
+
// No operation
|
|
9
|
+
};
|
|
10
|
+
NoopLogger.prototype.log = function () {
|
|
11
|
+
// No operation
|
|
12
|
+
};
|
|
13
|
+
return NoopLogger;
|
|
14
|
+
}());
|
|
15
|
+
var noopLogger = new NoopLogger();
|
|
16
|
+
export var getLogger = function () { return noopLogger; };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LoggingConfig } from './logging/logger';
|
|
2
|
+
import { AdyenSession } from './adyen/session';
|
|
3
|
+
import { StripeSession } from './stripe/session';
|
|
4
|
+
type BaseSession = {
|
|
5
|
+
metadata: Record<string, string>;
|
|
6
|
+
logging?: LoggingConfig;
|
|
7
|
+
};
|
|
8
|
+
export type Session = BaseSession & (AdyenSession | StripeSession);
|
|
9
|
+
export declare function decodePaymentSessionToContext(paymentSession: string): Session;
|
|
10
|
+
export declare function isTokenValid(token: unknown): token is Session;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseError } from './error';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when the session structure is invalid.
|
|
4
|
+
* @typedef {Error} InvalidSessionStructureError
|
|
5
|
+
*/
|
|
6
|
+
export declare class InvalidSessionStructureError extends BaseError {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when the session is invalid.
|
|
11
|
+
* @typedef {Error} InvalidSessionError
|
|
12
|
+
*/
|
|
13
|
+
export declare class InvalidSessionError extends BaseError {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BaseError } from './error';
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when the session structure is invalid.
|
|
19
|
+
* @typedef {Error} InvalidSessionStructureError
|
|
20
|
+
*/
|
|
21
|
+
var InvalidSessionStructureError = /** @class */ (function (_super) {
|
|
22
|
+
__extends(InvalidSessionStructureError, _super);
|
|
23
|
+
function InvalidSessionStructureError() {
|
|
24
|
+
return _super.call(this, 'InvalidSessionStructure', 'The contents of the session are invalid') || this;
|
|
25
|
+
}
|
|
26
|
+
return InvalidSessionStructureError;
|
|
27
|
+
}(BaseError));
|
|
28
|
+
export { InvalidSessionStructureError };
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown when the session is invalid.
|
|
31
|
+
* @typedef {Error} InvalidSessionError
|
|
32
|
+
*/
|
|
33
|
+
var InvalidSessionError = /** @class */ (function (_super) {
|
|
34
|
+
__extends(InvalidSessionError, _super);
|
|
35
|
+
function InvalidSessionError() {
|
|
36
|
+
return _super.call(this, 'InvalidSessionError', 'The provided session is invalid. Verify the correct session is being passed') || this;
|
|
37
|
+
}
|
|
38
|
+
return InvalidSessionError;
|
|
39
|
+
}(BaseError));
|
|
40
|
+
export { InvalidSessionError };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { InvalidSessionStructureError, InvalidSessionError, } from './session.error';
|
|
2
|
+
export function decodePaymentSessionToContext(paymentSession) {
|
|
3
|
+
try {
|
|
4
|
+
var decoded = atob(paymentSession);
|
|
5
|
+
var jsonToken = JSON.parse(decoded);
|
|
6
|
+
if (jsonToken && isTokenValid(jsonToken)) {
|
|
7
|
+
return jsonToken;
|
|
8
|
+
}
|
|
9
|
+
throw new InvalidSessionStructureError();
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
throw new InvalidSessionError();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function isTokenValid(token) {
|
|
16
|
+
var t = token;
|
|
17
|
+
if (t && !!t.psp && !!t.context) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SetupIntent, PaymentIntent } from '@stripe/stripe-js';
|
|
2
|
-
import { StripeContext } from '
|
|
3
|
-
import { Callbacks, DefaultValues, ResultCode, WidgetController, WidgetInterface } from '
|
|
2
|
+
import { StripeContext } from './session';
|
|
3
|
+
import { Callbacks, DefaultValues, ResultCode, WidgetController, WidgetInterface } from '../common';
|
|
4
4
|
export declare function mapStripeResultCode(code: SetupIntent.Status | PaymentIntent.Status): ResultCode;
|
|
5
5
|
export declare function mount(mountElement: HTMLElement, context: StripeContext, listeners: Callbacks, defaultValues?: DefaultValues): Promise<WidgetController>;
|
|
6
6
|
export declare const StripeWidget: WidgetInterface<StripeContext>;
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g =
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
13
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
14
|
function step(op) {
|
|
15
15
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -68,25 +68,32 @@ function init(context) {
|
|
|
68
68
|
}
|
|
69
69
|
export function mount(mountElement, context, listeners, defaultValues) {
|
|
70
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var _a, stripe, elements, paymentElement;
|
|
71
|
+
var _a, stripe, elements, options, paymentElement;
|
|
72
72
|
var _this = this;
|
|
73
73
|
return __generator(this, function (_b) {
|
|
74
74
|
switch (_b.label) {
|
|
75
75
|
case 0: return [4 /*yield*/, init(context)];
|
|
76
76
|
case 1:
|
|
77
77
|
_a = _b.sent(), stripe = _a.stripe, elements = _a.elements;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
options = {
|
|
79
|
+
wallets: {
|
|
80
|
+
applePay: 'never',
|
|
81
|
+
googlePay: 'never',
|
|
82
|
+
link: 'never',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
if (defaultValues) {
|
|
86
|
+
options.defaultValues = {
|
|
87
|
+
billingDetails: {
|
|
88
|
+
address: {
|
|
89
|
+
country: defaultValues.country,
|
|
90
|
+
postal_code: defaultValues.postalCode,
|
|
86
91
|
},
|
|
87
92
|
},
|
|
88
|
-
}
|
|
89
|
-
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
paymentElement = elements.create('payment', options);
|
|
96
|
+
paymentElement.on('ready', function () { var _a; return (_a = listeners.onReady) === null || _a === void 0 ? void 0 : _a.call(listeners); });
|
|
90
97
|
paymentElement.mount(mountElement);
|
|
91
98
|
return [2 /*return*/, {
|
|
92
99
|
unmount: function () { return paymentElement.unmount(); },
|
package/dist/v1/widget.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AdyenSession } from 'src/AdyenSession';
|
|
3
|
-
import { Callbacks, WidgetController, DefaultValues } from 'src/v1/common';
|
|
4
|
-
type Session = {
|
|
5
|
-
metadata: Record<string, string>;
|
|
6
|
-
} & (AdyenSession | StripeSession);
|
|
1
|
+
import { Callbacks, WidgetController, DefaultValues } from './common';
|
|
7
2
|
export type PaymentWidgetConfiguration = {
|
|
8
3
|
mountPoint: HTMLElement;
|
|
9
4
|
defaultValues?: DefaultValues;
|
|
10
5
|
} & Callbacks;
|
|
11
|
-
export declare function mountPaymentWidget(session: string, { mountPoint, onComplete, onFail, defaultValues }: PaymentWidgetConfiguration): Promise<WidgetController>;
|
|
12
|
-
export declare function decodePaymentSessionToContext(paymentSession: string): Session;
|
|
13
|
-
export declare function isTokenValid(token: unknown): token is Session;
|
|
14
|
-
export {};
|
|
6
|
+
export declare function mountPaymentWidget(session: string, { mountPoint, onComplete, onFail, onReady, defaultValues, }: PaymentWidgetConfiguration): Promise<WidgetController>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseError } from './error';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when the location is unsupported.
|
|
4
|
+
* @typedef {Error} UnsupportedLocationError
|
|
5
|
+
*/
|
|
6
|
+
export declare class UnsupportedLocationError extends BaseError {
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when the session structure is invalid.
|
|
11
|
+
* @typedef {Error} PaymentProcessingError
|
|
12
|
+
*/
|
|
13
|
+
export declare class PaymentProcessingError extends BaseError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
import { BaseError } from './error';
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when the location is unsupported.
|
|
19
|
+
* @typedef {Error} UnsupportedLocationError
|
|
20
|
+
*/
|
|
21
|
+
var UnsupportedLocationError = /** @class */ (function (_super) {
|
|
22
|
+
__extends(UnsupportedLocationError, _super);
|
|
23
|
+
function UnsupportedLocationError() {
|
|
24
|
+
return _super.call(this, 'UnsupportedLocation', 'The location you are attempting to process with is not supported') || this;
|
|
25
|
+
}
|
|
26
|
+
return UnsupportedLocationError;
|
|
27
|
+
}(BaseError));
|
|
28
|
+
export { UnsupportedLocationError };
|
|
29
|
+
/**
|
|
30
|
+
* Error thrown when the session structure is invalid.
|
|
31
|
+
* @typedef {Error} PaymentProcessingError
|
|
32
|
+
*/
|
|
33
|
+
var PaymentProcessingError = /** @class */ (function (_super) {
|
|
34
|
+
__extends(PaymentProcessingError, _super);
|
|
35
|
+
function PaymentProcessingError(message) {
|
|
36
|
+
return _super.call(this, 'PaymentProcessing', "An error occurred while processing the payment. ".concat(message)) || this;
|
|
37
|
+
}
|
|
38
|
+
return PaymentProcessingError;
|
|
39
|
+
}(BaseError));
|
|
40
|
+
export { PaymentProcessingError };
|
package/dist/v1/widget.js
CHANGED
|
@@ -1,41 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
20
35
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
};
|
|
37
|
+
import { AdyenWidget } from './adyen/widget';
|
|
38
|
+
import { withLogging, } from './common';
|
|
39
|
+
import { StripeWidget } from './stripe/widget';
|
|
40
|
+
import { decodePaymentSessionToContext } from './session';
|
|
41
|
+
import { UnsupportedLocationError } from './widget.error';
|
|
42
|
+
import { getLogger } from './logging/logger';
|
|
43
|
+
export function mountPaymentWidget(session_1, _a) {
|
|
44
|
+
return __awaiter(this, arguments, void 0, function (session, _b) {
|
|
45
|
+
var decodedSession, logger, handlers, widgetController, _c;
|
|
46
|
+
var mountPoint = _b.mountPoint, onComplete = _b.onComplete, onFail = _b.onFail, onReady = _b.onReady, defaultValues = _b.defaultValues;
|
|
47
|
+
return __generator(this, function (_d) {
|
|
48
|
+
switch (_d.label) {
|
|
49
|
+
case 0:
|
|
50
|
+
decodedSession = decodePaymentSessionToContext(session);
|
|
51
|
+
logger = getLogger(decodedSession.logging);
|
|
52
|
+
logger.setSessionContext(decodedSession.metadata);
|
|
53
|
+
handlers = {
|
|
54
|
+
onComplete: withLogging(logger, 'complete', onComplete || (function () { })),
|
|
55
|
+
onFail: withLogging(logger, 'fail', onFail || (function () { })),
|
|
56
|
+
onReady: withLogging(logger, 'ready', onReady || (function () { })),
|
|
57
|
+
};
|
|
58
|
+
logger.log('info', 'mount', { sessionContext: decodedSession.context });
|
|
59
|
+
_c = decodedSession.psp;
|
|
60
|
+
switch (_c) {
|
|
61
|
+
case 'ADYEN': return [3 /*break*/, 1];
|
|
62
|
+
case 'STRIPE': return [3 /*break*/, 3];
|
|
63
|
+
}
|
|
64
|
+
return [3 /*break*/, 5];
|
|
65
|
+
case 1: return [4 /*yield*/, AdyenWidget.mount(mountPoint, decodedSession.context, handlers)];
|
|
66
|
+
case 2:
|
|
67
|
+
widgetController = _d.sent();
|
|
68
|
+
return [3 /*break*/, 6];
|
|
69
|
+
case 3: return [4 /*yield*/, StripeWidget.mount(mountPoint, decodedSession.context, handlers, defaultValues)];
|
|
70
|
+
case 4:
|
|
71
|
+
widgetController = _d.sent();
|
|
72
|
+
return [3 /*break*/, 6];
|
|
73
|
+
case 5: throw new UnsupportedLocationError();
|
|
74
|
+
case 6:
|
|
75
|
+
widgetController.submit = withLogging(logger, 'submit', widgetController.submit);
|
|
76
|
+
widgetController.unmount = withLogging(logger, 'unmount', widgetController.unmount);
|
|
77
|
+
return [2 /*return*/, widgetController];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
41
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightspeed/online-payments-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3rc1",
|
|
4
4
|
"description": "Process online-payments with Lightspeed Payments",
|
|
5
5
|
"author": "Lightspeed Commerce Inc.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs --downlevelIteration --declaration false"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/jest": "^
|
|
30
|
+
"@types/jest": "^30.0.0",
|
|
31
31
|
"gts": "^6.0.2",
|
|
32
|
-
"jest": "^
|
|
33
|
-
"jest-environment-jsdom": "^
|
|
32
|
+
"jest": "^30.0.0",
|
|
33
|
+
"jest-environment-jsdom": "^30.0.0",
|
|
34
34
|
"jest-junit": "^16.0.0",
|
|
35
35
|
"rollup": "^4.34.8",
|
|
36
36
|
"ts-jest": "^29.2.5",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@adyen/adyen-web": "^6.8.0",
|
|
42
|
+
"@datadog/browser-logs": "^6.10.1",
|
|
42
43
|
"@stripe/stripe-js": "^7.3.0"
|
|
43
44
|
}
|
|
44
45
|
}
|
package/dist/cjs/v1/errors.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.PaymentProcessingError = exports.InvalidSessionError = exports.InvalidSessionStructureError = exports.UnsupportedLocationError = exports.ErrorCode = void 0;
|
|
19
|
-
var ErrorCode;
|
|
20
|
-
(function (ErrorCode) {
|
|
21
|
-
ErrorCode["UnsupportedLocation"] = "UnsupportedLocation";
|
|
22
|
-
ErrorCode["InvalidSessionStructure"] = "InvalidSessionStructure";
|
|
23
|
-
ErrorCode["InvalidSessionError"] = "InvalidSessionError";
|
|
24
|
-
ErrorCode["PaymentProcessingError"] = "PaymentProcessingError";
|
|
25
|
-
})(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
|
|
26
|
-
var BaseError = /** @class */ (function (_super) {
|
|
27
|
-
__extends(BaseError, _super);
|
|
28
|
-
function BaseError(code, message) {
|
|
29
|
-
var _this = _super.call(this, message) || this;
|
|
30
|
-
_this.code = code;
|
|
31
|
-
return _this;
|
|
32
|
-
}
|
|
33
|
-
return BaseError;
|
|
34
|
-
}(Error));
|
|
35
|
-
/**
|
|
36
|
-
* Error thrown when the location is unsupported.
|
|
37
|
-
* @typedef {Error} UnsupportedLocationError
|
|
38
|
-
*/
|
|
39
|
-
var UnsupportedLocationError = /** @class */ (function (_super) {
|
|
40
|
-
__extends(UnsupportedLocationError, _super);
|
|
41
|
-
function UnsupportedLocationError() {
|
|
42
|
-
return _super.call(this, ErrorCode.UnsupportedLocation, 'The location you are attempting to process with is not supported') || this;
|
|
43
|
-
}
|
|
44
|
-
return UnsupportedLocationError;
|
|
45
|
-
}(BaseError));
|
|
46
|
-
exports.UnsupportedLocationError = UnsupportedLocationError;
|
|
47
|
-
/**
|
|
48
|
-
* Error thrown when the session structure is invalid.
|
|
49
|
-
* @typedef {Error} InvalidSessionStructureError
|
|
50
|
-
*/
|
|
51
|
-
var InvalidSessionStructureError = /** @class */ (function (_super) {
|
|
52
|
-
__extends(InvalidSessionStructureError, _super);
|
|
53
|
-
function InvalidSessionStructureError() {
|
|
54
|
-
return _super.call(this, ErrorCode.InvalidSessionStructure, 'The contents of the session are invalid') || this;
|
|
55
|
-
}
|
|
56
|
-
return InvalidSessionStructureError;
|
|
57
|
-
}(BaseError));
|
|
58
|
-
exports.InvalidSessionStructureError = InvalidSessionStructureError;
|
|
59
|
-
/**
|
|
60
|
-
* Error thrown when the session is invalid.
|
|
61
|
-
* @typedef {Error} InvalidSessionError
|
|
62
|
-
*/
|
|
63
|
-
var InvalidSessionError = /** @class */ (function (_super) {
|
|
64
|
-
__extends(InvalidSessionError, _super);
|
|
65
|
-
function InvalidSessionError() {
|
|
66
|
-
return _super.call(this, ErrorCode.InvalidSessionError, 'The provided session is invalid. Verify the correct session is being passed') || this;
|
|
67
|
-
}
|
|
68
|
-
return InvalidSessionError;
|
|
69
|
-
}(BaseError));
|
|
70
|
-
exports.InvalidSessionError = InvalidSessionError;
|
|
71
|
-
/**
|
|
72
|
-
* Error thrown when the session structure is invalid.
|
|
73
|
-
* @typedef {Error} PaymentProcessingError
|
|
74
|
-
*/
|
|
75
|
-
var PaymentProcessingError = /** @class */ (function (_super) {
|
|
76
|
-
__extends(PaymentProcessingError, _super);
|
|
77
|
-
function PaymentProcessingError(message) {
|
|
78
|
-
return _super.call(this, ErrorCode.PaymentProcessingError, "An error occurred while processing the payment. ".concat(message)) || this;
|
|
79
|
-
}
|
|
80
|
-
return PaymentProcessingError;
|
|
81
|
-
}(BaseError));
|
|
82
|
-
exports.PaymentProcessingError = PaymentProcessingError;
|