@alipay/ams-checkout 0.0.1726046231-dev.0 → 0.0.1726046231-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,21 @@
1
+ export var ThemeType = /*#__PURE__*/function (ThemeType) {
2
+ ThemeType["NostalgicGray"] = "nostalgicGray";
3
+ ThemeType["Light"] = "light";
4
+ ThemeType["Night"] = "night";
5
+ ThemeType["CherryBlossomPink"] = "cherryBlossomPink";
6
+ ThemeType["GamingPurple"] = "gamingPurple";
7
+ ThemeType["AgateGreen"] = "agateGreen";
8
+ return ThemeType;
9
+ }({});
1
10
  export var addressTheme = {
2
11
  night: 'NIGHT',
3
12
  light: 'LIGHT'
4
13
  };
14
+ export var EventCallbackCode = /*#__PURE__*/function (EventCallbackCode) {
15
+ EventCallbackCode["Failed"] = "Failed";
16
+ EventCallbackCode["Completed"] = "Completed";
17
+ return EventCallbackCode;
18
+ }({});
5
19
  // export type IMountOptions = AddressMountOptions | LinkAuthMountOptions | PaymentMountOptions;
6
20
 
7
21
  export var AddressEventCallbackName = /*#__PURE__*/function (AddressEventCallbackName) {
@@ -9,6 +23,4 @@ export var AddressEventCallbackName = /*#__PURE__*/function (AddressEventCallbac
9
23
  return AddressEventCallbackName;
10
24
  }({});
11
25
 
12
- // export type IMountResult = AddressMountResult | LinkAuthMountResult | PaymentMountResult;
13
-
14
- ;
26
+ // export type IMountResult = AddressMountResult | LinkAuthMountResult | PaymentMountResult;
@@ -79,6 +79,7 @@ export default class AMSSDK {
79
79
  normalUrl?: string;
80
80
  schemeUrl?: string;
81
81
  applinkUrl?: string;
82
+ callAppJudgeTime?: number;
82
83
  }): Promise<void>;
