If the user hasn't accepted the charge yet, or canceled it, how to redirect them from my embedded app to the "Approve fees" page again?

Solved
Highlighted
New Member
2 1 1

Hi,
I am pretty new to Shopify development, so please bear with me. And thank you for help in advance!

I am creating an app with a RecurringApplicationCharge, and I have two situations where I have almost the same problem.

1. Say, the user has installed the app, but didn't accept the charge yet - they're on the "Approve fees" page. Then, in a separate tab, they go to the "Apps" page and select my app from the list.

In this case, I would like to redirect them to the "Approve fees" page.

I am trying to do it directly from my backend endpoint - the very first one hit by the app, the one I specified in the "App URL" field when I set up the app as an app developer.

However, my app is an embedded app and is opening in a frame in the Shopify store. So the redirect (from the frame to another whole Shopify page) doesn't work, and I see a broken page and this error in the browser console:

Refused to display 'https://xxx.myshopify.com/admin/charges/zzz/request_recurring_application_charge?...' in a frame because it set 'X-Frame-Options' to 'deny'.

How should I redirect the user correctly to the "Approve fees" page?

 

2. Say, the user has reviewed the "Approve fees" page and canceled the charge.

What Shopify seems to do automatically, is to redirect the user to the "Apps" page. Now, the link on the "Apps" page seems the only entry point to the app.

Am I right? Is this really the only entrypoint, or is there a way for the user to go back to the "Approve fees" page?

And, of course, I still have the same problem: the "Approve fees" page doesn't want to be open within the frame. Which brings me to the first question again: how do I redirect from my embedded app to the page where the user can accept charges?

 

Thanks!

0 Likes
Highlighted
Shopify Partner
11 0 3

Hii

You will got the status info in the confirmation_url.

Let me explain again.

When user comes to charge screen. Either they accept it or decline it.

after that they are redirecred to link (confirmation_url set by you).

On that function you need to print all post and get array i'm sure you will got the information there.

Php code look like this

$rurl = 'xyz.com/welcom_app';
$d=array('application_charge'=>array('name'=>'yourapp','price'=>'50','return_url'=>$rurl,'test'=>true));

$response = $this->shopify->call('POST',"/admin/application_charges.json", $d,$s,$t);

redirect($response['confirmation_url']);


then on welcome_app function try to print all requested data

print_r($_REQUEST);

 

 

Let me know if you have any other queries

 

 

Thanks

gddeveloper
0 Likes
Highlighted
New Member
2 1 1

This is an accepted solution.

Hi GD1,

Thank you for your reply! But the problem is a bit more complex.

You see, when the user _declines_ the charge. or simply closes the tab, they're not redirected to the confirmation_url. And they're not charged.

The app, however, remains installed.

When the unpaid user opens the app, I wanted to intercept that event on the backend, in the very first endpoint users hit, the one I specify in the "App URL" field. When this happens, I wanted to redirect _the whole page_ to the "Approve fees" page. But it doesn't seem possible because my app is an embedded app and is being opened in the iframe within Shopify.

 

I solved the problem this way.

 

When the unpaid user hits the "App URL" endpoint, I redirect them to the frontend endpoint, which serves index.html, just like I do for all paid users.

That frontend page fetches the user data from the backend, again, just like it does for all users.

For paid users, it will receive the "yes they've paid" flag and will proceed to showing the app.

For unpaid users, it will receive the flag "no, they haven't paid" and will display a nice small page explaining why paying is important for the app developer. On that page I added a button "Go to charges" which leads them to the "Approve fees" page again, where they can pay.

 

Basically, I didn't manage to do the redirect from the backend side; but I did it from the frontend side.

 

Hope this helps someone!

1 Like
Highlighted
Shopify Partner
12 2 5

I'm having a similar issue. I worked my way through the React and Node tutorial. When I cancel at the confirm charge step, surprisingly the app is installed and the app script tags are injected into the storefront. Basically the store owner can get access to the app without paying.

 

Is there a Nodejs middleware that confirms purchase of the app, then redirects the user based on the purchase status?

 

I have a number of other features I'm building out, so I'll put this on the back burner for now.

0 Likes
Highlighted
Shopify Partner
2 0 0

Hey, 

 

Thanks for this, it really helped me figure out how to deal with declined charges.  

 

My only question is what link did you use to get back to where they can accept the charge?  I tried to confirmation_url and it gave me 

undefined method `confirmation_url' for #<ShopifyAPI::RecurringApplicationCharge>
0 Likes
Highlighted
Shopify Partner
1 0 0

I was gonna do the same solution, but have no idea how to get the URL that would show the accept charges screen again... any ideas?

0 Likes
Highlighted
New Member
14 0 0

Hi, I'm really having the same problem. 

Can you please drop your code piece here.
Appreciate for that.

 

0 Likes
Highlighted
New Member
2 0 0

If you are running into this problem when using the Shopify rails templates...

Use `fullpage_redirect_to` instead of `redirect_to` in your controller actions. The reason is that redirect_to doesn't go past the iframe options and can't perform a "fullpage" redirect which the iframe will deny. The Shopify Rails helper has the method `fullpage_redirect_to` which sorts this out

 

fullpage_redirect_to @recurring_charge.confirmtion_url

 instead of:

redirect_to @recurring_charge.confirmation_url

 

0 Likes