Skip to content

Commit b0c3aaf

Browse files
feat: expose checkout options on present / preload
1 parent cf0ce3d commit b0c3aaf

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

modules/@shopify/checkout-sheet-kit/src/context.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
RemoveEventListeners,
3232
CheckoutEvent,
3333
Configuration,
34+
CheckoutOptions,
3435
} from './index.d';
3536

3637
type Maybe<T> = T | undefined;
@@ -41,8 +42,8 @@ interface Context {
4142
getConfig: () => Promise<Configuration | undefined>;
4243
setConfig: (config: Configuration) => Promise<void>;
4344
removeEventListeners: RemoveEventListeners;
44-
preload: (checkoutUrl: string) => void;
45-
present: (checkoutUrl: string) => void;
45+
preload: (checkoutUrl: string, options?: CheckoutOptions) => void;
46+
present: (checkoutUrl: string, options?: CheckoutOptions) => void;
4647
dismiss: () => void;
4748
invalidate: () => void;
4849
version: Maybe<string>;
@@ -95,15 +96,16 @@ export function ShopifyCheckoutSheetProvider({
9596
instance.current?.removeEventListeners(eventName);
9697
}, []);
9798

98-
const present = useCallback((checkoutUrl: string) => {
99+
const present = useCallback((checkoutUrl: string, options?: CheckoutOptions) => {
99100
if (checkoutUrl) {
100-
instance.current?.present(checkoutUrl);
101+
instance.current?.present(checkoutUrl, options
102+
);
101103
}
102104
}, []);
103105

104-
const preload = useCallback((checkoutUrl: string) => {
106+
const preload = useCallback((checkoutUrl: string, options?: CheckoutOptions) => {
105107
if (checkoutUrl) {
106-
instance.current?.preload(checkoutUrl);
108+
instance.current?.preload(checkoutUrl, options);
107109
}
108110
}, []);
109111

sample/src/screens/CartScreen.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
ActivityIndicator,
3333
Pressable,
3434
RefreshControl,
35+
Alert,
3536
} from 'react-native';
3637
import Icon from 'react-native-vector-icons/Entypo';
3738

@@ -48,6 +49,7 @@ import {useTheme} from '../context/Theme';
4849
import {useCart} from '../context/Cart';
4950
import {currency} from '../utils';
5051
import {useShopifyEventHandlers} from '../hooks/useCheckoutEventHandlers';
52+
import { fetchToken } from '../services/TokenClient';
5153

5254
function CartScreen(): React.JSX.Element {
5355
const ShopifyCheckout = useShopifyCheckoutSheet();
@@ -85,7 +87,15 @@ function CartScreen(): React.JSX.Element {
8587

8688
const presentCheckout = async () => {
8789
if (checkoutURL) {
88-
ShopifyCheckout.present(checkoutURL);
90+
const auth = await fetchToken();
91+
if (!auth) {
92+
Alert.alert('Error', 'Failed to authenticate');
93+
return;
94+
}
95+
96+
ShopifyCheckout.present(checkoutURL, {
97+
authentication: { token: auth },
98+
});
8999
}
90100
};
91101

0 commit comments

Comments
 (0)