Skip to content
This repository has been archived by the owner on Nov 29, 2019. It is now read-only.

After returning from PayPal, Validation fails, "State can't be blank" #58

Closed
patrickmcelwee opened this issue May 14, 2012 · 9 comments
Closed

Comments

@patrickmcelwee
Copy link

I have a customer in Germany who successfully goes to PayPal and completes the order there, but upon returning to our site, she gets redirected to her cart, which still has a "payment" state and looks full to her.

In production.log, on the return from PayPal, an Unprocessable Entity error is raised because an ActiveRecord validation (that state can't be blank) fails:

Started GET "/orders/R625114217/checkout/paypal_confirm?payment_method_id=5&token=EC-XXXXXXXXXXXXXXX&PayerID=XXXXXXXXXXXXX" for 217.xx.xxx.xxx at 2012-05-09 23:08:46 +0000
  Processing by CheckoutController#paypal_confirm as HTML
  Parameters: {"payment_method_id"=>"5", "token"=>"EC-XXXXXXXXXXXXXXXXX", "PayerID"=>"XXXXXXXXXXXXX", "order_id"=>"R625114217"}
Completed 422 Unprocessable Entity in 1038ms

ActiveRecord::RecordInvalid (Validation failed: State can't be blank):

I assume that the state in question is the one in the address, not the one in the state_machine. But my customer has an entry for :state_name in both billing and shipping addresses associated with her order.

One other thing is that PayPal gives me no record of the transaction in my history. I am running Spree 0.70.5.

@kennyadsl
Copy link

Same issue here. Have you already solved this problem?

@kennyadsl
Copy link

The missing "State" attribute refers to address, not to a state machine model. Looking deeper...

@patrickmcelwee
Copy link
Author

I upgraded to 1.0 and was hoping it might solve the issue, which I have only seen with one customer. One problem is that I can't reproduce the error. Later today, I will take a look at my production logs to see if the issue has recurred.

@patrickmcelwee
Copy link
Author

The issue has recurred ... this time with a customer from Norway.

It looks to me that the error must be raised when the checkout controller assigns the returning PayPal address to @order.ship_address and then tries to save it.

One way to fix would be to check whether the returning state is blank, and if so, to skip changing the ship_address.

Actually, I think my preferred solution would be to eliminate the overwriting of the Spree shipping address altogether. In my experience, the Spree address is more likely to be correct, since they must enter it at the time of order - while it is more difficult to change a PayPal address, which is stored over a longer period of time. Or, at least, if we are going to override what they entered, we should ideally give them the opportunity to confirm that.

@kennyadsl
Copy link

Ok, so setting "No shipping" via admin interface will solve the issue.

@ghost
Copy link

ghost commented Feb 26, 2013

I have this issue today ... but it happens only when selecting credit card in Paypal account ..
If user select his Paypal account , processing return is OK
see logs in gist : https://gist.github.com/erwin/5037469

It seems that using CreditCard in Paypal is returning user infos ( address ) without the 'state' info

@ghost
Copy link

ghost commented Feb 26, 2013

sorry I may have posted in the wrong git .. should have posted it in Spree .. but it's related ...

@jumph4x
Copy link

jumph4x commented Feb 27, 2013

@kennyadsl Can you elaborate on the effects of changing No shipping?

@kennyadsl
Copy link

@jumph4x As far as I can remember ( it's a 8 months ago comment :) ) setting to No shipping will prevent PayPal to pass address data to spree or viceversa.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants