@@ -40,7 +40,6 @@ import SettingsScreen from './screens/SettingsScreen';
4040
4141import type { Configuration } from '@shopify/checkout-sheet-kit' ;
4242import {
43- AcceleratedCheckoutWallet ,
4443 ColorScheme ,
4544 ShopifyCheckoutSheetProvider ,
4645 useShopifyCheckoutSheet ,
@@ -58,18 +57,28 @@ import ProductDetailsScreen from './screens/ProductDetailsScreen';
5857import type { ProductVariant , ShopifyProduct } from '../@types' ;
5958import ErrorBoundary from './ErrorBoundary' ;
6059import env from 'react-native-config' ;
60+ import { createDebugLogger } from './utils' ;
61+ import { useShopifyEventHandlers } from './hooks/useCheckoutEventHandlers' ;
62+
63+ const log = createDebugLogger ( 'ENV' ) ;
6164
6265const colorScheme = ColorScheme . web ;
6366
64- console . log ( 'Environment variables loaded:' , {
65- STOREFRONT_DOMAIN : env . STOREFRONT_DOMAIN ,
66- STOREFRONT_ACCESS_TOKEN : env . STOREFRONT_ACCESS_TOKEN
67- ? '***' + env . STOREFRONT_ACCESS_TOKEN . slice ( - 4 )
68- : 'undefined' ,
69- STOREFRONT_VERSION : env . STOREFRONT_VERSION ,
70- EMAIL : env . EMAIL ,
71- PHONE : env . PHONE ,
72- } ) ;
67+ function quote ( str : string | undefined ) {
68+ return `"${ str } "` ;
69+ }
70+
71+ log ( '--------------------------------' ) ;
72+ log ( 'Using the following env' ) ;
73+ log ( 'STOREFRONT_DOMAIN:' , quote ( env . STOREFRONT_DOMAIN ) ) ;
74+ log (
75+ 'STOREFRONT_ACCESS_TOKEN:' ,
76+ '*' . repeat ( 8 ) + env . STOREFRONT_ACCESS_TOKEN ?. slice ( - 4 ) ,
77+ ) ;
78+ log ( 'STOREFRONT_VERSION:' , quote ( env . STOREFRONT_VERSION ) ) ;
79+ log ( 'EMAIL:' , quote ( env . EMAIL ) ) ;
80+ log ( 'PHONE:' , quote ( env . PHONE ) ) ;
81+ log ( '--------------------------------' ) ;
7382
7483const checkoutKitConfig : Configuration = {
7584 colorScheme,
@@ -174,42 +183,38 @@ class StorefrontURL {
174183
175184function AppWithContext ( { children} : PropsWithChildren ) {
176185 const shopify = useShopifyCheckoutSheet ( ) ;
186+ const eventHandlers = useShopifyEventHandlers ( ) ;
177187
178188 useEffect ( ( ) => {
179189 // Configure AcceleratedCheckouts with both wallets
180190 shopify . configureAcceleratedCheckouts ( {
181- storefrontDomain : env . STOREFRONT_DOMAIN ?? '' ,
182- storefrontAccessToken : env . STOREFRONT_ACCESS_TOKEN ?? '' ,
191+ storefrontDomain : env . STOREFRONT_DOMAIN ! ,
192+ storefrontAccessToken : env . STOREFRONT_ACCESS_TOKEN ! ,
183193 customer : {
184- email : env . EMAIL ?? '' ,
185- phoneNumber : env . PHONE ?? '' ,
194+ email : env . EMAIL ! ,
195+ phoneNumber : env . PHONE ! ,
186196 } ,
187- wallets : [
188- AcceleratedCheckoutWallet . shopPay ,
189- AcceleratedCheckoutWallet . applePay ,
190- ] ,
191197 } ) ;
192198
193199 const close = shopify . addEventListener ( 'close' , ( ) => {
194- console . log ( '[CheckoutClose]' ) ;
200+ eventHandlers . onCancel ?. ( ) ;
195201 } ) ;
196202
197203 const pixel = shopify . addEventListener ( 'pixel' , ( event : PixelEvent ) => {
198- console . log ( '[CheckoutPixelEvent]' , event . name , event ) ;
204+ eventHandlers . onWebPixelEvent ?. ( event ) ;
199205 } ) ;
200206
201207 const completed = shopify . addEventListener (
202208 'completed' ,
203209 ( event : CheckoutCompletedEvent ) => {
204- console . log ( '[CheckoutCompletedEvent]' , event . orderDetails . id ) ;
205- console . log ( '[CheckoutCompletedEvent]' , event ) ;
210+ eventHandlers . onComplete ?.( event ) ;
206211 } ,
207212 ) ;
208213
209214 const error = shopify . addEventListener (
210215 'error' ,
211216 ( error : CheckoutException ) => {
212- console . log ( error . constructor . name , error ) ;
217+ eventHandlers . onFail ?. ( error ) ;
213218 } ,
214219 ) ;
215220
@@ -219,7 +224,7 @@ function AppWithContext({children}: PropsWithChildren) {
219224 close ?. remove ( ) ;
220225 error ?. remove ( ) ;
221226 } ;
222- } , [ shopify ] ) ;
227+ } , [ shopify , eventHandlers ] ) ;
223228
224229 return (
225230 < ConfigProvider >
0 commit comments