@blocklet/payment-react 1.13.150 → 1.13.151
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 +8 -1
- package/lib/checkout/form.js +7 -0
- package/package.json +3 -3
- package/src/checkout/form.tsx +9 -1
package/es/checkout/form.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useRequest, useSetState } from "ahooks";
|
|
3
3
|
import noop from "lodash/noop";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
import { joinURL } from "ufo";
|
|
4
6
|
import api from "../api.js";
|
|
5
7
|
import Payment from "../payment/index.js";
|
|
6
|
-
import { mergeExtraParams } from "../util.js";
|
|
8
|
+
import { getPrefix, mergeExtraParams } from "../util.js";
|
|
7
9
|
const startFromPaymentLink = async (id, params) => {
|
|
8
10
|
const { data } = await api.post(`/api/checkout-sessions/start/${id}?${mergeExtraParams(params)}`);
|
|
9
11
|
return data;
|
|
@@ -21,6 +23,11 @@ export default function CheckoutForm({ id, onPaid, onError, mode, goBack, extraP
|
|
|
21
23
|
const { error: apiError, data } = useRequest(
|
|
22
24
|
() => type === "paymentLink" ? startFromPaymentLink(id, extraParams) : fetchCheckoutSession(id)
|
|
23
25
|
);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (type === "paymentLink" && mode === "standalone" && data) {
|
|
28
|
+
window.history.replaceState(null, "", joinURL(getPrefix(), `/checkout/pay/${data.checkoutSession.id}`));
|
|
29
|
+
}
|
|
30
|
+
}, [type, mode, data]);
|
|
24
31
|
const handlePaid = () => {
|
|
25
32
|
setState({ completed: true });
|
|
26
33
|
onPaid?.(data);
|
package/lib/checkout/form.js
CHANGED
|
@@ -7,6 +7,8 @@ module.exports = CheckoutForm;
|
|
|
7
7
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
8
|
var _ahooks = require("ahooks");
|
|
9
9
|
var _noop = _interopRequireDefault(require("lodash/noop"));
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _ufo = require("ufo");
|
|
10
12
|
var _api = _interopRequireDefault(require("../api"));
|
|
11
13
|
var _payment = _interopRequireDefault(require("../payment"));
|
|
12
14
|
var _util = require("../util");
|
|
@@ -43,6 +45,11 @@ function CheckoutForm({
|
|
|
43
45
|
error: apiError,
|
|
44
46
|
data
|
|
45
47
|
} = (0, _ahooks.useRequest)(() => type === "paymentLink" ? startFromPaymentLink(id, extraParams) : fetchCheckoutSession(id));
|
|
48
|
+
(0, _react.useEffect)(() => {
|
|
49
|
+
if (type === "paymentLink" && mode === "standalone" && data) {
|
|
50
|
+
window.history.replaceState(null, "", (0, _ufo.joinURL)((0, _util.getPrefix)(), `/checkout/pay/${data.checkoutSession.id}`));
|
|
51
|
+
}
|
|
52
|
+
}, [type, mode, data]);
|
|
46
53
|
const handlePaid = () => {
|
|
47
54
|
setState({
|
|
48
55
|
completed: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.151",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@babel/core": "^7.23.9",
|
|
90
90
|
"@babel/preset-env": "^7.23.9",
|
|
91
91
|
"@babel/preset-react": "^7.23.3",
|
|
92
|
-
"@blocklet/payment-types": "1.13.
|
|
92
|
+
"@blocklet/payment-types": "1.13.151",
|
|
93
93
|
"@storybook/addon-essentials": "^7.6.13",
|
|
94
94
|
"@storybook/addon-interactions": "^7.6.13",
|
|
95
95
|
"@storybook/addon-links": "^7.6.13",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"vite-plugin-babel": "^1.2.0",
|
|
119
119
|
"vite-plugin-node-polyfills": "^0.19.0"
|
|
120
120
|
},
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "1697697b65f9372e868fb10d5766edb3144f44f8"
|
|
122
122
|
}
|
package/src/checkout/form.tsx
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
import { TCheckoutSessionExpanded, TPaymentMethodExpanded } from '@blocklet/payment-types';
|
|
3
3
|
import { useRequest, useSetState } from 'ahooks';
|
|
4
4
|
import noop from 'lodash/noop';
|
|
5
|
+
import { useEffect } from 'react';
|
|
6
|
+
import { joinURL } from 'ufo';
|
|
5
7
|
|
|
6
8
|
import api from '../api';
|
|
7
9
|
import Payment from '../payment';
|
|
8
10
|
import { CheckoutContext, CheckoutProps } from '../types';
|
|
9
|
-
import { mergeExtraParams } from '../util';
|
|
11
|
+
import { getPrefix, mergeExtraParams } from '../util';
|
|
10
12
|
|
|
11
13
|
const startFromPaymentLink = async (id: string, params?: Record<string, any>): Promise<CheckoutContext> => {
|
|
12
14
|
const { data } = await api.post(`/api/checkout-sessions/start/${id}?${mergeExtraParams(params)}`);
|
|
@@ -32,6 +34,12 @@ export default function CheckoutForm({ id, onPaid, onError, mode, goBack, extraP
|
|
|
32
34
|
type === 'paymentLink' ? startFromPaymentLink(id, extraParams) : fetchCheckoutSession(id)
|
|
33
35
|
);
|
|
34
36
|
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (type === 'paymentLink' && mode === 'standalone' && data) {
|
|
39
|
+
window.history.replaceState(null, '', joinURL(getPrefix(), `/checkout/pay/${data.checkoutSession.id}`));
|
|
40
|
+
}
|
|
41
|
+
}, [type, mode, data]);
|
|
42
|
+
|
|
35
43
|
const handlePaid = () => {
|
|
36
44
|
setState({ completed: true });
|
|
37
45
|
onPaid?.(data as CheckoutContext);
|