Skip to content

Commit

Permalink
Merge pull request #31 from degica/task/issue-fixing
Browse files Browse the repository at this point in the history
Task/issue fixing
  • Loading branch information
tharindu-rhino authored Jul 15, 2024
2 parents b770d3d + 1997b97 commit ed0f507
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 303 deletions.
4 changes: 2 additions & 2 deletions example/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
envName: 'APP_ENV',
moduleName: '@env',
path: '.env',
}],
['react-native-worklets-core/plugin']
}]
// ['react-native-worklets-core/plugin']
],
};
132 changes: 66 additions & 66 deletions example/ios/example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<EnvironmentVariable
key = "IDEPreferLogStreaming"
value = "YES"
isEnabled = "YES">
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "jest"
},
"dependencies": {
"@komoju/komoju-react-native": "0.0.1",
"@komoju/komoju-react-native": "0.0.3",
"i18next": "^23.11.5",
"react": "18.2.0",
"react-i18next": "^14.1.2",
Expand Down
14 changes: 3 additions & 11 deletions payment_sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@komoju/komoju-react-native",
"version": "0.0.1",
"version": "0.0.3",
"private": false,
"description": "degica payment SDK",
"main": "dist/index.js",
Expand Down Expand Up @@ -52,15 +52,10 @@
"jest": "^29.7.0",
"react": "18.2.0",
"react-native": "0.74.1",
"react-native-gesture-handler": "^2.16.2",
"react-native-reanimated": "^3.11.0",
"react-test-renderer": "^18.2.0",
"ts-jest": "^29.1.4",
"typescript": "^5.4.5",
"typescript-eslint": "^7.12.0",
"react-native-vision-camera": "^4.3.2",
"react-native-vision-camera-text-recognition": "^3.0.4",
"react-native-worklets-core": "^1.3.3"
"typescript-eslint": "^7.12.0"
},
"dependencies": {
"i18next": "^23.11.5",
Expand All @@ -73,9 +68,6 @@
},
"peerDependencies": {
"react": "*",
"react-native": "*",
"react-native-vision-camera": "^4.3.2",
"react-native-vision-camera-text-recognition": "^3.0.4",
"react-native-worklets-core": "^1.3.3"
"react-native": "*"
}
}
107 changes: 107 additions & 0 deletions payment_sdk/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

# Komoju SDK for React Native

