PHP code example of zkelo / unitpay-sdk

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

    

zkelo / unitpay-sdk example snippets


use zkelo\Unitpay\Unitpay;

$secretKey = 'Your secret key';
$publicKey = 'Your public key';

$sdk = new Unitpay($secretKey, $publicKey);


// Order amount
$amount = 5;

// Order ID
$orderId = 161;

// Order description
$description = "Order $orderId (test)";

// Creating form link
$url = $sdk->form($amount, $orderId, $description);

// Redirecting user to form
header("Location: $url");

// Retrieving IP
$remoteIp = $_SERVER['REMOTE_ADDR'];

// Retrieving request data from `$_GET` array using `filter_input()` function
$requestData = filter_input_array(INPUT_GET);

// Handling request using SDK
$response = $sdk->handleRequest($remoteIp, $requestData, $success);

// Returning response
echo json_encode($response);

// ...

// Handling request using SDK
$response = $sdk->handleRequest($remoteIp, $requestData, $success);

if ($success) {
    // Do something on success request
} else {
    // Do something on bad request
}

// Returning response
echo json_encode($response);

// Order amount
$amount = 5;

// Order ID
$orderId = 161;

// Order description
$description = "Order $orderId (test)";

// User IP (can be either IPv4 or IPv6)
$ip = '127.0.0.1';

// Creating payment
$paymentId = $sdk->initPayment('card', $orderId, $amount, $description, $ip);

// Payment ID in Unitpay (this is not order ID in your app or something else!)
$paymentId = 7777777777;

// Retrieving information
$paymentInfo = $sdk->getPayment($paymentId);

// Display order amount and currency
echo "Order amount: $paymentInfo->orderSum (currency: $paymentInfo->orderCurrency)", PHP_EOL;


namespace App\Locales;

/**
 * My own locale
 */
class MyLocale extends Locale implements LocaleInterface
{
    /**
     * {@inheritDoc}
     */
    public static function messages(): array
    {
        return [
            // Write translations here.
            //
            // For example, if you want to translate some currencies names,
            // you just need to specify all its messages inside `currency` property
            // which will be array which has currencies IDs as keys
            // and translation messages for each of them as values.
            'currency' => [
                // Don't use raw names of currencies,
                // payment methods and etc. in your
                // locale class like here:
                //
                'RUB' => 'Russian rouble', // <-- This is wrong!
                // Instead of using RAWs
                // you should use model
                // constants like here:
                //
                Currency::RUB => 'Russian rouble' // <-- This is right!
            ]
        ];
    }
}

use zkelo\Unitpay\Models\Locale;

// In this example `en_GB` is name of your locale
Locale::use('en_GB', App\Locales\MyLocale::class);

// Specifying locale as default for SDK
$sdk->setDefaultLocale('en_GB');

// Or... specifying locale in "real-time"
$sdk->form(10, 6, 'Test payment', zkelo\Unitpay\Models\Payment::METHOD_CARD, zkelo\Unitpay\Models\Currency::RUB, 'en_GB');