problems getting ActiveMerchant PayPal Gateway to work on rails 3 - ruby-on-rails

I am trying to get PayPal Gateway to work on a rails 3 app.
But I keep hitting this error "uninitialized constant ActiveMerchant::Billing::PayPalGateway (NameError)"
I've this in my development.rb:
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::PayPalGateway.new(
:login => "API USERNAME ",
:password => "API PASSWORD",
:signature => "API SIGNATURE"
)
Please help!

Your capitalisation is wrong. Try:
ActiveMerchant::Billing::PaypalGateway

Related

Authorize.net in Rails - User Authentication failed due to invalid authentication values

I am building a client's ecommerce website. I'm at the latest stages, where I have to integrate the payment system. I signed up for a developer account for Authorize.net in order to test the system. I've ran into a roadblock here
I submitted my payment form, and found the following in my Development Logs
User authentication failed due to invalid authentication values
I set up my gateway as followed, based on my login information to Authorize.net
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "mylogin",
:password => "mypassword",
:test => false
)
Apparently, I'm missing something, but I'm not sure what it is. I watched the RailsCasts videos 144 and 145. I just substituted the gateway to AuthorizeNetGateWay.
Where am I going wrong here?
Here is my development.rb file
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "mylogin",
:password => "mypassword",
#:signature => "AGjv6SW.mTiKxtkm6L9DcSUCUgePAUDQ3L-kTdszkPG8mRfjaRZDYtSu"
:test_requests => false
)
end
Could the problem be ActiveMerchant::Billing::Base.mode = :test considering this is my Development Environment file?
If you're using a developer account set test to true to use the developer server:
:test => true

Rails ActiveMerchant - Paypal Express Checkout Error

I am getting this error when I call this code.
response = EXPRESS_GATEWAY.setup_purchase(order.price_in_cents,
:ip => request.remote_ip,
:return_url => url_for(:action => :create, :only_path => false),
:cancel_return_url => root_path
)
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
Error:
This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow.
To show I setup EXPRESS_GATEWAY correctly. code development.rb file.
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => '*****************************',
:password => '*************',
:signature => '*******************************************************'
}
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
Gem file
gem 'activemerchant', :require => 'active_merchant'
So the login, password, and sig. were created in the sandbox are of paypal. So they should be working.
What should I try to get this error fixed. Or is this Paypal's side? Is there something wrong in the ActiveMerchant gem?
UPDATE 1
After inspecting the response var, this is what I get.
#<ActiveMerchant::Billing::PaypalExpressResponse:0x00000102402790 #params={"timestamp"=>"2012-06-29T01:30:18Z", "ack"=>"Failure", "correlation_id"=>"d1cb5dbb30425", "version"=>"72", "build"=>"3067390", "message"=>"CancelURL is invalid.", "error_codes"=>"10472", "Timestamp"=>"2012-06-29T01:30:18Z", "Ack"=>"Failure", "CorrelationID"=>"d1cb5dbb30425", "Errors"=>{"ShortMessage"=>"Transaction refused because of an invalid argument. See additional error messages for details.", "LongMessage"=>"CancelURL is invalid.", "ErrorCode"=>"10472", "SeverityCode"=>"Error"}, "Version"=>"72", "Build"=>"3067390"}, #message="CancelURL is invalid.", #success=false, #test=true, #authorization=nil, #fraud_review=false, #avs_result={"code"=>nil, "message"=>nil, "street_match"=>nil, "postal_match"=>nil}, #cvv_result={"code"=>nil, "message"=>nil}>
Any feedback is appreciated.
UDPATE 2
Turns out after looking at that message above, it was the cancelURL that was invalid, so I fixed that and presto!
Thanks.
This error is shown when you are not properly logged into the sandbox account on paypal's site.
Login to http://sandbox.paypal.com/
Open your site and checkout
When sent to paypal, login as one of your buyer test accounts

SendGrid on Heroku fails

