PHP code example of hotpayments / php-sdk

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

    

hotpayments / php-sdk example snippets




otPayments\Hotpayments;

// Set your API key
Hotpayments::auth('your-api-key-here');

// Create a customer
$customer = Hotpayments::customers()->create([
    'name' => 'John Doe',
    'email' => '[email protected]',
    'phone_number' => '1111111111',
    'document' => '11111111111'
]);

// List customers with pagination
$customers = Hotpayments::customers()->list(['per_page' => 10]);

// Create a PIX QR Code transaction
$transaction = Hotpayments::transactions()->createPixQrCode([
    'amount' => 100.50,
    'customer_id' => 'customer-uuid-here',
    'description' => 'Payment for services'
]);

// Check transaction status
$status = Hotpayments::transactions()->check('transaction-uuid-here');

Hotpayments::auth('your-api-key-here');

// Create a new customer
$customer = Hotpayments::customers()->create([
    'name' => 'John Doe',
    'email' => '[email protected]',
    'phone_number' => '1111111111',
    'document' => '11111111111'
]);

// List all customers with pagination
$customers = Hotpayments::customers()->list([
    'per_page' => 15,
    'page' => 1
]);

// Create a subscription
$subscription = Hotpayments::subscriptions()->create([
    'customer_id' => 'customer-uuid',
    'plan_id' => 'plan-uuid',
    'payment_method' => 'pix'
]);

// Get subscription details
$subscription = Hotpayments::subscriptions()->show('subscription-uuid');

// Cancel a subscription
$result = Hotpayments::subscriptions()->cancel('subscription-uuid', [
    'reason' => 'Customer requested cancellation'
]);

// Suspend a subscription
$result = Hotpayments::subscriptions()->suspend('subscription-uuid', [
    'reason' => 'Payment failure'
]);

// Reactivate a suspended subscription
$result = Hotpayments::subscriptions()->reactivate('subscription-uuid');

// List all subscription plans
$plans = Hotpayments::subscriptionPlans()->list([
    'per_page' => 20,
    'currency' => 'BRL'
]);

// Alternative method name
$plans = Hotpayments::subscriptionPlans()->all(['currency' => 'BRL']);

// Create a PIX QR Code
$qrCode = Hotpayments::transactions()->createPixQrCode([
    'amount' => 150.75,
    'customer_id' => 'customer-uuid',
    'description' => 'Payment description',
    'expires_at' => 3600, // 1 hour in seconds
    'splits' => [
        [
            'slug' => 'partner-company',
            'type' => 'percentage',
            'value' => 10.5
        ]
    ]
]);

// Request a PIX cashout
$cashout = Hotpayments::transactions()->pixCashout([
    'amount' => 100.00,
    'pix_key' => '[email protected]',
    'customer_id' => 'customer-uuid',
    'description' => 'Cashout request'
]);

// Check transaction status
$transaction = Hotpayments::transactions()->check('transaction-uuid');
echo "Status: " . $transaction['data']['status'];

'hotpayments' => [
    'key' => env('HOTPAYMENTS_API_KEY'),
],

use HotPayments\Hotpayments;

public function boot()
{
    Hotpayments::auth(config('services.hotpayments.key'));
}

use HotPayments\Hotpayments;

$customers = Hotpayments::customers()->list();

use HotPayments\Exceptions\ValidationException;
use HotPayments\Exceptions\AuthorizationException;
use HotPayments\Exceptions\HotpaymentsException;

try {
    $customer = Hotpayments::customers()->create([
        'name' => 'John Doe',
        'email' => 'invalid-email', // This will cause a validation error
    ]);
} catch (ValidationException $e) {
    // Handle validation errors
    echo "Validation Error: " . $e->getMessage();
    print_r($e->getErrors()); // Get detailed field errors
} catch (AuthorizationException $e) {
    // Handle authentication/authorization errors
    echo "Auth Error: " . $e->getMessage();
} catch (HotpaymentsException $e) {
    // Handle other API errors
    echo "API Error: " . $e->getMessage();
}
bash
composer