Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task >> code documentation improvements #15

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions payment_sdk/src/components/paymentState/stateProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import React, { ReactNode, useReducer } from "react";
import { DispatchContext, StateContext, reducer } from "../../state";
import { initialState } from "../../util/types";

/**
* StateProvider component to provide state and dispatch contexts to its children.
* @param {object} props - The props for the StateProvider component.
* @param {ReactNode | ReactNode[]} [props.children] - The children components to be wrapped by the provider.
* @returns {JSX.Element} The StateProvider component.
*/

const StateProvider = ({
children,
}: {
Expand Down
6 changes: 6 additions & 0 deletions payment_sdk/src/components/sections/CardSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { formatCurrency } from "../../util/helpers";

type Props = {};

/**
* CardSection component for displaying and handling the card payment form.
* @param {Props} props - The props for the CardSection component.
* @returns {JSX.Element} The CardSection component.
*/

const CardSection = (props: Props) => {
const {
sessionPay,
Expand Down
19 changes: 16 additions & 3 deletions payment_sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ import { useContext } from "react";
import { KomojuProvider } from "./KomojuProvider";
import { KomojuContext } from "./state";

/**
* KomojuSDK provides context utilities for the Komoju payment system.
*/
export const KomojuSDK = {
useKomoju: () => useContext(KomojuContext), // for functional components use this
komojuConsumer: KomojuContext.Consumer, // for class components use this
KomojuProvider: KomojuProvider, // wrap the react native entry point with this
/**
* Custom hook to use the Komoju context in functional components.
* @returns {object} The Komoju context.
*/
useKomoju: () => useContext(KomojuContext),
/**
* Context consumer component for use in class components.
*/
komojuConsumer: KomojuContext.Consumer,
/**
* Provider component to wrap around the React Native entry point, ensuring the context is available throughout the app.
*/
KomojuProvider: KomojuProvider,
};
14 changes: 14 additions & 0 deletions payment_sdk/src/services/paymentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import { BASE_URL } from "../util/constants";
import { getMonthYearFromExpiry, printLog } from "../util/helpers";
import { payForSessionProps, PaymentType } from "../util/types";

/**
* 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.sessionId - The session ID for the payment.
* @param {PaymentType} params.paymentType - The type of payment to process.
* @param {object} params.cardDetails - The details of the card for credit card payments.
* @param {string} params.cardDetails.cardholderName - The name of the cardholder.
* @param {string} params.cardDetails.cardNumber - The card number.
* @param {string} params.cardDetails.cardExpiredDate - The expiration date of the card.
* @param {string} params.cardDetails.cardCVV - The CVV of the card.
* @returns {Promise<object|null>} The response data from the payment API or null if an error occurs.
*/

const payForSession = async ({
publicKey,
sessionId,
Expand Down
36 changes: 35 additions & 1 deletion payment_sdk/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
initialState,
} from "./util/types";

/**
* Action types for the reducer
*/

export const Actions = {
SET_CARDHOLDER_NAME: "SET_CARDHOLDER_NAME",
SET_CARD_NUMBER: "SET_CARD_NUMBER",
Expand All @@ -24,7 +28,13 @@ export const Actions = {
SESSION_PAY: "SESSION_PAY",
};

// Define the reducer function
/**
* Reducer function to manage the state of the payment system.
* @param {State} state - The current state.
* @param {ActionType} action - The action to be processed.
* @returns {State} The new state after applying the action.
*/

export function reducer(state: State, action: ActionType) {
switch (action.type) {
case Actions.SET_PAYMENT_OPTION:
Expand Down Expand Up @@ -82,16 +92,40 @@ export function reducer(state: State, action: ActionType) {
}
}
const defaultValue = {
/**
* Function to create a payment session.
* @param {CreatePaymentFuncType} data - The data for creating a payment session.
*/
createPayment: (data: CreatePaymentFuncType) => {},
/**
* Function to display the payment sheet UI.
*/
showPaymentSheetUI: noop,
/**
* Function to initialize Komoju without relying on props.
* @param {InitPrams} data - The initialization parameters.
*/
initializeKomoju: (data: InitPrams) => {},
};
/**
* State context for the Komoju payment system.
* @type {React.Context<State>}
*/

export const StateContext = createContext(initialState);
/**
* Dispatch context for the Komoju payment system.
* @type {React.Context<(action: ActionType) => ActionType>}
*/
export const DispatchContext = createContext(
({ type, payload }: ActionType) => ({
type,
payload,
})
);

/**
* Komoju context providing default functions for payment operations.
* @type {React.Context<typeof defaultValue>}
*/
export const KomojuContext = createContext(defaultValue);
Loading