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)
});
});
ios node.js express stripe-payments payment
|
show 1 more comment
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)
});
});
ios node.js express stripe-payments payment
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
|
show 1 more comment
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)
});
});
ios node.js express stripe-payments payment
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
ios node.js express stripe-payments payment
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
|
show 1 more comment
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
|
show 1 more comment
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!
add a comment |
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!
add a comment |
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!
add a comment |
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!
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!
answered Nov 8 at 17:16
koopajah
14k74680
14k74680
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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