Stripe: 502 (Bad Gateway)











up vote
0
down vote

favorite












I am getting a 502 (Bad Gateway) error with Stripe. The payment successfully charges the card and shows up in the Stripe dashboard but it does not show its succesful on the front end and instead I get 502 error.



Am I suppose to add something below to make the front end show the payment is successful? Using the docs here:
https://stripe.com/docs/stripe-js/elements/payment-request-button



  // Send the token to your server to charge it!
fetch('/apple-pay', {
method: 'POST',
body: JSON.stringify({token: ev.token.id}),
headers: {'content-type': 'application/json'},
})

.then(function(response) {
console.log(response)
if (response.ok) {
// Report to the browser that the payment was successful, prompting
// it to close the browser payment interface.
ev.complete('success');
} else {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete('fail');
}
});
});


Server Side Code



app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
var stripe = require("stripe")("sk_test_xxx");
console.log('we got here....')
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

const token = req.body.token;
console.log(req.body)

// Using Express

console.log('this is the Token...' + token)
const charge = stripe.charges.create({
amount: 499,
currency: 'usd',
description: 'Example charge',
source: token,
}, function(err, charge) {
// asynchronously called
console.log(err)
});
});









share|improve this question
























  • The issue likely comes from the code server-side and you haven't shared it. You need to add logs to your code to track what value(s) you are returning exactly
    – koopajah
    Nov 8 at 3:15










  • @koopajah added
    – AndrewLeonardi
    Nov 8 at 3:16










  • Sure but you had another question earlier where you said the charge did not work. Did you add logs to the code that you read and were able to debug? For example right now you code creates a charge asynchronously and never returns anything, no response, no 200, etc. You need to handle the request properly
    – koopajah
    Nov 8 at 3:17












  • @koopajah Yes! I managed to solve that. Now the Payment successfully completes. And I can see it in the Stripe dashboard. However on the front end it looks like it does not complete...
    – AndrewLeonardi
    Nov 8 at 3:18










  • Awesome! I explained above what to look for though. You need to ensure that your code waits for the charge creation to be done and only then return a value. You likely want to read up on Node.js, Async flows, how to handle requests on your server, etc.
    – koopajah
    Nov 8 at 3:52















up vote
0
down vote

favorite












I am getting a 502 (Bad Gateway) error with Stripe. The payment successfully charges the card and shows up in the Stripe dashboard but it does not show its succesful on the front end and instead I get 502 error.



Am I suppose to add something below to make the front end show the payment is successful? Using the docs here:
https://stripe.com/docs/stripe-js/elements/payment-request-button



  // Send the token to your server to charge it!
fetch('/apple-pay', {
method: 'POST',
body: JSON.stringify({token: ev.token.id}),
headers: {'content-type': 'application/json'},
})

.then(function(response) {
console.log(response)
if (response.ok) {
// Report to the browser that the payment was successful, prompting
// it to close the browser payment interface.
ev.complete('success');
} else {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete('fail');
}
});
});


Server Side Code



app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
var stripe = require("stripe")("sk_test_xxx");
console.log('we got here....')
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

const token = req.body.token;
console.log(req.body)

// Using Express

console.log('this is the Token...' + token)
const charge = stripe.charges.create({
amount: 499,
currency: 'usd',
description: 'Example charge',
source: token,
}, function(err, charge) {
// asynchronously called
console.log(err)
});
});









share|improve this question
























  • The issue likely comes from the code server-side and you haven't shared it. You need to add logs to your code to track what value(s) you are returning exactly
    – koopajah
    Nov 8 at 3:15










  • @koopajah added
    – AndrewLeonardi
    Nov 8 at 3:16










  • Sure but you had another question earlier where you said the charge did not work. Did you add logs to the code that you read and were able to debug? For example right now you code creates a charge asynchronously and never returns anything, no response, no 200, etc. You need to handle the request properly
    – koopajah
    Nov 8 at 3:17












  • @koopajah Yes! I managed to solve that. Now the Payment successfully completes. And I can see it in the Stripe dashboard. However on the front end it looks like it does not complete...
    – AndrewLeonardi
    Nov 8 at 3:18










  • Awesome! I explained above what to look for though. You need to ensure that your code waits for the charge creation to be done and only then return a value. You likely want to read up on Node.js, Async flows, how to handle requests on your server, etc.
    – koopajah
    Nov 8 at 3:52













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am getting a 502 (Bad Gateway) error with Stripe. The payment successfully charges the card and shows up in the Stripe dashboard but it does not show its succesful on the front end and instead I get 502 error.



Am I suppose to add something below to make the front end show the payment is successful? Using the docs here:
https://stripe.com/docs/stripe-js/elements/payment-request-button



  // Send the token to your server to charge it!
fetch('/apple-pay', {
method: 'POST',
body: JSON.stringify({token: ev.token.id}),
headers: {'content-type': 'application/json'},
})

.then(function(response) {
console.log(response)
if (response.ok) {
// Report to the browser that the payment was successful, prompting
// it to close the browser payment interface.
ev.complete('success');
} else {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete('fail');
}
});
});


Server Side Code



app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
var stripe = require("stripe")("sk_test_xxx");
console.log('we got here....')
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

const token = req.body.token;
console.log(req.body)

// Using Express

console.log('this is the Token...' + token)
const charge = stripe.charges.create({
amount: 499,
currency: 'usd',
description: 'Example charge',
source: token,
}, function(err, charge) {
// asynchronously called
console.log(err)
});
});









share|improve this question















I am getting a 502 (Bad Gateway) error with Stripe. The payment successfully charges the card and shows up in the Stripe dashboard but it does not show its succesful on the front end and instead I get 502 error.



