@alipay/ams-checkout 0.0.1737621505-dev.3 → 0.0.1739763028-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.
@@ -1,4 +1,6 @@
1
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 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; }
3
+ 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; }
2
4
  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; }
3
5
  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); } }
4
6
  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); }); }; }
@@ -12,8 +14,7 @@ import { BusManager, BusMessage } from "../../core/bus";
12
14
  import { SecuritySDKActionEnum } from "../../core/bus/interface";
13
15
  import { getApplePayPaymentSession, submitPayInfo } from "../../service";
14
16
  import { EnvironmentEnum } from "../../types";
15
- import { device, isEmpty } from "../../util";
16
- import { APPLE_PAY_RECURRING_VERSION, APPLE_PAY_VERSION } from "../applepay/interface";
17
+ import { device } from "../../util";
17
18
  var APPLEPAYERRORENUM = /*#__PURE__*/function (APPLEPAYERRORENUM) {
18
19
  APPLEPAYERRORENUM["APPLE_PAY_MISSING_DATA"] = "APPLE_PAY_MISSING_DATA";
19
20
  APPLEPAYERRORENUM["APPLE_PAY_NOT_SUPPORTED"] = "APPLE_PAY_NOT_SUPPORTED";
@@ -116,332 +117,418 @@ export var handleGooglePay = function handleGooglePay(data) {
116
117
  };
117
118
  });
118
119
  };
