@alipay/ams-checkout 0.0.1742382470-dev.4 → 0.0.1743078169-dev.1

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.
Files changed (56) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/component/component.inline.style.js +1 -1
  3. package/esm/component/popupWindow.style.js +4 -1
  4. package/esm/constant/index.d.ts +3 -0
  5. package/esm/constant/index.js +3 -0
  6. package/esm/core/component/element/elementContainerService/containerService.d.ts +29 -0
  7. package/esm/core/component/element/elementContainerService/containerService.js +101 -0
  8. package/esm/core/component/element/elementContainerService/index.d.ts +19 -0
  9. package/esm/core/component/element/elementContainerService/index.js +55 -0
  10. package/esm/core/component/element/elementController/index.d.ts +22 -0
  11. package/esm/core/component/element/elementController/index.js +357 -0
  12. package/esm/core/component/element/elementProcessor/addressProcessor.d.ts +17 -0
  13. package/esm/core/component/element/elementProcessor/addressProcessor.js +122 -0
  14. package/esm/core/component/element/elementProcessor/authProcessor.d.ts +14 -0
  15. package/esm/core/component/element/elementProcessor/authProcessor.js +70 -0
  16. package/esm/core/component/element/elementProcessor/baseElementProcessor.d.ts +36 -0
  17. package/esm/core/component/element/elementProcessor/baseElementProcessor.js +79 -0
  18. package/esm/core/component/element/elementProcessor/paymentProcessor.d.ts +17 -0
  19. package/esm/core/component/element/elementProcessor/paymentProcessor.js +178 -0
  20. package/esm/core/component/element/index.d.ts +8 -46
  21. package/esm/core/component/element/index.js +28 -922
  22. package/esm/core/component/element/type.d.ts +29 -1
  23. package/esm/core/component/element/util.d.ts +58 -0
  24. package/esm/core/component/element/util.js +321 -0
  25. package/esm/core/component/index.d.ts +5 -1
  26. package/esm/core/component/index.js +1 -2
  27. package/esm/core/component/oldElement/index.d.ts +59 -0
  28. package/esm/core/component/oldElement/index.js +956 -0
  29. package/esm/core/component/oldElement/type.d.ts +351 -0
  30. package/esm/core/component/oldElement/type.js +81 -0
  31. package/esm/foundation/core/index.d.ts +5 -1
  32. package/esm/foundation/core/index.js +52 -30
  33. package/esm/foundation/index.d.ts +7 -0
  34. package/esm/foundation/index.js +10 -2
  35. package/esm/foundation/product-processor/element/index.d.ts +7 -0
  36. package/esm/foundation/product-processor/element/index.js +24 -0
  37. package/esm/foundation/service/container/index.d.ts +6 -3
  38. package/esm/foundation/service/container/index.js +19 -7
  39. package/esm/foundation/service/container/popup.d.ts +1 -1
  40. package/esm/foundation/service/event-center.js +1 -0
  41. package/esm/index.js +1 -0
  42. package/esm/plugin/component/cashierApp.d.ts +1 -1
  43. package/esm/plugin/component/index.js +1 -1
  44. package/esm/types/index.d.ts +1 -1
  45. package/esm/types/index.js +1 -1
  46. package/package.json +1 -1
  47. /package/esm/core/component/{element → oldElement}/components/address.d.ts +0 -0
  48. /package/esm/core/component/{element → oldElement}/components/address.js +0 -0
  49. /package/esm/core/component/{element → oldElement}/components/auth.d.ts +0 -0
  50. /package/esm/core/component/{element → oldElement}/components/auth.js +0 -0
  51. /package/esm/core/component/{element → oldElement}/components/payment.d.ts +0 -0
  52. /package/esm/core/component/{element → oldElement}/components/payment.js +0 -0
  53. /package/esm/core/component/{element → oldElement}/mock.d.ts +0 -0
  54. /package/esm/core/component/{element → oldElement}/mock.js +0 -0
  55. /package/esm/core/component/{element → oldElement}/utils.d.ts +0 -0
  56. /package/esm/core/component/{element → oldElement}/utils.js +0 -0
