activemerchant PayPalExpress transaction is invalid

Posted by Ameya Savale on Stack Overflow See other posts from Stack Overflow or by Ameya Savale
Published on 2014-06-02T01:05:05Z Indexed on 2014/06/02 3:26 UTC
Read the original article Hit count: 260

I am trying to integrate activemerchant into my ruby on rails application. This is my controller where I get the purchase attirbutes and create a PaypalExpressResponse object

def checkout
    total_as_cents, purchase_params = get_setup_params(Schedule.find(params[:schedule]), request)
    setup_response = @gateway.setup_purchase(total_as_cents, purchase_params)
    redirect_to @gateway.redirect_url_for(setup_response.token)
end

@gateway is my PaypalExpressGateway object which I create using this method in my controller

def assign_gateway
            @gateway = PaypalExpressGateway.new(
                    :login => api_user,
                    :password => api_pass,
                    :signature => api_signature
                )
        end

I got the api_user, api_pass, and api_signature values from my developer.paypal.com account, when I logged in for the first time there was already a sandbox user created as a merchant which is where I got the api credentials from.

And finally here is my get_setup_params method:

def get_setup_params(schedule, request)
        purchase_params = {
            :ip => request.remote_ip,
            :return_url => url_for(:action => 'review', :only_path => false, :sched => schedule.id),
            :cancel_return_url => register_path,
            :allow_note => true,
            :item => schedule.id
        }
        return to_cents(schedule.fee), purchase_params
    end

How ever when I click on the checkout button, I get redirected to a sandbox paypal page saying

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

I'm not sure exactly what's wrong, I think the problem lies in the credentials but don't know why. Any help will be appreciated. One other point, I'm running this in my development environment so I have put this in my config file

  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
  end

UPDATE

Found out what the problem was, my return cancel url was invalid instead of using register_path, I used url_for(action: "action-name", :only_path => false) this answer helped me Rails ActiveMerchant - Paypal Express Checkout Error even though I wasn't able to see the output of the response like the person has managed to do

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activemerchant