For some reason when some one charges to sign up to the subscription plan if their card is declined stripe is still creating the customer.
I'm not particularly sure why this is happening since I am creating the customer with the charge, how do I make it so if some one signs up but their card does not go through stripe doesn't make them a customer?
Here is my code
import stripe
@app.route('/stripe/charge', methods=['POST'])
def stripe_charge():
data = json.loads(request.data)
user = data['user']
source = data['stripeToken'] # obtained from Stripe.js
try:
customer = stripe.Customer.create(
source=source,
plan="gold5",
email=email,
)
except stripe.CardError, e:
return jsonify(error="%s" % e)
return jsonify(customer)
Because you create the customer with the plan parameter, Stripe will attempt to create both the customer and the subscription in one go. Unless the plan has a trial period, Stripe will immediately attempt to bill the customer for the plan's amount (since Stripe's subscriptions are paid upfront), and if the charge fails, then the call will return an error and the customer will not be created.
If you're seeing a different behavior, I recommend you get in touch with Stripe's support to describe the problem. Make sure you include the customer ID and/or request ID in your message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With