avto-dev/cloud-payments-laravel

Cloud Payments PHP-client

v1.3.0 2021-04-06 09:45 UTC

This package is auto-updated.

Last update: 2022-06-06 12:34:48 UTC


README

logo

Cloud Payments PHP-client

Version PHP Version Build Status Coverage Downloads count License

The package provides easy way to use Cloud Payments API.

Install

Require this package with composer using the following command:

$ composer require avto-dev/cloud-payments-laravel "^1.1"

Installed composer is required (how to install composer).

Configuration

You can find laravel framework integration here

For client configuration use Config instance. Client constructor requires Public ID and API Secret that you can find in ClodPayments personal area.

use AvtoDev\CloudPayments\Config;

$config = new Config('pk_some_key', 'some_api_key');

Usage

Select one of requset builders:

$request_builder = new \AvtoDev\CloudPayments\Requests\Payments\Cards\CardsAuthRequestBuilder;

Set all necessary parameters through the setters:

/** @var $request_builder \AvtoDev\CloudPayments\Requests\AbstractRequestBuilder */

$request_builder->setAccountId('some_id');
$request_builder->setName('name');

Get PSR7 request:

/** @var \AvtoDev\CloudPayments\Requests\AbstractRequestBuilder $request_builder */
/** @var \Psr\Http\Message\RequestInterface $request */

$request = $request_builder->buildRequest();

Set up client, and send the request:

$client = new \AvtoDev\CloudPayments\Client(
    new \GuzzleHttp\Client,
    new \AvtoDev\CloudPayments\Config('public_id', 'api_key')
);

/** @var \Psr\Http\Message\RequestInterface $request */
$response = $client->send($request);

Api client

Constructing

Constructor requires any GuzzleHttp\ClientInterface instance and Config instance

/** @var \AvtoDev\CloudPayments\Config $config */

use AvtoDev\CloudPayments\Client;
use GuzzleHttp\Client as GuzzleClient;

$client = new Client(new GuzzleClient, $config);

Sending

This method allows to send any Psr\Http\Message\RequestInterface and returns only Psr\Http\Message\ResponseInterface, that allow you to build own requests as you want or use one of provided requests builders.

This client does only one thing: authorizes requests for CloudPayments and sends them.

$request = new \GuzzleHttp\Psr7\Request('POST','https://api',[],'{"foo":"bar"}');

/** @var \AvtoDev\CloudPayments\Client $client */
$response = $client->send($request);

Request builders

Supported builders:

Builder Description Documentation link
TestRequestBuilder The method to test the interaction with the API Link
CardsAuthRequestBuilder The method to make a payment by a cryptogram Link
CardsChargeRequestBuilder The method to make a payment by a cryptogram. Charge only Link
CardsPost3DsRequestBuilder 3-D Secure Processing Link
TokensAuthRequestBuilder The method to make a payment by a token Link
TokensChargeRequestBuilder The method to make a payment by a token. Charge only Link
PaymentsConfirmRequestBuilder Payment Confirmation Link
PaymentsVoidRequestBuilder Payment Cancellation Link
SubscriptionsCreateRequestBuilder Creation of Subscriptions on Recurrent Payments Link
SubscriptionsGetRequestBuilder Subscription Details Link
SubscriptionsFindRequestBuilder Subscriptions Search Link
SubscriptionsUpdateRequestBuilder Recurrent Payments Subscription Change Link
SubscriptionsCancelRequestBuilder Subscription on Recurrent Payments Cancellation Link

How to get card cryptogram packet?

Idempotency

Idempotency is an ability of API to produce the same result as the first one without re-processing in case of repeated requests. That means you can send several requests to the system with the same identifier, and only one request will be processed. All the responses will be identical. Thus the protection against network errors is implemented which can lead to creation of duplicate records and actions.

To enable idempotency, it is necessary to call setRequestId('request_id') method with a unique identifier in API request. Generation of request identifier remains on your side - it can be a guid, a combination of an order number, date and amount, or other values of your choice. Each new request that needs to be processed must include new request_id value. The processed result is stored in the system for 1 hour.

Frameworks integration

Laravel

Laravel 5.5 and above uses Package Auto-Discovery, so doesn't require you to manually register the service-provider. Otherwise you must add the service provider to the providers array in ./config/app.php:

'providers' => [
    // ...
    AvtoDev\CloudPayments\Frameworks\Laravel\ServiceProvider::class,
]

Laravel configuration

Service provider pick configuration from services.cloud_payments config. So you need to put it into config/services.php file. For example:

return [
    // ...
    /*
    |--------------------------------------------------------------------------
    | CloudPayments Settings
    |--------------------------------------------------------------------------
    | - `public_id` (string) - Public ID  (You can find it in personal area)
    | - `api_key`   (string) - API Secret (You can find it in personal area)
    |
    */
    'cloud_payments' => [
        'public_id' => env('CLOUD_PAYMENTS_PUBLIC_ID', 'some id'),
        'api_key'   => env('CLOUD_PAYMENTS_API_KEY', 'some api key'),
    ],
];

Testing

For package testing we use phpunit framework. Just write into your terminal:

$ make build
$ make install
$ make test

Changes log

Release date Commits since latest release

Changes log can be found here.

Support

Issues Issues

If you will find any package errors, please, make an issue in current repository.

License

This is open-sourced software licensed under the MIT License.