PHP code example of apirone / apirone-sdk-php

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

    

apirone / apirone-sdk-php example snippets



// Our MySQL engine example
$conn = new mysqli('host', 'user', 'pass', 'database');
$conn->select_db('database');

// DB MySQL handler example
$db_handler = static function($query) {
    global $conn;
    $result = $conn->query($query, MYSQLI_STORE_RESULT);

    if (!$result) {
        return $conn->error;
    }
    if (gettype($result) == 'boolean') {
        return $result;
    }
    return $result->fetch_all(MYSQLI_ASSOC);
};



$logger = static function($level, $message, $context) {
    print_r([$level, $message, $context]);
};



$logger = new /Psr/Log/LoggerInterface();



use Apirone\SDK\Invoice;

Invoice::db($db_handler, 'table_prefix_');
Invoice::setLogger($logger);


use Apirone\SDK\Service\InvoiceDb;

// Create the invoice table if it doesn't exist
InvoiceDb::install('table_prefix', $charset = 'urf8', $collate = 'utf_general_ci');

// Setup invoice handlers and Settings
Invoice::db($db_handler, $table_prefix);
Invoice::log($log_handler);
Invoice::settings(Settings::fromFile('/absolute/path/to/settings.json'));

use Apirone\SDK\Model\Settings;

$settings = Settings::init();
$settings->createAccount();

// Save the settings object to the file
$settings->toFile('absolute/path/to/settings.json');

// Get settings as JSON-object to save it to the database
$json = $settings->toJson();


$fromFile = Settings::fromFile('/absolute/path/to/settings.json');

// For example you have get_option function
$json = get_option('apirone_settings');

$fromJson = Settings::fromJson($json);



use Apirone\SDK\Invoice;
use Apirone\SDK\Model\Settings;

// Setup invoice handlers and Settings
Invoice::db($db_handler, $table_prefix);
Invoice::log($log_handler);
Invoice::settings(Settings::fromFile('/absolute/path/to/settings.json'));

$invoice = Invoice::init('btc', 25000);

$invoice->callbackUrl('https://example.com/callback_page');
$invoice->lifetime(1800);

$invoice->crete();

// You can see the created invoice JSON data
$json = $invoice->toJson();

use Apirone\SDK\Invoice;
use Apirone\SDK\Model\Settings;

// Setup invoice handlers and Settings
Invoice::db($db_handler, $table_prefix);
Invoice::log($log_handler);
Invoice::settings(Settings::fromFile('/absolute/path/to/settings.json'));

$id = '9qAs2OQao43VWz72';
$invoice = Invoice::getInvoice($id);


// Create an order process function
$order_status_handler = static function ($invoice) {
    // You need to set the order_id when creating an invoice.
    $order_id = $invoice->order();
    // ... Write here your business logic
}
// ... Setup invoice handlers and settings


Invoice::callbackHandler($order_status_handler);

use Apirone\SDK\Invoice;
use Apirone\SDK\Model\Settings;

// Setup invoice handlers and Settings
Invoice::db($db_handler, $table_prefix);
Invoice::log($log_handler);
Invoice::settings(Settings::fromFile('/absolute/path/to/settings.json'));

// Set invoice data url - render ajsx response page
Invoice::dataUrl('render_ajax_response.php');

// In case when $invoice_id does not set function try to find id from request params - $_GET['invoice']
$ = Invoice::renderLoader();

// If you got the 

use Apirone\SDK\Invoice;
use Apirone\SDK\Model\Settings;

// Setup invoice handlers and Settings
Invoice::db($db_handler, $table_prefix);
Invoice::log($log_handler);
Invoice::settings(Settings::fromFile('/absolute/path/to/settings.json'));

Invoice::renderAjax();