1. Go to this page and download the library: Download capusta/php-sdk 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/ */
capusta / php-sdk example snippets
$guzzleClient = new GuzzleHttp\Client();
$transport = new Capusta\SDK\Transport\GuzzleApiTransport($guzzleClient);
$client = new Capusta\SDK\Client($transport);
$client-> setAuth('merchantEmail', 'token');
// Create a request object
$createPaymentRequest = new Capusta\SDK\Model\Request\Payment\CreatePaymentRequest();
// Set up $createPaymentRequest with ent($createPaymentRequest);
} catch (\Exception $e) {
// ...
}
$requestArray = [
'id' => "YOUR_TRANSACTION_ID", // your ID of transaction, optional.
'description' => "description", //optoinal
'amount' => [
'amount' => 1000, //1000 = 10 RUB, *** OPTIONAL *** (if you want to get bill with any amount within limits)
'currency' => 'RUB' //name of currency
], //array of 'amount' in minor value and 'currency'.
'projectCode' => "code", //nal array of 'name', 'phone', 'email', 'comment'.
'successUrl' => "https://my-site.com/payment/success", // optional redirection url after success payment.
'failUrl' => "https://my-site.com/payment/fail" // optional redirection url after failed payment
];
try {
/** @var Capusta\SDK\Model\Response\Payment\CreatePaymentResponse $createPaymentResponse */
$createPaymentResponse = $client->createPayment($requestArray);
} catch (\Exception $e) {
// ...
}
if ($createPaymentResponse->getStatus()=='CREATED'){
// redirect user to $createPaymentResponse->getPayUrl();
}
// Create a request object
$createBillRequest = new Capusta\SDK\Model\Request\Bill\CreateBillRequest();
// Set up $createBillRequest with l($createBillRequest);
} catch (\Exception $e) {
// ...
}
$requestArray = [
'id' => "YOUR_BILL_ID", //optional
'amount' => [
'amount' => 1000, //1000 = 10 RUB, *** OPTIONAL *** (if you want to get payment with any amount within limits)
'currency' => 'RUB' //name of currency
], //array of 'amount' in minor value and 'currency'
'subscription' => [
'per' => 'WEEKLY', // period, optional. can be 'DAILY', 'MONTHLY', 'WEEKLY, 'SELECTIVELY'.
// if per is absent it creates simple the recurring bill without any period.
'oneTimePayment' => false, //boolean. if false the bill can be paid several times.
'trialDays' => 0 // optional int. The free days of trial subscription before payment.
], //optional settings to create recurring payment.
'description' => "description", //optional description of bill
'projectCode' => "code", //your project code
'custom' => [/*...*/], // optional array of key=>value structure and length < 255.
'expire' => new DateTime('now + 1 day'), // optional expiration datetime (for example bill can be paid within 1 day)
'successUrl' => "https://my-site.com/payment/success", // optional redirection url after success payment.
'failUrl' => "https://my-site.com/payment/fail" // optional redirection url after failed payment
];
// ^^^^^^^^ the same fields like in payment method.
try {
/** @var Capusta\SDK\Model\Response\Bill\CreateBillResponse $createBillResponse */
$createBillResponse = $client->createBill($requestArray);
} catch (\Exception $e) {
// ...
}
if ($createBillResponse->getStatus()=='CREATED'){
// redirect user to $createBillResponse->getPayUrl();
}
// Create a request object
$createPayoutRequest = new Capusta\SDK\Model\Request\Payout\CreatePayoutRequest();
// Set up $createPayoutRequest with ($createPayoutRequest);
} catch (\Exception $e) {
// ...
}
$requestArray = [
'id' => 'transaction_id', // optional
'amount' => [
'amount' => 1000, //1000 = 10 RUB
'currency' => 'RUB' //name of currency
], // array of 'currency' and 'amount' in minor value
'projectCode' => 'ProjectCode', // or 'projectId' => projectId
'pan' => 'payout card number', // i.e. 4111111111111111
'description' => 'my payout description', //optional
];
try {
/** @var Capusta\SDK\Model\Response\Payout\CreatePayoutResponse $createPayoutResponse */
$createPayoutResponse = $client->createPayout($requestArray);
} catch (\Exception $e) {
// ...
}
// Create a request object
$getStatusRequest = new Capusta\SDK\Model\Request\Status\GetStatusRequest();
// Set up $getStatusRequest with ($getStatusRequest);
} catch (\Exception $e) {
// ...
}
$requestArray = [
'transaction_id' => 'YOUR_TRANSACTION_ID', // here is the id of the transaction
'withFailed' => TRUE, // Optional, Boolean. If TRUE, you can receive details of failed transaction
];
try {
/** @var Capusta\SDK\Model\Response\Status\getStatusResponse $getStatusResponse */
$getStatusResponse = $client->getStatus($requestArray);
} catch (\Exception $e) {
// ...
}
// Create a request object
$getBillStatusRequest = new Capusta\SDK\Model\Request\Status\GetStatusRequest();
// Set up $getStatusRequest with ($getBillStatusRequest);
} catch (\Exception $e) {
// ...
}
$requestArray = [
'transaction_id' => 'YOUR_TRANSACTION_ID', // here is the id of the transaction
'withFailed' => TRUE, // OPTIONAL BOOLEAN. If you want to get all transactions even failed with details of failure - you need to set it to TRUE, otherwise FALSE.
];
try {
/** @var Capusta\SDK\Model\Response\Status\getStatusResponse $getStatusResponse */
$getStatusResponse = $client->getBillStatus($requestArray);
} catch (\Exception $e) {
// ...
}
$registry = new Capusta\SDK\Model\Request\Registry\GetRegistryRequest();
$registry->setFrom(new \DateTime('1 day ago'))
->setTo(new \DateTime())
->setProjectCode('projectCode');
$response = $client->getRegistry($registry);
$requestArray = [
'projectCode' => 'projectCode', // here is the id of the transaction
'from' => '2020-04-30T08:19:47.000-04:00', // start date
'to' => '2020-05-01T08:19:47.000-04:00',
'withFailed' => TRUE, // If you want to get all (even failed) transactions.
];
try {
/** @var $getRegistryResponse array */
$getRegistryResponse = $client->getRegistry($requestArray);
} catch (\Exception $e) {
// ...
}
// Create a request object
$createProjectRequest = new Capusta\SDK\Model\Request\Project\CreateProjectRequest();
// Set up $createProjectRequest with ject($createProjectRequest);
} catch (\Exception $e) {
// ...
}