offline/postfinance

此包已被废弃且不再维护。未建议替代包。

用于与PostFinance电子支付系统协同工作的辅助类

v1.0.1 2017-05-29 08:15 UTC

This package is auto-updated.

Last update: 2024-05-06 22:37:04 UTC


README

此类有助于实现瑞士PostFinance的基本电子商务功能。实现遵循官方文档

安装它

composer require 'offline/postfinance'

使用它

查看index.php以获取示例。

将参数定义为数组。获取SHA-IN签名。初始化类实例并将参数数组传递给setParamList

$shaInSignature = 'Configuration -> Technical information -> Data and origni verification -> SHA-IN pass phrase';
$params = [
    'PSPID'        => 'your-postfinance-username',
    'ORDERID'      => '1234',
    'AMOUNT'       => '200' * 100,
    'CURRENCY'     => 'CHF',
    'LANGUAGE'     => 'de_CH',
];

$postfinance = new Offline\PaymentGateways\PostFinance($shaInSignature);
$postfinance->setParamList($params);

在视图文件中,在您希望输出隐藏输入字段的地方调用getFormFields

<form action="https://e-payment.postfinance.ch/ncol/test/orderstandard.asp" method="post">
    
    <?= $postfinance->getFormFields(); ?>
    
    <input type="submit" value="Submit Example">
</form>

使用不同的算法

要使用SHA256或SHA512算法,只需将PHP MHASH常量作为第二个参数传递。

$postfinance256 = new Offline\PaymentGateways\PostFinance($shaInSignature, 'sha256');
$postfinance512 = new Offline\PaymentGateways\PostFinance($shaInSignature, 'sha512');

验证SHA-OUT签名

确保在“交易反馈”下已启用选项我想在重定向URL上接收交易反馈参数。

$shaOutSignature = 'Configuration -> Transaction feedback -> SHA-OUT pass phrase';
$shaSign = isset($_GET['SHASIGN']) ? $_GET['SHASIGN'] : '';

$postfinance = new PostFinance($shaOutSignature);
$postfinance->setParamList($_GET);

$isValid = $postfinance->getDigest() === $shaSign;

var_dump($isValid);