nikapps/saman-ussd

一个用于连接 Saman 724 USSD 网关的 PHP 包

2.0.0 2018-09-20 11:51 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:25:57 UTC


README

过时包 - 由于伊朗中央银行禁止使用 USSD 进行支付(更多信息

Travis (.org) branch Latest Stable Version License Saman *724*

一个用于连接 Saman *724# 支付网关的 PHP 包。

目录

安装

使用 Composer,运行以下命令安装此

composer require nikapps/saman-ussd

使用

<?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();

监听器

您需要一个监听器来处理传入的 SOAP 调用。您有两种选择

1. 监听器类

您可以通过实现接口 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
    }
}

然后设置您的监听器

$samanUssd->setListener(new Listener());

2. 回调

您也可以为每个 SOAP 调用传递一个闭包

$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

});

响应

对于每个 API 调用,您应该返回其响应对象

onProductInfo

当在您的 SOAP 服务器上调用 GetProductInfo 方法时,您的监听器将调用 onProductInfo,并且您应该返回一个 Nikapps\SamanUssd\Responses\ProductInfoResponse 实例

public function onProductInfo(array $codes, $language)
{

    // TODO check codes

    return (new ProductInfoResponse)
        ->successful()
        ->amount(1000)
        ->description('Success!');
}

如果给定的代码不正确

return (new ProductInfoResponse())
    ->failed()
    ->reason('Failed!');

如果您想设置 TerminalWage

return (new ProductInfoResponse)
    ->successful()
    ->amount(1000)
    ->description('Success!')
    ->terminal(12345)
    ->wage(200);
  • 注意descriptionamount,一起或 reason 应该小于或等于 40 个字符。

别名方法

  • correct()successful() 的别名
  • incorrect()failed() 的别名
  • error($error)reason($reason) 的别名

onCallSale

当在您的 SOAP 服务器上调用 CallSaleProvider 方法时,您的监听器将调用 onCallSale,并且您应该返回一个 Nikapps\SamanUssd\Responses\CallSaleResponse 实例

public function onCallSale(array $codes, $amount, $phone, $sepId, $language)
{

    // Todo check sale

    return (new CallSaleResponse)
        ->successful()
        ->providerId('provider_id');
}

如果出现问题

return (new CallSaleResponse)
    ->failed()
    ->reason('Failed!');
  • 注意reason 应该小于或等于 40 个字符。

别名方法

  • error($error)reason($reason) 的别名
  • id($providerId)providerId($providerId) 的别名

onExecuteSale

当在您的 SOAP 服务器上调用 ExecSaleProvider 方法时,您的监听器将调用 onExecuteSale,并且您应该返回一个 Nikapps\SamanUssd\Responses\ExecuteSaleResponse 实例

public function onExecuteSale($providerId)
{
    return (new ExecuteSaleResponse)
        ->successful()
        ->description('Success!'); 
}

如果出现问题

return (new ExecuteSaleResponse)
    ->failed()
    ->reason('Failed!');
  • 注意descriptionreason 应该小于或等于 40 个字符。

别名方法

  • error($error)reason($reason) 的别名

onCheckStatus

当在您的 SOAP 服务器上调用 CheckStatus 方法时,您的监听器将调用 onCheckStatus,并且您应该返回一个 Nikapps\SamanUssd\Responses\CheckStatusResponse 实例

public function onCheckStatus($providerId)
{
    // Todo check provider id

    return (new CheckStatusResponse)
        ->found()
        ->successful();
}

当找不到 provider_id

return (new CheckStatusResponse)
    ->notFound()
    ->failed();

当找到 provider_id,但交易失败时

return (new CheckStatusResponse)
    ->found()
    ->failed();
}

别名方法

  • failedTransaction()failed() 的别名
  • successfulTransaction()successful() 的别名
  • failedResult()notFound() 的别名
  • successfulResult()found() 的别名

定制

1. 设置命名空间

如果您想设置自定义 XML 命名空间

$samanUssd->setNamespace('http://my-web-site.com');

2. 设置自定义 SOAP 选项

如果您想为 SoapServer 设置自定义 SOAP 选项或覆盖默认选项

$samanUssd->setOptions([
    'soap_version' => SOAP_1_2
]);

3. 设置自定义 WSDL 查询字符串

默认情况下,如果您将 ?wsdl 添加到您的端点 URI,您可以看到 WSDL 规范。如果您想为它设置自定义查询字符串

$samanUssd->setWsdlQueryString('WSDL');

测试

单元测试

运行

vendor/bin/phpspec run

API 测试

运行

docker-compose -f docker-compose.testing.yaml up -d

vendor/bin/codecept run

依赖项

  • php >= 7.1
  • piotrooo/wsdl-creator

开发依赖

  • phpspec/phpspec
  • codeception/codeception

官方文档

下载: 技术文档版本 1.8

贡献

想要贡献?简单地将此项目进行分叉并提交拉取请求!

许可证

本项目采用 MIT 许可证 发布。

/*
 * 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.
 */

捐赠

Donate via Paypal