@@ -3,61 +3,70 @@ import {
33 NativeEventEmitter ,
44 DeviceEventEmitter ,
55 Platform ,
6- } from ' react-native' ;
6+ } from " react-native" ;
77
88const { RNInAppPurchase } = NativeModules ;
99
1010const ERROR = {
11- FETCH_PRODUCTS : ' FETCH_PRODUCTS' ,
12- PURCHASE : ' PURCHASE' ,
13- CONNECTION : ' CONNECTION' ,
11+ FETCH_PRODUCTS : " FETCH_PRODUCTS" ,
12+ PURCHASE : " PURCHASE" ,
13+ CONNECTION : " CONNECTION" ,
1414} ;
1515
16- const addListener = ( event , listener ) => Platform . select ( {
17- ios : new NativeEventEmitter ( RNInAppPurchase ) ,
18- android : DeviceEventEmitter ,
19- } ) . addListener ( event , listener ) ;
16+ const addListener = ( event , listener ) =>
17+ Platform . select ( {
18+ ios : new NativeEventEmitter ( RNInAppPurchase ) ,
19+ android : DeviceEventEmitter ,
20+ } ) . addListener ( event , listener ) ;
2021
21- const removeAllListeners = ( event ) => Platform . select ( {
22- ios : new NativeEventEmitter ( RNInAppPurchase ) ,
23- android : DeviceEventEmitter ,
24- } ) . removeAllListeners ( event ) ;
22+ const removeAllListeners = ( event ) =>
23+ Platform . select ( {
24+ ios : new NativeEventEmitter ( RNInAppPurchase ) ,
25+ android : DeviceEventEmitter ,
26+ } ) . removeAllListeners ( event ) ;
2527
26- const onFetchProducts = listener => addListener ( 'iap:onFetchProductsSuccess' , listener ) ;
28+ const onFetchProducts = ( listener ) =>
29+ addListener ( "iap:onFetchProductsSuccess" , listener ) ;
2730
28- const onPurchase = listener => addListener ( ' iap:onPurchaseSuccess' , listener ) ;
31+ const onPurchase = ( listener ) => addListener ( " iap:onPurchaseSuccess" , listener ) ;
2932
3033const onError = ( listener ) => {
31- if ( Platform . OS === 'android' ) {
32- addListener ( 'iap:onConnectionFailure' , e => listener ( Object . assign ( e , { type : ERROR . CONNECTION } ) ) ) ;
34+ if ( Platform . OS === "android" ) {
35+ addListener ( "iap:onConnectionFailure" , ( e ) =>
36+ listener ( Object . assign ( e , { type : ERROR . CONNECTION } ) )
37+ ) ;
3338 }
34- addListener ( 'iap:onFetchProductsFailure' , e => listener ( Object . assign ( e , { type : ERROR . FETCH_PRODUCTS } ) ) ) ;
35- addListener ( 'iap:onPurchaseFailure' , e => listener ( Object . assign ( e , { type : ERROR . PURCHASE } ) ) ) ;
39+ addListener ( "iap:onFetchProductsFailure" , ( e ) =>
40+ listener ( Object . assign ( e , { type : ERROR . FETCH_PRODUCTS } ) )
41+ ) ;
42+ addListener ( "iap:onPurchaseFailure" , ( e ) =>
43+ listener ( Object . assign ( e , { type : ERROR . PURCHASE } ) )
44+ ) ;
3645} ;
3746
3847const clear = ( ) => {
39- removeAllListeners ( ' iap:onFetchProductsSuccess' ) ;
40- removeAllListeners ( ' iap:onPurchaseSuccess' ) ;
41- removeAllListeners ( ' iap:onFetchProductsFailure' ) ;
42- removeAllListeners ( ' iap:onPurchaseFailure' ) ;
43- if ( Platform . OS === ' android' ) {
44- removeAllListeners ( ' iap:onConnectionFailure' ) ;
48+ removeAllListeners ( " iap:onFetchProductsSuccess" ) ;
49+ removeAllListeners ( " iap:onPurchaseSuccess" ) ;
50+ removeAllListeners ( " iap:onFetchProductsFailure" ) ;
51+ removeAllListeners ( " iap:onPurchaseFailure" ) ;
52+ if ( Platform . OS === " android" ) {
53+ removeAllListeners ( " iap:onConnectionFailure" ) ;
4554 }
4655} ;
4756
48- const purchase = ( productId , oldProductId ) => {
49- if ( Platform . OS === ' android' ) {
50- RNInAppPurchase . purchase ( productId , oldProductId || null ) ;
57+ const purchase = ( productId , originalPurchaseToken ) => {
58+ if ( Platform . OS === " android" ) {
59+ RNInAppPurchase . purchase ( productId , originalPurchaseToken || null ) ;
5160 } else {
5261 RNInAppPurchase . purchase ( productId ) ;
5362 }
5463} ;
5564
5665const finalize = ( purchase , isConsumable ) => {
57- return Platform . OS === ' android'
66+ return Platform . OS === " android"
5867 ? RNInAppPurchase . finalize ( purchase , isConsumable )
5968 : RNInAppPurchase . finalize ( purchase ) ;
60- }
69+ } ;
6170
6271export default {
6372 configure : RNInAppPurchase . configure ,
@@ -70,4 +79,4 @@ export default {
7079 onError,
7180 clear,
7281 ERROR ,
73- }
82+ } ;
0 commit comments