How iaphub/react-native-iaphub works
Project type and purpose
• This is a React Native SDK module (“react-native-iaphub”) for integrating IAPHUB’s in‑app‑purchase/subscription services into mobile apps.
• It includes two deliverables:
• A reusable library with JavaScript/TypeScript bindings (in src/), plus native Android (Kotlin) and iOS (Swift/ObjC) modules.
• An “Example” React Native application that demonstrates usage and contains platform build configs.
File structure
• Top‑level folders:
• src/ – core JS/TS code (config.tsx, iaphub.tsx, index.tsx, models/)
• android/ – Android native implementation (RNIaphubModule.kt, Package.kt)
• ios/ – iOS native implementation (RNIaphub.swift/m, bridging header, podspec)
• Example/ – full React Native app for demonstration (with its own android/, ios/, src/)
• guides/ – Markdown migration guides (not part of runtime)
• Key patterns:
• Bridge pattern (JS ↔ native modules)
• Singleton service (IAPHUB instance)
• Model layer (Transaction, Product, BillingStatus)
• Config and build files: babel.config.js, metro.config.js, tsconfig*.json, gradle wrappers, Podspec, package.json
Extract insights from README
• Core function: wrappers for IAPHUB REST API + App Store/Play Store purchase flows
• No built‑in UI; consumers write their own UI on top of the exposed methods/events
• Supports iOS and Android through native modules bridged to JS
a. Components
1. React Native JS layer (src/index.tsx → config.tsx & iaphub.tsx)
2. Native Bridge Modules
– Android: RNIaphubModule (Kotlin)/RNIaphubPackage
– iOS: RNIaphub.swift + ObjC shim + Podspec
3. Platform IAP SDKs
– Google Play Billing (Android)
– StoreKit (iOS)
4. IAPHUB Backend API (cloud service)
5. Example App (consumer of the library)
6. Local State Management (stores/iap.js & app.js in Example)
7. External Dependencies (e.g., axios/fetch for REST calls, event emitter)
b. Relationships & Data Flow
• JS calls IAPHUB methods → forwarded through React Native bridge
• Native module invokes Play Billing/StoreKit → returns purchase events
• Native layer relays events back to JS via callbacks/events
• JS layer sends REST requests to IAPHUB API (authenticate, get products, validate receipts)
• Responses update JS models & fires events to app logic/UI
c. Architectural Patterns & Principles
• Bridge (JS ↔ native) ensuring platform‑agnostic JS interface
• Singleton pattern for the IAPHUB client instance
• Observer/event‑driven (app subscribes to purchase, restore, error events)
• Layered separation: UI (in Example) ←→ JS service ←→ native implementation ←→ platform SDK ←→ backend
d. Key technologies
• React Native (JS/TS)
• Native Android: Kotlin, Play Billing API
• Native iOS: Swift/Objective‑C, StoreKit, CocoaPods
• HTTP client (Fetch or Axios) for IAPHUB REST API
• Metro bundler, Babel, TypeScript