solidus_stripe
solidus_stripe copied to clipboard
Single page checkout doesn't work with v3 form elements
👋 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
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.
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.