@alipay/ams-checkout 0.0.1700804278-dev.1 → 0.0.1701393225-dev.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.
@@ -0,0 +1,314 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
15
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
23
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
24
+ /**
25
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
26
+ *
27
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
28
+ * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
29
+ * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
30
+ */
31
+ import { componentSignEnum, eventCodeEnum, productSceneEnum } from "../../types";
32
+ import ApplePayService from "../../common/applepay";
33
+ import { getComponentSign, parseSessionData } from "../component";
34
+ import { getApplePayPaymentSession, submitPayInfo } from "../../service";
35
+ import CoreInstance from "../instance";
36
+ import { ERRORMESSAGE, EVENT } from "../../constant";
37
+ /**
38
+ * Apple pay Component
39
+ */
40
+ var ApplePayComponent = /*#__PURE__*/function (_CoreInstance) {
41
+ _inherits(ApplePayComponent, _CoreInstance);
42
+ var _super = _createSuper(ApplePayComponent);
43
+ function ApplePayComponent(options) {
44
+ var _this;
45
+ _classCallCheck(this, ApplePayComponent);
46
+ var _options = Object.assign({}, options, {
47
+ product: productSceneEnum.CARD_APPLE_PAY
48
+ });
49
+ _this = _super.call(this, _options);
50
+ _defineProperty(_assertThisInitialized(_this), "_applePayService", void 0);
51
+ _defineProperty(_assertThisInitialized(_this), "_parseData", void 0);
52
+ _defineProperty(_assertThisInitialized(_this), "_sessionData", void 0);
53
+ _this._applePayService = new ApplePayService();
54
+ return _this;
55
+ }
56
+ _createClass(ApplePayComponent, [{
57
+ key: "getDeviceIdAndLog",
58
+ value: function getDeviceIdAndLog() {
59
+ var _this2 = this;
60
+ var deviceIdParameter = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
61
+ var isPolling = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
62
+ return new Promise(function (resolve) {
63
+ // To avoid rendering being blocked, move the logic to the next event loop for processing
64
+ setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
65
+ var _this2$_parseData;
66
+ var productScene, getDeviceIdStartTime, securitySDK, deviceId;
67
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
68
+ while (1) switch (_context.prev = _context.next) {
69
+ case 0:
70
+ productScene = (_this2$_parseData = _this2._parseData) === null || _this2$_parseData === void 0 || (_this2$_parseData = _this2$_parseData.paymentSessionConfig) === null || _this2$_parseData === void 0 ? void 0 : _this2$_parseData.productScene;
71
+ getDeviceIdStartTime = Date.now();
72
+ securitySDK = _this2._getSecuritySDKByProductScene({
73
+ product: (deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.productScene) || productScene
74
+ });
75
+ deviceId = '';
76
+ if (!securitySDK) {
77
+ _context.next = 16;
78
+ break;
79
+ }
80
+ if (!(isPolling && parseInt(deviceIdParameter === null || deviceIdParameter === void 0 ? void 0 : deviceIdParameter.tokenCollectTime) > 0)) {
81
+ _context.next = 11;
82
+ break;
83
+ }
84
+ _context.next = 8;
85
+ return securitySDK.pollingGetApdidToken(deviceIdParameter);
86
+ case 8:
87
+ _context.t0 = _context.sent;
88
+ _context.next = 14;
89
+ break;
90
+ case 11:
91
+ _context.next = 13;
92
+ return securitySDK.getApdidToken();
93
+ case 13:
94
+ _context.t0 = _context.sent;
95
+ case 14:
96
+ deviceId = _context.t0;
97
+ _this2.logDeviceId(deviceId, getDeviceIdStartTime);
98
+ case 16:
99
+ resolve(deviceId);
100
+ case 17:
101
+ case "end":
102
+ return _context.stop();
103
+ }
104
+ }, _callee);
105
+ })), 0);
106
+ });
107
+ }
108
+ }, {
109
+ key: "logDeviceId",
110
+ value: function logDeviceId(deviceId, getDeviceIdStartTime) {
111
+ var time = "".concat(Date.now() - getDeviceIdStartTime);
112
+ if (deviceId) {
113
+ this.logger.logInfo({
114
+ title: 'sdk_event_securitySdkGetTokenSuccess'
115
+ }, {
116
+ deviceId: deviceId,
117
+ time: time
118
+ }).send();
119
+ } else {
120
+ this.logger.logInfo({
121
+ title: 'sdk_error_securitySdkGetTokenFailed'
122
+ }, {
123
+ deviceId: deviceId,
124
+ time: time
125
+ }).send();
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Is Apple Pay Enabled
131
+ */
132
+ }, {
133
+ key: "isAppPayEnabled",
134
+ value: function isAppPayEnabled() {
135
+ return this._applePayService.isEnabled();
136
+ }
137
+
138
+ /**
139
+ * Submit Pay
140
+ * @param paymentSessionData
141
+ */
142
+ }, {
143
+ key: "submitPay",
144
+ value: function submitPay(paymentSessionData) {
145
+ var _this3 = this;
146
+ // parse session Data
147
+ var _parseSessionData = parseSessionData(paymentSessionData),
148
+ _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
149
+ parseData = _parseSessionData2[0],
150
+ sessionData = _parseSessionData2[1];
151
+ this._parseData = parseData;
152
+ this._sessionData = sessionData;
153
+ // validate parse data
154
+ var componentSign = getComponentSign(parseData);
155
+ if (componentSign === componentSignEnum.NONE) {
156
+ // eslint-disable-next-line prefer-promise-reject-errors
157
+ return Promise.reject({
158
+ code: ERRORMESSAGE.CREATEPAYMENT_PARAMETER_ERROR.code,
159
+ message: "Abnormal response data, interface failure, or unsupported payment method"
160
+ });
161
+ }
162
+ /**
163
+ * Get MerchantSession spi
164
+ * @param event
165
+ */
166
+ var getMerchantSession = /*#__PURE__*/function () {
167
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
168
+ var validationUrl, requestParams;
169
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
170
+ while (1) switch (_context2.prev = _context2.next) {
171
+ case 0:
172
+ validationUrl = _ref2.validationUrl;
173
+ // get validateUrl
174
+ requestParams = {
175
+ validateUrl: validationUrl
176
+ };
177
+ console.log('getMerchantSession validationUrl', validationUrl);
178
+ console.log('getMerchantSession _sessionData', _this3._sessionData);
179
+
180
+ // get deviceId
181
+ _context2.t0 = getApplePayPaymentSession;
182
+ _context2.t1 = _this3._sessionData;
183
+ _context2.t2 = requestParams;
184
+ _context2.t3 = _this3.options.env.environment;
185
+ _context2.next = 10;
186
+ return _this3.getDeviceIdAndLog();
187
+ case 10:
188
+ _context2.t4 = _context2.sent;
189
+ _context2.t5 = {
190
+ deviceId: _context2.t4
191
+ };
192
+ _context2.t6 = {
193
+ env: _context2.t3,
194
+ envInfo: _context2.t5
195
+ };
196
+ _context2.t7 = _this3.logger;
197
+ return _context2.abrupt("return", (0, _context2.t0)(_context2.t1, _context2.t2, _context2.t6, _context2.t7).then(function (res) {
198
+ if (res !== null && res !== void 0 && res.success && res.merchantSessionObject) {
199
+ Promise.resolve(res.merchantSessionObject);
200
+ return;
201
+ }
202
+ Promise.reject({
203
+ errorCode: res.errorCode,
204
+ errorMessage: res.errorMessage
205
+ });
206
+ }).catch(function (error) {
207
+ Promise.reject(error);
208
+ }));
209
+ case 15:
210
+ case "end":
211
+ return _context2.stop();
212
+ }
213
+ }, _callee2);
214
+ }));
215
+ return function getMerchantSession(_x) {
216
+ return _ref3.apply(this, arguments);
217
+ };
218
+ }();
219
+
220
+ /**
221
+ * Complete Payment Authorized spi
222
+ * @param tokens
223
+ */
224
+ var completePaymentAuthorized = /*#__PURE__*/function () {
225
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
226
+ var paymentToken, params;
227
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
228
+ while (1) switch (_context3.prev = _context3.next) {
229
+ case 0:
230
+ paymentToken = _ref4.paymentToken;
231
+ params = {
232
+ paymentFactors: {
233
+ instPaymentToken: paymentToken
234
+ },
235
+ paymentSessionData: _this3._sessionData
236
+ };
237
+ _context3.t0 = submitPayInfo;
238
+ _context3.t1 = params;
239
+ _context3.t2 = _this3.options.env.environment;
240
+ _context3.next = 7;
241
+ return _this3.getDeviceIdAndLog();
242
+ case 7:
243
+ _context3.t3 = _context3.sent;
244
+ _context3.t4 = {
245
+ deviceId: _context3.t3
246
+ };
247
+ _context3.t5 = {
248
+ env: _context3.t2,
249
+ envInfo: _context3.t4
250
+ };
251
+ _context3.t6 = _this3.logger;
252
+ return _context3.abrupt("return", (0, _context3.t0)(_context3.t1, _context3.t5, _context3.t6).then(function (res) {
253
+ if (res !== null && res !== void 0 && res.success) {
254
+ Promise.resolve(res);
255
+ return;
256
+ }
257
+ Promise.reject({
258
+ errorCode: res.errorCode,
259
+ errorMessage: res.errorMessage
260
+ });
261
+ }).catch(function (error) {
262
+ Promise.resolve(error);
263
+ }));
264
+ case 12:
265
+ case "end":
266
+ return _context3.stop();
267
+ }
268
+ }, _callee3);
269
+ }));
270
+ return function completePaymentAuthorized(_x2) {
271
+ return _ref5.apply(this, arguments);
272
+ };
273
+ }();
274
+ var completeApplePay = function completeApplePay(data) {
275
+ var _data$actionForm;
276
+ // TODO 处理redirectUrl
277
+ _this3._eventCenter.emit(EVENT.eventCallback.name, {
278
+ code: eventCodeEnum.SDK_PAYMENT_FINISH,
279
+ result: {
280
+ redirectUrl: (data === null || data === void 0 || (_data$actionForm = data.actionForm) === null || _data$actionForm === void 0 ? void 0 : _data$actionForm.redirectUrl) || ''
281
+ }
282
+ });
283
+ };
284
+ var logError = function logError(msg, error) {
285
+ // TODO 回抛错误给商户
286
+ console.error('msg', msg, error);
287
+ // this._eventCenter.emit(EVENT.error.name, error);
288
+ _this3._eventCenter.emit(EVENT.eventCallback.name, {
289
+ code: eventCodeEnum.SDK_PAYMENT_FAIL,
290
+ result: {
291
+ errorMsg: msg
292
+ }
293
+ });
294
+ };
295
+ var applePayTrace = function applePayTrace(msg) {
296
+ // TODO 记录日志
297
+ console.error('msg', msg);
298
+ _this3.logger.logInfo({
299
+ title: 'APPLE_PAY'
300
+ }, {
301
+ msg: msg
302
+ }).send();
303
+ };
304
+
305
+ // set Apple Pay params
306
+ this._applePayService.setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError, applePayTrace);
307
+
308
+ // init Apple Pay service
309
+ this._applePayService.startPay(this._parseData);
310
+ }
311
+ }]);
312
+ return ApplePayComponent;
313
+ }(CoreInstance);
314
+ export default ApplePayComponent;
@@ -1,6 +1,8 @@
1
1
  import ComponentApp from '../../plugin/component';
