承接 prosperoking/kudaopenapi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prosperoking/kudaopenapi

Composer 安装命令:

composer require prosperoking/kudaopenapi

包简介

A Simple library to communicate with kuda openapi

README 文档

README

I needed to work with the kuda openapi but it seems that the progress for the work on the openapi-php library is not ready yet. This library can help fill that gap till they have one ready.

Installation

> composer require prosperoking/kudaopenapi

Usage

Usage is takes into account the kudaOpenApi v1 and v2. The v1 makes use of private and public key pairs while the v2 uses an apiKey and email combination without the need to encrypt the body. Below are ways to utilize any of the api

For api v2

You can get your api key/keys from the kuda developer portal here

Test and live environment urls in use are

include './vendor/autoload.php';


use Prosperoking\KudaOpenApi\KudaOpenApiV2;

$email = "youremail@here.com"
// You can generate this on the developer dashboard
$apiKey = 'xxxxxxxxxxx';

// initialize the object and pass the path or string of your key in pem format
$openApi = KudaOpenApiV2::initLive($email, $apiKey);
// And for test environment 
$openApi = KudaOpenApiV2::initTest($email, $apiKey);

// You can also Use the constructor
$openApi = new KudaOpenApiV2($email,$openApi, null, $baseUrl )
    
try {
    // this will return the account NIBBS information
    var_dump($openApi->getAccountInfo([
        'beneficiaryAccountNumber'=> '1115744617',
        'beneficiaryBankCode'=>'999058',
    ]));

} catch (\Exception $th) {
    var_dump($th->getMessage());
}

v2 comes with a cache driver to avoid making unneeded calls for authentication making it 1 request every 12 minutes will help improve the speed of your requests. You can also write your own cache driver and supply for the client to use and example with laravel will look something like this:

Cache should last a max of 15 minutes

use Prosperoking\KudaOpenApi\Contracts\IAuthCacheDriver
class MyAwesomeCacheDriver implements IAuthCacheDriver {
    public function setAuthToken(string $value): bool
    {
        // You may decide to encrypt  the value before saving it
        return Cache::set('kuda_key', $value, now()->addMinutes(12);
    }
    public function getAuthToken(): ?string
    {
        // And Decrypt it here before returning it 
        return Cache::get('kuda_key');
    }
}

And pass it to the client with any of the methods

include './vendor/autoload.php';


use Prosperoking\KudaOpenApi\KudaOpenApiV2;

$email = "youremail@here.com"
// You can generate this on the developer dashboard
$apiKey = 'xxxxxxxxxxx';

// init your cache driver 
$myCacheDriver = new MyAwesomeCacheDriver()

// initialize the object and pass the path or string of your key in pem format
$openApi = KudaOpenApiV2::initLive($email, $apiKey, $myCacheDriver);
// And for test environment 
$openApi = KudaOpenApiV2::initTest($email, $apiKey, $myCacheDriver);

// You can set the cache driver using the set cache driver method

$openApi->setCacheDriver($myCacheDriver);

// You can also Use the constructor
$openApi = new KudaOpenApiV2($email,$openApi, $myCacheDriver, $baseUrl )

For api v1

include './vendor/autoload.php';


use Prosperoking\KudaOpenApi\KudaOpenApi;

$client = "your_client_id_here"
$baseUrl = 'https://sandbox.kudabank.com/v1';

// initialize the object and pass the path or string of your key in pem format
$openApi = new KudaOpenApi(
    __DIR__.'/private.pem',
    __DIR__.'/public.pem',
    
try {
    // this will return the account NIBSS information
    var_dump($openApi->getAccountInfo([
        'beneficiaryAccountNumber'=> '1115744617',
        'beneficiaryBankCode'=>'999058',
    ]));
    
    // or You can make use of makeRequest method
    $payload = [
        'beneficiaryAccountNumber'=> '1115744615',
        'beneficiaryBankCode'=>'999058'
    ];
    $requestRef= "myunique_identifier"
    // this will return the account information
    var_dump($openApi->makeRequest(
        ServiceTypes::NAME_ENQUIRY,
        $payload,
        $requestRef
    ));

} catch (\Exception $th) {
    var_dump($th->getMessage());
}

note that if you don't pass a referenceid the libray will generate one for you using php bin2hex(random_bytes(10))

You can also make request using the makeRequest method

use Prosperoking\KudaOpenApi\KudaOpenApi;
use Prosperoking\KudaOpenApi\ServiceTypes;

$client = "your client id here"
$baseUrl = 'https://sandbox.kudabank.com/v1';
// initialize the object and pass the path or string of your key in pem format
$openApi = new KudaOpenApi(
    __DIR__.'/private.pem',
    __DIR__.'/public.pem',
    $clientId,
    $baseUrl
);
try {
    $payload = [
        'beneficiaryAccountNumber'=> '1115744615',
        'beneficiaryBankCode'=>'999058'
    ];
    $requestRef= "myunique_identifier"
    // this will return the account information
    var_dump($openApi->makeRequest(
        ServiceTypes::NAME_ENQUIRY,
        $payload,
        $requestRef
    ));

} catch (\Exception $th) {
    var_dump($th->getMessage());
}

Road Map

Here are what I intend to add:

  • Create a simple api base similar to kuda openapi-node ☑

  • Make Simple Classes to create payloads to be used in the makeRequest object to help intelisense support. ⏳

  • Add support for laravel ⏳

  • Create tests ⏳

prosperoking/kudaopenapi 适用场景与选型建议

prosperoking/kudaopenapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.27k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「Kuda」 「Kuda openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 prosperoking/kudaopenapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 prosperoking/kudaopenapi 我们能提供哪些服务?
定制开发 / 二次开发

基于 prosperoking/kudaopenapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-11