diff --git a/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt b/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt index 101cd3c..8cabf86 100644 --- a/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt +++ b/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt @@ -3,10 +3,7 @@ package com.chargebee.android import com.chargebee.android.billingservice.CBPurchase import com.chargebee.android.exceptions.CBProductIDResult import com.chargebee.android.utils.convertArrayToWritableArray -import com.facebook.react.bridge.Promise -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactMethod -import com.facebook.react.bridge.ReadableMap +import com.facebook.react.bridge.* class ChargebeeReactNativeModule internal constructor(context: ReactApplicationContext) : ChargebeeReactNativeSpec(context) { @@ -36,6 +33,10 @@ class ChargebeeReactNativeModule internal constructor(context: ReactApplicationC } } + override fun retrieveProducts(productIds: ReadableArray, promise: Promise) { + TODO("Not yet implemented") + } + private fun getFormattedQueryParams(queryParams: ReadableMap): Array { if (queryParams != null) return arrayOf(queryParams.getString("limit") ?: "") diff --git a/android/src/oldarch/ChargebeeReactNativeSpec.kt b/android/src/oldarch/ChargebeeReactNativeSpec.kt index 47c9c5d..4ff2d60 100644 --- a/android/src/oldarch/ChargebeeReactNativeSpec.kt +++ b/android/src/oldarch/ChargebeeReactNativeSpec.kt @@ -1,13 +1,12 @@ package com.chargebee.android -import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactContextBaseJavaModule -import com.facebook.react.bridge.Promise -import com.facebook.react.bridge.ReadableMap +import com.facebook.react.bridge.* abstract class ChargebeeReactNativeSpec internal constructor(context: ReactApplicationContext) : ReactContextBaseJavaModule(context) { abstract fun configure(site: String, publishableApiKey: String, sdkKey: String = "") abstract fun retrieveProductIdentifiers(queryParams: ReadableMap, promise: Promise) + abstract fun retrieveProducts(productIds: ReadableArray, promise: Promise) + } diff --git a/example/src/App.tsx b/example/src/App.tsx index 5633a74..05e074e 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { StyleSheet, View, Button } from 'react-native'; import Chargebee from '@chargebee/react-native-chargebee'; @@ -8,10 +8,42 @@ export default function App() { const apiKey = 'apiKey'; const sdkKey = 'sdkKey'; - React.useEffect(() => { + let productIdentifiers: string[] = []; + + useEffect(() => { configure(site, apiKey, sdkKey); }, []); + const retrieveProductIdentifiers = async () => { + const queryParams = new Map(); + queryParams.set('limit', '1'); + try { + const result = await Chargebee.retrieveProductIdentifiers(queryParams); + console.log(result); + productIdentifiers = result; + } catch (error) { + console.error(error); + } + }; + + // TODO: Refactor Examples + const retrieveProducts = async () => { + try { + const result = await Chargebee.retrieveProducts(productIdentifiers); + console.log(result); + } catch (error) { + console.error(error); + } + }; + + const configure = (site: string, apiKey: string, sdkKey: string) => { + Chargebee.configure({ + site: site, + publishableApiKey: apiKey, + sdkKey: sdkKey, + }); + }; + return (