jvandemo/ogone

此包的最新版本(v2.1.0)没有可用的许可信息。

v2.1.0 2013-09-30 06:09 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:13:11 UTC


README

该项目正在寻找一位有动力的维护者。

如果您感兴趣,请与我联系:@jvandemo

同时,您可以查看 https://github.com/solidshops/PHPpayments

Ogone for PHP 类

用于与 Ogone 支付系统交互的 PHP 类允许您轻松创建 Ogone 支付表单,并以高效和灵活的方式处理 Ogone 响应。

要求

这些类仅在 PHP 5 及以上版本中受支持。

安装

安装此库的最简单方法是使用 composer。

请将以下依赖项添加到您的 composer.json 文件中

{
    "require": {
        "jvandemo/ogone": "2.0.*"
    }
}

如何使用类

第一步是创建一个用于启动支付的表单

use Jvandemo\Ogone\Form;

// Define form options
// See Ogone_Form for list of supported options
$options = array(
    'sha1InPassPhrase' => 'your_sha1_in_password',
    'formAction'       => Form::OGONE_TEST_URL,
);

// Define form parameters (see Ogone documentation for list)
// Default parameter values can be set in Ogone_Form if required
$params = array(
    'PSPID' => 'your_ogone_pspid',
    'orderID' => 'your_order_id',
    'amount' => 100,
    'currency' => 'EUR',
    'language' => 'en',
    'CN' => 'name of your client',
    'EMAIL' => 'email of your client',
    'accepturl' => 'where_to_go_if_accepted.html',
    'declineurl' => 'where_to_go_if_declined.html',
    'exceptionurl' => 'where_to_go_if_exception_occurs.html',
    'cancelurl' => 'where_to_go_if_cancelled.html',
);

// Instantiate form
$form = new Form($options, $params);

// You can also add parameters after instantiation
// with the addParam() method
$form->addParam('CN', 'Jurgen Van de Moere')
     ->addParam('EMAIL', 'email@email.com')
     ->addParam('language', 'en');

// Automatically generate HTML form with all params and SHA1Sign
echo $form->render();

第二步是创建一个处理 Ogone 响应的脚本

use Jvandemo\Ogone\Response;

// Define response options
// See Ogone_Response for list of supported options
$options = array(
    'sha1OutPassPhrase' => 'your_sha1_out_password'
);

// Define array of values returned by Ogone
// Parameters are validated and filtered automatically
// so it is safe to specify a superglobal variable
// like $_POST or $_GET if you don't want to
// specify all parameters manually
$params = $_POST;

// Instantiate response
$response = new Response($options, $params);

// Check if response by Ogone is valid
// The SHA1Sign is calculated automatically and
// verified with the SHA1Sign provided by Ogone
if(! $response->isValid()) {
    // Reponse is not valid so handle accordingly
    exit('The response is not valid');
}

// Use the dump() method to dump the whole response
// if you need to investigate the response when debugging
$response->dump();

// Use the getParam() method to retrieve
// parameters returned by Ogone
$creditCard = $response->getParam('CreditCard');
$amount = $response->getParam('amount');

// Handle further processing of your website
// such as saving payment details to database
// or sending confirmation email to client

// ...

此代码也位于 /examples 目录中。

单元测试

测试文件夹包含基本的单元测试以及一个附加的场景测试,该测试实际上连接到 Ogone 测试服务器并使用您的个人 Ogone 凭据来检查是否正确。

要使用您的 Ogone 详细信息配置场景测试,将 config/module.config.global.php 复制到 module.config.local.php 并填写您的 Ogone 详细信息

return array(
    'jvandemo_ogone' => array(
        'pspid' => 'your_ogone_pspid',
        'sha1_in_pass_phrase' => 'your_sha1_in_password',
        'sha1_out_pass_phrase' => 'your_sha1_out_password'
    )
);

.gitignore 文件已配置为忽略 module.config.local.php,因此您无需担心在创建自己的公共存储库时暴露您的 Ogone 详细信息。

要实际运行单元测试套件,请运行

grunt

变更日志

1.0.0

  • 添加了 Ogone_Form 用于生成与 Ogone 交互的表单
  • 添加了 Ogone_Response 用于处理来自 Ogone 的响应

2.0.0

  • 添加了 composer 支持
  • 引入了命名空间
  • 添加了单元测试
  • 修复了一些编码标准警告
  • 添加了 grunt 支持,用于单元测试和代码风格检查
  • 添加了语义版本控制

2.1.0

  • 添加了额外的单元测试
  • 添加了场景测试
  • 添加了对配置文件的支持