@alipay/ams-checkout 0.0.1730107332-dev.4 → 0.0.1730706734-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/index.d.ts +7 -7
  3. package/esm/config/index.js +7 -7
  4. package/esm/constant/index.d.ts +6 -1
  5. package/esm/constant/index.js +80 -3
  6. package/esm/core/bus/ability/callback.d.ts +9 -0
  7. package/esm/{foundation/service/api-bus → core/bus}/ability/callback.js +1 -1
  8. package/esm/core/bus/ability/globalData.d.ts +10 -0
  9. package/esm/{foundation/service/api-bus → core/bus}/ability/globalData.js +2 -2
  10. package/esm/{foundation/service/api-bus → core/bus}/ability/request.d.ts +1 -1
  11. package/esm/{foundation/service/api-bus → core/bus}/ability/request.js +2 -2
  12. package/esm/core/bus/ability/security.d.ts +10 -0
  13. package/esm/core/bus/ability/security.js +104 -0
  14. package/esm/core/bus/ability/tracker.d.ts +9 -0
  15. package/esm/core/bus/ability/tracker.js +77 -0
  16. package/esm/core/bus/index.d.ts +125 -0
  17. package/esm/core/bus/index.js +366 -0
  18. package/esm/core/component/address.d.ts +8 -0
  19. package/esm/core/component/address.js +72 -0
  20. package/esm/core/component/appPreloadProcessing.d.ts +1 -0
  21. package/esm/core/component/appPreloadProcessing.js +91 -0
  22. package/esm/core/component/ckp/index.d.ts +27 -0
  23. package/esm/core/component/ckp/index.js +166 -0
  24. package/esm/core/component/element/components/address.d.ts +19 -0
  25. package/esm/core/component/element/components/address.js +68 -0
  26. package/esm/core/component/element/components/auth.d.ts +17 -0
  27. package/esm/core/component/element/components/auth.js +59 -0
  28. package/esm/core/component/element/components/payment.d.ts +19 -0
  29. package/esm/core/component/element/components/payment.js +74 -0
  30. package/esm/core/component/element/element-mock.d.ts +2 -0
  31. package/esm/core/component/element/element-mock.js +263 -0
  32. package/esm/core/component/element/index.d.ts +47 -0
  33. package/esm/core/component/element/index.js +776 -0
  34. package/esm/core/component/element/mock.d.ts +3 -0
  35. package/esm/core/component/element/mock.js +1156 -0
  36. package/esm/core/component/element/type.d.ts +176 -0
  37. package/esm/core/component/element/type.js +34 -0
  38. package/esm/core/component/element/utils.d.ts +13 -0
  39. package/esm/core/component/element/utils.js +6 -0
  40. package/esm/core/component/index.d.ts +51 -0
  41. package/esm/core/component/index.js +535 -0
  42. package/esm/core/drop-in/index.d.ts +22 -0
  43. package/esm/core/drop-in/index.js +104 -0
  44. package/esm/core/instance/index.d.ts +89 -0
  45. package/esm/core/instance/index.js +500 -0
  46. package/esm/foundation/core/index.d.ts +3 -3
  47. package/esm/foundation/core/index.js +51 -114
  48. package/esm/foundation/index.d.ts +3 -5
  49. package/esm/foundation/product-processor/easysafepay/deps.d.ts +4 -7
  50. package/esm/foundation/product-processor/easysafepay/deps.js +2 -5
  51. package/esm/foundation/product-processor/easysafepay/index.d.ts +4 -5
  52. package/esm/foundation/product-processor/easysafepay/index.js +114 -174
  53. package/esm/foundation/service/container/index.js +5 -5
  54. package/esm/foundation/service/container/popup.js +1 -1
  55. package/esm/foundation/service/event-bus/ability/callback.js +55 -0
  56. package/esm/foundation/service/{api-bus → event-bus}/ability/globalData.d.ts +1 -1
  57. package/esm/foundation/service/event-bus/ability/globalData.js +89 -0
  58. package/esm/foundation/service/event-bus/ability/request.d.ts +10 -0
  59. package/esm/foundation/service/event-bus/ability/request.js +151 -0
  60. package/esm/foundation/service/{api-bus → event-bus}/ability/security.js +19 -29
  61. package/esm/foundation/service/{api-bus → event-bus}/ability/tracker.js +1 -1
  62. package/esm/foundation/service/{api-bus → event-bus}/busManager.js +1 -1
  63. package/esm/foundation/service/event-center.d.ts +5 -4
  64. package/esm/foundation/service/event-center.js +39 -8
  65. package/esm/foundation/service/global-data/index.js +5 -4
  66. package/esm/foundation/service/index.js +1 -1
  67. package/esm/foundation/service/requester/requester.js +11 -14
  68. package/esm/foundation/service/security/index.d.ts +7 -9
  69. package/esm/foundation/service/security/index.js +44 -113
  70. package/esm/foundation/utils/redirect_utils.js +8 -24
  71. package/esm/foundation/utils/web_app_url_utils.d.ts +2 -11
  72. package/esm/foundation/utils/web_app_url_utils.js +2 -17
  73. package/esm/index.d.ts +30 -1
  74. package/esm/index.js +147 -7
  75. package/esm/plugin/applepay/component.d.ts +50 -0
  76. package/esm/plugin/applepay/component.js +339 -0
  77. package/esm/plugin/applepay/index.d.ts +17 -0
  78. package/esm/plugin/applepay/index.js +117 -0
  79. package/esm/plugin/applepay/interface.d.ts +161 -0
  80. package/esm/plugin/applepay/interface.js +69 -0
  81. package/esm/plugin/applepay/service.d.ts +54 -0
  82. package/esm/plugin/applepay/service.js +289 -0
  83. package/esm/plugin/component/cashierApp.d.ts +36 -0
  84. package/esm/plugin/component/cashierApp.js +245 -0
  85. package/esm/{component → plugin/component}/channel.d.ts +2 -1
  86. package/esm/{component → plugin/component}/channel.js +37 -1
  87. package/esm/{component → plugin/component}/component.inline.style.d.ts +2 -2
  88. package/esm/{component → plugin/component}/component.inline.style.js +7 -6
  89. package/esm/{component → plugin/component}/component.popup.style.d.ts +1 -1
  90. package/esm/{component → plugin/component}/component.popup.style.js +4 -4
  91. package/esm/plugin/component/index.d.ts +126 -0
  92. package/esm/plugin/component/index.js +1862 -0
  93. package/esm/{component → plugin/component}/popupWindow.style.js +2 -2
  94. package/esm/plugin/const.d.ts +2 -0
  95. package/esm/plugin/const.js +33 -0
  96. package/esm/plugin/drop-in/index.d.ts +71 -0
  97. package/esm/plugin/drop-in/index.js +324 -0
  98. package/esm/plugin/payment-element/utils.d.ts +2 -0
  99. package/esm/plugin/payment-element/utils.js +7 -0
  100. package/esm/plugin/paypal/index.d.ts +20 -0
  101. package/esm/plugin/paypal/index.js +390 -0
  102. package/esm/plugin/type.d.ts +34 -0
  103. package/esm/plugin/type.js +1 -0
  104. package/esm/plugin/utils.d.ts +6 -0
  105. package/esm/plugin/utils.js +21 -0
  106. package/esm/service/element.d.ts +4 -0
  107. package/esm/service/element.js +51 -0
  108. package/esm/service/index.d.ts +1 -0
  109. package/esm/service/index.js +2 -0
  110. package/esm/types/index.d.ts +218 -22
  111. package/esm/types/index.js +47 -4
  112. package/esm/util/createIframeNode.d.ts +6 -0
  113. package/esm/util/createIframeNode.js +48 -0
  114. package/esm/util/getBackScheme.d.ts +2 -2
  115. package/esm/util/getBackScheme.js +2 -94
  116. package/esm/util/index.d.ts +11 -1
  117. package/esm/util/index.js +84 -4
  118. package/esm/util/intl-callapp/es/index.js +0 -1
  119. package/esm/util/ua/index.d.ts +2 -0
  120. package/esm/util/ua/index.js +2 -0
  121. package/esm/util/ua/isAndroid.d.ts +4 -0
  122. package/esm/util/ua/isAndroid.js +7 -0
  123. package/esm/util/ua/isIOS.d.ts +4 -0
  124. package/esm/util/ua/isIOS.js +7 -0
  125. package/package.json +2 -1
  126. package/esm/foundation/utils/payment_product_utils.d.ts +0 -13
  127. package/esm/foundation/utils/payment_product_utils.js +0 -38
  128. /package/esm/{foundation/service/api-bus → core/bus}/interface.d.ts +0 -0
  129. /package/esm/{foundation/service/api-bus → core/bus}/interface.js +0 -0
  130. /package/esm/foundation/service/{api-bus → event-bus}/ability/callback.d.ts +0 -0
  131. /package/esm/foundation/service/{api-bus → event-bus}/ability/security.d.ts +0 -0
  132. /package/esm/foundation/service/{api-bus → event-bus}/ability/tracker.d.ts +0 -0
  133. /package/esm/foundation/service/{api-bus → event-bus}/busManager.d.ts +0 -0
  134. /package/esm/foundation/service/{api-bus → event-bus}/index.d.ts +0 -0
  135. /package/esm/foundation/service/{api-bus → event-bus}/index.js +0 -0
  136. /package/esm/{component → plugin/component}/popupWindow.style.d.ts +0 -0
