1

Here is my post route. When I submit the form it basically just stalls out. The post is being made to the server but the response (redirect) is not being sent back to the client.

app.post('/signup', function(req, res) {
var customer = req.body.customer;
var newCustomer = {
    "first_name": customer.first_name,
    "last_name": customer.last_name,
    "email": customer.email,
    "password": customer.password,
    "phone": customer.phone,
    "address": `${customer.address} ${customer.appt}`,
    "city": customer.city,
    "state": customer.state,
    "zip": customer.zip,
    "country": "US",
    "gateway_type": "PayWhirl Test Gateway",
    "gateway_id": 4133,
    "currency": "USD",
    "metadata": customer.referral
}

paywhirl.Customers.createCustomer(newCustomer, function() {
    if(err) {
        console.log(err);
        res.redirect('/', {err: err});
    } else {
        console.log('customer created!');
        res.redirect('/', {first_name: customer.first_name});
    }
});
})

Here is the paywhirl function that is being called:

createCustomer: function(data, cb) {
    options.path = "/create/customer";
    options.method = "POST";

    utils.pwPOST(options, data, cb);

},
David
  • 944
  • 1
  • 13
  • 20
  • Are you sure the createCustomer callback is being called at all? You could add a `console.log` to check – Maluen Nov 18 '17 at 18:53
  • Possible duplicate of [How do I redirect in expressjs while passing some context?](https://stackoverflow.com/questions/19035373/how-do-i-redirect-in-expressjs-while-passing-some-context) – proofzy Nov 18 '17 at 18:54
  • Do you see either of your `console.log()` calls? Also, you don't seem to be passing `err` in your callback. – ImClarky Nov 18 '17 at 20:10
  • @ImClarky just console.logged and everything is being called. I originally had err but took it out, sorry about that. – David Nov 18 '17 at 20:30
  • I think you may be calling your redirect incorrectly. If you call it with two parameters, the first should be the status code and the second should be the url as [per the docs](http://expressjs.com/en/api.html#res.redirect). – ImClarky Nov 18 '17 at 20:39

0 Answers0