back-end
@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)), 403Interfaz
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> ); }aquí está mi código de banda donde espero que llegue Google Pay pero no viene en mi servidor local. Estoy usando una cuenta de banda en vivo para probar. ¿Google pay btn no viene debido a localhost?
Google Pay con elemento de pago tiene los mismos requisitos previos que la integración del botón de solicitud de pago de Stripe. En su documentación , especifican que su aplicación debe servirse a través de HTTPS, lo que su integración no está haciendo actualmente. Puede usar algo como ngrok para servir su aplicación a través de HTTPS y verificar que aparezca Google Pay.