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

fullpage_redirect_to not working in embedded app (App Bridge 2.0) #1387

Closed
CodeSchneider opened this issue Mar 8, 2022 · 12 comments
Closed

Comments

@CodeSchneider
Copy link

We have recently updated our version of this gem to v18.1.2 due to the App Bridge 2.0 related deprecation messages from Shopify.

When a user attempts to upgrade their plan, we create a new RecurringApplicationCharge and fire off a fullpage_redirect_to to the RecurringApplicationCharge's confirmation_url. In the browser we see the following:

Screen Shot 2022-03-08 at 4 28 30 PM

Any help would be appreciated.

@bgmat
Copy link

bgmat commented Mar 9, 2022

I can confirm. I have the exact same error.
It works if I roll back to 18.1.1

@CodeSchneider
Copy link
Author

@bgmat I confirm you are right. Rolling back 18.1.1 fixes the issue. Thank you!

@mel-mel-king
Copy link

I am getting the same error when tophatting the update during an install flow. Will the fix for this also resolve the issue I'm having?

This screenshot is after the oauth flow when installing the app

Screenshot 2022-03-10 at 10 12 32 AM

@khoimm92
Copy link

+1, I got the same issue. Temporarily solutions:

  • Revert to shopify_app from 18.1.2 to 18.1.1, or
  • Add the host param to the url

@forsbergplustwo
Copy link

I think the changes in PR #1360 would also help fix this, as it ensures the host param is always set.

@hoppergee
Copy link

Currently, I think the response.status = 303 # Makes Turbo render html response can fix your issue.
The solution comes from: #1287 (comment)

@flavio-b
Copy link
Contributor

flavio-b commented Apr 8, 2022

The host is pulled from params[:host], in the redirect view. Adding it as a query param to the target URL doesn't seem to work. The solution for me has been to assign params['host'] = @host before calling fullpage_redirect, but it's not a clean solution.

Since the redirect view already has access to current_shopify_domain, wouldn't it make more sense to just get the Shop object and ask for the host from it? Having to carry this param around is introducing another dependency.

Screen Shot 2022-04-07 at 7 36 12 PM

@hoppergee
Copy link

@flavio-b I fixed all related issues recently. You can check my way to set the params[:host] with HTTP header here: #1360

@rickmax
Copy link

rickmax commented May 3, 2022

I have same error from 19.0.1
response.status = 303 # Makes Turbo render html response does not work too

@janklimo
Copy link

Since Shopify now requires all apps to be on v18.1.2 or higher, here's my approach hoping it will help the rest of you guys deal with the upgrade.

The key is to make sure you pass in host param to every action that performs a fullpage_redirect_to. So, as an example, I had to make the following change when redirecting to the /upgrade path:

+  const { host } = AppConfig;
   const isOverLimit = imagesCount > imagesLimit;

   const title = isOverLimit ? "Please upgrade your plan now" : "You're currently on the free plan";
@@ -53,7 +54,7 @@ const UsageBanner: FunctionComponent<Props> = ({ planStats, fetchPlanStats }) =>
       <Banner title={title} status={status}>
         <TextContainer>
           {message()}
-          <Button outline download url="/upgrade">
+          <Button outline download url={`/upgrade?host=${host}`}>
             {`Upgrade for $${proPlanPrice}/mo.`}
           </Button>
         </TextContainer>

My app is an SPA which receives the host param when the app is authenticated. I set the @host instance variable in the admin controller:

class AdminController < ShopifyApp::AuthenticatedController
  # ...
  before_action :set_host

  private

  def set_host
    @host = params[:host]
  end
end

so it can be exposed to the frontend and passed into any redirect (as shown above).

For completeness I made the following changes to the charges controller:

 class ChargesController < AdminController
   def upgrade
-    charge = ChargesFactory.new_charge
+    charge = ChargesFactory.new_charge(@host)

     fullpage_redirect_to charge.confirmation_url if charge.save
   end

   def activate
     MailchimpEventsWorker.perform_async(@shop.id)
     @shop.update(current_charge: true)

-    fullpage_redirect_to root_url
+    redirect_to "#{root_url}?host=#{@host}&upgraded=true"
   end

And my charges factory:

 module ChargesFactory
   module_function

-  DEFAULTS = {
-    return_url: "#{ENV.fetch('HOST')}/activate_charge",
-  }.freeze
-
-  def new_charge
+  def new_charge(host)
     charge_options = {
       name: 'PRO plan. Big love!',
       price: Shop::PRO_PLAN_PRICE,
+      return_url: "#{ENV.fetch('HOST')}/activate_charge?host=#{host}",
     }

-    ShopifyAPI::RecurringApplicationCharge.new(DEFAULTS.merge(charge_options))
+    ShopifyAPI::RecurringApplicationCharge.new(charge_options)
   end
 end

This way the host param is present after the charge is accepted. Hope it helps!

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.

@github-actions github-actions bot added the stale label Sep 25, 2022
@github-actions
Copy link

We are closing this issue because it has been inactive for a few months.
This probably means that it is not reproducible or it has been fixed in a newer version.
If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants