From 3daa2fc8ce98349cd04f643da54173a847133272 Mon Sep 17 00:00:00 2001 From: mariuskurgonas Date: Mon, 26 Feb 2024 21:02:55 +0000 Subject: [PATCH] chore: cleanup and README update --- example/.env.example | 3 - example/README.md | 108 +++++++++++++++------------ example/src/hooks/useApiService.ts | 4 - example/src/react-native-config.d.ts | 3 - package.json | 2 +- 5 files changed, 62 insertions(+), 58 deletions(-) diff --git a/example/.env.example b/example/.env.example index 2aaf721..4106009 100644 --- a/example/.env.example +++ b/example/.env.example @@ -1,9 +1,6 @@ SAND_API_KEY=value -DEV_API_KEY=value PROD_API_KEY=value SAND_API_URL=value -DEV_API_URL=value PROD_API_URL=value SAND_CHECKOUT_API_URL=value -DEV_CHECKOUT_API_URL=value PROD_CHECKOUT_API_URL=value diff --git a/example/README.md b/example/README.md index 12470c3..6711eb0 100644 --- a/example/README.md +++ b/example/README.md @@ -1,79 +1,93 @@ -This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli). - # Getting Started ->**Note**: Make sure you have completed the [React Native - Environment Setup](https://reactnative.dev/docs/environment-setup) instructions till "Creating a new application" step, before proceeding. - -## Step 1: Start the Metro Server +- Installation +- Usage -First, you will need to start **Metro**, the JavaScript _bundler_ that ships _with_ React Native. +## Step 1: Installation -To start Metro, run the following command from the _root_ of your React Native project: +Add the module to your react native project by executing: ```bash # using npm -npm start +npm install @getivy/react-native-sdk # OR using Yarn -yarn start +yarn add @getivy/react-native-sdk ``` -## Step 2: Start your Application - -Let Metro Bundler run in its _own_ terminal. Open a _new_ terminal from the _root_ of your React Native project. Run the following command to start your _Android_ or _iOS_ app: +Create a personal Github access token with permission _read:packages_ and add the following in your Android application root _build.gradle_ file: -### For Android - -```bash -# using npm -npm run android - -# OR using Yarn -yarn android +``` +allprojects { + repositories { + maven { + name = "GitHub" + url = uri("https://maven.pkg.github.com/getivy/android-sdk-public") + credentials { + username = + password = + } + } + } + } ``` -### For iOS +Even though the Maven repository is public, Github requires this to be able to get the package. -```bash -# using npm -npm run ios +## Step 2: Usage -# OR using Yarn -yarn ios +Import the package: + +``` +import * as GetivySDK from '@getivy/react-native-sdk'; ``` -If everything is set up _correctly_, you should see your new app running in your _Android Emulator_ or _iOS Simulator_ shortly provided you have set up your emulator/simulator correctly. +Initialize the SDK with data session or checkout session id and environment: -This is one way to run your app — you can also run it directly from within Android Studio and Xcode respectively. +``` +// Data session +GetivySDK.initializeDataSession(dataSessionId, "production"); +``` -## Step 3: Modifying your App +``` +// Checkout session +GetivySDK.initializeCheckoutSession(checkoutSessionId, "sandbox"); +``` -Now that you have successfully run the app, let's modify it. +Possible environment values: _production_ and _sandbox_ -1. Open `App.tsx` in your text editor of choice and edit some lines. -2. For **Android**: Press the R key twice or select **"Reload"** from the **Developer Menu** (Ctrl + M (on Window and Linux) or Cmd ⌘ + M (on macOS)) to see your changes! +Open SDK UI: - For **iOS**: Hit Cmd ⌘ + R in your iOS Simulator to reload the app and see your changes! +``` +GetivySDK.openSDK(); +``` -## Congratulations! :tada: +It will open a modal view on top of your application in iOS, and new activity in Android. -You've successfully run and modified your React Native App. :partying_face: +Listen for SDK events: -### Now what? +``` +import { NativeEventEmitter } from 'react-native'; -- If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps). -- If you're curious to learn more about React Native, check out the [Introduction to React Native](https://reactnative.dev/docs/getting-started). +// Component implementation -# Troubleshooting +useEffect(() => { + const eventEmitter = new NativeEventEmitter(eventsEmitter); + const onSuccess = eventEmitter.addListener('onSuccess', (eventData) => { + Alert.alert('Success', JSON.stringify(eventData)); + }); -If you can't get this to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page. + const onError = eventEmitter.addListener('onError', (eventData) => { + Alert.alert('Error', JSON.stringify(eventData)); + }); -# Learn More + return () => { + onSuccess.remove(); + onError.remove(); + }; + }, []); +``` -To learn more about React Native, take a look at the following resources: +While going through SDK, closing, succeeding to pay or failing, events will be delivered by the listeners. -- [React Native Website](https://reactnative.dev) - learn more about React Native. -- [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment. -- [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**. -- [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts. -- [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native. +Refer to the _example_ application for more indepth usage example. diff --git a/example/src/hooks/useApiService.ts b/example/src/hooks/useApiService.ts index d75f6c5..8aa75fb 100644 --- a/example/src/hooks/useApiService.ts +++ b/example/src/hooks/useApiService.ts @@ -88,8 +88,6 @@ const getApiUrlFor = (environment: string, isDataSession: boolean): string => { switch (environment) { case 'Sandbox': return isDataSession ? Config.SAND_API_URL : Config.SAND_CHECKOUT_API_URL; - case 'Development': - return isDataSession ? Config.DEV_API_URL : Config.DEV_CHECKOUT_API_URL; case 'Production': return isDataSession ? Config.PROD_API_URL : Config.PROD_CHECKOUT_API_URL; default: @@ -101,8 +99,6 @@ const getApiKeyFor = (environment: string): string => { switch (environment) { case 'Sandbox': return Config.SAND_API_KEY; - case 'Development': - return Config.DEV_API_KEY; case 'Production': return Config.PROD_API_KEY; default: diff --git a/example/src/react-native-config.d.ts b/example/src/react-native-config.d.ts index 3d9018d..fa2f319 100644 --- a/example/src/react-native-config.d.ts +++ b/example/src/react-native-config.d.ts @@ -1,13 +1,10 @@ declare module 'react-native-config' { export interface Env { SAND_API_KEY: string; - DEV_API_KEY: string; PROD_API_KEY: string; SAND_API_URL: string; - DEV_API_URL: string; PROD_API_URL: string; SAND_CHECKOUT_API_URL: string; - DEV_CHECKOUT_API_URL: string; PROD_CHECKOUT_API_URL: string; } diff --git a/package.json b/package.json index b8c3710..adc7126 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@getivy/react-native-sdk", - "version": "1.0.1", + "version": "1.0.2", "description": "Getivy SDK for React Native", "main": "lib/commonjs/index", "module": "lib/module/index",