tcmug / fpiapi Goto Github PK
View Code? Open in Web Editor NEWPHP Api for making Finnish web payments via a handful of banks and Luottokunta.
License: GNU General Public License v2.0
PHP Api for making Finnish web payments via a handful of banks and Luottokunta.
License: GNU General Public License v2.0
FpiAPI Api for making Finnish web payments via a handful of banks and Luottokunta. Used by: http://drupal.org/project/uc_finnish_payments http://drupal.org/project/commerce_finnish_payments Initial development was sponsored by Mearra (which is today part of Wunderkraut) Supported gateways: Aktia Säästöpankki POP Pankki Ålandsbanken Handelsbanken Luottokunta Nordea Osuuspankki Sampo Pankki S-Pankki Tapiola Luottokunta (UNTESTED) Supported actions: Payment All gateways support payment actions. Payment queries Implemented except for Sampo Pankki. Untested! Payment refund Only a few banks support refunds. Untested and mostly unimplemented. For testing use the accounts listed below. PLEASE SEE test.php for usage example. Custom: Danskebank: Receiver (owner): public: 000000000000 private: jumCLB4T2ceZWGJ9ztjuhn5FaeZnTm5HpfDXWU2APRqfDcsrBs8mqkFARzm7uXKd Client: Requires real ids and passwords Sampopankki Receiver (owner): public: 000000000000 private: jumCLB4T2ceZWGJ9ztjuhn5FaeZnTm5HpfDXWU2APRqfDcsrBs8mqkFARzm7uXKd Client: Requires real ids and passwords Osuuspankki Receiver (owner): public: Esittelymyyja private: Esittelykauppiaansalainentunnus Client: id: 123456 password: 7890 confirmation: 1234 Nordea Receiver (owner): public: 12345678 private: LEHTI Client: id: provided in the process password: provided in the process confirmation: 1234 Luottokunta No testing account Samlink: No support for selectable languages or due dates (only express payments are supported). Versions 002 and 003 are supported. Aktia uses version 010 only. Handelsbanken Receiver (owner) public: 0000000000 private: 11111111111111111111 Client: proper ids and passwords provided in the process Aktia For Aktia you must use version 010. Receiver (owner) public: 0000000000 private: 11111111111111111111 Client: id: 12345678 password: 123456 confirmation: 1234 Säästöpankki For Säästöpankki you can use either versions 002 or 003. Receiver (owner) public: 0000000000 private: 11111111111111111111 Client: proper ids and passwords provided in the process POP Pankki For POP you can use either versions 002 or 003. Receiver (owner) public: 0000000000 private: 11111111111111111111 Client: proper ids and passwords provided in the process. Crosskey: Support for fi and sv only. Ålandsbanken Receiver (owner): public: AABESHOPID private: PAPEGOJA account: 660100-01130855 Client: id: 12345678 password: 9999 confirmation: 1234 S-Pankki Receiver (owner): public: SPANKKIESHOPID private: SPANKKI account: 393900-01002369 Client: id: 12345678 password: 123456 confirmation: 1234 Tapiola Receiver (owner): public: TAPESHOPID private: PAPUKAIJA account: 363630-01652643 Client: id: 12345678 password: 123TAP
Sampopankki uses 0 as some of their return codes which does pass php's empty().
The gateaway is fully working besides this little issue and here is how i fixed it:
/**
* checkFields
* Verifies that the rows in $fields have values
*/
public function checkFields(array $fields) {
foreach ($fields as $k => $v) {
/*
* do not use empty() here since some providers use status code 0 as valid return code
*/
if ($v == '') {
return FALSE;
}
}
return TRUE;
}
I could not find the Service Description for the implementation since Luottokunta is changing their infosec policy 26.11.2012 and only provided me with the latest Service Description which uses sha256 instead of md5 and added security policies.
I rewrote the Luottokunta -gateaway and tested it and got it working, but you also should change the checkFields() -method to use $v == '' instead of empty($v) since some providers return 0 as status codes which does not pass empty() (Like Sampopankki)
gateaway.php:205
public function checkFields(array $fields) {
foreach ($fields as $k => $v) {
/*
* do not use empty() here since some providers use status code 0 as valid return code
*/
if ($v == '') {
return FALSE;
}
}
return TRUE;
}
And this is the refactored AND tested version of Luottokunta.php -gateaway:
<?php
/**
* Gateway for Luottokunta
*
* Refactored gateway to be compatible with the new rules of Luottokunta
* Uses hash('sha256', $mac) instead of md5($mac) which is the new infosec-policy
*
*/
class FpiapiGatewayLuottokunta extends FpiapiGateway {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->name = "Luottokunta";
$this->postUrl = 'https://dmp2.luottokunta.fi/dmp/html_payments';
$this->hasPaymentAbility = true;
}
/**
* getPaymentFields()
* @see fpiapi/gateways/FpiapiGateway::getPaymentFields()
*/
public function getPaymentFields() {
$mac_fields = $this->getFieldArrayForRequest();
$mac_str = implode("&", $mac_fields);
$mac = hash('sha256', $mac_str);
$fields = array(
'Authentication_Mac' => $mac,
'Success_Url' => $this->getReturnUrl(),
'Failure_Url' => $this->getErrorUrl(),
'Cancel_Url' => $this->getErrorUrl(),
'Device_Category' => $this->getDeviceCategory(),
'Card_Details_Transmit' => $this->getCardDetailsTransmit(),
'Currency_Code' => $this->getCurrencyCode(),
'Merchant_Number' => $this->configuration['publicKey'],
'Order_ID' => $this->transaction->getUid(),
'Amount' => $this->getFormattedSum(),
'Transaction_Type' => $this->getTransactionType(),
);
return $fields;
}
/**
* isPaymentCompleted()
* @see fpiapi/gateways/FpiapiGateway::isPaymentCompleted()
*/
public function isPaymentCompleted() {
$params = &$_REQUEST;
if (!isset($params['LKMAC'])) {
return false;
}
$fields = $this->getFieldArrayForResponse();
if (!$this->checkFields($fields)) {
return false;
}
$mac_str = implode("&", $fields);
$mac = hash('sha256', $mac_str);
return strtolower($mac) == strtolower($params['LKMAC']);
}
protected function getFieldArrayForResponse() {
$fields = array(
'Private_key' => $this->configuration['privateKey'],
'Transaction_Type' => $this->getTransactionType(),
'Currency_Code' => $this->getCurrencyCode(),
'Amount' => $this->getFormattedSum(),
'Order_ID' => $this->transaction->getUid(),
'Merchant_Number' => $this->configuration['publicKey'],
);
$LB_fields = array(
'LKBINCOUNTRY',
'LKIPCOUNTRY',
'LKECI',
);
// Add LB-fields if they exist in reponse
foreach ($LB_fields as $LB_field) {
if (isset($_REQUEST[$LB_field])) {
$fields[$LB_field] = $_REQUEST[$LB_field];
}
}
return $fields;
}
protected function getFieldArrayForRequest() {
$fields = array(
'Merchant_Number' => $this->configuration['publicKey'],
'Order_ID' => $this->transaction->getUid(),
'Amount' => $this->getFormattedSum(),
'Currency_Code' => $this->getCurrencyCode(),
'Transaction_Type' => $this->getTransactionType(),
'Private_key' => $this->configuration['privateKey'],
);
return $fields;
}
protected function getFilteredSum() {
return str_replace(",", ".", $this->transaction->getSum());
}
protected function getFormattedSum() {
return round($this->getFilteredSum() * 100);
}
protected function getTransactionType() {
return '1';
}
protected function getCurrencyCode() {
return '978';
}
protected function getDeviceCategory() {
return '1';
}
protected function getCardDetailsTransmit() {
return '0';
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.