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

buyerJourney.intercept doesn't intercept payment methods switching #1799

Closed
AncleMarvel opened this issue Mar 4, 2024 · 4 comments
Closed
Labels

Comments

@AncleMarvel
Copy link

Please list the package(s) involved in the issue, and include the version you are using

"@shopify/ui-extensions": "2024.1.x"

Describe the bug

api.buyerJourney.intercept works only once after checkout is loaded if I switch from e.g. Shopify Payments to my custom method. If I reload the page and switch from the custom method to Shopify Payments - api.buyerJourney.intercept doesn't work. Customers have to change their data on checkout or click Review step anytime to trigger my logic which is based on selected payment method.

Steps to reproduce the behavior:

There are 2 cases when it doesn't work as expected.
The 1st case:

  1. After checkout opened with selected custom payment method, switch the method to e.g. the default one.

The 2nd case:

  1. It doesn't work anytime when you switch payment methods except switching from default to custom method after checkout is opened. It only works once

Expected behavior

Anytime I switch payment methods it triggers

Screenshots

Additional context

I have a checkout ui extension which appears when my custom payment method is selected and dissapears when any other is selected. But I can't implement this logic cuz interceptor triggers only once and in only specific case when I switch methods

@AncleMarvel AncleMarvel added the bug Something isn't working label Mar 4, 2024
@jamesvidler
Copy link
Contributor

@AncleMarvel selecting a payment method doesn't currently cause a buyerjourney event to fire. If you need to show a UI based on the selected payment option, I would instead subscribe to selectedPaymentOptions so when that value changes you can conditionally render UI.

@jamesvidler jamesvidler added enhancement New feature or request foundations Team - Checkout Extensibility Extension APIs and removed bug Something isn't working labels Mar 8, 2024
@AncleMarvel
Copy link
Author

Hi @jamesvidler thank you for your answer! Is it possible to check somewhere an example of code how to subscribe to something because in Shopify's docs there are only examples for React, I'm not handy with it at all so it's hard to understand how to work with it in just JS?

@jamesvidler
Copy link
Contributor

jamesvidler commented Mar 12, 2024

@AncleMarvel Thank you for your feedback regarding the docs. That's something we will take a look at.

To subscribe to value changes in vanilla JS would:

import {extension} from '@shopify/ui-extensions/checkout';

export default extension(
  'purchase.checkout.block.render',
  (root, {selectedPaymentOptions, availablePaymentOptions}) => {
    selectedPaymentOptions.subscribe((newValue) => {
      // Do something when new payment option(s) have been selected
    });
  },
);

@AncleMarvel
Copy link
Author

@jamesvidler Thank you very much! You was very helpful!

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

No branches or pull requests

2 participants