[![NPM Version](https://img.shields.io/npm/v/%40komoju%2Fkomoju-react-native)](https://www.npmjs.com/package/@komoju/komoju-react-native)
[![License](https://img.shields.io/npm/l/%40komoju%2Fkomoju-react-native)](https://www.npmjs.com/package/@komoju/komoju-react-native)

**Welcome to the Komoju Payment Gateway SDK!** This SDK empowers you to seamlessly integrate secure payment processing into your Android and iOS apps using React Native.

## Getting Started
Get started with our
[Developer-oriented API documentation](https://doc.komoju.com/) or [example project](https://github.com/degica/mobile-sdk_react-native/tree/main/example)

## Installation

```sh
yarn add @komoju/komoju-react-native
or
npm install @komoju/komoju-react-native
```


> ### *In order to use the SDK you will have to install bellow packages as dependancies.*
```sh
i18next
react-i18next
react-native-svg
react-native-webview
```

## Usage example
```tsx
// App.ts
import { KomojuSDK } from '@komoju/komoju-react-native';

function App() {
return (
<KomojuSDK.KomojuProvider
publicKey={PUBLIC_KEY}
>
<PaymentScreen />
</KomojuSDK.KomojuProvider>
);
}

// PaymentScreen.ts
import { KomojuSDK } from '@komoju/komoju-react-native';

export default function PaymentScreen() {
const { createPayment } = KomojuSDK.useKomoju();

const checkout = async () => {
createPayment({
sessionId, // retrieve this from your server
onComplete, // (optional) pass a callback to get the final results of response when payment is complete
});
};

return (
<View>
<Button title="Checkout" onPress={checkout} />
</View>
);
}
```

## Komoju initialization

You can [visit our docs](https://doc.komoju.com/reference/createsession) to see how a session id can be created

To initialize Komoju in your React Native app, use the `KomojuSDK.KomojuProvider` component in the root component of your application.

`KomojuProvider` can accept `publicKey`, `payment_methods` and `language` as props. Only `publicKey` is required.

```tsx
import { KomojuSDK, PaymentTypes, LanguageTypes} from '@komoju/komoju-react-native';

function App() {
const [publicKey, setPublicKey] = useState('');

const fetchPublicKey = async () => {
const key = await fetchKey(); // fetch key from your server here
setPublicKey(key);
};

useEffect(() => {
fetchPublicKey();
}, []);

return (
<KomojuSDK.KomojuProvider
publicKey={publicKey}
payment_methods={[PaymentTypes.KONBINI]} // explicitly set the payment method(s) for purchase
language={LanguageTypes.JAPANESE} // explicitly set the language, if not set language will be picked from your session Id
>
// Your app code here
</KomojuSDK.KomojuProvider>
);
}
```

### Properties

| property | type | description |
| ------------------ | -------------------------------------------- | ------------------------------------------------------------- |
| **publicKey** | `string` | Your publishable key from the KOMOJU [merchant settings page](https://komoju.com/sign_in/) (this is mandtory) |
| **payment_methods**| `Array <PaymentTypes>` | explicitly set the payment method(s) for purchase. (optional) |
| **language** | `string (LanguageTypes)` | explicitly set the language, if not set language will be picked from your session Id (optional) |
22 changes: 11 additions & 11 deletions payment_sdk/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
global.__DEV__ = process.env.NODE_ENV !== "production";

jest.mock('react-native-vision-camera', () => ({
Camera: 'mockCamera',
useCameraDevices: jest.fn(),
useFrameProcessor: jest.fn(),
}));
// jest.mock('react-native-vision-camera', () => ({
// Camera: 'mockCamera',
// useCameraDevices: jest.fn(),
// useFrameProcessor: jest.fn(),
// }));

jest.mock('react-native-vision-camera-text-recognition', () => ({
useTextRecognition: jest.fn(),
}));
// jest.mock('react-native-vision-camera-text-recognition', () => ({
// useTextRecognition: jest.fn(),
// }));

jest.mock('react-native-worklets-core', () => ({
Worklets: jest.fn(),
}));
// jest.mock('react-native-worklets-core', () => ({
// Worklets: jest.fn(),
// }));
143 changes: 67 additions & 76 deletions payment_sdk/src/components/CardInputGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { PaymentType, sessionShowPaymentMethodType } from "@util/types";
import { isCardNumberValid, validateCardExpiry } from "@util/validator";

import CardScanner from "./CardScanner";
// import CardScanner from "./CardScanner";
import Input from "./Input";
import KomojuText from "./KomojuText";
// import ScanCardButton from "./ScanCardButton";
Expand All @@ -45,7 +45,7 @@ const CARD_HEIGHT = 30;
const CardInputGroup = ({ inputErrors, resetError }: Props) => {
const dispatch = useContext(DispatchContext);
const [cardType, setCardType] = useState<string | null>(null);
const [toggleScanCard, setToggleScanCard] = useState<boolean>(false);
// const [toggleScanCard, setToggleScanCard] = useState<boolean>(false);
const { cardCVV, cardNumber, cardExpiredDate, paymentMethods } =
useContext(StateContext);

Expand Down Expand Up @@ -96,102 +96,93 @@ const CardInputGroup = ({ inputErrors, resetError }: Props) => {
}
}, [cardType, paymentMethods]);

const onCardScanned = useCallback(
(cardDetails: { cardNumber?: string; expirationDate?: string }) => {
dispatch({
type: Actions.SET_CARD_NUMBER,
payload: cardDetails.cardNumber,
});
dispatch({
type: Actions.SET_CARD_EXPIRED_DATE,
payload: cardDetails.expirationDate,
});
setToggleScanCard(false);
},
[]
);
// const onCardScanned = useCallback(
// (cardDetails: { cardNumber?: string; expirationDate?: string }) => {
// dispatch({
// type: Actions.SET_CARD_NUMBER,
// payload: cardDetails.cardNumber,
// });
// dispatch({
// type: Actions.SET_CARD_EXPIRED_DATE,
// payload: cardDetails.expirationDate,
// });
// setToggleScanCard(false);
// },
// []
// );

return (
<View style={styles.parentContainer}>
<View style={styles.titleScanRow}>
<KomojuText style={styles.label}>CARD_NUMBER</KomojuText>
{/* <ScanCardButton onPress={toggleCardScanner} /> */}
</View>
{toggleScanCard ? (
<View style={styles.scanContainer}>
<CardScanner
isVisible={toggleScanCard}
onCardScanned={onCardScanned}
<View style={styles.container}>
<View style={styles.cardNumberRow}>
<Input
value={cardNumber ?? ""}
testID="cardNumberInput"
keyboardType="number-pad"
placeholder="1234 1234 1234 1234"
onChangeText={(text: string) => {
resetError("number");
if (isCardNumberValid(text)) {
const derivedText = formatCreditCardNumber(text);
dispatch({
type: Actions.SET_CARD_NUMBER,
payload: derivedText,
});
// Determine card type and set it
const type = determineCardType(text);
setCardType(type);
}
}}
inputStyle={styles.numberInputStyle}
error={inputErrors.number}
/>
<View style={styles.cardContainer}>{cardImage()}</View>
</View>
) : (
<View style={styles.container}>
<View style={styles.cardNumberRow}>
<View style={styles.splitRow}>
<View style={styles.itemRow}>
<Input
value={cardNumber ?? ""}
testID="cardNumberInput"
value={cardExpiredDate as string}
keyboardType="number-pad"
placeholder="1234 1234 1234 1234"
testID="cardExpiryInput"
placeholder="MM / YY"
onChangeText={(text: string) => {
resetError("number");
if (isCardNumberValid(text)) {
const derivedText = formatCreditCardNumber(text);
resetError("expiry");
if (validateCardExpiry(text)) {
dispatch({
type: Actions.SET_CARD_NUMBER,
payload: derivedText,
type: Actions.SET_CARD_EXPIRED_DATE,
payload: formatExpiry(text),
});
// Determine card type and set it
const type = determineCardType(text);
setCardType(type);
}
}}
inputStyle={styles.numberInputStyle}
error={inputErrors.number}
inputStyle={styles.expiryInputStyle}
error={inputErrors.expiry}
/>
<View style={styles.cardContainer}>{cardImage()}</View>
</View>
<View style={styles.splitRow}>
<View style={styles.itemRow}>
<Input
value={cardExpiredDate as string}
keyboardType="number-pad"
testID="cardExpiryInput"
placeholder="MM / YY"
onChangeText={(text: string) => {
resetError("expiry");
if (validateCardExpiry(text)) {
dispatch({
type: Actions.SET_CARD_EXPIRED_DATE,
payload: formatExpiry(text),
});
}
}}
inputStyle={styles.expiryInputStyle}
error={inputErrors.expiry}
/>
</View>
<View style={styles.itemRow}>
<Input
value={cardCVV as string}
testID="cardCVVInput"
keyboardType="number-pad"
placeholder="CVV"
onChangeText={(text: string) => {
resetError("cvv");
<View style={styles.itemRow}>
<Input
value={cardCVV as string}
testID="cardCVVInput"
keyboardType="number-pad"
placeholder="CVV"
onChangeText={(text: string) => {
resetError("cvv");

if (text?.length < 11)
dispatch({ type: Actions.SET_CARD_CVV, payload: text });
}}
inputStyle={styles.cvvInputStyle}
error={inputErrors.cvv}
/>
<View style={styles.cardContainer}>
{renderSvg(STATIC_CREDIT_CARD_CVC_SVG)}
</View>
if (text?.length < 11)
dispatch({ type: Actions.SET_CARD_CVV, payload: text });
}}
inputStyle={styles.cvvInputStyle}
error={inputErrors.cvv}
/>
<View style={styles.cardContainer}>
{renderSvg(STATIC_CREDIT_CARD_CVC_SVG)}
</View>
</View>
</View>
)}
</View>
</View>
);
};
Expand Down
Loading

0 comments on commit ed0f507

Please sign in to comment.