Skip to content

Commit

Permalink
Merge pull request #11 from iamshabell/dev
Browse files Browse the repository at this point in the history
add: currency enums for requests
  • Loading branch information
iamshabell authored Dec 11, 2023
2 parents 7a9ddb7 + 454be02 commit c4e1f59
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/docs/pages/guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ To start using the MaruPay SDK in your application, the first step is to configu
```typescript
import { config } from 'dotenv';
import express from 'express';
import { HandlerName, ConfigObject, getPaymentHandler } from 'marupay';
import { HandlerName, ConfigObject, getPaymentHandler, Currency } from 'marupay';
import { env } from 'process';

// Load environment variables from a .env file
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/pages/guide/credit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.get('/purchase', async (req, res) => {
const paymentInfo = await handler.request({
accountNumber: "6512312341",
amount: 500,
currency: "SLSH",
currency: Currency.SLSH,
description: "Test purchase",
accountType: 'CUSTOMER'
});
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/pages/guide/purchase.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ app.get('/credit', async (req, res) => {
const paymentInfo = await handler.request({
accountNumber: "6512312341",
amount: 500,
currency: "SLSH",
currency: Currency.SLSH,
description: "Test purchase",
});

Expand Down
6 changes: 3 additions & 3 deletions examples/express-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from 'dotenv';
import express from 'express';
import { HandlerName, ConfigObject, getPaymentHandler } from 'marupay';
import { HandlerName, ConfigObject, getPaymentHandler, Currency } from 'marupay';
import { env } from 'process';

// Load environment variables from a .env file
Expand Down Expand Up @@ -37,7 +37,7 @@ app.get('/purchase', async (req, res) => {
const paymentInfo = await handler.request({
accountNumber: "6512312341",
amount: 500,
currency: "SLSH",
currency: Currency.SLSH,
description: "Test purchase",
});

Expand All @@ -57,7 +57,7 @@ app.get('/credit', async (req, res) => {
const paymentInfo = await handler.credit({
accountNumber: "6512312341",
amount: 1000,
currency: "SLSH",
currency: Currency.SLSH,
description: "Test credit",
});

Expand Down
5 changes: 3 additions & 2 deletions packages/marupay/src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Currency } from './handlers/enums';
import { safeParse } from './utils/safeParser';
import { z, ZodSchema } from 'zod';

Expand All @@ -11,9 +12,9 @@ export const baseConfigSchema = z.object({});
export type BaseConfigOptions = z.infer<typeof baseConfigSchema>;

export const baseRequestSchema = z.object({
accountNumber: z.string().regex(new RegExp(/^252\d{9}$/), 'Invalid Account Number'),
accountNumber: z.string(),
amount: z.number(),
currency: z.string(),
currency: z.nativeEnum(Currency),
description: z.string().optional(),
});

Expand Down
4 changes: 4 additions & 0 deletions packages/marupay/src/handlers/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Currency {
USD = 'USD',

Check warning on line 2 in packages/marupay/src/handlers/enums.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'USD' is defined but never used

Check warning on line 2 in packages/marupay/src/handlers/enums.ts

View workflow job for this annotation

GitHub Actions / Release

'USD' is defined but never used
SLSH = 'SLSH'

Check warning on line 3 in packages/marupay/src/handlers/enums.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'SLSH' is defined but never used

Check warning on line 3 in packages/marupay/src/handlers/enums.ts

View workflow job for this annotation

GitHub Actions / Release

'SLSH' is defined but never used
};
3 changes: 2 additions & 1 deletion packages/marupay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './handlers';
export * from './handlers/config'
export * from './handlers/config'
export * from './handlers/enums'

0 comments on commit c4e1f59

Please sign in to comment.