Stripe API on Node.js Error: No such customer:
<p>Pretty new to this. Everything works fine, card validates, but when they submit the information the webpage shows "internal server error" and the error log shows "Error: no such customer". Research on that error message shows that something is wrong in my code, but i'm having trouble spotting it. </p>

<p>Customers are paying for a subscription product.</p>

<pre><code>  let promise = Promise.resolve();
    if(user.stripe_plan_id !== plan || card_token){
        promise = promise.then( () =&gt; {
            return new Promise( (resolve, reject) =&gt; {
                if(!user.stripe_user_id){
                    stripe.customers.create({
                        description: 'Customer for test@example.com',
                        email: user.email,
                        //source: "tok_16UzfA2eZvKYlo2CVJRxXLSR" // obtained with Stripe.js
                        plan: 'free',
                        metadata: {
                            userId: user.id
                        }
                    }, function(err, customer) {
                        if(err){
                            reject(err);
                        }else{
                            user.stripe_user_id = customer.id;
                            resolve();
                        }
                    });
                }else{
                    resolve();
                }
            });
        });
    }
    if(card_token){
        promise = promise.then( () =&gt; {
            return new Promise( (resolve, reject) =&gt; {
                stripe.customers.update(user.stripe_user_id, {
                    source: card_token
                }, function(err, customer) {
                    if(err){
                        reject(err);
                    }else{
                        let last4;
                        if(customer.default_source){
                            customer.sources.data.forEach( (source) =&gt; {
                                if(source.id == customer.default_source){
                                    last4 = source.last4;
                                }
                            });
                        }
                        user.last4 = last4 || '';
                        resolve(); //next section will save the user anyways.
                    }
                });
            });
        });
    }
    if(user.stripe_plan_id !== plan){
        promise = promise.then( () =&gt; {
            return new Promise( (resolve, reject) =&gt; {
                stripe.customers.listSubscriptions(user.stripe_user_id, function(err, subscriptions) {
                    if(err){
                        reject(err);
                    }else{
                        resolve(subscriptions);
                    }
                });
            });
        }).then( (subscriptions) =&gt; {
            return new Promise( (resolve, reject) =&gt; {
                if(subscriptions.data[0]){
                    stripe.customers.updateSubscription(
                        user.stripe_user_id,
                        subscriptions.data[0].id,
                        { plan },
                        function(err, subscription) {
                            if(err){
                                reject(err);
                            }else{
                                user.stripe_plan_id = plan;
                                resolve();
                            }
                        }
                    );
                }else{
                    stripe.customers.createSubscription(
                        user.stripe_user_id,
                        {plan},
                        function(err, subscription) {
                            if(err){
                                reject(err);
                            }else{
                                user.stripe_plan_id = plan;
                                resolve();
                            }
                        }
                    );
                }
            });
        });
    }
    return promise.then( () =&gt; {
        return user.save();
    });
}).then( (user) =&gt; {
    res.json({
        plan: user.stripe_plan_id
    }).end();
}).catch( (err) =&gt; {
    console.error(err);
    if(err.message === 'This customer has no attached payment source'){
        res.json({
            error: true,
            message:'Payment source missing.'
        }).end();
        return;
    }
    res.json({
        error: true,
        message:typeof(err)==="string"?err:'internal server error'
    }).end();
});
</code></pre>

<p>});</p>