wrappedcbdc / cngn-php-library
An opensource library to give you the best experience with managing your cNGN merchant account
Requires
- guzzlehttp/guzzle: ^7.9
- kornrunner/keccak: ^1.1
- mdanter/ecc: ^1.0
- owenvoke/mnemonics-php: ^2.0
- soneso/stellar-php-sdk: ^1.5
Requires (Dev)
- phpunit/phpunit: ^11.3
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
- Usage
- Available Methods
- Testing
- Error Handling
- Types
- Security
- Contributing
- Support
- License
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 ChainNetwork.ATC
- Asset ChainNetwork.XBN
- Bantu ChainNetwork.ETTH
- EthereumNetwork.MATIC
- Polygon (Matic)Network.TRX
- TronNetwork.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:
-
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 networkAssetType
- Asset constantsProviderType
- 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:
- Fork the repository
- Create a feature branch
- Commit your changes
- Create a Pull Request
Support
For support, please:
- Open an issue in the GitHub repository
- Check existing documentation
- Contact the support team