apna-payment/settlement-sdk
Composer 安装命令:
composer require apna-payment/settlement-sdk
包简介
A PHP SDK for managing settlements between Laravel backends.
README 文档
README
Overview
This PHP SDK allows you to integrate ApnaPayment's settlement system into your application. You can use it to create settlement accounts, create settlements, check settlement statuses, and more.
Installation
To use the ApnaPayment Settlement SDK, first install it via Composer:
composer require apna-payment/settlement-sdk
Configuration
After installation, publish the configuration file:
php artisan vendor:publish --provider="ApnaPayment\Settlements\SettlementServiceProvider" --tag="config"
This will publish a settlement-sdk.php configuration file to the config folder of your Laravel project.
In your .env file, set your API token:
SETTLEMENT_BASE_URL=<base_url_depending_on_env>
SETTLEMENT_API_TOKEN=<your_api_token_here>
Usage
Create a VPA-based settlement account
try{
$account = (new SettlementAccountBuilder())
->setAccountHolderName("My Name")
->setType(SettlementAccountBuilder::$TYPE_VPA)
->setVirtualAddress("testvpa@hdfcbank")
->setNickname("My Temp account test");
$accountId = Settlement::createAccount($account);
}
catch (\ApnaPayment\Settlements\Exceptions\DuplicationAccountException $e){
//Account already exists
}
Create a bank account-based settlement account
try{
$account = (new SettlementAccountBuilder())
->setType(SettlementAccountBuilder::$TYPE_BANK_ACCOUNT)
->setAccountNumber("988231872481874")
->setAccountHolderName("My Name")
->setIfscCode("IFSCTEST001")
->setNickname("My Name");
$accountId = Settlement::createAccount($account);
}
catch (\ApnaPayment\Settlements\Exceptions\DuplicationAccountException $e){
//Account already exists
}
Delete a settlement account
$is_deleted=Settlement::removeAccount($accountId); //returns boolean
if($is_deleted){
//Account deleted successfully
}
else{
//Something went wrong
}
Fetch all settlements
$accounts = Settlement::getAllSettlements();
Fetch settlements for specific accounts
$accounts = Settlement::getSettlementsByAccount($accountId);
Handle an invalid account ID
try {
$settlements = Settlement::getSettlementsByAccount("InvalidId");
}
catch (\ApnaPayment\Settlements\Exceptions\InvalidAccountException) {
$message = "Invalid Account";
}
Create settlement
$settlementBuilder = (new SettlementBuilder())
->setAmount(200.25)
->setRemarks("Test Payment")
->setSettlementAccountId($accountId);
$settlement = Settlement::createNewSettlement($settlementBuilder);
Exception Handling
try {
$settlement = (new Settlement(config('settlement-sdk.api_token')))
->createSettlement($settlementBuilder);
}
catch (\ApnaPayment\Settlements\Exceptions\DuplicateTransactionException $e) {
$message = "Duplicate";
}
catch (\ApnaPayment\Settlements\Exceptions\InvalidAccountException $e) {
$message = "Invalid account";
} catch (\ApnaPayment\Settlements\Exceptions\LimitExceededException $e) {
$message = "Limit exceeded";
}
Fetch account balance
$balance = Settlement::getBalance();
Find a settlement by ID
try{
$settlement = Settlement::find($settlementId); //settlement id is always returned from creating a settlement (static or from object)
// Now the 'data' attribute has status in it
$arrayData=$settlement->toArray();
}
catch (\ApnaPayment\Settlements\Exceptions\SettlementNotFound $e){
//Invalid settlement id
}
Find a settlement by TxnId
try{
$settlement = Settlement::findByTxnId($txnId);
$arrayData=$settlement->toArray();
$pending=$settlement->isPending(); //call any instance methods
}
catch (\ApnaPayment\Settlements\Exceptions\SettlementNotFound $e){
//Invalid txnId
}
Usage of Webhook Base URL:
Callbacks V1
Note:
All Endpoints when triggered will expect 200-299 http response code, even if in the case 500,400 is thrown, there will always be one time updates to balance server load.
After our backend receives a valid web hook url for updates relating to following events:
- Settlement status: {'completed','failed'}
- Account Approval Update : { 'approved','rejected' }
Our Backend triggers an HTTP/HTTPS POST request to following endpoints:
1. {base_url}/settlement/status :
{
'id': '<settlement_id>',
'status':'completed'
}
2. {base_url}/settlement/status :
{
'id': '<settlement_id>',
‘status’:’failed’
}
3. {base_url}/settlement_account/approval :
{
'id': '<settlement_account_id>',
'status':'rejected'
}
4.{base_url}/settlement_account/approval :
{
'id': '<settlement_account_id>',
'status':'approved'
}
Querying the status of a settlement
Suppose you have the settlementId returned from Settlement::createSettlemen($settlementBuilder)
$settlement = new Settlement();
// Load the settlement data
$settlement->getSettlementById($settlementId)
// Now the 'data' attribute has status in it
if($settlement->isPending()){
// Pending
}
else if($settlement->isProcessing()){
// Processing
}
else if($settlement->isCompleted()){
// Completed
}
else if( $settlement->isFailed()){
// Failed
}
Methods Overview
- createAccount(SettlementAccountBuilder $builder): Creates a new settlement account using the provided builder.
- createNewSettlement(SettlementBuilder $builder): Creates a new settlement using the provided builder.
- allSettlements(): Retrieves all settlements for the authenticated user.
- settlementsByAccount(string $accountId): Retrieves settlements for a specific settlement account.
- find(string $settlementId): Finds a specific settlement by its ID.
- checkBalance(): Retrieves the balance associated with the authenticated user.
- isPending(): Checks if the settlement is in the 'pending' state.
- isProcessing(): Checks if the settlement is in the 'processing' state.
- isCompleted(): Checks if the settlement is in the 'completed' state.
- isFailed(): Checks if the settlement has 'failed' status.
apna-payment/settlement-sdk 适用场景与选型建议
apna-payment/settlement-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 448 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 apna-payment/settlement-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apna-payment/settlement-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 448
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-02