|
@@ -9,6 +9,7 @@ import { useAuth } from "@/providers/auth-provider";
|
|
|
import {
|
|
import {
|
|
|
fetchBankChannelOptions,
|
|
fetchBankChannelOptions,
|
|
|
fetchRemittanceChannels,
|
|
fetchRemittanceChannels,
|
|
|
|
|
+ isTelegraphicStylePayRequestUrl,
|
|
|
submitXfgPayOrder,
|
|
submitXfgPayOrder,
|
|
|
type BankChannelOption,
|
|
type BankChannelOption,
|
|
|
type RemittanceChannel,
|
|
type RemittanceChannel,
|
|
@@ -43,7 +44,7 @@ export function CheckoutForm() {
|
|
|
const [bankOptionsError, setBankOptionsError] = useState<string | null>(null);
|
|
const [bankOptionsError, setBankOptionsError] = useState<string | null>(null);
|
|
|
const [selectedBankCode, setSelectedBankCode] = useState("");
|
|
const [selectedBankCode, setSelectedBankCode] = useState("");
|
|
|
const [depositAmount, setDepositAmount] = useState("");
|
|
const [depositAmount, setDepositAmount] = useState("");
|
|
|
- const [msg, setMsg] = useState<string | null>(null);
|
|
|
|
|
|
|
+ const [, setMsg] = useState<string | null>(null);
|
|
|
const [submitting, setSubmitting] = useState(false);
|
|
const [submitting, setSubmitting] = useState(false);
|
|
|
const [submitDialog, setSubmitDialog] = useState<{
|
|
const [submitDialog, setSubmitDialog] = useState<{
|
|
|
open: boolean;
|
|
open: boolean;
|
|
@@ -120,15 +121,18 @@ export function CheckoutForm() {
|
|
|
status: "loading",
|
|
status: "loading",
|
|
|
message: "订单提交中,请稍候...",
|
|
message: "订单提交中,请稍候...",
|
|
|
});
|
|
});
|
|
|
|
|
+ const requestUrl = selectedChannel?.requestUrl || "/xfgpay/pay";
|
|
|
|
|
+ const isTelegraphicPay = isTelegraphicStylePayRequestUrl(requestUrl);
|
|
|
const { resultUrl } = await submitXfgPayOrder({
|
|
const { resultUrl } = await submitXfgPayOrder({
|
|
|
- requestUrl: selectedChannel?.requestUrl || "/xfgpay/pay",
|
|
|
|
|
|
|
+ requestUrl,
|
|
|
amount: finalAmount,
|
|
amount: finalAmount,
|
|
|
bankCode: selectedBankCode || undefined,
|
|
bankCode: selectedBankCode || undefined,
|
|
|
|
|
+ code: selectedChannel?.code || undefined,
|
|
|
goodIds: [goodsId],
|
|
goodIds: [goodsId],
|
|
|
payName: "",
|
|
payName: "",
|
|
|
payPhone: "",
|
|
payPhone: "",
|
|
|
});
|
|
});
|
|
|
- if (!resultUrl) {
|
|
|
|
|
|
|
+ if (!resultUrl && !isTelegraphicPay) {
|
|
|
throw new Error("下单成功但未返回支付地址");
|
|
throw new Error("下单成功但未返回支付地址");
|
|
|
}
|
|
}
|
|
|
addMockOrder({
|
|
addMockOrder({
|
|
@@ -139,11 +143,13 @@ export function CheckoutForm() {
|
|
|
setSubmitDialog({
|
|
setSubmitDialog({
|
|
|
open: true,
|
|
open: true,
|
|
|
status: "success",
|
|
status: "success",
|
|
|
- message: "提交订单成功,正在跳转到支付页面...",
|
|
|
|
|
|
|
+ message: isTelegraphicPay ? "提交订单成功。" : "提交订单成功,正在跳转到支付页面...",
|
|
|
});
|
|
});
|
|
|
- setTimeout(() => {
|
|
|
|
|
- window.open(resultUrl, "_blank", "noopener,noreferrer");
|
|
|
|
|
- }, 1000);
|
|
|
|
|
|
|
+ if (resultUrl) {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ window.open(resultUrl, "_blank", "noopener,noreferrer");
|
|
|
|
|
+ }, 1000);
|
|
|
|
|
+ }
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
const e = error as Error;
|
|
const e = error as Error;
|
|
|
setSubmitDialog({
|
|
setSubmitDialog({
|
|
@@ -323,8 +329,6 @@ export function CheckoutForm() {
|
|
|
</p>
|
|
</p>
|
|
|
)}
|
|
)}
|
|
|
|
|
|
|
|
- {msg && <p className="text-sm text-emerald-700">{msg}</p>}
|
|
|
|
|
-
|
|
|
|
|
{submitDialog.open ? (
|
|
{submitDialog.open ? (
|
|
|
<ModalShell open={submitDialog.open} className="max-w-sm">
|
|
<ModalShell open={submitDialog.open} className="max-w-sm">
|
|
|
<div className="w-full rounded-2xl border border-[var(--border)] bg-[var(--card)] p-6 shadow-xl">
|
|
<div className="w-full rounded-2xl border border-[var(--border)] bg-[var(--card)] p-6 shadow-xl">
|
|
@@ -351,13 +355,13 @@ export function CheckoutForm() {
|
|
|
<p className="mt-1 text-sm text-[var(--muted)]">{submitDialog.message}</p>
|
|
<p className="mt-1 text-sm text-[var(--muted)]">{submitDialog.message}</p>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- {submitDialog.status === "error" ? (
|
|
|
|
|
|
|
+ {submitDialog.status !== "loading" ? (
|
|
|
<button
|
|
<button
|
|
|
type="button"
|
|
type="button"
|
|
|
onClick={() => setSubmitDialog((prev) => ({ ...prev, open: false }))}
|
|
onClick={() => setSubmitDialog((prev) => ({ ...prev, open: false }))}
|
|
|
className="mt-5 w-full rounded-lg border border-[var(--border)] px-3 py-2 text-sm hover:bg-[var(--background)]"
|
|
className="mt-5 w-full rounded-lg border border-[var(--border)] px-3 py-2 text-sm hover:bg-[var(--background)]"
|
|
|
>
|
|
>
|
|
|
- 知道了
|
|
|
|
|
|
|
+ {submitDialog.status === "success" ? "确定" : "知道了"}
|
|
|
</button>
|
|
</button>
|
|
|
) : null}
|
|
) : null}
|
|
|
</div>
|
|
</div>
|