I have created backendless custom business logic service which uses npm module Stripe for payment.

Below is the code that does external request with stripe api using stripe npm module. This works perfectly fine in debug mode and i can see the output in my terminal. But when deployed using npm run deploy and testing the api service method, its not reaching anywhere

return stripe.charges.create({
amount: amount,
currency: "usd",
source: token,
description: description
}, function(err, charge) {
if(err){
console.log("It was an error");
console.log(err);
// return "Charging failed, sorry";
// return err;
}else{
console.log("It was success");
console.log(charge);
// return "charging is done, thanks";
// return charge;
}
});

To test, i removed all stripe module, just made a plain http request to google.com after adding google.com to the domains list which got instantly approved. Still its the same error. This also works perfectly in debug and fails in prodcution.

Please see the code:



return new Promise((resolve, reject) => {
  		console.log("inside promise");
			var options = {
			    url : 'https://www.google.com',
			    method: 'GET',
			    body : '',
			    auth: {
			        'user': 'sk_test_rwXpFKat6zsIloS4eGDTGfLW',
			        'pass': ''
			    }
			};


			function callback(error, response, body) {
			    if (!error && response.statusCode == 200) {
			        console.log(body.substring(0,30));
			        resolve("succedded in payment");
			    }else{
			    	console.log(response.body);
			    	reject("failed the the order");
			    }
			}
			request(options, callback);
});

Hi

See the troubleshooting guide and Sync vs Async explanation

You have to return a Promise from your event handler, which should be resolved/rejected only after you get the result of your stripe operation

Something like this :

return new Promise((resolve, reject) => {
stripe.charges.create(opts, function(err, charge) {
if (err) {
console.log("It was an error", err);
reject(new Error('Charging failed, sorry'))
} else {
console.log("It was success", charge);
resolve(charge)
}
});
})

Thanks for replying. I understand that, but the request is not even hitting the server. Please see my second comment, its a simple request to google using request module. Even that’s not working. I created that following your comment on a similar issue. can you please check if something is wrong in that ? Its perfectly working in debug mode also

just curious, have you not forgot to save required packages?

I have definitely saved the packages. When you say save, i hope you mean that it should be in dependencies - rit ?

Just try the code I wrote.

Otherwise, the CodeRunner will exit before you send any request.

Your second example looks good though

What is your applicationId ?

My Application Id is : 336ADF99-649D-1939-FF97-229D09300100

The code is still there. Awaiting a solution from you, thanks in advance

The second example (request to google.com) is the code there and google.com is added and approved as external host. Going really made over these for days :slight_smile:

Any updates ??

Hi, Abdul.
We have made a little reconfiguration.
Pleas, try again. Firstly, I recommend with simple request to make sure the requests to external hosts pass correctly.

Ok Oleg, i will try now and let you know

Oleg,

It’s still the same. Getting below error message:

{
“code”: 14005,
“message”: “Service invocation failed by timeout”
}

This is quite weird. My Application Id is : 336ADF99-649D-1939-FF97-229D09300100

For testing purpose, i have made it as a simple request to google.com and google.com is added to approved external host.

Below is the code:


return new Promise((resolve, reject) => {
			console.log("inside promise");
			var options = {
			    url : 'https://www.google.com',
			    method: 'GET',
			    body : '',
			};


			function callback(error, response, body) {
			    if (!error && response.statusCode == 200) {
			        console.log(body.substring(0,30));
			        resolve("succedded in payment");
			    }else{
			    	console.log(response.body);
			    	reject("failed the the order");
			    }
			}
			request(options, callback);
		});