Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luottokunta -gateway does not work #1

Open
boubbin opened this issue Oct 31, 2012 · 3 comments
Open

Luottokunta -gateway does not work #1

boubbin opened this issue Oct 31, 2012 · 3 comments

Comments

@boubbin
Copy link

boubbin commented Oct 31, 2012

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';
    }

}
@tcmug
Copy link
Owner

tcmug commented Nov 1, 2012

Has it been verified that nothing breaks after the modification done to gateway.php?

tcmug added a commit that referenced this issue May 13, 2013
@tcmug
Copy link
Owner

tcmug commented May 13, 2013

As seen above its now been committed. I wonder if it also fixed the issues people have with the latest changes Luottokunta has done?

@kmort89
Copy link

kmort89 commented Jan 17, 2016

I would like to mention that luottokunta is now "nets" and if you visit the url it will tell you that this will probably no longer work:

BULLETIN:
We are renewing our service offerings and for this reason ePayment Service has been discontinued from our product range. Receiving payments through the service expires 30.9.2015. We are currently contacting our clients and partners regarding the change of payment service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants