@alipay/ams-checkout 0.0.1735810732-dev.0 → 0.0.1737621505-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +7 -7
- package/esm/constant/index.d.ts +9 -0
- package/esm/constant/index.js +9 -0
- package/esm/core/component/element/index.d.ts +3 -0
- package/esm/core/component/element/index.js +154 -76
- package/esm/core/component/element/mock.d.ts +2 -0
- package/esm/core/component/element/mock.js +129 -53
- package/esm/core/component/element/type.d.ts +2 -2
- package/esm/core/component/element/type.js +2 -2
- package/esm/core/component/index.js +2 -2
- package/esm/foundation/core/index.js +4 -4
- package/esm/plugin/applepay/interface.d.ts +2 -2
- package/esm/plugin/component/channel.d.ts +35 -1
- package/esm/plugin/component/channel.js +551 -0
- package/esm/plugin/component/index.d.ts +1 -1
- package/esm/plugin/component/index.js +93 -39
- package/esm/types/index.d.ts +37 -3
- package/esm/types/index.js +5 -2
- package/esm/util/index.d.ts +2 -1
- package/esm/util/index.js +16 -1
- package/esm/util/versionCompare.d.ts +1 -1
- package/package.json +1 -1
@@ -1,3 +1,32 @@
|
|
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 _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
|
+
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
|
+
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); }); }; }
|
5
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6
|
+
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); } }
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
8
|
+
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; }
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
10
|
+
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); }
|
11
|
+
import { BusManager, BusMessage } from "../../core/bus";
|
12
|
+
import { SecuritySDKActionEnum } from "../../core/bus/interface";
|
13
|
+
import { getApplePayPaymentSession, submitPayInfo } from "../../service";
|
14
|
+
import { EnvironmentEnum } from "../../types";
|
15
|
+
import { device, isEmpty } from "../../util";
|
16
|
+
import { APPLE_PAY_RECURRING_VERSION, APPLE_PAY_VERSION } from "../applepay/interface";
|
17
|
+
var APPLEPAYERRORENUM = /*#__PURE__*/function (APPLEPAYERRORENUM) {
|
18
|
+
APPLEPAYERRORENUM["APPLE_PAY_MISSING_DATA"] = "APPLE_PAY_MISSING_DATA";
|
19
|
+
APPLEPAYERRORENUM["APPLE_PAY_NOT_SUPPORTED"] = "APPLE_PAY_NOT_SUPPORTED";
|
20
|
+
APPLEPAYERRORENUM["APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED"] = "APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED";
|
21
|
+
APPLEPAYERRORENUM["APPLE_PAY_TOKEN_ERROR"] = "APPLE_PAY_TOKEN_ERROR";
|
22
|
+
APPLEPAYERRORENUM["APPLE_PAY_CANCEL"] = "APPLE_PAY_CANCEL";
|
23
|
+
return APPLEPAYERRORENUM;
|
24
|
+
}(APPLEPAYERRORENUM || {});
|
25
|
+
var PAYMENT_STATUS = /*#__PURE__*/function (PAYMENT_STATUS) {
|
26
|
+
PAYMENT_STATUS["PENDING"] = "PENDING";
|
27
|
+
PAYMENT_STATUS["NORMAL"] = "NORMAL";
|
28
|
+
return PAYMENT_STATUS;
|
29
|
+
}(PAYMENT_STATUS || {});
|
1
30
|
export function getChannelBehavior(paymentSessionMetaData) {
|
2
31
|
var _paymentSessionMetaDa, _paymentSessionMetaDa2, _paymentSessionMetaDa3, _paymentSessionMetaDa4, _paymentSessionMetaDa5, _paymentSessionMetaDa6, _paymentSessionMetaDa7, _paymentSessionMetaDa8;
|
3
32
|
// TOSS EASYPAY 2.0
|
@@ -86,4 +115,526 @@ export var handleGooglePay = function handleGooglePay(data) {
|
|
86
115
|
});
|
87
116
|
};
|
88
117
|
});
|
118
|
+
};
|
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);
|
125
|
+
_defineProperty(this, "APPLESDKURL", 'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js');
|
126
|
+
_defineProperty(this, "session", null);
|
127
|
+
_defineProperty(this, "paymentSessionData", void 0);
|
128
|
+
_defineProperty(this, "parseData", void 0);
|
129
|
+
/**
|
130
|
+
* @description 支付状态,pending:支付中,normal:正常
|
131
|
+
*/
|
132
|
+
_defineProperty(this, "paymentStatus", void 0);
|
133
|
+
_defineProperty(this, "logger", void 0);
|
134
|
+
this.paymentSessionData = paymentSessionData;
|
135
|
+
this.parseData = parseData;
|
136
|
+
this.logger = logger;
|
137
|
+
}
|
138
|
+
_createClass(ApplePaySdk, [{
|
139
|
+
key: "startPay",
|
140
|
+
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) {
|
144
|
+
case 0:
|
145
|
+
_context.prev = 0;
|
146
|
+
_context.next = 3;
|
147
|
+
return this.initApplePaySession();
|
148
|
+
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();
|
225
|
+
reject({
|
226
|
+
errorCode: APPLEPAYERRORENUM.APPLE_PAY_PAYMENT_SESSION_REQUEST_FAILED
|
227
|
+
});
|
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 = {
|
258
|
+
instPaymentToken: JSON.stringify(token)
|
259
|
+
};
|
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) {
|
262
|
+
obj['applePayBillingContact'] = JSON.stringify(billingContact);
|
263
|
+
}
|
264
|
+
if (!isEmpty(requiredShippingContactFields) && shippingContact) {
|
265
|
+
obj['applePayShippingContact'] = JSON.stringify(shippingContact);
|
266
|
+
}
|
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'
|
278
|
+
});
|
279
|
+
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
|
+
});
|
313
|
+
}
|
314
|
+
}, {
|
315
|
+
key: "submitPay",
|
316
|
+
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) {
|
321
|
+
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,
|
326
|
+
paymentSessionData: this.paymentSessionData,
|
327
|
+
paymentFactors: params,
|
328
|
+
paymentMethod: {
|
329
|
+
paymentMethodType: 'APPLEPAY'
|
330
|
+
}
|
331
|
+
};
|
332
|
+
_context4.t2 = EnvironmentEnum.prod;
|
333
|
+
_context4.next = 6;
|
334
|
+
return this.getDeviceId();
|
335
|
+
case 6:
|
336
|
+
_context4.t3 = _context4.sent;
|
337
|
+
_context4.t4 = {
|
338
|
+
deviceId: _context4.t3
|
339
|
+
};
|
340
|
+
_context4.t5 = {
|
341
|
+
env: _context4.t2,
|
342
|
+
envInfo: _context4.t4
|
343
|
+
};
|
344
|
+
_context4.t6 = this.logger;
|
345
|
+
_context4.next = 12;
|
346
|
+
return (0, _context4.t0)(_context4.t1, _context4.t5, _context4.t6);
|
347
|
+
case 12:
|
348
|
+
return _context4.abrupt("return", _context4.sent);
|
349
|
+
case 15:
|
350
|
+
_context4.prev = 15;
|
351
|
+
_context4.t7 = _context4["catch"](0);
|
352
|
+
case 17:
|
353
|
+
case "end":
|
354
|
+
return _context4.stop();
|
355
|
+
}
|
356
|
+
}, _callee4, this, [[0, 15]]);
|
357
|
+
}));
|
358
|
+
function submitPay(_x3) {
|
359
|
+
return _submitPay.apply(this, arguments);
|
360
|
+
}
|
361
|
+
return submitPay;
|
362
|
+
}()
|
363
|
+
}, {
|
364
|
+
key: "setPayStatus",
|
365
|
+
value: function setPayStatus(result) {
|
366
|
+
var _this$session2, _this$session2$comple;
|
367
|
+
var payStatus = {
|
368
|
+
success: window.ApplePaySession.STATUS_SUCCESS,
|
369
|
+
fail: window.ApplePaySession.STATUS_FAILURE
|
370
|
+
};
|
371
|
+
var status;
|
372
|
+
if (result !== null && result !== void 0 && result.success || (result === null || result === void 0 ? void 0 : result.errorStatus) === 'U') {
|
373
|
+
status = 'success';
|
374
|
+
} else {
|
375
|
+
status = 'fail';
|
376
|
+
}
|
377
|
+
this.paymentStatus = PAYMENT_STATUS.NORMAL;
|
378
|
+
(_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]);
|
379
|
+
}
|
380
|
+
}, {
|
381
|
+
key: "initApplePaySession",
|
382
|
+
value: function () {
|
383
|
+
var _initApplePaySession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
384
|
+
var _this$logger7, _this$parseData3, _this$logger6, _this$parseData$payme2, recurringInfo, version, _this$logger8;
|
385
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
386
|
+
while (1) switch (_context5.prev = _context5.next) {
|
387
|
+
case 0:
|
388
|
+
_context5.prev = 0;
|
389
|
+
if (!(this.paymentStatus === PAYMENT_STATUS.PENDING)) {
|
390
|
+
_context5.next = 3;
|
391
|
+
break;
|
392
|
+
}
|
393
|
+
return _context5.abrupt("return");
|
394
|
+
case 3:
|
395
|
+
if (this.isRequiredParameters) {
|
396
|
+
_context5.next = 7;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
(_this$logger6 = this.logger) === null || _this$logger6 === void 0 || _this$logger6.logError({
|
400
|
+
title: 'a3753.b103030.c386485.d507448'
|
401
|
+
});
|
402
|
+
this.paymentStatus = PAYMENT_STATUS.NORMAL;
|
403
|
+
return _context5.abrupt("return", Promise.reject({
|
404
|
+
errorCode: APPLEPAYERRORENUM.APPLE_PAY_MISSING_DATA
|
405
|
+
}));
|
406
|
+
case 7:
|
407
|
+
(_this$logger7 = this.logger) === null || _this$logger7 === void 0 || _this$logger7.logInfo({
|
408
|
+
title: 'a3753.b103030.c386485.d507459'
|
409
|
+
});
|
410
|
+
_context5.next = 10;
|
411
|
+
return this.loadApplePaySdk();
|
412
|
+
case 10:
|
413
|
+
if ('ApplePaySession' in window) {
|
414
|
+
_context5.next = 12;
|
415
|
+
break;
|
416
|
+
}
|
417
|
+
throw new Error('Apple Pay not supported');
|
418
|
+
case 12:
|
419
|
+
_this$parseData$payme2 = (_this$parseData3 = this.parseData) === null || _this$parseData3 === void 0 ? void 0 : _this$parseData3.paymentSessionFactor, recurringInfo = _this$parseData$payme2.recurringInfo;
|
420
|
+
version = recurringInfo ? APPLE_PAY_RECURRING_VERSION : APPLE_PAY_VERSION;
|
421
|
+
if (this.isCanMakePayments(version)) {
|
422
|
+
_context5.next = 16;
|
423
|
+
break;
|
424
|
+
}
|
425
|
+
throw new Error('Apple Pay not supported');
|
426
|
+
case 16:
|
427
|
+
this.session = new window.ApplePaySession(version, this.initSessionParams);
|
428
|
+
_context5.next = 23;
|
429
|
+
break;
|
430
|
+
case 19:
|
431
|
+
_context5.prev = 19;
|
432
|
+
_context5.t0 = _context5["catch"](0);
|
433
|
+
(_this$logger8 = this.logger) === null || _this$logger8 === void 0 || _this$logger8.logError({
|
434
|
+
title: 'a3753.b103030.c386485.d507471'
|
435
|
+
});
|
436
|
+
return _context5.abrupt("return", Promise.reject({
|
437
|
+
errorCode: APPLEPAYERRORENUM.APPLE_PAY_NOT_SUPPORTED
|
438
|
+
}));
|
439
|
+
case 23:
|
440
|
+
case "end":
|
441
|
+
return _context5.stop();
|
442
|
+
}
|
443
|
+
}, _callee5, this, [[0, 19]]);
|
444
|
+
}));
|
445
|
+
function initApplePaySession() {
|
446
|
+
return _initApplePaySession.apply(this, arguments);
|
447
|
+
}
|
448
|
+
return initApplePaySession;
|
449
|
+
}()
|
450
|
+
}, {
|
451
|
+
key: "abortSession",
|
452
|
+
value: function abortSession() {
|
453
|
+
try {
|
454
|
+
var _this$session$abort, _this$session3;
|
455
|
+
this.paymentStatus = PAYMENT_STATUS.NORMAL;
|
456
|
+
this.session && ((_this$session$abort = (_this$session3 = this.session).abort) === null || _this$session$abort === void 0 ? void 0 : _this$session$abort.call(_this$session3));
|
457
|
+
} catch (e) {
|
458
|
+
console.error('abortPaySession error', e);
|
459
|
+
} finally {
|
460
|
+
this.session = null;
|
461
|
+
}
|
462
|
+
}
|
463
|
+
}, {
|
464
|
+
key: "initSessionParams",
|
465
|
+
get: function get() {
|
466
|
+
var _this$parseData4;
|
467
|
+
var _ref4 = ((_this$parseData4 = this.parseData) === null || _this$parseData4 === void 0 ? void 0 : _this$parseData4.paymentSessionFactor) || {},
|
468
|
+
merchantInfo = _ref4.merchantInfo,
|
469
|
+
order = _ref4.order,
|
470
|
+
paymentAmount = _ref4.paymentAmount,
|
471
|
+
recurringInfo = _ref4.recurringInfo,
|
472
|
+
extendInfo = _ref4.extendInfo;
|
473
|
+
var request = {
|
474
|
+
countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
|
475
|
+
currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
|
476
|
+
merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
|
477
|
+
supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
|
478
|
+
total: {
|
479
|
+
label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
|
480
|
+
type: 'final',
|
481
|
+
amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
|
482
|
+
},
|
483
|
+
requiredBillingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredBillingContactFields,
|
484
|
+
requiredShippingContactFields: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.requiredShippingContactFields
|
485
|
+
};
|
486
|
+
if (recurringInfo) {
|
487
|
+
var _recurringInfo$interv;
|
488
|
+
if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
|
489
|
+
return;
|
490
|
+
}
|
491
|
+
var lineItem = {
|
492
|
+
type: 'final',
|
493
|
+
label: recurringInfo.title,
|
494
|
+
amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value,
|
495
|
+
paymentTiming: 'recurring',
|
496
|
+
recurringPaymentStartDate: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.startDate ? new Date(Number(recurringInfo.startDate) * 1000) : undefined,
|
497
|
+
recurringPaymentEndDate: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.endDate ? new Date(Number(recurringInfo.endDate) * 1000) : undefined,
|
498
|
+
recurringPaymentIntervalUnit: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.intervalUnit ? recurringInfo.intervalUnit : 'month',
|
499
|
+
recurringPaymentIntervalCount: (_recurringInfo$interv = recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.intervalCount) !== null && _recurringInfo$interv !== void 0 ? _recurringInfo$interv : 1
|
500
|
+
};
|
501
|
+
var recurringRequest = {
|
502
|
+
paymentDescription: order === null || order === void 0 ? void 0 : order.orderDescription,
|
503
|
+
billingAgreement: recurringInfo.agreementDescription,
|
504
|
+
regularBilling: lineItem,
|
505
|
+
managementURL: recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.managementURL,
|
506
|
+
tokenNotificationURL: recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.tokenNotificationURL
|
507
|
+
};
|
508
|
+
request.total = lineItem;
|
509
|
+
request.lineItems = [lineItem];
|
510
|
+
request.recurringPaymentRequest = recurringRequest;
|
511
|
+
}
|
512
|
+
return request;
|
513
|
+
}
|
514
|
+
}, {
|
515
|
+
key: "isRequiredParameters",
|
516
|
+
get: function get() {
|
517
|
+
var _this$parseData5;
|
518
|
+
var _ref5 = ((_this$parseData5 = this.parseData) === null || _this$parseData5 === void 0 ? void 0 : _this$parseData5.paymentSessionFactor) || {},
|
519
|
+
merchantInfo = _ref5.merchantInfo,
|
520
|
+
extendInfo = _ref5.extendInfo,
|
521
|
+
paymentAmount = _ref5.paymentAmount;
|
522
|
+
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);
|
523
|
+
}
|
524
|
+
}, {
|
525
|
+
key: "isCanMakePayments",
|
526
|
+
value: function isCanMakePayments() {
|
527
|
+
var _window$ApplePaySessi, _window$ApplePaySessi2;
|
528
|
+
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
|
529
|
+
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));
|
530
|
+
}
|
531
|
+
}, {
|
532
|
+
key: "loadApplePaySdk",
|
533
|
+
value: function loadApplePaySdk() {
|
534
|
+
var _this2 = this;
|
535
|
+
if (device.Android) {
|
536
|
+
return Promise.reject('APPLE_PAY_NOT_SUPPORTED');
|
537
|
+
}
|
538
|
+
// 如果支持或者已经加载sdk直接返回
|
539
|
+
if (this.checkScriptIsLoaded || this.isCanMakePayments()) {
|
540
|
+
return Promise.resolve(true);
|
541
|
+
}
|
542
|
+
return new Promise(function (resolve, reject) {
|
543
|
+
var script = document.createElement('script');
|
544
|
+
script.src = _this2.APPLESDKURL;
|
545
|
+
script.onload = function () {
|
546
|
+
resolve(true);
|
547
|
+
};
|
548
|
+
script.onerror = function () {
|
549
|
+
reject(false);
|
550
|
+
};
|
551
|
+
document.body.appendChild(script);
|
552
|
+
});
|
553
|
+
}
|
554
|
+
}, {
|
555
|
+
key: "checkScriptIsLoaded",
|
556
|
+
get: function get() {
|
557
|
+
return !!document.querySelector("script[src=\"".concat(this.APPLESDKURL, "\"]"));
|
558
|
+
}
|
559
|
+
/**
|
560
|
+
* @description 非标方案,sdk目前无法直接监听国内不支持弹窗的关闭操作
|
561
|
+
*/
|
562
|
+
}, {
|
563
|
+
key: "addEventListener",
|
564
|
+
value: function addEventListener(reject) {
|
565
|
+
var _this3 = this;
|
566
|
+
var appleModal = document.querySelector('apple-pay-modal');
|
567
|
+
var shadowRoot = appleModal === null || appleModal === void 0 ? void 0 : appleModal.shadowRoot;
|
568
|
+
var closeButton = (shadowRoot === null || shadowRoot === void 0 ? void 0 : shadowRoot.querySelector('.modal-close-button')) || null;
|
569
|
+
if (!closeButton) {
|
570
|
+
this.logger.logInfo({
|
571
|
+
title: 'a3753.b103030.c386485.d533112'
|
572
|
+
});
|
573
|
+
}
|
574
|
+
var callFn = function callFn() {
|
575
|
+
var _this3$logger;
|
576
|
+
(_this3$logger = _this3.logger) === null || _this3$logger === void 0 || _this3$logger.logInfo({
|
577
|
+
title: 'a3753.b103030.c386485.d507470'
|
578
|
+
});
|
579
|
+
_this3.abortSession();
|
580
|
+
closeButton === null || closeButton === void 0 || closeButton.removeEventListener('click', callFn);
|
581
|
+
reject === null || reject === void 0 || reject();
|
582
|
+
};
|
583
|
+
closeButton === null || closeButton === void 0 || closeButton.addEventListener('click', callFn, {
|
584
|
+
once: true
|
585
|
+
});
|
586
|
+
}
|
587
|
+
}, {
|
588
|
+
key: "getDeviceId",
|
589
|
+
value: function () {
|
590
|
+
var _getDeviceId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
591
|
+
var _yield$BusManager$pub, _this$parseData6;
|
592
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
593
|
+
while (1) switch (_context6.prev = _context6.next) {
|
594
|
+
case 0:
|
595
|
+
_context6.next = 2;
|
596
|
+
return BusManager.publishForResult(new BusMessage(SecuritySDKActionEnum.getSecurityDeviceId, JSON.stringify({
|
597
|
+
deviceIdParameter: {
|
598
|
+
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
|
599
|
+
}
|
600
|
+
})), {
|
601
|
+
fallback: ''
|
602
|
+
});
|
603
|
+
case 2:
|
604
|
+
_context6.t1 = _yield$BusManager$pub = _context6.sent;
|
605
|
+
_context6.t0 = _context6.t1 === null;
|
606
|
+
if (_context6.t0) {
|
607
|
+
_context6.next = 6;
|
608
|
+
break;
|
609
|
+
}
|
610
|
+
_context6.t0 = _yield$BusManager$pub === void 0;
|
611
|
+
case 6:
|
612
|
+
if (!_context6.t0) {
|
613
|
+
_context6.next = 10;
|
614
|
+
break;
|
615
|
+
}
|
616
|
+
_context6.t2 = void 0;
|
617
|
+
_context6.next = 11;
|
618
|
+
break;
|
619
|
+
case 10:
|
620
|
+
_context6.t2 = _yield$BusManager$pub.getJSONObject();
|
621
|
+
case 11:
|
622
|
+
return _context6.abrupt("return", _context6.t2);
|
623
|
+
case 12:
|
624
|
+
case "end":
|
625
|
+
return _context6.stop();
|
626
|
+
}
|
627
|
+
}, _callee6, this);
|
628
|
+
}));
|
629
|
+
function getDeviceId() {
|
630
|
+
return _getDeviceId.apply(this, arguments);
|
631
|
+
}
|
632
|
+
return getDeviceId;
|
633
|
+
}()
|
634
|
+
}]);
|
635
|
+
return ApplePaySdk;
|
636
|
+
}();
|
637
|
+
export var isSkipRenderPaymentMethod = function isSkipRenderPaymentMethod(parseData) {
|
638
|
+
var _parseData$paymentSes;
|
639
|
+
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';
|
89
640
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type AMSCheckout from '../../core/instance';
|
2
2
|
import type { EventPayload, EventPayloadContext, IappendIframeNodesParams, IMerchantAppointParam, Iselector } from '../../types';
|
3
|
-
import { ComponentSignEnum, DeviceIdParameter,
|
3
|
+
import { ComponentSignEnum, DeviceIdParameter, DisplayTypeEnum, PlatformEnum } from '../../types';
|
4
4
|
type IrenderFuncParams = (context: ComponentApp, selector: Iselector, renderDisplayType: DisplayTypeEnum) => Promise<void>;
|
5
5
|
export default class ComponentApp {
|
6
6
|
app: null | HTMLIFrameElement;
|