2017 © Pedro Peláez
 

library php-tupas

image

tuutti/php-tupas

  • Monday, September 18, 2017
  • by tuutti
  • Repository
  • 2 Watchers
  • 1 Stars
  • 1,070 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 17 % Grown

The README.md

php-tupas

Build Status codecov, (*1)

Install

composer require tuutti/php-tupas

Testing

Run tests with phpunit., (*2)

./vendor/bin/phpunit

Usage

Building tupas button/form

Create a new class that implements \Tupas\Entity\BankInterface., (*3)

<?php
class YourBankClass implements \Tupas\Entity\BankInterface {
    // Add required getters and populate required values.
}
...
/** @var \Tupas\Entity\BankInterface $bank */
$bank = new YourBankClass();
...

$form = new \Tupas\Form\TupasForm($bank);
$form->setCancelUrl('http://example.com/tupas/cancel')
    ->setRejectedUrl('http://example.com/tupas/rejected')
    ->setReturnUrl('http://example.com/tupas/return')
    ->setLanguage('FI');

Generate and store transaction id in a storage that persists over multiple requests, for example:, (*4)

<?php
$_SESSION['transaction_id'] = $form->getTransactionId();

Note: This is not required, but highly recommended as otherwise users can reuse their valid authentication urls as many times they want., (*5)

Build your form:, (*6)

<?php
foreach ($form->build() as $key => $value) {
    // Your form logic should generate a hidden input field:
    // <input type="hidden" name="$key", value="$value">
}

Set form action:, (*7)

<form method="..." action="$bank->getActionUrl();">

Validating returning customer

<?php
...
// You should always use the bank number (three first
// characters of B02K_TIMESTMP) to validate the bank.
// Something like:
$bank_number = substr($_GET['B02K_TIMESTMP'], 0, 3);
...

$tupas = new \Tupas\Tupas($bank, $_GET);
// Compare transaction id stored in a persistent storage against
// the one returned by the Tupas service.
if (!$tupas->isValidTransaction($_SESSION['transaction_id'])) {
    // Transaction id validation failed.
}
try {
    $tupas->validate();
}
catch (\Tupas\Exception\TupasGenericException $e) {
    // Validation failed due to missing parameters.
}
catch (\Tupas\Exception\HashMatchException $e) {
    // Validation failed due to hash mismatch.
}

Invalidate transaction id after a successful authentication:, (*8)

<?php
unset($_SESSION['transaction_id']);

Examples

https://github.com/tuutti/tupas, (*9)

The Versions

18/09 2017
18/09 2017
29/08 2017
25/08 2017

1.0.0-alpha3

1.0.0.0-alpha3

  Sources   Download

The Requires

 

The Development Requires

by Lari Rauno

11/12 2016

1.0.0-alpha2

1.0.0.0-alpha2

  Sources   Download

The Requires

 

The Development Requires

by Lari Rauno

11/12 2016

1.0.0-alpha1

1.0.0.0-alpha1

  Sources   Download

The Requires

 

The Development Requires

by Lari Rauno