Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google pay option is not coming in stripe

backend

    @app.route('/create-payment-intent', methods=['POST'])
    def create_payment():
        try:
            data = json.loads(request.data)
            # Create a PaymentIntent with the order amount and currency
            intent = stripe.PaymentIntent.create(
                amount=calculate_order_amount(data['items']),
                currency='usd',
                automatic_payment_methods={
                    'enabled': True,
                },
            )
            return jsonify({
                'clientSecret': intent['client_secret']
            })
        except Exception as e:
            return jsonify(error=str(e)), 403

frontend

    export default function App() {
    const [clientSecret, setClientSecret] = useState("");

    useEffect(() => {
        // Create PaymentIntent as soon as the page loads
        fetch("/create-payment-intent", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ items: [{ id: "xl-tshirt" }] }),
        })
        .then((res) => res.json())
        .then((data) => setClientSecret(data.clientSecret));
    }, []);

    const appearance = {
        theme: "stripe",
    };
    const options = {
        clientSecret,
        appearance,
    };

    return (
        <div className="App">
        {clientSecret && (
            <Elements options={options} stripe={stripePromise}>
            <CheckoutForm />
            </Elements>
        )}
        </div>
    );
    }

here is my stripe code where i am expecting google pay to come but it is not coming in my localhost. I am using live stripe acccount for testing . Is google pay btn not coming because of localhost ?

Please check the screenshot how it is coming . enter image description here

Not sure what this mean in there doc enter image description here

like image 654
Kiran S youtube channel Avatar asked Nov 02 '25 13:11

Kiran S youtube channel


1 Answers

Google Pay with Payment Element has the same prerequisites as Stripe's Payment Request Button integration. In their documentation they specify that your application has to be served over HTTPS, which your integration isn't currently doing. You can use something like ngrok to serve your application over HTTPS and verify that Google Pay shows up.

like image 130
karbi Avatar answered Nov 04 '25 04:11

karbi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!