Reputation: 878
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. I am using live stripe acccount for testing . https://dev.polyverse.app/pay here is the my application you can check.
Upvotes: 1
Views: 423
Reputation: 2784
The Payment Element also supports Google Pay and Apple Pay [0]. There is no need to implement a separate Payment Request button.
Google Pay and Apple Pay are unavailable for merchants and customers in India on Stripe Checkout and Stripe Elements [1] which is probably why you're not seeing these payment method options.
If it helps, I do see Google Pay and Apple Pay as an option to pay with on the URL you've provided.
[0]https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#apple-pay-and-google-pay
Upvotes: 1