@lightspeed/online-payments-sdk 0.1.5 → 0.2.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/AdyenSession.d.ts +16 -0
- package/dist/AdyenSession.js +1 -0
- package/dist/StripeSession.d.ts +10 -0
- package/dist/StripeSession.js +1 -0
- package/dist/cjs/AdyenSession.js +2 -0
- package/dist/cjs/StripeSession.js +2 -0
- package/dist/cjs/index.js +5 -90
- package/dist/cjs/v1/AdyenWidget.js +125 -0
- package/dist/cjs/v1/StripeWidget.js +149 -0
- package/dist/cjs/v1/common.js +2 -0
- package/dist/cjs/v1/errors.js +82 -0
- package/dist/cjs/v1/index.js +16 -0
- package/dist/cjs/v1/widget.js +47 -0
- package/dist/index.d.ts +3 -10
- package/dist/index.js +3 -87
- package/dist/v1/AdyenWidget.d.ts +5 -0
- package/dist/v1/AdyenWidget.js +121 -0
- package/dist/v1/StripeWidget.d.ts +6 -0
- package/dist/v1/StripeWidget.js +144 -0
- package/dist/v1/common.d.ts +17 -0
- package/dist/v1/common.js +1 -0
- package/dist/v1/errors.d.ts +42 -0
- package/dist/v1/errors.js +79 -0
- package/dist/v1/index.d.ts +20 -0
- package/dist/v1/index.js +10 -0
- package/dist/v1/widget.d.ts +13 -0
- package/dist/v1/widget.js +41 -0
- package/package.json +14 -5
- package/styles/lightspeed-global-styles.css +1 -0
- package/dist/cjs/frameMessenger.js +0 -59
- package/dist/frameMessenger.d.ts +0 -41
- package/dist/frameMessenger.js +0 -56
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PaymentMethodsResponse } from '@adyen/adyen-web';
|
|
2
|
+
export type AdyenSession = {
|
|
3
|
+
psp: 'ADYEN';
|
|
4
|
+
context: AdyenContext;
|
|
5
|
+
};
|
|
6
|
+
export type AdyenContext = {
|
|
7
|
+
clientKey: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
sessionData: string;
|
|
10
|
+
locale: string;
|
|
11
|
+
countryCode: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
currency: string;
|
|
14
|
+
env: 'test' | 'live';
|
|
15
|
+
paymentMethods: PaymentMethodsResponse;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,92 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
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;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "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 };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
collectPaymentMethod: function (paymentSessionId) { return __awaiter(_this, void 0, void 0, function () {
|
|
46
|
-
var responseListeners, response;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
responseListeners = Promise.race([
|
|
51
|
-
messenger.awaitMessage('COMPLETE'),
|
|
52
|
-
messenger.awaitMessage('ERROR'),
|
|
53
|
-
]);
|
|
54
|
-
messenger.publishMessage('SET_PAYMENT_SESSION_V1', { paymentSessionId: paymentSessionId });
|
|
55
|
-
return [4 /*yield*/, responseListeners];
|
|
56
|
-
case 1:
|
|
57
|
-
response = _a.sent();
|
|
58
|
-
if (response.type === 'COMPLETE') {
|
|
59
|
-
return [2 /*return*/, {
|
|
60
|
-
success: true,
|
|
61
|
-
paymentId: response.payload.data.paymentId,
|
|
62
|
-
}];
|
|
63
|
-
}
|
|
64
|
-
throw Error(response.payload.data.message);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}); },
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function mountLightspeedPayments(mountPoint, configuration) {
|
|
71
|
-
var _a;
|
|
72
|
-
if (configuration === void 0) { configuration = {}; }
|
|
73
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
-
var contentHostname, lspIframe, messenger, ready;
|
|
75
|
-
return __generator(this, function (_b) {
|
|
76
|
-
contentHostname = (_a = configuration === null || configuration === void 0 ? void 0 : configuration.contentHostnameOverride) !== null && _a !== void 0 ? _a : DefaultContentHostname;
|
|
77
|
-
lspIframe = window.document.createElement('iframe');
|
|
78
|
-
lspIframe.height = '800px';
|
|
79
|
-
lspIframe.width = '700px';
|
|
80
|
-
lspIframe.src = contentHostname;
|
|
81
|
-
if (!mountPoint) {
|
|
82
|
-
throw Error('HtmlElement to mount checkout to is required. Received undefined');
|
|
83
|
-
}
|
|
84
|
-
messenger = frameMessenger_1.FrameMessenger.createFrameMessenger(window, lspIframe, contentHostname);
|
|
85
|
-
ready = messenger.awaitMessage('READY');
|
|
86
|
-
mountPoint.appendChild(lspIframe);
|
|
87
|
-
// Only return the messenger once it is verified that the content within the iframe is listening
|
|
88
|
-
return [2 /*return*/, ready.then(function () { return createOnlinePaymentsInterface(messenger); })];
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
exports.mountLightspeedPayments = mountLightspeedPayments;
|
|
3
|
+
exports.LightspeedPayments = void 0;
|
|
4
|
+
var v1_1 = require("./v1");
|
|
5
|
+
exports.LightspeedPayments = {
|
|
6
|
+
v1: v1_1.v1,
|
|
7
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "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 };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AdyenWidget = exports.mapAdyenResultCode = void 0;
|
|
40
|
+
var adyen_web_1 = require("@adyen/adyen-web");
|
|
41
|
+
var errors_1 = require("./errors");
|
|
42
|
+
function mapAdyenResultCode(code) {
|
|
43
|
+
switch (code) {
|
|
44
|
+
case 'Authorised':
|
|
45
|
+
return 'Authorized';
|
|
46
|
+
case 'Refused':
|
|
47
|
+
return 'Refused';
|
|
48
|
+
default:
|
|
49
|
+
return 'Unexpected';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.mapAdyenResultCode = mapAdyenResultCode;
|
|
53
|
+
function mount(mountElement, context, listeners) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var checkoutConfig, checkout, dropinConfiguration, dropIn;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
checkoutConfig = createAdyenConfiguration(context, listeners);
|
|
60
|
+
return [4 /*yield*/, (0, adyen_web_1.AdyenCheckout)(checkoutConfig)];
|
|
61
|
+
case 1:
|
|
62
|
+
checkout = _a.sent();
|
|
63
|
+
dropinConfiguration = createDropinConfiguration();
|
|
64
|
+
dropIn = new adyen_web_1.Dropin(checkout, dropinConfiguration).mount(mountElement);
|
|
65
|
+
return [2 /*return*/, {
|
|
66
|
+
unmount: function () { return dropIn.unmount(); },
|
|
67
|
+
submit: function () {
|
|
68
|
+
return new Promise(function (resolve) {
|
|
69
|
+
dropIn.submit();
|
|
70
|
+
resolve({
|
|
71
|
+
status: 'Pending',
|
|
72
|
+
code: 'Success',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function createAdyenConfiguration(context, listeners) {
|
|
82
|
+
return {
|
|
83
|
+
clientKey: context.clientKey,
|
|
84
|
+
session: {
|
|
85
|
+
id: context.sessionId,
|
|
86
|
+
sessionData: context.sessionData,
|
|
87
|
+
},
|
|
88
|
+
countryCode: context.countryCode,
|
|
89
|
+
amount: {
|
|
90
|
+
value: context.amount,
|
|
91
|
+
currency: context.currency,
|
|
92
|
+
},
|
|
93
|
+
locale: context.locale,
|
|
94
|
+
environment: context.env,
|
|
95
|
+
analytics: {
|
|
96
|
+
enabled: false,
|
|
97
|
+
},
|
|
98
|
+
onPaymentCompleted: function (data) {
|
|
99
|
+
var _a;
|
|
100
|
+
(_a = listeners === null || listeners === void 0 ? void 0 : listeners.onComplete) === null || _a === void 0 ? void 0 : _a.call(listeners, {
|
|
101
|
+
code: mapAdyenResultCode(data.resultCode),
|
|
102
|
+
status: 'Complete',
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
onPaymentFailed: function (data) {
|
|
106
|
+
var _a;
|
|
107
|
+
(_a = listeners === null || listeners === void 0 ? void 0 : listeners.onFail) === null || _a === void 0 ? void 0 : _a.call(listeners, {
|
|
108
|
+
status: 'Complete',
|
|
109
|
+
code: mapAdyenResultCode(data.resultCode),
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
onError: function (error) {
|
|
113
|
+
throw new errors_1.PaymentProcessingError(error.message);
|
|
114
|
+
},
|
|
115
|
+
paymentMethodsResponse: context.paymentMethods,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function createDropinConfiguration() {
|
|
119
|
+
return {
|
|
120
|
+
paymentMethodComponents: [adyen_web_1.Card, adyen_web_1.GooglePay, adyen_web_1.ApplePay],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
exports.AdyenWidget = {
|
|
124
|
+
mount: mount,
|
|
125
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "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 };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.StripeWidget = exports.mount = exports.mapStripeResultCode = void 0;
|
|
40
|
+
var stripe_js_1 = require("@stripe/stripe-js");
|
|
41
|
+
function mapStripeResultCode(code) {
|
|
42
|
+
switch (code) {
|
|
43
|
+
case 'succeeded':
|
|
44
|
+
return 'Success';
|
|
45
|
+
default:
|
|
46
|
+
return 'Unexpected';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.mapStripeResultCode = mapStripeResultCode;
|
|
50
|
+
function init(context) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var publishableKey, clientSecret, customerSessionClientSecret, loadedStripe, stripe, elements;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
publishableKey = context.publishableKey, clientSecret = context.clientSecret, customerSessionClientSecret = context.customerSessionClientSecret;
|
|
57
|
+
return [4 /*yield*/, (0, stripe_js_1.loadStripe)(publishableKey)];
|
|
58
|
+
case 1:
|
|
59
|
+
loadedStripe = _a.sent();
|
|
60
|
+
if (!loadedStripe) {
|
|
61
|
+
throw new Error('Failed to initialize Stripe');
|
|
62
|
+
}
|
|
63
|
+
stripe = loadedStripe;
|
|
64
|
+
elements = stripe.elements({
|
|
65
|
+
clientSecret: clientSecret,
|
|
66
|
+
customerSessionClientSecret: customerSessionClientSecret,
|
|
67
|
+
});
|
|
68
|
+
return [2 /*return*/, { stripe: stripe, elements: elements }];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function mount(mountElement, context, listeners) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var _a, stripe, elements, paymentElement;
|
|
76
|
+
var _this = this;
|
|
77
|
+
return __generator(this, function (_b) {
|
|
78
|
+
switch (_b.label) {
|
|
79
|
+
case 0: return [4 /*yield*/, init(context)];
|
|
80
|
+
case 1:
|
|
81
|
+
_a = _b.sent(), stripe = _a.stripe, elements = _a.elements;
|
|
82
|
+
paymentElement = elements.create('payment');
|
|
83
|
+
paymentElement.update({
|
|
84
|
+
fields: {
|
|
85
|
+
billingDetails: {
|
|
86
|
+
address: {
|
|
87
|
+
postalCode: 'never',
|
|
88
|
+
country: 'never',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
paymentElement.mount(mountElement);
|
|
94
|
+
return [2 /*return*/, {
|
|
95
|
+
unmount: function () { return paymentElement.unmount(); },
|
|
96
|
+
submit: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
97
|
+
var result, _a, error, setupIntent, _b, error, paymentIntent;
|
|
98
|
+
var _c, _d;
|
|
99
|
+
return __generator(this, function (_e) {
|
|
100
|
+
switch (_e.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
result = { status: 'Pending', code: 'Unexpected' };
|
|
103
|
+
if (!(context.intent === 'save-card')) return [3 /*break*/, 2];
|
|
104
|
+
return [4 /*yield*/, stripe.confirmSetup({
|
|
105
|
+
elements: elements,
|
|
106
|
+
redirect: 'if_required',
|
|
107
|
+
confirmParams: { return_url: window.location.href },
|
|
108
|
+
})];
|
|
109
|
+
case 1:
|
|
110
|
+
_a = _e.sent(), error = _a.error, setupIntent = _a.setupIntent;
|
|
111
|
+
result = {
|
|
112
|
+
status: 'Complete',
|
|
113
|
+
code: error ? 'Failure' : mapStripeResultCode(setupIntent.status),
|
|
114
|
+
};
|
|
115
|
+
_e.label = 2;
|
|
116
|
+
case 2:
|
|
117
|
+
if (!(context.intent === 'payment')) return [3 /*break*/, 4];
|
|
118
|
+
return [4 /*yield*/, stripe.confirmPayment({
|
|
119
|
+
elements: elements,
|
|
120
|
+
redirect: 'if_required',
|
|
121
|
+
confirmParams: { return_url: window.location.href },
|
|
122
|
+
})];
|
|
123
|
+
case 3:
|
|
124
|
+
_b = _e.sent(), error = _b.error, paymentIntent = _b.paymentIntent;
|
|
125
|
+
result = {
|
|
126
|
+
status: 'Complete',
|
|
127
|
+
code: error ? 'Failure' : mapStripeResultCode(paymentIntent.status),
|
|
128
|
+
};
|
|
129
|
+
_e.label = 4;
|
|
130
|
+
case 4:
|
|
131
|
+
if (result.code === 'Failure') {
|
|
132
|
+
(_c = listeners.onFail) === null || _c === void 0 ? void 0 : _c.call(listeners, result);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
(_d = listeners.onComplete) === null || _d === void 0 ? void 0 : _d.call(listeners, result);
|
|
136
|
+
}
|
|
137
|
+
return [2 /*return*/, result];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}); },
|
|
141
|
+
}];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
exports.mount = mount;
|
|
147
|
+
exports.StripeWidget = {
|
|
148
|
+
mount: mount,
|
|
149
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Entry point for version 1 of the LSP Online Payments SDK.
|
|
4
|
+
* This module exports the necessary functions and types for mounting the payment widget
|
|
5
|
+
* and handling errors related to payment sessions.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.v1 = exports.InvalidSessionError = exports.UnsupportedLocationError = exports.InvalidSessionStructureError = void 0;
|
|
9
|
+
var widget_1 = require("./widget");
|
|
10
|
+
var errors_1 = require("./errors");
|
|
11
|
+
Object.defineProperty(exports, "InvalidSessionStructureError", { enumerable: true, get: function () { return errors_1.InvalidSessionStructureError; } });
|
|
12
|
+
Object.defineProperty(exports, "UnsupportedLocationError", { enumerable: true, get: function () { return errors_1.UnsupportedLocationError; } });
|
|
13
|
+
Object.defineProperty(exports, "InvalidSessionError", { enumerable: true, get: function () { return errors_1.InvalidSessionError; } });
|
|
14
|
+
exports.v1 = {
|
|
15
|
+
mountPaymentWidget: widget_1.mountPaymentWidget,
|
|
16
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTokenValid = exports.decodePaymentSessionToContext = exports.mountPaymentWidget = void 0;
|
|
4
|
+
var AdyenWidget_1 = require("./AdyenWidget");
|
|
5
|
+
var errors_1 = require("./errors");
|
|
6
|
+
var StripeWidget_1 = require("./StripeWidget");
|
|
7
|
+
function mountPaymentWidget(session, _a) {
|
|
8
|
+
var mountPoint = _a.mountPoint, onComplete = _a.onComplete, onFail = _a.onFail;
|
|
9
|
+
var decodedSession = decodePaymentSessionToContext(session);
|
|
10
|
+
switch (decodedSession.psp) {
|
|
11
|
+
case 'ADYEN':
|
|
12
|
+
return AdyenWidget_1.AdyenWidget.mount(mountPoint, decodedSession.context, {
|
|
13
|
+
onComplete: onComplete,
|
|
14
|
+
onFail: onFail,
|
|
15
|
+
});
|
|
16
|
+
case 'STRIPE':
|
|
17
|
+
return StripeWidget_1.StripeWidget.mount(mountPoint, decodedSession.context, {
|
|
18
|
+
onComplete: onComplete,
|
|
19
|
+
onFail: onFail,
|
|
20
|
+
});
|
|
21
|
+
default:
|
|
22
|
+
throw new errors_1.UnsupportedLocationError();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.mountPaymentWidget = mountPaymentWidget;
|
|
26
|
+
function decodePaymentSessionToContext(paymentSession) {
|
|
27
|
+
try {
|
|
28
|
+
var decoded = atob(paymentSession);
|
|
29
|
+
var jsonToken = JSON.parse(decoded);
|
|
30
|
+
if (jsonToken && isTokenValid(jsonToken)) {
|
|
31
|
+
return jsonToken;
|
|
32
|
+
}
|
|
33
|
+
throw new errors_1.InvalidSessionStructureError();
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new errors_1.InvalidSessionError();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.decodePaymentSessionToContext = decodePaymentSessionToContext;
|
|
40
|
+
function isTokenValid(token) {
|
|
41
|
+
var t = token;
|
|
42
|
+
if (t && !!t.psp && !!t.context) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
exports.isTokenValid = isTokenValid;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
1
|
+
export type * from './v1';
|
|
2
|
+
export declare const LightspeedPayments: {
|
|
3
|
+
v1: import("./v1").LightspeedPaymentsV1;
|
|
3
4
|
};
|
|
4
|
-
export type CollectPaymentMethodResponse = {
|
|
5
|
-
success: true;
|
|
6
|
-
paymentId: string;
|
|
7
|
-
};
|
|
8
|
-
export type OnlinePaymentsInterface = {
|
|
9
|
-
collectPaymentMethod(paymentSessionId: string): Promise<CollectPaymentMethodResponse>;
|
|
10
|
-
};
|
|
11
|
-
export declare function mountLightspeedPayments(mountPoint: HTMLElement, configuration?: Configuration): Promise<OnlinePaymentsInterface>;
|