Skip to content

Commit

Permalink
chore: cleanup and README update
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuskurgonasativy committed Feb 26, 2024
1 parent ec033f6 commit 3daa2fc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 58 deletions.
3 changes: 0 additions & 3 deletions example/.env.example
Original file line number Diff line number Diff line change
@@ -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
108 changes: 61 additions & 47 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -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 = <Github_username>
password = <Github_token>
}
}
}
}
```

### 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 <kbd>R</kbd> key twice or select **"Reload"** from the **Developer Menu** (<kbd>Ctrl</kbd> + <kbd>M</kbd> (on Window and Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (on macOS)) to see your changes!
Open SDK UI:

For **iOS**: Hit <kbd>Cmd ⌘</kbd> + <kbd>R</kbd> 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.
4 changes: 0 additions & 4 deletions example/src/hooks/useApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions example/src/react-native-config.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 3daa2fc

Please sign in to comment.