119
- export var ApplePaySdk = /*#__PURE__*/function () {
120
- function ApplePaySdk(_ref) {
121
- var paymentSessionData = _ref.paymentSessionData,
122
- parseData = _ref.parseData,
123
- logger = _ref.logger;
124
- _classCallCheck(this, ApplePaySdk);
120
+ export var ApplePayService = /*#__PURE__*/function () {
121
+ function ApplePayService(_ref) {
122
+ var _paymentMethod$paymen;
123
+ var sessionData = _ref.sessionData,
124
+ paymentSessionMetaData = _ref.paymentSessionMetaData,
125
+ paymentMethod = _ref.paymentMethod,
126
+ logger = _ref.logger,
127
+ dispatchToApp = _ref.dispatchToApp;
128
+ _classCallCheck(this, ApplePayService);
125
129
  _defineProperty(this, "APPLESDKURL", 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js');
126
- _defineProperty(this, "session", null);
130
+ _defineProperty(this, "applePaySession", void 0);
127
131
  _defineProperty(this, "paymentSessionData", void 0);
128
- _defineProperty(this, "parseData", void 0);
132
+ _defineProperty(this, "sessionResult", void 0);
129
133
  /**
130
134
  * @description 支付状态,pending:支付中,normal:正常
131
135
  */
132
136
  _defineProperty(this, "paymentStatus", void 0);
137
+ /**
138
+ * @description paymentRequest
139
+ */
140
+ _defineProperty(this, "paymentRequest", void 0);
133
141
  _defineProperty(this, "logger", void 0);
134
- this.paymentSessionData = paymentSessionData;
135
- this.parseData = parseData;
142
+ _defineProperty(this, "dispatchToApp", void 0);
143
+ _defineProperty(this, "paymentMethod", void 0);
144
+ this.paymentMethod = paymentMethod;
145
+ this.dispatchToApp = dispatchToApp;
136
146
  this.logger = logger;
147
+ this.paymentSessionData = sessionData;
148
+ this.sessionResult = paymentSessionMetaData;
149
+ this.paymentRequest = paymentMethod === null || paymentMethod === void 0 || (_paymentMethod$paymen = paymentMethod.paymentMethodDetail) === null || _paymentMethod$paymen === void 0 || (_paymentMethod$paymen = _paymentMethod$paymen.applePayProps) === null || _paymentMethod$paymen === void 0 ? void 0 : _paymentMethod$paymen.paymentRequest;
137
150
  }
138
- _createClass(ApplePaySdk, [{
151
+ _createClass(ApplePayService, [{
139
152
  key: "startPay",
140
153
  value: function () {
141
- var _startPay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
142
- return _regeneratorRuntime().wrap(function _callee$(_context) {
143
- while (1) switch (_context.prev = _context.next) {
154
+ var _startPay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
155
+ var _this = this;
156
+ var _this$logger2, _this$logger;
157
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
158
+ while (1) switch (_context2.prev = _context2.next) {
144
159
  case 0:
145
- _context.prev = 0;
146
- _context.next = 3;
147
- return this.initApplePaySession();
160
+ _context2.prev = 0;
161
+ if (!(this.paymentStatus === PAYMENT_STATUS.PENDING)) {
162
+ _context2.next = 3;
163
+ break;
164
+ }
165
+ return _context2.abrupt("return");
148
166
  case 3:
149
- return _context.abrupt("return", this.begin());
150
- case 6:
151
- _context.prev = 6;
152
- _context.t0 = _context["catch"](0);
153
- return _context.abrupt("return", Promise.reject(_context.t0));
154
- case 9:
155
- case "end":
156
- return _context.stop();
157
- }
158
- }, _callee, this, [[0, 6]]);
159
- }));
160
- function startPay() {
161
- return _startPay.apply(this, arguments);
162
- }
163
- return startPay;
164
- }()
165
- }, {
166
- key: "begin",
167
- value: function begin() {
168
- var _this = this;
169
- return new Promise(function (resolve, reject) {
170
- try {
171
- if (!_this.session) return;
172
- _this.paymentStatus = PAYMENT_STATUS.PENDING;
173
- _this.session.onvalidatemerchant = /*#__PURE__*/function () {
174
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(event) {
175
- var requestParams, res, merchantSession, _this$logger, _this$logger2;
176
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
177
- while (1) switch (_context2.prev = _context2.next) {
178
- case 0:
179
- _context2.prev = 0;
180
- requestParams = {
181
- validateUrl: event === null || event === void 0 ? void 0 : event.validationURL,
182
- paymentSessionData: _this.paymentSessionData
183
- };
184
- _context2.t0 = getApplePayPaymentSession;
185
- _context2.t1 = _this.paymentSessionData;
186
- _context2.t2 = requestParams;
187
- _context2.t3 = EnvironmentEnum.prod;
188
- _context2.next = 8;
189
- return _this.getDeviceId();
190
- case 8:
191
- _context2.t4 = _context2.sent;
192
- _context2.t5 = {
193
- deviceId: _context2.t4
194
- };
195
- _context2.t6 = {
196
- env: _context2.t3,
197
- envInfo: _context2.t5
198
- };
199
- _context2.t7 = _this.logger;
200
- _context2.next = 14;
201
- return (0, _context2.t0)(_context2.t1, _context2.t2, _context2.t6, _context2.t7);
202
- case 14:
203
- res = _context2.sent;
204
- if (res !== null && res !== void 0 && res.success && res.merchantSessionObject) {
205
- merchantSession = JSON.parse(res.merchantSessionObject);
206
- _this.session.completeMerchantValidation(merchantSession);
207
- } else {
208
- (_this$logger = _this.logger) === null || _this$logger === void 0 || _this$logger.logError({
209
- title: 'a3753.b103030.c386485.d507483'
210
- });
211
- _this.abortSession();
212
- reject({
213
- errorCode: APPLEPAYERRORENUM.APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED
214
- });
215
- }
216
- _context2.next = 23;
217
- break;
218
- case 18:
219
- _context2.prev = 18;
220
- _context2.t8 = _context2["catch"](0);
221
- (_this$logger2 = _this.logger) === null || _this$logger2 === void 0 || _this$logger2.logError({
222
- title: 'a3753.b103030.c386485.d507483'
223
- });
224
- _this.abortSession();
167
+ if (this.isRequiredParameters) {
168
+ _context2.next = 7;
169
+ break;
170
+ }
171
+ (_this$logger = this.logger) === null || _this$logger === void 0 || _this$logger.logError({
172
+ code: 'a3753.b103030.c386485.d507448'
173
+ }, {
174
+ paymentRequest: JSON.stringify(this.paymentRequest)
175
+ });
176
+ this.paymentStatus = PAYMENT_STATUS.NORMAL;
177
+ return _context2.abrupt("return", Promise.reject({
178
+ errorCode: APPLEPAYERRORENUM.APPLE_PAY_MISSING_DATA
179
+ }));
180
+ case 7:
181
+ (_this$logger2 = this.logger) === null || _this$logger2 === void 0 || _this$logger2.logInfo({
182
+ code: 'a3753.b103030.c386485.d507459'
183
+ }, {
184
+ paymentRequest: JSON.stringify(this.paymentRequest)
185
+ });
186
+ _context2.next = 10;
187
+ return this.initApplePaySession();
188
+ case 10:
189
+ return _context2.abrupt("return", new Promise(function (resolve, reject) {
190
+ _this.applePaySession.onvalidatemerchant = /*#__PURE__*/function () {
191
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
192
+ var requestParams, res, merchantSession, _this$logger3, _this$logger4;
193
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
194
+ while (1) switch (_context.prev = _context.next) {
195
+ case 0:
196
+ _context.prev = 0;
197
+ requestParams = {
198
+ validateUrl: event === null || event === void 0 ? void 0 : event.validationURL,
199
+ paymentSessionData: _this.paymentSessionData
200
+ };
201
+ _context.t0 = getApplePayPaymentSession;
202
+ _context.t1 = _this.paymentSessionData;
203
+ _context.t2 = requestParams;
204
+ _context.t3 = EnvironmentEnum.prod;
205
+ _context.next = 8;
206
+ return _this.getDeviceId();
207
+ case 8:
208
+ _context.t4 = _context.sent;
209
+ _context.t5 = {
210
+ deviceId: _context.t4
211
+ };
212
+ _context.t6 = {
213
+ env: _context.t3,
214
+ envInfo: _context.t5
215
+ };
216
+ _context.t7 = _this.logger;
217
+ _context.next = 14;
218
+ return (0, _context.t0)(_context.t1, _context.t2, _context.t6, _context.t7);
219
+ case 14:
220
+ res = _context.sent;
221
+ if (res !== null && res !== void 0 && res.success && res.merchantSessionObject) {
222
+ merchantSession = JSON.parse(res.merchantSessionObject);
223
+ _this.applePaySession.completeMerchantValidation(merchantSession);
224
+ } else {
225
+ (_this$logger3 = _this.logger) === null || _this$logger3 === void 0 || _this$logger3.logError({
226
+ code: 'a3753.b103030.c386485.d507483'
227
+ });
228
+ _this.abortPaySession();
229
+ reject({
230
+ errorCode: APPLEPAYERRORENUM.APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED
231
+ });
232
+ }
233
+ _context.next = 23;
234
+ break;
235
+ case 18:
236
+ _context.prev = 18;
237
+ _context.t8 = _context["catch"](0);
238
+ (_this$logger4 = _this.logger) === null || _this$logger4 === void 0 || _this$logger4.logError({
239
+ code: 'a3753.b103030.c386485.d507483'
240
+ });
241
+ _this.abortPaySession();
242
+ reject({
243
+ errorCode: APPLEPAYERRORENUM.APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED
244
+ });
245
+ case 23:
246
+ case "end":
247
+ return _context.stop();
248
+ }
249
+ }, _callee, null, [[0, 18]]);
250
+ }));
251
+ return function (_x) {
252
+ return _ref2.apply(this, arguments);
253
+ };
254
+ }();
255
+ _this.applePaySession.onpaymentauthorized = function (event) {
256
+ var exception = function exception() {
257
+ var _this$applePaySession, _this$applePaySession2;
258
+ (_this$applePaySession = _this.applePaySession) === null || _this$applePaySession === void 0 || (_this$applePaySession2 = _this$applePaySession.completePayment) === null || _this$applePaySession2 === void 0 || _this$applePaySession2.call(_this$applePaySession, window.ApplePaySession.STATUS_FAILURE);
259
+ _this.abortPaySession();
225
260
  reject({
226
- errorCode: APPLEPAYERRORENUM.APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED
261
+ errorCode: APPLEPAYERRORENUM.APPLE_PAY_TOKEN_ERROR
227
262
  });
228
- case 23:
229
- case "end":
230
- return _context2.stop();
231
- }
232
- }, _callee2, null, [[0, 18]]);
233
- }));
234
- return function (_x) {
235
- return _ref2.apply(this, arguments);
236
- };
237
- }();
238
- _this.session.onpaymentauthorized = /*#__PURE__*/function () {
239
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(event) {
240
- var exception, _event$payment, token, billingContact, shippingContact, _this$parseData, obj, _this$parseData$payme, requiredBillingContactFields, requiredShippingContactFields, res, _this$logger3;
241
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
242
- while (1) switch (_context3.prev = _context3.next) {
243
- case 0:
244
- exception = function exception() {
245
- var _this$session, _this$session$complet;
246
- (_this$session = _this.session) === null || _this$session === void 0 || (_this$session$complet = _this$session.completePayment) === null || _this$session$complet === void 0 || _this$session$complet.call(_this$session, window.ApplePaySession.STATUS_FAILURE);
247
- _this.abortSession();
248
- return Promise.reject({
249
- errorCode: APPLEPAYERRORENUM.APPLE_PAY_TOKEN_ERROR
250
- });
251
- };
252
- _event$payment = event === null || event === void 0 ? void 0 : event.payment, token = _event$payment.token, billingContact = _event$payment.billingContact, shippingContact = _event$payment.shippingContact;
253
- if (!token) {
254
- _context3.next = 14;
255
- break;
256
- }
257
- obj = {
263
+ };
264
+ var _event$payment = event === null || event === void 0 ? void 0 : event.payment,
265
+ token = _event$payment.token,
266
+ billingContact = _event$payment.billingContact,
267
+ shippingContact = _event$payment.shippingContact;
268
+ if (token) {
269
+ var _this$paymentRequest, _this$paymentRequest2;
270
+ var obj = {
258
271
  instPaymentToken: JSON.stringify(token)
259
272
  };
260
- _this$parseData$payme = (_this$parseData = _this.parseData) === null || _this$parseData === void 0 || (_this$parseData = _this$parseData.paymentSessionFactor) === null || _this$parseData === void 0 ? void 0 : _this$parseData.extendInfo, requiredBillingContactFields = _this$parseData$payme.requiredBillingContactFields, requiredShippingContactFields = _this$parseData$payme.requiredShippingContactFields;
261
- if (!isEmpty(requiredBillingContactFields) && billingContact) {
273
+ if ((_this$paymentRequest = _this.paymentRequest) !== null && _this$paymentRequest !== void 0 && _this$paymentRequest.requiredBillingContactFields && billingContact) {
262
274
  obj['applePayBillingContact'] = JSON.stringify(billingContact);
263
275
  }
264
- if (!isEmpty(requiredShippingContactFields) && shippingContact) {
276
+ if ((_this$paymentRequest2 = _this.paymentRequest) !== null && _this$paymentRequest2 !== void 0 && _this$paymentRequest2.requiredShippingContactFields && shippingContact) {
265
277
  obj['applePayShippingContact'] = JSON.stringify(shippingContact);
266
278
  }
267
- _context3.next = 9;
268
- return _this.submitPay(obj);
269
- case 9:
270
- res = _context3.sent;
271
- _this.setPayStatus(res);
272
- resolve(res);
273
- _context3.next = 16;
274
- break;
275
- case 14:
276
- (_this$logger3 = _this.logger) === null || _this$logger3 === void 0 || _this$logger3.logError({
277
- title: 'a3753.b103030.c386485.d507486'
279
+ _this.submitPay(obj).then(function (res) {
280
+ _this.setApplePayStatus(res);
281
+ resolve(res);
282
+ });
283
+ } else {
284
+ var _this$logger5;
285
+ (_this$logger5 = _this.logger) === null || _this$logger5 === void 0 || _this$logger5.logError({
286
+ code: 'a3753.b103030.c386485.d507486'
278
287
  });
279
288
  exception();
280
- case 16:
281
- case "end":
282
- return _context3.stop();
283
- }
284
- }, _callee3);
285
- }));
286
- return function (_x2) {
287
- return _ref3.apply(this, arguments);
288
- };
289
- }();
290
- _this.session.oncancel = function () {
291
- if (_this.paymentStatus === PAYMENT_STATUS.PENDING) {
292
- var _this$logger4;
293
- (_this$logger4 = _this.logger) === null || _this$logger4 === void 0 || _this$logger4.logError({
294
- title: 'a3753.b103030.c386485.d507497'
295
- });
296
- } else {
297
- var _this$logger5;
298
- (_this$logger5 = _this.logger) === null || _this$logger5 === void 0 || _this$logger5.logInfo({
299
- title: 'a3753.b103030.c386485.d507498'
300
- });
301
- }
302
- _this.abortSession();
303
- reject({
304
- errorCode: APPLEPAYERRORENUM.APPLE_PAY_CANCEL
305
- });
306
- };
307
- _this.session.begin();
308
- _this.addEventListener(reject);
309
- } catch (e) {
310
- return Promise.reject(e);
311
- }
312
- });
289
+ }
290
+ };
291
+ _this.applePaySession.oncancel = function () {
292
+ if (_this.paymentStatus === PAYMENT_STATUS.PENDING) {
293
+ var _this$logger6;
294
+ (_this$logger6 = _this.logger) === null || _this$logger6 === void 0 || _this$logger6.logError({
295
+ code: 'a3753.b103030.c386485.d507497'
296
+ });
297
+ } else {
298
+ var _this$logger7;
299
+ (_this$logger7 = _this.logger) === null || _this$logger7 === void 0 || _this$logger7.logInfo({
300
+ code: 'a3753.b103030.c386485.d507498'
301
+ });
302
+ }
303
+ _this.abortPaySession();
304
+ reject({
305
+ errorCode: APPLEPAYERRORENUM.APPLE_PAY_CANCEL
306
+ });
307
+ };
308
+ _this.applePaySession.begin();
309
+ _this.addEventListener(reject);
310
+ }));
311
+ case 13:
312
+ _context2.prev = 13;
313
+ _context2.t0 = _context2["catch"](0);
314
+ return _context2.abrupt("return", Promise.reject(_context2.t0));
315
+ case 16:
316
+ case "end":
317
+ return _context2.stop();
318
+ }
319
+ }, _callee2, this, [[0, 13]]);
320
+ }));
321
+ function startPay() {
322
+ return _startPay.apply(this, arguments);
323
+ }
324
+ return startPay;
325
+ }()
326
+ }, {
327
+ key: "setApplePayStatus",
328
+ value: function setApplePayStatus(result) {
329
+ var _this$applePaySession3, _this$applePaySession4;
330
+ var payStatus = {
331
+ success: window.ApplePaySession.STATUS_SUCCESS,
332
+ fail: window.ApplePaySession.STATUS_FAILURE
333
+ };
334
+ var status;
335
+ if (result !== null && result !== void 0 && result.success || (result === null || result === void 0 ? void 0 : result.errorStatus) === 'U') {
336
+ status = 'success';
337
+ } else {
338
+ status = 'fail';
339
+ }
340
+ this.paymentStatus = PAYMENT_STATUS.NORMAL;
341
+ (_this$applePaySession3 = this.applePaySession) === null || _this$applePaySession3 === void 0 || (_this$applePaySession4 = _this$applePaySession3.completePayment) === null || _this$applePaySession4 === void 0 || _this$applePaySession4.call(_this$applePaySession3, payStatus[status]);
313
342
  }
314
343
  }, {
315
344
  key: "submitPay",
316
345
  value: function () {
317
- var _submitPay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
318
- var _this$parseData2;
319
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
320
- while (1) switch (_context4.prev = _context4.next) {
346
+ var _submitPay = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
347
+ var _this$sessionResult, _this$paymentMethod, _this$paymentMethod2, _this$paymentMethod3;
348
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
349
+ while (1) switch (_context3.prev = _context3.next) {
321
350
  case 0:
322
- _context4.prev = 0;
323
- _context4.t0 = submitPayInfo;
324
- _context4.t1 = {
325
- paymentSessionConfig: (_this$parseData2 = this.parseData) === null || _this$parseData2 === void 0 ? void 0 : _this$parseData2.paymentSessionConfig,
351
+ _context3.prev = 0;
352
+ _context3.t0 = submitPayInfo;
353
+ _context3.t1 = {
354
+ paymentSessionConfig: (_this$sessionResult = this.sessionResult) === null || _this$sessionResult === void 0 ? void 0 : _this$sessionResult.paymentSessionConfig,
326
355
  paymentSessionData: this.paymentSessionData,
327
356
  paymentFactors: params,
328
357
  paymentMethod: {
329
- paymentMethodType: 'APPLEPAY'
358
+ paymentMethodType: (_this$paymentMethod = this.paymentMethod) === null || _this$paymentMethod === void 0 ? void 0 : _this$paymentMethod.paymentMethodType,
359
+ category: (_this$paymentMethod2 = this.paymentMethod) === null || _this$paymentMethod2 === void 0 ? void 0 : _this$paymentMethod2.category,
360
+ paymentMethodDetail: (_this$paymentMethod3 = this.paymentMethod) === null || _this$paymentMethod3 === void 0 ? void 0 : _this$paymentMethod3.paymentMethodDetail
330
361
  }
331
362
  };
332
- _context4.t2 = EnvironmentEnum.prod;
333
- _context4.next = 6;
363
+ _context3.t2 = EnvironmentEnum.prod;
364
+ _context3.next = 6;
334
365
  return this.getDeviceId();
335
366
  case 6:
336
- _context4.t3 = _context4.sent;
337
- _context4.t4 = {
338
- deviceId: _context4.t3
367
+ _context3.t3 = _context3.sent;
368
+ _context3.t4 = {
369
+ deviceId: _context3.t3
339
370
  };
340
- _context4.t5 = {
341
- env: _context4.t2,
342
- envInfo: _context4.t4
371
+ _context3.t5 = {
372
+ env: _context3.t2,
373
+ envInfo: _context3.t4
343
374
  };
344
- _context4.t6 = this.logger;
345
- _context4.next = 12;
346
- return (0, _context4.t0)(_context4.t1, _context4.t5, _context4.t6);
375
+ _context3.t6 = this.logger;
376
+ _context3.next = 12;
377
+ return (0, _context3.t0)(_context3.t1, _context3.t5, _context3.t6);
347
378
  case 12:
348
- return _context4.abrupt("return", _context4.sent);
379
+ return _context3.abrupt("return", _context3.sent);
349
380
  case 15:
350
- _context4.prev = 15;
351
- _context4.t7 = _context4["catch"](0);
352
- return _context4.abrupt("return", Promise.resolve(_context4.t7));
353
- case 18:
381
+ _context3.prev = 15;
382
+ _context3.t7 = _context3["catch"](0);
383
+ case 17:
354
384
  case "end":
355
- return _context4.stop();
385
+ return _context3.stop();
356
386
  }
357
- }, _callee4, this, [[0, 15]]);
387
+ }, _callee3, this, [[0, 15]]);
358
388
  }));
