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

pesepayclient

v1.0.1

Published

pesepay to make online paymenys online

Downloads

13

Readme


Payment Encryption & Decryption Utility Package

This package provides utilities for encrypting and decrypting payment information, initiating payments, and checking the status of payments using the Pesepay .

Features

  • EncryptPayment: Encrypts the payment details.
  • DecryptPayment: Decrypts the encrypted payment response.
  • MakePayment: Makes an encrypted payment request to Pesepay API.
  • CheckPayment: Checks the payment status by reference number.

Installation

Install the package via npm:

npm install pesepayclient

Usage

In React

  1. Import the functions:

    import { InitiatePayment, CheckPayment, EncryptPayment, DecriptPayment } from 'pesepayclient';
  2. Example of Making a Payment:

    import React, { useState } from 'react';
    import { InitiatePaymentnt } from 'pesepayclient';
    
    const PaymentComponent = () => {
      const [paymentResult, setPaymentResult] = useState(null);
    
      const handlePayment = async () => {
        const paymentBody = {
          amountDetails: { amount: 100, currencyCode: "USD" },
          reasonForPayment: "Order Payment",
          resultUrl: "https://yourapp.com/payment-result",
          returnUrl: "https://yourapp.com/return"
        };
    
        const encryptionKey = "your-encryption-key";
        const integrationKey = "your-integration-key";
    
        const result = await InitiatePayment(paymentBody, encryptionKey, integrationKey);
        setPaymentResult(result);
        // save the reference number so that u can use it to check the payments
         localStorage.setItem("reference", result.referenceNumber)
        // after getting the result redirect to pesepay
         window.location.href = result?.redirectUrl;
      };
    
      return (
        <div>
          <button onClick={handlePayment}>Make Payment</button>
          {paymentResult && <div>Payment Result: {JSON.stringify(paymentResult)}</div>}
        </div>
      );
    };
    
    export default PaymentComponent;
  3. Example of Checking Payment Status:

    import React, { useState } from 'react';
    import { CheckPayment } from 'pesepayclient';
    
    const CheckPaymentComponent = () => {
      const [paymentStatus, setPaymentStatus] = useState(null);
    
      const checkPaymentStatus = async () => {
        const referenceNumber = "your-reference-number";
        const encryptionKey = "your-encryption-key";
        const integrationKey = "your-integration-key";
    
        const status = await CheckPayment(referenceNumber, encryptionKey, integrationKey);
        setPaymentStatus(status);
      };
    
      return (
        <div>
          <button onClick={checkPaymentStatus}>Check Payment Status</button>
          {paymentStatus && <div>Payment Status: {JSON.stringify(paymentStatus)}</div>}
        </div>
      );
    };
    
    export default CheckPaymentComponent;

In Angular

  1. Import the package:

    First, ensure that you have installed the package:

    npm install your-package-name axios crypto-js
  2. Create a service for the payment functions:

    // payment.service.ts
    
    import { Injectable } from '@angular/core';
    import {InitiatePayment, CheckPayment } from 'pesepayclient';
    
    @Injectable({
      providedIn: 'root',
    })
    export class PaymentService {
    
      async makePayment() {
        const paymentBody = {
          amountDetails: { amount: 100, currencyCode: "USD" },
          reasonForPayment: "Order Payment",
          resultUrl: "https://yourapp.com/payment-result",
          returnUrl: "https://yourapp.com/return"
        };
    
        const encryptionKey = 'your-encryption-key';
        const integrationKey = 'your-integration-key';
    
        return await InitiatePayment(paymentBody, encryptionKey, integrationKey);
      }
    
      async checkPayment(referenceNumber: string) {
        const encryptionKey = 'your-encryption-key';
        const integrationKey = 'your-integration-key';
    
        return await CheckPayment(referenceNumber, encryptionKey, integrationKey);
      }
    }
  3. Use the payment service in a component:

    // payment.component.ts
    import { Component } from '@angular/core';
    import { PaymentService } from './payment.service';
    
    @Component({
      selector: 'app-payment',
      templateUrl: './payment.component.html'
    })
    export class PaymentComponent {
    
      paymentResult: any;
      paymentStatus: any;
    
      constructor(private paymentService: PaymentService) {}
    
      makePayment() {
        this.paymentService.makePayment().then(result => {
          this.paymentResult = result;
           // save the reference number so that u can use it to check the payments
         localStorage.setItem("reference", result.referenceNumber)
        // after getting the result redirect to pesepay
         window.location.href = result?.redirectUrl;
        }).catch(error => console.error("Payment Error:", error));
      }
    
      checkPaymentStatus() {
        const referenceNumber = 'your-reference-number';
        this.paymentService.checkPayment(referenceNumber).then(status => {
          this.paymentStatus = status;
        }).catch(error => console.error("Payment Status Error:", error));
      }
    }
  4. Component Template Example:

    <!-- payment.component.html -->
    <button (click)="makePayment()">Make Payment</button>
    <div *ngIf="paymentResult">Payment Result: {{ paymentResult | json }}</div>
    
    <button (click)="checkPaymentStatus()">Check Payment Status</button>
    <div *ngIf="paymentStatus">Payment Status: {{ paymentStatus | json }}</div>

