Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
88 stars 9 forks source link

App Bridge APP::CART::UPDATE doesn't work for Android Shopify POS #75

Closed derrickrc closed 3 years ago

derrickrc commented 3 years ago

Title says it all, the same snippet below works for iOS without issue: https://shopify.dev/apps/tools/app-bridge/actions/cart

var unsubscriber = cart.subscribe(Cart.Action.UPDATE, function (payload) {
  console.log('[Client] fetchCart', payload);
  unsubscriber();
});
cart.dispatch(Cart.Action.FETCH);
andrewapperley commented 3 years ago

Hey @derrickrc Thanks for reporting this issue. I'm going to get this in front of the Retail team.

BrittaEvansFenton commented 3 years ago

Hi @derrickrc I'm unable to reproduce this on my side, so I'm hoping I can gather a little more information from you:

  1. Are you you getting any returns? or just errors?
  2. What is the state of the cart at the time you are calling?
  3. Where is your app located in POS? Are you trying to make the call on the Smart Grid?
derrickrc commented 3 years ago

@BrittaEvansFenton thanks for looking into this.

  1. I don't believe I am getting any returns at all in this case (though it's impossible to say because Chrome WebView debugging no longer works with the "new" Android POS)
  2. The state of the POS cart is that it has items in it already. It similarly just doesn't run at all if there are no items in the cart.
  3. Yes, I am making the call as an embedded POS app on the Smart Grid

To confirm, you're able to get a payload callback value with that snippet of code upon opening an embedded POS app? I am on a Pixel 4a on Shopify POS 4.16.0.

For example, if I change the console.log() to alert() to make sure I can see the payload value without WebView debugging, nothing happens.

once2go commented 3 years ago

Hi @derrickrc When did you check WebView debugging last time? This feature should be fixed in last releases. I think, we need more information from your side to figure out what is wrong. Is it a first time you using this API? Are you able to modify the cart from your app (like add items, discounts, etc...)?

derrickrc commented 3 years ago

@once2go Hi Denys, thanks for responding.

WebView Debugging has not worked for me, or for any other developers since the "new" Android POS launched (https://shopifypartners.slack.com/archives/C4E5GV5U4/p1628797121188300) . I just tried it again, please see the screenshot - when I open my embedded app, it does not show up.

This is not my first time using this API, I am using it in a production app. As mentioned, the code snippet works for iOS and it fetches the cart, but for Android Shopify POS the code does not execute and I am unable to get the cart payload. I am not sure what else I can share.

Screen Shot 2021-09-09 at 4 09 09 PM

BrittaEvansFenton commented 3 years ago

Hey @derrickrc can we grab your email. We want to test your application if possible and ask a lot more questions.

I'll join the partner slack

gvarandas commented 3 years ago

Hey @derrickrc 👋 We have shipped a fix in our latest version that corrected how the cart actions were handled in the App Bridge for POS Next Android. Can you please check if this issue has been fixed as well?

derrickrc commented 3 years ago

@gvarandas thank you! I still only have 4.19.0 available to me in the Play Store, when the next version becomes available I'll check for us.

derrickrc commented 3 years ago

@gvarandas now that I can see errors in the console, I'm getting an App Bridge permission error for accessing the cart on Android POS. The same code works fine for iOS without any permission errors.

Screen Shot 2021-10-11 at 8 37 47 AM

gvarandas commented 3 years ago

Thanks for the feedback, @derrickrc! I'll check it out internally and ask the team to post an update here ASAP. 🙏

js-goupil commented 3 years ago

@derrickrc Hey there, I'm running out of ideas. I'm not fully up to speed on all things App Bridge as I'm more focused on the POS side, but is it possible you might need to set up the app for Android separately from iOS? I'm just looking at some docs here, and I'm wondering if you need to double check the app_id and the platforms https://shopify.dev/api/admin-rest/2021-10/resources/mobileplatformapplication#resource_object

Some other maybe relevant docs: https://shopify.dev/apps/tools/app-bridge/mobile#authentication

derrickrc commented 3 years ago

@js-goupil thanks for responding, however this is an App Bridge permissions issue specific to Android POS. There is another similar issue as well (perhaps whoever's investigating can look at both simultaneously: https://github.com/Shopify/shopify-app-bridge/issues/58)

Is there someone who's up to speed on App Bridge for Shopify POS who can chime in? @andrewapperley ?

js-goupil commented 3 years ago

@derrickrc I dug into it to try to understand it more. I installed your app on my shop and was able to reproduce it. It looks like when the app is loaded, the error related to permissions appears. However, I am able to add a line item to the cart afterwards without any issue. Is this your experience currently? I wonder if something on the Android side isn't set up properly, that it causes it to error out when we try to fetch the cart early on. Have you tried fetching the cart once the app is loaded? ie if you add a button that that fetches the cart when tapped, would you get the same error?

derrickrc commented 3 years ago

@js-goupil thanks for your help and investigation! It does appear to be a timing issue - if I throw in a 500ms sleep on the initial load before making the call to fetchCart, it works.

Screen Shot 2021-10-26 at 1 00 36 PM

js-goupil commented 3 years ago

@derrickrc Amazing! Just out of curiosity, on your end do you receive any sort of notification or state as to when everything is set up and loaded? Either way, I'm happy we found the cause!

derrickrc commented 3 years ago

@js-goupil on Android POS no, on iOS you can see certain logs show up in Mac Console (but I don't think there's an explicit way to listen for an App Bridge on loaded event, though on iOS there's no loading timing issue).