PHP code example of wiopayments / php-sdk-vanilla

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

    

wiopayments / php-sdk-vanilla example snippets


// Simply include the main SDK file
ioPayments = new WioPayments('your_api_key_here');

// Create payment data
$paymentData = [
    'amount' => 50.00,
    'currency' => 'USD',
    'order_id' => 'ORDER_' . uniqid(),
    'customer' => [
        'name' => 'John Doe',
        'email' => '[email protected]'
    ]
];

// Create payment and get client secret
$payment = $wioPayments->createPayment($paymentData);

// Generate complete payment form
$paymentForm = $wioPayments->renderPaymentForm($paymentData);
file_put_contents('payment.html', $paymentForm);

$status = $wioPayments->getPaymentStatus($payment->id);
echo "Payment status: " . $status->status;

// Add to your existing PHP application


Payments = new WioPayments('your_api_key');

$paymentData = [
    'amount' => 99.99,
    'currency' => 'USD',
    'order_id' => 'ORDER_123',
    'description' => 'Premium Product',
    'customer' => [
        'name' => 'Customer Name',
        'email' => '[email protected]'
    ]
];

// Generate complete payment page
$paymentForm = $wioPayments->renderPaymentForm($paymentData, [
    'submit_button_text' => 'Pay $99.99',
    'success_url' => 'https://yoursite.com/success',
    'custom_css' => '.wiopayments-button { background: #28a745; }'
]);

echo $paymentForm;


Payments = new WioPayments('your_api_key');

$sessionData = [
    'amount' => 75.00,
    'currency' => 'USD',
    'order_id' => 'ORDER_456',
    'success_url' => 'https://yoursite.com/success',
    'cancel_url' => 'https://yoursite.com/cancel',
    'customer' => [
        'name' => 'Jane Smith',
        'email' => '[email protected]'
    ]
];

// Get payment URL and redirect
$paymentUrl = $wioPayments->createHostedPaymentUrl($sessionData);
header('Location: ' . $paymentUrl);
exit;


Payments = new WioPayments('your_api_key');

// Create payment
$payment = $wioPayments->createPayment($paymentData);

// Get JavaScript code
$script = $wioPayments->generatePaymentScript($payment->id);


Payments = new WioPayments('your_api_key');

// Create payment link
$linkData = [
    'amount' => 25.00,
    'currency' => 'USD',
    'description' => 'Digital Product',
    'max_uses' => 1,
    'expires_at' => date('Y-m-d H:i:s', strtotime('+7 days'))
];

$paymentLink = $wioPayments->createPaymentLink($linkData);

echo "Share this payment link: " . $paymentLink['url'];

// List all payment links
$allLinks = $wioPayments->listPaymentLinks();
foreach ($allLinks['data'] as $link) {
    echo $link['description'] . ": " . $link['url'] . "\n";
}

$wioPayments = new WioPayments('your_api_key', [
    'base_url' => 'https://gw.wiopayments.com',
    'timeout' => 30,
    'verify_ssl' => true
]);

$paymentForm = $wioPayments->renderPaymentForm($paymentData, [
    'custom_css' => '
        .wiopayments-form {
            background: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 8px;
        }
        .wiopayments-button {
            background: linear-gradient(45deg, #007bff, #0056b3);
            border-radius: 25px;
        }
        .wiopayments-card-element {
            border: 2px solid #007bff;
        }
    '
]);

$options = [
    'submit_button_text' => 'Complete Purchase',
    'loading_button_text' => 'Processing Payment...',
    'success_url' => 'https://yoursite.com/thank-you',
    'cancel_url' => 'https://yoursite.com/checkout',
    'form_id' => 'my-payment-form',
    'card_element_id' => 'my-card-element',
    'error_element_id' => 'my-error-element'
];

try {
    $payment = $wioPayments->createPayment($paymentData);
    echo "Payment created: " . $payment->id;
} catch (WioPaymentsException $e) {
    echo "Payment error: " . $e->getMessage();
    echo "Error code: " . $e->getCode();
} catch (Exception $e) {
    echo "Unexpected error: " . $e->getMessage();
}

// Old way (Composer)
use WioPayments\Client;
$client = new Client('api_key');

// New way (Vanilla)
ment($data);