Guzzle middleware for easy authentication with the CM Payments API
Branch: master
Clone or download
Latest commit e3f2591 Jun 2, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests Add extra comments in the test Jun 1, 2017
.gitattributes Initial commit Jun 1, 2017
.gitignore Initial commit Jun 1, 2017
.scrutinizer.yml
.travis.yml
LICENSE
README.md Add badge-coverage Jun 1, 2017
composer.json
phpunit.xml.dist Initial commit Jun 1, 2017

README.md

Guzzle Authentication Middleware

Build Status Scrutinizer Software License Total Downloads Code Coverage

This middleware implements the authentication part of a guzzle request to the CM Payments PSP-api.

This library is compatible with PHP 5.5+ and PHP 7.0, but requires the Guzzle, PHP HTTP client version ^6.0

Installation

To install cmpayments/guzzle-psp-authentication-middleware just require it with composer:

# composer require cmpayments/guzzle-psp-authentication-middleware

Usage examples

Below an example in order to request an iDEAL-transaction via a POST-request.

<?php
    $key = 'Your-OAuth-Consumer-Key';
    $secret = 'Your-OAuth-Consumer-Secret';

    $body = [
        'amount'   => 15.95,
        'currency' => 'EUR',
        'payments' => [
            [
                'amount'          => 15.95,
                'currency'        => 'EUR',
                'payment_method'  => 'iDEAL',
                'payment_details' => [
                    'issuer_id'     => 'RABONL2U',
                    'purchase_id'   => 'unqiue' . (new \DateTime())->format('YmdHis'),
                    'description'   => 'Transaction description',
                    'success_url'   => 'http://www.yourdomain.com/ideal/success',
                    'failed_url'    => 'http://www.yourdomain.com/ideal/failed',
                    'cancelled_url' => 'http://www.yourdomain.com/ideal/cancelled',
                    'expired_url'   => 'http://www.yourdomain.com/ideal/expired'
                ]
            ],

        ],
    ];

    $stack = HandlerStack::create();
    $authenticationMiddleware = new AuthenticationMiddleware($key, $secret);
    $stack->push($authenticationMiddleware);
    $client = new Client(['base_uri' => 'https://api.cmpayments.com/', 'handler' => $stack]);

    $response = $client->request('POST', 'charges/v1', [
        'json' => $body
    ]);

Below an example in order to request the iDEAL-issuers list via a GET-request.

<?php
    $key = 'Your-OAuth-Consumer-Key';
    $secret = 'Your-OAuth-Consumer-Secret';

    $stack = HandlerStack::create();
    $authenticationMiddleware = new AuthenticationMiddleware($key, $secret);
    $stack->push($authenticationMiddleware);
    $client = new Client(['base_uri' => 'https://api.cmpayments.com/', 'handler' => $stack]);

    $response = $client->request('GET', 'issuers/v1/ideal', []);

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Copyright and license

The cmpayment/guzzle-psp-authentication-middleware library is copyright © CM Payments and licensed for use under the MIT License (MIT). Please see LICENSE for more information.