@alipay/ams-checkout 0.0.1710212811-dev.30 → 0.0.1710212811-dev.31
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/plugin/applepay/component.js +14 -10
- package/esm/plugin/applepay/interface.d.ts +1 -1
- package/esm/plugin/applepay/service.d.ts +1 -0
- package/esm/plugin/applepay/service.js +27 -5
- package/esm/types/index.d.ts +7 -2
- package/esm/types/index.js +3 -1
- package/package.json +1 -1
@@ -85,12 +85,12 @@ var ApplePayComponent = /*#__PURE__*/function () {
|
|
85
85
|
if (!this._parseData || !this._sessionData) {
|
86
86
|
this.onEventCallback({
|
87
87
|
code: eventCodeEnum.SDK_PAYMENT_FAIL,
|
88
|
-
message: 'Abnormal
|
88
|
+
message: 'Abnormal paymentSessionData'
|
89
89
|
});
|
90
90
|
this.logger.logError({
|
91
91
|
name: 'APPLE_PAY',
|
92
92
|
title: 'sessionDataNull',
|
93
|
-
msg: 'Abnormal
|
93
|
+
msg: 'Abnormal paymentSessionData'
|
94
94
|
}, {
|
95
95
|
type: 'error',
|
96
96
|
biz: 'sdk'
|
@@ -259,18 +259,20 @@ var ApplePayComponent = /*#__PURE__*/function () {
|
|
259
259
|
var _data$actionForm;
|
260
260
|
_this._isFinish = true;
|
261
261
|
_this.onEventCallback({
|
262
|
-
code: eventCodeEnum.
|
262
|
+
code: eventCodeEnum.SDK_PAYMENT_SUCCESSFUL,
|
263
|
+
message: 'Payment successful',
|
263
264
|
result: {
|
264
265
|
redirectUrl: (data === null || data === void 0 || (_data$actionForm = data.actionForm) === null || _data$actionForm === void 0 ? void 0 : _data$actionForm.redirectUrl) || ''
|
265
266
|
}
|
266
267
|
});
|
267
268
|
};
|
268
|
-
var logError = function logError(msg, error) {
|
269
|
+
var logError = function logError(code, msg, error) {
|
269
270
|
// log error
|
270
271
|
_this.logger.logError({
|
271
272
|
name: 'APPLE_PAY',
|
272
273
|
title: msg,
|
273
274
|
label: msg,
|
275
|
+
code: code,
|
274
276
|
msg: error
|
275
277
|
}, {
|
276
278
|
type: 'error',
|
@@ -280,16 +282,18 @@ var ApplePayComponent = /*#__PURE__*/function () {
|
|
280
282
|
return;
|
281
283
|
}
|
282
284
|
_this._isFinish = true;
|
283
|
-
if (
|
285
|
+
if (error !== null && error !== void 0 && error.errorCode) {
|
284
286
|
_this.onEventCallback({
|
285
|
-
code:
|
287
|
+
code: code,
|
288
|
+
message: msg,
|
289
|
+
result: {
|
290
|
+
errorCode: error === null || error === void 0 ? void 0 : error.errorCode
|
291
|
+
}
|
286
292
|
});
|
287
293
|
} else {
|
288
294
|
_this.onEventCallback({
|
289
|
-
code:
|
290
|
-
|
291
|
-
errorMsg: msg
|
292
|
-
}
|
295
|
+
code: code,
|
296
|
+
message: msg
|
293
297
|
});
|
294
298
|
}
|
295
299
|
};
|
@@ -158,6 +158,6 @@ export type ICompletePaymentAuthorized = (params: {
|
|
158
158
|
paymentToken?: string;
|
159
159
|
}) => Promise<any>;
|
160
160
|
export type ICompleteApplePay = (data: any) => void;
|
161
|
-
export type ILogError = (msg: string, error?: any) => void;
|
161
|
+
export type ILogError = (code: string, msg: string, error?: any) => void;
|
162
162
|
export type traceMsg = 'start' | 'sessionBegin' | 'onValidateMerchant' | 'completeMerchantValidation' | 'onpaymentauthorized' | 'completePaymentAuthorized' | 'completeApplePay';
|
163
163
|
export type IApplePayTrace = (msg: traceMsg) => void;
|
@@ -17,6 +17,14 @@ 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
|
+
var PaymentState = /*#__PURE__*/function (PaymentState) {
|
22
|
+
PaymentState[PaymentState["notStarted"] = 0] = "notStarted";
|
23
|
+
PaymentState[PaymentState["pending"] = 1] = "pending";
|
24
|
+
PaymentState[PaymentState["fail"] = 2] = "fail";
|
25
|
+
PaymentState[PaymentState["success"] = 3] = "success";
|
26
|
+
return PaymentState;
|
27
|
+
}(PaymentState || {});
|
20
28
|
/**
|
21
29
|
* Apple Pay Service
|
22
30
|
*/
|
@@ -27,6 +35,7 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
27
35
|
_defineProperty(this, "merchantIdentifier", void 0);
|
28
36
|
_defineProperty(this, "merchantName", void 0);
|
29
37
|
_defineProperty(this, "session", void 0);
|
38
|
+
_defineProperty(this, "paymentState", void 0);
|
30
39
|
_defineProperty(this, "getMerchantSession", void 0);
|
31
40
|
_defineProperty(this, "completePaymentAuthorized", void 0);
|
32
41
|
_defineProperty(this, "completeApplePay", void 0);
|
@@ -44,7 +53,7 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
44
53
|
_this.session.completeMerchantValidation(merchantSessionObject);
|
45
54
|
_this.applePayTrace('completeMerchantValidation');
|
46
55
|
}).catch(function (error) {
|
47
|
-
_this.logError('MerchantValidationError', error);
|
56
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'MerchantValidationError', error);
|
48
57
|
_this.session.abort();
|
49
58
|
});
|
50
59
|
});
|
@@ -55,19 +64,22 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
55
64
|
ApplePaySession = _window.ApplePaySession;
|
56
65
|
var exception = function exception(error) {
|
57
66
|
_this.session.completePayment(ApplePaySession.STATUS_FAILURE);
|
58
|
-
_this.logError('PaymentAuthorizedError', error);
|
67
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'PaymentAuthorizedError', error);
|
59
68
|
_this.session.abort();
|
60
69
|
};
|
61
70
|
if (event !== null && event !== void 0 && (_event$payment = event.payment) !== null && _event$payment !== void 0 && _event$payment.token) {
|
62
71
|
_this.applePayTrace('completePaymentAuthorized');
|
72
|
+
_this.paymentState = PaymentState.pending;
|
63
73
|
_this.completePaymentAuthorized({
|
64
74
|
paymentToken: JSON.stringify(event.payment.token)
|
65
75
|
}).then(function (data) {
|
66
76
|
_this.applePayTrace('completeApplePay');
|
67
77
|
_this.session.completePayment(ApplePaySession.STATUS_SUCCESS);
|
68
78
|
_this.completeApplePay(data);
|
79
|
+
_this.paymentState = PaymentState.success;
|
69
80
|
}).catch(function (error) {
|
70
81
|
exception(error);
|
82
|
+
_this.paymentState = PaymentState.fail;
|
71
83
|
});
|
72
84
|
} else {
|
73
85
|
exception();
|
@@ -91,13 +103,13 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
91
103
|
recurringInfo = paymentSessionFactor.recurringInfo;
|
92
104
|
_this.merchantIdentifier = merchantInfo === null || merchantInfo === void 0 ? void 0 : merchantInfo.partnerId;
|
93
105
|
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("
|
106
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal paymentSessionFactor");
|
95
107
|
return;
|
96
108
|
}
|
97
109
|
if (recurringInfo) {
|
98
110
|
var _recurringInfo$interv;
|
99
111
|
if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
|
100
|
-
_this.logError("
|
112
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal recurringInfo");
|
101
113
|
return;
|
102
114
|
}
|
103
115
|
var lineItem = {
|
@@ -145,7 +157,16 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
145
157
|
_this.session.onvalidatemerchant = _this.onvalidatemerchant;
|
146
158
|
_this.session.onpaymentauthorized = _this.onpaymentauthorized;
|
147
159
|
_this.session.oncancel = function () {
|
148
|
-
_this.
|
160
|
+
if (_this.paymentState === PaymentState.pending) {
|
161
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_PROCESSING, 'Payment processing but user dismissed the sheet');
|
162
|
+
} else {
|
163
|
+
_this.logError(eventCodeEnum.SDK_PAYMENT_CANCEL, 'User dismissed the sheet');
|
164
|
+
}
|
165
|
+
try {
|
166
|
+
_this.session.abort();
|
167
|
+
} catch (error) {
|
168
|
+
console.log("session.abort() error");
|
169
|
+
}
|
149
170
|
};
|
150
171
|
_this.session.begin();
|
151
172
|
_this.applePayTrace('sessionBegin');
|
@@ -168,6 +189,7 @@ var ApplePayService = /*#__PURE__*/function () {
|
|
168
189
|
this.completeApplePay = completeApplePay;
|
169
190
|
this.logError = logError;
|
170
191
|
this.applePayTrace = applePayTrace;
|
192
|
+
this.paymentState = PaymentState.notStarted;
|
171
193
|
}
|
172
194
|
|
173
195
|
/**
|
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) {
|