Wallogit.com
2017 © Pedro Peláez
Helper class to work with the PostFinance e-payment system
This class helps to implement basic e-commerce features from PostFinance Switzerland. The implementation follows the official documentation., (*1)
composer require 'offline/postfinance'
See index.php for an example., (*2)
Define your parameters as an array. Get your SHA-IN signature at hand. Initialize a class instance and pass your parameter array to setParamList., (*3)
$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);
In your view file call getFormFields wherever you want to output the hidden input fields., (*4)
<form action="https://e-payment.postfinance.ch/ncol/test/orderstandard.asp" method="post">
<?= $postfinance->getFormFields(); ?>
<input type="submit" value="Submit Example">
</form>
To use SHA256 or SHA512 algorithms, simply pass the php MHASH constant as second parameter:, (*5)
$postfinance256 = new Offline\PaymentGateways\PostFinance($shaInSignature, 'sha256'); $postfinance512 = new Offline\PaymentGateways\PostFinance($shaInSignature, 'sha512');
Make sure you have the option I would like to receive transaction feedback parameters on the redirection URLs. under Transaktion feedback enabled., (*6)
$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);