Skip to content

Commit

Permalink
Merge pull request wysow#1 from b-alidra/master
Browse files Browse the repository at this point in the history
Set back alias related elements and update to marlon version
  • Loading branch information
wysow committed May 17, 2015
2 parents 99ffdc7 + 784f5e7 commit 1b11764
Show file tree
Hide file tree
Showing 50 changed files with 2,596 additions and 257 deletions.
159 changes: 107 additions & 52 deletions README.markdown → README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
# Ogone PHP library #
# PostFinance PHP library #

This library allows you to easily implement an [Ogone](http://ogone.com) integration into your project.
It provides the necessary components to complete a correct payment flow with the [Ogone](http://ogone.com) platform.

[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/marlon-be/marlon-ogone/badges/quality-score.png?s=ceabe3e767cad807b589fc63169e6a330d20f9fa)](https://scrutinizer-ci.com/g/marlon-be/marlon-ogone/)
[![Build Status](https://travis-ci.org/marlon-be/marlon-ogone.png)](https://travis-ci.org/marlon-be/marlon-ogone)
This library allows you to easily implement an [PostFinance](https://www.postfinance.ch/) integration into your project.
It provides the necessary components to complete a correct payment flow with the [PostFinance](https://www.postfinance.ch/) platform.

Requirements:

- PHP 5.3
- network connection between your webserver and the Ogone platform
- network connection between your webserver and the PostFinance platform

As always, this is work in progress. Please feel free to fork this project and let them pull requests coming!

## Overview ##
Installation:
-------------
The library is [PSR-0 compliant](http://www.php-fig.org/psr/psr-0/fr/)
and the simplest way to install it is via composer:

The library complies to the [PSR-0 standard](http://groups.google.com/group/php-standards/web/psr-0-final-proposal),
so it can be autoloaded using PSR-0 classloaders like the one in Symfony2. See autoload.php for an example.
composer require wysow/postfinance

## Overview ##

- Create an EcommercePaymentRequest or CreateAliasRequest, containing all the info needed by Ogone.
- Create an EcommercePaymentRequest or CreateAliasRequest, containing all the info needed by PostFinance.
- Generate a form
- Submit it to Ogone (client side)
- Receive a PaymentResponse back from Ogone (as a HTTP Request)
- Submit it to PostFinance (client side)
- Receive a PaymentResponse back from PostFinance (as a HTTP Request)

Both EcommercePaymentRequest, CreateAliasRequest and PaymentResponse are authenticated by comparing the SHA sign, which is a hash of the parameters and a secret passphrase. You can create the hash using a ShaComposer.

The library also allows:
- Fetching order information via PostFinance API using DirectLinkQueryRequest
- Executing maintenance request via PostFinance API using DirectLinkMaintenanceRequest

# SHA Composers #

Ogone provides 2 methods to generate a SHA sign:
PostFinance provides 2 methods to generate a SHA sign:

- "Main parameters only"

Expand All @@ -37,7 +42,7 @@ Ogone provides 2 methods to generate a SHA sign:

```php
<?php
use Ogone\ShaComposer\LegacyShaComposer;
use PostFinance\ShaComposer\LegacyShaComposer;
$shaComposer = new LegacyShaComposer($passphrase);
```

Expand All @@ -49,7 +54,7 @@ Ogone provides 2 methods to generate a SHA sign:

```php
<?php
use Ogone\ShaComposer\AllParametersShaComposer;
use PostFinance\ShaComposer\AllParametersShaComposer;
$shaComposer = new AllParametersShaComposer($passphrase);
```

Expand All @@ -59,23 +64,23 @@ This library currently supports both the legacy method "Main parameters only" an

```php
<?php
use Ogone\Passphrase;
use Ogone\Ecommerce\EcommercePaymentRequest;
use Ogone\ShaComposer\AllParametersShaComposer;
use Ogone\FormGenerator;
use PostFinance\Passphrase;
use PostFinance\Ecommerce\EcommercePaymentRequest;
use PostFinance\ShaComposer\AllParametersShaComposer;
use PostFinance\FormGenerator;

$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-ogone-interface');
$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaInParameterFilter); //optional

$ecommercePaymentRequest = new EcommercePaymentRequest($shaComposer);

// Optionally set Ogone uri, defaults to TEST account
//$ecommercePaymentRequest->setOgoneUri(EcommercePaymentRequest::PRODUCTION);
// Optionally set PostFinance uri, defaults to TEST account
//$ecommercePaymentRequest->setPostFinanceUri(EcommercePaymentRequest::PRODUCTION);

// Set various params:
$ecommercePaymentRequest->setOrderid('123456');
$ecommercePaymentRequest->setAmount('150'); // in cents
$ecommercePaymentRequest->setAmount(150); // in cents
$ecommercePaymentRequest->setCurrency('EUR');
// ...

Expand All @@ -91,48 +96,48 @@ This library currently supports both the legacy method "Main parameters only" an
```php
<?php

use Ogone\Passphrase;
use Ogone\DirectLink\CreateAliasRequest;
use Ogone\ShaComposer\AllParametersShaComposer;
use Ogone\DirectLink\Alias;
use PostFinance\Passphrase;
use PostFinance\DirectLink\CreateAliasRequest;
use PostFinance\ShaComposer\AllParametersShaComposer;
use PostFinance\DirectLink\Alias;

$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-ogone-interface');
$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaInParameterFilter); //optional

$createAliasRequest = new CreateAliasRequest($shaComposer);

// Optionally set Ogone uri, defaults to TEST account
// $createAliasRequest->setOgoneUri(CreateAliasRequest::PRODUCTION);
// Optionally set PostFinance uri, defaults to TEST account
// $createAliasRequest->setPostFinanceUri(CreateAliasRequest::PRODUCTION);

// set required params
$createAliasRequest->setPspid('123456');
$createAliasRequest->setAccepturl('http://example.com/accept');
$createAliasRequest->setExceptionurl('http://example.com/exception');

// set optional alias, if empty, Ogone creates one
// set optional alias, if empty, PostFinance creates one
$alias = new Alias('customer_123');
$createAliasRequest->setAlias($alias);

$createAliasRequest->validate();

// Now pass $createAliasRequest to a view to build a custom form, you have access to
// $createAliasRequest->getOgoneUri(), $createAliasRequest->getParameters() and $createAliasRequest->getShaSign()
// $createAliasRequest->getPostFinanceUri(), $createAliasRequest->getParameters() and $createAliasRequest->getShaSign()
// Be sure to add the required fields CN (Card holder's name), CARDNO (Card/account number), ED (Expiry date (MMYY)), CVC (Card Verification Code)
// and the SHASIGN
```

# DirectLinkRequest #
# DirectLinkPaymentRequest #

```php
<?php

use Ogone\DirectLink\DirectLinkPaymentRequest;
use Ogone\Passphrase;
use Ogone\ShaComposer\AllParametersShaComposer;
use Ogone\DirectLink\Alias;
use PostFinance\DirectLink\DirectLinkPaymentRequest;
use PostFinance\Passphrase;
use PostFinance\ShaComposer\AllParametersShaComposer;
use PostFinance\DirectLink\Alias;

$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-ogone-interface');
$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaInParameterFilter); //optional

Expand All @@ -142,30 +147,80 @@ This library currently supports both the legacy method "Main parameters only" an
$alias = new Alias('customer_123');
$directLinkRequest->setAlias($alias);
$directLinkRequest->setPspid('123456');
$directLinkRequest->setUserId('ogone-api-user');
$directLinkRequest->setPassword('ogone-api-password');
$directLinkRequest->setUserId('postfinance-api-user');
$directLinkRequest->setPassword('postfinance-api-password');
$directLinkRequest->setAmount(100);
$directLinkRequest->setCurrency('EUR');
$directLinkRequest->validate();

// now create a url to be posted to Ogone
// you have access to $directLinkRequest->toArray(), $directLinkRequest->getOgoneUri() and directLinkRequest->getShaSign()
// now create a url to be posted to PostFinance
// you have access to $directLinkRequest->toArray(), $directLinkRequest->getPostFinanceUri() and directLinkRequest->getShaSign()
```

# DirectLinkQueryRequest #

```php
<?php

use PostFinance\DirectLink\DirectLinkQueryRequest;
use PostFinance\Passphrase;
use PostFinance\ShaComposer\AllParametersShaComposer;
use PostFinance\DirectLink\Alias;

$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaInParameterFilter); //optional

$directLinkRequest = new DirectLinkQueryRequest($shaComposer);
$directLinkRequest->setPspid('123456');
$directLinkRequest->setUserId('postfinance-api-user');
$directLinkRequest->setPassword('postfinance-api-password');
$directLinkRequest->setPayId('order_1234');
$directLinkRequest->validate();

// now create a url to be posted to PostFinance
// you have access to $directLinkRequest->toArray(), $directLinkRequest->getPostFinanceUri() and directLinkRequest->getShaSign()
```

# DirectLinkMaintenanceRequest #

```php
<?php

use PostFinance\DirectLink\DirectLinkMaintenanceRequest;
use PostFinance\Passphrase;
use PostFinance\ShaComposer\AllParametersShaComposer;
use PostFinance\DirectLink\Alias;

$passphrase = new Passphrase('my-sha-in-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaInParameterFilter); //optional

$directLinkRequest = new DirectLinkMaintenanceRequest($shaComposer);
$directLinkRequest->setPspid('123456');
$directLinkRequest->setUserId('postfinance-api-user');
$directLinkRequest->setPassword('postfinance-api-password');
$directLinkRequest->setPayId('order_1234');
$directLinkRequest->setOperation(DirectLinkMaintenanceRequest::OPERATION_AUTHORISATION_RENEW);
$directLinkRequest->validate();

// now create a url to be posted to PostFinance
// you have access to $directLinkRequest->toArray(), $directLinkRequest->getPostFinanceUri() and directLinkRequest->getShaSign()
```

# EcommercePaymentResponse #

```php
<?php

use Ogone\Ecommerce\EcommercePaymentResponse;
use Ogone\ShaComposer\AllParametersShaComposer;
use PostFinance\Ecommerce\EcommercePaymentResponse;
use PostFinance\ShaComposer\AllParametersShaComposer;

// ...

$ecommercePaymentResponse = new EcommercePaymentResponse($_REQUEST);

$passphrase = new Passphrase('my-sha-out-passphrase-defined-in-ogone-interface');
$passphrase = new Passphrase('my-sha-out-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaOutParameterFilter); //optional

Expand All @@ -182,14 +237,14 @@ This library currently supports both the legacy method "Main parameters only" an
```php
<?php

use Ogone\DirectLink\CreateAliasResponse;
use Ogone\ShaComposer\AllParametersShaComposer;
use PostFinance\DirectLink\CreateAliasResponse;
use PostFinance\ShaComposer\AllParametersShaComposer;

// ...

$createAliasResponse = new CreateAliasResponse($_REQUEST);

$passphrase = new Passphrase('my-sha-out-passphrase-defined-in-ogone-interface');
$passphrase = new Passphrase('my-sha-out-passphrase-defined-in-postfinance-interface');
$shaComposer = new AllParametersShaComposer($passphrase);
$shaComposer->addParameterFilter(new ShaOutParameterFilter); //optional

Expand All @@ -209,9 +264,9 @@ As the DirectLink payment gets an instant feedback from the server (and no async
```php
<?php

use Ogone\DirectLink\DirectLinkPaymentResponse;
use PostFinance\DirectLink\DirectLinkPaymentResponse;

$directLinkResponse = new DirectLinkPaymentResponse('ogone-direct-link-result-as-xml');
$directLinkResponse = new DirectLinkPaymentResponse('postfinance-direct-link-result-as-xml');

if($directLinkResponse->isSuccessful()) {
// handle payment confirmation
Expand All @@ -224,5 +279,5 @@ As the DirectLink payment gets an instant feedback from the server (and no async

# Parameter filters #
ParameterFilters are used to filter the provided parameters (no shit Sherlock).
Both ShaIn- and ShaOutParameterFilters are provided and are based on the parameter lists defined in the Ogone documentation.
Both ShaIn- and ShaOutParameterFilters are provided and are based on the parameter lists defined in the PostFinance documentation.
Parameter filtering is optional, but we recommend using them to enforce expected parameters.
19 changes: 0 additions & 19 deletions autoload.php

This file was deleted.

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
"require-dev" : {
"phpunit/phpunit": "3.7.*",
"guzzle/guzzle": "3.7.*"
"guzzle/guzzle": "3.7.*",
"symfony/class-loader": "2.5.*"
}
}
}
44 changes: 44 additions & 0 deletions lib/PostFinance/AbstractDirectLinkRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
* @author Nicolas Clavaud <[email protected]>
*/

namespace PostFinance;

use InvalidArgumentException;

abstract class AbstractDirectLinkRequest extends AbstractRequest {

public function setUserId($userid)
{
if (strlen($userid) < 8) {
throw new InvalidArgumentException("User ID is too short");
}
$this->parameters['userid'] = $userid;
}

public function setPassword($password)
{
if (strlen($password) < 8) {
throw new InvalidArgumentException("Password is too short");
}
$this->parameters['pswd'] = $password;
}

public function setPayId($payid)
{
$this->parameters['payid'] = $payid;
}

public function setOrderId($orderid)
{
$this->parameters['orderid'] = $orderid;
}

protected function getRequiredFieldGroups()
{
return array(
array('payid', 'orderid'),
);
}
}
Loading

0 comments on commit 1b11764

Please sign in to comment.