avto-dev / cloud-payments-laravel
Cloud Payments PHP-client
Installs: 13 127
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ~7.5
- guzzlehttp/psr7: ^2.6.2
- psr/http-client: ~1.0
Requires (Dev)
- avto-dev/guzzle-url-mock: ^1.6
- fakerphp/faker: ^1.12
- laravel/laravel: ~10.0 || ~11.0
- nesbot/carbon: ^2.66
- phpstan/phpstan: ^1.10.66
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2024-12-01 00:07:18 UTC
README
Cloud Payments PHP-client
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
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:
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
Changes log can be found here.
Support
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.