@alipay/ams-checkout 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,389 @@
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; }
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; }
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); } }
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); }); }; }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
11
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
14
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
15
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
+ 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; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
19
+ 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); }
20
+ import { BusManager, BusMessage, BusSubscriber } from "../../core/bus";
21
+ import { PaypalActionEnum, SDKCallbackActionEnum } from "../../core/bus/interface";
22
+ import { queryPaymentInfo } from "../../service";
23
+ import { eventCodeEnum, payPalConfigurationIntentEnum, PaypalMethodEnum } from "../../types";
24
+ import { isFunction } from "../../util";
25
+ import { appendLoadingIcon, isShowLoading } from "../utils";
26
+ export var PaypalBusSubscriber = /*#__PURE__*/function (_BusSubscriber) {
27
+ _inherits(PaypalBusSubscriber, _BusSubscriber);
28
+ var _super = _createSuper(PaypalBusSubscriber);
29
+ function PaypalBusSubscriber(logger) {
30
+ var _this;
31
+ _classCallCheck(this, PaypalBusSubscriber);
32
+ _this = _super.call(this);
33
+ _defineProperty(_assertThisInitialized(_this), "logger", void 0);
34
+ _defineProperty(_assertThisInitialized(_this), "onEventCallback", function (state) {
35
+ BusManager.publish(new BusMessage(SDKCallbackActionEnum.onEventCallback, JSON.stringify(state)));
36
+ });
37
+ _defineProperty(_assertThisInitialized(_this), "appendPaypalLoading", function (_ref) {
38
+ var selector = _ref.selector;
39
+ if (document.querySelector('.paypal-loading')) {
40
+ return;
41
+ }
42
+ var container = document.querySelector(selector);
43
+ container.innerHTML = '';
44
+ var loadingDiv = document.createElement('div');
45
+ loadingDiv.className = 'paypal-loading';
46
+ loadingDiv.style.backgroundColor = '#EBEBEB';
47
+ loadingDiv.style.width = '100%';
48
+ loadingDiv.style.height = '64px';
49
+ loadingDiv.style.borderRadius = '4px';
50
+ var loadingImage = document.createElement('div');
51
+ loadingImage.style.position = 'absolute';
52
+ loadingImage.style.top = '50%';
53
+ loadingImage.style.left = '50%';
54
+ loadingImage.style.transform = 'translate(-50%, -50%)';
55
+ loadingDiv.style.maxWidth = '750px';
56
+ loadingDiv.style.position = 'relative';
57
+ appendLoadingIcon({
58
+ htmlElement: loadingImage,
59
+ loadingWidth: '25px',
60
+ loadingHeight: '25px'
61
+ });
62
+ loadingDiv.appendChild(loadingImage);
63
+ container.appendChild(loadingDiv);
64
+ });
65
+ _defineProperty(_assertThisInitialized(_this), "removePaypalLoading", function () {
66
+ var loadingDiv = document.querySelector('.paypal-loading');
67
+
68
+ // 如果找到了该类元素,则从DOM中移除
69
+ if (loadingDiv) {
70
+ loadingDiv.remove();
71
+ }
72
+ });
73
+ _defineProperty(_assertThisInitialized(_this), "preCheck", function (paypalPluginProps) {
74
+ var _paypalPluginProps$pa, _paypalPluginProps$pa2;
75
+ var boundPaymentMethod = (_paypalPluginProps$pa = paypalPluginProps.paymentSessionFactor) === null || _paypalPluginProps$pa === void 0 || (_paypalPluginProps$pa = _paypalPluginProps$pa.paymentMethodInfo) === null || _paypalPluginProps$pa === void 0 || (_paypalPluginProps$pa = _paypalPluginProps$pa.paymentMethodMetaData) === null || _paypalPluginProps$pa === void 0 ? void 0 : _paypalPluginProps$pa.boundPaymentMethod;
76
+ var paymentMethodType = (_paypalPluginProps$pa2 = paypalPluginProps.paymentSessionFactor) === null || _paypalPluginProps$pa2 === void 0 || (_paypalPluginProps$pa2 = _paypalPluginProps$pa2.paymentMethodInfo) === null || _paypalPluginProps$pa2 === void 0 ? void 0 : _paypalPluginProps$pa2.paymentMethodType;
77
+ if (boundPaymentMethod && PaypalMethodEnum.PAYPAL_VAULT === paymentMethodType) {
78
+ _this.onEventCallback({
79
+ code: eventCodeEnum.SDK_PAYMENT_WARN,
80
+ message: 'You can directly request the server interface without antom-sdk.'
81
+ });
82
+ }
83
+ return Promise.resolve(paypalPluginProps);
84
+ });
85
+ // 加载paypal资源
86
+ _defineProperty(_assertThisInitialized(_this), "loadPaypalResource", function (paypalPluginProps) {
87
+ return new Promise(function (resolve, reject) {
88
+ var _paypalPluginProps$ap;
89
+ if (isShowLoading((_paypalPluginProps$ap = paypalPluginProps.appearance) === null || _paypalPluginProps$ap === void 0 ? void 0 : _paypalPluginProps$ap.showLoading)) {
90
+ _this.appendPaypalLoading({
91
+ selector: paypalPluginProps.selector
92
+ });
93
+ }
94
+ var paypalScript = _this.createPaypalScript(paypalPluginProps);
95
+ // 将script标签添加到DOM中
96
+ document.body.appendChild(paypalScript);
97
+ // 在script加载完成后执行回调函数
98
+ paypalScript.onload = function () {
99
+ resolve('loading successfully');
100
+ };
101
+ // 如果有错误则输出错误信息
102
+ paypalScript.onerror = function (error) {
103
+ reject(error);
104
+ };
105
+ });
106
+ });
107
+ _defineProperty(_assertThisInitialized(_this), "createPaypalScript", function (paypalPluginProps) {
108
+ var _paypalPluginProps$pa3, _paypalPluginProps$pa4, _paypalPluginProps$pa5, _paypalPluginProps$pa6;
109
+ var channelMerchantAccountId = (_paypalPluginProps$pa3 = paypalPluginProps.paymentSessionFactor) === null || _paypalPluginProps$pa3 === void 0 || (_paypalPluginProps$pa3 = _paypalPluginProps$pa3.merchantInfo) === null || _paypalPluginProps$pa3 === void 0 ? void 0 : _paypalPluginProps$pa3.channelMerchantClientId;
110
+ var accessToken = (_paypalPluginProps$pa4 = paypalPluginProps.paymentSessionFactor) === null || _paypalPluginProps$pa4 === void 0 || (_paypalPluginProps$pa4 = _paypalPluginProps$pa4.paypal) === null || _paypalPluginProps$pa4 === void 0 ? void 0 : _paypalPluginProps$pa4.accessToken;
111
+ var locale = paypalPluginProps.locale;
112
+ var currency = (_paypalPluginProps$pa5 = paypalPluginProps.paymentSessionFactor) === null || _paypalPluginProps$pa5 === void 0 || (_paypalPluginProps$pa5 = _paypalPluginProps$pa5.paymentAmount) === null || _paypalPluginProps$pa5 === void 0 ? void 0 : _paypalPluginProps$pa5.currency;
113
+ var paymentMethodType = (_paypalPluginProps$pa6 = paypalPluginProps.paymentSessionFactor) === null || _paypalPluginProps$pa6 === void 0 || (_paypalPluginProps$pa6 = _paypalPluginProps$pa6.paymentMethodInfo) === null || _paypalPluginProps$pa6 === void 0 ? void 0 : _paypalPluginProps$pa6.paymentMethodType;
114
+ var _ref2 = (paypalPluginProps === null || paypalPluginProps === void 0 ? void 0 : paypalPluginProps.paypalConfiguration) || {},
115
+ blockPayPalCreditButton = _ref2.blockPayPalCreditButton,
116
+ blockPayPalPayLaterButton = _ref2.blockPayPalPayLaterButton,
117
+ displayPayPalPayLaterButtonOnly = _ref2.displayPayPalPayLaterButtonOnly,
118
+ enableMessages = _ref2.enableMessages,
119
+ intent = _ref2.intent;
120
+ var script = document.createElement('script');
121
+ var src = "https://www.paypal.com/sdk/js?";
122
+ var urlSearchParams = new URLSearchParams({
123
+ currency: currency,
124
+ locale: locale,
125
+ 'client-id': channelMerchantAccountId
126
+ });
127
+ var disableFundingArr = [];
128
+ if (blockPayPalCreditButton && !displayPayPalPayLaterButtonOnly) {
129
+ disableFundingArr.push('card');
130
+ }
131
+ if (blockPayPalPayLaterButton && !displayPayPalPayLaterButtonOnly) {
132
+ disableFundingArr.push('credit');
133
+ }
134
+ if (disableFundingArr.length) {
135
+ urlSearchParams.append('disable-funding', disableFundingArr.join(','));
136
+ }
137
+ if (enableMessages) {
138
+ urlSearchParams.append('components', 'messages,buttons');
139
+ } else {
140
+ urlSearchParams.append('components', 'buttons');
141
+ }
142
+ if (payPalConfigurationIntentEnum.intent === intent && PaypalMethodEnum.PAYPAL_CHECKOUT === paymentMethodType) {
143
+ urlSearchParams.append('intent', 'authorize');
144
+ urlSearchParams.append('commit', 'false');
145
+ }
146
+ if (PaypalMethodEnum.PAYPAL_VAULT === paymentMethodType) {
147
+ urlSearchParams.append('vault', 'true');
148
+ }
149
+ src += urlSearchParams.toString();
150
+ script.src = src;
151
+ script.setAttribute('data-user-id-token', accessToken);
152
+ return script;
153
+ });
154
+ _defineProperty(_assertThisInitialized(_this), "onShippingChange", /*#__PURE__*/function () {
155
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
156
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
157
+ while (1) switch (_context.prev = _context.next) {
158
+ case 0:
159
+ _this.onEventCallback({
160
+ code: eventCodeEnum.SDK_PAYMENT_SHIPPINGCHANGE,
161
+ result: {
162
+ data: data
163
+ }
164
+ });
165
+ case 1:
166
+ case "end":
167
+ return _context.stop();
168
+ }
169
+ }, _callee);
170
+ }));
171
+ return function (_x) {
172
+ return _ref3.apply(this, arguments);
173
+ };
174
+ }());
175
+ _defineProperty(_assertThisInitialized(_this), "createOrder", /*#__PURE__*/function () {
176
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_data, _action, paymentSessionData, env, paymentSessionConfig) {
177
+ var _queryPaymentInfoRes$;
178
+ var queryPaymentInfoRes;
179
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
180
+ while (1) switch (_context2.prev = _context2.next) {
181
+ case 0:
182
+ _context2.next = 2;
183
+ return queryPaymentInfo({
184
+ paymentSessionData: paymentSessionData,
185
+ paymentSessionConfig: paymentSessionConfig
186
+ }, {
187
+ env: env,
188
+ timeout: 15000
189
+ }, _this.logger);
190
+ case 2:
191
+ queryPaymentInfoRes = _context2.sent;
192
+ if (!(!(queryPaymentInfoRes !== null && queryPaymentInfoRes !== void 0 && queryPaymentInfoRes.success) || !(queryPaymentInfoRes !== null && queryPaymentInfoRes !== void 0 && (_queryPaymentInfoRes$ = queryPaymentInfoRes.extendInfo) !== null && _queryPaymentInfoRes$ !== void 0 && _queryPaymentInfoRes$.channelOrderId))) {
193
+ _context2.next = 7;
194
+ break;
195
+ }
196
+ _this.logger.logInfo({
197
+ title: 'paypal_payment_failed'
198
+ });
199
+ _this.onEventCallback({
200
+ code: eventCodeEnum.SDK_PAYMENT_FAIL,
201
+ message: 'Create order failed.'
202
+ });
203
+ return _context2.abrupt("return");
204
+ case 7:
205
+ return _context2.abrupt("return", queryPaymentInfoRes.extendInfo.channelOrderId);
206
+ case 8:
207
+ case "end":
208
+ return _context2.stop();
209
+ }
210
+ }, _callee2);
211
+ }));
212
+ return function (_x2, _x3, _x4, _x5, _x6) {
213
+ return _ref4.apply(this, arguments);
214
+ };
215
+ }());
216
+ _defineProperty(_assertThisInitialized(_this), "onApprove", /*#__PURE__*/function () {
217
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(onApproveData) {
218
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
219
+ while (1) switch (_context3.prev = _context3.next) {
220
+ case 0:
221
+ _this.onEventCallback({
222
+ code: eventCodeEnum.SDK_PAYMENT_APPROVE,
223
+ result: {
224
+ onApproveData: onApproveData
225
+ }
226
+ });
227
+ if (_this.logger && isFunction(_this.logger.logInfo)) {
228
+ _this.logger.logInfo({
229
+ title: 'paypal_payment_approved'
230
+ });
231
+ }
232
+ case 2:
233
+ case "end":
234
+ return _context3.stop();
235
+ }
236
+ }, _callee3);
237
+ }));
238
+ return function (_x7) {
239
+ return _ref5.apply(this, arguments);
240
+ };
241
+ }());
242
+ _defineProperty(_assertThisInitialized(_this), "onCancel", /*#__PURE__*/function () {
243
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderId) {
244
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
245
+ while (1) switch (_context4.prev = _context4.next) {
246
+ case 0:
247
+ _this.onEventCallback({
248
+ code: eventCodeEnum.SDK_PAYMENT_CANCEL,
249
+ result: {
250
+ orderId: orderId
251
+ }
252
+ });
253
+ if (_this.logger && isFunction(_this.logger.logInfo)) {
254
+ _this.logger.logInfo({
255
+ title: 'paypal_payment_cancelled'
256
+ });
257
+ }
258
+ case 2:
259
+ case "end":
260
+ return _context4.stop();
261
+ }
262
+ }, _callee4);
263
+ }));
264
+ return function (_x8) {
265
+ return _ref6.apply(this, arguments);
266
+ };
267
+ }());
268
+ _defineProperty(_assertThisInitialized(_this), "destroyComponent", /*#__PURE__*/function () {
269
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(context, message) {
270
+ var data;
271
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
272
+ while (1) switch (_context5.prev = _context5.next) {
273
+ case 0:
274
+ data = message.getJSONObject();
275
+ _this.logger.logInfo({
276
+ title: 'sdk_event_clean_component'
277
+ }).send();
278
+ if (document.querySelector(data === null || data === void 0 ? void 0 : data.selector)) {
279
+ document.querySelector(data === null || data === void 0 ? void 0 : data.selector).innerHTML = '';
280
+ console.log('paypal: destroy Component');
281
+ }
282
+ case 3:
283
+ case "end":
284
+ return _context5.stop();
285
+ }
286
+ }, _callee5);
287
+ }));
288
+ return function (_x9, _x10) {
289
+ return _ref7.apply(this, arguments);
290
+ };
291
+ }());
292
+ _this.logger = logger;
293
+ return _this;
294
+ }
295
+ _createClass(PaypalBusSubscriber, [{
296
+ key: "actionNames",
297
+ value: function actionNames() {
298
+ return Object.values(PaypalActionEnum);
299
+ }
300
+ }, {
301
+ key: "renderPaypalButton",
302
+ value: function renderPaypalButton(context, message) {
303
+ var _data$options,
304
+ _data$options2,
305
+ _data$appendParams,
306
+ _data$appendParams2,
307
+ _data$appendParams3,
308
+ _data$appendParams4,
309
+ _data$appendParams5,
310
+ _data$appendParams6,
311
+ _this2 = this;
312
+ var data = message.getJSONObject();
313
+ var paypalPluginProps = {
314
+ locale: (_data$options = data.options) === null || _data$options === void 0 ? void 0 : _data$options.locale,
315
+ environment: (_data$options2 = data.options) === null || _data$options2 === void 0 ? void 0 : _data$options2.environment,
316
+ paymentSessionData: (_data$appendParams = data.appendParams) === null || _data$appendParams === void 0 || (_data$appendParams = _data$appendParams.iframeNodesParams) === null || _data$appendParams === void 0 ? void 0 : _data$appendParams.sessionData,
317
+ paymentSessionFactor: (_data$appendParams2 = data.appendParams) === null || _data$appendParams2 === void 0 || (_data$appendParams2 = _data$appendParams2.iframeNodesParams) === null || _data$appendParams2 === void 0 || (_data$appendParams2 = _data$appendParams2.paymentSessionMetaData) === null || _data$appendParams2 === void 0 ? void 0 : _data$appendParams2.paymentSessionFactor,
318
+ selector: (_data$appendParams3 = data.appendParams) === null || _data$appendParams3 === void 0 || (_data$appendParams3 = _data$appendParams3.iframeNodesParams) === null || _data$appendParams3 === void 0 ? void 0 : _data$appendParams3.selector,
319
+ paypalConfiguration: (_data$appendParams4 = data.appendParams) === null || _data$appendParams4 === void 0 || (_data$appendParams4 = _data$appendParams4.iframeNodesParams) === null || _data$appendParams4 === void 0 ? void 0 : _data$appendParams4.paypalConfiguration,
320
+ appearance: (_data$appendParams5 = data.appendParams) === null || _data$appendParams5 === void 0 || (_data$appendParams5 = _data$appendParams5.iframeNodesParams) === null || _data$appendParams5 === void 0 ? void 0 : _data$appendParams5.appearance,
321
+ paymentSessionConfig: (_data$appendParams6 = data.appendParams) === null || _data$appendParams6 === void 0 || (_data$appendParams6 = _data$appendParams6.iframeNodesParams) === null || _data$appendParams6 === void 0 || (_data$appendParams6 = _data$appendParams6.paymentSessionMetaData) === null || _data$appendParams6 === void 0 ? void 0 : _data$appendParams6.paymentSessionConfig
322
+ };
323
+ return this.preCheck(paypalPluginProps).then(function (paypalPluginProps) {
324
+ return _this2.loadPaypalResource(paypalPluginProps).then(function () {
325
+ var _paypalPluginProps$pa7, _paypalPluginProps$pa8;
326
+ var createButtonConfig = {
327
+ style: _objectSpread({
328
+ layout: 'vertical',
329
+ color: 'gold',
330
+ shape: 'rect'
331
+ }, ((_paypalPluginProps$pa7 = paypalPluginProps.paypalConfiguration) === null || _paypalPluginProps$pa7 === void 0 ? void 0 : _paypalPluginProps$pa7.style) || {}),
332
+ fundingSource: undefined,
333
+ onShippingChange: _this2.onShippingChange,
334
+ createOrder: function createOrder(data, action) {
335
+ return _this2.createOrder(data, action, paypalPluginProps.paymentSessionData, paypalPluginProps.environment, paypalPluginProps.paymentSessionConfig);
336
+ },
337
+ onApprove: _this2.onApprove,
338
+ onCancel: _this2.onCancel
339
+ };
340
+ if ((_paypalPluginProps$pa8 = paypalPluginProps.paypalConfiguration) !== null && _paypalPluginProps$pa8 !== void 0 && _paypalPluginProps$pa8.displayPayPalPayLaterButtonOnly) {
341
+ createButtonConfig.fundingSource = window.paypal.FUNDING.PAYLATER;
342
+ }
343
+ try {
344
+ window.paypal.Buttons(createButtonConfig).render(paypalPluginProps.selector);
345
+ } catch (error) {
346
+ _this2.logger.logError({
347
+ title: 'button_render_failed'
348
+ }, {
349
+ message: error
350
+ });
351
+ _this2.onEventCallback({
352
+ code: eventCodeEnum.SDK_PAYMENT_FAIL,
353
+ message: 'Button render failed.'
354
+ });
355
+ return Promise.reject(error);
356
+ }
357
+ }).catch(function (error) {
358
+ _this2.logger.logError({
359
+ title: 'paypal_payment_loadSDK_failed'
360
+ });
361
+ _this2.onEventCallback({
362
+ code: eventCodeEnum.SDK_PAYMENT_FAIL,
363
+ message: 'Loading paypal sdk failed.'
364
+ });
365
+ return Promise.reject(error);
366
+ }).finally(function () {
367
+ var _paypalPluginProps$ap2;
368
+ if (isShowLoading((_paypalPluginProps$ap2 = paypalPluginProps.appearance) === null || _paypalPluginProps$ap2 === void 0 ? void 0 : _paypalPluginProps$ap2.showLoading)) {
369
+ _this2.removePaypalLoading();
370
+ }
371
+ });
372
+ });
373
+ }
374
+ }, {
375
+ key: "onMessage",
376
+ value: function onMessage(context, message) {
377
+ switch (message.getAction()) {
378
+ case PaypalActionEnum.mountComponent:
379
+ this.renderPaypalButton(context, message);
380
+ break;
381
+ case PaypalActionEnum.destroyComponent:
382
+ this.destroyComponent(context, message);
383
+ default:
384
+ console.log('Unknown action: ' + message.getAction());
385
+ }
386
+ }
387
+ }]);
388
+ return PaypalBusSubscriber;
389
+ }(BusSubscriber);
@@ -1,4 +1,4 @@
1
- import { BusSubscriber } from '../core/bus';
1
+ import { BusSubscriber } from 'src/core/bus';
2
2
  import { paymentMethodCategoryTypeEnum, productSceneEnum, ProductSceneVersion } from '../types';