@@ -0,0 +1,956 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ 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); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ 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; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
19
+ import PackageJson from "../../../../package.json";
20
+ import { AntomSDKCore } from "../../../foundation/core";
21
+ import { ServiceProvider } from "../../../foundation/service";
22
+ import { EVENT as ConstantEvent } from "../../../constant";
23
+ import { ProductSceneEnum } from "../../../types";
24
+ import { parseSessionData } from "../index";
25
+ import { ElementAddressComponent } from "./components/address";
26
+ import { ElementAuthComponent } from "./components/auth";
27
+ import { ElementPaymentComponent } from "./components/payment";
28
+ // import { oneAccount, sdkAction, submitResult } from './mock';
29
+ import { ApplePaySdk, isSkipRenderPaymentMethod } from "../../../plugin/component/channel";
30
+ import { v4 as uuid } from 'uuid';
31
+ import { destroyModal } from "../../../plugin/component/popupWindow.style";
32
+ import { LogConfig, Logger } from "../../../util/logger";
33
+ import { addressTheme, ElementPaymentEvent, ElementPaymentMethod, ElementType, ELEMENT_ENVIRONMENT, EventCallbackCode, MountElementType, ThemeType } from "./type";
34
+ var logger = new Logger(LogConfig, true);
35
+ var ElementProcessor = /*#__PURE__*/function () {
36
+ function ElementProcessor(options) {
37
+ _classCallCheck(this, ElementProcessor);
38
+ _defineProperty(this, "requestService", void 0);
39
+ // 接口服务
40
+ _defineProperty(this, "_options", void 0);
41
+ this._options = options;
42
+ }
43
+ _createClass(ElementProcessor, [{
44
+ key: "init",
45
+ value: function init(config, instanceId) {
46
+ this.requestService = ServiceProvider.getInstance(instanceId).getService('Requester');
47
+ }
48
+ }, {
49
+ key: "sdkActionQuery",
50
+ value: function sdkActionQuery() {
51
+ var _this = this;
52
+ return new Promise(function (resolve, reject) {
53
+ // setTimeout(() => {
54
+ // resolve(sdkAction)
55
+ // }, 2000);
56
+ // return;
57
+ var hostSign = _this._options.sessionData.split('&&')[1] || '';
58
+ _this.requestService.request({
59
+ paymentSessionConfig: _this._options.paymentSessionConfig,
60
+ paymentSessionData: _this._options.sessionData
61
+ }, {
62
+ env: _this._options.environment,
63
+ envInfo: {
64
+ locale: _this._options.locale
65
+ },
66
+ hostSign: hostSign,
67
+ timeout: 300000,
68
+ // TODO dev环境接口超时
69
+ 'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
70
+ }).then(function (result) {
71
+ if (!result.success) {
72
+ reject('sdk.action.query Request Error');
73
+ }
74
+ resolve(result);
75
+ }, function () {
76
+ reject('sdk.action.query Request Error');
77
+ });
78
+ });
79
+ }
80
+ }, {
81
+ key: "oneAccountQuery",
82
+ value: function oneAccountQuery() {
83
+ var _this2 = this;
84
+ return new Promise(function (resolve, reject) {
85
+ // setTimeout(() => {
86
+ // resolve(oneAccount)
87
+ // }, 2000);
88
+ // return;
89
+ _this2.requestService.request({
90
+ paymentSessionConfig: _this2._options.paymentSessionConfig,
91
+ paymentSessionData: _this2._options.sessionData,
92
+ accountInfo: {
93
+ email: ''
94
+ }
95
+ }, {
96
+ env: _this2._options.environment,
97
+ envInfo: {
98
+ locale: _this2._options.locale
99
+ },
100
+ timeout: 300000,
101
+ // TODO dev环境接口超时
102
+ 'Operation-Type': 'com.ipay.iexpfront.one.account.query'
103
+ }).then(function (result) {
104
+ resolve(result);
105
+ }, function () {
106
+ reject('one.account.query Request Error');
107
+ });
108
+ });
109
+ }
110
+ }, {
111
+ key: "startBizFlow",
112
+ value: function startBizFlow() {
113
+ var _this3 = this;
114
+ return new Promise(function (resolve) {
115
+ if (_this3._options.isConnect) {
116
+ Promise.all([_this3.oneAccountQuery(), _this3.sdkActionQuery()]).then(function (result) {
117
+ resolve({
118
+ behaviorType: 'NONE',
119
+ payload: {},
120
+ data: {
121
+ success: true,
122
+ oneAccountRes: result[0],
123
+ sdkActionRes: result[1]
124
+ }
125
+ });
126
+ }, function (error) {
127
+ resolve({
128
+ behaviorType: 'NONE',
129
+ payload: {},
130
+ data: {
131
+ success: false,
132
+ errorMsg: error
133
+ }
134
+ });
135
+ });
136
+ } else {
137
+ resolve({
138
+ behaviorType: 'NONE',
139
+ payload: {},
140
+ data: {
141
+ success: true
142
+ }
143
+ });
144
+ }
145
+ });
146
+ }
147
+ }]);
148
+ return ElementProcessor;
149
+ }();
150
+ export var ElementComponent = /*#__PURE__*/function () {
151
+ function ElementComponent(options) {
152
+ var _this4 = this;
153
+ _classCallCheck(this, ElementComponent);
154
+ _defineProperty(this, "parseData", void 0);
155
+ // sessionData 解析出来的数据
156
+ _defineProperty(this, "loading", void 0);
157
+ // element loading
158
+ _defineProperty(this, "sessionData", void 0);
159
+ // sessionData 解析出来的数据
160
+ _defineProperty(this, "elementContainer", void 0);
161
+ // element
162
+ _defineProperty(this, "authBase", void 0);
163
+ // auth element
164
+ _defineProperty(this, "addressBase", void 0);
165
+ // address element
166
+ _defineProperty(this, "paymentBase", void 0);
167
+ // payment element
168
+ _defineProperty(this, "_options", void 0);
169
+ // element 入参
170
+ _defineProperty(this, "eventService", void 0);
171
+ // 消息服务
172
+ // private requestService: RequesterService; // 接口服务 一期connect功能,目前已都放入到应用层
173
+ _defineProperty(this, "sdkActionRes", void 0);
174
+ // sdk aciton接口返回
175
+ _defineProperty(this, "oneAccountRes", void 0);
176
+ // one account接口返回
177
+ _defineProperty(this, "launchSource", void 0);
178
+ // launch 来源记录
179
+ _defineProperty(this, "initCompleted", void 0);
180
+ // init完成
181
+ _defineProperty(this, "isConnect", void 0);
182
+ // 当前sessionData是否connect模式
183
+ _defineProperty(this, "iframeSrc", void 0);
184
+ // iframe src记录
185
+ _defineProperty(this, "mountOptions", void 0);
186
+ // 组件mount配置记录
187
+ _defineProperty(this, "iframes", void 0);
188
+ // iframs合集
189
+ _defineProperty(this, "loadingElement", []);
190
+ // 当前加载中的element
191
+ _defineProperty(this, "componentsCount", void 0);
192
+ // mount 渲染了多少个element
193
+ _defineProperty(this, "eventCallback", void 0);
194
+ // address事件回调
195
+ // apple pay
196
+ _defineProperty(this, "ApplePayService", void 0);
197
+ // 渲染地址组件
198
+ _defineProperty(this, "mountAddress", function (renderOptions, sdkSelector) {
199
+ var _renderOptions$appear, _this4$_options;
200
+ var _mountParams = {
201
+ appearance: {
202
+ themeType: addressTheme[(renderOptions === null || renderOptions === void 0 || (_renderOptions$appear = renderOptions.appearance) === null || _renderOptions$appear === void 0 ? void 0 : _renderOptions$appear.theme) || ((_this4$_options = _this4._options) === null || _this4$_options === void 0 || (_this4$_options = _this4$_options.appearance) === null || _this4$_options === void 0 ? void 0 : _this4$_options.theme) || ThemeType.Default]
203
+ },
204
+ configParams: _objectSpread({
205
+ needEditBackBtn: _this4.isConnect,
206
+ autoSaveAsDefaultAddress: _this4.isConnect,
207
+ editingNeedShippingQuery: _this4.isConnect,
208
+ showTitle: _this4.isConnect
209
+ }, renderOptions.configParams),
210
+ prefillValue: renderOptions.prefillValue
211
+ };
212
+ _this4.mountOptions[ElementPaymentMethod.ADDRESS_ELEMENT] = _mountParams;
213
+ _this4.addressBase.mount(_objectSpread({
214
+ selector: sdkSelector,
215
+ elementProps: renderOptions.elementProps,
216
+ sessionData: renderOptions.sessionData
217
+ }, _mountParams)).then(function (result) {
218
+ if (!result) {
219
+ return _this4.mountErrorHandle();
220
+ }
221
+ _this4.eventService.addIFrame(result);
222
+ _this4.iframes[ElementPaymentMethod.ADDRESS_ELEMENT] = result;
223
+ });
224
+ return {
225
+ on: function on(event, callback) {
226
+ _this4.registerEventListener(ElementPaymentMethod.ADDRESS_ELEMENT, event, callback);
227
+ }
228
+ };
229
+ });
230
+ // 渲染卡支付组件
231
+ _defineProperty(this, "mountPayment", function (renderOptions, sdkSelector) {
232
+ var _this4$_options2;
233
+ var _mountParams = {
234
+ appearance: renderOptions.appearance || ((_this4$_options2 = _this4._options) === null || _this4$_options2 === void 0 ? void 0 : _this4$_options2.appearance) || {
235
+ theme: ThemeType.Default
236
+ }
237
+ };
238
+ _this4.mountOptions[ElementPaymentMethod.PAYMENT_ELEMENT] = _mountParams;
239
+ _this4.initApplePaySdk();
240
+ _this4.paymentBase.mount(_objectSpread({
241
+ selector: sdkSelector,
242
+ sessionData: renderOptions.sessionData,
243
+ elementProps: renderOptions.elementProps
244
+ }, _mountParams)).then(function (result) {
245
+ if (!result) {
246
+ return _this4.mountErrorHandle();
247
+ }
248
+ _this4.eventService.addIFrame(result);
249
+ _this4.iframes[ElementPaymentMethod.PAYMENT_ELEMENT] = result;
250
+ });
251
+ return {};
252
+ });
253
+ // submit提交非RISK_REJECT错误 一期connect功能,目前已都放入到应用层
254
+ _defineProperty(this, "onAfterSubmitFunc", function (target, params) {
255
+ _this4.eventService.emitAndListen({
256
+ event: ElementPaymentEvent.AFTER_SUBMIT,
257
+ data: {
258
+ target: target,
259
+ source: ElementPaymentMethod.CONTAINER_ELEMENT,
260
+ params: params
261
+ }
262
+ }, function () {});
263
+ });
264
+ // submit提交 失败,清空组件数据 一期connect功能,目前已都放入到应用层
265
+ // private onSubmitRiskFunc = (target: ElementPaymentMethod) => {
266
+ // this.eventService.emitAndListen(
267
+ // {
268
+ // event: ElementPaymentEvent.SUBMIT_RISK,
269
+ // data: {
270
+ // target,
271
+ // source: ElementPaymentMethod.CONTAINER_ELEMENT,
272
+ // params: {},
273
+ // },
274
+ // },
275
+ // () => {},
276
+ // );
277
+ // };
278
+ // 发起支付 一期connect功能,目前已都放入到应用层
279
+ // private onSubmit = (params: SubmitServiceParams): Promise<SubmitFuncResult> => {
280
+ // return new Promise((resolve) => {
281
+ // const { paymentSessionConfig } = this.parseData;
282
+ // console.log('element submit params ------', {
283
+ // paymentSessionConfig,
284
+ // paymentSessionData: this.sessionData,
285
+ // ...params,
286
+ // });
287
+ // this.requestService
288
+ // .request<SubmitServiceResult>(
289
+ // {
290
+ // paymentSessionConfig,
291
+ // paymentSessionData: this.sessionData,
292
+ // ...params,
293
+ // },
294
+ // {
295
+ // env: this._options.environment,
296
+ // envInfo: {
297
+ // locale: this._options.locale,
298
+ // },
299
+ // timeout: 300000, // TODO dev环境submit提交接口超时
300
+ // 'Operation-Type': 'com.ipay.iexpcashier.cashier.submitPayByPaymentSession',
301
+ // },
302
+ // )
303
+ // .then(
304
+ // (result) => {
305
+ // if (
306
+ // result?.codeFormViews &&
307
+ // result?.codeFormViews?.[0]?.codeExpireTime &&
308
+ // result?.actionForm &&
309
+ // !result?.actionForm?.paymentCodeExpireTime
310
+ // ) {
311
+ // result.actionForm.paymentCodeExpireTime = result?.codeFormViews?.[0]?.codeExpireTime;
312
+ // }
313
+ // if (result.errorCode === ConnectErrorCode.RISK_REJECT) {
314
+ // this.onSubmitRiskFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
315
+ // this.onSubmitRiskFunc(ElementPaymentMethod.AUTH_ELEMENT);
316
+ // this.onSubmitRiskFunc(ElementPaymentMethod.PAYMENT_ELEMENT);
317
+ // } else {
318
+ // this.onAfterSubmitFunc(ElementPaymentMethod.PAYMENT_ELEMENT, result);
319
+ // }
320
+ // resolve({
321
+ // success: result.success,
322
+ // msg: result.errorMessage,
323
+ // });
324
+ // },
325
+ // () => {
326
+ // resolve({
327
+ // success: false,
328
+ // msg: 'submitPayByPaymentSession api error',
329
+ // });
330
+ // },
331
+ // );
332
+ // });
333
+ // };
334
+ // 发送validate消息
335
+ _defineProperty(this, "onValidateFunc", function (target, params) {
336
+ return new Promise(function (resolve) {
337
+ _this4.eventService.emitAndListen({
338
+ event: ElementPaymentEvent.VALIDATE,
339
+ data: {
340
+ target: target,
341
+ source: ElementPaymentMethod.CONTAINER_ELEMENT,
342
+ params: _objectSpread(_objectSpread({}, params), {}, {
343
+ sessionResult: _this4.parseData
344
+ })
345
+ }
346
+ }, function (result) {
347
+ resolve(result);
348
+ });
349
+ });
350
+ });
351
+ // 处理validate事件
352
+ _defineProperty(this, "validatePromiseFuncs", function () {
353
+ return new Promise( /*#__PURE__*/function () {
354
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resolve) {
355
+ var params, _result$data, _result$data2, result, _result$data3, _result$data4, _result, _result2$data, _result2;
356
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
357
+ while (1) switch (_context.prev = _context.next) {
358
+ case 0:
359
+ params = {};
360
+ if (!_this4.launchSource.includes(ElementPaymentMethod.AUTH_ELEMENT)) {
361
+ _context.next = 8;
362
+ break;
363
+ }
364
+ _context.next = 4;
365
+ return _this4.onValidateFunc(ElementPaymentMethod.AUTH_ELEMENT);
366
+ case 4:
367
+ result = _context.sent;
368
+ params.accountInfo = (_result$data = result.data) === null || _result$data === void 0 || (_result$data = _result$data.data) === null || _result$data === void 0 ? void 0 : _result$data.accountInfo;
369
+ if (result !== null && result !== void 0 && (_result$data2 = result.data) !== null && _result$data2 !== void 0 && _result$data2.success) {
370
+ _context.next = 8;
371
+ break;
372
+ }
373
+ return _context.abrupt("return", resolve(undefined));
374
+ case 8:
375
+ if (!_this4.launchSource.includes(ElementPaymentMethod.ADDRESS_ELEMENT)) {
376
+ _context.next = 15;
377
+ break;
378
+ }
379
+ _context.next = 11;
380
+ return _this4.onValidateFunc(ElementPaymentMethod.ADDRESS_ELEMENT);
381
+ case 11:
382
+ _result = _context.sent;
383
+ params.shipping = (_result$data3 = _result.data) === null || _result$data3 === void 0 ? void 0 : _result$data3.data;
384
+ if (_result !== null && _result !== void 0 && (_result$data4 = _result.data) !== null && _result$data4 !== void 0 && _result$data4.success) {
385
+ _context.next = 15;
386
+ break;
387
+ }
388
+ return _context.abrupt("return", resolve(undefined));
389
+ case 15:
390
+ if (!(_this4.launchSource.includes(ElementPaymentMethod.PAYMENT_ELEMENT) || !_this4.isConnect)) {
391
+ _context.next = 27;
392
+ break;
393
+ }
394
+ _context.prev = 16;
395
+ _context.next = 19;
396
+ return _this4.onValidateFunc(ElementPaymentMethod.PAYMENT_ELEMENT, params);
397
+ case 19:
398
+ _result2 = _context.sent;
399
+ if (_result2 !== null && _result2 !== void 0 && (_result2$data = _result2.data) !== null && _result2$data !== void 0 && _result2$data.success) {
400
+ _context.next = 22;
401
+ break;
402
+ }
403
+ return _context.abrupt("return", resolve(undefined));
404
+ case 22:
405
+ _context.next = 27;
406
+ break;
407
+ case 24:
408
+ _context.prev = 24;
409
+ _context.t0 = _context["catch"](16);
410
+ return _context.abrupt("return", resolve(undefined));
411
+ case 27:
412
+ // params.paymentFactors = paymentResult.data?.data.paymentFactors;
413
+ // params.paymentMethod = paymentResult.data?.data.paymentMethod;
414
+ resolve(params);
415
+ case 28:
416
+ case "end":
417
+ return _context.stop();
418
+ }
419
+ }, _callee, null, [[16, 24]]);
420
+ }));
421
+ return function (_x) {
422
+ return _ref.apply(this, arguments);
423
+ };
424
+ }());
425
+ });
426
+ var env = options.environment || ELEMENT_ENVIRONMENT.PROD;
427
+ this._options = _objectSpread(_objectSpread({}, options), {}, {
428
+ environment: env.toLocaleLowerCase()
429
+ });
430
+ this.createElement();
431
+ }
432
+
433
+ // 初始化注册
434
+ _createClass(ElementComponent, [{
435
+ key: "createElement",
436
+ value: function createElement() {
437
+ this.eventCallback = _defineProperty(_defineProperty(_defineProperty({}, ElementPaymentMethod.ADDRESS_ELEMENT, {}), ElementPaymentMethod.AUTH_ELEMENT, {}), ElementPaymentMethod.PAYMENT_ELEMENT, {});
438
+ this.launchSource = [];
439
+ this.componentsCount = 0;
440
+ this.iframes = {};
441
+ this.mountOptions = {};
442
+ logger.logInfo({
443
+ title: 'sdk_element_create'
444
+ });
445
+ this.elementContainer = new AntomSDKCore();
446
+ this.iframeSrc = this.createIframeSrc(this._options.environment, this._options.version);
447
+ }
448
+ }, {
449
+ key: "beforeMount",
450
+ value: function beforeMount(mountSessionData) {
451
+ var _parseData$connectFac,
452
+ _parseData$paymentSes,
453
+ _this5 = this;
454
+ if (this.initCompleted) return;
455
+ this.initCompleted = true;
456
+ var _parseSessionData = parseSessionData(mountSessionData),
457
+ _parseSessionData2 = _slicedToArray(_parseSessionData, 2),
458
+ parseData = _parseSessionData2[0],
459
+ sessionData = _parseSessionData2[1];
460
+ this.parseData = parseData;
461
+ this.sessionData = sessionData;
462
+ this.isConnect = (parseData === null || parseData === void 0 || (_parseData$connectFac = parseData.connectFactor) === null || _parseData$connectFac === void 0 ? void 0 : _parseData$connectFac.enableConnect) && (parseData === null || parseData === void 0 || (_parseData$paymentSes = parseData.paymentSessionConfig) === null || _parseData$paymentSes === void 0 ? void 0 : _parseData$paymentSes.productScene) === ProductSceneEnum.ELEMENT_PAYMENT;
463
+ this.elementContainer.registerProcessor(ProductSceneEnum.ELEMENT_PAYMENT, '', new ElementProcessor({
464
+ paymentSessionConfig: parseData === null || parseData === void 0 ? void 0 : parseData.paymentSessionConfig,
465
+ sessionData: sessionData,
466
+ environment: this._options.environment,
467
+ locale: this._options.locale,
468
+ isConnect: this.isConnect
469
+ }));
470
+ this.elementContainer.init({}, ProductSceneEnum.ELEMENT_PAYMENT);
471
+ try {
472
+ this.elementContainer.startBizFlow({
473
+ paymentSession: mountSessionData
474
+ }).then(function () {
475
+ var _bizFlowBehavior$data;
476
+ if (!_this5.isConnect) return;
477
+ var bizFlowBehavior = _this5.elementContainer.getBizFlowBehavior();
478
+ if (!(bizFlowBehavior !== null && bizFlowBehavior !== void 0 && (_bizFlowBehavior$data = bizFlowBehavior.data) !== null && _bizFlowBehavior$data !== void 0 && _bizFlowBehavior$data.success)) {
479
+ var _this5$_options, _this5$_options$onEve;
480
+ _this5 === null || _this5 === void 0 || (_this5$_options = _this5._options) === null || _this5$_options === void 0 || (_this5$_options$onEve = _this5$_options.onEventCallback) === null || _this5$_options$onEve === void 0 || _this5$_options$onEve.call(_this5$_options, {
481
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
482
+ message: 'Component initialization exception.'
483
+ });
484
+ _this5.closeLoading();
485
+ } else {
486
+ var _bizFlowBehavior$data2, _bizFlowBehavior$data3;
487
+ _this5.oneAccountRes = bizFlowBehavior === null || bizFlowBehavior === void 0 || (_bizFlowBehavior$data2 = bizFlowBehavior.data) === null || _bizFlowBehavior$data2 === void 0 ? void 0 : _bizFlowBehavior$data2.oneAccountRes;
488
+ _this5.sdkActionRes = bizFlowBehavior === null || bizFlowBehavior === void 0 || (_bizFlowBehavior$data3 = bizFlowBehavior.data) === null || _bizFlowBehavior$data3 === void 0 ? void 0 : _bizFlowBehavior$data3.sdkActionRes;
489
+ _this5.afterInit();
490
+ }
491
+ });
492
+ } catch (error) {
493
+ this._options.onEventCallback({
494
+ code: EventCallbackCode.SDK_CREATEPAYMENT_PARAMETER_ERROR,
495
+ message: 'Initialization parameter exception.'
496
+ });
497
+ this.closeLoading();
498
+ }
499
+ var serviceProvider = this.elementContainer.getServiceProvider();
500
+ // 注册事件服务
501
+ this.eventService = serviceProvider.getService('EventCenter');
502
+ // 注册请求服务服务 一期connect功能,目前已都放入到应用层
503
+ // this.requestService = serviceProvider.getService<RequesterService>('Requester');
504
+ // 注册监听消息
505
+ this.addListener();
506
+ }
507
+
508
+ // 创建
509
+ }, {
510
+ key: "createComponentSdk",
511
+ value: function createComponentSdk(type) {
512
+ try {
513
+ // 注册 auth 邮箱模块
514
+ if (type === ElementType.auth) {
515
+ this.authBase = new ElementAuthComponent();
516
+ this.authBase.create({
517
+ environment: this._options.environment,
518
+ locale: this._options.locale
519
+ });
520
+ } else if (type === ElementType.address) {
521
+ this.addressBase = new ElementAddressComponent();
522
+ this.addressBase.create({
523
+ environment: this._options.environment,
524
+ locale: this._options.locale,
525
+ appVersion: this._options.version || ''
526
+ }, this.isConnect);
527
+ } else if (type === ElementType.payment) {
528
+ // 注册 payment 卡支付模块
529
+ this.paymentBase = new ElementPaymentComponent();
530
+ this.paymentBase.create({
531
+ environment: this._options.environment,
532
+ locale: this._options.locale,
533
+ appVersion: this._options.version || ''
534
+ }, this.isConnect);
535
+ } else {
536
+ throw Error("The provided 'type' value is invalid");
537
+ }
538
+ } catch (error) {
539
+ var _this$_options, _this$_options$onEven;
540
+ this === null || this === void 0 || (_this$_options = this._options) === null || _this$_options === void 0 || (_this$_options$onEven = _this$_options.onEventCallback) === null || _this$_options$onEven === void 0 || _this$_options$onEven.call(_this$_options, {
541
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
542
+ message: 'Component initialization exception.'
543
+ });
544
+ this.closeLoading();
545
+ }
546
+ }
547
+
548
+ // iframe src生成方法
549
+ }, {
550
+ key: "createIframeSrc",
551
+ value: function createIframeSrc() {
552
+ var env = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ELEMENT_ENVIRONMENT.DEV;
553
+ var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PackageJson.version;
554
+ var baseUrl = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ELEMENT_ENVIRONMENT.DEV, 'http://page.alipay.net/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.TEST, 'http://page.test.alipay.net/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.SIT, 'http://page.test.alipay.net/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.PRE, 'https://pre.ac.alipay.com/page/antom-web-checkout-v2'), ELEMENT_ENVIRONMENT.SANDBOX, 'https://checkout.antom.com'), ELEMENT_ENVIRONMENT.PROD, 'https://checkout.antom.com');
555
+ var _env = (env === null || env === void 0 ? void 0 : env.toLocaleUpperCase()) || ELEMENT_ENVIRONMENT.DEV;
556
+ var payment = "".concat(baseUrl[_env], "/elements/").concat(version, "/pages/element_payment/index.html");
557
+ try {
558
+ var expressCheckout = JSON.parse(JSON.parse(this.parseData.extendInfo).expressCheckout);
559
+ if (expressCheckout) {
560
+ payment = "".concat(baseUrl[_env], "/elements/").concat(version, "/pages/express_checkout/index.html");
561
+ }
562
+ } catch (error) {}
563
+ return {
564
+ auth: "".concat(baseUrl[_env], "/auth-element/").concat(version, "/pages/element_auth/index.html"),
565
+ address: "".concat(baseUrl[_env], "/element-address/").concat(version, "/pages/address/index.html"),
566
+ payment: payment
567
+ };
568
+ }
569
+ }, {
570
+ key: "closeLoading",
571
+ value: function closeLoading() {
572
+ var _this$_options$loadin;
573
+ if (this.loading && (_this$_options$loadin = this._options.loading) !== null && _this$_options$loadin !== void 0 && _this$_options$loadin.onEndLoading) {
574
+ var _this$_options$loadin2, _this$_options$loadin3;
575
+ (_this$_options$loadin2 = this._options.loading) === null || _this$_options$loadin2 === void 0 || (_this$_options$loadin3 = _this$_options$loadin2.onEndLoading) === null || _this$_options$loadin3 === void 0 || _this$_options$loadin3.call(_this$_options$loadin2);
576
+ }
577
+ this.loading = false;
578
+ }
579
+
580
+ // 循环给所有iframe发同一个消息
581
+ // private postCommonMessage<T>(event: ElementPaymentEvent, params: T) {
582
+ // for (let index = 0; index < this.launchSource.length; index++) {
583
+ // this.eventService.emitAndListen(
584
+ // {
585
+ // event: event,
586
+ // data: {
587
+ // source: ElementPaymentMethod.CONTAINER_ELEMENT,
588
+ // target: this.launchSource[0],
589
+ // params: params,
590
+ // },
591
+ // },
592
+ // () => {},
593
+ // )
594
+ // }
595
+ // }
596
+
597
+ // 监听sdk消息
598
+ }, {
599
+ key: "addListener",
600
+ value: function addListener() {
601
+ var _this6 = this;
602
+ this.eventService.listen(ElementPaymentEvent.LAUNCH, function (result) {
603
+ _this6.launchFunc(result);
604
+ });
605
+ this.eventService.listen(ElementPaymentEvent.SIZE_CHANGE, function (result) {
606
+ if (result.target === ElementPaymentMethod.CONTAINER_ELEMENT && result.source === ElementPaymentMethod.AUTH_ELEMENT) {
607
+ var _this6$authBase;
608
+ (_this6 === null || _this6 === void 0 ? void 0 : _this6.authBase) && (_this6 === null || _this6 === void 0 || (_this6$authBase = _this6.authBase) === null || _this6$authBase === void 0 ? void 0 : _this6$authBase.update(result.data.height));
609
+ }
610
+ });
611
+ this.eventService.listen(ElementPaymentEvent.SEND_MUITI_APP_EVENT_TO_SDK, function (result) {
612
+ var _this6$_options$onEve, _this6$_options;
613
+ (_this6$_options$onEve = (_this6$_options = _this6._options).onEventCallback) === null || _this6$_options$onEve === void 0 || _this6$_options$onEve.call(_this6$_options, result.data);
614
+ });
615
+ this.eventService.listen(ElementPaymentEvent.CALLBACK, function (result) {
616
+ var _this6$eventCallback;
617
+ if ((_this6$eventCallback = _this6.eventCallback) !== null && _this6$eventCallback !== void 0 && (_this6$eventCallback = _this6$eventCallback[result.source]) !== null && _this6$eventCallback !== void 0 && _this6$eventCallback[result.event]) {
618
+ var _this6$eventCallback$, _this6$eventCallback$2;
619
+ (_this6$eventCallback$ = (_this6$eventCallback$2 = _this6.eventCallback[result.source])[result.event]) === null || _this6$eventCallback$ === void 0 || _this6$eventCallback$.call(_this6$eventCallback$2, result.data);
620
+ }
621
+ });
622
+ this.eventService.listen(ConstantEvent.close.name, function () {
623
+ _this6.unmount();
624
+ });
625
+ this.eventService.listen(ConstantEvent.redirect.name, function (data, res) {
626
+ data.isDestroy && _this6.unmount();
627
+ });
628
+ this.eventService.listen(ConstantEvent.appHeartBeat.name, function (result) {
629
+ _this6.closeLoading();
630
+ });
631
+
632
+ // this.eventService.listen(ElementPaymentEvent.LOG, (result: EventCallbackData) => {
633
+ // console.log('antom sdk 组件日志回调');
634
+ // });
635
+
636
+ this.eventService.listen(ElementPaymentEvent.HANDLE_PAYMENT, function (result) {
637
+ if ((result === null || result === void 0 ? void 0 : result.paymentMethodType) === 'APPLEPAY') {
638
+ _this6.ApplePayService.begin().then(function (res) {
639
+ _this6.onAfterSubmitFunc(ElementPaymentMethod.PAYMENT_ELEMENT, {
640
+ submitPayData: res
641
+ });
642
+ }).catch(function (e) {
643
+ _this6.onAfterSubmitFunc(ElementPaymentMethod.PAYMENT_ELEMENT, {
644
+ submitPayData: {},
645
+ errorInfo: {
646
+ hasError: true,
647
+ errorCode: e === null || e === void 0 ? void 0 : e.errorCode
648
+ }
649
+ });
650
+ });
651
+ }
652
+ });
653
+ }
654
+
655
+ // launch消息处理
656
+ }, {
657
+ key: "launchFunc",
658
+ value: function launchFunc() {
659
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
660
+ var eventSource = Object.keys(ElementPaymentMethod);
661
+ var source = data.source,
662
+ target = data.target;
663
+ if (eventSource.includes(source) && target === ElementPaymentMethod.CONTAINER_ELEMENT) {
664
+ if (this.launchSource.every(function (item) {
665
+ return item !== source;
666
+ })) {
667
+ this.launchSource.push(source);
668
+ this.afterInit();
669
+ }
670
+ }
671
+ }
672
+ }, {
673
+ key: "showIframe",
674
+ value: function showIframe() {
675
+ var _this$paymentBase, _this$addressBase, _this$authBase;
676
+ (this === null || this === void 0 ? void 0 : this.paymentBase) && (this === null || this === void 0 || (_this$paymentBase = this.paymentBase) === null || _this$paymentBase === void 0 ? void 0 : _this$paymentBase.update());
677
+ (this === null || this === void 0 ? void 0 : this.addressBase) && (this === null || this === void 0 || (_this$addressBase = this.addressBase) === null || _this$addressBase === void 0 ? void 0 : _this$addressBase.update());
678
+ (this === null || this === void 0 ? void 0 : this.authBase) && (this === null || this === void 0 || (_this$authBase = this.authBase) === null || _this$authBase === void 0 ? void 0 : _this$authBase.update());
679
+ }
680
+ }, {
681
+ key: "afterInit",
682
+ value: function afterInit() {
683
+ if (this.launchSource.length === this.componentsCount && this.sdkActionRes && this.oneAccountRes && this.isConnect) {
684
+ this.sendRenderData();
685
+ this.showIframe();
686
+ }
687
+ }
688
+
689
+ // 发送初始化数据
690
+ }, {
691
+ key: "sendRenderData",
692
+ value: function sendRenderData() {
693
+ var _this7 = this;
694
+ var baseData = {
695
+ originActionQueryResult: this.sdkActionRes,
696
+ originOneAccountQueryResult: this.oneAccountRes,
697
+ paymentSessionData: this.sessionData,
698
+ sessionResult: this.parseData || {}
699
+ };
700
+ this.launchSource.forEach(function (target) {
701
+ var _this7$mountOptions;
702
+ var params = _objectSpread(_objectSpread({}, (_this7$mountOptions = _this7.mountOptions) === null || _this7$mountOptions === void 0 ? void 0 : _this7$mountOptions[target]), baseData);
703
+ if (target === ElementPaymentMethod.ADDRESS_ELEMENT) {
704
+ params.prefillValue = _this7.oneAccountRes.shippings || [];
705
+ } else if (target === ElementPaymentMethod.PAYMENT_ELEMENT) {
706
+ params.queryResult = _this7.sdkActionRes;
707
+ }
708
+ _this7.eventService.emitAndListen({
709
+ event: ElementPaymentEvent.RENDER_COMPONENT,
710
+ data: {
711
+ target: target,
712
+ source: ElementPaymentMethod.CONTAINER_ELEMENT,
713
+ params: params
714
+ }
715
+ }, function () {});
716
+ });
717
+ }
718
+
719
+ // 注销所有消息监听,这里需要和addListener里面监听的事件对应
720
+ }, {
721
+ key: "removeListener",
722
+ value: function removeListener() {
723
+ this.eventService.unlisten(ElementPaymentEvent.SIGN_OUT);
724
+ this.eventService.unlisten(ElementPaymentEvent.CAPTURE_ASSET);
725
+ this.eventService.unlisten(ElementPaymentEvent.LAUNCH);
726
+ this.eventService.unlisten(ElementPaymentEvent.SIZE_CHANGE);
727
+ this.eventService.unlisten(ElementPaymentEvent.CALLBACK);
728
+ this.eventService.unlisten(ConstantEvent.close.name);
729
+ this.eventService.unlisten(ConstantEvent.redirect.name);
730
+ this.eventService.unlisten(ConstantEvent.appHeartBeat.name);
731
+ this.eventService.unlisten(ElementPaymentEvent.HANDLE_PAYMENT);
732
+ }
733
+
734
+ // 注册组件事件监听
735
+ }, {
736
+ key: "registerEventListener",
737
+ value: function registerEventListener(source, event, callback) {
738
+ this.eventCallback[source][event] = callback;
739
+ }
740
+
741
+ // 渲染邮箱组件
742
+ }, {
743
+ key: "mountAuth",
744
+ value: function mountAuth(renderOptions, sdkSelector) {
745
+ var _this$_options2,
746
+ _renderOptions$elemen,
747
+ _this8 = this;
748
+ var _mountParams = {
749
+ appearance: renderOptions.appearance || ((_this$_options2 = this._options) === null || _this$_options2 === void 0 ? void 0 : _this$_options2.appearance) || {
750
+ theme: ThemeType.Default
751
+ }
752
+ };
753
+ this.mountOptions[ElementPaymentMethod.AUTH_ELEMENT] = _mountParams;
754
+ var link = renderOptions === null || renderOptions === void 0 || (_renderOptions$elemen = renderOptions.elementProps) === null || _renderOptions$elemen === void 0 ? void 0 : _renderOptions$elemen.elementLink;
755
+ var params = window.location.href.split('?')[1];
756
+ params = "instanceId=".concat(uuid(), "&") + params;
757
+ var url = link.indexOf('?') === -1 ? "".concat(link, "?").concat(params) : link;
758
+ this.authBase.mount({
759
+ selector: sdkSelector,
760
+ sessionData: renderOptions.sessionData,
761
+ url: url
762
+ }).then(function (result) {
763
+ if (!result) {
764
+ return _this8.mountErrorHandle();
765
+ }
766
+ _this8.eventService.addIFrame(result);
767
+ _this8.iframes[ElementPaymentMethod.AUTH_ELEMENT] = result;
768
+ });
769
+ return {};
770
+ }
771
+ }, {
772
+ key: "initApplePaySdk",
773
+ value: function () {
774
+ var _initApplePaySdk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
775
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
776
+ while (1) switch (_context2.prev = _context2.next) {
777
+ case 0:
778
+ if (!isSkipRenderPaymentMethod(this.parseData)) {
779
+ _context2.next = 12;
780
+ break;
781
+ }
782
+ this.ApplePayService = new ApplePaySdk({
783
+ paymentSessionData: this.sessionData,
784
+ parseData: this.parseData,
785
+ logger: logger
786
+ });
787
+ _context2.prev = 2;
788
+ logger.logInfo({
789
+ title: 'a3753.b107385.c398110'
790
+ });
791
+ _context2.next = 6;
792
+ return this.ApplePayService.initApplePaySession();
793
+ case 6:
794
+ logger.logInfo({
795
+ title: 'a3753.b107385.c398112'
796
+ });
797
+ _context2.next = 12;
798
+ break;
799
+ case 9:
800
+ _context2.prev = 9;
801
+ _context2.t0 = _context2["catch"](2);
802
+ logger.logError({
803
+ title: 'a3753.b107385.c398111'
804
+ });
805
+ case 12:
806
+ case "end":
807
+ return _context2.stop();
808
+ }
809
+ }, _callee2, this, [[2, 9]]);
810
+ }));
811
+ function initApplePaySdk() {
812
+ return _initApplePaySdk.apply(this, arguments);
813
+ }
814
+ return initApplePaySdk;
815
+ }()
816
+ }, {
817
+ key: "mountErrorHandle",
818
+ value: function mountErrorHandle() {
819
+ var _this$_options3, _this$_options3$onEve;
820
+ this === null || this === void 0 || (_this$_options3 = this._options) === null || _this$_options3 === void 0 || (_this$_options3$onEve = _this$_options3.onEventCallback) === null || _this$_options3$onEve === void 0 || _this$_options3$onEve.call(_this$_options3, {
821
+ code: EventCallbackCode.SDK_CREATE_COMPONENT_ERROR,
822
+ message: 'Component initialization exception.'
823
+ });
824
+ this.closeLoading();
825
+ logger.logError({
826
+ title: 'sdk_element_mount_fail'
827
+ });
828
+ this.resetState();
829
+ }
830
+ }, {
831
+ key: "mount",
832
+ value: function mount(renderOptions, sdkSelector) {
833
+ // 当前type element已加载 / 加载中
834
+ if (this.iframes[MountElementType[renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.type]] || this.loadingElement.includes(renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.type)) {
835
+ throw Error('The component has been mounted, please do not execute it again.');
836
+ }
837
+ if (typeof sdkSelector === 'string') {
838
+ var _this$_options$loadin4, _renderOptions$debugP, _renderOptions$debugP2;
839
+ var element = document.querySelector(sdkSelector);
840
+ // 容器是否存在
841
+ if (!element) {
842
+ throw Error('Loading failed, you need to check if the element exists.');
843
+ }
844
+ // 生成sdk,同时判断 type 是否合规,不合规会直接报错
845
+ this.createComponentSdk(renderOptions.type);
846
+ this.beforeMount(renderOptions.sessionData);
847
+ this.loadingElement.push(renderOptions === null || renderOptions === void 0 ? void 0 : renderOptions.type);
848
+ logger.logInfo({
849
+ title: 'sdk_element_mount_start'
850
+ });
851
+ if (!this.loading && (_this$_options$loadin4 = this._options.loading) !== null && _this$_options$loadin4 !== void 0 && _this$_options$loadin4.onStartLoading) {
852
+ var _this$_options$loadin5, _this$_options$loadin6;
853
+ (_this$_options$loadin5 = this._options.loading) === null || _this$_options$loadin5 === void 0 || (_this$_options$loadin6 = _this$_options$loadin5.onStartLoading) === null || _this$_options$loadin6 === void 0 || _this$_options$loadin6.call(_this$_options$loadin5);
854
+ }
855
+ this.loading = true;
856
+ this.componentsCount = this.componentsCount + 1;
857
+ var elementLink = renderOptions !== null && renderOptions !== void 0 && (_renderOptions$debugP = renderOptions.debugProps) !== null && _renderOptions$debugP !== void 0 && _renderOptions$debugP.localLink ? renderOptions === null || renderOptions === void 0 || (_renderOptions$debugP2 = renderOptions.debugProps) === null || _renderOptions$debugP2 === void 0 ? void 0 : _renderOptions$debugP2.localLink : this.iframeSrc[renderOptions.type];
858
+ renderOptions.elementProps = {
859
+ elementLink: elementLink
860
+ };
861
+ if (renderOptions.type === ElementType.auth) {
862
+ return this.mountAuth(renderOptions, sdkSelector);
863
+ }
864
+ if (renderOptions.type === ElementType.address) {
865
+ return this.mountAddress(renderOptions, sdkSelector);
866
+ }
867
+ if (renderOptions.type === ElementType.payment) {
868
+ return this.mountPayment(renderOptions, sdkSelector);
869
+ }
870
+ } else {
871
+ return this.mountErrorHandle();
872
+ }
873
+ }
874
+
875
+ // 注销单个iframe,暂时没有用到
876
+ // private removeIframe(sdk: ElementPaymentMethod) {
877
+ // if (sdk && this.launchSource.some((source) => source === sdk)) {
878
+ // this.launchSource = this.launchSource.filter((source) => source !== sdk);
879
+ // this.componentsCount = this.componentsCount - 1;
880
+ // this.eventService.removeIFrame(this.iframes[sdk]);
881
+ // }
882
+ // }
883
+
884
+ // 暴露出去的注销组件方法
885
+ }, {
886
+ key: "resetState",
887
+ value: function resetState() {
888
+ var _this$authBase2, _this$authBase2$unmou, _this$addressBase2, _this$addressBase2$un, _this$paymentBase2, _this$paymentBase2$un;
889
+ (_this$authBase2 = this.authBase) === null || _this$authBase2 === void 0 || (_this$authBase2$unmou = _this$authBase2.unmount) === null || _this$authBase2$unmou === void 0 || _this$authBase2$unmou.call(_this$authBase2);
890
+ (_this$addressBase2 = this.addressBase) === null || _this$addressBase2 === void 0 || (_this$addressBase2$un = _this$addressBase2.unmount) === null || _this$addressBase2$un === void 0 || _this$addressBase2$un.call(_this$addressBase2);
891
+ (_this$paymentBase2 = this.paymentBase) === null || _this$paymentBase2 === void 0 || (_this$paymentBase2$un = _this$paymentBase2.unmount) === null || _this$paymentBase2$un === void 0 || _this$paymentBase2$un.call(_this$paymentBase2);
892
+ this.launchSource = [];
893
+ this.iframes = {};
894
+ this.componentsCount = 0;
895
+ this.eventService.destroy();
896
+ this.removeListener();
897
+ this.loadingElement = [];
898
+ this.initCompleted = false;
899
+ }
900
+ }, {
901
+ key: "unmount",
902
+ value: function unmount() {
903
+ if (!this.iframes.PAYMENT_ELEMENT) {
904
+ throw Error('Component is not mounted. You need to check if the mount method has been successfully called to mount the component.');
905
+ }
906
+ // popup未注册会报错,但element不需要感知popup是否被注册
907
+ try {
908
+ destroyModal(); // 关闭popup弹窗
909
+ } catch (error) {}
910
+ this.resetState();
911
+ }
912
+ }, {
913
+ key: "submitPayment",
914
+ value: // 暴露出去的submit方法
915
+ function () {
916
+ var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
917
+ var _this$_options$loadin7;
918
+ var _this$_options$loadin8, _this$_options$loadin9;
919
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
920
+ while (1) switch (_context3.prev = _context3.next) {
921
+ case 0:
922
+ if (this.iframes.PAYMENT_ELEMENT) {
923
+ _context3.next = 2;
924
+ break;
925
+ }
926
+ throw Error('Component is not mounted. You need to check if the mount method has been successfully called to mount the component.');
927
+ case 2:
928
+ if (!this.loading) {
929
+ _context3.next = 4;
930
+ break;
931
+ }
932
+ throw Error('The form is submitted repeatedly. without the need to click submit repeatedly.');
933
+ case 4:
934
+ if ((_this$_options$loadin7 = this._options.loading) !== null && _this$_options$loadin7 !== void 0 && _this$_options$loadin7.onStartLoading) {
935
+ (_this$_options$loadin8 = this._options.loading) === null || _this$_options$loadin8 === void 0 || (_this$_options$loadin9 = _this$_options$loadin8.onStartLoading) === null || _this$_options$loadin9 === void 0 || _this$_options$loadin9.call(_this$_options$loadin8);
936
+ }
937
+ this.loading = true;
938
+ _context3.next = 8;
939
+ return this.validatePromiseFuncs();
940
+ case 8:
941
+ this.closeLoading();
942
+ return _context3.abrupt("return");
943
+ case 10:
944
+ case "end":
945
+ return _context3.stop();
946
+ }
947
+ }, _callee3, this);
948
+ }));
949
+ function submitPayment() {
950
+ return _submitPayment.apply(this, arguments);
951
+ }
952
+ return submitPayment;
953
+ }()
954
+ }]);
955
+ return ElementComponent;
956
+ }();