PHP code example of plugninja / sdk

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

    

plugninja / sdk example snippets




use PlugNinja\Plug;

$plug = new Plug('your-api-key');

// Send an email
$result = $plug->email->send([
    'to' => '[email protected]',
    'subject' => 'Welcome!',
    'html' => '<h1>Hello from plug.ninja</h1>',
]);

echo $result['messageId'];

// Send email
$plug->email->send([
    'to' => '[email protected]',
    'subject' => 'Hello',
    'html' => '<h1>Hi</h1>',
]);

// Send OTP
$plug->email->sendOtp('[email protected]');

// Verify OTP
$result = $plug->email->verifyOtp('[email protected]', '123456');
echo $result['token'];

// Create checkout (Stripe or MercadoPago — configured in dashboard)
$checkout = $plug->payment->checkout([
    'amount' => 2990,       // in cents
    'successUrl' => 'https://yourapp.com/thanks',
    'cancelUrl' => 'https://yourapp.com/cancel',
    'customerEmail' => '[email protected]',
]);

// Redirect user to:
echo $checkout['url'];

// Create subscription
$sub = $plug->payment->subscription([
    'priceId' => 'price_xxx',
    'customerEmail' => '[email protected]',
    'successUrl' => 'https://yourapp.com/thanks',
]);

// Check payment status
$status = $plug->payment->status('payment-id');

// Refund
$plug->payment->refund('payment-id');

// Get Google OAuth URL
$auth = $plug->auth->google->getAuthUrl([
    'redirectUri' => 'https://yourapp.com/auth/callback',
]);

// Redirect user to $auth['url'], then on callback:
$result = $plug->auth->google->callback([
    'code' => $_GET['code'],
    'redirectUri' => 'https://yourapp.com/auth/callback',
]);

echo $result['user']['email'];
echo $result['tokens']['accessToken'];

$plug = new Plug('your-api-key', 'http://localhost:4000');

use PlugNinja\PlugException;

try {
    $plug->email->send([
        'to' => '[email protected]',
        'subject' => 'Test',
        'html' => '<p>Hello</p>',
    ]);
} catch (PlugException $e) {
    echo $e->getMessage();    // "From email is