2
- import { IcreateComponent, IoptionsParams, Iselector, Isubmit } from '../../types';
2
+ import { componentSignEnum, IcreateComponent, IoptionsParams, IpaymentSessionMetaData, Iselector, Isubmit } from '../../types';
3
3
  import CoreInstance from '../instance/index';
4
+ export declare const getComponentSign: (params: IpaymentSessionMetaData) => componentSignEnum;
5
+ export declare const parseSessionData: (sessionData: string) => [IpaymentSessionMetaData, string];
4
6
  export declare class AMSComponent extends CoreInstance {
5
7
  _componentApp: ComponentApp;
6
8
  constructor(options: IoptionsParams);
@@ -13,12 +15,14 @@ export declare class AMSComponent extends CoreInstance {
13
15
  createComponent(params: IcreateComponent): Promise<void>;
14
16
  /**
15
17
  * @description Create and render components in the specified element area
16
- * @param params - The data source created by the component, necessary sessionData, necessary element selector IDs, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
18
+ * @param params - The data source created by the component, necessary sessionData, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
19
+ * @param selector - Necessary element selector ID
17
20
  */
18
21
  mountComponent(params: IcreateComponent, selector: Iselector): Promise<void>;
19
22
  /**
20
23
  * @description Execute payment submission process
21
24
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
25
+ * @param data - Transfer information in the submission interface according to your requirements (optional)
22
26
  */
23
27
  submit(data?: Isubmit): Promise<unknown>;
24
28
  }
@@ -29,10 +29,11 @@ import { v4 as uuid } from 'uuid';
29
29
  import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
30
30
  import ComponentApp from "../../plugin/component";
31
31
  import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
32
- import { isPC } from "../../util";
32
+ import { getOrSetStorageId, isPC } from "../../util";
33
33
  import { createIframeNode } from "../../util/createIframeNode";
34
+ import { getSecurityConfigStorageKey } from "../../util/security";
34
35
  import CoreInstance from "../instance/index";
35
- var getComponentSign = function getComponentSign(params) {
36
+ export var getComponentSign = function getComponentSign(params) {
36
37
  var _params$paymentSessio = params.paymentSessionConfig,
37
38
  _params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
38
39
  _params$paymentSessio3 = _params$paymentSessio2.productScene,
@@ -41,7 +42,7 @@ var getComponentSign = function getComponentSign(params) {
41
42
  paymentMethodCategoryType = _params$paymentSessio4 === void 0 ? '' : _params$paymentSessio4;
42
43
  return productScene && paymentMethodCategoryType ? "".concat(productScene, "_").concat(paymentMethodCategoryType) : componentSignEnum.NONE;
43
44
  };
44
- var parseSessionData = function parseSessionData(sessionData) {
45
+ export var parseSessionData = function parseSessionData(sessionData) {
45
46
  try {
46
47
  return [JSON.parse(atob(sessionData.split('&&')[3])), sessionData.split('&&').slice(0, 3).join('&&')];
47
48
  } catch (error) {
@@ -84,6 +85,11 @@ var handleParams = function handleParams(params) {
84
85
  message: "Abnormal response data, interface failure, or unsupported payment method"
85
86
  });
86
87
  }
88
+ if (parseData && parseData !== null && parseData !== void 0 && parseData.securityConfig) {
89
+ var _parseData$paymentSes;
90
+ var product = parseData === null || parseData === void 0 || (_parseData$paymentSes = parseData.paymentSessionConfig) === null || _parseData$paymentSes === void 0 ? void 0 : _parseData$paymentSes.productScene;
91
+ getOrSetStorageId(getSecurityConfigStorageKey(product), JSON.stringify(parseData === null || parseData === void 0 ? void 0 : parseData.securityConfig));
92
+ }
87
93
  _params.sessionData = sessionData;
88
94
  _params.paymentSessionMetaData = parseData;
89
95
  return Promise.resolve({
@@ -140,7 +146,6 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
140
146
  return Promise.reject(error);
141
147
  }
142
148
  }
143
-
144
149
  /**
145
150
  * @description Create component application
146
151
  * @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
@@ -158,12 +163,23 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
158
163
  _this2._eventCenter.emit(EVENT.error.name, error);
159
164
  return Promise.reject(error);
160
165
  }).then(function (appendParams) {
166
+ var _appendParams$iframeN, _appendParams$iframeN2;
167
+ // This version, easypay2.0 only supports alipayhk
168
+ var productSceneVersion = appendParams === null || appendParams === void 0 || (_appendParams$iframeN = appendParams.iframeNodesParams) === null || _appendParams$iframeN === void 0 || (_appendParams$iframeN = _appendParams$iframeN.paymentSessionMetaData) === null || _appendParams$iframeN === void 0 || (_appendParams$iframeN = _appendParams$iframeN.paymentSessionConfig) === null || _appendParams$iframeN === void 0 ? void 0 : _appendParams$iframeN.productSceneVersion;
169
+ var paymentMethodType = appendParams === null || appendParams === void 0 || (_appendParams$iframeN2 = appendParams.iframeNodesParams) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentSessionMetaData) === null || _appendParams$iframeN2 === void 0 || (_appendParams$iframeN2 = _appendParams$iframeN2.paymentMethodInfoView) === null || _appendParams$iframeN2 === void 0 ? void 0 : _appendParams$iframeN2.paymentMethodType;
170
+ if ((appendParams === null || appendParams === void 0 ? void 0 : appendParams.componentSign) === componentSignEnum.EASY_PAY_WALLET && productSceneVersion === '2.0' && paymentMethodType !== 'ALIPAY_HK') {
171
+ return Promise.reject({
172
+ code: ERRORMESSAGE.CREATEPAYMENT_PARAMETER_ERROR.code,
173
+ message: "Abnormal response data, interface failure, or unsupported payment method"
174
+ });
175
+ }
161
176
  return _this2.pluginAppendIframe(appendParams);
162
177
  });
163
178
  }
164
179
  /**
165
180
  * @description Create and render components in the specified element area
166
- * @param params - The data source created by the component, necessary sessionData, necessary element selector IDs, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
181
+ * @param params - The data source created by the component, necessary sessionData, optional appearance configurations, and refer to the documentation for other parameters and detailed information.
182
+ * @param selector - Necessary element selector ID
167
183
  */
168
184
  }, {
169
185
  key: "mountComponent",
@@ -185,6 +201,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
185
201
  /**
186
202
  * @description Execute payment submission process
187
203
  * @description - When using your own payment button, you can execute the submit payment process by actively calling this function.
204
+ * @param data - Transfer information in the submission interface according to your requirements (optional)
188
205
  */
189
206
  }, {
190
207
  key: "submit",
@@ -1,28 +1,41 @@
1
- import { Logger } from '../../util/logger';
2
- import type { AMSCheckoutOptions, IcheckoutState, IoptionsParams, IsecurityConfig } from '../../types/index';
1
+ import type { AMSCheckoutOptions, InitSecurityConfig, IoptionsParams } from '../../types/index';
3
2
  import { EventCenter } from '../../util/index';
3
+ import { Logger } from '../../util/logger';
4
+ import { Security } from '../../util/security';
4
5
  export default class AMSSDK {
5
6
  options: AMSCheckoutOptions;
6
- checkoutState: IcheckoutState;
7
- securityConfig: IsecurityConfig;
7
+ logger: Logger;
8
8
  _eventCenter: EventCenter;
9
- protected plugins: Map<string, any>;
10
9
  _instanceId: string;
11
10
  _storageId: string;
12
- logger: Logger;
11
+ protected securitySdkMap: Map<string, Security>;
12
+ protected plugins: Map<string, any>;
13
13
  constructor(options: IoptionsParams);
14
+ private preInitSecurity;
14
15
  /**
15
16
  * @description Destroy and process some contents of the plug-in
16
17
  */
17
18
  unmount(): void;
18
19
  /**
19
- * @description set STORAGE_ID for a user session
20
+ * @description init security SDK
21
+ * @param product Product Scenarios
22
+ * @param scene Scenario of the product (compatible with old version parameters, about to be deleted)
23
+ */
24
+ initSecurity({ product, scene, }: InitSecurityConfig & {
25
+ scene?: string;
26
+ }): void;
27
+ /**
28
+ * @description Obtain security SDK through scenario identification
29
+ */
30
+ _getSecuritySDKByProductScene(securityConfig: InitSecurityConfig): Security;
31
+ /**
32
+ * @description New security SDK through scenario identification
20
33
  */
21
- getStorageId(instanceId: string): any;
34
+ _newSecuritySDKByScene(securityConfig: InitSecurityConfig, successCallback?: () => void, failCallback?: (errMsg?: string) => void): Security;
22
35
  /**
23
- * @description init initSecurity SDK
36
+ * @description Obtain risk control configuration in local storage
24
37
  */
25
- initSecurity(securityConfig: IsecurityConfig): void;
38
+ private getSecurityConfigStorage;
26
39
  /**
27
40
  * @description Set the sdk basic configuration
28
41
  */