@@ -8,14 +8,16 @@ import {
88 TextInput ,
99 Platform ,
1010} from 'react-native' ;
11- import {
11+ import Qonversion , {
1212 NoCodesAction ,
1313 NoCodesConfigBuilder ,
1414 ScreenPresentationStyle ,
1515 ScreenPresentationConfig ,
1616 NoCodes ,
17+ NoCodesError ,
18+ type PurchaseDelegate ,
19+ Product
1720} from '@qonversion/react-native-sdk' ;
18- import type NoCodesError from '../../../../src/dto/NoCodesError' ;
1921import { AppContext } from '../../store/AppStore' ;
2022import styles from './styles' ;
2123import Snackbar from 'react-native-snackbar' ;
@@ -37,6 +39,42 @@ const NoCodesScreen: React.FC = () => {
3739 // Initialize No-Codes SDK once
3840 const initializeNoCodes = ( ) => {
3941 console . log ( '🔄 [NoCodes] Starting SDK initialization...' ) ;
42+ // @ts -ignore - PurchaseDelegate is not used until the comment below is uncommented
43+ const purchaseDelegate : PurchaseDelegate = {
44+ purchase : async ( product : Product ) => {
45+ console . log ( '🔄 [PurchaseDelegate] Starting purchase for product:' , product . qonversionId ) ;
46+ try {
47+ const entitlements = await Qonversion . getSharedInstance ( ) . purchaseProduct ( product ) ;
48+ console . log ( '✅ [PurchaseDelegate] Purchase successful:' , Object . fromEntries ( entitlements ) ) ;
49+ dispatch ( { type : 'ADD_NOCODES_EVENT' , payload : `Purchase completed: ${ product . qonversionId } ` } ) ;
50+ Snackbar . show ( {
51+ text : `Purchase completed: ${ product . qonversionId } ` ,
52+ duration : Snackbar . LENGTH_SHORT ,
53+ } ) ;
54+ } catch ( error : any ) {
55+ console . error ( '❌ [PurchaseDelegate] Purchase failed:' , error ) ;
56+ dispatch ( { type : 'ADD_NOCODES_EVENT' , payload : `Purchase failed: ${ error . message } ` } ) ;
57+ throw error ; // Re-throw to let NoCodes SDK handle the error
58+ }
59+ } ,
60+ restore : async ( ) => {
61+ console . log ( '🔄 [PurchaseDelegate] Starting restore...' ) ;
62+ try {
63+ const entitlements = await Qonversion . getSharedInstance ( ) . restore ( ) ;
64+ console . log ( '✅ [PurchaseDelegate] Restore successful:' , Object . fromEntries ( entitlements ) ) ;
65+ dispatch ( { type : 'ADD_NOCODES_EVENT' , payload : 'Restore completed' } ) ;
66+ Snackbar . show ( {
67+ text : 'Restore completed successfully!' ,
68+ duration : Snackbar . LENGTH_SHORT ,
69+ } ) ;
70+ } catch ( error : any ) {
71+ console . error ( '❌ [PurchaseDelegate] Restore failed:' , error ) ;
72+ dispatch ( { type : 'ADD_NOCODES_EVENT' , payload : `Restore failed: ${ error . message } ` } ) ;
73+ throw error ; // Re-throw to let NoCodes SDK handle the error
74+ }
75+ } ,
76+ } ;
77+
4078 const noCodesConfig = new NoCodesConfigBuilder ( ProjectKey )
4179 . setNoCodesListener ( {
4280 onScreenShown : ( id : string ) => {
@@ -71,6 +109,7 @@ const NoCodesScreen: React.FC = () => {
71109 NoCodes . getSharedInstance ( ) . close ( ) ;
72110 } ,
73111 } )
112+ // .setPurchaseDelegate(purchaseDelegate) // Uncomment this to use the purchase delegate
74113 . build ( ) ;
75114 console . log ( '✅ [NoCodes] Config built successfully:' , noCodesConfig ) ;
76115
0 commit comments