wrappedcbdc/cngn-php-library

An opensource library to give you the best experience with managing your cNGN merchant account

v1.0.1 2024-11-04 14:31 UTC

This package is auto-updated.

Last update: 2024-12-04 14:39:44 UTC


README

CNGnManager is a PHP library for interacting with a CNGN API. It provides a simple interface for various operations such as checking balance, swapping between chains, depositing for redemption, creating virtual accounts, and more.

Table of Contents

Installation

To install CNGnManager and its dependencies, run:

composer require wrappedcbdc/cngn-php-library

Usage

First, import the CNGnManager class using it namespace WrappedCBDC\CNGNManager: and all necessary constants.

<?php declare(strict_types=1);
    require __DIR__ ."/vendor/autoload.php";
    use WrappedCBDC\CNGnManager;
    use WrappedCBDC\constants\{Network, ProviderType};

Then, create an instance of CNGnManager with your secrets:

$apiKey = "cngn_live_sk**********";
$encryptionKey = "yourencryptionkey";
$sshPrivateKey = "-----BEGIN OPENSSH PRIVATE KEY-----
your ssh key
-----END OPENSSH PRIVATE KEY-----";

#NOTE: You can as well get your private key from a file using
$sshPrivateKey = file_get_contents("/path/to/sshkey.key");

$manager = new CNGnManager($apiKey, $sshPrivateKey, $encryptionKey);

// Example: Get balance
$balance = $manager->getBalance();
echo $balance;

Networks

The library supports multiple blockchain networks:

  • Network.BSC - Binance Smart Chain
  • Network.ATC - Asset Chain
  • Network.XBN - Bantu Chain
  • Network.ETTH - Ethereum
  • Network.MATIC - Polygon (Matic)
  • Network.TRX - Tron
  • Network.BASE - Base

Available Methods

cNGNManager Methods

Get Balance

$balance = $manager->getBalance();
echo $balance;

Get Transaction History

$transactions = $manager->getTransactionHistory();
echo $transaction

Withdraw from chains

$swapParams = [
    "amount"=> 100,
    "address" => '0x1234...',
    "network" => Network::BSC,
    "shouldSaveAddress" => true
];

$swapResult =  $manager->withdraw($swapParams);
echo $swapResult;

Redeem Asset

$depositParams = [
    "amount"=> 1000,
    "bank"=> '011',
    "accountNumber"=> '1234567890'
    "saveDetails" => true
];

$depositResult = $manager->depositForRedemption($depositParams);
echo $depositResult;

NOTE: to get bank codes please use the getBanks method to fetch the list of banks and ther codes

Create Virtual Account

$mintParams = [
    "provider"=> ProviderType::KORAPAY
];

$virtualAccount = $manager->createVirtualAccount($mintParams);
echo $virtualAccount;

NOTE: before creating the virtual account you need to have updated your BVN on the dashboard

Update Business

Address Options:

  • "xbnAddress": "string";
  • "bscAddress": "string";
  • "atcAddress": "string";
  • "polygonAddress": "string";
  • "ethAddress": "string";
  • "tronAddress": "string";
  • "baseAddress": "string";
  • "bantuUserId": "string";
$updateData: [
    "walletAddress" => [
        "bscAddress" => '0x1234...',
    ],
    "bankDetails" => [
        "bankName" => 'Example Bank',
        "bankAccountName" => 'Test Account',
        "bankAccountNumber" => '1234567890'
    ]
];

$updateResult = $manager->whitelistAddress($updateData);
echo $updateResult;

Get banks

$banklist = $manager->getBanks();
print($banklist)

WalletManager Methods

Generate Wallet Address

Not Available a the moment

Testing

This project uses Jest for testing. To run the tests, follow these steps:

  1. Run the test command:

    composer run test

    This will run all tests in the __tests__ directory.

Test Structure

The tests are located in the __tests__ directory. They cover various aspects of the CNGnManager class, including:

  • API calls for different endpoints (GET and POST requests)
  • Encryption and decryption of data
  • Error handling for various scenarios

Return Values

All responses are returned as a Json string you have to decode it to an object with; $data = json_decode($response) or to an array with; $data = json_decode($response, true) .

Error Handling

The library uses a custom error handling mechanism. All API errors are caught and thrown as Error objects with descriptive messages.

Types

The library includes python constant classes for all parameters:

  • Network - token network
  • AssetType - Asset constants
  • ProviderType - provider constants

Security

This library uses AES encryption for request payloads and Ed25519 decryption for response data. Ensure that your encryptionKey and privateKey are kept secure.

Contributing

Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.

To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Create a Pull Request

Support

For support, please:

  • Open an issue in the GitHub repository
  • Check existing documentation
  • Contact the support team

License

MIT