Coder Social home page Coder Social logo

renekorss / banklink Goto Github PK

View Code? Open in Web Editor NEW
36.0 10.0 19.0 2 MB

PHP payment library to easily integrate Baltic banklinks (supports old and new iPizza protocol), E-commerce gateaway (Estcard, Nets Estonia), Liisi Payment Link and Pocopay.

Home Page: http://renekorss.github.io/Banklink/

License: MIT License

PHP 100.00%
php-payment-library banklink payment gateway nets-estonia seb swedbank nordea lhv danskebank

banklink's Introduction

Actions Status Coverage Status Codacy Badge Latest Stable Version Total Downloads License

PHP Payment library

PHP payment library to easily integrate Baltic banklinks, E-commerce gateaway (Estcard, Nets Estonia), Liizi Payment Link and Pocopay.

View API documentation at https://renekorss.github.io/Banklink/

Install

composer require renekorss/banklink

Supported providers

Country / Provider Payment Authentication
Estonia
Danskebank
Coop Pank
LHV
SEB
Swedbank
Luminor
Nordea
Pocopay does not apply
Estcard does not apply
Liisi Payment Link does not apply
Lithuania
SEB does not apply
Swedbank does not apply
Luminor does not apply
Šiaulių does not apply
Estcard does not apply

How to use?

For more information, please visit Wiki. Basic example is below.

SECURITY WARNING

Never keep your private and public keys in publicly accessible folder. Instead place keys under root folder (usually public_html or www).

If you store keys as strings in database, then they should be accessible only over HTTPS protocol.

Payment

<?php
    require __DIR__ . '/vendor/autoload.php';

    use RKD\Banklink;

    // Init protocol
    $protocol = new Banklink\Protocol\IPizza(
        'uid100010', // seller ID (VK_SND_ID)
        __DIR__ . '/../keys/seb_user_key.pem', // private key
        '', // private key password, leave empty, if not needed
        __DIR__ . '/../keys/seb_bank_cert.pem', // public key
        'http://localhost/banklink/SEB.php' // return url
    );

    // Init banklink
    $seb = new Banklink\EE\SEB($protocol);

    // Set payment data and get payment request object
    // orderId, sum, message, language
    $request = $seb->getPaymentRequest(123453, 150, 'Test makse', 'EST');

    // You can also add custom request data and/or override request data
    // Optional
    $request = $seb->getPaymentRequest(123453, 150, 'Test makse', 'EST', 'EUR', [
        'VK_REF' => 'my_custom_reference_number', // Override reference number
        'INAPP' => true // Pocopay specific example
    ]);
?>

<form method="POST" action="<?php echo $request->getRequestUrl(); ?>">
  <?php echo $request->getRequestInputs(); ?>
  <input type="submit" value="Pay with SEB!" />
</form>

Authentication

<?php
    require __DIR__ . '/vendor/autoload.php';

    use RKD\Banklink;

    // Init protocol
    $protocol = new Banklink\Protocol\IPizza(
        'uid100010', // seller ID (SND ID)
        __DIR__ . '/../keys/seb_user_key.pem', // private key
        '', // private key password, leave empty, if not needed
        __DIR__ . '/../keys/seb_bank_cert.pem', // public key
        'http://localhost/banklink/SEB.php' // return url
    );

    // Init banklink
    $seb = new Banklink\EE\SEB($protocol);

    // Get auth request object
    $request = $seb->getAuthRequest();
?>

<form method="POST" action="<?php echo $request->getRequestUrl(); ?>">
  <?php echo $request->getRequestInputs(); ?>
  <input type="submit" value="Authenticate with SEB!" />
</form>

Response from provider

<?php
    require __DIR__ . '/vendor/autoload.php';

    use RKD\Banklink;

    // Init protocol
    $protocol = new Banklink\Protocol\IPizza(
        'uid100010', // seller ID (SND ID)
        __DIR__ . '/../keys/seb_user_key.pem', // private key
        '', // private key password, leave empty, if not needed
        __DIR__ . '/../keys/seb_bank_cert.pem', // public key
        'http://localhost/banklink/SEB.php' // return url
    );

    // Init banklink
    $seb = new Banklink\EE\SEB($protocol);

    // Get response object
    $response = $seb->handleResponse($_POST);

    // Successful
    if ($response->wasSuccessful()) {
        // Get whole array of response
        $responseData    = $response->getResponseData();

        // User prefered language
        $language        = $response->getLanguage();

        // Only for payment data
        $orderId         = $response->getOrderId();
        $sum             = $response->getSum();
        $currency        = $response->getCurrency();
        $sender          = $response->getSender();
        $transactionId   = $response->getTransactionId();
        $transactionDate = $response->getTransactionDate();
        $message         = $response->getMessage();
        $automatic       = $response->isAutomatic(); // true if response was sent automatically by bank

        // Only for auth data
        $userId          = $response->getUserId(); // Person ID
        $userName        = $response->getUserName(); // Person name
        $country         = $response->getUserCountry(); // Person country
        $authDate        = $response->getAuthDate(); // Authentication response datetime

        // Method used for authentication
        // Possible values: ID Card, Mobile ID, One-off code card, PIN-calculator, Code card or unknown
        $authMethod      = $response->getAuthMethod();

    // Failed
    } else {
        // Payment data
        $orderId         = $response->getOrderId(); // Order id to cancel order etc.
    }
