npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fusionpay

v0.0.5

Published

A library for handling payment operations with FusionPay. See: moneyfusion.net

Downloads

102

Readme

FusionPay

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

Install FusionPay using npm or yarn:

npm install fusionpay
# or
yarn add fusionpay

Usage

Initializing FusionPay

import { FusionPay } from "fusionpay";

// Basic initialization
const fusionPay = new FusionPay("https://your-api-url.com");

// With custom data type
interface OrderData {
  orderId: string;
  customerEmail: string;
}
const typedFusionPay = new FusionPay<OrderData>("https://your-api-url.com");

Setting Payment Data

fusionPay
  .totalPrice(200)
  .addArticle("Sac", 100)
  .addArticle("Veste", 100)
  .addInfo({
    orderId: "12345",
    customerEmail: "[email protected]",
  })
  .clientName("M. Yaya")
  .clientNumber("01010101")
  .returnUrl("https://my_callback_url.com");

Making a Payment

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);
}

Payment Response Structure

{
  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

//extract token in your url
//eg: Nodejs -> const {token} = req.query

try {
  // Verify payment status

  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

{
  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:

// 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 Reference

Constructor

  • new FusionPay<T = CustomPaymentData>(apiUrl: string)

Methods

All methods (except makePayment and checkPaymentStatus) support method chaining.

  • 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>>

Error Handling

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.