Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single page checkout doesn't work with v3 form elements #112

Open
seand7565 opened this issue Jun 29, 2021 · 2 comments
Open

Single page checkout doesn't work with v3 form elements #112

seand7565 opened this issue Jun 29, 2021 · 2 comments
Labels
v4.x Issues and PRs targeting the classic frontend (before v5)

Comments

@seand7565
Copy link

👋 Hey all!

v3 form elements don't work with single page checkouts. It requires a billing_address, and that is set on pageload from the orders existing billing address.

On single page checkout for a new customer, a new billing address is usually built on pageload, but it is not a valid address until the user fills it in - and because v3 form elements loads in the billing address on pageload, it will try to submit an invalid address as the billing address (regardless of what the user filled in), causing validation errors when on payment source creation.

Rather than the payment intent creator just using the payment source address, I think it should first look for the existence of an address in the order params, as that will be more up-to-date, and work with a single page checkout flow.

This is a prepender that fixes this issue on a clients project:

# frozen_string_literal: true

module [scrubbed_client_namespace]
  module SolidusStripe
    module CreateIntentsPaymentService
      module UseAddressParamsForPayment
        # Usually we have a billing address on the payment source in these
        # params because it is populated at pageload, however in single
        # page checkout, this mostly won't be the case. This ensures that
        # we can use the orders ship_address or bill_address params in that
        # case.
        def address_attributes
          if html_order_data["use_shipping"] == "1"
            html_order_data["ship_address_attributes"]
          elsif html_order_data["bill_address_attributes"]
            html_order_data["bill_address_attributes"]
          else
            super
          end
        end

        def html_order_data
          if form_data.is_a?(String)
            data = Rack::Utils.parse_nested_query(form_data)
            data["order"]
          else
            {}
          end
        end
      end
    end
  end
end
@seand7565
Copy link
Author

Some feedback on this from @elia that I think is valuable here:

I wish /stripe/create_intent was accepting a json instead of a serialized form-data string, the fact that this code is coupled to the form structure of the checkout with specific assumption smells really bad.

@stale
Copy link

stale bot commented Nov 11, 2022

This issue has been automatically marked as stale because it has not had recent activity. It might be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 11, 2022
@gsmendoza gsmendoza removed the stale label Nov 15, 2022
@elia elia added the v4.x Issues and PRs targeting the classic frontend (before v5) label Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v4.x Issues and PRs targeting the classic frontend (before v5)
Projects
None yet
Development

No branches or pull requests

3 participants