83
84
  /**
84
85
  * @description Overlay Subscription
@@ -418,6 +418,7 @@ var AMSSDK = /*#__PURE__*/function () {
418
418
  var normalUrl = (data === null || data === void 0 ? void 0 : data.normalUrl) || '';
419
419
  var schemeUrl = (data === null || data === void 0 ? void 0 : data.schemeUrl) || '';
420
420
  var applinkUrl = (data === null || data === void 0 ? void 0 : data.applinkUrl) || '';
421
+ var callAppJudgeTime = (data === null || data === void 0 ? void 0 : data.callAppJudgeTime) || '';
421
422
  var jumpFunc = function jumpFunc() {
422
423
  if (normalUrl) {
423
424
  resolve();
@@ -440,6 +441,9 @@ var AMSSDK = /*#__PURE__*/function () {
440
441
  },
441
442
  delay: 0
442
443
  };
444
+ if (callAppJudgeTime) {
445
+ config['resultJudgmentTime'] = callAppJudgeTime;
446
+ }
443
447
  try {
444
448
  var callLib = new CallApp(config);
445
449
  callLib.open({
@@ -25,6 +25,7 @@ export default class ComponentApp {
25
25
  private _appLocationSearch;
26
26
  private _renderDisplayType;
27
27
  private _multipleCallbackEvents;
28
+ private _isAppWebview;
28
29
  _merchantAppointParam: IMerchantAppointParam;
29
30
  private _webAppHeartBeatTimeoutFn;
30
31
  constructor(componentOption?: {
@@ -25,6 +25,7 @@ import { ComponentSignEnum, DisplayTypeEnum, eventCodeEnum, MessageName, Platfor
25
25
  import { getType, isJsonString, isPC } from "../../util";
26
26
  import { isLocalMock } from "../../util/mock";
27
27
  import { matchVersion } from "../../util/versionCompare";
28
+ import { getBackScheme } from "../../util/getBackScheme";
28
29
  import { handlePaymentSessionConfig } from "../payment-element/utils";
29
30
  import { createIframe, createPreloadIframe, getAppDomain, getIframeUrl } from "./cashierApp";
30
31
  import { getChannelBehavior } from "./channel";
@@ -57,6 +58,7 @@ var ComponentApp = /*#__PURE__*/function () {
57
58
  _defineProperty(this, "_appLocationSearch", void 0);
58
59
  _defineProperty(this, "_renderDisplayType", DisplayTypeEnum.popup);
59
60
  _defineProperty(this, "_multipleCallbackEvents", void 0);
61
+ _defineProperty(this, "_isAppWebview", void 0);
60
62
  _defineProperty(this, "_merchantAppointParam", void 0);
61
63
  _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
62
64
  this._appVersion = componentOption.appVersion;
@@ -269,6 +271,7 @@ var ComponentApp = /*#__PURE__*/function () {
269
271
  var appendAliasContainerId = renderParams.appendAliasContainerId ? "-".concat(this._selector) : '';
270
272
  var inlineId = "".concat(COMPONENT_CONTAINER_ID).concat(appendAliasContainerId);
271
273
  var insertedNode = this._renderDisplayType === DisplayTypeEnum.inline ? "#".concat(inlineId) : this._selector;
274
+ this._isAppWebview = renderParams.isAppWebview;
272
275
  this.initLoggerMeta();
273
276
  this.initSecurity();
274
277
  this._performanceData.push({
@@ -700,7 +703,7 @@ var ComponentApp = /*#__PURE__*/function () {
700
703
  this._actionSubmitPromise = new Promise( /*#__PURE__*/function () {
701
704
  var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
702
705
  var _channelBehavior$buil, _this6$_renderParams$;
703
- var shouldSkipSubmitPayInSDK, _this6$_renderParams, _this6$_renderParams2, _ref11, _ref11$productSceneVe, productSceneVersion, _ref11$productScene, productScene, _ref12, _ref12$action, _ref12$action2, _ref12$action2$enable, enableSignAgreement, _ref12$action2$autoDe, autoDebitWithToken, extParams;
706
+ var shouldSkipSubmitPayInSDK, _this6$_renderParams, _this6$_renderParams2, _this6$_renderParams3, _ref11, _ref11$productSceneVe, productSceneVersion, _ref11$productScene, productScene, _ref12, _ref12$action, _ref12$action2, _ref12$action2$enable, enableSignAgreement, _ref12$action2$autoDe, autoDebitWithToken, _ref13, _ref13$paymentMethodI, _ref13$paymentMethodI2, _ref13$paymentMethodI3, paymentMethodType, isAppWebview, backScheme, extParams;
704
707
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
705
708
  while (1) switch (_context3.prev = _context3.next) {
706
709
  case 0:
@@ -723,9 +726,16 @@ var ComponentApp = /*#__PURE__*/function () {
723
726
  if (ComponentSignEnum.EASY_PAY_WALLET === _this6._componentSign) {
724
727
  _ref11 = params.paymentSessionConfig || {}, _ref11$productSceneVe = _ref11.productSceneVersion, productSceneVersion = _ref11$productSceneVe === void 0 ? '' : _ref11$productSceneVe, _ref11$productScene = _ref11.productScene, productScene = _ref11$productScene === void 0 ? '' : _ref11$productScene;
725
728
  _ref12 = ((_this6$_renderParams2 = _this6._renderParams) === null || _this6$_renderParams2 === void 0 ? void 0 : _this6$_renderParams2.paymentSessionMetaData) || {}, _ref12$action = _ref12.action, _ref12$action2 = _ref12$action === void 0 ? {} : _ref12$action, _ref12$action2$enable = _ref12$action2.enableSignAgreement, enableSignAgreement = _ref12$action2$enable === void 0 ? false : _ref12$action2$enable, _ref12$action2$autoDe = _ref12$action2.autoDebitWithToken, autoDebitWithToken = _ref12$action2$autoDe === void 0 ? false : _ref12$action2$autoDe;
729
+ _ref13 = ((_this6$_renderParams3 = _this6._renderParams) === null || _this6$_renderParams3 === void 0 ? void 0 : _this6$_renderParams3.paymentSessionMetaData) || {}, _ref13$paymentMethodI = _ref13.paymentMethodInfoView, _ref13$paymentMethodI2 = _ref13$paymentMethodI === void 0 ? {} : _ref13$paymentMethodI, _ref13$paymentMethodI3 = _ref13$paymentMethodI2.paymentMethodType, paymentMethodType = _ref13$paymentMethodI3 === void 0 ? '' : _ref13$paymentMethodI3;
726
730
  if (productScene === ProductSceneEnum.EASY_PAY && productSceneVersion === '2.0' && !autoDebitWithToken) {
727
- ///EasyPay 2.0 首次传signAgreement字段
731
+ isAppWebview = _this6._isAppWebview || false; ///EasyPay 2.0 首次传signAgreement字段
728
732
  params['signAgreement'] = enableSignAgreement;
733
+ if (paymentMethodType == 'ALIPAY_CN' && !isAppWebview) {
734
+ backScheme = getBackScheme(undefined, _this6.AMSSDK.logger);
735
+ if (backScheme && backScheme !== 'https') {
736
+ params['h5FromApp'] = encodeURIComponent(backScheme);
737
+ }
738
+ }
729
739
  }
730
740
  }
731
741
  // 带上标记告知WebCheckOut SDK已发送submitpay请求
@@ -1371,6 +1381,8 @@ var ComponentApp = /*#__PURE__*/function () {
1371
1381
  key: "handleRedirect",
1372
1382
  value: function handleRedirect(data) {
1373
1383
  var _data$isDestroy,
1384
+ _data$isCallApp,
1385
+ _data$callAppDetectSu,
1374
1386
  _this7 = this;
1375
1387
  var fromFastSdk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1376
1388
  var _data = typeof data === 'string' ? {
@@ -1380,38 +1392,48 @@ var ComponentApp = /*#__PURE__*/function () {
1380
1392
  schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
1381
1393
  normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
1382
1394
  target: data === null || data === void 0 ? void 0 : data.target,
1383
- isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true
1395
+ isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true,
1396
+ isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
1397
+ callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 2000
1384
1398
  });
1385
1399
  this.AMSSDK.logger.logInfo({
1386
1400
  title: 'sdk_event_call_url_start'
1387
1401
  }, _objectSpread({}, data)).send();
1388
- var successCallback = function successCallback(type, url) {
1402
+ var successCallback = function successCallback(type, url, durationInSeconds) {
1389
1403
  _this7.dispatchToSDK(EVENT.eventCallback.name, {
1390
1404
  code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
1391
1405
  message: "Successfully opened the app,".concat(type, ": ").concat(url)
1392
1406
  });
1393
- _this7.AMSSDK.logger.logInfo({
1394
- title: 'sdk_event_call_url_success'
1395
- }, {
1407
+ var extra = {
1396
1408
  redirectInfo: JSON.stringify(_data),
1397
1409
  openType: type,
1398
1410
  url: url,
1399
1411
  fromFastSdk: fromFastSdk
1400
- }).send();
1412
+ };
1413
+ if (durationInSeconds) {
1414
+ extra['durationInSeconds'] = durationInSeconds;
1415
+ }
1416
+ _this7.AMSSDK.logger.logInfo({
1417
+ title: 'sdk_event_call_url_success'
1418
+ }, extra).send();
1401
1419
  };
1402
- var failCallback = function failCallback(type, url) {
1420
+ var failCallback = function failCallback(type, url, durationInSeconds) {
1403
1421
  _this7.dispatchToSDK(EVENT.eventCallback.name, {
1404
1422
  code: eventCodeEnum.SDK_CALL_URL_ERROR,
1405
1423
  message: "Failed to open app,applinkUrl: ".concat(_data === null || _data === void 0 ? void 0 : _data.applinkUrl, " schemeUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.schemeUrl, " normalUrl: ").concat(_data === null || _data === void 0 ? void 0 : _data.normalUrl)
1406
1424
  });
1407
- _this7.AMSSDK.logger.logInfo({
1408
- title: 'sdk_error_call_url_failed'
1409
- }, {
1425
+ var extra = {
1410
1426
  redirectInfo: JSON.stringify(_data),
1411
1427
  openType: type,
1412
1428
  url: url,
1413
1429
  fromFastSdk: fromFastSdk
1414
- }).send();
1430
+ };
1431
+ if (durationInSeconds) {
1432
+ extra['durationInSeconds'] = durationInSeconds;
1433
+ }
1434
+ _this7.AMSSDK.logger.logInfo({
1435
+ title: 'sdk_error_call_url_failed'
1436
+ }, extra).send();
1415
1437
  };
1416
1438
 
1417
1439
  // 支持 target: _blank,新开tab页打开
@@ -1429,6 +1451,26 @@ var ComponentApp = /*#__PURE__*/function () {
1429
1451
  }
1430
1452
  // 销毁iframe和全局loading
1431
1453
  if (_data !== null && _data !== void 0 && _data.isDestroy) this.cleanContainer();
1454
+ // 唤端
1455
+ if (_data !== null && _data !== void 0 && _data.isCallApp && _data !== null && _data !== void 0 && _data.schemeUrl) {
1456
+ var startCallAppTime = new Date();
1457
+ var detectSuccessDelay = typeof (data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) === 'number' ? data.callAppDetectSuccessDelay : 5000;
1458
+ this.AMSSDK._redirect({
1459
+ schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl,
1460
+ callAppJudgeTime: detectSuccessDelay
1461
+ }).then(function () {
1462
+ var endCallAppTime = new Date();
1463
+ var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
1464
+ var durationInSeconds = durationInMilliseconds / 1000;
1465
+ successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl, durationInSeconds);
1466
+ }).catch(function () {
1467
+ var endCallAppTime = new Date();
1468
+ var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
1469
+ var durationInSeconds = durationInMilliseconds / 1000;
1470
+ failCallback(RedirectType.SchemeUrl, _data.schemeUrl, durationInSeconds);
1471
+ });
1472
+ return;
1473
+ }
1432
1474
  this.AMSSDK._redirect({
1433
1475
  applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
1434
1476
  }).then(function () {
@@ -1453,9 +1495,9 @@ var ComponentApp = /*#__PURE__*/function () {
1453
1495
  }
1454
1496
  }, {
1455
1497
  key: "handleDeclareInfo",
1456
- value: function handleDeclareInfo(_ref13) {
1457
- var _ref13$closeDialogDat = _ref13.closeDialogData,
1458
- closeDialogData = _ref13$closeDialogDat === void 0 ? {} : _ref13$closeDialogDat;
1498
+ value: function handleDeclareInfo(_ref14) {
1499
+ var _ref14$closeDialogDat = _ref14.closeDialogData,
1500
+ closeDialogData = _ref14$closeDialogDat === void 0 ? {} : _ref14$closeDialogDat;
1459
1501
  _handleDeclareInfo({
1460
1502
  closeDialogData: closeDialogData
1461
1503
  });
@@ -1632,6 +1674,7 @@ var ComponentApp = /*#__PURE__*/function () {
1632
1674
  renderDisplayType: (_this$_renderParams17 = this._renderParams) === null || _this$_renderParams17 === void 0 ? void 0 : _this$_renderParams17.renderDisplayType,
1633
1675
  appearance: (_this$_renderParams18 = this._renderParams) === null || _this$_renderParams18 === void 0 ? void 0 : _this$_renderParams18.appearance,
1634
1676
  notRedirectAfterComplete: ((_this$_renderParams19 = this._renderParams) === null || _this$_renderParams19 === void 0 ? void 0 : _this$_renderParams19.notRedirectAfterComplete) === true,
1677
+ isAppWebview: this._isAppWebview,
1635
1678
  merchantAppointParam: this._merchantAppointParam,
1636
1679
  allowSubmitPayCallAhead: this._allowSubmitPayCallAhead,
1637
1680
  /** 地址组件集成的参数 */
@@ -110,6 +110,7 @@ export interface IcreateComponent {
110
110
  themeType?: string;
111
111
  accentColor?: string;
112
112
  };
113
+ isAppWebview?: boolean;
113
114
  merchantAppointParam?: IMerchantAppointParam;
114
115
  }
115
116
  export interface IappendIframeNodesParams extends IcreateComponent {
@@ -660,24 +661,6 @@ export type IAppendParams = {
660
661
  componentSign: ComponentSignEnum;
661
662
  iframeNodesParams: IappendIframeNodesParams;
662
663
  };
663
- export declare enum EventCallbackCode {
664
- Failed = "Failed",
665
- Completed = "Completed"
666
- }
667
- export interface IElementOptions {
668
- sessionData: string;
669
- environment?: string;
670
- locale?: string;
671
- mode?: string;
672
- onEventCallback?: ({ code, message }: {
673
- code: EventCallbackCode;
674
- message: string;
675
- }) => void;
676
- loading?: {
677
- onStartLoading: () => void;
678
- onEndLoading: () => void;
679
- };
680
- }
681
664
  export declare enum AccountStatusEnum {
682
665
  EFFECTIVE = "EFFECTIVE",
683
666
  UNREGISTERED = "UNREGISTERED"
@@ -209,11 +209,6 @@ export var ProductSceneVersion = /*#__PURE__*/function (ProductSceneVersion) {
209
209
  ProductSceneVersion["V2"] = "2.0";
210
210
  return ProductSceneVersion;
211
211
  }({});
212
- export var EventCallbackCode = /*#__PURE__*/function (EventCallbackCode) {
213
- EventCallbackCode["Failed"] = "Failed";
214
- EventCallbackCode["Completed"] = "Completed";
215
- return EventCallbackCode;
216
- }({});
217
212
  export var AccountStatusEnum = /*#__PURE__*/function (AccountStatusEnum) {
218
213
  AccountStatusEnum["EFFECTIVE"] = "EFFECTIVE";
219
214
  AccountStatusEnum["UNREGISTERED"] = "UNREGISTERED";
@@ -0,0 +1,5 @@
1
+ import { Logger } from './logger';
2
+ /**
3
+ * 通过配置规则检测 UA 和获得回跳 scheme
4
+ */
5
+ export declare function getBackScheme(mockUa?: string, logger?: Logger): any;
@@ -0,0 +1,42 @@
1
+ import { isAndroid, isIOS } from "./ua";
2
+ import { RULES } from "../constant/index";
3
+ /**
4
+ * 通过配置规则检测 UA 和获得回跳 scheme
5
+ */
6
+ export function getBackScheme(mockUa, logger) {
7
+ var ua = mockUa || window.navigator.userAgent || '';
8
+ // 获取规则
9
+ var uaMatchedRule = RULES;
10
+ var matchedRule;
11
+ var matched = null;
12
+ for (var i = 0; i < uaMatchedRule.length; i++) {
13
+ var rule = uaMatchedRule[i];
14
+ matched = ua.match(rule.matchRule);
15
+ if (matched) {
16
+ matchedRule = rule;
17
+ break;
18
+ }
19
+ }
20
+ if (!matchedRule) {
21
+ logBackScheme(logger, ua, '');
22
+ return;
23
+ }
24
+ if (isAndroid(ua)) {
25
+ logBackScheme(logger, ua, matchedRule.andScheme);
26
+ return matchedRule.andScheme;
27
+ }
28
+ if (isIOS(ua)) {
29
+ logBackScheme(logger, ua, matchedRule.iosScheme);
30
+ return matchedRule.iosScheme;
31
+ }
32
+ }
33
+ function logBackScheme(logger, userAgent, scheme) {
34
+ if (logger) {
35
+ logger.logInfo({
36
+ title: 'a3753.b101271.c377460'
37
+ }, {
38
+ userAgent: userAgent,
39
+ backScheme: scheme
40
+ });
41
+ }
42
+ }
@@ -0,0 +1,2 @@
1
+ export * from './isAndroid';
2
+ export * from './isIOS';
@@ -0,0 +1,2 @@
1
+ export * from "./isAndroid";
2
+ export * from "./isIOS";
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 当前运行环境是否 Android
3
+ */
4
+ export declare function isAndroid(mockUA?: string): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 当前运行环境是否 Android
3
+ */
4
+ export function isAndroid(mockUA) {
5
+ var ua = (mockUA || navigator.userAgent).toLowerCase();
6
+ return /android|adr|linux/.test(ua);
7
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 当前运行环境是否 IOS
3
+ */
4
+ export declare function isIOS(mockUA?: string): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 当前运行环境是否 IOS
3
+ */
4
+ export function isIOS(mockUA) {
5
+ var ua = (mockUA || navigator.userAgent).toLowerCase();
6
+ return /iphone|ipad|ipod|ios|macintosh/.test(ua);
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1726046231-dev.0",
3
+ "version": "0.0.1726046231-dev.1",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",
@@ -16,6 +16,7 @@
16
16
  "scripts": {
17
17
  "build": "father build",
18
18
  "build:w": "father dev",
19
+ "dev": "father dev",
19
20
  "ci": "npm run lint",
20
21
  "cov": "jest --coverage",
21
22
  "format": "prettier --write --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx,md,json,css,less}\"",