6

I'm trying to set up a PayPal express checkout using active merchant but I'm running into problems. I've followed a tutorial and I can get to the "choose a way to pay" form on paypal but there are no items or prices displayed.

Here's a screenshot. http://i39.tinypic.com/35mircz.png

Why is not displaying a price or any items even though I'm passing them in? Here is the code I'm using to setup_purchase.

@product = Product.find(params[:product_id])

setup_response = gateway.setup_purchase(200,
  :ip                => request.remote_ip,
  :items => [{:name => "Tickets", :quantity => 22, :description => "Tickets for 232323", :amount => 10}],
  :return_url        => url_for(:action => 'confirm', :only_path => false),
  :cancel_return_url => url_for(:action => 'index', :only_path => false)
)

redirect_to gateway.redirect_url_for(setup_response.token)

Any help would be greatly appreciated. Alex

Alex Fox
  • 1,175
  • 2
  • 15
  • 27
  • Please could I ask what tutorial you are following? I'm going at this blindly so far and its proving difficult! – Adam Waite Jul 03 '13 at 18:01

2 Answers2

8

Your problem lies with your quantities and pricing - if you output setup_response after it does the call with something like

logger.debug setup_response

And check the log, you'll see that it's probably complaining that the price in the items is not matching up to the amount you're passing (the first value).

At the moment, you have a quantity of 22, with each 'amount' being 10. 10*22 = 220, and since you're only putting in 200 in the first value, you're mis-matching them. Fix that and you should be good to go.

Wakeuphate
  • 493
  • 3
  • 13
  • No probs, ran into that issue myself a day or two ago and it near drove me insane until I found out I could debug the response to see what I was doing wrong :) – Wakeuphate Feb 20 '12 at 12:08
  • Hey. I'm trying to solve this still.. I did what you said but it still isn't displaying items. The debugger just gave me # ?? – Alex Fox Mar 05 '12 at 11:36
  • I'm not sure if this will work correctly, but it may be worth a try - instead of `logger.debug setup_response` try `logger.debug "The object is #{setup_response.to_yaml}"` it may print it out a bit nicer to read. Debugging is not my strong point in rails yet :) – Wakeuphate Mar 06 '12 at 20:38
  • that just gives me .. authorization: avs_result: code: postal_match: street_match: message: cvv_result: code: message: fraud_review: false message: Success params: timestamp: "2012-03-09T20:01:35Z" correlation_id: 831a04c53e7f5 token: EC-2EG03962TU397403R build: "2649250" version: "59.0" ack: Success success: true test: true – Alex Fox Mar 09 '12 at 20:03
1

I have encountered the same issue and have finally found the reason, and it is unbelievably stupid. Are you ready?

There is a mismatch between the total price you specified (200) and the sum of your items (22*10=220). If you change your quantity to 20, it will work. Paypal requires that the sum of your items' cost would equal the total price you specify. I have no idea how I realised this.

lior
  • 537
  • 4
  • 13