IkoroVictor / paystack-ruby

A ruby gem for easy integration of Paystack.
MIT License
31 stars 28 forks source link

RestClient::BadRequest (400 Bad Request): #13

Closed galonge closed 6 years ago

galonge commented 7 years ago

Hi, i am getting a consistent (400 - Bad Request Error) on the initializeTransaction function. i am initializing in my controller. see screenshot.

screen shot 2017-05-15 at 3 40 54 pm

paingha commented 7 years ago

I experience same when trying to setup subscription. Did you by chance find a fix?

galonge commented 7 years ago

Hello @paingha , There are two basic things i did that helped me resolve this.

  1. Make sure all environment variables are set in production. i.e. if you are getting this error in production. you can use the "figaro" gem to set this. see here

  2. Restart your server and try again.

My observation: I think there is a time frame for each call to the initialize transaction method. calling it more than once for an auth url within that time frame can give you the "Bad Request" error. So, try and ensure you are not having multiple calls to the initialize transaction method within a few seconds and you should be good.

This is just my observation and you can try it as a temporary solution to this until we get a permanent solution or an update.

Regards :)

paingha commented 7 years ago

Hi @wayneskillz thanks for the reply. I still get some errors I haven't used paystack before do you think you can help me take a look at my subscription controller, please. I will really appreciate it. https://github.com/paingha/subscriptions

galonge commented 7 years ago

Okay @paingha. No problem

galonge commented 7 years ago

Can you specify what errors exactly you are getting @paingha

paingha commented 7 years ago

@wayneskillz I get a bad request sometimes and sometimes a 404 http client not found

galonge commented 7 years ago

@paingha, a 404 error means your app cannot communicate with the paystack server. This is possible if you have poor or bad network connection.

I took a look at your subscriptions controller. The only possible reason i see for you to get the Bad request error is if your paystack keys are not properly initialized. How are you setting this keys in your app. can you specify how you did set them?

paingha commented 7 years ago

Hi @wayneskillz I have environment variables setup in Heroku environment variables. Customer creation method works well just subscription and new transaction method gives an error. The new customer method is in my user model. And that works fine.

galonge commented 7 years ago

@paingha , you said you have them setup on heroku. did you set them locally too? send me an email "georgedelson@gmail.com" i may need to do a remote session with you to help resolve this.

dev-men commented 6 years ago

@paingha did Your issue is resolved? I'm also getting the same error. Creating a customer works fine. But can't commit the transaction. @wayneskillz can You help please?

galonge commented 6 years ago

@dev-men can you share your repo with me so i can take a look at your code. email me at "georgedelson[at]gmail.com

paingha commented 6 years ago

@dev-men Hi yes the issue was resolved. This is an example of how I ended up implementing it https://github.com/paingha/subscriptions

eyewritecode commented 5 years ago

In case you land here having the same Issue, Just know that this is a common error that happens when your environment variables are not "set".
I put this in quotes because you might have set it but not available in the current terminal session! You can check if the ENV KEY is available with:

printenv <yourenvkey>

if you get nothing then it means you need to readd it or just put it in your bash files

oomis commented 2 years ago

@dev-men I'm also getting the same error. Creating a customer works fine. But can't commit the transaction. Can you help, please?

oomis commented 2 years ago

I was able to fix it by ensuring the email address is valid