diff --git a/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt b/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt
index 7c2d3be..987e77c 100644
--- a/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt
+++ b/android/src/main/java/com/chargebee/android/ChargebeeReactNativeModule.kt
@@ -1,7 +1,5 @@
-package com.chargebee.example
+package com.chargebee.android
-import com.chargebee.android.Chargebee
-import com.chargebee.android.ChargebeeReactNativeSpec
import com.chargebee.android.billingservice.CBPurchase
import com.chargebee.android.exceptions.CBProductIDResult
import com.facebook.react.bridge.ReactApplicationContext
diff --git a/android/src/oldarch/ChargebeeReactNativeSpec.kt b/android/src/oldarch/ChargebeeReactNativeSpec.kt
index 11df4ec..47c9c5d 100644
--- a/android/src/oldarch/ChargebeeReactNativeSpec.kt
+++ b/android/src/oldarch/ChargebeeReactNativeSpec.kt
@@ -3,9 +3,11 @@ 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
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)
}
diff --git a/example/src/App.tsx b/example/src/App.tsx
index 948a1c9..4951673 100644
--- a/example/src/App.tsx
+++ b/example/src/App.tsx
@@ -1,34 +1,51 @@
-import React, { useState } from 'react';
+import React from 'react';
-import { StyleSheet, View, Text } from 'react-native';
+import { StyleSheet, View, Button } from 'react-native';
import Chargebee from '@chargebee/react-native-chargebee';
export default function App() {
- const [configComplete, isConfigComplete] = useState(false);
const site = 'site';
- const apiKey = 'test_key';
- const sdkKey = 'sdk-key';
+ const apiKey = 'apiKey';
+ const sdkKey = 'sdkKey';
React.useEffect(() => {
- Chargebee.configure({
- site: site,
- publishableApiKey: apiKey,
- sdkKey: sdkKey,
- });
- isConfigComplete(true);
+ configure(site, apiKey, sdkKey);
}, []);
return (
- {!configComplete ? (
- Pending config
- ) : (
- Config complete
- )}
+
);
}
+const retrieveProductIdentifiers = () => {
+ const queryParams = new Map();
+ queryParams.set('limit', '100');
+ Chargebee.retrieveProductIdentifiers(queryParams)
+ .then((result) => {
+ console.log(result);
+ })
+ .catch((e) => {
+ console.error(e);
+ });
+};
+
+const configure = (site: string, apiKey: string, sdkKey: string) => {
+ Chargebee.configure({
+ site: site,
+ publishableApiKey: apiKey,
+ sdkKey: sdkKey,
+ });
+};
+
const styles = StyleSheet.create({
container: {
flex: 1,
diff --git a/ios/ChargebeeHelper.swift b/ios/ChargebeeHelper.swift
index bf88f6b..0dcadc1 100644
--- a/ios/ChargebeeHelper.swift
+++ b/ios/ChargebeeHelper.swift
@@ -13,4 +13,16 @@ public class ChargebeeHelper: NSObject {
Chargebee.configure(site: site, apiKey: apiKey, sdkKey: sdkKey)
}
+ @objc public func retrieveProductIdentifiers(queryParams: Dictionary, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
+ CBPurchase.shared.retrieveProductIdentifers(queryParams: queryParams) { result in
+ switch result {
+ case let .success(products):
+ resolver(products)
+ case let .failure(error as NSError):
+ rejecter("\(error.code)", error.localizedDescription, error)
+ }
+ }
+
+ }
+
}
diff --git a/ios/ChargebeeReactNative.mm b/ios/ChargebeeReactNative.mm
index 4505c36..92da9cf 100644
--- a/ios/ChargebeeReactNative.mm
+++ b/ios/ChargebeeReactNative.mm
@@ -13,6 +13,15 @@ @implementation ChargebeeReactNative
[helper configureWithSite:site apiKey:publishableApiKey sdkKey:sdkKey];
}
+RCT_REMAP_METHOD(retrieveProductIdentifiers,
+ retrieveProductIdentifiersWithQueryParams:(NSDictionary *)queryParams
+ withResolver:(RCTPromiseResolveBlock)resolve
+ withRejecter:(RCTPromiseRejectBlock)reject)
+{
+ ChargebeeHelper* helper = [[ChargebeeHelper alloc] init];
+ [helper retrieveProductIdentifiersWithQueryParams:queryParams resolver:resolve rejecter:reject];
+}
+
// Don't compile this code when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr)getTurboModule:
diff --git a/src/NativeChargebeeReactNative.ts b/src/NativeChargebeeReactNative.ts
index bf9c9c9..f908395 100644
--- a/src/NativeChargebeeReactNative.ts
+++ b/src/NativeChargebeeReactNative.ts
@@ -3,6 +3,7 @@ import { TurboModuleRegistry } from 'react-native';
export interface Spec extends TurboModule {
configure(site: string, publishableApiKey: string, sdkKey: string): void;
+ retrieveProductIdentifiers(queryParams: Object): Promise>;
}
export default TurboModuleRegistry.getEnforcing('ChargebeeReactNative');
diff --git a/src/index.tsx b/src/index.tsx
index 76fe06e..e97e1a8 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -38,4 +38,10 @@ export default class Chargebee {
}: ChargebeeConfig): void {
ChargebeeReactNative.configure(site, publishableApiKey, sdkKey);
}
+
+ public static async retrieveProductIdentifiers(
+ queryParams: Map
+ ): Promise> {
+ return ChargebeeReactNative.retrieveProductIdentifiers(queryParams);
+ }
}