?>

Tasks

  • composer build - build by running tests and all code checks
  • composer test - run tests
  • composer format - format code against standards
  • composer docs - build API documentation
  • composer phpmd - run PHP Mess Detector
  • composer phpcs - run PHP CodeSniffer

License

Licensed under MIT

banklink's People

Contributors

dependabot[bot] avatar lenar avatar peter279k avatar rang501 avatar renekorss avatar smolevich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

banklink's Issues

Feature request: ability to set different return and cancel urls

Expected Behavior

Return and cancel url should not be same, at least there should be option to change it

Actual Behavior

Request url is used as RETURN and CANCEL

Steps to Reproduce the Problem

  1. Just add one more parameter for cancel url to IPizza.php __contruct() method

Problem of PHP 7.0 version support

Expected Behavior

  • It should be worked on php-7.0 version.

Actual Behavior

  • It should be failed on php-7.0 version.

One of error message is as follows on php-7.0 version:

PHP Parse error:  syntax error, unexpected '?', expecting variable (T_VARIABLE) in /data/Banklink/src/Banklink.php on line 166

Possible solution

  • I think it should let package require php-7.1 version at least.

Swedbank LT doesn't include VK_RETURN into mac

Expected Behavior

for swedbank lt mac calculation VK_RETURN should not be included at least for PAYMENT_REQUEST_2001

Actual Behavior

it is included into calculation, and bank returns an error

Steps to Reproduce the Problem

  1. make a payment request
    2.submit to swedbank

Rename banks

Rename old class names to new:

  • Krediidipank to Coop Pank

Duplicate:

  • Nordea to Luminor (Luminor only exists in Baltics)

orderId type from int to string in protocol requests

Expected Behavior

orderId parameter to accept string in protocol requests so that more unique identifiers could be provided and therefore reducing the probablity of collisions.

Actual Behavior

Currently orderId parameter accepts only int and this somewhat limits the usage of unique order identifiers to max int size.

I am not sure if current integer orderId is somehow influenced by the underlaying protocol specifications or integration specifics to specific bank, but if string orderId works with all the banks it should be allowed to set string orderId's.

Banklink implementation sets VK_REF and VK_MSG even if LtSwedbank specification allows only one of the fields to be used

Normally this isn't an issue, however, if you want to use LtSEB via LtSwedbank (spec allows it by changing the request URL), Swedbank will throw an error such as this:

index

This requirement is specified in the Swedbank specification in https://www.swedbank.lt/static/pdf/business/banklink_technines_specifikacijos_LT_2020-08-07.pdf however it is not mentioned in the English spec. I assume this is because using other banks via LtSwed is a LtSwed only feature.

See request 1002 specs which near VK_REF says

Mokėjimo pavedimo įmokos kodas. Šio lauko negalima naudoti, jei naudojamas VK_MSG.

Which roughly translates to

Payment transfer code. This field cannot be used if VK_MSG is used.

The lib user should be provided with a way to control the fields sensibly before creating the finalized form. Specifically, I'd like the ability to set VK_REF to null, in which case the VK_REF field would not be included in VK_MAC and the data itself.

Steps to Reproduce the Problem

  1. Create LtSwedbank payment
  2. Change URL to https://banklink.swedbank.com/LT/CBVILT2X
  3. Redirect user for payment
  4. See error as shown above

Specifications

  • Version: "renekorss/banklink": "^3.3"
  • Platform: Symfony 4.4

Problem of PHP versions

Expected Behavior

  • All tests will be successful on php-7.1 and php-7.0 versions.