359
- function submitPay(_x3) {
389
+ function submitPay(_x2) {
360
390
  return _submitPay.apply(this, arguments);
361
391
  }
362
392
  return submitPay;
363
393
  }()
364
394
  }, {
365
- key: "setPayStatus",
366
- value: function setPayStatus(result) {
367
- var _this$session2, _this$session2$comple;
368
- var payStatus = {
369
- success: window.ApplePaySession.STATUS_SUCCESS,
370
- fail: window.ApplePaySession.STATUS_FAILURE
371
- };
372
- var status;
373
- if (result !== null && result !== void 0 && result.success || (result === null || result === void 0 ? void 0 : result.errorStatus) === 'U') {
374
- status = 'success';
375
- } else {
376
- status = 'fail';
395
+ key: "submit",
396
+ value: function () {
397
+ var _submit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
398
+ var result;
399
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
400
+ while (1) switch (_context4.prev = _context4.next) {
401
+ case 0:
402
+ _context4.prev = 0;
403
+ _context4.next = 3;
404
+ return this.startPay();
405
+ case 3:
406
+ result = _context4.sent;
407
+ this.dispatchToApp({
408
+ context: {
409
+ event: 'getApplePayToken',
410
+ data: {
411
+ success: true,
412
+ result: result
413
+ }
414
+ }
415
+ });
416
+ _context4.next = 10;
417
+ break;
418
+ case 7:
419
+ _context4.prev = 7;
420
+ _context4.t0 = _context4["catch"](0);
421
+ this.dispatchToApp({
422
+ context: {
423
+ event: 'getApplePayToken',
424
+ data: {
425
+ success: false,
426
+ result: _context4.t0
427
+ }
428
+ }
429
+ });
430
+ case 10:
431
+ case "end":
432
+ return _context4.stop();
433
+ }
434
+ }, _callee4, this, [[0, 7]]);
435
+ }));
436
+ function submit() {
437
+ return _submit.apply(this, arguments);
377
438
  }
