Stripe is creating customers when charge declined
<p>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.</p>

<p>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?</p>

<p>Here is my code</p>

<pre><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)
</code></pre>

<p>Because you <a href="https://stripe.com/docs/api#create_customer" rel="nofollow">create the customer</a> with the <code>plan</code> 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 <em>not</em> be created.</p>

<p>If you're seeing a different behavior, I recommend you get in touch with <a href="https://support.stripe.com/email" rel="nofollow">Stripe's support</a> to describe the problem. Make sure you include the customer ID and/or request ID in your message.</p>

python flask stripe-payments