Skip to content

Commit 68d98c6

Browse files
committed
update: package readme
1 parent 5e5f785 commit 68d98c6

File tree

1 file changed

+62
-59
lines changed

1 file changed

+62
-59
lines changed

packages/marupay/README.md

+62-59
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
[![CI](https://github.com/iamshabell/marupay/actions/workflows/main.yml/badge.svg)](https://github.com/iamshabell/marupay/actions/workflows/main.yml)
1+
[![CI](https://github.com/iamshabell/marupay/actions/workflows/main.yml/badge.svg)](https://github.com/iamshabell/marupay/actions/workflows/main.yml) [![npm version](https://img.shields.io/npm/v/marupay.svg?color=0c0)](https://www.npmjs.com/package/marupay)
22

33
# Marupay SDK
44

5-
The Marupay SDK is a npm library that provides an easy-to-use interface for integrating with the multiple payment systems.
5+
The Marupay SDK is a npm library that provides an easy-to-use interface for integrating with the multiple payment systems.
66

77
## This SDK offers
8+
89
- Edahab API
910
- Waafi API
1011

11-
1212
## Installation
1313

1414
To use the Marupay SDK in your project, you can install it using npm:
@@ -22,10 +22,10 @@ npm install marupay
2222
To get started, import the necessary modules and configure the SDK with your credentials. The following example demonstrates how to set up the SDK for both eDahab and Waafi:
2323

2424
```typescript
25-
import { config } from 'dotenv';
26-
import express from 'express';
27-
import { HandlerName, ConfigObject, getPaymentHandler, Currency } from 'marupay';
28-
import { env } from 'process';
25+
import { config } from "dotenv";
26+
import express from "express";
27+
import { HandlerName, ConfigObject, getPaymentHandler, Currency } from "marupay";
28+
import { env } from "process";
2929

3030
// Load environment variables from a .env file
3131
config();
@@ -37,67 +37,68 @@ app.use(express.urlencoded({ extended: true }));
3737

3838
// Configuration for different payment handlers (e.g., edahab, waafi)
3939
const paymentConfig: ConfigObject = {
40-
edahab: {
41-
apiKey: env.DAHAB_API_KEY!,
42-
secretKey: env.DAHAB_SECRET_KEY!,
43-
merchantId: env.DAHAB_AGENT_CODE!,
44-
},
45-
waafi: {
46-
apiKey: env.WAAFI_API_KEY!,
47-
secretKey: env.WAAFI_API_USER_ID!,
48-
merchantId: env.WAAFI_MERCHANT_KEY!,
49-
},
40+
edahab: {
41+
apiKey: env.DAHAB_API_KEY!,
42+
secretKey: env.DAHAB_SECRET_KEY!,
43+
merchantId: env.DAHAB_AGENT_CODE!,
44+
},
45+
waafi: {
46+
apiKey: env.WAAFI_API_KEY!,
47+
secretKey: env.WAAFI_API_USER_ID!,
48+
merchantId: env.WAAFI_MERCHANT_KEY!,
49+
},
5050
};
5151

5252
// Choose a payment handler
53-
const chosenHandler: HandlerName = 'edahab';
54-
55-
app.get('/purchase', async (req, res) => {
56-
try {
57-
// Get the payment handler based on the chosen handler
58-
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);
59-
60-
// Make a purchase request
61-
const paymentInfo = await handler.purchase({
62-
accountNumber: "+2526512312341", // must start with `+` followed by country code
63-
amount: 500,
64-
currency: Currency.SLSH,
65-
description: "Test purchase",
66-
// for web handlers, you can optionally provide a return URL
67-
returnUrl: "https://example.com/return",
68-
});
69-
70-
res.send(paymentInfo);
71-
} catch (e) {
72-
console.log(e);
73-
res.status(500).send("Internal Server Error");
74-
}
53+
const chosenHandler: HandlerName = "edahab";
54+
55+
app.get("/purchase", async (req, res) => {
56+
try {
57+
// Get the payment handler based on the chosen handler
58+
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);
59+
60+
// Make a purchase request
61+
const paymentInfo = await handler.purchase({
62+
accountNumber: "+2526512312341", // must start with `+` followed by country code
63+
amount: 500,
64+
currency: Currency.SLSH,
65+
description: "Test purchase",
66+
// for web handlers, you can optionally provide a return URL
67+
returnUrl: "https://example.com/return",
68+
});
69+
70+
res.send(paymentInfo);
71+
} catch (e) {
72+
console.log(e);
73+
res.status(500).send("Internal Server Error");
74+
}
7575
});
7676

77-
app.get('/credit', async (req, res) => {
78-
try {
79-
// Get the payment handler based on the chosen handler
80-
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);
81-
82-
// Credit an account
83-
const paymentInfo = await handler.credit({
84-
accountNumber: "+2526512312341", // must start with `+` followed by country code
85-
amount: 1000,
86-
currency: Currency.SLSH,
87-
description: "Test credit",
88-
});
89-
90-
res.send(paymentInfo);
91-
} catch (e) {
92-
console.log(e);
93-
res.status(500).send("Internal Server Error");
94-
}
77+
app.get("/credit", async (req, res) => {
78+
try {
79+
// Get the payment handler based on the chosen handler
80+
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);
81+
82+
// Credit an account
83+
const paymentInfo = await handler.credit({
84+
accountNumber: "+2526512312341", // must start with `+` followed by country code
85+
amount: 1000,
86+
currency: Currency.SLSH,
87+
description: "Test credit",
88+
});
89+
90+
res.send(paymentInfo);
91+
} catch (e) {
92+
console.log(e);
93+
res.status(500).send("Internal Server Error");
94+
}
9595
});
9696

9797
app.listen(port, () => {
98-
console.log(`Server is listening at http://localhost:${port}`);
98+
console.log(`Server is listening at http://localhost:${port}`);
9999
});
100100
```
101+
101102
### Responses
102103

103104
The `credit` and `purchase` methods both returns a `PaymentInfo` object. It'll return these details:
@@ -110,14 +111,16 @@ The `credit` and `purchase` methods both returns a `PaymentInfo` object. It'll r
110111

111112
- **`raw`:** This will return unfiltered response details from the vendor.
112113

113-
114114
### Examples
115115

116116
The provided examples demonstrate how to use the Marupay SDK for both purchase and credit transactions with eDahab and Waafi payment handlers. Customize the route handlers according to your application's needs.
117117

118118
### Contributing
119+
119120
If you encounter any issues or have suggestions for improvements, feel free to contribute by opening [issues]('https://github.com/iamshabell/marupay/issues') or submitting [pull requests]('https://github.com/iamshabell/marupay/pulls') on the GitHub repository.
120121

122+
Check here for full guide on how to contribute: https://docs.marupay.dev/contributing
123+
121124
### License
122125

123126
This SDK is released under the MIT License. Feel free to use, modify, and distribute it as needed for your projects.

0 commit comments

Comments
 (0)