@alipay/ams-checkout 0.0.1710212811-dev.31 → 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.
@@ -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 = {
@@ -162,15 +191,20 @@ var ApplePayService = /*#__PURE__*/function () {
162
191
  } else {
163
192
  _this.logError(eventCodeEnum.SDK_PAYMENT_CANCEL, 'User dismissed the sheet');
164
193
  }
165
- try {
166
- _this.session.abort();
167
- } catch (error) {
168
- console.log("session.abort() error");
169
- }
194
+ _this.sessionAbort();
170
195
  };
171
196
  _this.session.begin();
172
- _this.applePayTrace('sessionBegin');
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();
173
206
  });
207
+ this.logger = logger;
174
208
  }
175
209
 
176
210
  /**
@@ -183,12 +217,11 @@ var ApplePayService = /*#__PURE__*/function () {
183
217
  */
184
218
  _createClass(ApplePayService, [{
185
219
  key: "setApplePayParams",
186
- value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError, applePayTrace) {
220
+ value: function setApplePayParams(getMerchantSession, completePaymentAuthorized, completeApplePay, logError) {
187
221
  this.getMerchantSession = getMerchantSession;
188
222
  this.completePaymentAuthorized = completePaymentAuthorized;
189
223
  this.completeApplePay = completeApplePay;
190
224
  this.logError = logError;
191
- this.applePayTrace = applePayTrace;
192
225
  this.paymentState = PaymentState.notStarted;
193
226
  }
194
227
 
@@ -229,6 +262,17 @@ var ApplePayService = /*#__PURE__*/function () {
229
262
  }
230
263
  return hasActiveCard;
231
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
+ }
232
276
  }], [{
233
277
  key: "canMakePayments",
234
278
  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.32",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",