378
- this.paymentStatus = PAYMENT_STATUS.NORMAL;
379
- (_this$session2 = this.session) === null || _this$session2 === void 0 || (_this$session2$comple = _this$session2.completePayment) === null || _this$session2$comple === void 0 || _this$session2$comple.call(_this$session2, payStatus[status]);
380
- }
439
+ return submit;
440
+ }()
381
441
  }, {
382
- key: "initApplePaySession",
442
+ key: "getDeviceId",
383
443
  value: function () {
384
- var _initApplePaySession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
385
- var _this$logger7, _this$parseData3, _this$logger6, _this$parseData$payme2, recurringInfo, version, _this$logger8;
444
+ var _getDeviceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
445
+ var _yield$BusManager$pub, _this$sessionResult2;
386
446
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
387
447
  while (1) switch (_context5.prev = _context5.next) {
388
448
  case 0:
389
- _context5.prev = 0;
390
- if (!(this.paymentStatus === PAYMENT_STATUS.PENDING)) {
391
- _context5.next = 3;
449
+ _context5.next = 2;
450
+ return BusManager.publishForResult(new BusMessage(SecuritySDKActionEnum.getSecurityDeviceId, JSON.stringify({
451
+ deviceIdParameter: {
452
+ productScene: (_this$sessionResult2 = this.sessionResult) === null || _this$sessionResult2 === void 0 || (_this$sessionResult2 = _this$sessionResult2.paymentSessionConfig) === null || _this$sessionResult2 === void 0 ? void 0 : _this$sessionResult2.productScene
453
+ }
454
+ })), {
455
+ fallback: ''
456
+ });
457
+ case 2:
458
+ _context5.t1 = _yield$BusManager$pub = _context5.sent;
459
+ _context5.t0 = _context5.t1 === null;
460
+ if (_context5.t0) {
461
+ _context5.next = 6;
392
462
  break;
393
463
  }
394
- return _context5.abrupt("return");
395
- case 3:
396
- if (this.isRequiredParameters) {
397
- _context5.next = 7;
464
+ _context5.t0 = _yield$BusManager$pub === void 0;
465
+ case 6:
466
+ if (!_context5.t0) {
467
+ _context5.next = 10;
398
468
  break;
399
469
  }
400
- (_this$logger6 = this.logger) === null || _this$logger6 === void 0 || _this$logger6.logError({
401
- title: 'a3753.b103030.c386485.d507448'
402
- });
403
- this.paymentStatus = PAYMENT_STATUS.NORMAL;
404
- return _context5.abrupt("return", Promise.reject({
405
- errorCode: APPLEPAYERRORENUM.APPLE_PAY_MISSING_DATA
406
- }));
407
- case 7:
408
- (_this$logger7 = this.logger) === null || _this$logger7 === void 0 || _this$logger7.logInfo({
409
- title: 'a3753.b103030.c386485.d507459'
410
- });
411
- _context5.next = 10;
412
- return this.loadApplePaySdk();
470
+ _context5.t2 = void 0;
471
+ _context5.next = 11;
472
+ break;
413
473
  case 10:
474
+ _context5.t2 = _yield$BusManager$pub.getJSONObject();
475
+ case 11:
476
+ return _context5.abrupt("return", _context5.t2);
477
+ case 12:
478
+ case "end":
479
+ return _context5.stop();
480
+ }
481
+ }, _callee5, this);
482
+ }));
483
+ function getDeviceId() {
484
+ return _getDeviceId.apply(this, arguments);
485
+ }
486
+ return getDeviceId;
487
+ }()
488
+ }, {
489
+ key: "initApplePaySession",
490
+ value: function () {
491
+ var _initApplePaySession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
492
+ var version, _this$logger8;
493
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
494
+ while (1) switch (_context6.prev = _context6.next) {
495
+ case 0:
496
+ _context6.prev = 0;
497
+ _context6.next = 3;
498
+ return this.loadApplePaySdk();
499
+ case 3:
414
500
  if ('ApplePaySession' in window) {
415
- _context5.next = 12;
501
+ _context6.next = 5;
416
502
  break;
417
503
  }
418
504
  throw new Error('Apple Pay not supported');
419
- case 12:
420
- _this$parseData$payme2 = (_this$parseData3 = this.parseData) === null || _this$parseData3 === void 0 ? void 0 : _this$parseData3.paymentSessionFactor, recurringInfo = _this$parseData$payme2.recurringInfo;
421
- version = recurringInfo ? APPLE_PAY_RECURRING_VERSION : APPLE_PAY_VERSION;
505
+ case 5:
506
+ version = this.paymentRequest.version;
422
507
  if (this.isCanMakePayments(version)) {
423
- _context5.next = 16;
508
+ _context6.next = 8;
424
509
  break;
425
510
  }
426
511
  throw new Error('Apple Pay not supported');
427
- case 16:
428
- this.session = new window.ApplePaySession(version, this.initSessionParams);
429
- _context5.next = 23;
512
+ case 8:
513
+ this.applePaySession = new window.ApplePaySession(version, this.initSessionParams);
514
+ _context6.next = 15;
430
515
  break;
431
- case 19:
432
- _context5.prev = 19;
433
- _context5.t0 = _context5["catch"](0);
516
+ case 11:
517
+ _context6.prev = 11;
518
+ _context6.t0 = _context6["catch"](0);
434
519
  (_this$logger8 = this.logger) === null || _this$logger8 === void 0 || _this$logger8.logError({
435
- title: 'a3753.b103030.c386485.d507471'
520
+ code: 'a3753.b103030.c386485.d507471'
521
+ }, {
522
+ paymentRequest: JSON.stringify(this.paymentRequest)
436
523
  });
437
- return _context5.abrupt("return", Promise.reject({
524
+ return _context6.abrupt("return", Promise.reject({
438
525
  errorCode: APPLEPAYERRORENUM.APPLE_PAY_NOT_SUPPORTED
439
526
  }));
440
- case 23:
527
+ case 15:
441
528
  case "end":
442
- return _context5.stop();
529
+ return _context6.stop();
443
530
  }
444
- }, _callee5, this, [[0, 19]]);
531
+ }, _callee6, this, [[0, 11]]);
445
532
  }));
