@alipay/ams-checkout 0.0.1710212811-dev.31 → 0.0.1710212811-dev.33

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.
@@ -18,6 +18,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
19
  import { APPLE_PAY_VERSION, APPLE_PAY_RECURRING_VERSION } from "./interface";
20
20
  import { eventCodeEnum } from "../../types";
21
+ import { ApplePayComponentEvent } from "./component";
21
22
  var PaymentState = /*#__PURE__*/function (PaymentState) {
22
23
  PaymentState[PaymentState["notStarted"] = 0] = "notStarted";
23
24
  PaymentState[PaymentState["pending"] = 1] = "pending";
@@ -29,7 +30,7 @@ var PaymentState = /*#__PURE__*/function (PaymentState) {
29
30
  * Apple Pay Service
30
31
  */
31
32
  var ApplePayService = /*#__PURE__*/function () {
32
- function ApplePayService() {
33
+ function ApplePayService(logger) {
33
34
  var _this = this;
34
35
  _classCallCheck(this, ApplePayService);
35
36
  _defineProperty(this, "merchantIdentifier", void 0);
@@ -40,9 +41,10 @@ var ApplePayService = /*#__PURE__*/function () {
40
41
  _defineProperty(this, "completePaymentAuthorized", void 0);
41
42
  _defineProperty(this, "completeApplePay", void 0);
42
43
  _defineProperty(this, "logError", void 0);
43
- _defineProperty(this, "applePayTrace", void 0);
44
+ _defineProperty(this, "isRecurring", false);
45
+ _defineProperty(this, "logger", void 0);
44
46
  _defineProperty(this, "onvalidatemerchant", function (event) {
45
- _this.applePayTrace('onValidateMerchant');
47
+ var success = false;
46
48
  _this.getMerchantSession({
47
49
  displayName: _this.merchantName,
48
50
  merchantIdentifier: _this.merchantIdentifier,
@@ -51,32 +53,40 @@ var ApplePayService = /*#__PURE__*/function () {
51
53
  console.log("onvalidatemerchant#merchantSessionObjectString", merchantSessionObjectString);
52
54
  var merchantSessionObject = JSON.parse(merchantSessionObjectString);
53
55
  _this.session.completeMerchantValidation(merchantSessionObject);
54
- _this.applePayTrace('completeMerchantValidation');
56
+ success = true;
55
57
  }).catch(function (error) {
56
58
  _this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'MerchantValidationError', error);
57
- _this.session.abort();
59
+ _this.sessionAbort();
58
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();
59
70
  });
60
71
  _defineProperty(this, "onpaymentauthorized", function (event) {
61
72
  var _event$payment;
62
- _this.applePayTrace('onpaymentauthorized');
63
73
  var _window = window,
64
74
  ApplePaySession = _window.ApplePaySession;
75
+ var success = false;
65
76
  var exception = function exception(error) {
66
77
  _this.session.completePayment(ApplePaySession.STATUS_FAILURE);
67
78
  _this.logError(eventCodeEnum.SDK_PAYMENT_FAIL, 'PaymentAuthorizedError', error);
68
- _this.session.abort();
79
+ _this.sessionAbort();
69
80
  };
70
81
  if (event !== null && event !== void 0 && (_event$payment = event.payment) !== null && _event$payment !== void 0 && _event$payment.token) {
71
- _this.applePayTrace('completePaymentAuthorized');
72
82
  _this.paymentState = PaymentState.pending;
73
83
  _this.completePaymentAuthorized({
74
84
  paymentToken: JSON.stringify(event.payment.token)
75
85
  }).then(function (data) {
76
- _this.applePayTrace('completeApplePay');
77
86
  _this.session.completePayment(ApplePaySession.STATUS_SUCCESS);
78
87
  _this.completeApplePay(data);
79
88
  _this.paymentState = PaymentState.success;
89
+ success = true;
80
90
  }).catch(function (error) {
81
91
  exception(error);
82
92
  _this.paymentState = PaymentState.fail;
@@ -84,17 +94,20 @@ var ApplePayService = /*#__PURE__*/function () {
84
94
  } else {
85
95
  exception();
86
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();
87
106
  });
88
107
  /**
89
108
  * Start Pay
90
109
  */
91
110
  _defineProperty(this, "startPay", function (param) {
92
- _this.applePayTrace('start');
93
- var _window2 = window,
94
- ApplePaySession = _window2.ApplePaySession;
95
- if (!ApplePaySession) {
96
- throw Error('ApplePaySession is null in window');
97
- }
98
111
  var paymentSessionFactor = param.paymentSessionFactor;
99
112
  var extendInfo = paymentSessionFactor.extendInfo,
100
113
  merchantInfo = paymentSessionFactor.merchantInfo,
@@ -102,14 +115,30 @@ var ApplePayService = /*#__PURE__*/function () {
102
115
  order = paymentSessionFactor.order,
103
116
  recurringInfo = paymentSessionFactor.recurringInfo;
104
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
+ }
105
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)) {
106
- _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal paymentSessionFactor");
135
+ _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params paymentSessionFactor");
107
136
  return;
108
137
  }
109
138
  if (recurringInfo) {
110
139
  var _recurringInfo$interv;
111
140
  if (!(order !== null && order !== void 0 && order.orderDescription) || !(recurringInfo !== null && recurringInfo !== void 0 && recurringInfo.managementURL)) {
112
- _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal recurringInfo");
141
+ _this.logError(eventCodeEnum.SDK_PAYMENT_ERROR, "Abnormal params recurringInfo");
113
142
  return;
114
143
  }
115
144
  var lineItem = {
@@ -154,7 +183,9 @@ var ApplePayService = /*#__PURE__*/function () {
154
183
  };
155
184
  _this.session = new ApplePaySession(APPLE_PAY_VERSION, _request);
156
185
  }
186
+ // 核身前触发
157
187
  _this.session.onvalidatemerchant = _this.onvalidatemerchant;
188
+ // 核身后触发
158
189
  _this.session.onpaymentauthorized = _this.onpaymentauthorized;
159
190
  _this.session.oncancel = function () {
160
191
  if (_this.paymentState === PaymentState.pending) {
@@ -162,15 +193,20 @@ var ApplePayService = /*#__PURE__*/function () {
162
193
  } else {
163
194
  _this.logError(eventCodeEnum.SDK_PAYMENT_CANCEL, 'User dismissed the sheet');
164
195
  }
165
- try {
166
- _this.session.abort();
167
- } catch (error) {
168
- console.log("session.abort() error");
169
- }
196
+ _this.sessionAbort();
170
197
  };
171
198
  _this.session.begin();
172
- _this.applePayTrace('sessionBegin');
199
+ _this.logger.logInfo({
200
+ name: 'APPLE_PAY',
201
+ title: ApplePayComponentEvent.sdk_event_appleShowPaymentSheet
202
+ }, {
203
+ biz: 'sdk',
204
+ type: 'funnel',
205
+ success: true,
206
+ recurring: recurringInfo !== null
207
+ }).send();
173
208
  });
209
+ this.logger = logger;
174
210
  }
175
211
 
176
212
  /**
@@ -183,12 +219,11 @@ var ApplePayService = /*#__PURE__*/function () {
183
219
  */
184
220
  _createClass(ApplePayService, [{
185
221
  key: "setApplePayParams",
186
- value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError, applePayTrace) {
222
+ value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError) {
187
223
  this.getMerchantSession = getMerchantSession;
188
224
  this.completePaymentAuthorized = completePaymentAuthorized;
189
225
  this.completeApplePay = completeApplePay;
190
226
  this.logError = logError;
191
- this.applePayTrace = applePayTrace;
192
227
  this.paymentState = PaymentState.notStarted;
193
228
  }
194
229
 
@@ -229,6 +264,17 @@ var ApplePayService = /*#__PURE__*/function () {
229
264
  }
230
265
  return hasActiveCard;
231
266
  }())
267
+ }, {
268
+ key: "sessionAbort",
269
+ value: function sessionAbort() {
270
+ if (this.session) {
271
+ try {
272
+ this.session.abort();
273
+ } catch (error) {
274
+ console.log("session.abort() error");
275
+ }
276
+ }
277
+ }
232
278
  }], [{
233
279
  key: "canMakePayments",
234
280
  value: function canMakePayments(subTypeEnum) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1710212811-dev.31",
3
+ "version": "0.0.1710212811-dev.33",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",