Skip to content

Commit

Permalink
pump
Browse files Browse the repository at this point in the history
  • Loading branch information
iamshabell committed Jun 8, 2024
1 parent a1ee262 commit e54b94d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 58 deletions.
5 changes: 0 additions & 5 deletions .changeset/dry-readers-yawn.md

This file was deleted.

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

// Load environment variables from a .env file
config();
Expand All @@ -13,63 +13,63 @@ app.use(express.urlencoded({ extended: true }));

// Configuration for different payment handlers (e.g., edahab, waafi)
const paymentConfig: ConfigObject = {
edahab: {
apiKey: env.DAHAB_API_KEY!,
secretKey: env.DAHAB_SECRET_KEY!,
merchantId: env.DAHAB_AGENT_CODE!,
},
waafi: {
apiKey: env.WAAFI_API_KEY!,
secretKey: env.WAAFI_API_USER_ID!,
merchantId: env.WAAFI_MERCHANT_KEY!,
},
edahab: {
apiKey: env.DAHAB_API_KEY!,
secretKey: env.DAHAB_SECRET_KEY!,
merchantId: env.DAHAB_AGENT_CODE!,
},
waafi: {
apiKey: env.WAAFI_API_KEY!,
secretKey: env.WAAFI_API_USER_ID!,
merchantId: env.WAAFI_MERCHANT_KEY!,
},
};

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

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

// Make a purchase request
const paymentInfo = await handler.purchase({
accountNumber: "+2526512312341", // must start with `+` followed by country code
amount: 500,
currency: Currency.SLSH,
description: "Test purchase",
// for web handlers, you can optionally provide a return URL
returnUrl: "https://example.com/return",
});
// Make a purchase request
const paymentInfo = await handler.purchase({
accountNumber: "+252634034190", // must start with `+` followed by country code
amount: 500,
currency: Currency.SLSH,
description: "Test purchase",
// for web handlers, you can optionally provide a return URL
returnUrl: "https://example.com/return",
});

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

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

// Credit an account
const paymentInfo = await handler.credit({
accountNumber: "+2526512312341", // must start with `+` followed by country code
amount: 1000,
currency: Currency.SLSH,
description: "Test credit",
});
// Credit an account
const paymentInfo = await handler.credit({
accountNumber: "+2526512312341", // must start with `+` followed by country code
amount: 1000,
currency: Currency.SLSH,
description: "Test credit",
});

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

app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
});
console.log(`Server is listening at http://localhost:${port}`);
});
10 changes: 10 additions & 0 deletions packages/marupay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# marupay

## 0.4.0

### Minor Changes

- d565ea1: add edahab web payment version

### Patch Changes

- redo

## 0.3.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/marupay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marupay",
"version": "0.3.0",
"version": "0.4.0",
"description": "A package for making payment transactions with different african payments gateways.",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
1 change: 0 additions & 1 deletion packages/marupay/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const basePurchaseSchema = z.object({
amount: z.number(),
currency: z.nativeEnum(Currency),
description: z.string().optional(),
returnUrl: z.string().optional(),
});

export type BasePurchaseOptions = z.infer<typeof basePurchaseSchema>;
Expand Down

0 comments on commit e54b94d

Please sign in to comment.