@alipay/ams-checkout 0.0.1730107332-dev.24 → 0.0.1730107332-dev.26
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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/component/component.inline.style.js +1 -1
- package/esm/config/index.d.ts +7 -7
- package/esm/config/index.js +7 -7
- package/esm/constant/index.d.ts +3 -0
- package/esm/constant/index.js +3 -0
- package/esm/core/bus/ability/callback.d.ts +9 -0
- package/esm/core/bus/ability/callback.js +55 -0
- package/esm/core/bus/ability/security.d.ts +10 -0
- package/esm/core/bus/ability/security.js +104 -0
- package/esm/core/bus/ability/tracker.d.ts +9 -0
- package/esm/core/bus/ability/tracker.js +77 -0
- package/esm/core/bus/index.d.ts +125 -0
- package/esm/core/bus/index.js +366 -0
- package/esm/core/bus/interface.d.ts +36 -0
- package/esm/core/bus/interface.js +40 -0
- package/esm/core/component/address.d.ts +8 -0
- package/esm/core/component/address.js +72 -0
- package/esm/core/component/appPreloadProcessing.d.ts +1 -0
- package/esm/core/component/appPreloadProcessing.js +89 -0
- package/esm/core/component/ckp/index.d.ts +27 -0
- package/esm/core/component/ckp/index.js +166 -0
- package/esm/core/component/index.d.ts +51 -0
- package/esm/core/component/index.js +531 -0
- package/esm/core/drop-in/index.d.ts +22 -0
- package/esm/core/drop-in/index.js +104 -0
- package/esm/core/instance/index.d.ts +89 -0
- package/esm/core/instance/index.js +499 -0
- package/esm/foundation/core/index.d.ts +2 -2
- package/esm/foundation/index.d.ts +5 -5
- package/esm/foundation/product-processor/easysafepay/deps.d.ts +2 -2
- package/esm/foundation/product-processor/easysafepay/deps.js +1 -1
- package/esm/foundation/product-processor/easysafepay/index.d.ts +2 -2
- package/esm/foundation/service/api-bus/index.d.ts +2 -2
- package/esm/foundation/service/container/index.d.ts +2 -2
- package/esm/foundation/service/event-center.d.ts +4 -4
- package/esm/foundation/service/event-center.js +10 -10
- package/esm/foundation/service/global-data/index.d.ts +2 -2
- package/esm/foundation/service/index.d.ts +2 -2
- package/esm/foundation/service/log/index.d.ts +2 -2
- package/esm/foundation/service/requester/deps.d.ts +1 -1
- package/esm/foundation/service/requester/requester.d.ts +2 -2
- package/esm/foundation/service/security/index.d.ts +2 -2
- package/esm/foundation/utils/redirect_utils.d.ts +5 -0
- package/esm/foundation/utils/redirect_utils.js +135 -1
- package/esm/foundation/utils/web_app_url_utils.js +1 -1
- package/esm/index.d.ts +27 -2
- package/esm/index.js +131 -6
- package/esm/plugin/applepay/component.d.ts +50 -0
- package/esm/plugin/applepay/component.js +339 -0
- package/esm/plugin/applepay/index.d.ts +17 -0
- package/esm/plugin/applepay/index.js +117 -0
- package/esm/plugin/applepay/interface.d.ts +161 -0
- package/esm/plugin/applepay/interface.js +69 -0
- package/esm/plugin/applepay/service.d.ts +54 -0
- package/esm/plugin/applepay/service.js +289 -0
- package/esm/plugin/component/cashierApp.d.ts +34 -0
- package/esm/plugin/component/cashierApp.js +237 -0
- package/esm/plugin/component/channel.d.ts +21 -0
- package/esm/plugin/component/channel.js +89 -0
- package/esm/plugin/component/component.inline.style.d.ts +10 -0
- package/esm/plugin/component/component.inline.style.js +119 -0
- package/esm/plugin/component/component.popup.style.d.ts +16 -0
- package/esm/plugin/component/component.popup.style.js +174 -0
- package/esm/plugin/component/index.d.ts +126 -0
- package/esm/plugin/component/index.js +1839 -0
- package/esm/plugin/component/popupWindow.style.d.ts +11 -0
- package/esm/plugin/component/popupWindow.style.js +121 -0
- package/esm/plugin/const.d.ts +2 -0
- package/esm/plugin/const.js +33 -0
- package/esm/plugin/drop-in/index.d.ts +71 -0
- package/esm/plugin/drop-in/index.js +324 -0
- package/esm/plugin/payment-element/utils.d.ts +2 -0
- package/esm/plugin/payment-element/utils.js +6 -0
- package/esm/plugin/paypal/index.d.ts +20 -0
- package/esm/plugin/paypal/index.js +390 -0
- package/esm/plugin/type.d.ts +34 -0
- package/esm/plugin/type.js +1 -0
- package/esm/plugin/utils.d.ts +6 -0
- package/esm/plugin/utils.js +21 -0
- package/esm/types/index.d.ts +28 -9
- package/esm/types/index.js +5 -1
- package/esm/util/createIframeNode.d.ts +6 -0
- package/esm/util/createIframeNode.js +48 -0
- package/esm/util/getBackScheme.d.ts +2 -2
- package/esm/util/getBackScheme.js +2 -2
- package/esm/util/index.d.ts +11 -1
- package/esm/util/index.js +84 -3
- package/esm/util/intl-callapp/es/index.js +0 -1
- package/esm/util/security.d.ts +33 -0
- package/esm/util/security.js +182 -0
- package/package.json +2 -2
- package/esm/foundation/types/index.d.ts +0 -4
- package/esm/foundation/types/index.js +0 -4
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare const createCustomSheet: (curTheme?: 'dark' | 'light') => void;
|
2
|
+
export declare const renderPopupLoading: (container: HTMLDivElement, curTheme: 'dark' | 'light') => void;
|
3
|
+
export declare const removePopupLoading: (isShowMockup?: boolean) => void;
|
4
|
+
export declare const insertStyleSheet: () => void;
|
5
|
+
export declare const createModal: ({ device, url, widthPadding, loadingConfig }: {
|
6
|
+
device: any;
|
7
|
+
url: any;
|
8
|
+
widthPadding: any;
|
9
|
+
loadingConfig: any;
|
10
|
+
}) => Promise<HTMLIFrameElement>;
|
11
|
+
export declare const destroyModal: () => void;
|
@@ -0,0 +1,121 @@
|
|
1
|
+
import { AMSPOPUP_PREFIX, ANIMATION_TIME, MOCKUP_ID, POPUPLOADING_ID } from "../../constant";
|
2
|
+
import { getDesignFontSize } from "../../util";
|
3
|
+
|
4
|
+
// CSS样式字符串
|
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");
|
6
|
+
var getCurrentTheme = function getCurrentTheme() {
|
7
|
+
var curTheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
|
8
|
+
var theme = {
|
9
|
+
night: 'dark',
|
10
|
+
gamingPurple: 'dark',
|
11
|
+
agateGreen: 'dark',
|
12
|
+
default: 'light',
|
13
|
+
nostalgicGray: 'light',
|
14
|
+
cherryBlossomPink: 'light'
|
15
|
+
};
|
16
|
+
return theme[curTheme];
|
17
|
+
};
|
18
|
+
export var createCustomSheet = function createCustomSheet() {
|
19
|
+
var curTheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'light';
|
20
|
+
var sheet = "\n .ams-component-popup-loading .line div:before,\n .ams-component-popup-loading .line div:after {\n background: ".concat(curTheme === 'light' ? '#000000' : '#ffffff', " !important;\n }");
|
21
|
+
var style = document.createElement('style');
|
22
|
+
style.innerHTML = sheet;
|
23
|
+
document.head.appendChild(style);
|
24
|
+
};
|
25
|
+
export var renderPopupLoading = function renderPopupLoading(container, curTheme) {
|
26
|
+
createCustomSheet(curTheme);
|
27
|
+
var loading = document.createElement('div');
|
28
|
+
loading === null || loading === void 0 || loading.classList.add(POPUPLOADING_ID);
|
29
|
+
loading.id = POPUPLOADING_ID;
|
30
|
+
loading.innerHTML = '<div class="line"><div></div><div></div><div></div><div></div></div>';
|
31
|
+
loading.style.fontSize = "".concat(getDesignFontSize(), "px");
|
32
|
+
container.appendChild(loading);
|
33
|
+
};
|
34
|
+
export var removePopupLoading = function removePopupLoading() {
|
35
|
+
var _document$getElementB;
|
36
|
+
var isShowMockup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
37
|
+
var mockup = document.getElementById(MOCKUP_ID);
|
38
|
+
if (mockup) {
|
39
|
+
mockup.style.background = 'rgb(0, 0, 0, 0.6)';
|
40
|
+
mockup.style.display = isShowMockup ? 'block' : 'none';
|
41
|
+
}
|
42
|
+
(_document$getElementB = document.getElementById(POPUPLOADING_ID)) === null || _document$getElementB === void 0 || _document$getElementB.remove();
|
43
|
+
};
|
44
|
+
// 创建和插入样式表
|
45
|
+
export var insertStyleSheet = function insertStyleSheet() {
|
46
|
+
var style = document.createElement('style');
|
47
|
+
style.innerHTML = modalStyles;
|
48
|
+
document.head.appendChild(style);
|
49
|
+
};
|
50
|
+
var modalDevice = 'desktop';
|
51
|
+
// 插入弹窗
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
53
|
+
export var createModal = function createModal(_ref) {
|
54
|
+
var device = _ref.device,
|
55
|
+
url = _ref.url,
|
56
|
+
widthPadding = _ref.widthPadding,
|
57
|
+
loadingConfig = _ref.loadingConfig;
|
58
|
+
return new Promise(function (resolve, reject) {
|
59
|
+
try {
|
60
|
+
modalDevice = device;
|
61
|
+
var overlay = document.createElement('div');
|
62
|
+
overlay.classList.add("".concat(AMSPOPUP_PREFIX, "overlay"), "".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
63
|
+
var modal = document.createElement('div');
|
64
|
+
if (device === 'desktop') {
|
65
|
+
modal.classList.add("".concat(AMSPOPUP_PREFIX, "modal"), "".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
66
|
+
modal.style.width = '656px';
|
67
|
+
modal.style.height = '620px';
|
68
|
+
modal.style.borderRadius = '12px';
|
69
|
+
} else {
|
70
|
+
modal.classList.add("".concat(AMSPOPUP_PREFIX, "modal-mobile"), "".concat(AMSPOPUP_PREFIX, "-drawer-enter"));
|
71
|
+
modal.style.width = '100%';
|
72
|
+
modal.style.height = '80vh';
|
73
|
+
modal.style.borderRadius = '12px 12px 0 0';
|
74
|
+
}
|
75
|
+
var iframe = document.createElement('iframe');
|
76
|
+
iframe.src = url; // 替换为实际的 URL 地址
|
77
|
+
iframe.style.border = 'none';
|
78
|
+
iframe.style.width = '100%';
|
79
|
+
iframe.style.height = '100%';
|
80
|
+
if (loadingConfig && Object.keys(loadingConfig).length) {
|
81
|
+
var _loadingConfig$theme = loadingConfig.theme,
|
82
|
+
theme = _loadingConfig$theme === void 0 ? 'default' : _loadingConfig$theme,
|
83
|
+
_loadingConfig$backgr = loadingConfig.backgroundPrimary,
|
84
|
+
backgroundPrimary = _loadingConfig$backgr === void 0 ? '#ffffff' : _loadingConfig$backgr;
|
85
|
+
var mode = getCurrentTheme(theme);
|
86
|
+
renderPopupLoading(modal, mode);
|
87
|
+
modal.style.backgroundColor = backgroundPrimary;
|
88
|
+
iframe.style.backgroundColor = backgroundPrimary;
|
89
|
+
}
|
90
|
+
modal.appendChild(iframe);
|
91
|
+
var body = document.getElementsByTagName('body')[0];
|
92
|
+
body.appendChild(overlay);
|
93
|
+
body.appendChild(modal);
|
94
|
+
resolve(iframe);
|
95
|
+
} catch (error) {
|
96
|
+
reject({
|
97
|
+
title: 'sdk_error_create_pop_up',
|
98
|
+
message: error === null || error === void 0 ? void 0 : error.toString()
|
99
|
+
});
|
100
|
+
}
|
101
|
+
});
|
102
|
+
};
|
103
|
+
|
104
|
+
// 销毁弹窗
|
105
|
+
export var destroyModal = function destroyModal() {
|
106
|
+
var overlay = document.querySelector(".".concat(AMSPOPUP_PREFIX, "overlay"));
|
107
|
+
var modal = modalDevice === 'desktop' ? document.querySelector(".".concat(AMSPOPUP_PREFIX, "modal")) : document.querySelector(".".concat(AMSPOPUP_PREFIX, "modal-mobile"));
|
108
|
+
overlay.classList.remove("".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
109
|
+
overlay.classList.add("".concat(AMSPOPUP_PREFIX, "fadeOut"));
|
110
|
+
if (modalDevice === 'desktop') {
|
111
|
+
modal.classList.remove("".concat(AMSPOPUP_PREFIX, "fadeIn"));
|
112
|
+
modal.classList.add("".concat(AMSPOPUP_PREFIX, "fadeOut"));
|
113
|
+
} else {
|
114
|
+
modal.classList.remove("".concat(AMSPOPUP_PREFIX, "-drawer-enter"));
|
115
|
+
modal.classList.add("".concat(AMSPOPUP_PREFIX, "-drawer-exit"));
|
116
|
+
}
|
117
|
+
setTimeout(function () {
|
118
|
+
overlay.parentNode.removeChild(overlay);
|
119
|
+
modal.parentNode.removeChild(modal);
|
120
|
+
}, ANIMATION_TIME);
|
121
|
+
};
|
@@ -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,6 @@
|
|
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
|
+
};
|
6
|
+
};
|
@@ -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
|
+
}
|