PonponPay

PHP SDK

Official PonponPay SDK for PHP. Compatible with PHP 7.4+ and works with Laravel, Symfony, and other frameworks.

Installation

composer require ponponpay/sdk

Basic Usage

Initialize Client

<?php
use PonponPay\PonponPay;

$ponponpay = new PonponPay([
    'apiKey' => $_ENV['PONPONPAY_API_KEY'],
    // Optional configurations
    'baseUrl' => 'https://api.ponponpay.com/api/v1/pay/sdk',
    'timeout' => 30,
]);

Create Order

<?php
$order = $ponponpay->createOrder([
    'currency' => 'USDT',
    'network' => 'tron',
    'amount' => 100.00,
    'mchOrderId' => 'ORDER_123456',  // Optional
    'notifyUrl' => 'https://your-site.com/webhook',
    'redirectUrl' => 'https://your-site.com/success',
]);

echo $order->tradeId;      // PonponPay transaction ID
echo $order->paymentUrl;   // Redirect user to this URL
echo $order->address;      // Receiving wallet address
echo $order->actualAmount; // Actual payment amount

// Redirect to payment page
header('Location: ' . $order->paymentUrl);
exit;

Query Order

<?php
// Query by PonponPay trade ID
$order = $ponponpay->queryOrder('PP202412110001');

// Query by your merchant order ID
$order = $ponponpay->queryOrderByMchId('ORDER_123456');

echo $order->status;  // 'pending', 'paid', 'expired', 'cancelled'
echo $order->txHash;  // Blockchain transaction hash (if paid)

Cancel Order

<?php
// Cancel by trade ID
$ponponpay->cancelOrder('PP202412110001');

// Cancel by merchant order ID
$ponponpay->cancelOrderByMchId('ORDER_123456');

Get Payment Methods

<?php
$methods = $ponponpay->getPaymentMethods();

foreach ($methods as $method) {
    echo $method->currency . ' on ' . $method->network;
}

Webhook Verification

<?php
$signature = $_SERVER['HTTP_X_PONPONPAY_SIGNATURE'] ?? '';
$payload = file_get_contents('php://input');

if ($ponponpay->verifyWebhook($payload, $signature)) {
    $data = $ponponpay->parseWebhook($payload);
    
    if ($data->status === 'paid') {
        // Update your order status
        // $data->tradeId, $data->mchOrderId, $data->amount, etc.
    }
}

echo 'OK';

HTML Components (Monolithic Apps)

For traditional PHP applications without frontend frameworks, the SDK provides methods to render payment UI components.

Render Payment Button

<?php
// In your view/template
echo $ponponpay->renderPaymentButton([
    'currency' => 'USDT',
    'network' => 'tron',
    'amount' => 100.00,
    'mchOrderId' => 'ORDER_123456',
    'notifyUrl' => 'https://your-site.com/webhook',
    'redirectUrl' => 'https://your-site.com/success',
], [
    'text' => 'Pay with Crypto',
    'class' => 'btn btn-primary',
    'id' => 'pay-button',
]);

Render Payment Form

<?php
// Render a form with currency/network selection
echo $ponponpay->renderPaymentForm([
    'amount' => 100.00,
    'mchOrderId' => 'ORDER_123456',
    'notifyUrl' => 'https://your-site.com/webhook',
    'redirectUrl' => 'https://your-site.com/success',
], [
    'class' => 'payment-form',
    'submitText' => 'Proceed to Payment',
]);

Laravel Integration

Service Provider

<?php
// config/services.php
return [
    'ponponpay' => [
        'api_key' => env('PONPONPAY_API_KEY'),
    ],
];

// app/Providers/AppServiceProvider.php
use PonponPay\PonponPay;

public function register()
{
    $this->app->singleton(PonponPay::class, function ($app) {
        return new PonponPay([
            'apiKey' => config('services.ponponpay.api_key'),
        ]);
    });
}

Controller Example

<?php
namespace App\Http\Controllers;

use PonponPay\PonponPay;
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    public function __construct(
        private PonponPay $ponponpay
    ) {}

    public function create(Request $request)
    {
        $order = $this->ponponpay->createOrder([
            'currency' => $request->currency,
            'network' => $request->network,
            'amount' => $request->amount,
            'notifyUrl' => route('payment.webhook'),
            'redirectUrl' => route('payment.success'),
        ]);

        return redirect($order->paymentUrl);
    }

    public function webhook(Request $request)
    {
        $signature = $request->header('X-PonponPay-Signature');
        $payload = $request->getContent();

        if ($this->ponponpay->verifyWebhook($payload, $signature)) {
            $data = $this->ponponpay->parseWebhook($payload);
            // Update order status...
        }

        return response('OK');
    }
}

Routes

<?php
// routes/web.php
Route::post('/payment/create', [PaymentController::class, 'create'])
    ->name('payment.create');

Route::post('/payment/webhook', [PaymentController::class, 'webhook'])
    ->name('payment.webhook')
    ->withoutMiddleware(['csrf']);

Route::get('/payment/success', [PaymentController::class, 'success'])
    ->name('payment.success');

Symfony Integration

<?php
// config/services.yaml
services:
    PonponPay\PonponPay:
        arguments:
            - apiKey: '%env(PONPONPAY_API_KEY)%'

// src/Controller/PaymentController.php
namespace App\Controller;

use PonponPay\PonponPay;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class PaymentController
{
    public function __construct(
        private PonponPay $ponponpay
    ) {}

    #[Route('/payment/create', methods: ['POST'])]
    public function create(Request $request): Response
    {
        $order = $this->ponponpay->createOrder([
            'currency' => 'USDT',
            'network' => 'tron',
            'amount' => 100.00,
        ]);

        return $this->redirect($order->paymentUrl);
    }
}

Error Handling

<?php
use PonponPay\Exceptions\PonponPayException;
use PonponPay\Exceptions\AuthenticationException;
use PonponPay\Exceptions\ValidationException;

try {
    $order = $ponponpay->createOrder([...]);
} catch (AuthenticationException $e) {
    // Invalid API Key
    echo 'Authentication failed: ' . $e->getMessage();
} catch (ValidationException $e) {
    // Invalid parameters
    echo 'Validation error: ' . $e->getMessage();
} catch (PonponPayException $e) {
    // Other API errors
    echo 'Error: ' . $e->getCode() . ' - ' . $e->getMessage();
}