@lightspeed/online-payments-sdk 0.2.1 → 0.2.2
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} +5 -5
- package/dist/cjs/v1/widget.error.js +43 -0
- package/dist/cjs/v1/widget.js +79 -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 +2 -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} +2 -2
- package/dist/v1/widget.d.ts +1 -9
- package/dist/v1/widget.error.d.ts +15 -0
- package/dist/v1/widget.error.js +40 -0
- package/dist/v1/widget.js +78 -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
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -36,9 +36,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.AdyenWidget =
|
|
39
|
+
exports.AdyenWidget = void 0;
|
|
40
|
+
exports.mapAdyenResultCode = mapAdyenResultCode;
|
|
40
41
|
var adyen_web_1 = require("@adyen/adyen-web");
|
|
41
|
-
var
|
|
42
|
+
var widget_error_1 = require("../widget.error");
|
|
42
43
|
function mapAdyenResultCode(code) {
|
|
43
44
|
switch (code) {
|
|
44
45
|
case 'Authorised':
|
|
@@ -49,7 +50,6 @@ function mapAdyenResultCode(code) {
|
|
|
49
50
|
return 'Unexpected';
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
exports.mapAdyenResultCode = mapAdyenResultCode;
|
|
53
53
|
function mount(mountElement, context, listeners) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
55
|
var checkoutConfig, checkout, dropinConfiguration, dropIn;
|
|
@@ -110,7 +110,7 @@ function createAdyenConfiguration(context, listeners) {
|
|
|
110
110
|
});
|
|
111
111
|
},
|
|
112
112
|
onError: function (error) {
|
|
113
|
-
throw new
|
|
113
|
+
throw new widget_error_1.PaymentProcessingError(error.message);
|
|
114
114
|
},
|
|
115
115
|
paymentMethodsResponse: context.paymentMethods,
|
|
116
116
|
};
|
package/dist/cjs/v1/common.js
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
2
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.withLogging = withLogging;
|
|
29
|
+
function withLogging(logger, event, handler) {
|
|
30
|
+
return function () {
|
|
31
|
+
var args = [];
|
|
32
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
|
+
args[_i] = arguments[_i];
|
|
34
|
+
}
|
|
35
|
+
logger.log('info', event, { args: args });
|
|
36
|
+
return handler.apply(void 0, __spreadArray([], __read(args), false));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.BaseError = void 0;
|
|
19
|
+
var BaseError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(BaseError, _super);
|
|
21
|
+
function BaseError(code, message) {
|
|
22
|
+
var _this = _super.call(this, message) || this;
|
|
23
|
+
_this.code = code;
|
|
24
|
+
return _this;
|
|
25
|
+
}
|
|
26
|
+
return BaseError;
|
|
27
|
+
}(Error));
|
|
28
|
+
exports.BaseError = BaseError;
|
package/dist/cjs/v1/index.js
CHANGED
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
* @fileoverview Entry point for version 1 of the LSP Online Payments SDK.
|
|
4
4
|
* This module exports the necessary functions and types for mounting the payment widget
|
|
5
5
|
* and handling errors related to payment sessions.
|
|
6
|
+
* Don't use * for exports. Be specific to prevent leaking internal APIs.
|
|
6
7
|
*/
|
|
7
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.v1 = exports.
|
|
9
|
+
exports.v1 = exports.PaymentProcessingError = exports.UnsupportedLocationError = exports.InvalidSessionError = exports.InvalidSessionStructureError = void 0;
|
|
9
10
|
var widget_1 = require("./widget");
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "InvalidSessionStructureError", { enumerable: true, get: function () { return
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
|
|
11
|
+
var session_error_1 = require("./session.error");
|
|
12
|
+
Object.defineProperty(exports, "InvalidSessionStructureError", { enumerable: true, get: function () { return session_error_1.InvalidSessionStructureError; } });
|
|
13
|
+
Object.defineProperty(exports, "InvalidSessionError", { enumerable: true, get: function () { return session_error_1.InvalidSessionError; } });
|
|
14
|
+
var widget_error_1 = require("./widget.error");
|
|
15
|
+
Object.defineProperty(exports, "UnsupportedLocationError", { enumerable: true, get: function () { return widget_error_1.UnsupportedLocationError; } });
|
|
16
|
+
Object.defineProperty(exports, "PaymentProcessingError", { enumerable: true, get: function () { return widget_error_1.PaymentProcessingError; } });
|
|
14
17
|
exports.v1 = {
|
|
15
18
|
mountPaymentWidget: widget_1.mountPaymentWidget,
|
|
16
19
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogger = exports.Logger = void 0;
|
|
4
|
+
var browser_logs_1 = require("@datadog/browser-logs");
|
|
5
|
+
var Logger = /** @class */ (function () {
|
|
6
|
+
function Logger() {
|
|
7
|
+
}
|
|
8
|
+
Logger.prototype.init = function (config) {
|
|
9
|
+
var site = config.site, token = config.token, env = config.env;
|
|
10
|
+
var logsConfig = {
|
|
11
|
+
clientToken: token,
|
|
12
|
+
site: site,
|
|
13
|
+
service: 'lsp-online-payments-sdk',
|
|
14
|
+
env: env,
|
|
15
|
+
};
|
|
16
|
+
browser_logs_1.datadogLogs.init(logsConfig);
|
|
17
|
+
};
|
|
18
|
+
Logger.prototype.setSessionContext = function (context) {
|
|
19
|
+
// setting global context removes all existing context
|
|
20
|
+
browser_logs_1.datadogLogs.setGlobalContext(context);
|
|
21
|
+
};
|
|
22
|
+
Logger.prototype.log = function (status, message, context) {
|
|
23
|
+
browser_logs_1.datadogLogs.logger.log(message, context, status);
|
|
24
|
+
};
|
|
25
|
+
return Logger;
|
|
26
|
+
}());
|
|
27
|
+
exports.Logger = Logger;
|
|
28
|
+
var datadogLogger = new Logger();
|
|
29
|
+
var getLogger = function () { return datadogLogger; };
|
|
30
|
+
exports.getLogger = getLogger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogger = getLogger;
|
|
4
|
+
var logger_1 = require("./datadog/logger");
|
|
5
|
+
var noop_logger_1 = require("./noop-logger");
|
|
6
|
+
function getLogger(config) {
|
|
7
|
+
if ((config === null || config === void 0 ? void 0 : config.provider) === 'datadog') {
|
|
8
|
+
var ddLogger = (0, logger_1.getLogger)();
|
|
9
|
+
ddLogger.init(config.params);
|
|
10
|
+
return ddLogger;
|
|
11
|
+
}
|
|
12
|
+
return (0, noop_logger_1.getLogger)();
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogger = void 0;
|
|
4
|
+
var NoopLogger = /** @class */ (function () {
|
|
5
|
+
function NoopLogger() {
|
|
6
|
+
}
|
|
7
|
+
NoopLogger.prototype.init = function () {
|
|
8
|
+
// No operation
|
|
9
|
+
};
|
|
10
|
+
NoopLogger.prototype.setSessionContext = function () {
|
|
11
|
+
// No operation
|
|
12
|
+
};
|
|
13
|
+
NoopLogger.prototype.log = function () {
|
|
14
|
+
// No operation
|
|
15
|
+
};
|
|
16
|
+
return NoopLogger;
|
|
17
|
+
}());
|
|
18
|
+
var noopLogger = new NoopLogger();
|
|
19
|
+
var getLogger = function () { return noopLogger; };
|
|
20
|
+
exports.getLogger = getLogger;
|
|
@@ -0,0 +1,43 @@
|
|
|
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.InvalidSessionError = exports.InvalidSessionStructureError = void 0;
|
|
19
|
+
var error_1 = require("./error");
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when the session structure is invalid.
|
|
22
|
+
* @typedef {Error} InvalidSessionStructureError
|
|
23
|
+
*/
|
|
24
|
+
var InvalidSessionStructureError = /** @class */ (function (_super) {
|
|
25
|
+
__extends(InvalidSessionStructureError, _super);
|
|
26
|
+
function InvalidSessionStructureError() {
|
|
27
|
+
return _super.call(this, 'InvalidSessionStructure', 'The contents of the session are invalid') || this;
|
|
28
|
+
}
|
|
29
|
+
return InvalidSessionStructureError;
|
|
30
|
+
}(error_1.BaseError));
|
|
31
|
+
exports.InvalidSessionStructureError = InvalidSessionStructureError;
|
|
32
|
+
/**
|
|
33
|
+
* Error thrown when the session is invalid.
|
|
34
|
+
* @typedef {Error} InvalidSessionError
|
|
35
|
+
*/
|
|
36
|
+
var InvalidSessionError = /** @class */ (function (_super) {
|
|
37
|
+
__extends(InvalidSessionError, _super);
|
|
38
|
+
function InvalidSessionError() {
|
|
39
|
+
return _super.call(this, 'InvalidSessionError', 'The provided session is invalid. Verify the correct session is being passed') || this;
|
|
40
|
+
}
|
|
41
|
+
return InvalidSessionError;
|
|
42
|
+
}(error_1.BaseError));
|
|
43
|
+
exports.InvalidSessionError = InvalidSessionError;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodePaymentSessionToContext = decodePaymentSessionToContext;
|
|
4
|
+
exports.isTokenValid = isTokenValid;
|
|
5
|
+
var session_error_1 = require("./session.error");
|
|
6
|
+
function decodePaymentSessionToContext(paymentSession) {
|
|
7
|
+
try {
|
|
8
|
+
var decoded = atob(paymentSession);
|
|
9
|
+
var jsonToken = JSON.parse(decoded);
|
|
10
|
+
if (jsonToken && isTokenValid(jsonToken)) {
|
|
11
|
+
return jsonToken;
|
|
12
|
+
}
|
|
13
|
+
throw new session_error_1.InvalidSessionStructureError();
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
throw new session_error_1.InvalidSessionError();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function isTokenValid(token) {
|
|
20
|
+
var t = token;
|
|
21
|
+
if (t && !!t.psp && !!t.context) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -36,7 +36,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.StripeWidget =
|
|
39
|
+
exports.StripeWidget = void 0;
|
|
40
|
+
exports.mapStripeResultCode = mapStripeResultCode;
|
|
41
|
+
exports.mount = mount;
|
|
40
42
|
var stripe_js_1 = require("@stripe/stripe-js");
|
|
41
43
|
function mapStripeResultCode(code) {
|
|
42
44
|
switch (code) {
|
|
@@ -46,7 +48,6 @@ function mapStripeResultCode(code) {
|
|
|
46
48
|
return 'Unexpected';
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
exports.mapStripeResultCode = mapStripeResultCode;
|
|
50
51
|
function init(context) {
|
|
51
52
|
return __awaiter(this, void 0, void 0, function () {
|
|
52
53
|
var publishableKey, clientSecret, customerSessionClientSecret, loadedStripe, stripe, elements;
|
|
@@ -144,7 +145,6 @@ function mount(mountElement, context, listeners, defaultValues) {
|
|
|
144
145
|
});
|
|
145
146
|
});
|
|
146
147
|
}
|
|
147
|
-
exports.mount = mount;
|
|
148
148
|
exports.StripeWidget = {
|
|
149
149
|
mount: mount,
|
|
150
150
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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.UnsupportedLocationError = void 0;
|
|
19
|
+
var error_1 = require("./error");
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when the location is unsupported.
|
|
22
|
+
* @typedef {Error} UnsupportedLocationError
|
|
23
|
+
*/
|
|
24
|
+
var UnsupportedLocationError = /** @class */ (function (_super) {
|
|
25
|
+
__extends(UnsupportedLocationError, _super);
|
|
26
|
+
function UnsupportedLocationError() {
|
|
27
|
+
return _super.call(this, 'UnsupportedLocation', 'The location you are attempting to process with is not supported') || this;
|
|
28
|
+
}
|
|
29
|
+
return UnsupportedLocationError;
|
|
30
|
+
}(error_1.BaseError));
|
|
31
|
+
exports.UnsupportedLocationError = UnsupportedLocationError;
|
|
32
|
+
/**
|
|
33
|
+
* Error thrown when the session structure is invalid.
|
|
34
|
+
* @typedef {Error} PaymentProcessingError
|
|
35
|
+
*/
|
|
36
|
+
var PaymentProcessingError = /** @class */ (function (_super) {
|
|
37
|
+
__extends(PaymentProcessingError, _super);
|
|
38
|
+
function PaymentProcessingError(message) {
|
|
39
|
+
return _super.call(this, 'PaymentProcessing', "An error occurred while processing the payment. ".concat(message)) || this;
|
|
40
|
+
}
|
|
41
|
+
return PaymentProcessingError;
|
|
42
|
+
}(error_1.BaseError));
|
|
43
|
+
exports.PaymentProcessingError = PaymentProcessingError;
|
package/dist/cjs/v1/widget.js
CHANGED
|
@@ -1,47 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
23
36
|
}
|
|
24
|
-
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
39
|
exports.mountPaymentWidget = mountPaymentWidget;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
var widget_1 = require("./adyen/widget");
|
|
41
|
+
var common_1 = require("./common");
|
|
42
|
+
var widget_2 = require("./stripe/widget");
|
|
43
|
+
var session_1 = require("./session");
|
|
44
|
+
var widget_error_1 = require("./widget.error");
|
|
45
|
+
var logger_1 = require("./logging/logger");
|
|
46
|
+
function mountPaymentWidget(session_2, _a) {
|
|
47
|
+
return __awaiter(this, arguments, void 0, function (session, _b) {
|
|
48
|
+
var decodedSession, logger, handlers, widgetController, _c;
|
|
49
|
+
var mountPoint = _b.mountPoint, onComplete = _b.onComplete, onFail = _b.onFail, defaultValues = _b.defaultValues;
|
|
50
|
+
return __generator(this, function (_d) {
|
|
51
|
+
switch (_d.label) {
|
|
52
|
+
case 0:
|
|
53
|
+
decodedSession = (0, session_1.decodePaymentSessionToContext)(session);
|
|
54
|
+
logger = (0, logger_1.getLogger)(decodedSession.logging);
|
|
55
|
+
logger.setSessionContext(decodedSession.metadata);
|
|
56
|
+
handlers = {
|
|
57
|
+
onComplete: (0, common_1.withLogging)(logger, 'complete', onComplete || (function () { })),
|
|
58
|
+
onFail: (0, common_1.withLogging)(logger, 'fail', onFail || (function () { })),
|
|
59
|
+
};
|
|
60
|
+
logger.log('info', 'mount', { sessionContext: decodedSession.context });
|
|
61
|
+
_c = decodedSession.psp;
|
|
62
|
+
switch (_c) {
|
|
63
|
+
case 'ADYEN': return [3 /*break*/, 1];
|
|
64
|
+
case 'STRIPE': return [3 /*break*/, 3];
|
|
65
|
+
}
|
|
66
|
+
return [3 /*break*/, 5];
|
|
67
|
+
case 1: return [4 /*yield*/, widget_1.AdyenWidget.mount(mountPoint, decodedSession.context, handlers)];
|
|
68
|
+
case 2:
|
|
69
|
+
widgetController = _d.sent();
|
|
70
|
+
return [3 /*break*/, 6];
|
|
71
|
+
case 3: return [4 /*yield*/, widget_2.StripeWidget.mount(mountPoint, decodedSession.context, handlers, defaultValues)];
|
|
72
|
+
case 4:
|
|
73
|
+
widgetController = _d.sent();
|
|
74
|
+
return [3 /*break*/, 6];
|
|
75
|
+
case 5: throw new widget_error_1.UnsupportedLocationError();
|
|
76
|
+
case 6:
|
|
77
|
+
widgetController.submit = (0, common_1.withLogging)(logger, 'submit', widgetController.submit);
|
|
78
|
+
widgetController.unmount = (0, common_1.withLogging)(logger, 'unmount', widgetController.unmount);
|
|
79
|
+
return [2 /*return*/, widgetController];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
46
83
|
}
|
|
47
|
-
exports.isTokenValid = isTokenValid;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResultCode as AdyenResultCode } from '@adyen/adyen-web';
|
|
2
|
-
import { AdyenContext } from '
|
|
3
|
-
import { WidgetInterface, ResultCode } from '
|
|
2
|
+
import { AdyenContext } from './session';
|
|
3
|
+
import { WidgetInterface, ResultCode } from '../common';
|
|
4
4
|
export declare function mapAdyenResultCode(code: AdyenResultCode): ResultCode;
|
|
5
5
|
export declare const AdyenWidget: WidgetInterface<AdyenContext>;
|
|
@@ -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.");
|
|
@@ -35,7 +35,7 @@ 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 { PaymentProcessingError } from '
|
|
38
|
+
import { PaymentProcessingError } from '../widget.error';
|
|
39
39
|
export function mapAdyenResultCode(code) {
|
|
40
40
|
switch (code) {
|
|
41
41
|
case 'Authorised':
|
package/dist/v1/common.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Logger } from './logging/common';
|
|
1
2
|
export type ResultCode = 'Authorized' | 'Success' | 'Failure' | 'Refused' | 'Unexpected';
|
|
2
3
|
export type Status = 'Pending' | 'Complete';
|
|
3
4
|
export type Result = {
|
|
@@ -19,3 +20,4 @@ export type DefaultValues = {
|
|
|
19
20
|
export type WidgetInterface<T> = {
|
|
20
21
|
mount: (mountElement: HTMLElement, context: T, listeners: Callbacks, defaultValues?: DefaultValues) => Promise<WidgetController>;
|
|
21
22
|
};
|
|
23
|
+
export declare function withLogging<T extends object, Args extends unknown[], R>(logger: Logger<T>, event: string, handler: (...args: Args) => R): (...args: Args) => R;
|
package/dist/v1/common.js
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
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
|
+
}
|
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
|
};
|