Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe is creating customers when charge declined

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)
like image 485
nadermx Avatar asked Dec 05 '25 03:12

nadermx


1 Answers

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.

like image 122
Ywain Avatar answered Dec 07 '25 15:12

Ywain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!