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

update(examples, docs): example for better readability, and add doc web contents #1

Merged
merged 4 commits into from
Dec 9, 2023
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
69 changes: 22 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ To get started, import the necessary modules and configure the SDK with your cre
```typescript
import { config } from 'dotenv';
import express from 'express';
import { HandlerName, ConfigObject, getPaymentHandler} from 'marupay';
import { HandlerName, ConfigObject, getPaymentHandler } from 'marupay';
import { env } from 'process';

// Load environment variables from a .env file
config();

const app = express();
const port = 3002;

app.use(express.urlencoded({ extended: true }));

const marupayConfiguration: ConfigObject = {
// Configuration for different payment handlers (e.g., edahab, waafi)
const paymentConfig: ConfigObject = {
edahab: {
apiKey: env.DAHAB_API_KEY!,
secretKey: env.DAHAB_SECRET_KEY!,
Expand All @@ -45,80 +49,51 @@ const marupayConfiguration: ConfigObject = {
},
};

// Choose a payment handler
const chosenHandler: HandlerName = 'edahab';
const chosenHandler2: HandlerName = 'waafi';

app.get('/purchaseEdahab', async (req, res) => {
try {
const handler = getPaymentHandler(chosenHandler)(marupayConfiguration[chosenHandler]!);

const paymentInfo = await handler.request({
accountNumber: "651234567",
amount: 500,
currency: "SLSH",
description: "test payment",
});

res.send(paymentInfo);
} catch (e) {
console.log(e);
}
});

app.get('/purchaseWaafi', async (req, res) => {
app.get('/purchase', async (req, res) => {
try {
const handler = getPaymentHandler(chosenHandler2)(marupayConfiguration[chosenHandler2]!);
// Get the payment handler based on the chosen handler
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);

// Make a purchase request
const paymentInfo = await handler.request({
accountNumber: "252612345678",
accountNumber: "6512312341",
amount: 500,
currency: "SLSH",
description: "test payment",
accountType: 'CUSTOMER',
});

res.send(paymentInfo);
} catch (e) {
console.log(e);
}
});

app.get('/creditEdahab', async (req, res) => {
try {
const handler = getPaymentHandler(chosenHandler)(marupayConfiguration[chosenHandler]!);

const paymentInfo = await handler.credit({
accountNumber: "651234567,
amount: 1000,
currency: "SLSH",
description: "test payment",
description: "Test purchase",
});

res.send(paymentInfo);
} catch (e) {
console.log(e);
res.status(500).send("Internal Server Error");
}
});

app.get('/creditWaafi', async (req, res) => {
app.get('/credit', async (req, res) => {
try {
const handler = getPaymentHandler(chosenHandler2)(marupayConfiguration[chosenHandler2]!);
// Get the payment handler based on the chosen handler
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);

// Credit an account
const paymentInfo = await handler.credit({
accountNumber: "2526312345678",
accountNumber: "6512312341",
amount: 1000,
currency: "SLSH",
description: "test payment",
description: "Test credit",
});

res.send(paymentInfo);
} catch (e) {
console.log(e);
res.status(500).send("Internal Server Error");
}
});

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
console.log(`Server is listening at http://localhost:${port}`);
});
```

Expand Down
9 changes: 0 additions & 9 deletions apps/docs/.eslintrc.js

This file was deleted.

2 changes: 2 additions & 0 deletions apps/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next
node_modules
21 changes: 21 additions & 0 deletions apps/docs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Shu Ding

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 15 additions & 16 deletions apps/docs/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
## Getting Started
# About MaruPay

## Overview

First, run the development server:
MaruPay is a versatile payment processing SDK designed to simplify the integration process with multiple payment systems in your applications. With MaruPay, developers can easily handle various payment operations, including purchases and account crediting, using a unified and straightforward interface.

```bash
yarn dev
```
## Key Features

Open [http://localhost:3001](http://localhost:3001) with your browser to see the result.
### Flexibility

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
MaruPay offers flexibility by supporting integration with different payment handlers. Whether you are dealing with edahab, waafi, or other systems, MaruPay streamlines the process, allowing you to focus on building robust and secure payment solutions.

To create [API routes](https://nextjs.org/docs/app/building-your-application/routing/router-handlers) add an `api/` directory to the `app/` directory with a `route.ts` file. For individual endpoints, create a subfolder in the `api` directory, like `api/hello/route.ts` would map to [http://localhost:3001/api/hello](http://localhost:3001/api/hello).
### Easy Configuration

## Learn More
Configuring MaruPay is a breeze. You can set up payment handlers with specific API keys, secret keys, and merchant IDs, ensuring a seamless and secure connection to various payment systems.

To learn more about Next.js, take a look at the following resources:
### Express Integration

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn/foundations/about-nextjs) - an interactive Next.js tutorial.
MaruPay integrates seamlessly with Express.js, a popular web application framework for Node.js. This integration simplifies the process of building web applications that require payment processing capabilities.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Purpose

## Deploy on Vercel
MaruPay aims to empower developers by providing a reliable and easy-to-use SDK for handling payments. Whether you are building an e-commerce platform, a donation system, or any application that involves financial transactions, MaruPay is designed to facilitate the integration of diverse payment systems.

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js.
## Getting Started

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
To get started with MaruPay, refer to the [Installation](installation.md) and [Configuration](configuration.md) sections in the documentation. The [Full Guide](guide.md) section provides a complete walkthrough of integrating MaruPay into an Express.js application.
Binary file removed apps/docs/app/favicon.ico
Binary file not shown.
50 changes: 0 additions & 50 deletions apps/docs/app/globals.css

This file was deleted.

22 changes: 0 additions & 22 deletions apps/docs/app/layout.tsx

This file was deleted.

Loading
Loading