0

When this promise is run the browser just times out ( didn’t send any data. ERR_EMPTY_RESPONSE). There aren't any errors in the terminal. The first console.log is printed but nothing else.

var createStripeCustomer = function(customer, source) {
    console.log('create stripe customer');
    return new Promise(function(res, rej) {
        stripe.customers.create({
            email: customer.email,
            source: source,
            account_balance: 500,
            metadata: {
                first_name: customer.first_name,
                last_name: customer.last_name,
                phone: customer.phone,
                address: `${customer.address} ${customer.appt}`,
                city: customer.city,
                state: customer.state,
                zipcode: customer.zip,
                referral: customer.referral
            },
            function(err, newCustomer) {
                if (err) {
                    console.log(err);
                    rej(err);
                }
                else {
                    console.log('created customer');
                    res(newCustomer);
                }
            }
        });
    });
};
David
  • 944
  • 1
  • 13
  • 20

1 Answers1

1

You have missed a } in the stripe.customers.create method first parameter:

var createStripeCustomer = function(customer, source) {
    console.log('create stripe customer');
    return new Promise(function(res, rej) {
        stripe.customers.create({
            email: customer.email,
            source: source,
            account_balance: 500,
            metadata: {
                first_name: customer.first_name,
                last_name: customer.last_name,
                phone: customer.phone,
                address: `${customer.address} ${customer.appt}`,
                city: customer.city,
                state: customer.state,
                zipcode: customer.zip,
                referral: customer.referral
             }
            },
            function(err, newCustomer) {
                if (err) {
                    console.log(err);
                    rej(err);
                }
                else {
                    console.log('created customer');
                    res(newCustomer);
                }
            }
        });
    });
};

and then it should work in this way:

createStripeCustomer(customer, source).then( res => console.log(res) ).catch(error => console.error(error))
loretoparisi
  • 15,724
  • 11
  • 102
  • 146
  • oh wow. \facepalm\. you're saying the .then( res.... should be when the function is called in the promise chain? – David Nov 29 '17 at 22:41