PHP code example of payselection / payselection-php-client

1. Go to this page and download the library: Download payselection/payselection-php-client 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/ */

    

payselection / payselection-php-client example snippets


$apiClient = new \PaySelection\Library();
$apiClient->setConfiguration([
    'webpay_url' => 'https://webform.payselection.com',
    'api_url' => 'https://gw.payselection.com',
    'site_id' => '123',
    'secret_key' => '###########',
    'webhook_url' => 'https://webhook.site/notification/'
]);

try {
    $response = $apiClient->createWebPay([
        'MetaData' => [
            'PaymentType' => 'Pay'
        ],
        'PaymentRequest' => [
            'OrderId' => 'a3a393d8-ac47-11ed-afa1-0242ac1200021',
            'Amount' => '100.00',
            'Currency' => 'RUB',
            'Description' => 'Order description',
            'RebillFlag' => true,
            'ExtraData' => [
                'WebhookUrl' => 'https://webhook.site/f2bea4b3-e85c-40e9-9587-b588cfda84d3'
            ],
        ],
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ],
        'CustomerInfo' => [
            'ZIP' => '222410',
            'Language' => 'ru'
        ],
        'RecurringData' => [
            'Amount' => '100.00',
            'Currency' => 'RUB',
            'Description' => 'Recurring description',
            'WebhookUrl' => 'https://webhook.site/f2bea4b3-e85c-40e9-9587-b588cfda84d3',
            'AccountId' => 'order63',
            'Email' => '[email protected]',
            'StartDate' => '2023-05-11T13:38+0000',
            'Interval' => '5',
            'Period' => 'day',
            'MaxPeriods' => '3',
            'ReceiptData' => [
                'timestamp' => '2023-01-11T13:38+0000',
                'external_id' => '12345678',
                'receipt' => [
                    'client' => [
                        'name' => 'Inan Ivanov',
                        'email' => '[email protected]',
                    ],
                    'company' => [
                        'email' => '[email protected]',
                        'inn' => '12345',
                        'payment_address' => 'company address',
                    ],
                    'items' => [
                        [
                            'name' => 'Product title 1',
                            'price' => 123.00,
                            'quantity' => 1,
                            'sum' => 123.00,
                            'payment_method' => 'full_prepayment',
                            'payment_object' => 'commodity',
                            'vat' => [
                                'type' => 'vat0'
                            ]
                        ],
                        [
                            'name' => 'Product title 2',
                            'price' => 10.00,
                            'quantity' => 2,
                            'sum' => 20.00,
                            'payment_method' => 'full_prepayment',
                            'payment_object' => 'commodity',
                            'vat' => [
                                'type' => 'vat0'
                            ]
                            ],
                    ],
                    'payments' => [
                        [
                            'type' => 1, 
                            'sum' => 143.00
                        ]
                    ],
                    'total' => 143.00     
                ]
            ]
        ]
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->getOrderStatus('a3a393d8-ac47-11ed-afa1-0242ac120002');
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->getTransactionStatus('PS00000000000001');
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->createPayment([
        'OrderId' => 'a3a393d8-ac47-11ed-afa1-0242ac120002',
        'Amount' => '100.00',
        'Currency' => 'RUB',
        'Description' => 'Order description',
        'RebillFlag' => false,
        'CustomerInfo' => [
            'IP' => '192.168.1.10'
        ],
        'ExtraData' => [
            'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
        ],
        'PaymentMethod' => 'Card',
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ],
        'PaymentDetails' => [
            'CardNumber'=> '4111111111111111',
            'ExpMonth'=> '02',
            'ExpYear'=> '25',
            'CardholderName'=> 'Card Holder',
            'CVC'=> '789'
        ]
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->createBlock([
        'OrderId' => 'a3a393d8-ac47-11ed-afa1-0242ac120002',
        'Amount' => '100.00',
        'Currency' => 'RUB',
        'Description' => 'Order description',
        'RebillFlag' => false,
        'CustomerInfo' => [
            'IP' => '192.168.1.10'
        ],
        'ExtraData' => [
            'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
        ],
        'PaymentMethod' => 'Card',
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ],
        'PaymentDetails' => [
            'CardNumber'=> '4111111111111111',
            'ExpMonth'=> '02',
            'ExpYear'=> '25',
            'CardholderName'=> 'Card Holder',
            'CVC'=> '789'
        ]
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->rebillPayment([
        'OrderId' => 'a3a393d8-ac47-11ed-afa1-0242ac120002',
        'Amount' => '1.00',
        'Currency' => 'RUB',
        'Description' => 'Order description',
        'RebillFlag' => true,
        'RebillId' => 'GE00000001173680',
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ],
        'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->confirmPayment([
        'TransactionId' => 'PS00000000000001',
        'OrderId' => 'a3a393d8-ac47-11ed-afa1-0242ac120002',
        'PaRes' => '123',
        'MD' => '456'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->createRefund([
        'TransactionId' => 'PS00000000000001',
        'Amount' => '1.00',
        'Currency' => 'RUB',
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ],
        'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->cancelPayment([
            'TransactionId' => 'PS00000000000001',
            'Amount' => '100.00',
            'Currency' => 'RUB',
            'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->chargePayment([
        'TransactionId' => 'PS00000000000001',
        'Amount' => '100.00',
        'Currency' => 'RUB',
        'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->cancelSubscription([
        'RebillId' => 'GE00000001173680'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->createPayout([
        'OrderId' => 'a3a393d8-ac47-11ed-afa1-0242ac120002',
        'Amount' => '100.00',
        'Currency' => 'RUB',
        'Description' => 'Order description',
        'CustomerInfo' => [
            'IP' => '192.168.1.10'
        ],
        'ExtraData' => [
            'WebhookUrl' => 'https://webhook.site/38fb8867-a648-423e-9146-30576b2ad8e4'
        ],
        'PayoutMethod' => 'Card',
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ],
        'PayoutDetails' => [
            'CardNumber'=> '4111111111111111',
            'CardholderName'=> 'Card Holder',
        ]
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->getBalance();
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->registerRecurring([
        'RebillId' => 'GE00000001173680',
        'Amount' => '100.00',
        'Currency' => 'RUB',
        'Description' => 'Recurring description',
        'WebhookUrl' => 'https://webhook.site/f2bea4b3-e85c-40e9-9587-b588cfda84d3',
        'AccountId' => 'order63',
        'Email' => '[email protected]',
        'StartDate' => '2023-05-11T13:38+0000',
        'Interval' => '5',
        'Period' => 'day',
        'MaxPeriods' => '3',
        'ReceiptData' => [
            'timestamp' => '2023-01-11T13:38+0000',
            'external_id' => '12345678',
            'receipt' => [
                'client' => [
                    'name' => 'Inan Ivanov',
                    'email' => '[email protected]',
                ],
                'company' => [
                    'email' => '[email protected]',
                    'inn' => '12345',
                    'payment_address' => 'company address',
                ],
                'items' => [
                    [
                        'name' => 'Product title 1',
                        'price' => 123.00,
                        'quantity' => 1,
                        'sum' => 123.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                    ],
                    [
                        'name' => 'Product title 2',
                        'price' => 10.00,
                        'quantity' => 2,
                        'sum' => 20.00,
                        'payment_method' => 'full_prepayment',
                        'payment_object' => 'commodity',
                        'vat' => [
                            'type' => 'vat0'
                        ]
                        ],
                ],
                'payments' => [
                    [
                        'type' => 1, 
                        'sum' => 143.00
                    ]
                ],
                'total' => 143.00     
            ]
        ]
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $response = $apiClient->cancelRecurring([
        'RecurringId' => '1173'
    ]);
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($response);

try {
    $result = $apiClient->hookPay();
} catch (\Exception $e) {
    $response = $e->getMessage();
}

var_dump($result);

composer