0

I have been following this tutorial

http://railscasts.com/episodes/146-paypal-express-checkout?autoplay=true

I have put paypal button in cart page

<%= link_to(image_tag("https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"), express_checkout_path) %>

My express checkout method looks as follows

def express_checkout
  response = EXPRESS_GATEWAY.setup_purchase(1000,

    ip: request.remote_ip,
    return_url: cart_item_index_path,
    cancel_return_url: cart_item_index_path,
    currency: "USD",
    allow_guest_checkout: true,
    items: [{name: "Order", description: "Order description", quantity: 1, amount: 1000}]

  )

  puts "printing token #{response.token}"


  redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end

when i print the response.token then it prints empty string. Also when i run the app and click on paypal button then it redirects to

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=

with the following error

No token passed

I am using activemerchant gem in rails.

Shiko
  • 2,448
  • 1
  • 24
  • 31
kofhearts
  • 3,607
  • 8
  • 46
  • 79

1 Answers1

0

ok. byebug saved the day.

I checked the errors in response object and noticed that return url and cancel url were invalid paths.

so i changed

response = EXPRESS_GATEWAY.setup_purchase(1000,

    ip: request.remote_ip,
    return_url: cart_item_index_path,
    cancel_return_url: cart_item_index_path,
    currency: "USD",
    allow_guest_checkout: true,
    items: [{name: "Order", description: "Order description", quantity: 1, amount: 1000}]

  )

to

response = EXPRESS_GATEWAY.setup_purchase(1000,

    ip: request.remote_ip,
    return_url: cart_item_index_url,
    cancel_return_url: cart_item_index_url,
    currency: "USD",
    allow_guest_checkout: true,
    items: [{name: "Order", description: "Order description", quantity: 1, amount: 1000}]

  )

and it worked! thanks byebug!

kofhearts
  • 3,607
  • 8
  • 46
  • 79