cmpayments/guzzle-psp-authentication-middleware

Guzzle middleware which adds authentication-header to Guzzle-requests.

1.0.1 2020-07-07 09:20 UTC

This package is auto-updated.

Last update: 2024-12-07 18:45:58 UTC


README

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 or ^7.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.