芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/Payment/StripeModal.jsx
import { ElementsConsumer, CardElement } from "@stripe/react-stripe-js"; import React, { useState } from "react"; import Loader from "./Loader"; import { useSelector } from "react-redux"; import toast from "react-hot-toast"; import { userSignUpData } from "@/store/reducer/authSlice"; import { useRouter } from "next/router"; import { confirmPaymentApi } from "@/store/actions/campaign"; import { settingsData } from "@/store/reducer/settingsSlice"; import { translate } from "@/utils"; const CARD_OPTIONS = { iconStyle: "solid", style: { base: { // iconColor: "#c4f0ff", fontWeight: 500, fontFamily: "Roboto, Open Sans, Segoe UI, sans-serif", fontSize: "16px", fontSmoothing: "antialiased", ":-webkit-autofill": { color: "#fce883" }, "::placeholder": { color: "#87bbfd" }, border: "2px solid black", }, invalid: { // iconColor: "#ffc7ee", color: "#ffc7ee", }, }, }; const StripeModal = (props) => { const navigate = useRouter(); const user = useSelector(userSignUpData); const systemsettings = useSelector(settingsData); const [loadingPay, setloadingPay] = useState(false); const handleSubmit = async (event) => { event.preventDefault(); const { stripe, elements, orderID } = props; // setloadingPay(true); if (!stripe || !elements || !orderID) { setloadingPay(false); return; } const { paymentIntent, error } = await stripe?.confirmCardPayment(props.client_key.client_secret, { payment_method: { card: elements.getElement(CardElement), billing_details: { name: user?.data?.data?.name, address: { line1: props?.stripeForm?.address, postal_code: props?.stripeForm?.postalcode, city: props?.stripeForm?.city, state: props?.stripeForm?.state, country: props?.stripeForm?.country, }, }, }, }); if (error) { console.log(error) toast.error(error.message); setloadingPay(false) // props?.setPaymentModal(false) props?.resetFormAndCardNumber(); } else if (paymentIntent?.status === "succeeded") { confirmPaymentApi( props?.client_key?.id, (res) => { toast.success(res.message); navigate.push("/"); setloadingPay(false); props?.setPaymentModal(false) props?.resetFormAndCardNumber(); }, (err) => { toast.error(err.message); console.log(err) } ); } else { setloadingPay(false); toast.error(translate("paymentfailed")); } }; return ( <>
Stripe: {systemsettings?.company_name} Payment
{/*
*/}
{loadingPay ? (
) : (
Pay
)}
> ); }; export default function InjectCheckout(props) { return (
{({ stripe, elements }) => (
props.resetFormAndCardNumber(elements)} /> )}
); }