青蛙 / 合作银行SDK
此SDK向合作银行API发送请求,以实现易于集成
dev-main
2021-02-26 21:22 UTC
Requires
- php: ^7.4|^8.0
- ext-curl: *
- frog/php-curl-sai: 1.1.1
- vlucas/phpdotenv: ^5.3
Requires (Dev)
- pestphp/pest: ^1.0
- phpstan/phpstan: ^0.12.79
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-27 05:06:28 UTC
README
一个用于与合作银行API交互的SDK
安装
您可以通过composer安装此包
composer require frog/cooperative-bank-sdk
设置环境变量
COOP_CONSUMER_KEY=
COOP_CONSUMER_SECRET=
COOP_API_BASE_URL=http://developer.co-opbank.co.ke:8280#Testing
# COOP_API_BASE_URL=https://developer.co-opbank.co.ke:8243 # Production
使用
use FROG\CooperativeBankSdk\CooperativeBankSdk; use FROG\CooperativeBankSdk\CoopUtils; $coop_sdk = new CooperativeBankSDK(); /** * Generate an access token * NB: Not necessarily used anywhere as the SDK uses it internally to send requests * */ $access_token = $coop_sdk->generate_access_token(); print_r($access_token); // { // "access_token": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", // "scope": "am_application_scope default", // "token_type": "Bearer", // "expires_in": 3600 // } /** * Check for the account balance * * The message reference is optional in the case the client has an internal unique referencing system * The SDK implements the php random_bytes function internally to generate a unique number * @param string $account_number the cooperative bank account number * @param void|string $message_reference an optional message reference */ // Option 1: Pass in your unique internal message reference (UUID's don't work though) $balance = $coop_sdk->check_account_balance( "account-number", "message-reference", ); // Or you could use the utility from the package to get a unique message reference before the request is made $balance = $coop_sdk->check_account_balance( "account-number", CoopUtils::generate_message_reference(), ); // Or let the sdk generate one internally and access the message reference from the response. // All responses usually have message references $balance = $coop_sdk->check_account_balance( "account-number", ); print_r($balance); // { // "MessageReference": "MESSAGE_REFERENCE_WILL_APPEAR_HERE", // "MessageDateTime": "2021-02-26 15:18:58", // "MessageCode": "0", // "MessageDescription": "Success", // "AccountNumber": "36001873000", // "AccountName": "JOE K. DOE", // "Currency": "USD", // "ProductName": "CURRENT ACCOUNT", // "ClearedBalance": "13706.07", // "BookedBalance": "75391.31", // "BlockedBalance": "27066.64", // "AvailableBalance": "21962.96", // "ArrearsAmount": "12645.56", // "BranchName": "GIGIRI MALL", // "BranchSortCode": "11151", // "AverageBalance": "27339.95", // "UnclearedBalance": "26658.48", // "ODLimit": "17614.28", // "CreditLimit": "23181.53" // } /** * Get the full & mini statement of an account * @param string $account_number an account number from a cooperative bank branch * @param string $start_date the date at which the earliest transaction is to be fetched * @param string $end_date the date at which the latest transction is to be fetched * @param string $message_reference a unique client generated string to be a reference when a request is sent * The message reference is optional in the case the client has an internal unique referencing system * The SDK implements the php random_bytes function internally to generate a unique number */ $statement = $coop_sdk->get_account_full_statement( "account-number", "start-date", "end-date", "message-reference", ); $statement = $coop_sdk->get_account_mini_statement( "account-number", "start-date", "end-date", "message-reference", ); print_r($statement); // { // "MessageReference": "40ca18c6765086089a1", // "MessageDateTime": "2021-02-26 10:27:16", // "MessageCode": "0", // "MessageDescription": "Success", // "AccountNumber": "36001873000", // "AccountName": "JOE K. DOE", // "Transactions": [ // { // "TransactionID": "50a603a3-2", // "TransactionDate": "2021-03-07 23:52:28", // "ValueDate": "2021-03-07 23:52:28", // "Narration": "Electricity payment", // "TransactionType": "D", // "ServicePoint": "POS-P0917", // "TransactionReference": "8be9b10d-4", // "CreditAmount": "0.00", // "DebitAmount": "72869.62", // "RunningClearedBalance": "22749.45", // "RunningBookBalance": "22749.45", // "DebitLimit": "0.00", // "LimitExpiryDate": "2021-03-07 00:00:00" // }, // ... // ] // } /** * Retrieves the transactions of the specified account * * @param string $message_reference a unique client generated string to be a reference when a request is sent * @param string $account_number an account number from a cooperative bank branch * @param string $no_of_transactions a number of transactions to be retrieved (1 - 500) */ $transactions = $coop_sdk->get_account_transactions( "account-number", "no-of-transactions", "message-reference", ); print_r($transactions); // { // "MessageReference": "40ca18c6765086089a1", // "MessageDateTime": "2021-02-26 15:18:04", // "MessageCode": "0", // "MessageDescription": "Success", // "AccountNumber": "36001873000", // "AccountName": "JOE K. DOE", // "Transactions": [ // { // "TransactionID": "fa24e510-c", // "TransactionDate": "2021-02-28 20:28:45", // "ValueDate": "2021-02-28 20:28:45", // "Narration": "Cash Deposit", // "TransactionType": "C", // "ServicePoint": "AGENT-10001", // "TransactionReference": "37e4a38d-9", // "CreditAmount": "97705.30", // "DebitAmount": "0.00", // "RunningClearedBalance": "172774.05", // "RunningBookBalance": "172774.05", // "DebitLimit": "0.00", // "LimitExpiryDate": "2021-02-27 00:00:00" // }, // ... // ] // } /** * Retrieves the status of the specified transaction fetched by a message id * @param string $message_reference a unique client generated string to be a reference when a request is sent */ $status = $coop_sdk->check_transaction_status("message-reference"); print_r($status); // { // "messageReference": "40ca18c6765086089a1", // "messageDateTime": "2021-02-26 15:23:32", // "messageCode": "0", // "messageDescription": "Full Success", // "source": { // "accountNumber": "36001873000", // "amount": "777", // "transactionCurrency": "KES", // "narration": "Supplier Payment", // "responseCode": "0", // "responseDescription": "Success" // }, // "destination": { // "referenceNumber": "40ca18c6765086089a1_1", // "accountNumber": "54321987654321", // "amount": "777", // "transactionCurrency": "KES", // "narration": "Electricity Payment", // "transactionID": "cfea0f9d-c", // "responseCode": "0", // "responseDescription": "Success" // } // } /** * Retrieves the validity of the specified account * * @param string $account_number an account number from a cooperative bank branch * @param string $message_reference a unique client generated string to be a reference when a request is sent */ $status = $coop_sdk->validate_account("account-number", "message-reference"); print_r($status); // { // "MessageReference": "BTVd6xr7vEX97hWgNqM", // "MessageDateTime": "2021-02-26 16:36:39", // "MessageCode": "0", // "MessageDescription": "VALID ACCOUNT NUMBER" // } /** * Retrieves the exhange rate for the day for a specific account * * @param string $from_currency a valid international currency * @param string $to_currency a valid international currency * @param string $message_reference a unique client generated string to be a reference when a request is sent */ $rate = $coop_sdk->exchange_rate("from-currency", "to-currency", "message-reference"); print_r($rate); // { // "MessageReference": "40ca18c6765086089a1", // "MessageDateTime": "2021-02-26 20:31:31", // "MessageCode": "0", // "MessageDescription": "Success", // "FromCurrencyCode": "KES", // "ToCurrencyCode": "USD", // "RateType": "SPOT", // "Rate": "104.35", // "Tolerance": "6", // "MultiplyDivide": "D" // }
测试
注意
:主要开发机器是Windows,请确保在composer.json脚本部分的路径中更改操作系统
测试由PestPHP提供支持
composer test
变更日志
请参阅变更日志以获取有关最近更改的更多信息。
贡献
请参阅贡献指南以获取详细信息。
安全
如果您发现任何安全相关的问题,请通过电子邮件milleradulu@gmail.com联系,而不是使用问题跟踪器。
鸣谢
许可
MIT。请参阅许可文件以获取更多信息。
PHP包模板
此包是使用PHP包模板生成的。