I setup send grid starter for my heroku app.
I put this in my config/environment.rb:
ActionMailer::Base.smtp_settings = {
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:domain => "my-sites-domain.com",
:address => "smtp.sendgrid.net",
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
I create this class models/notifier.rb:
class Notifier < ActionMailer::Base
def notify()
mail(
:to => "my-email#gmail.com",
:subject => "New Website Contact",
:body => "body",
:message => "message",
:from => "website#my-sites-domain.com"
)
end
end
I put this in another controller to send the email:
def contact
Notifier.notify().deliver
redirect_to("/", :notice => "We Have Received Your Request And Will Contact You Soon.")
end
When I deploy and try to send an email I get this error:
Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password
I have setup send grid completely and it says I am ready to send emails.
I also ran heroku config --long to get the actual password and user name and hard coded them and that still gave me the same error.
RoR + SendGrid + Heroku:
I came across similar problem where I kept receiving this error
Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password when I was trying to send email.
I tried
username with which I signed up with sendgrid, and
also the one heroku generated (when I commissioned the addon).
Answer is very simple.
DO not use any username. It is simple text 'apikey' and for password use the generated API key that you got from Dashboard.
More here #
https://support.sendgrid.com/hc/en-us
What is my SMTP Username and Password?
We recommend using "apikey" for your SMTP username and creating an API Key to use for your password. For more information, click here.
https://sendgrid.com/docs/for-developers/sending-email/integrating-with-the-smtp-api/
I had tried to set my password with the command:
heroku config:add SENDGRID_PASSWORD=my-new-password
But it turns out this only changes what heroku has stored as your password, it doesn't actually change your password. You also cannot retrieve your password after doing this.
What I had to do was remove and re-add the sendgrid add on.

PayPal error: This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow

I was trying to implement paypal payment gateway.
But I am getting an error:
This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow.
In Gem File
gem 'activemerchant', :require => 'active_merchant'
In development.rb
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => "************",
:password => "************",
:signature => "************",
}
::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
Sample code I am using in my controller
response = EXPRESS_GATEWAY.setup_purchase(10000,
:ip => request.remote_ip,
:return_url => new_order_url,
:cancel_return_url => orders_url
)
p response
p response.token
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
O/p for response:
#<ActiveMerchant::Billing::PaypalExpressResponse:0x007f90bbababa0 #params={"timestamp"=>"2011-12-17T21:41:21Z", "ack"=>"Failure", "correlation_id"=>"c152e1862f475", "version"=>"62.0", "build"=>"2271164", "message"=>"Security header is not valid", "error_codes"=>"10002", "Timestamp"=>"2011-12-17T21:41:21Z", "Ack"=>"Failure", "CorrelationID"=>"c152e1862f475", "Errors"=>{"ShortMessage"=>"Security error", "LongMessage"=>"Security header is not valid", "ErrorCode"=>"10002", "SeverityCode"=>"Error"}, "Version"=>"62.0", "Build"=>"2271164"}, #message="Security header is not valid", #success=false, #test=true, #authorization=nil, #fraud_review=false, #avs_result={"code"=>nil, "message"=>nil, "street_match"=>nil, "postal_match"=>nil}, #cvv_result={"code"=>nil, "message"=>nil}>
o/p for response.token
nil
So I think the problem is response.token is nil
any suggestions why this is happening?
Probably the first thing you checked but are the login, password and signature the ones for the sandboxed user and not your own login to the sandbox. You need to log in to the sandboxed users account and the get the signature from in there.
So when you log into sandbox.paypal.com and then go to Test Accounts, select the one you want the details for and press Enter Sandbox Test Site. In the new window enter the details for the fake user (email should be prefilled). Once logged in go to Profile -> API Access and request or view the API signature.
Sorry if you've already tried this but I couldn't post a comment to ask ;)

Fail:(TESTMODE) Transactions of this market type cannot be processed on this system

I have created a test account with Authorize.net and am using ActiveMerchant to process
credit card payments for a website. What error I always get is Error#*87 - "Transactions of this market type cannot be processed on this system" mentioned in ActiveMerchant documentations. Any suggestions how to resolve this error ?
Following is how i created my gateway. I also checked gateway.test? and it returns true.
gateway = ActiveMerchant::Billing::Base.gateway(:authorized_net).new(
:login =>'API Login ID',
:password =>'Transaction Key',
:test => true)
Try
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => 'API Login ID',
:password => 'Transaction Key',
:test => true)

Resources