I'm using Rails 3.1 and ActiveMerchant 1.17
I'm calling the PaymentExpress gateway, using the correct test credit card details. However, it keeps giving some form of invalid response.
The most I can make out is that the response.params array contains
{"re_co"=>"Zz", "response_text"=>"Error in getting response.", "success"=>"0"}
This is using the local rails server.
I have a hunch that it may be to do with the SSL verify_peer option, though I have no way of proving that, and I have no idea how to configure that option.
This is my code, fairly standard stuff:
credit_card = ActiveMerchant::Billing::CreditCard.new(params[:credit_card])
gateway = ActiveMerchant::Billing::PaymentExpressGateway.new(:login => APP_CONFIG[:dps_username], :password => APP_CONFIG[:dps_password])
response = gateway.authorize total_cents, credit_card
Interestingly, it seems to work fine from the rails console. Are there any steps I should be taking to debug this?
Ok, it turns out the problem wasn't to do with ActiveMerchant at all.
I should have been using
APP_CONFIG['dps_username']
instead of
APP_CONFIG[:dps_username]
Ahh, the simple problems
Related
I am trying to use the ShopifyAPI::GraphQL from the shopify_api gem, which seemed to work fine in my local environment, but I am having problems in my Heroku environment.
The first error seemed to be related to a bug in the shopify_api gem and was fixed by setting the api version i.e. ShopifyAPI::Base.api_version = "2019-10" (even though it was already set in the config/initializers/shopify_app.rb with config.api_version = "2019-10").
Moving on I get the following error when starting the server in the Heroku environment:
NoMethodError: undefined method `path=' for nil:NilClass
info /app/vendor/bundle/ruby/2.5.0/gems/shopify_api-8.1.0/lib/shopify_api/resources/graphql.rb:10:in `initialize'
Looking at the lines in the graphql.rb file from shopify_api that fails:
uri = Base.site.dup #line 9
uri.path = Base.api_version.construct_graphql_path #line 10
it seems to be caused by the fact that Base.site is nil, which makes sense as there is no session at the time the server is started.
As far as I can see, the graphql queries need to be constants, and as they refer the graphql client, I instantiate the graphql client as a class parameter:
##client = ShopifyAPI::GraphQL.new
The above line seem to be initialized during server start (I am very new to rails), and as mentioned the error occurs because there is no session and hence no site at the time.
So I must be using the graphql component wrong. My question is, how am I supposed to use the class ShopifyAPI::GraphQL? Where should I e.g. place the ShopifyAPI::GraphQL.new code?
Or to make the question more general - the graphql-client requires the queries and thus the graphql client ShopifyAPI::GraphQL to be defined as constants. How do I prevent the constants from being initialized during server startup, as the there is no session at server startup which is required when initializing the graphql client?
Thanks,
-Louise
Since upgraded to Ruby 2.2.0 I get the following message in my tests:
invalid salt (BCrypt::Errors::InvalidSalt)
I didn't find any upgrade notice helping me to understand the problem. I'm using Rails 4.1.8 and Sorcery 0.8.6.
Anybody else having this problem?
MORE Details:
I'm using Sorcery and not Devise. The encrypted data is the password.
It all started in Cucumber tests, in 2 cases:
When I used to send the #user to the mailer to prepare the data for the mails. Here was the code:
UserMailer.passphrase_reset_notification(#user).deliver
Which generated the exception with the message I wrote in the initial message. As a workaround instead of sending the #user I sent the fields I needed and it worked. Here's the new code:
UserMailer.passphrase_reset_notification(#user.name, #user.email).deliver
But the second case is the sign up. It failed in dev and I had to add :salt to user_params to fix it. But it does not fix the thing in the test env.
There's no stack trace, just that one liner message with the lines of my scenario leading to the error.
And I press "Sign up"
invalid salt (BCrypt::Errors::InvalidSalt)
./app/controllers/users_controller.rb:66:in block in create'
./app/controllers/users_controller.rb:64:increate'
./app/controllers/application_controller.rb:120:in scope_current_tenant'
./features/step_definitions/web_steps.rb:53:in/^(?:|I )press "([^"]*)"$/'
features/users/sign_up.feature:149:in `And I press "Sign up"'
I removed the "null: false" for the field "salt" in the user table, as suggested by a community member in a post on a more or less similar issue, it didn't help either.
My main question is still the same: what the Ruby new version (2.2.0) has to do with this? And what might be the other surprises if I upgrade the prod?
I just fixed this. Turned out it had to do with serializing an object with has_secure_password (which uses bcrypt-ruby)
More specifically, something like the following was causing the issue with Sidekiq as it tried to serialize arguments into objects for Redis queueing.
#user = User.new(
:firstname => 'Scott',
:lastname => 'Klein',
:password => 'mypass',
:password_confirmation => 'mypass'
)
#user.save!
# broken
# note that #user.password can still be called here
# and sidekiq will attempt to serialize this whole object using YAML
# and this is the serialization issue that barfs (in the depths of YAML)
UserMailer.delay.new_user_signup(#user)
# fixed
# i just passed the id and then recalled the user record in the mailer class
UserMailer.delay.new_user_signup(#user.id)
I've had similar problem. Investigation made me conclude that it's bcrypt not playing well with Psych (that's the Ruby system library for generating and parsing YAML).
There's an open bcrypt issue now. Waiting for gem author to fix it.
** FIXED **
The problem, at least mine, is fixed. I just upgraded the bcrypt gem from 3.1.
9 to 3.1.10 and it was it! Thanks Oleg to have created an issue on bcrypt account.
Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)
I'm working through the railsapps.org book on learning rails I have finished implementing the mailchimp email list code, and when I press submit on my form, I get the following error:
URI::InvalidURIError at /visitors
the scheme https does not accept registry part: us8'.api.mailchimp.com (or bad hostname?)
My debug screen seems to indicate that it's failing at the call
result = mailchimp.lists.subscribe({
:id => Rails.application.secrets.mailchimp_list_id,
:email => {:email => self.email},
:double_optin => false,
:update_existing => true,
:send_welcome => true
})
I have my API key and List IDs both hard coded into secrets.yml, so I know they are correct.
Any ideas?
Regards,
Jeff
The error message indicates that the URL used to contact the Mailchimp server is malformed.
The Gibbon gem constructs the HTTPS request to the Mailchimp server and uses the httparty gem to make the HTTPS request. We can be confident that Gibbon works as expected. You can check the Gibbon issues to confirm; I just did and saw no reported problems like yours.
So we know Gibbon is working, and we can presume the code from the learn-rails tutorial application works (because no one else has reported this problem). So what can be the cause of the problem? My guess is that your API key is incorrect. It may have an extra single quote that does not belong. I'm guessing that something about the API key is preventing Gibbon from forming a correct URL string.
You can diagnose by entering a correctly formatted but wrong API Key. Instead of the URL error should get a response from the Mailchimp server that your API key is not known.
I am trying to use an OmniAuth (0.2.6) strategy for my application. The architecture is Rails 2.3.10 and Rack is version is 1.1 (this version or higher is required for OmniAuth). A problem that occurs is Rails doesn't recognize my redirect to "/auth/provider". The actual error message is "No route matches "/auth/casport". Even though that error gets thrown, the code seems to execute past that point up to this error: "request.env['omniauth.auth']", which I'm pretty sure means it doesn't recognize the "omniauth.auth" key for the env hash. I have a feeling that OmniAuth isn't being loaded properly. I've tested the same strategy and code base with Mongrel and Webrick, and I get identical error messages.
Here is my OmniAuth initializer (config/initializers/omniauth.rb):
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider :casport, :setup => true
end
I definitely have routes in places for auth/casport/setup and auth/casport/callback.
I've also tried this approach: How do you implement OmniAuth on Rails 2.2?
config.middleware.use OmniAuth::Builder do
provider :casport, :setup => true
end
by placing that middleware code in the config/environments/development.rb file.
Does anyone have any thoughts on what I could be doing incorrectly? Thanks!
Edit: I've also tried this approach Has anyone used omniauth with rails 2.3.8?
ActionController::Dispatcher.middleware.use OmniAuth::Strategies::Casport = {
:setup => true
}
and that returns a read error: "NoMethodError: undefined method 'new' for #Hash...
Edit 2: I've upgraded to Rails 2.3.10 as OmniAuth isn't compatible with Rails 2.3.4.
I created an issue on OmniAuth's Github page https://github.com/intridea/omniauth/issues/397, with the above details and this is the response from Michael Bleigh, the creator of OmniAuth:
"OmniAuth has never officially supported Rails 2.3.x -- I've heard that some people have had luck with it but it's not something that is guaranteed. Sorry!"
So it looks like the methods I posted above may work for some folks. To guarantee correct operation, Rails 3 is needed.
Why would I get NoMethodError on my Heroku app when the same code works flawlessly on my local setup?
The error is triggered by this code:
#customer = Customer.find(1)
#customer.responses.create(:offer_id => '1', :digit => '2')
That code works as intended on my local server and in my local Rails console.
However, on Heroku the above code triggers NoMethodError:
NoMethodError (undefined method `responses' for #<Customer:0x7f7bcbee3808>):
The Response model is tied to the Customer model by means of belongs_to :customer
Additionally, I can login to the Heroku console and run this without any problems:
Response.create(:offer_id => '1', :customer_id => '1', :digit => '2')
So if the above works and both versions work fine on my local box, why would the association fail on Heroku?
--
Running Rails 3.0.6 and tested on Heroku Ruby 1.8.7 and Ruby 1.9.2
Databases are identical on Heroku and on my local box.
Usually when something like this doesn't work it indicates you're missing a has_many association. You need to define both the belongs_to and has_many sides of the association if you wish to access them both.
By the sounds of it, if it's working on your local machine but not Heroku then it would be because you haven't pushed the changes to the Heroku server and restarted the console there. Please make sure you have pushed the changes and try again.
Marco, I thought about this a bit, and I have a few guesses for you to try. Before you do either of these, restart your app. Sometimes that does miracles.
heroku restart
Ok, now, try in console just
#customer.responses
What does that return? I assume it should be []. Maybe doing some inspection etc. of that can give us insights here. If you build and associate a response manually can you get it to show up?
Second, your no method error is on responses, not on create, so whatever you type after that probably doesn't matter, BUT, are your offer_id and digit fields integers? If so, try creating them using integers, not strings. PostgreSQL is so fragile compared to MySQL or SQLite, I've had loads of issues that trace back to my unfamiliarity working with Postgre prior to developing on Heroku.
#customer.responses.create(:offer_id=>1,:digit=>3)
That probably doesn't matter but it's worth checking out.
The other thing to check is all your callbacks and validations etc. Is anything failing? It may not seem related but I've had issues before where things acted very weird because of seemingly tiny silent failures in a callback that I had overlooked. I'm sure you're testing as you go, but if you've got shallow test coverage anywhere on this model you might as well use this bug hunt as a chance to beef it up :)
Sympathies on the error, I don't know if any of this will help, but good luck! Please post if Heroku staff find the issue, I'd be very interested to learn from it!
I think you problem is how you are creating the response:
#customer.responses.create(:offer_id => '1', :digit => '2')
You might want to try this instead.
Response.create(:offer_id => '1', :digit => '2', :customer_id => 1)