PHP code example of wearesho-team / platon

1. Go to this page and download the library: Download wearesho-team/platon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wearesho-team / platon example snippets




use Wearesho\Bobra\Platon;

$config = new Platon\Config("Key", "Pass", "PaymentType");



use Wearesho\Bobra\Platon;

$config = new Platon\EnvironmentConfig();



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
    )
);



$config = $payment->jsonSerialize(); // ['action' => 'URL', 'data' => 'url']



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 



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();