{"action":"created","issue":{"url":"https://api.github.com/repos/guardian/support-frontend/issues/525","repository_url":"https://api.github.com/repos/guardian/support-frontend","labels_url":"https://api.github.com/repos/guardian/support-frontend/issues/525/labels{/name}","comments_url":"https://api.github.com/repos/guardian/support-frontend/issues/525/comments","events_url":"https://api.github.com/repos/guardian/support-frontend/issues/525/events","html_url":"https://github.com/guardian/support-frontend/pull/525","id":299467523,"number":525,"title":"Fix - Checkout Amount Querystring Bug","user":{"login":"Ap0c","id":5131341,"avatar_url":"https://avatars3.githubusercontent.com/u/5131341?v=4","gravatar_id":"","url":"https://api.github.com/users/Ap0c","html_url":"https://github.com/Ap0c","followers_url":"https://api.github.com/users/Ap0c/followers","following_url":"https://api.github.com/users/Ap0c/following{/other_user}","gists_url":"https://api.github.com/users/Ap0c/gists{/gist_id}","starred_url":"https://api.github.com/users/Ap0c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ap0c/subscriptions","organizations_url":"https://api.github.com/users/Ap0c/orgs","repos_url":"https://api.github.com/users/Ap0c/repos","events_url":"https://api.github.com/users/Ap0c/events{/privacy}","received_events_url":"https://api.github.com/users/Ap0c/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-02-22T18:54:44Z","updated_at":"2018-02-23T11:13:13Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/guardian/support-frontend/pulls/525","html_url":"https://github.com/guardian/support-frontend/pull/525","diff_url":"https://github.com/guardian/support-frontend/pull/525.diff","patch_url":"https://github.com/guardian/support-frontend/pull/525.patch"},"body":"## Why are you doing this?\r\n\r\n### Problem\r\n\r\nOn some older browsers we've had a problem passing through the contribution amount to our checkout pages. For some reason, these browsers weren't picking up the amount from the query param in the URL, and were showing the default amount as a result. This was one of the issues dealt with in #465 for the Samsung Browser. It has subsequently shown up in older versions of Firefox.\r\n\r\n### What's going on?\r\n\r\nThis was an interesting one to track down. This screenshot explains the problem:\r\n\r\n![querystring-madness](https://user-images.githubusercontent.com/5131341/36557330-defc1b94-17ff-11e8-8b10-461e0046b253.png)\r\n\r\nThe `URLSearchParams` constructor doesn't handle querystrings that include the leading question mark `?`. This is a problem because that's what `window.location.search` returns, which is what we happen to be using in our `getQueryParameter` helper.\r\n\r\nIt seems like the spec wasn't specific as to what should happen here, and was subsequently updated to mandate that the leading `?` be handled. However, both [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1268361) and Chromium (which is what the Samsung Browser is based on) had already implemented the standard. They have both been updated to fix this, but older versions still suffer from the problem.\r\n\r\n### Solution\r\n\r\nI've switched our usages of `URLSearchParams(window.location.search)` to use `URL(window.location).searchParams` instead. By getting our URLSearchParams object via the URL interface, instead of from the URLSearchParams constructor, we sidestep the problem, as seen here:\r\n\r\n![querystring-solution](https://user-images.githubusercontent.com/5131341/36557929-7d783a72-1801-11e8-9932-4751f1e7bf8b.png)\r\n\r\nPresumably when picking apart a full URL, the `?` was usually expected, so it was handled from the start.\r\n\r\n[**Trello Card**](https://trello.com/c/xskTe9Ak/1322-ff-48-not-passing-through-contribution-amount-to-checkout)\r\n\r\n## Changes\r\n\r\n- Updated two usages of the `URLSearchParams` constructor being used in concert with `window.location.search` to use the `URL.searchParams` interface instead.\r\n"},"comment":{"url":"https://api.github.com/repos/guardian/support-frontend/issues/comments/367981326","html_url":"https://github.com/guardian/support-frontend/pull/525#issuecomment-367981326","issue_url":"https://api.github.com/repos/guardian/support-frontend/issues/525","id":367981326,"user":{"login":"Ap0c","id":5131341,"avatar_url":"https://avatars3.githubusercontent.com/u/5131341?v=4","gravatar_id":"","url":"https://api.github.com/users/Ap0c","html_url":"https://github.com/Ap0c","followers_url":"https://api.github.com/users/Ap0c/followers","following_url":"https://api.github.com/users/Ap0c/following{/other_user}","gists_url":"https://api.github.com/users/Ap0c/gists{/gist_id}","starred_url":"https://api.github.com/users/Ap0c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ap0c/subscriptions","organizations_url":"https://api.github.com/users/Ap0c/orgs","repos_url":"https://api.github.com/users/Ap0c/repos","events_url":"https://api.github.com/users/Ap0c/events{/privacy}","received_events_url":"https://api.github.com/users/Ap0c/received_events","type":"User","site_admin":false},"created_at":"2018-02-23T11:13:13Z","updated_at":"2018-02-23T11:13:13Z","author_association":"CONTRIBUTOR","body":"Ok, I've put a card in to review it."}}
{"actor":{"display_login":"Ap0c"}}