nikapps/saman-ussd
Composer 安装命令:
composer require nikapps/saman-ussd
包简介
A php package for connecting to Saman 724 USSD gateway
README 文档
README
Obsolete package - payment with USSD is forbidden by Iranian central bank (more info)
A php package for connecting to Saman *724# payment gateway.
Table of contents:
- Installation
- Usage
- Listener
- Responses
- Customization
- Testing
- Dependencies
- Official documentation
- Contribute
- License
- Donation
Installation
Using Composer, install this package by running this command:
composer require nikapps/saman-ussd
Usage
<?php use Nikapps\SamanUssd\SamanUssd; $samanUssd = new SamanUssd(); // Set api endpoint $samanUssd->endpoint('http://example.com/webservice.php'); // TODO: Set listener or callbacks $samanUssd->handle();
Listener
You need a listener for incoming soap calls. You have two options:
1. Listener Class:
You can setup your listener by implementing interface Nikapps\SamanUssd\Contracts\SamanUssdListener:
<?php use Nikapps\SamanUssd\Contracts\SamanUssdListener; class Listener implements SamanUssdListener{ /** * When `GetProductInfo` is called * * @param string[] $codes * @param string $language * * @return \Nikapps\SamanUssd\Responses\ProductInfoResponse; */ public function onProductInfo(array $codes, $language) { // TODO: response } /** * When `CallSaleProvider` is called * * @param string[] $codes * @param integer $amount * @param string $phone Mobile/Call number * @param long $sepId Unique number provided by saman724 * @param string $language * * @return \Nikapps\SamanUssd\Responses\CallSaleResponse */ public function onCallSale(array $codes, $amount, $phone, $sepId, $language) { // TODO: return response } /** * When `ExecSaleProvider` is called * * @param string $providerId * * @return \Nikapps\SamanUssd\Responses\ExecuteSaleResponse */ public function onExecuteSale($providerId) { // TODO: return response } /** * When `CheckStatus` is called * * @param string $providerId * * @return \Nikapps\SamanUssd\Responses\CheckStatusResponse */ public function onCheckStatus($providerId) { // TODO: return response } }
Then set your listener:
$samanUssd->setListener(new Listener());
2. Callbacks:
Also you can pass a closure for each soap call:
$samanUssd->onProductInfo(function (array $codes, $language) { // TODO: return response }); $samanUssd->onCallSale(function (array $codes, $amount, $phone, $sepId, $language) { // TODO: return response }); $samanUssd->onExecuteSale(function ($providerId) { // TODO: return response }); $samanUssd->onCheckStatus(function ($providerId) { // TODO: return response });
Responses
For each api call, you should return its response object:
onProductInfo
When method GetProductInfo is called on your soap server, onProductInfo will be called on your listener and you should return an instance of Nikapps\SamanUssd\Responses\ProductInfoResponse:
public function onProductInfo(array $codes, $language) { // TODO check codes return (new ProductInfoResponse) ->successful() ->amount(1000) ->description('Success!'); }
If the given codes are incorrect:
return (new ProductInfoResponse()) ->failed() ->reason('Failed!');
If you want to set Terminal and Wage:
return (new ProductInfoResponse) ->successful() ->amount(1000) ->description('Success!') ->terminal(12345) ->wage(200);
- Notice :
descriptionandamount, together orreasonshould be less than or equal to40characters.
Alias methods:
correct()alias ofsuccessful()incorrect()alias offailed()error($error)alias ofreason($reason)
onCallSale
When method CallSaleProvider is called on your soap server, onCallSale will be called on your listener and you should return an instance of Nikapps\SamanUssd\Responses\CallSaleResponse:
public function onCallSale(array $codes, $amount, $phone, $sepId, $language) { // Todo check sale return (new CallSaleResponse) ->successful() ->providerId('provider_id'); }
If something goes wrong:
return (new CallSaleResponse) ->failed() ->reason('Failed!');
- Notice :
reasonshould be less than or equal to40characters.
Alias methods:
error($error)alias ofreason($reason)id($providerId)alias ofproviderId($providerId)
onExecuteSale
When method ExecSaleProvider is called on your soap server, onExecuteSale will be called on your listener and you should return an instance of Nikapps\SamanUssd\Responses\ExecuteSaleResponse:
public function onExecuteSale($providerId) { return (new ExecuteSaleResponse) ->successful() ->description('Success!'); }
If something goes wrong:
return (new ExecuteSaleResponse) ->failed() ->reason('Failed!');
- Notice :
descriptionorreasonshould be less than or equal to40characters.
Alias method:
error($error)alias ofreason($reason)
onCheckStatus
When method CheckStatus is called on your soap server, onCheckStatus will be called on your listener and you should return an instance of Nikapps\SamanUssd\Responses\CheckStatusResponse:
public function onCheckStatus($providerId) { // Todo check provider id return (new CheckStatusResponse) ->found() ->successful(); }
When provider_id is not found:
return (new CheckStatusResponse) ->notFound() ->failed();
When provider_id is found, but transaction was failed:
return (new CheckStatusResponse) ->found() ->failed(); }
Alias methods:
failedTransaction()alias offailed()successfulTransaction()alias ofsuccessful()failedResult()alias ofnotFound()successfulResult()alias offound()
Customization
1. Set Namespace
If you want to set your custom xml namespace:
$samanUssd->setNamespace('http://my-web-site.com');
2. Set custom soap options:
If you want to set custom soap options for SoapServer or override default options:
$samanUssd->setOptions([ 'soap_version' => SOAP_1_2 ]);
3. Set custom WSDL query string
By default, if you append ?wsdl to your endpoint uri, you can see wsdl specification. If you want to set custom query string for that:
$samanUssd->setWsdlQueryString('WSDL');
Testing
Unit test
Run:
vendor/bin/phpspec run
Api test
Run:
docker-compose -f docker-compose.testing.yaml up -d vendor/bin/codecept run
Dependencies
php >= 7.1piotrooo/wsdl-creator
Dev dependencies:
phpspec/phpspeccodeception/codeception
Official documentation
Download: Technical Documentation Version 1.8
Contribute
Wanna contribute? simply fork this project and make a pull request!
License
This project released under the MIT License.
/*
* Copyright (C) 2015 NikApps Team.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* 1- The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* 2- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
Donation
nikapps/saman-ussd 适用场景与选型建议
nikapps/saman-ussd 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.01k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「gateway」 「Bank」 「iran」 「nikpay」 「saman」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nikapps/saman-ussd 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nikapps/saman-ussd 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nikapps/saman-ussd 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
Symfony integration for Czech bank account library
Check for holidays - localeaware
A basic wrapper for citco/carbon which returns business days between two given dates.
Iranian payment gateways handler for laravel applicationss
统计信息
- 总下载量: 27.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-16