wearesho-team / platon
Platon integration
3.1.0
2024-11-12 16:40 UTC
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^6.5.8 || ^7.4.5
- horat1us/environment-config: ^1.2
- nekman/luhn-algorithm: ^5.0.1
- nesbot/carbon: ^2.24 || ^3.0
- wearesho-team/bobra-payments: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- dev-master
- 3.1.0
- 3.0.0
- 2.0.1
- 2.0.0
- 1.13.7
- 1.13.6
- 1.13.5
- 1.13.4
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.3
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.0
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.2.0-BETA
- 1.1.0
- 1.0.0
- 1.0.0-RC6
- 1.0.0-RC5
- 1.0.0-RC4
- 1.0.0-RC3
- 1.0.0-RC2
- 1.0.0-RC1
- dev-hotfix/credit-response-optimize
- dev-feature/cghooks
- dev-feature/unique-transfer
This package is auto-updated.
Last update: 2024-11-12 16:40:39 UTC
README
Platon SDK for PHP.
Changelog |
Usage Examples
API
Installation
Using composer:
composer require wearesho-team/platon
Usage
Configuration
For configuration you have to use ConfigInterface. Available implementations:
- Config - simple entity. Example:
<?php use Wearesho\Bobra\Platon; $config = new Platon\Config("Key", "Pass", "PaymentType");
- EnvironmentConfig - configuration using getenv. Example:
<?php use Wearesho\Bobra\Platon; $config = new Platon\EnvironmentConfig();
Environment configuration:
Generating payment configuration
Use Client to fetch payment config
<?php use Wearesho\Bobra\Platon; use Wearesho\Bobra\Payments; $config = new Platon\EnvironmentConfig(); $client = new Platon\Client($config); $payment = $client->createPayment( new Payments\UrlPair( 'http://redirect-url-on-success', 'http://redirect-url-on-fail' ), new Platon\Transaction( $serviceId = 1, $amount = 500, $paymentType = 'paymentType', $description = 'description for payment', $ext = [ 0 => 'some-info' ], // optional, will be returned in notification $currency = 'UAH', // optional $formId = 'Form id for front-end' // optional ) );
Rendering form
<?php $config = $payment->jsonSerialize(); // ['action' => 'URL', 'data' => 'url']
*You should send data
to action
url.
Notification
Use Notification\Server to create payment instance from platon`s request:
<?php use Wearesho\Bobra\Platon; class PlatonController { public function actionHandle() { // You can use several platon configs in different cases. // Handler will get that one that matches `key` param from platon`s request. // All platon configs should be passed into ConfigProvider. $configProvider = new Platon\Notification\ConfigProvider([ new Platon\Config('First key', 'first pass', 'CC'), new Platon\Config('Second key', 'second pass', 'CC'), ]); $server = new Platon\Notification\Server($configProvider); try { $payment = $server->handle($_POST); } catch (Platon\Notification\InvalidSignException $exception) { // handle invalid sign } catch (\InvalidArgumentException $exception) { // When received data is incorrect or some required fields are empty } // You can use returned Payment instance to save transaction data. } }
Info
Fetching information about account balance. Use Info\ConfigInterface for configuration. EnvironmentConfig available:
<?php use Wearesho\Bobra\Platon; $publicKey = readline("Public Key: "); $privateKey = readline("Private Key: "); $config = new Platon\Info\Config($publicKey, $privateKey); $client = new GuzzleHttp\Client(); $repository = new Platon\Info\Repository($config, $client); // All items can be converted to string and JSON formats $responses = $repository->get();
See Info\Response for details.