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

Upvotes: 4

Views: 3385

Answers (1)

karbi
karbi

Reputation: 2183

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.

Upvotes: 2

Related Questions