Skip to content

Commit

Permalink
Use fullpage redirect for billing in embedded apps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillplatonov committed Dec 30, 2022
1 parent 8c18e68 commit e002eda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Unreleased
* Removed Logged output for rescued JWT exceptions [#1610](https://github.com/Shopify/shopify_app/pull/1610)
* Fixes a bug with `ShopifyApp::WebhooksManager.destroy_webhooks` causing not passing session arguments to [unregister](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/webhooks/registry.rb#L99) method [#1569](https://github.com/Shopify/shopify_app/pull/1569)
* Validates shop's offline session token is still valid when using `EnsureInstalled`[#1612](https://github.com/Shopify/shopify_app/pull/1612)
* Fixes a bug with `EnsureBilling` causing infinite redirect in embedded apps [#1578](https://github.com/Shopify/shopify_app/pull/1578)

21.3.1 (Dec 12, 2022)
----------
Expand Down
2 changes: 2 additions & 0 deletions lib/shopify_app/controller_concerns/ensure_billing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def check_billing(session = current_shopify_session)
add_top_level_redirection_headers(url: confirmation_url, ignore_response_code: true)
ShopifyApp::Logger.debug("Responding with 401 unauthorized")
head(:unauthorized)
elsif ShopifyApp.configuration.embedded_app?
fullpage_redirect_to(confirmation_url)
else
redirect_to(confirmation_url, allow_other_host: true)
end
Expand Down
12 changes: 9 additions & 3 deletions test/controllers/concerns/ensure_billing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def index

get :index

assert_redirected_to(%r{^https://totally-real-url})
assert_client_side_redirection "https://totally-real-url"

get :index, xhr: true

Expand Down Expand Up @@ -93,7 +93,7 @@ def index

get :index

assert_redirected_to(%r{^https://totally-real-url})
assert_client_side_redirection "https://totally-real-url"

get :index, xhr: true

Expand Down Expand Up @@ -159,7 +159,7 @@ def index

get :index

assert_redirected_to(%r{^https://totally-real-url})
assert_client_side_redirection "https://totally-real-url"

get :index, xhr: true

Expand Down Expand Up @@ -204,6 +204,12 @@ def index

private

def assert_client_side_redirection(url)
assert_response :success
assert_match "Redirecting", response.body
assert_match(url, response.body)
end

def stub_graphql_requests(*requests)
requests.each do |request|
stub_request(:post, "https://my-shop.myshopify.com/admin/api/#{@api_version}/graphql.json")
Expand Down

0 comments on commit e002eda

Please sign in to comment.