Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Silent failure after payment #153

Closed
mntmn opened this issue Feb 26, 2018 · 7 comments
Closed

Silent failure after payment #153

mntmn opened this issue Feb 26, 2018 · 7 comments

Comments

@mntmn
Copy link

mntmn commented Feb 26, 2018

I'm locally testing solidus_paypal_braintree and configured a payment method to use my Braintree sandbox account which in turn is linked to the Paypal sandbox.

I then add a product to my cart and click the "Paypal Check out" button. I log in with my sandbox account, which is based in Germany, and pay for the order. Then, the paypal popup window closes and nothing happens on the cart page.

When running web inspector, I can see that the request to /solidus_paypal_braintree/transactions failed with error 422:

{errors: {Address: ["is invalid"], address: ["spree_state can't be blank"]}, status: 422}

But no error message is displayed to the (fake) customer.

The parameters submitted where:

Processing by SolidusPaypalBraintree::TransactionsController#create as JSON
  Parameters: {"payment_method_id"=>"4", "transaction"=>{"email"=>"[email protected]", "nonce"=>"03485389-9766-0c0a-7883-a095b3e72f0e", "payment_type"=>"PayPalAccount", "address_attributes"=>{"first_name"=>"test", "last_name"=>"buyer", "address_line_1"=>"ESpachstr. 1", "city"=>"Freiburg", "state_code"=>"Empty", "zip"=>"79111", "country_code"=>"DE"}}}

In Germany, states are not relevant/normally not included in addresses. This might trigger the spree_state problem. But this bug report is more about the silent failure. Is there a workaround to at least show the error to the customer?

@alepore
Copy link
Contributor

alepore commented Mar 1, 2018

Yes, you have to set states_required: false on Germany to make it work.
This is actually a problem of the Solidus data and we are thinking about a clean, long term solution.

I have to check what we do with error messages but, in this case, this is not an error the user can fix himself anyway.

@mntmn
Copy link
Author

mntmn commented Mar 2, 2018

OK, thanks for that bit of info. Maybe it's the wrong place to ask here, but do you know why 150 of the countries in the DB have that field set to true as a default? I'm aware of only a few countries requiring the State as part of an address. (example https://webmasters.stackexchange.com/a/3228)

@mntmn
Copy link
Author

mntmn commented Mar 2, 2018

After changing the flag, the error 422 persists but turns into

{"errors":{"Address":["is invalid"]},"status":422}

Probably because it tries to validate Paypal's "Empty" State and can't find it. This is problematic because the user has no chance to know what is going on, if they have a typo in their address... even a javascript alert with the error message would help.

@mntmn
Copy link
Author

mntmn commented Mar 2, 2018

FWIW I managed to work around the validation problems by doing the following steps. Maybe its useful to someone if they find this bug. It was stumbling not only over the state, but also over a missing phone number.

Spree::Country.update_all(:states_required => false)
Spree::Country.where(:iso3 => ["USA","CAN","AUS","CHN","MEX","ITA","MYT"]).update(:states_required => true).size

Adding this switch in config:
config.address_requires_state = false

And adding this override module:

module Spree
  module OptionalPhoneAddress
    # require_phone?
    #   - no longer require a phone
    #   - a * no longer appears next to phone in the view
    #
    def require_phone?
      false
    end

    # validate_state_matches_country
    #   - apply the same early returns as in state_validate
    def validate_state_matches_country
      return if country.blank? || !Spree::Config[:address_requires_state]
      return unless country.states_required

      if state && state.country != country
        errors.add(:state, :does_not_match_country)
      end
    end
  end
end

@seand7565
Copy link
Contributor

It's true that German should not be set to states_required by default. I've created an issue on Solidus to fix this: solidusio/solidus#3803

@kennyadsl
Copy link
Member

Thanks Sean!

@MrFehr
Copy link

MrFehr commented Jan 14, 2021

Does anyone know how to fix this for UK sites? Our shipping page calculates their rate depending on their state so it's quite important

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

5 participants