woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
258 stars 108 forks source link

Error loading orders (Swift.DecodingError) caused by invalid URL string for payment_url #9683

Closed rachelmcr closed 1 year ago

rachelmcr commented 1 year ago

Describe the bug

While investigating the new reports of errors loading the orders list in https://github.com/woocommerce/woocommerce-ios/issues/5512, I encountered this decoding error on a test store while trying to load the Orders tab:

⛔️ Error synchronizing orders: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "data", intValue: nil), _JSONKey(stringValue: "Index 6", intValue: 6), CodingKeys(stringValue: "payment_url", intValue: nil)], debugDescription: "Invalid URL string.", underlyingError: nil))

This seems to be caused by orders for subscription products (e.g. WooCommerce Subscriptions extension) with payment URLs like this: https://example.com/checkout/order-pay/573/?pay_for_order=true&key=wc_order_abcde12345&subscription_renewal=true

Those URL strings include HTML-encoded ampersands (&) which aren't valid for creating URLs.

rachelmcr commented 1 year ago

I might be wrong about the Subscriptions extension being the cause. I thought it was related to the change in https://github.com/woocommerce/woocommerce-subscriptions/pull/4510, released in version 5.1.0 of the extension. However, that was reverted in https://github.com/woocommerce/woocommerce-subscriptions/pull/4522, released in version 5.1.1, and I'm still seeing this issue on a store using that latest release.

I'll continue investigating the cause tomorrow to see if I can pinpoint where it's coming from (so we can fix the problem at its source). If we need to, we could also try to fix this in the app by decoding HTML in the URL string first, but that's not ideal given that we wouldn't expect that encoding in the first place.

rachelmcr commented 1 year ago

@Jinksi @mattallan Do either of you know why this encoding would still be happening on a site running WooCommerce Subscriptions 5.1.1? In this case the store is hosted on WordPress.com, so I'm not sure if there's something different with how the extension is hosted/managed that might cause this issue to persist there when it's not happening on other stores with the same version.

reginabally commented 1 year ago

Adding the reports I came across so far. All of these sites have WooCommerce Subscriptions installed and activated.

mattallan commented 1 year ago

Hey @rachelmcr, thanks for the ping and sorry about this issue! Subscriptions 5.1.1 only patched a portion of these problems and we're currently reviewing and merging more fixes which will come in the next release (today or tomorrow)

Here's the PR which should fix the issues you're seeing: https://github.com/Automattic/woocommerce-subscriptions-core/pull/440

mattallan commented 1 year ago

Hey @rachelmcr @reginabally we have just released WooCommerce Subscriptions 5.1.2 which should fix these issues.

reginabally commented 1 year ago

Thank you for the quick fix, @mattallan! We'll inform the users to update the extension once it's available to be downloaded.

rachelmcr commented 1 year ago

Thank you for the quick fix, @mattallan! I confirmed that the 5.1.2 release resolves the issue I was seeing with the payment_url in the app.

reginabally commented 1 year ago

I'm reopening this issue because I've seen other cases where merchants use the built-in subscriptions feature in WooCommerce Payments. They don't have WooCommerce Subscriptions extension on their sites.

Sample URL:

.../checkout/order-pay/1799/?pay_for_order=true&key=wc_order_c1ma6h1unh1Ok&subscription_renewal=true

Hi @mattallan Will the fix in https://github.com/Automattic/woocommerce-subscriptions-core/pull/440 be merged to WooCommerce Payments since this is related to subscriptions?

jhnstn commented 1 year ago

Another report:

Jinksi commented 1 year ago

@reginabally WooCommerce Payments 5.9.0 has just been released which includes subscriptions-core 5.7.1 and this fix you've mentioned in your comment: https://github.com/Automattic/woocommerce-subscriptions-core/pull/440 👍

reginabally commented 1 year ago

Awesome! Thank you so much @Jinksi!

I'll keep this open for now until we hear back from the merchants.

rachelmcr commented 1 year ago

@reginabally It looks like we haven't heard back from these merchants in the past couple of weeks, so I'm going to go ahead and close this issue as resolved. If we do hear back from anyone with further concerns about this, please feel free to reopen the issue!