@alipay/ams-checkout 0.0.1710212811-dev.0 → 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
  */
@@ -30,9 +30,11 @@ declare class ApplePayService {
30
30
  */
31
31
  setApplePayParams(getMerchantSession: IGetMerchantSession, completePaymentAuthorized: ICompletePaymentAuthorized, completeApplePay: ICompleteApplePay, logError: ILogError, applePayTrace: IApplePayTrace): void;
32
32
  /**
33
- * Apple Pay is enabled
33
+ * Is Apple Pay Enabled
34
+ * @param subTypeEnum
35
+ * @returns
34
36
  */
35
- isEnabled: () => boolean;
37
+ static canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): any;
36
38
  /**
37
39
  * has Active Card in Apple Pay
38
40
  * @param merchantIdentifier
@@ -16,6 +16,9 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
16
16
  * 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.
17
17
  */
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
+ import { APPLE_PAY_VERSION, APPLE_PAY_RECURRING_VERSION } from "./interface";
20
+ import { ApplePaySubTypeEnum } from "../../types";
21
+
19
22
  /**
20
23
  * Apple Pay Service
21
24
  */
@@ -31,12 +34,6 @@ var ApplePayService = /*#__PURE__*/function () {
31
34
  _defineProperty(this, "completeApplePay", void 0);
32
35
  _defineProperty(this, "logError", void 0);
33
36
  _defineProperty(this, "applePayTrace", void 0);
34
- /**
35
- * Apple Pay is enabled
36
- */
37
- _defineProperty(this, "isEnabled", function () {
38
- return window.ApplePaySession ? window.ApplePaySession.canMakePayments() : false;
39
- });
40
37
  _defineProperty(this, "onvalidatemerchant", function (event) {
41
38
  _this.applePayTrace('onValidateMerchant');
42
39
  _this.getMerchantSession({
@@ -44,6 +41,7 @@ var ApplePayService = /*#__PURE__*/function () {
44
41
  merchantIdentifier: _this.merchantIdentifier,
45
42
  validationUrl: event.validationURL
46
43
  }).then(function (merchantSessionObjectString) {
44
+ console.log("onvalidatemerchant#merchantSessionObjectString", merchantSessionObjectString);
47
45
  var merchantSessionObject = JSON.parse(merchantSessionObjectString);
48
46
  _this.session.completeMerchantValidation(merchantSessionObject);
49
47
  _this.applePayTrace('completeMerchantValidation');
@@ -88,28 +86,80 @@ var ApplePayService = /*#__PURE__*/function () {
88
86
  throw Error('ApplePaySession is null in window');
89
87
  }
90
88
  var paymentSessionFactor = param.paymentSessionFactor;
91
- var applePay = paymentSessionFactor.applePay,
89
+ var extendInfo = paymentSessionFactor.extendInfo,
92
90
  merchantInfo = paymentSessionFactor.merchantInfo,
93
91
  paymentAmount = paymentSessionFactor.paymentAmount,
94
- order = paymentSessionFactor.order;
92
+ order = paymentSessionFactor.order,
93
+ recurringInfo = paymentSessionFactor.recurringInfo;
95
94
  _this.merchantIdentifier = merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.partnerId;
96
- var request = {
97
- merchantCapabilities: applePay === null || applePay === void 0 ? void 0 : applePay.merchantCapabilities,
98
- supportedNetworks: applePay === null || applePay === void 0 ? void 0 : applePay.supportedNetworks,
99
- countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
100
- currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
101
- total: {
102
- type: 'final',
103
- label: order === null || order === void 0 ? void 0 : order.orderDescription,
104
- amount: paymentAmount === null || paymentAmount === void 0 ? 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)) {
96
+ _this.logError("invalid session data");
97
+ return;
98
+ }
99
+ // todo 补充参数校验
100
+ if (recurringInfo) {
101
+ var _recurringInfo$interv;
102
+ if (!(order !== null && order !== void 0 && order.orderDescription) || recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL) {
103
+ _this.logError("invalid session data");
104
+ return;
105
105
  }
106
- };
107
- _this.session = new ApplePaySession(2, request);
106
+ // && order
107
+ var lineItem = {
108
+ type: 'final',
109
+ label: recurringInfo.title,
110
+ amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value,
111
+ paymentTiming: "recurring",
112
+ recurringPaymentStartDate: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.startDate ? new Date(recurringInfo.startDate) : null,
113
+ recurringPaymentEndDate: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.endDate ? new Date(recurringInfo.endDate) : null,
114
+ recurringPaymentIntervalUnit: recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.intervalUnit ? recurringInfo.intervalUnit : "month",
115
+ recurringPaymentIntervalCount: (_recurringInfo$interv = recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.intervalCount) !== null && _recurringInfo$interv !== void 0 ? _recurringInfo$interv : 1
116
+ };
117
+ var recurringRequest = {
118
+ // 不知道显示在哪里
119
+ paymentDescription: order === null || order === void 0 ? void 0 : order.orderDescription,
120
+ billingAgreement: recurringInfo.agreementDescription,
121
+ // todo
122
+ regularBilling: lineItem,
123
+ managementURL: recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.managementURL,
124
+ tokenNotificationURL: recurringInfo === null || recurringInfo === void 0 ? void 0 : recurringInfo.tokenNotificationURL
125
+ };
126
+ var request = {
127
+ merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
128
+ supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
129
+ countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
130
+ currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
131
+ total: {
132
+ type: 'final',
133
+ label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
134
+ amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
135
+ },
136
+ recurringPaymentRequest: recurringRequest,
137
+ lineItems: [lineItem]
138
+ };
139
+ _this.session = new ApplePaySession(APPLE_PAY_RECURRING_VERSION, request);
140
+ } else {
141
+ var _request = {
142
+ merchantCapabilities: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.merchantCapabilities,
143
+ supportedNetworks: extendInfo === null || extendInfo === void 0 ? void 0 : extendInfo.supportedNetworks,
144
+ countryCode: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.registeredCountry,
145
+ currencyCode: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.currency,
146
+ total: {
147
+ type: 'final',
148
+ label: merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.merchantName,
149
+ amount: paymentAmount === null || paymentAmount === void 0 ? void 0 : paymentAmount.value
150
+ }
151
+ };
152
+ _this.session = new ApplePaySession(APPLE_PAY_VERSION, _request);
153
+ }
108
154
  _this.session.onvalidatemerchant = _this.onvalidatemerchant;
109
155
  _this.session.onpaymentauthorized = _this.onpaymentauthorized;
110
156
  _this.session.oncancel = function () {
111
157
  _this.logError('UserCancel');
112
- _this.session.abort();
158
+ try {
159
+ _this.session.abort();
160
+ } catch (error) {
161
+ console.log("session.abort() error");
162
+ }
113
163
  };
114
164
  _this.session.begin();
115
165
  _this.applePayTrace('sessionBegin');
@@ -133,6 +183,12 @@ var ApplePayService = /*#__PURE__*/function () {
133
183
  this.logError = logError;
134
184
  this.applePayTrace = applePayTrace;
135
185
  }
186
+
187
+ /**
188
+ * Is Apple Pay Enabled
189
+ * @param subTypeEnum
190
+ * @returns
191
+ */
136
192
  }, {
137
193
  key: "hasActiveCard",
138
194
  value: (
@@ -165,6 +221,14 @@ var ApplePayService = /*#__PURE__*/function () {
165
221
  }
166
222
  return hasActiveCard;
167
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
+ }
168
232
  }]);
169
233
  return ApplePayService;
170
234
  }();
@@ -5,8 +5,8 @@
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 { IApplePayOptionsParams } from '../../types';
9
- import CoreInstance from '../instance';
8
+ import { ApplePaySubTypeEnum, IApplePayOptionsParams } from '../../types';
9
+ import CoreInstance from '../../core/instance';
10
10
  /**
11
11
  * Apple pay Component
12
12
  */
@@ -20,7 +20,10 @@ declare class ApplePayComponent extends CoreInstance {
20
20
  private logDeviceId;
21
21
  /**
22
22
  * Is Apple Pay Enabled
23
+ * @param subTypeEnum
24
+ * @returns
23
25
  */
26
+ canMakePayments(subTypeEnum?: ApplePaySubTypeEnum): boolean;
24
27
  isAppPayEnabled(): boolean;
25
28
  /**
26
29
  * Submit Pay
@@ -29,10 +29,10 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
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
31
  import { componentSignEnum, environmentEnum, eventCodeEnum, productSceneEnum } from "../../types";
32
- import ApplePayService from "../../common/applepay";
33
- import { getComponentSign, parseSessionData } from "../component";
32
+ import ApplePayService from "./apple";
33
+ import { getComponentSign, parseSessionData } from "../../core/component";
34
34
  import { getApplePayPaymentSession, submitPayInfo } from "../../service";
35
- import CoreInstance from "../instance";
35
+ import CoreInstance from "../../core/instance";
36
36
  import { EVENT } from "../../constant";
37
37
 
38
38
  /**
@@ -132,11 +132,18 @@ var ApplePayComponent = /*#__PURE__*/function (_CoreInstance) {
132
132
 
133
133
  /**
134
134
  * Is Apple Pay Enabled
135
+ * @param subTypeEnum
136
+ * @returns
135
137
  */
138
+ }, {
139
+ key: "canMakePayments",
140
+ value: function canMakePayments(subTypeEnum) {
141
+ return ApplePayService.canMakePayments(subTypeEnum);
142
+ }
136
143
  }, {
137
144
  key: "isAppPayEnabled",
138
145
  value: function isAppPayEnabled() {
139
- return this._applePayService.isEnabled();
146
+ return true;
140
147
  }
141
148
 
142
149
  /**
@@ -356,12 +363,14 @@ var ApplePayComponent = /*#__PURE__*/function (_CoreInstance) {
356
363
  biz: 'sdk'
357
364
  }).send();
358
365
  };
359
-
360
366
  // set Apple Pay params
361
367
  this._applePayService.setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError, applePayTrace);
362
-
363
368
  // init Apple Pay service
364
- this._applePayService.startPay(this._parseData);
369
+ try {
370
+ this._applePayService.startPay(this._parseData);
371
+ } catch (error) {
372
+ logError("appple runtime excepiton", error);
373
+ }
365
374
  }
366
375
  }]);
367
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);