Actual Behavior

  • It will not be worked on php-7.1 and php-7,2 versions because the PHPUnit version is defined as the 8.*. This PHPUnit version will require php-7.2 version at least.
  • And it will output errors when using php-7.0 and php-7.1 versions to install cached dependencies.
    The reason is about this cached dependencies are installed on php-7.2 version at least.
    The error output will be as follows:
 Problem 1
    - Installation request for cedx/coveralls v11.2.0 -> satisfiable by cedx/coveralls[v11.2.0].
    - cedx/coveralls v11.2.0 requires php >=7.2.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 2
    - Installation request for cedx/lcov v7.0.0 -> satisfiable by cedx/lcov[v7.0.0].
    - cedx/lcov v7.0.0 requires php >=7.2.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 3
    - Installation request for cedx/which v7.2.0 -> satisfiable by cedx/which[v7.2.0].
    - cedx/which v7.2.0 requires php >=7.2.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 4
    - Installation request for doctrine/lexer 1.2.0 -> satisfiable by doctrine/lexer[1.2.0].
    - doctrine/lexer 1.2.0 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 5
    - Installation request for phpdocumentor/reflection-docblock 5.1.0 -> satisfiable by phpdocumentor/reflection-docblock[5.1.0].
    - phpdocumentor/reflection-docblock 5.1.0 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 6
    - Installation request for phpdocumentor/type-resolver 1.1.0 -> satisfiable by phpdocumentor/type-resolver[1.1.0].
    - phpdocumentor/type-resolver 1.1.0 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 7
    - Installation request for phpunit/php-code-coverage 7.0.10 -> satisfiable by phpunit/php-code-coverage[7.0.10].
    - phpunit/php-code-coverage 7.0.10 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 8
    - Installation request for phpunit/phpunit 8.5.3 -> satisfiable by phpunit/phpunit[8.5.3].
    - phpunit/phpunit 8.5.3 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 9
    - Installation request for psr/event-dispatcher 1.0.0 -> satisfiable by psr/event-dispatcher[1.0.0].
    - psr/event-dispatcher 1.0.0 requires php >=7.2.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 10
    - Installation request for sebastian/global-state 3.0.0 -> satisfiable by sebastian/global-state[3.0.0].
    - sebastian/global-state 3.0.0 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 11
    - Installation request for sebastian/type 1.1.3 -> satisfiable by sebastian/type[1.1.3].
    - sebastian/type 1.1.3 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 12
    - Installation request for symfony/config v5.0.7 -> satisfiable by symfony/config[v5.0.7].
    - symfony/config v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 13
    - Installation request for symfony/console v5.0.7 -> satisfiable by symfony/console[v5.0.7].
    - symfony/console v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 14
    - Installation request for symfony/dependency-injection v5.0.7 -> satisfiable by symfony/dependency-injection[v5.0.7].
    - symfony/dependency-injection v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 15
    - Installation request for symfony/event-dispatcher v5.0.7 -> satisfiable by symfony/event-dispatcher[v5.0.7].
    - symfony/event-dispatcher v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 16
    - Installation request for symfony/event-dispatcher-contracts v2.0.1 -> satisfiable by symfony/event-dispatcher-contracts[v2.0.1].
    - symfony/event-dispatcher-contracts v2.0.1 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 17
    - Installation request for symfony/filesystem v5.0.7 -> satisfiable by symfony/filesystem[v5.0.7].
    - symfony/filesystem v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 18
    - Installation request for symfony/finder v5.0.7 -> satisfiable by symfony/finder[v5.0.7].
    - symfony/finder v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 19
    - Installation request for symfony/options-resolver v5.0.7 -> satisfiable by symfony/options-resolver[v5.0.7].
    - symfony/options-resolver v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 20
    - Installation request for symfony/process v5.0.7 -> satisfiable by symfony/process[v5.0.7].
    - symfony/process v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 21
    - Installation request for symfony/service-contracts v2.0.1 -> satisfiable by symfony/service-contracts[v2.0.1].
    - symfony/service-contracts v2.0.1 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 22
    - Installation request for symfony/stopwatch v5.0.7 -> satisfiable by symfony/stopwatch[v5.0.7].
    - symfony/stopwatch v5.0.7 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 23
    - doctrine/lexer 1.2.0 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
    - doctrine/annotations 1.10.1 requires doctrine/lexer 1.* -> satisfiable by doctrine/lexer[1.2.0].
    - Installation request for doctrine/annotations 1.10.1 -> satisfiable by doctrine/annotations[1.10.1].

Possible solution

  • IMHO, I think we can consider using following solutions to resolve this:
  • Let the package require php-7.0 or php-7.1 version at least.
  • And update the cached dependencies with php-7.0 or php-7.1 version.
  • Let the PHPUnit package version definition be the 7.* and it can be compatible with php-7.1 version during PHPUnit tests.

@renekorss, what do you think about this?

Once this issue is accepted, I can work on this :).

VK_STAMP could be string as well

Expected Behavior

I can be wrong, but i can't find a reason not to allow string in VK_STAMP (orderId). Ipizza specs do not have type info. It actually works too.

Actual Behavior

TypeError: Argument 1 passed to Banklink::getPaymentRequest() must be of the type integer, string given

Very nice code and docs BTW!

Drop PHP 5.6 & 7.0 support

Starting from 3.x require minimum of PHP 7.1 since PHP 7.0 will be EOL soon, just like PHP 5.6.

Older PHP versions are still supported by 2.x and will get security fixes until EOL of PHP 5.6 and 7.0 (31.12.2018).

PaymentResponse::setAutomatic is not part of the ResponseInterface

This is not a bug or breaking issue, I just ran into this when the auto-complete did not show isAutomatic as an option.

Method \RKD\Banklink\Response\PaymentResponse::isAutomatic is not part of the \RKD\Banklink\Response\ResponseInterface

I understand this is because AuthResponse and PaymentResponse are different and \RKD\Banklink\Banklink::handleResponse returns ResponseInterface. But at this point it's up to the developer to know if there is a method setAutomatic on the response instance or do an instanceof check:

            if ($response instanceof PaymentResponse && $response->isAutomatic()) {
                ...
            }

I see two solutions:

  1. Add the isAutomatic to the current interface and in case of AuthResponse always return false.
  2. Extend ResponseInterface with PaymentResponseInterface which adds isAutomatic and change handleResponse

Just something to consider, I would consider making the changes if the author thinks this as something worthwhile of doing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.