446
533
  function initApplePaySession() {
447
534
  return _initApplePaySession.apply(this, arguments);
@@ -449,41 +536,93 @@ export var ApplePaySdk = /*#__PURE__*/function () {
449
536
  return initApplePaySession;
450
537
  }()
451
538
  }, {
452
- key: "abortSession",
453
- value: function abortSession() {
539
+ key: "isCanMakePayments",
540
+ value: function isCanMakePayments() {
541
+ var _window$ApplePaySessi, _window$ApplePaySessi2;
542
+ var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
543
+ return ((_window$ApplePaySessi = window.ApplePaySession) === null || _window$ApplePaySessi === void 0 ? void 0 : _window$ApplePaySessi.canMakePayments()) && ((_window$ApplePaySessi2 = window.ApplePaySession) === null || _window$ApplePaySessi2 === void 0 ? void 0 : _window$ApplePaySessi2.supportsVersion(version));
544
+ }
545
+ }, {
546
+ key: "loadApplePaySdk",
547
+ value: function loadApplePaySdk() {
548
+ var _this2 = this;
549
+ if (device.Android) {
550
+ return Promise.reject('APPLE_PAY_NOT_SUPPORTED');
551
+ }
552
+ // 如果支持或者已经加载sdk直接返回
553
+ if (this.checkScriptIsLoaded || this.isCanMakePayments()) {
554
+ return Promise.resolve(true);
555
+ }
556
+ return new Promise(function (resolve, reject) {
557
+ var script = document.createElement('script');
558
+ script.src = _this2.APPLESDKURL;
559
+ script.onload = function () {
560
+ resolve(true);
561
+ };
562
+ script.onerror = function () {
563
+ reject(false);
564
+ };
565
+ document.body.appendChild(script);
566
+ });
567
+ }
568
+ }, {
569
+ key: "abortPaySession",
570
+ value: function abortPaySession() {
454
571
  try {
455
- var _this$session$abort, _this$session3;
572
+ var _this$applePaySession5, _this$applePaySession6;
456
573
  this.paymentStatus = PAYMENT_STATUS.NORMAL;
457
- this.session && ((_this$session$abort = (_this$session3 = this.session).abort) === null || _this$session$abort === void 0 ? void 0 : _this$session$abort.call(_this$session3));
574
+ this.applePaySession && ((_this$applePaySession5 = (_this$applePaySession6 = this.applePaySession).abort) === null || _this$applePaySession5 === void 0 ? void 0 : _this$applePaySession5.call(_this$applePaySession6));
458
575
  } catch (e) {
459
576
  console.error('abortPaySession error', e);
460
- } finally {
461
- this.session = null;
462
577
  }
463
578
  }
579
+ }, {
580
+ key: "addEventListener",
581
+ value: function addEventListener(reject) {
582
+ var _this3 = this;
583
+ var appleModal = document.querySelector('apple-pay-modal');
584
+ var shadowRoot = appleModal === null || appleModal === void 0 ? void 0 : appleModal.shadowRoot;
585
+ var closeButton = (shadowRoot === null || shadowRoot === void 0 ? void 0 : shadowRoot.querySelector('.modal-close-button')) || null;
586
+ var callFn = function callFn() {
587
+ var _this3$logger;
588
+ (_this3$logger = _this3.logger) === null || _this3$logger === void 0 || _this3$logger.logInfo({
589
+ code: 'a3753.b103030.c386485.d507470'
590
+ });
591
+ _this3.abortPaySession();
592
+ closeButton === null || closeButton === void 0 || closeButton.removeEventListener('click', callFn);
593
+ return reject === null || reject === void 0 ? void 0 : reject({
594
+ errorCode: APPLEPAYERRORENUM.APPLE_PAY_CANCEL
595
+ });
596
+ };
597
+ closeButton === null || closeButton === void 0 || closeButton.addEventListener('click', callFn, {
598
+ once: true
599
+ });
600
+ }
464
601
  }, {
465
602
  key: "initSessionParams",
466
603
  get: function get() {
467
- var _this$parseData4;
468
- var _ref4 = ((_this$parseData4 = this.parseData) === null || _this$parseData4 === void 0 ? void 0 : _this$parseData4.paymentSessionFactor) || {},
469
- merchantInfo = _ref4.merchantInfo,
470
- order = _ref4.order,
471
- paymentAmount = _ref4.paymentAmount,
472
- recurringInfo = _ref4.recurringInfo,
473
- extendInfo = _ref4.extendInfo;
474
- var request = {
604
+ var _this$sessionResult3;
605
+ var _this$paymentRequest3 = this.paymentRequest,
606
+ supportedNetworks = _this$paymentRequest3.supportedNetworks,
607
+ requiredBillingContactFields = _this$paymentRequest3.requiredBillingContactFields,
608
+ requiredShippingContactFields = _this$paymentRequest3.requiredShippingContactFields,
609
+ merchantCapabilities = _this$paymentRequest3.merchantCapabilities;
610
+ var _ref3 = ((_this$sessionResult3 = this.sessionResult) === null || _this$sessionResult3 === void 0 ? void 0 : _this$sessionResult3.paymentSessionFactor) || {},
611
+ merchantInfo = _ref3.merchantInfo,
612
+ order = _ref3.order,
613
+ paymentAmount = _ref3.paymentAmount,
614
+ recurringInfo = _ref3.recurringInfo;
615
+ var request = _objectSpread(_objectSpread({
475
616
  countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
476
617
  currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
477
- merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
478
- supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
618
+ merchantCapabilities: merchantCapabilities,
619
+ supportedNetworks: supportedNetworks,
479
620
  total: {
480
621
  label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
481
622
  type: 'final',
482
623
  amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
483
- },
484
- requiredBillingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredBillingContactFields,
485
- requiredShippingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredShippingContactFields
486
- };
624
+ }
625
+ }, requiredBillingContactFields ? requiredBillingContactFields : null), requiredShippingContactFields ? requiredShippingContactFields : null);
487
626
  if (recurringInfo) {
488
627
  var _recurringInfo$interv;
489
628
  if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
@@ -515,127 +654,24 @@ export var ApplePaySdk = /*#__PURE__*/function () {
515
654
  }, {
516
655
  key: "isRequiredParameters",
517
656
  get: function get() {
518
- var _this$parseData5;
519
- var _ref5 = ((_this$parseData5 = this.parseData) === null || _this$parseData5 === void 0 ? void 0 : _this$parseData5.paymentSessionFactor) || {},
520
- merchantInfo = _ref5.merchantInfo,
521
- extendInfo = _ref5.extendInfo,
522
- paymentAmount = _ref5.paymentAmount;
523
- return !isEmpty(merchantInfo) && !isEmpty(paymentAmount) && !isEmpty(extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks) && !isEmpty(extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities);
524
- }
525
- }, {
526
- key: "isCanMakePayments",
527
- value: function isCanMakePayments() {
528
- var _window$ApplePaySessi, _window$ApplePaySessi2;
529
- var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
530
- return ((_window$ApplePaySessi = window.ApplePaySession) === null || _window$ApplePaySessi === void 0 ? void 0 : _window$ApplePaySessi.canMakePayments()) && ((_window$ApplePaySessi2 = window.ApplePaySession) === null || _window$ApplePaySessi2 === void 0 ? void 0 : _window$ApplePaySessi2.supportsVersion(version));
531
- }
532
- }, {
533
- key: "loadApplePaySdk",
534
- value: function loadApplePaySdk() {
535
- var _this2 = this;
536
- if (device.Android) {
537
- return Promise.reject('APPLE_PAY_NOT_SUPPORTED');
538
- }
539
- // 如果支持或者已经加载sdk直接返回
540
- if (this.checkScriptIsLoaded || this.isCanMakePayments()) {
541
- return Promise.resolve(true);
542
- }
543
- return new Promise(function (resolve, reject) {
544
- var script = document.createElement('script');
545
- script.src = _this2.APPLESDKURL;
546
- script.onload = function () {
547
- resolve(true);
548
- };
549
- script.onerror = function () {
550
- reject(false);
551
- };
552
- document.body.appendChild(script);
553
- });
657
+ if (!this.paymentRequest) return false;
658
+ var _this$paymentRequest4 = this.paymentRequest,
659
+ _this$paymentRequest5 = _this$paymentRequest4.supportedNetworks,
660
+ supportedNetworks = _this$paymentRequest5 === void 0 ? [] : _this$paymentRequest5,
661
+ _this$paymentRequest6 = _this$paymentRequest4.merchantCapabilities,
662
+ merchantCapabilities = _this$paymentRequest6 === void 0 ? [] : _this$paymentRequest6,
663
+ version = _this$paymentRequest4.version;
664
+ var _ref4 = this.sessionResult || {},
665
+ paymentSessionFactor = _ref4.paymentSessionFactor;
666
+ var isSupportedNetworks = Array.isArray(supportedNetworks) && supportedNetworks.length > 0;
667
+ var isMerchantCapabilities = Array.isArray(merchantCapabilities) && merchantCapabilities.length > 0;
668
+ return !(!version || !isSupportedNetworks || !(paymentSessionFactor !== null && paymentSessionFactor !== void 0 && paymentSessionFactor.merchantInfo) || !(paymentSessionFactor !== null && paymentSessionFactor !== void 0 && paymentSessionFactor.paymentAmount) || !isMerchantCapabilities);
554
669
  }
555
670
  }, {
556
671
  key: "checkScriptIsLoaded",
557
672
  get: function get() {
558
673
  return !!document.querySelector("script[src=\"".concat(this.APPLESDKURL, "\"]"));
559
674
  }
560
- /**
561
- * @description 非标方案,sdk目前无法直接监听国内不支持弹窗的关闭操作
562
- */
563
- }, {
564
- key: "addEventListener",
565
- value: function addEventListener(reject) {
566
- var _this3 = this;
567
- var appleModal = document.querySelector('apple-pay-modal');
568
- var shadowRoot = appleModal === null || appleModal === void 0 ? void 0 : appleModal.shadowRoot;
569
- var closeButton = (shadowRoot === null || shadowRoot === void 0 ? void 0 : shadowRoot.querySelector('.modal-close-button')) || null;
570
- if (!closeButton) {
571
- this.logger.logInfo({
572
- title: 'a3753.b103030.c386485.d533112'
573
- });
574
- }
575
- var callFn = function callFn() {
576
- var _this3$logger;
577
- (_this3$logger = _this3.logger) === null || _this3$logger === void 0 || _this3$logger.logInfo({
578
- title: 'a3753.b103030.c386485.d507470'
579
- });
580
- _this3.abortSession();
581
- closeButton === null || closeButton === void 0 || closeButton.removeEventListener('click', callFn);
582
- reject === null || reject === void 0 || reject();
583
- };
584
- closeButton === null || closeButton === void 0 || closeButton.addEventListener('click', callFn, {
585
- once: true
586
- });
587
- }
588
- }, {
589
- key: "getDeviceId",
590
- value: function () {
591
- var _getDeviceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
592
- var _yield$BusManager$pub, _this$parseData6;
593
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
594
- while (1) switch (_context6.prev = _context6.next) {
595
- case 0:
596
- _context6.next = 2;
597
- return BusManager.publishForResult(new BusMessage(SecuritySDKActionEnum.getSecurityDeviceId, JSON.stringify({
598
- deviceIdParameter: {
599
- productScene: (_this$parseData6 = this.parseData) === null || _this$parseData6 === void 0 || (_this$parseData6 = _this$parseData6.paymentSessionConfig) === null || _this$parseData6 === void 0 ? void 0 : _this$parseData6.productScene
600
- }
601
- })), {
602
- fallback: ''
603
- });
604
- case 2:
605
- _context6.t1 = _yield$BusManager$pub = _context6.sent;
606
- _context6.t0 = _context6.t1 === null;
607
- if (_context6.t0) {
608
- _context6.next = 6;
609
- break;
610
- }
611
- _context6.t0 = _yield$BusManager$pub === void 0;
612
- case 6:
613
- if (!_context6.t0) {
614
- _context6.next = 10;
615
- break;
616
- }
617
- _context6.t2 = void 0;
618
- _context6.next = 11;
619
- break;
620
- case 10:
621
- _context6.t2 = _yield$BusManager$pub.getJSONObject();
622
- case 11:
623
- return _context6.abrupt("return", _context6.t2);
624
- case 12:
625
- case "end":
626
- return _context6.stop();
627
- }
628
- }, _callee6, this);
629
- }));
630
- function getDeviceId() {
631
- return _getDeviceId.apply(this, arguments);
632
- }
633
- return getDeviceId;
634
- }()
635
675
  }]);
636
- return ApplePaySdk;
637
- }();
638
- export var isSkipRenderPaymentMethod = function isSkipRenderPaymentMethod(parseData) {
639
- var _parseData$paymentSes;
640
- return (parseData === null || parseData === void 0 ? void 0 : parseData.skipRenderPaymentMethod) && (parseData === null || parseData === void 0 || (_parseData$paymentSes = parseData.paymentSessionFactor) === null || _parseData$paymentSes === void 0 || (_parseData$paymentSes = _parseData$paymentSes.paymentMethodInfo) === null || _parseData$paymentSes === void 0 ? void 0 : _parseData$paymentSes.paymentMethodType) === 'APPLEPAY';
641
- };
676
+ return ApplePayService;
677
+ }();