3
3
  export type IExtendPlugin = IExtendPluginItem[];
4
4
  export interface ComponentActionNamesType {
@@ -7,7 +7,7 @@ export interface ComponentActionNamesType {
7
7
  createComponent?: string;
8
8
  mountComponent?: string;
9
9
  submit?: string;
10
- destoryComponent?: string;
10
+ destroyComponent?: string;
11
11
  }
12
12
  export type IExtendPluginItem = {
13
13
  /**
@@ -0,0 +1,6 @@
1
+ export declare const appendLoadingIcon: (props: {
2
+ htmlElement: HTMLElement;
3
+ loadingWidth: string;
4
+ loadingHeight: string;
5
+ }) => void;
6
+ export declare const isShowLoading: (showLoading?: boolean) => boolean;
@@ -0,0 +1,21 @@
1
+ export var appendLoadingIcon = function appendLoadingIcon(props) {
2
+ var htmlElement = props.htmlElement,
3
+ loadingHeight = props.loadingHeight,
4
+ loadingWidth = props.loadingWidth;
5
+ var spinStyles = "\n @keyframes loadingSpin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n }\n ";
6
+ var loadingImg = document.createElement('img');
7
+ loadingImg.src = 'https://mdn.alipayobjects.com/huamei_saktgs/afts/img/A*vmqbT6W9g4oAAAAAAAAAAAAADviCAQ/original';
8
+ loadingImg.classList.add('atom-loading');
9
+ loadingImg.style.width = loadingWidth;
10
+ loadingImg.style.height = loadingHeight;
11
+ loadingImg.style.animation = 'loadingSpin 0.8s linear infinite';
12
+ var styleElement = document.createElement('style');
13
+ styleElement.textContent = spinStyles;
14
+ document.head.appendChild(styleElement);
15
+ if (htmlElement) {
16
+ htmlElement.appendChild(loadingImg);
17
+ }
18
+ };
19
+ export var isShowLoading = function isShowLoading(showLoading) {
20
+ return showLoading = typeof showLoading === 'boolean' ? showLoading : true;
21
+ };
@@ -50,8 +50,6 @@ function requestInstance(options) {
50
50
  withCredentials: (_options$withCredenti = options.withCredentials) !== null && _options$withCredenti !== void 0 ? _options$withCredenti : true,
51
51
  method: (options === null || options === void 0 ? void 0 : options.method) || 'POST'
52
52
  });
53
- console.log('baseURL', baseURL);
54
- console.log('_headers', _headers);
55
53
  return instance.request;
56
54
  }
57
55
 
@@ -99,25 +97,21 @@ function _request() {
99
97
  })];
100
98
  startTime = Date.now();
101
99
  _context.prev = 5;
102
- console.log('requestInstance options', options);
103
- console.log('requestInstance -data', _data);
104
100
  myRequest = requestInstance(options);
105
- _context.next = 11;
101
+ _context.next = 9;
106
102
  return myRequest({
107
103
  data: _data
108
104
  });
109
- case 11:
105
+ case 9:
110
106
  _yield$myRequest = _context.sent;
111
107
  data = _yield$myRequest.data;
112
108
  headers = _yield$myRequest.headers;
113
- console.log('requestInstance data', data);
114
- console.log('requestInstance headers', headers);
115
109
  resData = data || {};
116
110
  traceId = get(headers, 'Mgw-TraceId') || get(headers, 'mgw-traceid', '');
117
111
  resData.traceId = traceId || '';
118
112
  handleGetWayError = fomatGetwayError(headers, traceId);
119
113
  if (!(handleGetWayError !== null && handleGetWayError !== void 0 && handleGetWayError.errorCode)) {
120
- _context.next = 25;
114
+ _context.next = 21;
121
115
  break;
122
116
  }
123
117
  errorMessage = (resData === null || resData === void 0 ? void 0 : resData.errorMessage) || (handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorMessage);
@@ -136,7 +130,7 @@ function _request() {
136
130
  errorCode: errorCode,
137
131
  success: false
138
132
  }));
139
- case 25:
133
+ case 21:
140
134
  logger.reportRPC({
141
135
  name: options === null || options === void 0 ? void 0 : options['Operation-Type'],
142
136
  label: 'request',
@@ -147,8 +141,8 @@ function _request() {
147
141
  traceId: traceId
148
142
  }).send();
149
143
  return _context.abrupt("return", resData);
150
- case 29:
151
- _context.prev = 29;
144
+ case 25:
145
+ _context.prev = 25;
152
146
  _context.t0 = _context["catch"](5);
153
147
  _error = safeJson(_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message, {
154
148
  success: false,
@@ -170,11 +164,11 @@ function _request() {
170
164
  errorCode: _errorCode,
171
165
  errorMessage: _error === null || _error === void 0 ? void 0 : _error.message
172
166
  }));
173
- case 36:
167
+ case 32:
174
168
  case "end":
175
169
  return _context.stop();
176
170
  }
177
- }, _callee, null, [[5, 29]]);
171
+ }, _callee, null, [[5, 25]]);
178
172
  }));
179
173
  return _request.apply(this, arguments);
180
174
  }
@@ -81,6 +81,19 @@ export interface IappendIframeNodesParams extends IcreateComponent {
81
81
  paymentSessionMetaData: IpaymentSessionMetaData;
82
82
  renderDisplayType: renderDisplayTypeEnum;
83
83
  selector?: Iselector;
84
+ paypalConfiguration?: IPaypalConfiguration;
85
+ }
86
+ export interface IPaypalConfiguration {
87
+ style?: Object;
88
+ blockPayPalCreditButton?: boolean;
89
+ blockPayPalPayLaterButton?: boolean;
90
+ displayPayPalPayLaterButtonOnly?: boolean;
91
+ enableMessages?: boolean;
92
+ intent?: payPalConfigurationIntentEnum;
93
+ }
94
+ export declare enum payPalConfigurationIntentEnum {
95
+ 'intent' = "intent",
96
+ 'capture' = "capture"
84
97
  }
85
98
  export interface IMerchantAppointParam {
86
99
  storedCard?: IStoredCard;
@@ -99,7 +112,7 @@ export interface IbillingAddress {
99
112
  export interface Isubmit {
100
113
  billingAddress?: IbillingAddress;
101
114
  }
102
- interface IpaymentSessionConfig {
115
+ export interface IpaymentSessionConfig {
103
116
  productScene: productSceneEnum;
104
117
  paymentMethodCategoryType: paymentMethodCategoryTypeEnum;
105
118
  productSceneVersion: string;
@@ -133,6 +146,11 @@ export interface IpaymentSessionMetaData {
133
146
  action?: {
134
147
  autoDebitWithToken: boolean;
135
148
  skipSdkQuery: boolean;
149
+ skipSdkQueryForm?: {
150
+ value: boolean;
151
+ version: string;
152
+ platform: string;
153
+ };
136
154
  };
137
155
  paymentSessionFactor?: {
138
156
  extendInfo?: {
@@ -196,6 +214,33 @@ export interface IpaymentSessionMetaData {
196
214
  };
197
215
  };
198
216
  }
217
+ export interface IPaymentSessionFactor {
218
+ merchantInfo?: IMerchantInfo;
219
+ paymentMethodInfo: IPaymentMethodInfo;
220
+ paymentAmount?: IPaymentAmount;
221
+ paypal?: IPaypalConfig;
222
+ }
223
+ export interface IPaymentMethodInfo {
224
+ paymentMethodMetaData?: IPaymentMethodMetaData;
225
+ paymentMethodType?: PaypalMethodEnum;
226
+ }
227
+ export type IPaypalConfig = {
228
+ accessToken: string;
229
+ };
230
+ export interface IPaymentMethodMetaData {
231
+ bindPaymentMethod?: string;
232
+ boundPaymentMethod?: string;
233
+ }
234
+ export interface IMerchantInfo {
235
+ channelMerchantClientId?: string;
236
+ }
237
+ export interface IPaymentAmount {
238
+ value?: string;
239
+ currency?: PaymentAmountEnum;
240
+ }
241
+ export declare enum PaymentAmountEnum {
242
+ USD = "USD"
243
+ }
199
244
  export declare enum localeEnum {
200
245
  'en-US' = "en-US"
201
246
  }
@@ -397,6 +442,9 @@ export interface CashierSdkActionQueryResult {
397
442
  applinkUrl?: string;
398
443
  schemeUrl?: string;
399
444
  authUrl?: string;
445
+ extendInfo?: {
446
+ channelOrderId?: string;
447
+ };
400
448
  }
401
449
  /**
402
450
  * Get App Pay Payment Session Request.
@@ -455,7 +503,10 @@ export declare enum eventCodeEnum {
455
503
  /**
456
504
  * 当前为Apple Pay发起了Pay请求,但是用户关闭了页面
457
505
  */
458
- SDK_PAYMENT_PROCESSING = "SDK_PAYMENT_PROCESSING"
506
+ SDK_PAYMENT_PROCESSING = "SDK_PAYMENT_PROCESSING",
507
+ SDK_PAYMENT_WARN = "SDK_PAYMENT_WARN",
508
+ SDK_PAYMENT_SHIPPINGCHANGE = "SDK_PAYMENT_SHIPPINGCHANGE",
509
+ SDK_PAYMENT_APPROVE = "SDK_PAYMENT_APPROVE"
459
510
  }
460
511
  export declare enum RedirectType {
461
512
  ApplinkUrl = "ApplinkUrl",
@@ -476,6 +527,11 @@ export interface CallbackEventInfo {
476
527
  export interface MultipleCallbackEvents {
477
528
  [key: string]: CallbackEventInfo;
478
529
  }
530
+ export declare enum PaypalMethodEnum {
531
+ PAYPAL_CHECKOUT = "PAYPAL_CHECKOUT",
532
+ PAYPAL_VAULT = "PAYPAL_VAULT",
533
+ PAYPAL_PAYLATER = "PAYPAL_PAYLATER"
534
+ }
479
535
  export type PaymentMethodTypeEnum = 'ApplePay';
480
536
  export type ApplePaySubTypeEnum = 'ApplePayRecurringPayment';
481
537
  export type SubPaymentMethodTypeEnum = ApplePaySubTypeEnum;
@@ -487,4 +543,3 @@ export type IAppendParams = {
487
543
  componentSign: componentSignEnum;
488
544
  iframeNodesParams: IappendIframeNodesParams;
489
545
  };
490
- export {};