dilab/ipay

CakePHP的iPay88插件

维护者

详细信息

github.com/dilab/ipay

源代码

问题

安装次数: 21

依赖项: 0

建议者: 0

安全: 0

星级: 0

关注者: 1

分支: 0

开放问题: 2

类型:cakephp-plugin

1.0.0 2015-10-09 09:23 UTC

This package is auto-updated.

Last update: 2024-09-14 19:09:20 UTC


README

iPay88是东南亚领先的区域支付网关服务提供商。

要求

  • CakePHP版本:2.5.x

安装

使用Git

git clone git@github.com:dilab/ipay.git Ipay

使用Composer

composer require dilab/ipay

使用方法

创建插件数据库

cake schema create --plugin ipay

提供iPay88商户信息

  • 将ipay_config.php复制到App/Config文件夹 cp app/Plugin/Ipay/Config/ipay_config_sample.php app/Config/ipay_config.php

  • 打开app/Config/ipay_config.php并填写正确的merchantKeymerchantCode信息。其余信息保持不变。

创建事件监听器

Ipay.IpayResponse模型触发以下两个事件,您可以使用它们添加业务逻辑。

  • Model.IpayResponse.afterValidResponse:当iPay88发送有效响应时触发此事件。它检查statussignature字段。

  • Model.IpayResponse.afterSuccessResponse:只有在上一个事件发生时才会触发此事件。它将重新查询iPay88服务器以检查是否为有效付款。

应使用Model.IpayResponse.afterSuccessResponse来识别成功的付款。

Ipay插件默认包含后端帖子,它将使用此事件监听器进行处理

示例

在文件 app/Controller/AppController.php

public function beforeFilter()
{
  $this->loadModel('Ipay.IpayResponse');
  $callback = array($this, 'ipaySuccessResponseCallBack');
  $this->IpayResponse->getEventManager()->attach(
          $callback,
          'Model.IpayResponse.afterSuccessResponse',
          array('passParams' => true)
  );
}

public function ipaySuccessResponseCallBack($id)
{
  // Process your order with your business logic
  // Use $id to get the order information from ipay_repsonses table
}

使用Helper创建iPay88表单

您可以使用iPay88创建支付表单,您应该始终使用helper,因为它负责创建签名。

示例

$data = array(
    'RefNo' => 123,
    'Amount' => 100.00,
    'Currency' => 'USD',
    'ProdDesc' => 'Product',
    'UserName' => 'test user',
    'UserEmail' => 'test@gmail.com',
    'UserContact' => '123',
    'ResponseURL' => 'http://domain/controller/response_handler',
);

echo $this->Ipay->button($data);
             

使用组件处理响应

在您的响应操作中,只需调用Ipay.processPaymentResponse();即可,它将处理所有后端过程。

示例

public response_handler() 
{
    // Your other code
    
    
    $this->Ipay->processPaymentResponse();

}

测试

单元测试

cake test Ipay all

集成测试

cake test Ipay Integration/IpayRequeryIntegration

(不要将此测试作为单元测试的一部分运行,因为它将向iPay88服务器发送HTTP请求。)

支持

请使用Github Issues报告错误/问题。

许可证

根据MIT许可证授权。文件的分发必须保留上述版权声明。

作者

Xu Ding

https://github.com/dilab