Skip to content

Commit

Permalink
publishable key rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharindu Kumarasiri committed Aug 19, 2024
1 parent 0858720 commit c7f4c9d
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 41 deletions.
4 changes: 3 additions & 1 deletion example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ function App(): React.JSX.Element {
<SafeAreaView style={styles.mainContainer}>
<LanguageSelectComponent language={language} setLanguage={setLanguage} />

<KomojuSDK.KomojuProvider publicKey={publishableKey} language={language}>
<KomojuSDK.KomojuProvider
publishableKey={publishableKey}
language={language}>
<PaymentScreen />
</KomojuSDK.KomojuProvider>
</SafeAreaView>
Expand Down
3 changes: 3 additions & 0 deletions example/services/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const PUBLISHABLE_KEY_URL = 'https://rn-komoju-app.glitch.me/serve-keys';
export const CREATE_SESSION_URL =
'https://rn-komoju-app.glitch.me/create-session';
4 changes: 2 additions & 2 deletions example/services/keyService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Alert} from 'react-native';
import {PUBLISHABLE_KEY_URL} from './constants';

const getPublishableKey = async () => {
try {
const url = 'https://rn-komoju-app.glitch.me/serve-keys';
const response = await fetch(url);
const response = await fetch(PUBLISHABLE_KEY_URL);
const {publishableKey} = await response.json();

return publishableKey;
Expand Down
4 changes: 2 additions & 2 deletions example/services/sessionService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Alert} from 'react-native';
import {CREATE_SESSION_URL} from './constants';

// Refer documentation on https://doc.komoju.com/reference/post_sessions
// for creating a session
Expand All @@ -13,7 +14,6 @@ const createSession = async ({
currency,
}: createSessionProps): Promise<string | null> => {
try {
const url = 'https://rn-komoju-app.glitch.me/create-session';
const options = {
method: 'POST',
headers: {
Expand All @@ -25,7 +25,7 @@ const createSession = async ({
currency,
}),
};
const response = await fetch(url, options);
const response = await fetch(CREATE_SESSION_URL, options);
const {sessionId} = await response.json();

return sessionId;
Expand Down
16 changes: 8 additions & 8 deletions payment_sdk/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { KomojuSDK } from "@komoju/komoju-react-native";

function App() {
return (
<KomojuSDK.KomojuProvider publicKey={PUBLIC_KEY}>
<KomojuSDK.KomojuProvider publishableKey={PUBLISHABLE_KEY}>
<PaymentScreen />
</KomojuSDK.KomojuProvider>
);
Expand Down Expand Up @@ -78,7 +78,7 @@ When a customer exits your app, for example to authenticate in Safari or their b
To initialize Komoju in your React Native app, use the `KomojuSDK.KomojuProvider` component in the root component of your application.

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

```tsx
import {
Expand All @@ -88,20 +88,20 @@ import {
} from "@komoju/komoju-react-native";

function App() {
const [publicKey, setPublicKey] = useState("");
const [publishableKey, setpublishableKey] = useState("");

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

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

return (
<KomojuSDK.KomojuProvider
publicKey={publicKey}
publishableKey={publishableKey}
paymentMethods={[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
>
Expand All @@ -115,6 +115,6 @@ function App() {

| property | type | description |
| ------------------ | ------------------------ | ------------------------------------------------------------------------------------------------------------- |
| **publicKey** | `string` | Your publishable key from the KOMOJU [merchant settings page](https://komoju.com/sign_in/) (this is mandtory) |
| **publishableKey** | `string` | Your publishable key from the KOMOJU [merchant settings page](https://komoju.com/sign_in/) (this is mandtory) |
| **paymentMethods** | `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) |
2 changes: 1 addition & 1 deletion payment_sdk/src/__tests__/CardSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const mockState = {
cardholderName: "John Doe",
cardCVV: "123",
cardNumber: "4100000000000100",
cardExpiredDate: "08/25",
cardExpiredDate: "08 / 25",
amount: 1000,
currency: "USD",
};
Expand Down
2 changes: 1 addition & 1 deletion payment_sdk/src/__tests__/paymentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PaymentType } from "../util/types";
global.fetch = jest.fn();

const paymentDetails = {
publicKey: "samplepublickKey",
publishableKey: "samplepublishablekKey",
sessionId: "sessionID123",
paymentType: PaymentType.CREDIT,
paymentDetails: {
Expand Down
2 changes: 1 addition & 1 deletion payment_sdk/src/context/KomojuProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const KomojuProvider = (props: KomojuProviderIprops) => {
<StateProvider>
<ThemeProvider>
<MainStateProvider
publicKey={props.publicKey}
publishableKey={props.publishableKey}
paymentMethods={props?.paymentMethods}
language={props?.language}
useBottomSheet={props?.useBottomSheet}
Expand Down
8 changes: 4 additions & 4 deletions payment_sdk/src/context/MainStateProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {
const onUserCancel = async () => {
if (onDismissCallback.current) {
const sessionShowPayload = {
publicKey: props?.publicKey,
publishableKey: props?.publishableKey,
sessionId: sessionIdRef.current,
};

Expand Down Expand Up @@ -135,7 +135,7 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {
// Fetching session data from given session ID
const sessionData = await sessionShow({
sessionId,
publicKey: props.publicKey,
publishableKey: props.publishableKey,
});

// validating the session data and closing the payment gateway if data is not valid
Expand Down Expand Up @@ -180,7 +180,7 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {

// if this is a session flow, check until session response changes from 'pending' to 'completed' or 'error'
const sessionShowPayload = {
publicKey: props.publicKey,
publishableKey: props.publishableKey,
sessionId: sessionIdRef.current,
};

Expand Down Expand Up @@ -221,7 +221,7 @@ export const MainStateProvider = (props: KomojuProviderIprops) => {
const response = await payForSession({
paymentType,
sessionId,
publicKey: props.publicKey,
publishableKey: props.publishableKey,
paymentDetails,
});

Expand Down
6 changes: 3 additions & 3 deletions payment_sdk/src/services/payForSessionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
/**
* Processes a payment for a given session.
* @param {object} params - The parameters for processing the payment.
* @param {string} params.publicKey - The public key for authorization.
* @param {string} params.publishableKey - The publishable key for authorization.
* @param {string} params.sessionId - The session ID for the payment.
* @param {PaymentType} params.paymentType - The type of payment to process.
* @param {object} params.paymentDetails - The details of the relevant payment type.
Expand All @@ -23,7 +23,7 @@ import {
*/

const payForSession = async ({
publicKey,
publishableKey,
sessionId,
paymentType,
paymentDetails,
Expand Down Expand Up @@ -115,7 +115,7 @@ const payForSession = async ({
// payment POST request options of headers and body should be as bellow
const options = {
method: "POST",
headers: API_HEADER(publicKey),
headers: API_HEADER(publishableKey),
body: JSON.stringify({
capture: "auto",
payment_details,
Expand Down
6 changes: 3 additions & 3 deletions payment_sdk/src/services/sessionShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { SessionShowResponseType } from "@util/types";

type SessionShowProps = {
sessionId: string;
publicKey: string;
publishableKey: string;
};

const sessionShow = async ({
sessionId,
publicKey,
publishableKey,
}: SessionShowProps): Promise<SessionShowResponseType | null> => {
try {
const url = `${BASE_URL_API}/sessions/${sessionId}`;
const options = {
method: "GET",
headers: API_HEADER(publicKey),
headers: API_HEADER(publishableKey),
};

const response = await fetch(url, options);
Expand Down
9 changes: 4 additions & 5 deletions payment_sdk/src/util/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PaymentType } from "./types";

export const noop = () => { };
export const noop = () => {};
export const BASE_URL = "https://komoju.com";
export const BASE_URL_API = `${BASE_URL}/api/v1`;
export const API_HEADER = (publicKey: string) => ({
export const API_HEADER = (publishableKey: string) => ({
accept: "application/json",
"content-type": "application/json",
"KOMOJU-VIA": "mobile_react",
Authorization: `Basic ${btoa(publicKey + ":")}`,
Authorization: `Basic ${btoa(publishableKey + ":")}`,
});

export const paymentSuccessCtaText = "BACK_TO_STORE";
Expand All @@ -34,7 +34,7 @@ export enum SimpleRedirectTypeModes {
linepay = "LINE_PAY",
merpay = "MER_PAY",
rakuten = "RAKUTEN",
aupay = "AU_PAY"
aupay = "AU_PAY",
}

export const LangKeys: { [key in PaymentType]: string } = {
Expand All @@ -52,5 +52,4 @@ export const LangKeys: { [key in PaymentType]: string } = {
[PaymentType.RAKUTEN]: "RAKUTEN",
[PaymentType.WEB_MONEY]: "WEB_MONEY",
[PaymentType.NET_CASH]: "NET_CASH",

};
4 changes: 2 additions & 2 deletions payment_sdk/src/util/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dispatch, ReactNode, SetStateAction } from "react";

export type InitPrams = {
publicKey: string;
publishableKey: string;
paymentMethods?: Array<PaymentType>;
language?: LanguageTypes;
useBottomSheet?: boolean;
Expand Down Expand Up @@ -103,7 +103,7 @@ export enum CurrencyTypes {
}

export type payForSessionProps = {
publicKey: string;
publishableKey: string;
sessionId: string;
paymentType: PaymentType;
paymentDetails?: CardDetailsType &
Expand Down
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { KomojuSDK } from "@komoju/komoju-react-native";

function App() {
return (
<KomojuSDK.KomojuProvider publicKey={PUBLIC_KEY}>
<KomojuSDK.KomojuProvider publishable={PUBLISHABLE_KEY}>
<PaymentScreen />
</KomojuSDK.KomojuProvider>
);
Expand Down Expand Up @@ -78,7 +78,7 @@ When a customer exits your app, for example to authenticate in Safari or their b
To initialize Komoju in your React Native app, use the `KomojuSDK.KomojuProvider` component in the root component of your application.

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

```tsx
import {
Expand All @@ -88,20 +88,20 @@ import {
} from "@komoju/komoju-react-native";

function App() {
const [publicKey, setPublicKey] = useState("");
const [publishableKey, setpublishableKey] = useState("");

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

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

return (
<KomojuSDK.KomojuProvider
publicKey={publicKey}
publishableKey={publishableKey}
paymentMethods={[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
>
Expand All @@ -115,6 +115,6 @@ function App() {

| property | type | description |
| ------------------ | ------------------------ | ------------------------------------------------------------------------------------------------------------- |
| **publicKey** | `string` | Your publishable key from the KOMOJU [merchant settings page](https://komoju.com/sign_in/) (this is mandtory) |
| **publishableKey** | `string` | Your publishable key from the KOMOJU [merchant settings page](https://komoju.com/sign_in/) (this is mandtory) |
| **paymentMethods** | `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) |

0 comments on commit c7f4c9d

Please sign in to comment.