@blocklet/payment-react 1.19.19 → 1.19.20
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/es/checkout/form.js +16 -0
- package/es/payment/form/index.js +11 -1
- package/lib/checkout/form.js +16 -0
- package/lib/payment/form/index.js +11 -1
- package/package.json +3 -3
- package/src/checkout/form.tsx +19 -0
- package/src/payment/form/index.tsx +13 -1
package/es/checkout/form.js
CHANGED
|
@@ -3,6 +3,7 @@ import { useRequest, useSetState } from "ahooks";
|
|
|
3
3
|
import noop from "lodash/noop";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
5
|
import { joinURL } from "ufo";
|
|
6
|
+
import { ReactGA } from "@arcblock/ux/lib/withTracker";
|
|
6
7
|
import api from "../libs/api.js";
|
|
7
8
|
import { getPrefix, mergeExtraParams } from "../libs/util.js";
|
|
8
9
|
import Payment from "../payment/index.js";
|
|
@@ -56,11 +57,26 @@ export default function CheckoutForm({
|
|
|
56
57
|
const handlePaid = (result) => {
|
|
57
58
|
setState({ completed: true });
|
|
58
59
|
onPaid?.(result);
|
|
60
|
+
const paySuccessEvent = {
|
|
61
|
+
action: "paySuccess",
|
|
62
|
+
// @ts-ignore 后续升级的话就会报错了,移除这个 lint 即可
|
|
63
|
+
mode: data?.checkoutSession?.mode,
|
|
64
|
+
success: true
|
|
65
|
+
};
|
|
66
|
+
ReactGA.event(paySuccessEvent.action, paySuccessEvent);
|
|
59
67
|
};
|
|
60
68
|
const handleError = (err) => {
|
|
61
69
|
console.error(err);
|
|
62
70
|
setState({ appError: err });
|
|
63
71
|
onError?.(err);
|
|
72
|
+
const payFailedEvent = {
|
|
73
|
+
action: "payFailed",
|
|
74
|
+
// @ts-ignore后续升级的话就会报错了,移除这个 lint 即可
|
|
75
|
+
mode: data?.checkoutSession?.mode,
|
|
76
|
+
errorMessage: err.message,
|
|
77
|
+
success: false
|
|
78
|
+
};
|
|
79
|
+
ReactGA.event(payFailedEvent.action, payFailedEvent);
|
|
64
80
|
};
|
|
65
81
|
const Checkout = formType === "donation" ? /* @__PURE__ */ jsx(
|
|
66
82
|
DonationForm,
|
package/es/payment/form/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { fromUnitToToken } from "@ocap/util";
|
|
|
14
14
|
import DID from "@arcblock/ux/lib/DID";
|
|
15
15
|
import isEmpty from "lodash/isEmpty";
|
|
16
16
|
import { HelpOutline, OpenInNew } from "@mui/icons-material";
|
|
17
|
+
import { ReactGA } from "@arcblock/ux/lib/withTracker";
|
|
17
18
|
import FormInput from "../../components/input.js";
|
|
18
19
|
import FormLabel from "../../components/label.js";
|
|
19
20
|
import { usePaymentContext } from "../../contexts/payment.js";
|
|
@@ -267,7 +268,16 @@ export default function PaymentForm({
|
|
|
267
268
|
onPaid(result);
|
|
268
269
|
}
|
|
269
270
|
} catch (err) {
|
|
270
|
-
|
|
271
|
+
const errorMessage = formatError(err);
|
|
272
|
+
const payFailedEvent = {
|
|
273
|
+
action: "payFailed",
|
|
274
|
+
// @ts-ignore 后续升级的话就会报错了,移除这个 lint 即可
|
|
275
|
+
mode: checkoutSession.mode,
|
|
276
|
+
errorMessage,
|
|
277
|
+
success: false
|
|
278
|
+
};
|
|
279
|
+
ReactGA.event(payFailedEvent.action, payFailedEvent);
|
|
280
|
+
Toast.error(errorMessage);
|
|
271
281
|
} finally {
|
|
272
282
|
setState({ paying: false });
|
|
273
283
|
processingRef.current = false;
|
package/lib/checkout/form.js
CHANGED
|
@@ -9,6 +9,7 @@ var _ahooks = require("ahooks");
|
|
|
9
9
|
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
10
10
|
var _react = require("react");
|
|
11
11
|
var _ufo = require("ufo");
|
|
12
|
+
var _withTracker = require("@arcblock/ux/lib/withTracker");
|
|
12
13
|
var _api = _interopRequireDefault(require("../libs/api"));
|
|
13
14
|
var _util = require("../libs/util");
|
|
14
15
|
var _payment = _interopRequireDefault(require("../payment"));
|
|
@@ -67,6 +68,13 @@ function CheckoutForm({
|
|
|
67
68
|
completed: true
|
|
68
69
|
});
|
|
69
70
|
onPaid?.(result);
|
|
71
|
+
const paySuccessEvent = {
|
|
72
|
+
action: "paySuccess",
|
|
73
|
+
// @ts-ignore 后续升级的话就会报错了,移除这个 lint 即可
|
|
74
|
+
mode: data?.checkoutSession?.mode,
|
|
75
|
+
success: true
|
|
76
|
+
};
|
|
77
|
+
_withTracker.ReactGA.event(paySuccessEvent.action, paySuccessEvent);
|
|
70
78
|
};
|
|
71
79
|
const handleError = err => {
|
|
72
80
|
console.error(err);
|
|
@@ -74,6 +82,14 @@ function CheckoutForm({
|
|
|
74
82
|
appError: err
|
|
75
83
|
});
|
|
76
84
|
onError?.(err);
|
|
85
|
+
const payFailedEvent = {
|
|
86
|
+
action: "payFailed",
|
|
87
|
+
// @ts-ignore后续升级的话就会报错了,移除这个 lint 即可
|
|
88
|
+
mode: data?.checkoutSession?.mode,
|
|
89
|
+
errorMessage: err.message,
|
|
90
|
+
success: false
|
|
91
|
+
};
|
|
92
|
+
_withTracker.ReactGA.event(payFailedEvent.action, payFailedEvent);
|
|
77
93
|
};
|
|
78
94
|
const Checkout = formType === "donation" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_donationForm.default, {
|
|
79
95
|
checkoutSession: data?.checkoutSession,
|
|
@@ -21,6 +21,7 @@ var _util = require("@ocap/util");
|
|
|
21
21
|
var _DID = _interopRequireDefault(require("@arcblock/ux/lib/DID"));
|
|
22
22
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
23
23
|
var _iconsMaterial = require("@mui/icons-material");
|
|
24
|
+
var _withTracker = require("@arcblock/ux/lib/withTracker");
|
|
24
25
|
var _input = _interopRequireDefault(require("../../components/input"));
|
|
25
26
|
var _label = _interopRequireDefault(require("../../components/label"));
|
|
26
27
|
var _payment = require("../../contexts/payment");
|
|
@@ -305,7 +306,16 @@ function PaymentForm({
|
|
|
305
306
|
onPaid(result);
|
|
306
307
|
}
|
|
307
308
|
} catch (err) {
|
|
308
|
-
|
|
309
|
+
const errorMessage = (0, _util2.formatError)(err);
|
|
310
|
+
const payFailedEvent = {
|
|
311
|
+
action: "payFailed",
|
|
312
|
+
// @ts-ignore 后续升级的话就会报错了,移除这个 lint 即可
|
|
313
|
+
mode: checkoutSession.mode,
|
|
314
|
+
errorMessage,
|
|
315
|
+
success: false
|
|
316
|
+
};
|
|
317
|
+
_withTracker.ReactGA.event(payFailedEvent.action, payFailedEvent);
|
|
318
|
+
_Toast.default.error(errorMessage);
|
|
309
319
|
} finally {
|
|
310
320
|
setState({
|
|
311
321
|
paying: false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.20",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@babel/core": "^7.27.4",
|
|
95
95
|
"@babel/preset-env": "^7.27.2",
|
|
96
96
|
"@babel/preset-react": "^7.27.1",
|
|
97
|
-
"@blocklet/payment-types": "1.19.
|
|
97
|
+
"@blocklet/payment-types": "1.19.20",
|
|
98
98
|
"@storybook/addon-essentials": "^7.6.20",
|
|
99
99
|
"@storybook/addon-interactions": "^7.6.20",
|
|
100
100
|
"@storybook/addon-links": "^7.6.20",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"vite-plugin-babel": "^1.3.1",
|
|
126
126
|
"vite-plugin-node-polyfills": "^0.23.0"
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "4e09a5936748fc15c1ab6ea90b741b3e44f5eab7"
|
|
129
129
|
}
|
package/src/checkout/form.tsx
CHANGED
|
@@ -4,6 +4,8 @@ import noop from 'lodash/noop';
|
|
|
4
4
|
import { useEffect } from 'react';
|
|
5
5
|
import { joinURL } from 'ufo';
|
|
6
6
|
|
|
7
|
+
import { ReactGA } from '@arcblock/ux/lib/withTracker';
|
|
8
|
+
import type { PayFailedEvent, PaySuccessEvent } from '@arcblock/ux/lib/withTracker/action/pay';
|
|
7
9
|
import api from '../libs/api';
|
|
8
10
|
import { getPrefix, mergeExtraParams } from '../libs/util';
|
|
9
11
|
import Payment from '../payment';
|
|
@@ -70,12 +72,29 @@ export default function CheckoutForm({
|
|
|
70
72
|
const handlePaid = (result: CheckoutContext) => {
|
|
71
73
|
setState({ completed: true });
|
|
72
74
|
onPaid?.(result as CheckoutContext);
|
|
75
|
+
|
|
76
|
+
const paySuccessEvent: PaySuccessEvent = {
|
|
77
|
+
action: 'paySuccess',
|
|
78
|
+
// @ts-ignore 后续升级的话就会报错了,移除这个 lint 即可
|
|
79
|
+
mode: data?.checkoutSession?.mode!,
|
|
80
|
+
success: true,
|
|
81
|
+
};
|
|
82
|
+
ReactGA.event(paySuccessEvent.action, paySuccessEvent);
|
|
73
83
|
};
|
|
74
84
|
|
|
75
85
|
const handleError = (err: any) => {
|
|
76
86
|
console.error(err);
|
|
77
87
|
setState({ appError: err });
|
|
78
88
|
onError?.(err);
|
|
89
|
+
|
|
90
|
+
const payFailedEvent: PayFailedEvent = {
|
|
91
|
+
action: 'payFailed',
|
|
92
|
+
// @ts-ignore后续升级的话就会报错了,移除这个 lint 即可
|
|
93
|
+
mode: data?.checkoutSession?.mode!,
|
|
94
|
+
errorMessage: err.message,
|
|
95
|
+
success: false,
|
|
96
|
+
};
|
|
97
|
+
ReactGA.event(payFailedEvent.action, payFailedEvent);
|
|
79
98
|
};
|
|
80
99
|
|
|
81
100
|
const Checkout =
|
|
@@ -15,9 +15,11 @@ import { dispatch } from 'use-bus';
|
|
|
15
15
|
import isEmail from 'validator/es/lib/isEmail';
|
|
16
16
|
import { fromUnitToToken } from '@ocap/util';
|
|
17
17
|
import DID from '@arcblock/ux/lib/DID';
|
|
18
|
+
import { PayFailedEvent } from '@arcblock/ux/lib/withTracker/action/pay';
|
|
18
19
|
|
|
19
20
|
import isEmpty from 'lodash/isEmpty';
|
|
20
21
|
import { HelpOutline, OpenInNew } from '@mui/icons-material';
|
|
22
|
+
import { ReactGA } from '@arcblock/ux/lib/withTracker';
|
|
21
23
|
import FormInput from '../../components/input';
|
|
22
24
|
import FormLabel from '../../components/label';
|
|
23
25
|
import { usePaymentContext } from '../../contexts/payment';
|
|
@@ -382,7 +384,17 @@ export default function PaymentForm({
|
|
|
382
384
|
onPaid(result);
|
|
383
385
|
}
|
|
384
386
|
} catch (err) {
|
|
385
|
-
|
|
387
|
+
const errorMessage = formatError(err);
|
|
388
|
+
const payFailedEvent: PayFailedEvent = {
|
|
389
|
+
action: 'payFailed',
|
|
390
|
+
// @ts-ignore 后续升级的话就会报错了,移除这个 lint 即可
|
|
391
|
+
mode: checkoutSession.mode,
|
|
392
|
+
errorMessage,
|
|
393
|
+
success: false,
|
|
394
|
+
};
|
|
395
|
+
ReactGA.event(payFailedEvent.action, payFailedEvent);
|
|
396
|
+
|
|
397
|
+
Toast.error(errorMessage);
|
|
386
398
|
} finally {
|
|
387
399
|
setState({ paying: false });
|
|
388
400
|
processingRef.current = false;
|