#thereal-charge-status
1 messages ยท Page 1 of 1 (latest)
i Am using django
What's the purchase_id in this case? Is that a Stripe Charge ID? Have you tested this out?
ya it works with the test card, the purchase ID is the charge.id I was just wondering if this would work in production or if I'm doing it wrong
Got it. So there is no paid attribute on a charge. You likely want to use charge.status in your conditional: https://stripe.com/docs/api/charges/object#charge_object-status
thanks I was wondering where it was in the API ๐
def check_payment_status(charge_id):
stripe.api_key = settings.STRIPE_SECRET_KEY
try:
charge = stripe.Charge.retrieve(charge_id)
if charge.status == 'pending':
return "Payment is pending"
elif charge.status == 'succeeded':
return "Payment succeeded"
elif charge.status == 'failed':
return "Payment failed"
else:
return "Unknown payment status"
except stripe.error.StripeError as e:
return f"Error: {e}"
works great ๐