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

paycardjs

v1.0.2

Published

Paycardjs is a Node.js library for creating and managing payments using the Paycard API. This library provides an easy-to-use interface for integrating Paycard payment functionality into your Node.js applications.

Downloads

5

Readme

Paycardjs Library

Paycardjs is a Node.js library for creating and managing payments using the Paycard API. This library provides an easy-to-use interface for integrating Paycard payment functionality into your Node.js applications.

Using Paycardjs, you can make payments via Orange Money Guinea, MTN MoMo, VISA, and Paycard.

Table of Contents

Installation

Install the library using npm:

npm install paycardjs

Usage

You can find an example of the library's use in javascript and typescript

initialize the library

Instantiate a payment with your Paycard API_KEY

const paycard = new Paycard('your-api-key');

Configuring payment information

const createPaymentRequest: CreatePaymentRequest = {
    amount: 100,
    description: 'Test payment',
};

| Field | Type |Mandatory | Description | |-----------------|---------------|----------|----------------------------------------------------| | amount | number | Yes | The amount to be paid. Must be greater than 0. | | description | string | Yes | Description of the payment. | | reference | string | No | Unique reference for the payment. if you do not provide a reference, Paycard generates one for the payment | | paymentMethod | PaymentMethod | No | The payment method to use. The possible values are: CREDIT_CARD, MOMO, ORANGE_MONEY, PAYCARD | | callbackUrl | string | No | URL to be called back after payment. | | autoRedirect | boolean | No | Auto redirect after payment (default: false). | | redirectWithGet | boolean | No | Use GET for redirect (default: false). |

Creating a Payment

paycard.createPayment(createPaymentRequest)
    .then(response => {
        console.log('Payment created successfully:', response);
    })
    .catch(error => {
        console.error('Error creating payment:', error);
    });

| Field | Type | Description | |--------------------------|--------|--------------------------------------| | code | number | Response code (0 for success). | | payment_amount | number | Amount paid. | | payment_amount_formatted | string | Formatted payment amount. | | payment_description | string | Description of the payment. | | operation_reference | string | Reference for the payment operation. | | payment_url | string | URL for completing the payment. | | error_message | string | Error message if any error occurred. |

Getting Payment Status

paycard.getPaymentStatus('test-ref')
    .then(response => {
        console.log('Payment status:', response);
    })
    .catch(error => {
        console.error('Error getting payment status:', error);
    });

| Field | Type | Description | |--------------------------|--------|-------------------------------------------------| | code | number | Response code (0 for success). | | payment_amount | number | Date of the transaction. | | payment_amount_formatted | string | Status of the payment. | | payment_description | string | Description of the payment status. | | payment_method | number | The method used for payment. | | payment_reference | string | Reference of the payment in the Paycard system. | | payment_method_reference | string | Reference of the payment method used. | | reference | string | Reference for the payment. | | status_description | string | Description of the payment status. | | status | string | Status of the payment. | | ecommerce_description | string | Description for the ecommerce transaction. | | transaction_date | string | Date of the transaction. | | merchant_name | string | Name of the merchant. | | error_message | string | Error message if any error occurred. |

Error Handling

The library throws custom errors for various error conditions. These errors can be imported and used for handling specific error cases.

import { PaymentError, PaymentErrorType } from 'paycard';
...
paycard.createPayment(createPaymentRequest)
    .catch(error => {
        if (error instanceof PaymentError) {
        switch (error.type) {
            case PaymentErrorType.INVALID_PAYMENT_AMOUNT:
                console.error('Invalid payment amount');
                break;
            case PaymentErrorType.INVALID_CALBACK_URL:
                console.error('Invalid callback URL');
                break;
            // Handle other error types
            default:
                console.error('Payment error:', error.message);
        }
    } else {
        console.error('Unexpected error:', error);
    }
    });

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue on GitHub.

  • Fork the repository.
  • Create a new branch.
  • Make your changes.
  • Open a pull request.