PHP code example of ziyoren / pay-sdk

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

    

ziyoren / pay-sdk example snippets


use Ziyoren\PaySdk\Client;

$client = new Client('your-api-key', 'your-secret-key', 'https://api.ziyoren.com');

$orderData = [
    'out_trade_no' => 'ORDER-' . time(),
    'total_amount' => 100.00,
    'subject' => 'Product Name',
    'notify_url' => 'https://your-domain.com/notify'
];

try {
    $result = $client->createPaymentOrder($orderData);
    // Handle result
    var_dump($result);
} catch (\Ziyoren\PaySdk\Exceptions\ApiException $e) {
    // Handle API error
    echo "API Error: " . $e->getMessage();
}

try {
    $result = $client->getPaymentStatus('ORDER-123456789');
    // Handle result
    var_dump($result);
} catch (\Ziyoren\PaySdk\Exceptions\ApiException $e) {
    // Handle API error
    echo "API Error: " . $e->getMessage();
}

// Example: in your notification endpoint
$notificationData = $_POST; // or however you receive the data

if ($client->verifyNotification($notificationData)) {
    // Signature is valid, process the notification
    echo "Valid notification";
} else {
    // Invalid signature, reject
    http_response_code(400);
    echo "Invalid signature";
}