-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
389 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ npm-debug.log | |
.DS_Store | ||
node_modules | ||
tmp | ||
example | ||
example | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ npm-debug.log | |
.DS_Store | ||
node_modules | ||
tmp | ||
example | ||
example | ||
src | ||
.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,181 @@ | ||
# FusionPay | ||
|
||
FusionPay is a JavaScript library for handling payment operations, providing a simple and intuitive API to facilitate online payments for moneyfusion.net. | ||
FusionPay is a TypeScript/JavaScript library for handling payment operations with the MoneyFusion payment gateway, providing a simple and intuitive API to facilitate online payments. | ||
|
||
## Installation | ||
|
||
You can install FusionPay via npm or yarn.: | ||
Install FusionPay using npm or yarn: | ||
|
||
```bash | ||
npm install fusionpay | ||
``` | ||
|
||
```bash | ||
# or | ||
yarn add fusionpay | ||
``` | ||
|
||
## Usage | ||
|
||
Initializing FusionPay | ||
To start using FusionPay, you need to initialize a new instance with your API URL: | ||
### Initializing FusionPay | ||
|
||
```javascript | ||
const { FusionPay } = require("fusionpay"); | ||
//OR import { FusionPay } from "fusionpay"; | ||
```typescript | ||
import { FusionPay } from "fusionpay"; | ||
|
||
// Basic initialization | ||
const fusionPay = new FusionPay("https://your-api-url.com"); | ||
``` | ||
|
||
## Setting Payment Data | ||
// With custom data type | ||
interface OrderData { | ||
orderId: string; | ||
customerEmail: string; | ||
} | ||
const typedFusionPay = new FusionPay<OrderData>("https://your-api-url.com"); | ||
``` | ||
|
||
You can set the payment data using the various methods provided by FusionPay: | ||
### Setting Payment Data | ||
|
||
```javascript | ||
```typescript | ||
fusionPay | ||
.totalPrice(200) | ||
.addArticle("Sac", 100) | ||
.addArticle("Veste", 200) | ||
.addInfo({ userId: "1245d858sf8f95f9ff", token: "dffqsyyyysfs56556sjsjh" }) | ||
.addArticle("Veste", 100) | ||
.addInfo({ | ||
orderId: "12345", | ||
customerEmail: "[email protected]", | ||
}) | ||
.clientName("M. Yaya") | ||
.clientNumber("0574801791") | ||
.returnUrl("https://my_call_back_link.com"); | ||
.clientNumber("01010101") | ||
.returnUrl("https://my_callback_url.com"); | ||
``` | ||
|
||
## Making a Payment | ||
### Making a Payment | ||
|
||
To make a payment, use the makePayment() method: | ||
```typescript | ||
try { | ||
const response = await fusionPay.makePayment(); | ||
console.log("Payment initiated:", response); | ||
// Redirect user to payment URL or send url to client | ||
} catch (error) { | ||
console.error("Payment initiation failed:", error); | ||
} | ||
``` | ||
|
||
```javascript | ||
fusionPay | ||
.makePayment() | ||
.then((response) => { | ||
console.log("Payment successful:", response); | ||
}) | ||
.catch((error) => { | ||
console.error("Payment failed:", error); | ||
}); | ||
#### Payment Response Structure | ||
|
||
```typescript | ||
{ | ||
statut: boolean; // Payment initiation status | ||
token: string; // Token for payment verification | ||
message: string; // Status message | ||
url: string; // Payment gateway URL for user redirection | ||
} | ||
``` | ||
|
||
### Handling Payment Callback | ||
|
||
When the payment is completed, the user will be redirected to your return URL with a token parameter: | ||
|
||
``` | ||
https://my_callback_url.com?token=payment_token_here | ||
``` | ||
|
||
## Checking Payment Status | ||
### Checking Payment Status | ||
|
||
To check the payment status, use the checkPaymentStatus() method: | ||
```typescript | ||
//extract token in your url | ||
//eg: Nodejs -> const {token} = req.query | ||
|
||
```javascript | ||
const paymentToken = "your_payment_token_here"; | ||
try { | ||
// Verify payment status | ||
|
||
fusionPay | ||
.checkPaymentStatus(paymentToken) | ||
.then((status) => { | ||
console.log("Payment status:", status); | ||
}) | ||
.catch((error) => { | ||
console.error("Failed to check payment status:", error); | ||
}); | ||
const status = await fusionPay.checkPaymentStatus(token); | ||
if (status.statut && status.data.statut === "paid") { | ||
// Payment successful | ||
const customData = status.data.personal_Info[0]; | ||
// Handle success... | ||
} | ||
} catch (error) { | ||
console.error("Status check failed:", error); | ||
} | ||
``` | ||
|
||
#### Payment Verification Response Structure | ||
|
||
```typescript | ||
{ | ||
statut: boolean; // Verification request status | ||
message: string; // Status message | ||
data: { | ||
_id: string; // Payment record ID | ||
tokenPay: string; // Payment token | ||
numeroSend: string; // Customer phone number | ||
nomclient: string; // Customer name | ||
personal_Info: T[]; // Your custom data array | ||
numeroTransaction: string; // Transaction reference | ||
Montant: number; // Payment amount | ||
frais: number; // Transaction fees | ||
statut: "pending" | "paid" | "failed"; // Payment status | ||
moyen: string; // Payment method used | ||
return_url: string; // Callback URL | ||
createdAt: string; // Transaction timestamp | ||
} | ||
} | ||
``` | ||
|
||
## Custom Data Examples | ||
|
||
Here are some examples of custom data you might want to store: | ||
|
||
```typescript | ||
// E-commerce order | ||
interface OrderData { | ||
orderId: string; | ||
customerEmail: string; | ||
} | ||
|
||
// Subscription | ||
interface SubscriptionData { | ||
planId: string; | ||
subscriberId: string; | ||
period: "monthly" | "yearly"; | ||
} | ||
|
||
// Event ticket | ||
interface TicketData { | ||
eventId: string; | ||
ticketType: string; | ||
quantity: number; | ||
} | ||
|
||
// Usage | ||
const payment = new FusionPay<OrderData>(apiUrl); | ||
payment.addInfo({ | ||
orderId: "ORD-123", | ||
customerEmail: "[email protected]", | ||
}); | ||
``` | ||
|
||
## API | ||
## API Reference | ||
|
||
### Constructor | ||
|
||
- `new FusionPay<T = CustomPaymentData>(apiUrl: string)` | ||
|
||
### Methods | ||
|
||
`FusionPay(apiUrl: string)` | ||
All methods (except `makePayment` and `checkPaymentStatus`) support method chaining. | ||
|
||
- `apiUrl: The API URL for payment.` | ||
- `totalPrice(amount: number): this` | ||
- `addArticle(name: string, value: number): this` | ||
- `addInfo(data: T): this` | ||
- `clientName(name: string): this` | ||
- `clientNumber(number: string): this` | ||
- `returnUrl(url: string): this` | ||
- `makePayment(): Promise<PaymentResponse>` | ||
- `checkPaymentStatus(token: string): Promise<PaymentVerificationResponse<T>>` | ||
|
||
## Methods | ||
## Error Handling | ||
|
||
- `totalPrice(amount: number): FusionPay` | ||
- `addArticle(name: string, value: number): FusionPay` | ||
- `addInfo(info: Record<string, string>): FusionPay` | ||
- `clientName(name: string): FusionPay` | ||
- `clientNumber(number: string): FusionPay` | ||
- `returnUrl(url: string): FusionPay` | ||
- `makePayment(): Promise<AxiosResponse>` | ||
- `checkPaymentStatus(token: string): Promise<AxiosResponse>` | ||
The library throws errors for failed API calls and invalid parameters. Always wrap API calls in try-catch blocks for proper error handling. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the LICENSE file for details. | ||
This project is licensed under the MIT License - see the LICENSE file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.