Am I suppose to add something below to make the front end show the payment is successful? Using the docs here:
https://stripe.com/docs/stripe-js/elements/payment-request-button



  // Send the token to your server to charge it!
fetch('/apple-pay', {
method: 'POST',
body: JSON.stringify({token: ev.token.id}),
headers: {'content-type': 'application/json'},
})

.then(function(response) {
console.log(response)
if (response.ok) {
// Report to the browser that the payment was successful, prompting
// it to close the browser payment interface.
ev.complete('success');
} else {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete('fail');
}
});
});


Server Side Code



app.post('/apple-pay', function(req, res, next) {
// Set your secret key: remember to change this to your live secret key in production
var stripe = require("stripe")("sk_test_xxx");
console.log('we got here....')
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

const token = req.body.token;
console.log(req.body)

// Using Express

console.log('this is the Token...' + token)
const charge = stripe.charges.create({
amount: 499,
currency: 'usd',
description: 'Example charge',
source: token,
}, function(err, charge) {
// asynchronously called
console.log(err)
});
});






ios node.js express stripe-payments payment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 3:26

























asked Nov 8 at 2:59









AndrewLeonardi

1,08421542




1,08421542












  • The issue likely comes from the code server-side and you haven't shared it. You need to add logs to your code to track what value(s) you are returning exactly
    – koopajah
    Nov 8 at 3:15










  • @koopajah added
    – AndrewLeonardi
    Nov 8 at 3:16










  • Sure but you had another question earlier where you said the charge did not work. Did you add logs to the code that you read and were able to debug? For example right now you code creates a charge asynchronously and never returns anything, no response, no 200, etc. You need to handle the request properly
    – koopajah
    Nov 8 at 3:17












  • @koopajah Yes! I managed to solve that. Now the Payment successfully completes. And I can see it in the Stripe dashboard. However on the front end it looks like it does not complete...
    – AndrewLeonardi
    Nov 8 at 3:18










  • Awesome! I explained above what to look for though. You need to ensure that your code waits for the charge creation to be done and only then return a value. You likely want to read up on Node.js, Async flows, how to handle requests on your server, etc.
    – koopajah
    Nov 8 at 3:52


















  • The issue likely comes from the code server-side and you haven't shared it. You need to add logs to your code to track what value(s) you are returning exactly
    – koopajah
    Nov 8 at 3:15










  • @koopajah added
    – AndrewLeonardi
    Nov 8 at 3:16










  • Sure but you had another question earlier where you said the charge did not work. Did you add logs to the code that you read and were able to debug? For example right now you code creates a charge asynchronously and never returns anything, no response, no 200, etc. You need to handle the request properly
    – koopajah
    Nov 8 at 3:17












  • @koopajah Yes! I managed to solve that. Now the Payment successfully completes. And I can see it in the Stripe dashboard. However on the front end it looks like it does not complete...
    – AndrewLeonardi
    Nov 8 at 3:18










  • Awesome! I explained above what to look for though. You need to ensure that your code waits for the charge creation to be done and only then return a value. You likely want to read up on Node.js, Async flows, how to handle requests on your server, etc.
    – koopajah
    Nov 8 at 3:52
















The issue likely comes from the code server-side and you haven't shared it. You need to add logs to your code to track what value(s) you are returning exactly
– koopajah
Nov 8 at 3:15




The issue likely comes from the code server-side and you haven't shared it. You need to add logs to your code to track what value(s) you are returning exactly
– koopajah
Nov 8 at 3:15












@koopajah added
– AndrewLeonardi
Nov 8 at 3:16




@koopajah added
– AndrewLeonardi
Nov 8 at 3:16












Sure but you had another question earlier where you said the charge did not work. Did you add logs to the code that you read and were able to debug? For example right now you code creates a charge asynchronously and never returns anything, no response, no 200, etc. You need to handle the request properly
– koopajah
Nov 8 at 3:17






Sure but you had another question earlier where you said the charge did not work. Did you add logs to the code that you read and were able to debug? For example right now you code creates a charge asynchronously and never returns anything, no response, no 200, etc. You need to handle the request properly
– koopajah
Nov 8 at 3:17














@koopajah Yes! I managed to solve that. Now the Payment successfully completes. And I can see it in the Stripe dashboard. However on the front end it looks like it does not complete...
– AndrewLeonardi
Nov 8 at 3:18




@koopajah Yes! I managed to solve that. Now the Payment successfully completes. And I can see it in the Stripe dashboard. However on the front end it looks like it does not complete...
– AndrewLeonardi
Nov 8 at 3:18












Awesome! I explained above what to look for though. You need to ensure that your code waits for the charge creation to be done and only then return a value. You likely want to read up on Node.js, Async flows, how to handle requests on your server, etc.
– koopajah
Nov 8 at 3:52




Awesome! I explained above what to look for though. You need to ensure that your code waits for the charge creation to be done and only then return a value. You likely want to read up on Node.js, Async flows, how to handle requests on your server, etc.
– koopajah
Nov 8 at 3:52












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










As discussed in the comments, the issue is that the request server-side does not return any status code and because of this the client-side code does not know it succeeded!






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53200929%2fstripe-502-bad-gateway%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    As discussed in the comments, the issue is that the request server-side does not return any status code and because of this the client-side code does not know it succeeded!






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      As discussed in the comments, the issue is that the request server-side does not return any status code and because of this the client-side code does not know it succeeded!






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        As discussed in the comments, the issue is that the request server-side does not return any status code and because of this the client-side code does not know it succeeded!






        share|improve this answer












        As discussed in the comments, the issue is that the request server-side does not return any status code and because of this the client-side code does not know it succeeded!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 17:16









        koopajah

        14k74680




        14k74680






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53200929%2fstripe-502-bad-gateway%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini