@alipay/ams-checkout 0.0.1710212811-dev.30 → 0.0.1710212811-dev.32
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/core/bus/index.d.ts +57 -1
- package/esm/core/bus/index.js +85 -26
- package/esm/core/component/index.js +1 -1
- package/esm/plugin/applepay/component.d.ts +11 -1
- package/esm/plugin/applepay/component.js +46 -26
- package/esm/plugin/applepay/index.js +19 -2
- package/esm/plugin/applepay/interface.d.ts +1 -3
- package/esm/plugin/applepay/interface.js +1 -5
- package/esm/plugin/applepay/service.d.ts +8 -4
- package/esm/plugin/applepay/service.js +89 -23
- package/esm/types/index.d.ts +7 -2
- package/esm/types/index.js +3 -1
- package/package.json +1 -1
@@ -17,23 +17,34 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
17
17
|
*/
|
18
18
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
19
19
|
import { APPLE_PAY_VERSION, APPLE_PAY_RECURRING_VERSION } from "./interface";
|
20
|
+
import { eventCodeEnum } from "../../types";
|
21
|
+
import { ApplePayComponentEvent } from "./component";
|
22
|
+
var PaymentState = /*#__PURE__*/function (PaymentState) {
|
23
|
+
PaymentState[PaymentState["notStarted"] = 0] = "notStarted";
|
24
|
+
PaymentState[PaymentState["pending"] = 1] = "pending";
|
25
|
+
PaymentState[PaymentState["fail"] = 2] = "fail";
|
26
|
+
PaymentState[PaymentState["success"] = 3] = "success";
|
27
|
+
return PaymentState;
|
28
|
+
}(PaymentState || {});
|
20
29
|
/**
|
21
30
|
* Apple Pay Service
|
22
31
|
*/
|
23
32
|
var ApplePayService = /*#__PURE__*/function () {
|
24
|
-
function ApplePayService() {
|
33
|
+
function ApplePayService(logger) {
|
25
34
|
var _this = this;
|
26
35
|
_classCallCheck(this, ApplePayService);
|
27
36
|
_defineProperty(this, "merchantIdentifier", void 0);
|
28
37
|
_defineProperty(this, "merchantName", void 0);
|
29
38
|
_defineProperty(this, "session", void 0);
|
39
|
+
_defineProperty(this, "paymentState", void 0);
|
30
40
|
_defineProperty(this, "getMerchantSession", void 0);
|
31
41
|
_defineProperty(this, "completePaymentAuthorized", void 0);
|
32
42
|
_defineProperty(this, "completeApplePay", void 0);
|
33
43
|
_defineProperty(this, "logError", void 0);
|
34
|
-
_defineProperty(this, "
|
44
|
+
_defineProperty(this, "isRecurring", false);
|
45
|
+
_defineProperty(this, "logger", void 0);
|
35
46
|
_defineProperty(this, "onvalidatemerchant", function (event) {
|
36
|
-
|
47
|
+
var success = false;
|
37
48
|
_this.getMerchantSession({
|
38
49
|
displayName: _this.merchantName,
|
39
50
|
merchantIdentifier: _this.merchantIdentifier,
|
@@ -42,47 +53,61 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
42
53
|
console.log("onvalidatemerchant#merchantSessionObjectString", merchantSessionObjectString);
|
43
54
|
var merchantSessionObject = JSON.parse(merchantSessionObjectString);
|
44
55
|
_this.session.completeMerchantValidation(merchantSessionObject);
|
45
|
-
|
56
|
+
success = true;
|
46
57
|
}).catch(function (error) {
|
47
|
-
_this.logError('MerchantValidationError', error);
|
48
|
-
_this.
|
58
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'MerchantValidationError', error);
|
59
|
+
_this.sessionAbort();
|
49
60
|
});
|
61
|
+
_this.logger.logInfo({
|
62
|
+
name: 'APPLE_PAY',
|
63
|
+
title: ApplePayComponentEvent.sdk_event_appleCreateComponent
|
64
|
+
}, {
|
65
|
+
biz: 'sdk',
|
66
|
+
type: 'funnel',
|
67
|
+
success: success,
|
68
|
+
recurring: _this.isRecurring
|
69
|
+
}).send();
|
50
70
|
});
|
51
71
|
_defineProperty(this, "onpaymentauthorized", function (event) {
|
52
72
|
var _event$payment;
|
53
|
-
_this.applePayTrace('onpaymentauthorized');
|
54
73
|
var _window = window,
|
55
74
|
ApplePaySession = _window.ApplePaySession;
|
75
|
+
var success = false;
|
56
76
|
var exception = function exception(error) {
|
57
77
|
_this.session.completePayment(ApplePaySession.STATUS_FAILURE);
|
58
|
-
_this.logError('PaymentAuthorizedError', error);
|
59
|
-
_this.
|
78
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'PaymentAuthorizedError', error);
|
79
|
+
_this.sessionAbort();
|
60
80
|
};
|
61
81
|
if (event !== null && event !== void 0 && (_event$payment = event.payment) !== null && _event$payment !== void 0 && _event$payment.token) {
|
62
|
-
_this.
|
82
|
+
_this.paymentState = PaymentState.pending;
|
63
83
|
_this.completePaymentAuthorized({
|
64
84
|
paymentToken: JSON.stringify(event.payment.token)
|
65
85
|
}).then(function (data) {
|
66
|
-
_this.applePayTrace('completeApplePay');
|
67
86
|
_this.session.completePayment(ApplePaySession.STATUS_SUCCESS);
|
68
87
|
_this.completeApplePay(data);
|
88
|
+
_this.paymentState = PaymentState.success;
|
89
|
+
success = true;
|
69
90
|
}).catch(function (error) {
|
70
91
|
exception(error);
|
92
|
+
_this.paymentState = PaymentState.fail;
|
71
93
|
});
|
72
94
|
} else {
|
73
95
|
exception();
|
74
96
|
}
|
97
|
+
_this.logger.logInfo({
|
98
|
+
name: 'APPLE_PAY',
|
99
|
+
title: ApplePayComponentEvent.sdk_event_appleSubmitToken
|
100
|
+
}, {
|
101
|
+
biz: 'sdk',
|
102
|
+
type: 'funnel',
|
103
|
+
success: success,
|
104
|
+
recurring: _this.isRecurring
|
105
|
+
}).send();
|
75
106
|
});
|
76
107
|
/**
|
77
108
|
* Start Pay
|
78
109
|
*/
|
79
110
|
_defineProperty(this, "startPay", function (param) {
|
80
|
-
_this.applePayTrace('start');
|
81
|
-
var _window2 = window,
|
82
|
-
ApplePaySession = _window2.ApplePaySession;
|
83
|
-
if (!ApplePaySession) {
|
84
|
-
throw Error('ApplePaySession is null in window');
|
85
|
-
}
|
86
111
|
var paymentSessionFactor = param.paymentSessionFactor;
|
87
112
|
var extendInfo = paymentSessionFactor.extendInfo,
|
88
113
|
merchantInfo = paymentSessionFactor.merchantInfo,
|
@@ -90,14 +115,30 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
90
115
|
order = paymentSessionFactor.order,
|
91
116
|
recurringInfo = paymentSessionFactor.recurringInfo;
|
92
117
|
_this.merchantIdentifier = merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.partnerId;
|
118
|
+
var _window2 = window,
|
119
|
+
ApplePaySession = _window2.ApplePaySession;
|
120
|
+
_this.isRecurring = recurringInfo !== null;
|
121
|
+
_this.logger.logInfo({
|
122
|
+
name: 'APPLE_PAY',
|
123
|
+
title: ApplePayComponentEvent.sdk_event_appleCreateComponent
|
124
|
+
}, {
|
125
|
+
biz: 'sdk',
|
126
|
+
type: 'funnel',
|
127
|
+
success: ApplePaySession !== null,
|
128
|
+
recurring: _this.isRecurring
|
129
|
+
}).send();
|
130
|
+
if (!ApplePaySession) {
|
131
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "ApplePaySession is only support in Safari");
|
132
|
+
return;
|
133
|
+
}
|
93
134
|
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)) {
|
94
|
-
_this.logError("
|
135
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params paymentSessionFactor");
|
95
136
|
return;
|
96
137
|
}
|
97
138
|
if (recurringInfo) {
|
98
139
|
var _recurringInfo$interv;
|
99
140
|
if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
|
100
|
-
_this.logError("
|
141
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params recurringInfo");
|
101
142
|
return;
|
102
143
|
}
|
103
144
|
var lineItem = {
|
@@ -145,11 +186,25 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
145
186
|
_this.session.onvalidatemerchant = _this.onvalidatemerchant;
|
146
187
|
_this.session.onpaymentauthorized = _this.onpaymentauthorized;
|
147
188
|
_this.session.oncancel = function () {
|
148
|
-
_this.
|
189
|
+
if (_this.paymentState === PaymentState.pending) {
|
190
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_PROCESSING, 'Payment processing but user dismissed the sheet');
|
191
|
+
} else {
|
192
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_CANCEL, 'User dismissed the sheet');
|
193
|
+
}
|
194
|
+
_this.sessionAbort();
|
149
195
|
};
|
150
196
|
_this.session.begin();
|
151
|
-
_this.
|
197
|
+
_this.logger.logInfo({
|
198
|
+
name: 'APPLE_PAY',
|
199
|
+
title: ApplePayComponentEvent.sdk_event_appleShowPaymentSheet
|
200
|
+
}, {
|
201
|
+
biz: 'sdk',
|
202
|
+
type: 'funnel',
|
203
|
+
success: true,
|
204
|
+
recurring: recurringInfo !== null
|
205
|
+
}).send();
|
152
206
|
});
|
207
|
+
this.logger = logger;
|
153
208
|
}
|
154
209
|
|
155
210
|
/**
|
@@ -162,12 +217,12 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
162
217
|
*/
|
163
218
|
_createClass(ApplePayService, [{
|
164
219
|
key: "setApplePayParams",
|
165
|
-
value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError
|
220
|
+
value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError) {
|
166
221
|
this.getMerchantSession = getMerchantSession;
|
167
222
|
this.completePaymentAuthorized = completePaymentAuthorized;
|
168
223
|
this.completeApplePay = completeApplePay;
|
169
224
|
this.logError = logError;
|
170
|
-
this.
|
225
|
+
this.paymentState = PaymentState.notStarted;
|
171
226
|
}
|
172
227
|
|
173
228
|
/**
|
@@ -207,6 +262,17 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
207
262
|
}
|
208
263
|
return hasActiveCard;
|
209
264
|
}())
|
265
|
+
}, {
|
266
|
+
key: "sessionAbort",
|
267
|
+
value: function sessionAbort() {
|
268
|
+
if (this.session) {
|
269
|
+
try {
|
270
|
+
this.session.abort();
|
271
|
+
} catch (error) {
|
272
|
+
console.log("session.abort() error");
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
210
276
|
}], [{
|
211
277
|
key: "canMakePayments",
|
212
278
|
value: function canMakePayments(subTypeEnum) {
|
package/esm/types/index.d.ts
CHANGED
@@ -448,9 +448,14 @@ export declare enum eventCodeEnum {
|
|
448
448
|
SDK_CREATECOMPONENT_ERROR = "SDK_CREATECOMPONENT_ERROR",
|
449
449
|
SDK_CALL_URL_ERROR = "SDK_CALL_URL_ERROR",
|
450
450
|
SDK_CALL_URL_SUCCESS = "SDK_CALL_URL_SUCCESS",
|
451
|
-
|
451
|
+
SDK_PAYMENT_SUCCESSFUL = "SDK_PAYMENT_SUCCESSFUL",
|
452
452
|
SDK_PAYMENT_FAIL = "SDK_PAYMENT_FAIL",
|
453
|
-
|
453
|
+
SDK_PAYMENT_ERROR = "SDK_PAYMENT_ERROR",
|
454
|
+
SDK_PAYMENT_CANCEL = "SDK_PAYMENT_CANCEL",
|
455
|
+
/**
|
456
|
+
* 当前为Apple Pay发起了Pay请求,但是用户关闭了页面
|
457
|
+
*/
|
458
|
+
SDK_PAYMENT_PROCESSING = "SDK_PAYMENT_PROCESSING"
|
454
459
|
}
|
455
460
|
export declare enum RedirectType {
|
456
461
|
ApplinkUrl = "ApplinkUrl",
|
package/esm/types/index.js
CHANGED
@@ -153,9 +153,11 @@ export var eventCodeEnum = /*#__PURE__*/function (eventCodeEnum) {
|
|
153
153
|
eventCodeEnum["SDK_CREATECOMPONENT_ERROR"] = "SDK_CREATECOMPONENT_ERROR";
|
154
154
|
eventCodeEnum["SDK_CALL_URL_ERROR"] = "SDK_CALL_URL_ERROR";
|
155
155
|
eventCodeEnum["SDK_CALL_URL_SUCCESS"] = "SDK_CALL_URL_SUCCESS";
|
156
|
-
eventCodeEnum["
|
156
|
+
eventCodeEnum["SDK_PAYMENT_SUCCESSFUL"] = "SDK_PAYMENT_SUCCESSFUL";
|
157
157
|
eventCodeEnum["SDK_PAYMENT_FAIL"] = "SDK_PAYMENT_FAIL";
|
158
|
+
eventCodeEnum["SDK_PAYMENT_ERROR"] = "SDK_PAYMENT_ERROR";
|
158
159
|
eventCodeEnum["SDK_PAYMENT_CANCEL"] = "SDK_PAYMENT_CANCEL";
|
160
|
+
eventCodeEnum["SDK_PAYMENT_PROCESSING"] = "SDK_PAYMENT_PROCESSING";
|
159
161
|
return eventCodeEnum;
|
160
162
|
}({});
|
161
163
|
export var RedirectType = /*#__PURE__*/function (RedirectType) {
|