API Reference

EncryptPayment(paymentBody: PaymentBody, encryptionKey: string): string

  • Parameters:
    • paymentBody: The body of the payment.
    • encryptionKey: The encryption key used for encrypting the payment details.
  • Returns: A string representing the encrypted payment body.

DecriptPayment(encryptedString: string, encryptionKey: string): TransactionDetails | null

  • Parameters:
    • encryptedString: The encrypted string to decrypt.
    • encryptionKey: The key used for decryption.
  • Returns: The decrypted payment details or null if decryption fails.

MakePayment(paymentBody: PaymentBody, encryptionKey: string, integrationKey: string): Promise<TransactionDetails | null>

  • Parameters:
    • paymentBody: The payment details to be sent to the API.
    • encryptionKey: The encryption key used for encrypting the payment.
    • integrationKey: The integration key used for authenticating with the API.
  • Returns: The payment response as TransactionDetails.

CheckPayment(referenceNumber: string, encryptionKey: string, integrationKey: string): Promise<TransactionDetails | null>

  • Parameters:
    • referenceNumber: The reference number of the payment.
    • encryptionKey: The encryption key used for decrypting the response.
    • integrationKey: The integration key used for authenticating with the API.
  • Returns: The payment status as TransactionDetails.

TransactionDetails Structure

interface TransactionDetails {
  amountDetails: {
    amount: number;
    currencyCode: string;
    customerPayableAmount: number;
    defaultCurrencyAmount: number;
    defaultCurrencyCode: string;
    formattedMerchantAmount: string;
    merchantAmount: number;
    totalTransactionAmount: number;
    transactionServiceFee: number;
  };
  applicationCode: string;
  applicationName: string;
  chargeType: "NO_CHARGE" | string;
  customer: {
    contactNumbers: string[];
    email: string;
    name: string;
  };
  customerAmountPaid: {
    amountPaid: number;
    currencyCode: string;
  };
  dateOfTransaction: string;
  id: number;
  internalReference: string;
  liquidationStatus: "COMPLETED" | string;
  liquidationTransactionReference: string;
  localDateTimeOfTransaction: string;
  merchantReference: string;
  paymentMetadata: Record<string, any>;
  paymentMethodDetails: {
    paymentMethodCode: string;
    paymentMethodId: number;
    paymentMethodMessage: string;
    paymentMethodName: string;
    paymentMethodReference: string;
    paymentMethodStatus: string;
  };
  pollUrl: string;
  reasonForPayment: string;
  redirectRequired: boolean;
  redirectUrl: string;
  referenceNumber: string;
  resultUrl: string;
  returnUrl: string;
  settlementMode: "DIRECTLY_SETTLED" | string;
  timeOfTransaction: string;
  transactionDate: string;
  transactionStatus: "AUTHORIZATION_FAILED" | string;
  transactionStatusCode: number;
  transactionStatusDescription: string;
  transactionType: "BASIC" | string;
}

License

This project is licensed under the MIT License.