@@ -1,5 +1,5 @@
1
- import { AMSPOPUP_PREFIX, ANIMATION_TIME, MOCKUP_ID, POPUPLOADING_ID } from "../constant";
2
- import { getDesignFontSize } from "../util";
1
+ import { AMSPOPUP_PREFIX, ANIMATION_TIME, MOCKUP_ID, POPUPLOADING_ID } from "../../constant";
2
+ import { getDesignFontSize } from "../../util";
3
3
 
4
4
  // CSS样式字符串
5
5
  var modalStyles = "\n .".concat(AMSPOPUP_PREFIX, "modal {\n /* \u6DFB\u52A0\u5F39\u7A97\u6837\u5F0F */\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 9999; /* \u8BBE\u7F6E\u5F39\u7A97\u7684\u5C42\u7EA7\u4E3A 9999 */\n overflow: hidden;\n }\n .").concat(AMSPOPUP_PREFIX, "modal-mobile{\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);\n position: fixed;\n bottom: 0;\n left: 0%;\n z-index: 9999; /* \u8BBE\u7F6E\u5F39\u7A97\u7684\u5C42\u7EA7\u4E3A 9999 */\n overflow: hidden;\n }\n\n .").concat(AMSPOPUP_PREFIX, "overlay {\n /* \u6DFB\u52A0\u8499\u5C42\u6837\u5F0F */\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: rgba(0, 0, 0, 0.4);\n z-index: 999;\n }\n\n .").concat(AMSPOPUP_PREFIX, "fadeIn {\n /* \u6DFB\u52A0\u6DE1\u5165\u52A8\u753B */\n animation: fadeIn ").concat(ANIMATION_TIME, "ms;\n animation-fill-mode: forwards;\n }\n\n .").concat(AMSPOPUP_PREFIX, "fadeOut {\n /* \u6DFB\u52A0\u6DE1\u51FA\u52A8\u753B */\n animation: fadeOut ").concat(ANIMATION_TIME, "ms;\n animation-fill-mode: forwards;\n }\n\n .").concat(AMSPOPUP_PREFIX, "-drawer-enter {\n animation: slideIn ").concat(ANIMATION_TIME, "ms forwards;\n }\n \n @keyframes slideIn {\n from {\n transform: translateY(100%); /* \u6ED1\u5165\u65F6\u5728\u89C6\u53E3\u5E95\u90E8\u5916 */\n opacity: 0; /* \u521D\u59CB\u900F\u660E\u5EA6\u4E3A 0 */\n }\n to {\n transform: translateY(0); /* \u6ED1\u5165\u7ED3\u675F\u65F6\u5728\u539F\u4F4D\u7F6E */\n opacity: 1; /* \u7ED3\u675F\u65F6\u900F\u660E\u5EA6\u4E3A 1 */\n }\n }\n\n /* \u62BD\u5C49\u4ECE\u5E95\u90E8\u6ED1\u51FA */\n .").concat(AMSPOPUP_PREFIX, "-drawer-exit {\n animation: slideOut ").concat(ANIMATION_TIME, "ms forwards;\n }\n\n @keyframes slideOut {\n from {\n transform: translateY(0); /* \u6ED1\u51FA\u65F6\u4ECE\u5F53\u524D\u4F4D\u7F6E\u5F00\u59CB */\n opacity: 1; /* \u521D\u59CB\u900F\u660E\u5EA6\u4E3A 1 */\n }\n to {\n transform: translateY(100%); /* \u6ED1\u51FA\u7ED3\u675F\u65F6\u5728\u89C6\u53E3\u5E95\u90E8\u5916 */\n opacity: 0; /* \u7ED3\u675F\u65F6\u900F\u660E\u5EA6\u4E3A 0 */\n }\n }\n\n /* \u5B9A\u4E49\u6DE1\u5165\u52A8\u753B */\n @keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n @-webkit-keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n @-moz-keyframes fadeIn {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n /* \u5B9A\u4E49\u6DE1\u51FA\u52A8\u753B */\n @keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n @-webkit-keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n @-moz-keyframes fadeOut {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n }\n }\n\n\n.ams-component-popup-loading {\n width: 0.8em;\n height:0.8em;\n border-radius: 8px;\n position: fixed;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n z-index: 1001;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n}\n\n.ams-component-popup-loading .line {\n width: 40px;\n height: 40px;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n.ams-component-popup-loading .line div {\n position: absolute;\n left: 17.67px;\n top: 0;\n width: 5.33px;\n height: 40px;\n}\n\n.ams-component-popup-loading .line div:before,\n.ams-component-popup-loading .line div:after {\n content: '';\n display: block;\n height: 13.33px;\n background: black;\n border-radius: 5.3px;\n}\n.ams-component-popup-loading .line div:after {\n margin-top: 13.33px;\n}\n\n.ams-component-popup-loading .line div:nth-child(2) {\n -webkit-transform: rotate(45deg);\n}\n\n.ams-component-popup-loading .line div:nth-child(3) {\n -webkit-transform: rotate(90deg);\n}\n\n.ams-component-popup-loading .line div:nth-child(4) {\n -webkit-transform: rotate(135deg);\n}\n\n/** \u52A0\u8F7D\u52A8\u753B **/\n@-webkit-keyframes load {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n }\n}\n\n.ams-component-popup-loading .line div:nth-child(1):before {\n -webkit-animation: load 1s linear 0s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(2):before {\n -webkit-animation: load 1s linear 0.125s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(3):before {\n -webkit-animation: load 1s linear 0.25s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(4):before {\n -webkit-animation: load 1s linear 0.375s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(1):after {\n -webkit-animation: load 1s linear 0.5s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(2):after {\n -webkit-animation: load 1s linear 0.675s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(3):after {\n -webkit-animation: load 1s linear 0.75s infinite;\n}\n\n.ams-component-popup-loading .line div:nth-child(4):after {\n -webkit-animation: load 1s linear 0.875s infinite;\n}\n\n.ams-component-popup-loading-logo {\n width: 0.44em;\n height: 0.44em;\n -webkit-transform:rotate(360deg);\n transform:rotate(360deg);\n -webkit-transition:-webkit-transform 1s linear;\n transition:transform 1s linear;\n animation: ams-component-loading-logo 1s linear infinite;\n}\n");
