yaphet17/chapa
Composer 安装命令:
composer require yaphet17/chapa
包简介
PHP SDK for Chapa payment gateway
README 文档
README
Unofficial PHP library for Chapa Payment Gateway.
Description
Integrating Chapa to your app is simple as it is. So what benefit can you get from using this library? well, here are some of the benefits you can get by using this library.
- Allows you to focus on building your app instead of spending time on making the integration to work.
- It provides utility methods that can save you from writing some lines of codes. For example the library supports data validation out of the box, so that you don't have to manually sanitize users input.
- The library gives you an easy interface to manage any data send to or received from Chapa API in an object-oriented approach.
Documentation
Visit official Chapa's API Documentation
Installation
Go to your project directory and install the latest version of the library using following command
composer require yaphet17/chapa
Usage
Instantiate a Chapa class.
$chapa = new Chapa('{your-secrete-key}');
Create a PostData object that will represent your payment details.PostData class uses the Fluent Interface,
so you can be able to chain setter methods.
$postData = new PostData(); $postData->amount('100') ->currency('ETB') ->email('abebe@bikila.com') ->firstname('Abebe') ->lastname('Bikila') ->transactionRef('transaction-ref') ->callbackUrl('https://chapa.co') ->customizations( array( 'customization[title]' => 'I love e-commerce', 'customization[description]' => 'It is time to pay' ) );
You can also use a utility method provided by the library to generate a unique and convenient transaction reference token. Util class provides a method
that can generate a token by combining your custom prefix such as company initials (optional), current timestamp and random string.
$transactionRef = Util::generateToken('acme'); // generated transaction reference will start with the prefix aceme
To initialize a transaction, all you have to do is call initializa method in side Chapa class. Pass the PostData object you created in the above step.
$response1 = $chapa->initialize($postData);
You can also verify your transaction using verify method inside Chapa class. This method takes a transaction reference token so that it can uniquely
identify a specific transaction.
$response2 = $chapa->verify($transactionRef);
Both of the above two methods (i.e initialize and verify) returns an instance of ReponseData class. This class will allow you to access the data
returned by Chapa API with an OOP approach. It has the same structure as the JSON data returned by Chapa API plus status code and a raw JSON data.
$statusCode = $resopnse1->getStatusCode(); $message = $response1->getMessage(); $success = $response1->getStatus(); $data = $response1->getData();
For some reason, if you want the raw JSON data you can easily access it using getRawJSON method.
$json = $response->getRawJson();
Below is the full implementation of the above steps.
$chapa = new Chapa('{your-secrete-key}'); $transactionRef = Util::generateToken(); $postData = new PostData(); $postData->amount('100') ->currency('ETB') ->email('abebe@bikila.com') ->firstname('test') ->lastname('user') ->transactionRef($transactionRef) ->callbackUrl('https://chapa.co') ->customizations( array( 'customization[title]' => 'E-commerce', 'customization[description]' => 'It is time to pay' ) ); $response1 = $chapa->initialize($postData); print_r($response1->getMessage()); print_r($response1->getStatus()); print_r($response1->getData()); echo $response->getRawJson(); $response2 = $chapa->verify($transactionRef); if($response2->getStatusCode() == 200){ echo 'Payment not verified because ' . $response2->getMessage()['message']; }
Contribution
Any sort of contribution to this library is appreciated. Make a PR for minor changes or create an issue for breaking changes.
This open source library is licensed under the terms of the MIT License.
Enjoy.
yaphet17/chapa 适用场景与选型建议
yaphet17/chapa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 327 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yaphet17/chapa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yaphet17/chapa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 327
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-22