For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
import { MORE_IMPORTS..., reactExtension, useSelectedPaymentOptions, } from "@shopify/ui-extensions-react/checkout"; reactExtension("purchase.checkout.actions.render-before", async () => <Extension />); export default function Extension() { const [expressPayment, setExpressPayment] = useState(false); const paymentOptions = useSelectedPaymentOptions(); //check for express payments useEffect(() => { if (paymentOptions.some((option) => option.type === "wallet")) { setExpressPayment(true); } else { setExpressPayment(false); } }, [paymentOptions]); return expressPayment && <>RENDER SOMETHING</> }
Note: we are on Shopify Plus
Thank you in advance!
Vieweg
Hi Vieweg,
Could you try querying the checkout to get the payment methods used in a checkout session? It should look something like this:
query GetCheckoutPaymentMethods($checkoutId: ID!) {
checkout(id: $checkoutId) {
paymentMethods {
name
id
}
}
}
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi Liam, really appreciate that.
I couldn't find this query in the docs, but I'm wondering that would it only be available after the customers finished their checkout ? in that case it's not exactly what I'm looking, I'm trying to detect the use of express payment before finished checkout.
anyway will give it a try 🙂
thank you!
Running it with useApi query (extensions UI), doesn't work as expected
import {
...
reactExtension,
useApi,
...
} from "@shopify/ui-extensions-react/checkout";
reactExtension("purchase.checkout.actions.render-before", async () => <Extension />);
export default function Extension() {
const { query, checkoutToken } = useApi();
useEffect(() => {
const ql = `query GetCheckoutPaymentMethods($checkoutId: ID!) {
checkout(id: $checkoutId) {
paymentMethods {
name
id
}
}
}`;
query(ql,{variables: {checkoutId: checkoutToken}})
.then((data ) => console.log(data))
.catch(console.error);
...
}, []);
}
returns error
"errors": [
{
"message": "Field 'checkout' doesn't exist on type 'QueryRoot'",
"locations": [{"line": 2,"column": 4}],
"path": ["query GetCheckoutPaymentMethods","checkout"],
"extensions": {
"code": "undefinedField",
"typeName": "QueryRoot",
"fieldName": "checkout"
}
...
}