@alipay/ams-checkout 0.0.1710212811-dev.1 → 0.0.1710212811-dev.10

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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
5
  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); } }
4
6
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -28,11 +30,15 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
28
30
  import { v4 as uuid } from 'uuid';
29
31
  import { COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
30
32
  import ComponentApp from "../../plugin/component";
31
- import { componentSignEnum, modeEnum, networkModeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
33
+ import { componentSignEnum, modeEnum, networkModeEnum, PaymentMethodTypeEnum, productSceneEnum, renderDisplayTypeEnum } from "../../types";
32
34
  import { getOrSetStorageId, isPC, parseBase64ToString } from "../../util";
33
35
  import { createIframeNode, createPreloadIframeNode } from "../../util/createIframeNode";
34
36
  import { getSecurityConfigStorageKey } from "../../util/security";
35
37
  import CoreInstance from "../instance/index";
38
+ import { BusManager, BusMessage } from "../bus";
39
+ import { ApplePayActionEnum, PaymentActionEnum } from "../bus/interface";
40
+ import { SDKCallbackBusSubscriber } from "../bus/ability/sdk";
41
+ import { ApplePayBusSubscriber } from "../../plugin/applepay";
36
42
  export var getComponentSign = function getComponentSign(params) {
37
43
  var _params$paymentSessio = params.paymentSessionConfig,
38
44
  _params$paymentSessio2 = _params$paymentSessio === void 0 ? {} : _params$paymentSessio,
@@ -114,6 +120,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
114
120
  // Register Cashier Application Plug in
115
121
  _this._registerPlugin(COMPONENTPLUGINID, ComponentPlugin);
116
122
  _this._componentApp = _this._getPlugin(COMPONENTPLUGINID);
123
+ _this.registerBusAbility();
117
124
  return _this;
118
125
  }
119
126
  _createClass(AMSComponent, [{
@@ -188,6 +195,54 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
188
195
  localStorage.setItem('antom_checkout_previousChannel', JSON.stringify(previousChannel));
189
196
  }
190
197
  }
198
+
199
+ /**
200
+ * 初始化 Bus总线的能力
201
+ */
202
+ }, {
203
+ key: "registerBusAbility",
204
+ value: function registerBusAbility() {
205
+ var _this2 = this,
206
+ _this$originOptions;
207
+ BusManager.clear();
208
+ BusManager.addInterceptor({
209
+ onPublishException: function onPublishException(message, e) {
210
+ _this2.logger.logInfo({
211
+ title: 'onPublishException'
212
+ }, _objectSpread(_objectSpread({}, message), {}, {
213
+ errorMessage: JSON.stringify(e)
214
+ }));
215
+ }
216
+ });
217
+ BusManager.subscribe(new SDKCallbackBusSubscriber((_this$originOptions = this.originOptions) === null || _this$originOptions === void 0 ? void 0 : _this$originOptions.onEventCallback));
218
+ BusManager.subscribe(new ApplePayBusSubscriber());
219
+ BusManager.publish(new BusMessage(PaymentActionEnum.optional_init, JSON.stringify(this.originOptions)));
220
+ }
221
+ }, {
222
+ key: "canMakePayments",
223
+ value: function canMakePayments(paymentMethod, subPaymentMethod) {
224
+ var _this3 = this;
225
+ // 判断支付方式是否可用
226
+ return new Promise(function (resolve) {
227
+ if (paymentMethod === PaymentMethodTypeEnum.ApplePay) {
228
+ BusManager.publishForResult(new BusMessage(ApplePayActionEnum.canMakePayments, JSON.stringify({
229
+ subPaymentMethod: subPaymentMethod
230
+ }))).then(function (message) {
231
+ resolve(message.getJSONObject().result);
232
+ }).catch(function (e) {
233
+ _this3.logger.logInfo({
234
+ title: 'canMakePayments_error'
235
+ }, {
236
+ params: JSON.stringify(e)
237
+ });
238
+ resolve(false);
239
+ });
240
+ } else {
241
+ resolve(true);
242
+ }
243
+ });
244
+ }
245
+
191
246
  /**
192
247
  * @description Create component application
193
248
  * @param params - The data source created by the component, necessary sessionData, optional appearance configuration, and refer to the documentation for other parameters and detailed information.
@@ -195,7 +250,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
195
250
  }, {
196
251
  key: "createComponent",
197
252
  value: function createComponent(params) {
198
- var _this2 = this;
253
+ var _this4 = this;
199
254
  this.clearPreloadIframe();
200
255
  return this.parameterInitAndCheck({
201
256
  params: params,
@@ -203,23 +258,42 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
203
258
  }).then(function (_params) {
204
259
  return handleParams(_params);
205
260
  }).catch(function (error) {
206
- _this2.logger.logError({
261
+ _this4.logger.logError({
207
262
  title: 'sdk_error_parameter'
208
263
  }, {
209
264
  params: JSON.stringify(params)
210
265
  }).send();
211
- _this2._eventCenter.emit(EVENT.error.name, error);
266
+ _this4._eventCenter.emit(EVENT.error.name, error);
212
267
  return Promise.reject(error);
213
268
  }).then(function (appendParams) {
269
+ if (_this4.isApplePay(params === null || params === void 0 ? void 0 : params.paymentSessionData) && BusManager.isSubscribed(ApplePayActionEnum.createComponent)) {
270
+ // 执行出错了,在通用拦截器返回
271
+ BusManager.publish(new BusMessage(ApplePayActionEnum.createComponent, JSON.stringify({
272
+ paymentSessionData: params === null || params === void 0 ? void 0 : params.paymentSessionData,
273
+ options: _this4.originOptions
274
+ })));
275
+ return;
276
+ }
214
277
  var iframeNodesParams = appendParams.iframeNodesParams;
215
- _this2.savePreviousChannel(iframeNodesParams);
216
- return _this2.pluginAppendIframe(appendParams);
278
+ _this4.savePreviousChannel(iframeNodesParams);
279
+ return _this4.pluginAppendIframe(appendParams);
217
280
  });
218
281
  }
282
+ }, {
283
+ key: "isApplePay",
284
+ value: function isApplePay(paymentSessionData) {
285
+ var _parseData$paymentSes2;
286
+ var _parseSessionData3 = parseSessionData(paymentSessionData),
287
+ _parseSessionData4 = _slicedToArray(_parseSessionData3, 2),
288
+ parseData = _parseSessionData4[0],
289
+ sessionData = _parseSessionData4[1];
290
+ // todo 补充全量判断
291
+ return sessionData && (parseData === null || parseData === void 0 || (_parseData$paymentSes2 = parseData.paymentSessionFactor) === null || _parseData$paymentSes2 === void 0 || (_parseData$paymentSes2 = _parseData$paymentSes2.paymentMethodInfo) === null || _parseData$paymentSes2 === void 0 ? void 0 : _parseData$paymentSes2.paymentMethodType) === "CARD_APPLE_PAY";
292
+ }
219
293
  }, {
220
294
  key: "preloadComponent",
221
295
  value: function preloadComponent(channelType, productSceneVersion) {
222
- var _this3 = this;
296
+ var _this5 = this;
223
297
  this.channelType = channelType;
224
298
  this.productSceneVersion = productSceneVersion;
225
299
  var MAX_CLEAR_TIME = 10000;
@@ -235,7 +309,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
235
309
  });
236
310
  }
237
311
  setTimeout(function () {
238
- _this3.clearPreloadIframe(true);
312
+ _this5.clearPreloadIframe(true);
239
313
  }, MAX_CLEAR_TIME);
240
314
  }
241
315
  }, {
@@ -266,7 +340,7 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
266
340
  }, {
267
341
  key: "mountComponent",
268
342
  value: function mountComponent(params, selector) {
269
- var _this4 = this;
343
+ var _this6 = this;
270
344
  this.clearPreloadIframe();
271
345
  return this.parameterInitAndCheck({
272
346
  params: params,
@@ -275,17 +349,17 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
275
349
  }).then(function (_params) {
276
350
  return handleParams(_params);
277
351
  }).catch(function (error) {
278
- _this4.logger.logError({
352
+ _this6.logger.logError({
279
353
  title: 'sdk_error_parameter'
280
354
  }, {
281
355
  params: JSON.stringify(params)
282
356
  }).send();
283
- _this4._eventCenter.emit(EVENT.error.name, error);
357
+ _this6._eventCenter.emit(EVENT.error.name, error);
284
358
  return Promise.reject(error);
285
359
  }).then(function (appendParams) {
286
360
  var iframeNodesParams = appendParams.iframeNodesParams;
287
- _this4.savePreviousChannel(iframeNodesParams);
288
- return _this4.pluginAppendIframe(appendParams);
361
+ _this6.savePreviousChannel(iframeNodesParams);
362
+ return _this6.pluginAppendIframe(appendParams);
289
363
  });
290
364
  }
291
365
  /**
@@ -296,22 +370,22 @@ export var AMSComponent = /*#__PURE__*/function (_CoreInstance) {
296
370
  }, {
297
371
  key: "submit",
298
372
  value: function submit(data) {
299
- var _this5 = this;
373
+ var _this7 = this;
300
374
  return new Promise(function (resolve, reject) {
301
375
  try {
302
376
  var eventCallbackId = uuid();
303
377
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
304
- _this5._eventCenter.once(eventCallbackId, function (_data) {
378
+ _this7._eventCenter.once(eventCallbackId, function (_data) {
305
379
  resolve(_data);
306
380
  });
307
- _this5._componentApp.dispatchToApp({
381
+ _this7._componentApp.dispatchToApp({
308
382
  context: {
309
383
  event: 'submitPay',
310
384
  eventCallbackId: eventCallbackId,
311
385
  data: data
312
386
  }
313
387
  });
314
- _this5.logger.logInfo({
388
+ _this7.logger.logInfo({
315
389
  title: 'sdk_event_apiSubmit'
316
390
  });
317
391
  } catch (error) {
@@ -4,6 +4,7 @@ import { Logger } from '../../util/logger';
4
4
  import { Security } from '../../util/security';
5
5
  export default class AMSSDK {
6
6
  options: AMSCheckoutOptions;
7
+ originOptions: IoptionsParams;
7
8
  logger: Logger;
8
9
  _eventCenter: EventCenter;
9
10
  _instanceId: string;
@@ -30,6 +30,7 @@ var AMSSDK = /*#__PURE__*/function () {
30
30
  function AMSSDK(options) {
31
31
  _classCallCheck(this, AMSSDK);
32
32
  _defineProperty(this, "options", void 0);
33
+ _defineProperty(this, "originOptions", void 0);
33
34
  _defineProperty(this, "logger", void 0);
34
35
  _defineProperty(this, "_eventCenter", void 0);
35
36
  _defineProperty(this, "_instanceId", void 0);
@@ -37,6 +38,7 @@ var AMSSDK = /*#__PURE__*/function () {
37
38
  _defineProperty(this, "securitySdkMap", void 0);
38
39
  _defineProperty(this, "plugins", void 0);
39
40
  this._instanceId = uuid();
41
+ this.originOptions = options;
40
42
  this.options = {};
41
43
  this._eventCenter = new EventCenter();
42
44
  this._initEvent(options);
package/esm/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
- import ApplePayComponent from './core/applepay';
8
+ import ApplePayComponent from './plugin/applepay/component';
9
9
  import { AMSComponent } from './core/component/index';
10
10
  import { IoptionsParams, componentSignEnum } from './types';
11
11
  export * from './types';
package/esm/index.js CHANGED
@@ -18,7 +18,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
18
18
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
19
19
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
20
20
  */
21
- import ApplePayComponent from "./core/applepay";
21
+ import ApplePayComponent from "./plugin/applepay/component";
22
22
  import { AMSComponent } from "./core/component/index";
23
23
  import { componentSignEnum } from "./types";
24
24
  import { productSceneEnum } from "./types/index";
@@ -6,7 +6,7 @@
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
8
  import { IGetMerchantSession, ICompletePaymentAuthorized, ICompleteApplePay, ILogError, IApplePayTrace } from './interface';
9
- import { IpaymentSessionMetaData } from '../../types';
9
+ import { ApplePaySubTypeEnum, IpaymentSessionMetaData } from '../../types';
10
10
  /**
11
11
  * Apple Pay Service
12
12
  */
@@ -19,7 +19,6 @@ declare class ApplePayService {
19
19
  private completeApplePay;
20
20
  private logError;
21
21
  private applePayTrace;
22
- private onEventCallback;
23
22
  constructor();
24
23
  /**
25
24
  * set Apple Pay Params
@@ -31,9 +30,11 @@ declare class ApplePayService {
31
30
  */
32
31
  setApplePayParams(getMerchantSession: IGetMerchantSession, completePaymentAuthorized: ICompletePaymentAuthorized, completeApplePay: ICompleteApplePay, logError: ILogError, applePayTrace: IApplePayTrace): void;
33
32
  /**
34
- * Apple Pay is enabled
33
+ * Is Apple Pay Enabled
34
+ * @param subTypeEnum
35
+ * @returns
35
36
  */
36
- isEnabled: () => boolean;
37
+ static canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): any;
37
38
  /**
38
39
  * has Active Card in Apple Pay
39
40
  * @param merchantIdentifier
@@ -17,6 +17,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
17
17
  */
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
19
  import { APPLE_PAY_VERSION, APPLE_PAY_RECURRING_VERSION } from "./interface";
20
+ import { ApplePaySubTypeEnum } from "../../types";
21
+
20
22
  /**
21
23
  * Apple Pay Service
22
24
  */
@@ -32,13 +34,6 @@ var ApplePayService = /*#__PURE__*/function () {
32
34
  _defineProperty(this, "completeApplePay", void 0);
33
35
  _defineProperty(this, "logError", void 0);
34
36
  _defineProperty(this, "applePayTrace", void 0);
35
- _defineProperty(this, "onEventCallback", void 0);
36
- /**
37
- * Apple Pay is enabled
38
- */
39
- _defineProperty(this, "isEnabled", function () {
40
- return window.ApplePaySession ? window.ApplePaySession.canMakePayments() : false;
41
- });
42
37
  _defineProperty(this, "onvalidatemerchant", function (event) {
43
38
  _this.applePayTrace('onValidateMerchant');
44
39
  _this.getMerchantSession({
@@ -46,6 +41,7 @@ var ApplePayService = /*#__PURE__*/function () {
46
41
  merchantIdentifier: _this.merchantIdentifier,
47
42
  validationUrl: event.validationURL
48
43
  }).then(function (merchantSessionObjectString) {
44
+ console.log("onvalidatemerchant#merchantSessionObjectString", merchantSessionObjectString);
49
45
  var merchantSessionObject = JSON.parse(merchantSessionObjectString);
50
46
  _this.session.completeMerchantValidation(merchantSessionObject);
51
47
  _this.applePayTrace('completeMerchantValidation');
@@ -96,7 +92,7 @@ var ApplePayService = /*#__PURE__*/function () {
96
92
  order = paymentSessionFactor.order,
97
93
  recurringInfo = paymentSessionFactor.recurringInfo;
98
94
  _this.merchantIdentifier = merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.partnerId;
99
- if (!(extendInfo !== null && extendInfo !== void 0 && extendInfo.merchantCapabilities) || !(extendInfo !== null && extendInfo !== void 0 && extendInfo.supportedNetworks) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.registeredCountry) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.currency) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.value)) {
95
+ if (!(extendInfo !== null && extendInfo !== void 0 && extendInfo.merchantCapabilities) || !(extendInfo !== null && extendInfo !== void 0 && extendInfo.supportedNetworks) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.registeredCountry) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.currency) || !(paymentAmount !== null && paymentAmount !== void 0 && paymentAmount.value) || !(merchantInfo !== null && merchantInfo !== void 0 && merchantInfo.merchantName)) {
100
96
  _this.logError("invalid session data");
101
97
  return;
102
98
  }
@@ -134,7 +130,7 @@ var ApplePayService = /*#__PURE__*/function () {
134
130
  currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
135
131
  total: {
136
132
  type: 'final',
137
- label: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantName,
133
+ label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
138
134
  amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
139
135
  },
140
136
  recurringPaymentRequest: recurringRequest,
@@ -149,7 +145,7 @@ var ApplePayService = /*#__PURE__*/function () {
149
145
  currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
150
146
  total: {
151
147
  type: 'final',
152
- label: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantName,
148
+ label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
153
149
  amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
154
150
  }
155
151
  };
@@ -159,7 +155,11 @@ var ApplePayService = /*#__PURE__*/function () {
159
155
  _this.session.onpaymentauthorized = _this.onpaymentauthorized;
160
156
  _this.session.oncancel = function () {
161
157
  _this.logError('UserCancel');
162
- _this.session.abort();
158
+ try {
159
+ _this.session.abort();
160
+ } catch (error) {
161
+ console.log("session.abort() error");
162
+ }
163
163
  };
164
164
  _this.session.begin();
165
165
  _this.applePayTrace('sessionBegin');
@@ -183,6 +183,12 @@ var ApplePayService = /*#__PURE__*/function () {
183
183
  this.logError = logError;
184
184
  this.applePayTrace = applePayTrace;
185
185
  }
186
+
187
+ /**
188
+ * Is Apple Pay Enabled
189
+ * @param subTypeEnum
190
+ * @returns
191
+ */
186
192
  }, {
187
193
  key: "hasActiveCard",
188
194
  value: (
@@ -215,6 +221,14 @@ var ApplePayService = /*#__PURE__*/function () {
215
221
  }
216
222
  return hasActiveCard;
217
223
  }())
224
+ }], [{
225
+ key: "canMakePayments",
226
+ value: function canMakePayments(subTypeEnum) {
227
+ if (ApplePaySubTypeEnum.ApplePayRecurringPayment === subTypeEnum) {
228
+ return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_RECURRING_VERSION) : false;
229
+ }
230
+ return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_VERSION) : false;
231
+ }
218
232
  }]);
219
233
  return ApplePayService;
220
234
  }();
@@ -6,7 +6,7 @@
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
8
  import { ApplePaySubTypeEnum, IApplePayOptionsParams } from '../../types';
9
- import CoreInstance from '../instance';
9
+ import CoreInstance from '../../core/instance';
10
10
  /**
11
11
  * Apple pay Component
12
12
  */
@@ -23,7 +23,8 @@ declare class ApplePayComponent extends CoreInstance {
23
23
  * @param subTypeEnum
24
24
  * @returns
25
25
  */
26
- canMakePayments(subTypeEnum: ApplePaySubTypeEnum): any;
26
+ canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): boolean;
27
+ isAppPayEnabled(): boolean;
27
28
  /**
28
29
  * Submit Pay
29
30
  * @param paymentSessionData
@@ -28,12 +28,11 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
28
28
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
29
29
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
30
30
  */
31
- import { ApplePaySubTypeEnum, componentSignEnum, environmentEnum, eventCodeEnum, productSceneEnum } from "../../types";
32
- import ApplePayService from "../../common/applepay";
33
- import { getComponentSign, parseSessionData } from "../component";
31
+ import { componentSignEnum, environmentEnum, eventCodeEnum, productSceneEnum } from "../../types";
32
+ import ApplePayService from "./apple";
33
+ import { getComponentSign, parseSessionData } from "../../core/component";
34
34
  import { getApplePayPaymentSession, submitPayInfo } from "../../service";
35
- import CoreInstance from "../instance";
36
- import { APPLE_PAY_RECURRING_VERSION, APPLE_PAY_VERSION } from "../../common/applepay/interface";
35
+ import CoreInstance from "../../core/instance";
37
36
  import { EVENT } from "../../constant";
38
37
 
39
38
  /**
@@ -139,10 +138,12 @@ var ApplePayComponent = /*#__PURE__*/function (_CoreInstance) {
139
138
  }, {
140
139
  key: "canMakePayments",
141
140
  value: function canMakePayments(subTypeEnum) {
142
- if (ApplePaySubTypeEnum.ApplePayRecurringPayment === subTypeEnum) {
143
- return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_RECURRING_VERSION) : false;
144
- }
145
- return window.ApplePaySession ? window.ApplePaySession.canMakePayments() && window.ApplePaySession.supportsVersion(APPLE_PAY_VERSION) : false;
141
+ return ApplePayService.canMakePayments(subTypeEnum);
142
+ }
143
+ }, {
144
+ key: "isAppPayEnabled",
145
+ value: function isAppPayEnabled() {
146
+ return true;
146
147
  }
147
148
 
148
149
  /**
@@ -364,9 +365,12 @@ var ApplePayComponent = /*#__PURE__*/function (_CoreInstance) {
364
365
  };
365
366
  // set Apple Pay params
366
367
  this._applePayService.setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError, applePayTrace);
367
-
368
368
  // init Apple Pay service
369
- this._applePayService.startPay(this._parseData);
369
+ try {
370
+ this._applePayService.startPay(this._parseData);
371
+ } catch (error) {
372
+ logError("appple runtime excepiton", error);
373
+ }
370
374
  }
371
375
  }]);
372
376
  return ApplePayComponent;
@@ -0,0 +1,15 @@
1
+ import { BusContext, BusMessage, BusSubscriber } from "../../core/bus";
2
+ export declare class ApplePayInitMessage {
3
+ private environment;
4
+ private locale;
5
+ }
6
+ export declare class ApplePayBusSubscriber extends BusSubscriber {
7
+ private applePay;
8
+ constructor();
9
+ actionNames(): string[];
10
+ protected onOptionalInit(context: BusContext, message: BusMessage): void;
11
+ protected onCanMakePayments(context: BusContext, message: BusMessage): void;
12
+ protected onCreateComponent(context: BusContext, message: BusMessage): void;
13
+ protected onDestoryComponent(context: BusContext, message: BusMessage): void;
14
+ onMessage(context: BusContext, message: BusMessage): void;
15
+ }
@@ -0,0 +1,99 @@
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 _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); }
5
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
6
+ 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); }; }
7
+ 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); }
8
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
9
+ 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; } }
10
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ 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; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
16
+ 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); }
17
+ import { BusManager, BusMessage, BusSubscriber } from "../../core/bus";
18
+ import { ApplePayActionEnum, PaymentActionEnum, SDKCallbackActionEnum } from "../../core/bus/interface";
19
+ import ApplePayComponent from "./component";
20
+ import ApplePayService from "./apple";
21
+ export var ApplePayInitMessage = /*#__PURE__*/_createClass(function ApplePayInitMessage() {
22
+ _classCallCheck(this, ApplePayInitMessage);
23
+ _defineProperty(this, "environment", void 0);
24
+ _defineProperty(this, "locale", void 0);
25
+ });
26
+ export var ApplePayBusSubscriber = /*#__PURE__*/function (_BusSubscriber) {
27
+ _inherits(ApplePayBusSubscriber, _BusSubscriber);
28
+ var _super = _createSuper(ApplePayBusSubscriber);
29
+ function ApplePayBusSubscriber() {
30
+ var _this;
31
+ _classCallCheck(this, ApplePayBusSubscriber);
32
+ _this = _super.call(this);
33
+ _defineProperty(_assertThisInitialized(_this), "applePay", void 0);
34
+ return _this;
35
+ }
36
+ _createClass(ApplePayBusSubscriber, [{
37
+ key: "actionNames",
38
+ value: function actionNames() {
39
+ return Object.values(ApplePayActionEnum).concat(Object.values(PaymentActionEnum));
40
+ }
41
+ }, {
42
+ key: "onOptionalInit",
43
+ value: function onOptionalInit(context, message) {
44
+ console.log('onOptionalInit', message.getData());
45
+ }
46
+ }, {
47
+ key: "onCanMakePayments",
48
+ value: function onCanMakePayments(context, message) {
49
+ var _message$getJSONObjec;
50
+ console.log('onCanMakePayments', message.getData());
51
+ var canMakePayments = ApplePayService.canMakePayments((_message$getJSONObjec = message.getJSONObject()) === null || _message$getJSONObjec === void 0 ? void 0 : _message$getJSONObjec.subPaymentMethod);
52
+ context === null || context === void 0 || context.onCallBack(message.result(canMakePayments));
53
+ }
54
+ }, {
55
+ key: "onCreateComponent",
56
+ value: function onCreateComponent(context, message) {
57
+ var data = message.getJSONObject();
58
+ console.log('onCreateComponent', message);
59
+ this.applePay = new ApplePayComponent(_objectSpread(_objectSpread({}, data === null || data === void 0 ? void 0 : data.options), {}, {
60
+ // todo 需要补充其它参数的桥接
61
+ onEventCallback: function onEventCallback(state) {
62
+ console.log('onCreateComponent#onEventCallback', state);
63
+ if (state) {
64
+ BusManager.publish(new BusMessage(SDKCallbackActionEnum.onEventCallback, JSON.stringify(state)));
65
+ }
66
+ }
67
+ }));
68
+ var paymentSessionData = data === null || data === void 0 ? void 0 : data.paymentSessionData;
69
+ this.applePay.submitPay(paymentSessionData);
70
+ }
71
+ }, {
72
+ key: "onDestoryComponent",
73
+ value: function onDestoryComponent(context, message) {
74
+ this.applePay = null;
75
+ console.log('onDestoryComponent', context, message);
76
+ }
77
+ }, {
78
+ key: "onMessage",
79
+ value: function onMessage(context, message) {
80
+ switch (message.getAction()) {
81
+ case PaymentActionEnum.optional_init:
82
+ this.onOptionalInit(context, message);
83
+ break;
84
+ case ApplePayActionEnum.canMakePayments:
85
+ this.onCanMakePayments(context, message);
86
+ break;
87
+ case ApplePayActionEnum.createComponent:
88
+ this.onCreateComponent(context, message);
89
+ break;
90
+ case ApplePayActionEnum.destoryComponent:
91
+ this.onDestoryComponent(context, message);
92
+ break;
93
+ default:
94
+ console.log("Unknown action: " + message.getAction());
95
+ }
96
+ }
97
+ }]);
98
+ return ApplePayBusSubscriber;
99
+ }(BusSubscriber);
@@ -364,7 +364,7 @@ var ComponentApp = /*#__PURE__*/function () {
364
364
  this._actionQueryPromise = new Promise( /*#__PURE__*/function () {
365
365
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
366
366
  var _this5$_renderParams, _this5$_renderParams2, _this5$_renderParams3, _this5$_renderParams4, _this5$_renderParams5;
367
- var envInfo, params, _this5$_renderParams$, extendInfo, enableVaultingApiOptimize, enableEasypayApiOptimize, extendInfoData, _this5$_renderParams6, _this5$_renderParams7, _ref3, _ref3$productSceneVer, productSceneVersion, _ref3$productScene, productScene, _ref4, _ref4$action, _ref4$action2, _ref4$action2$autoDeb, autoDebitWithToken, _this5$_renderParams8, _action$web, _action$wap, action, signType;
367
+ var envInfo, params, _ref3, extendInfo, enableVaultingApiOptimize, enableEasypayApiOptimize, extendInfoData, _this5$_renderParams6, _this5$_renderParams7, _ref4, _ref4$productSceneVer, productSceneVersion, _ref4$productScene, productScene, _ref5, _ref5$action, _ref5$action2, _ref5$action2$autoDeb, autoDebitWithToken, _this5$_renderParams8, _action$web, _action$wap, action, signType;
368
368
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
369
369
  while (1) switch (_context2.prev = _context2.next) {
370
370
  case 0:
@@ -380,7 +380,7 @@ var ComponentApp = /*#__PURE__*/function () {
380
380
  /**
381
381
  * @description Simulated or unnecessary scenarios
382
382
  */
383
- _this5$_renderParams$ = (_this5$_renderParams4 = _this5._renderParams) === null || _this5$_renderParams4 === void 0 ? void 0 : _this5$_renderParams4.paymentSessionMetaData, extendInfo = _this5$_renderParams$.extendInfo;
383
+ _ref3 = ((_this5$_renderParams4 = _this5._renderParams) === null || _this5$_renderParams4 === void 0 ? void 0 : _this5$_renderParams4.paymentSessionMetaData) || {}, extendInfo = _ref3.extendInfo;
384
384
  enableVaultingApiOptimize = false;
385
385
  enableEasypayApiOptimize = false;
386
386
  try {
@@ -427,8 +427,8 @@ var ComponentApp = /*#__PURE__*/function () {
427
427
  _context2.next = 26;
428
428
  break;
429
429
  }
430
- _ref3 = params.paymentSessionConfig || {}, _ref3$productSceneVer = _ref3.productSceneVersion, productSceneVersion = _ref3$productSceneVer === void 0 ? '' : _ref3$productSceneVer, _ref3$productScene = _ref3.productScene, productScene = _ref3$productScene === void 0 ? '' : _ref3$productScene;
431
- _ref4 = ((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.paymentSessionMetaData) || {}, _ref4$action = _ref4.action, _ref4$action2 = _ref4$action === void 0 ? {} : _ref4$action, _ref4$action2$autoDeb = _ref4$action2.autoDebitWithToken, autoDebitWithToken = _ref4$action2$autoDeb === void 0 ? false : _ref4$action2$autoDeb;
430
+ _ref4 = params.paymentSessionConfig || {}, _ref4$productSceneVer = _ref4.productSceneVersion, productSceneVersion = _ref4$productSceneVer === void 0 ? '' : _ref4$productSceneVer, _ref4$productScene = _ref4.productScene, productScene = _ref4$productScene === void 0 ? '' : _ref4$productScene;
431
+ _ref5 = ((_this5$_renderParams6 = _this5._renderParams) === null || _this5$_renderParams6 === void 0 ? void 0 : _this5$_renderParams6.paymentSessionMetaData) || {}, _ref5$action = _ref5.action, _ref5$action2 = _ref5$action === void 0 ? {} : _ref5$action, _ref5$action2$autoDeb = _ref5$action2.autoDebitWithToken, autoDebitWithToken = _ref5$action2$autoDeb === void 0 ? false : _ref5$action2$autoDeb;
432
432
  if (!((_this5$_renderParams7 = _this5._renderParams) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.paymentSessionMetaData) !== null && _this5$_renderParams7 !== void 0 && (_this5$_renderParams7 = _this5$_renderParams7.action) !== null && _this5$_renderParams7 !== void 0 && _this5$_renderParams7.skipSdkQuery && enableEasypayApiOptimize)) {
433
433
  _context2.next = 21;
434
434
  break;
@@ -542,7 +542,7 @@ var ComponentApp = /*#__PURE__*/function () {
542
542
 
543
543
  // eslint-disable-next-line no-async-promise-executor
544
544
  this._actionSubmitPromise = new Promise( /*#__PURE__*/function () {
545
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
545
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
546
546
  var _this6$_renderParams;
547
547
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
548
548
  while (1) switch (_context3.prev = _context3.next) {
@@ -605,7 +605,7 @@ var ComponentApp = /*#__PURE__*/function () {
605
605
  }, _callee3);
606
606
  }));
607
607
  return function (_x3) {
608
- return _ref5.apply(this, arguments);
608
+ return _ref6.apply(this, arguments);
609
609
  };
610
610
  }());
611
611
  }
@@ -1196,9 +1196,9 @@ var ComponentApp = /*#__PURE__*/function () {
1196
1196
  }
1197
1197
  }, {
1198
1198
  key: "handleDeclareInfo",
1199
- value: function handleDeclareInfo(_ref6) {
1200
- var _ref6$closeDialogData = _ref6.closeDialogData,
1201
- closeDialogData = _ref6$closeDialogData === void 0 ? {} : _ref6$closeDialogData;
1199
+ value: function handleDeclareInfo(_ref7) {
1200
+ var _ref7$closeDialogData = _ref7.closeDialogData,
1201
+ closeDialogData = _ref7$closeDialogData === void 0 ? {} : _ref7$closeDialogData;
1202
1202
  _handleDeclareInfo({
1203
1203
  closeDialogData: closeDialogData
1204
1204
  });