@@ -0,0 +1,2 @@
1
+ import { IExtendPlugin } from './type';
2
+ export declare const ExtendPlugin: IExtendPlugin;
@@ -0,0 +1,33 @@
1
+ import { ApplePayActionEnum, PaymentActionEnum, PaypalActionEnum } from "../core/bus/interface";
2
+ import { PaymentMethodCategoryTypeEnum, PaypalMethodEnum, ProductSceneEnum, ProductSceneVersion } from "../types/index";
3
+ export var ExtendPlugin = [{
4
+ sessionMatcher: {
5
+ productScene: ProductSceneEnum.CASHIER_PAYMENT,
6
+ productSceneVersion: ProductSceneVersion.V1,
7
+ paymentMethodCategoryType: PaymentMethodCategoryTypeEnum.CARD,
8
+ paymentMethodTypes: ['CARD_APPLE_PAY']
9
+ },
10
+ paymentChannelMatcher: {
11
+ paymentMethod: 'ApplePay'
12
+ },
13
+ busActionNames: {
14
+ canMakePayments: ApplePayActionEnum.canMakePayments,
15
+ optional_init: PaymentActionEnum.optional_init,
16
+ createComponent: ApplePayActionEnum.createComponent,
17
+ destroyComponent: ApplePayActionEnum.destroyComponent
18
+ }
19
+ }, {
20
+ sessionMatcher: {
21
+ productScene: ProductSceneEnum.CASHIER_PAYMENT,
22
+ productSceneVersion: ProductSceneVersion.V1,
23
+ paymentMethodCategoryType: PaymentMethodCategoryTypeEnum.APM,
24
+ paymentMethodTypes: [PaypalMethodEnum.PAYPAL_CHECKOUT, PaypalMethodEnum.PAYPAL_PAYLATER, PaypalMethodEnum.PAYPAL_VAULT]
25
+ },
26
+ paymentChannelMatcher: {
27
+ paymentMethod: 'Paypal'
28
+ },
29
+ busActionNames: {
30
+ mountComponent: PaypalActionEnum.mountComponent,
31
+ destroyComponent: PaypalActionEnum.destroyComponent
32
+ }
33
+ }];
@@ -0,0 +1,71 @@
1
+ import type AMSCheckout from '../../core/instance';
2
+ import type { IcreatePaymentParams, EventPayload } from '../../types';
3
+ export default class CheckoutApp {
4
+ app: any;
5
+ paymentMethodsResult: any;
6
+ appDomain: string;
7
+ AMSSDK: AMSCheckout;
8
+ private _render;
9
+ private _selector;
10
+ private _version;
11
+ constructor();
12
+ /**
13
+ * @description When SDK registers plug-ins, it is a required function to receive SDK instances
14
+ */
15
+ applyPlugin(AMSSDK: AMSCheckout): void;
16
+ /**
17
+ * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
18
+ */
19
+ setRender(createIframeNode: any): void;
20
+ /**
21
+ * @description High order function of rendering capability
22
+ */
23
+ render(renderParams: IcreatePaymentParams): Promise<void>;
24
+ /**
25
+ * @description Cancel listening and destroy the dom
26
+ */
27
+ logoutPlugin(): void;
28
+ /**
29
+ * @description Create app
30
+ */
31
+ private _createApp;
32
+ private _getIframeUrl;
33
+ /**
34
+ * @description Create iframe
35
+ */
36
+ private _createIframe;
37
+ /**
38
+ * @description Get iftame id
39
+ */
40
+ private _getIframeId;
41
+ _listener(e: any): void;
42
+ /**
43
+ * @description Initialize subscription iframe message
44
+ */
45
+ _addEventListener(): void;
46
+ _removeEventListener(): void;
47
+ /**
48
+ * @description Processing messages from iframe
49
+ */
50
+ _handleAppMessage(data: EventPayload): void;
51
+ /**
52
+ * @description Send message to SDK
53
+ */
54
+ _dispatchToSDK(data: EventPayload): void;
55
+ /**
56
+ * @description Send message to iframe
57
+ */
58
+ _dispatchToApp(data: EventPayload): void;
59
+ /**
60
+ * @description Subscribe to messages from SDK
61
+ */
62
+ _subscribeFromSDK(): void;
63
+ /**
64
+ * @description Send rendering events to iframe
65
+ */
66
+ _renderPaymentMethods(paymentResult: any): void;
67
+ /**
68
+ * @description Send the post submission processing event, and the cashier applies the consumption result
69
+ */
70
+ _handleRequestPayment(data: EventPayload): void;
71
+ }
@@ -0,0 +1,324 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ /**
9
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+ * 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
12
+ * 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.
13
+ */
14
+ /* eslint-disable @typescript-eslint/no-explicit-any */
15
+ import { BASEPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
16
+ import { MessageName } from "../../types";
17
+ import { getOrigin, getType, getViewPort, isDom, isJsonString, serialize } from "../../util";
18
+ var getServerPath = function getServerPath() {
19
+ var _environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
20
+ var version = arguments.length > 1 ? arguments[1] : undefined;
21
+ var host = '';
22
+ switch (_environment) {
23
+ case 'dev':
24
+ host = "http://page.alipay.net/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
25
+ break;
26
+ case 'sandbox':
27
+ host = "https://pre.ac.alipay.com/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
28
+ break;
29
+ case 'prod':
30
+ host = "https://ac.alipay.com/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
31
+ break;
32
+ default:
33
+ host = "https://ac.alipay.com/page/antom-web-checkout/src/drop-in-app/index.".concat(version, ".html");
34
+ break;
35
+ }
36
+ return host;
37
+ };
38
+ var getServerHost = function getServerHost(_environment, version) {
39
+ var reg = /^https?:\/\/([^/<>\s]+\.?)*/;
40
+ var macth = reg.exec(getServerPath(_environment, version));
41
+ return macth && macth[0] || '';
42
+ };
43
+ var CheckoutApp = /*#__PURE__*/function () {
44
+ function CheckoutApp() {
45
+ _classCallCheck(this, CheckoutApp);
46
+ _defineProperty(this, "app", void 0);
47
+ _defineProperty(this, "paymentMethodsResult", void 0);
48
+ _defineProperty(this, "appDomain", void 0);
49
+ _defineProperty(this, "AMSSDK", void 0);
50
+ _defineProperty(this, "_render", void 0);
51
+ _defineProperty(this, "_selector", void 0);
52
+ _defineProperty(this, "_version", void 0);
53
+ this._version = '1.0.0';
54
+ this._render = function () {
55
+ return Promise.resolve();
56
+ };
57
+ }
58
+ /**
59
+ * @description When SDK registers plug-ins, it is a required function to receive SDK instances
60
+ */
61
+ _createClass(CheckoutApp, [{
62
+ key: "applyPlugin",
63
+ value: function applyPlugin(AMSSDK) {
64
+ this.AMSSDK = AMSSDK;
65
+ this._subscribeFromSDK();
66
+ // Subscribe to messages from iframe
67
+ this._addEventListener();
68
+ this.appDomain = getServerHost(this.AMSSDK.options.env.environment, this._version);
69
+ this.app = this._createApp();
70
+ }
71
+ /**
72
+ * @description Set the rendering capability of the cashier plug-in. Different technology stacks have some differences in the packaging and use of rendering functions
73
+ */
74
+ }, {
75
+ key: "setRender",
76
+ value: function setRender(createIframeNode) {
77
+ this._render = createIframeNode;
78
+ }
79
+ /**
80
+ * @description High order function of rendering capability
81
+ */
82
+ }, {
83
+ key: "render",
84
+ value: function render(renderParams) {
85
+ this.paymentMethodsResult = renderParams.paymentMethodsResult;
86
+ this._selector = renderParams.selector;
87
+ this.app.src = this._getIframeUrl((renderParams === null || renderParams === void 0 ? void 0 : renderParams.appearance) || {});
88
+ return this._render(this, {
89
+ selector: renderParams.selector
90
+ });
91
+ }
92
+ /**
93
+ * @description Cancel listening and destroy the dom
94
+ */
95
+ }, {
96
+ key: "logoutPlugin",
97
+ value: function logoutPlugin() {
98
+ try {
99
+ this.app = null;
100
+ this._removeEventListener();
101
+ var dorpinDom = null;
102
+ if (getType(this._selector) === 'string') {
103
+ dorpinDom = document.querySelector(this._selector);
104
+ }
105
+ if (isDom(this._selector)) {
106
+ dorpinDom = this._selector;
107
+ }
108
+ if (dorpinDom) dorpinDom.innerHTML = '';
109
+ // eslint-disable-next-line no-empty
110
+ } catch (error) {}
111
+ }
112
+ /**
113
+ * @description Create app
114
+ */
115
+ }, {
116
+ key: "_createApp",
117
+ value: function _createApp() {
118
+ var iframe;
119
+ try {
120
+ iframe = this._createIframe();
121
+ } catch (error) {
122
+ this._dispatchToSDK({
123
+ name: MessageName.APP_TO_SDK,
124
+ instanceId: this.AMSSDK._instanceId,
125
+ context: {
126
+ event: 'onError',
127
+ data: Object.assign({}, ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.FAILED_TO_CREATE_IFRAME, {
128
+ stack: error
129
+ })
130
+ }
131
+ });
132
+ return;
133
+ }
134
+ if (!!window.postMessage !== true) {
135
+ this._dispatchToSDK({
136
+ name: MessageName.APP_TO_SDK,
137
+ instanceId: this.AMSSDK._instanceId,
138
+ context: {
139
+ event: 'onError',
140
+ data: ERRORMESSAGE.SDK_COMPATIBILITY_ISSUES.BROWSER_NOT_SUPPORT_POSTMESSAGE
141
+ }
142
+ });
143
+ return;
144
+ }
145
+ return iframe;
146
+ }
147
+ }, {
148
+ key: "_getIframeUrl",
149
+ value: function _getIframeUrl(appearance) {
150
+ var path = getServerPath(this.AMSSDK.options.env.environment, this._version);
151
+ var scale = getViewPort('initial-scale') || 1;
152
+ var instanceId = this.AMSSDK._instanceId;
153
+ var urlParams = Object.assign({
154
+ locale: this.AMSSDK.options.locale,
155
+ scale: scale,
156
+ merchantDomain: window.btoa(getOrigin()),
157
+ instanceId: instanceId
158
+ }, appearance);
159
+ var locationSearch = serialize(urlParams);
160
+ return "".concat(path, "?").concat(locationSearch);
161
+ }
162
+ /**
163
+ * @description Create iframe
164
+ */
165
+ }, {
166
+ key: "_createIframe",
167
+ value: function _createIframe() {
168
+ var iframe = document.createElement('iframe');
169
+ var iframeId = this._getIframeId(this.AMSSDK.options.mode);
170
+ iframe.id = iframeId;
171
+ iframe.style.height = '100%';
172
+ iframe.style.width = '100%';
173
+ iframe.style.border = '0';
174
+ iframe.style.overflow = 'hidden';
175
+ return iframe;
176
+ }
177
+ /**
178
+ * @description Get iftame id
179
+ */
180
+ }, {
181
+ key: "_getIframeId",
182
+ value: function _getIframeId(UIMode) {
183
+ var id = 'checkout-dropin';
184
+ switch (UIMode) {
185
+ case 'DROPIN':
186
+ id = 'checkout-dropin';
187
+ break;
188
+ case 'COMPONENT':
189
+ id = 'ams-checkout-component';
190
+ break;
191
+ }
192
+ return id;
193
+ }
194
+ }, {
195
+ key: "_listener",
196
+ value: function _listener(e) {
197
+ if (e.origin !== this.appDomain) {
198
+ return;
199
+ }
200
+ var isJson = isJsonString(e.data);
201
+ if (isJson) {
202
+ var data = JSON.parse(e.data);
203
+ if (data.name !== MessageName.APP_TO_SDK && data.name !== MessageName.APP_TO_APP || data.instanceId !== this.AMSSDK._instanceId) {
204
+ return;
205
+ }
206
+ this._handleAppMessage(data);
207
+ } else {
208
+ console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
209
+ this._dispatchToSDK({
210
+ name: MessageName.APP_TO_SDK,
211
+ instanceId: this.AMSSDK._instanceId,
212
+ context: {
213
+ event: 'onError',
214
+ data: ERRORMESSAGE.NOT_JSON_FORMAT
215
+ }
216
+ });
217
+ }
218
+ }
219
+ /**
220
+ * @description Initialize subscription iframe message
221
+ */
222
+ }, {
223
+ key: "_addEventListener",
224
+ value: function _addEventListener() {
225
+ this._removeEventListener();
226
+ window.addEventListener('message', this._listener.bind(this));
227
+ }
228
+ }, {
229
+ key: "_removeEventListener",
230
+ value: function _removeEventListener() {
231
+ window.removeEventListener('message', this._listener.bind(this));
232
+ }
233
+ /**
234
+ * @description Processing messages from iframe
235
+ */
236
+ }, {
237
+ key: "_handleAppMessage",
238
+ value: function _handleAppMessage(data) {
239
+ var eventKeyMap = [EVENT.error.name, EVENT.ready.name, EVENT.launch.name, EVENT.redirect.name, EVENT.sizeChanged.name, 'onPaymentMethodsSelected', EVENT.log.name];
240
+ if (!eventKeyMap.includes(data.context.event)) {
241
+ return;
242
+ }
243
+ if (data.context.event === 'onLaunch') {
244
+ this._renderPaymentMethods(this.paymentMethodsResult);
245
+ }
246
+ if (data.context.event === 'onSizeChanged') {
247
+ this.app.style.height = "".concat(data.context.data.height, "px");
248
+ this.app.style.width = '100%';
249
+ this.app.style.border = '0';
250
+ this.app.style.overflow = 'hidden';
251
+ }
252
+ if (data.context.event === 'onPaymentMethodsSelected') data.context.event = 'onPaymentMethodSelected';
253
+ // The plug-in communicates with the sdk after processing
254
+ this._dispatchToSDK(data);
255
+ }
256
+ /**
257
+ * @description Send message to SDK
258
+ */
259
+ }, {
260
+ key: "_dispatchToSDK",
261
+ value: function _dispatchToSDK(data) {
262
+ var _data = Object.assign({
263
+ name: MessageName.APP_TO_SDK,
264
+ mode: this.AMSSDK.options.mode,
265
+ appId: BASEPLUGINID,
266
+ instanceId: this.AMSSDK._instanceId
267
+ }, data);
268
+ this.AMSSDK._eventCenter.emit("".concat(BASEPLUGINID, "-").concat(data.context.event), _data);
269
+ }
270
+ /**
271
+ * @description Send message to iframe
272
+ */
273
+ }, {
274
+ key: "_dispatchToApp",
275
+ value: function _dispatchToApp(data) {
276
+ if (this.app && this.app.contentWindow) {
277
+ this.app.contentWindow.postMessage(JSON.stringify(data), this.appDomain);
278
+ }
279
+ }
280
+ /**
281
+ * @description Subscribe to messages from SDK
282
+ */
283
+ }, {
284
+ key: "_subscribeFromSDK",
285
+ value: function _subscribeFromSDK() {
286
+ var eventKeyMap = {
287
+ handleRequestPayment: this._handleRequestPayment
288
+ };
289
+ for (var key in eventKeyMap) {
290
+ // eslint-disable-next-line no-prototype-builtins
291
+ if (eventKeyMap.hasOwnProperty(key)) {
292
+ this.AMSSDK._eventCenter.on("".concat(BASEPLUGINID, "-").concat(key), eventKeyMap[key].bind(this));
293
+ }
294
+ }
295
+ }
296
+ /**
297
+ * @description Send rendering events to iframe
298
+ */
299
+ }, {
300
+ key: "_renderPaymentMethods",
301
+ value: function _renderPaymentMethods(paymentResult) {
302
+ this._dispatchToApp({
303
+ name: MessageName.SDK_TO_APP,
304
+ mode: this.AMSSDK.options.mode,
305
+ appId: BASEPLUGINID,
306
+ instanceId: this.AMSSDK._instanceId,
307
+ context: {
308
+ event: 'renderPaymentMethods',
309
+ data: paymentResult
310
+ }
311
+ });
312
+ }
313
+ /**
314
+ * @description Send the post submission processing event, and the cashier applies the consumption result
315
+ */
316
+ }, {
317
+ key: "_handleRequestPayment",
318
+ value: function _handleRequestPayment(data) {
319
+ this._dispatchToApp(data);
320
+ }
321
+ }]);
322
+ return CheckoutApp;
323
+ }();
324
+ export { CheckoutApp as default };
@@ -0,0 +1,2 @@
1
+ import type { IpaymentSessionConfig } from '../../types';
2
+ export declare const handlePaymentSessionConfig: (config: IpaymentSessionConfig) => Pick<IpaymentSessionConfig, 'productScene' | 'productSceneVersion' | 'paymentMethodCategoryType'>;
@@ -0,0 +1,7 @@
1
+ export var handlePaymentSessionConfig = function handlePaymentSessionConfig(config) {
2
+ return {
3
+ productScene: config === null || config === void 0 ? void 0 : config.productScene,
4
+ productSceneVersion: config === null || config === void 0 ? void 0 : config.productSceneVersion,
5
+ paymentMethodCategoryType: config === null || config === void 0 ? void 0 : config.paymentMethodCategoryType
6
+ };
7
+ };
@@ -0,0 +1,20 @@
1
+ import { BusContext, BusMessage, BusSubscriber } from '../../core/bus';
2
+ import { Logger } from '../../util/logger';
3
+ export declare class PaypalBusSubscriber extends BusSubscriber {
4
+ logger: Logger;
5
+ constructor(logger: Logger);
6
+ actionNames(): string[];
7
+ private onEventCallback;
8
+ protected renderPaypalButton(context: BusContext, message: BusMessage): Promise<never>;
9
+ private appendPaypalLoading;
10
+ private removePaypalLoading;
11
+ private preCheck;
12
+ private loadPaypalResource;
13
+ private createPaypalScript;
14
+ private onShippingChange;
15
+ private createOrder;
16
+ private onApprove;
17
+ private onCancel;
18
+ private destroyComponent;
19
+ onMessage(context: BusContext, message: BusMessage): void;
20
+ }