PHP code example of taqin / jayapay-sdk

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

    

taqin / jayapay-sdk example snippets




aqin\Jayapay\JayaPay;

// Initialize SDK
$jayapay = new JayaPay(
    'YOUR_MERCHANT_CODE',
    'YOUR_PRIVATE_KEY',     // PKCS8 format
    'PLATFORM_PUBLIC_KEY',
    false,                  // false for production, true for sandbox
    30                      // timeout in seconds
);

// Create a fiat collection order
$orderParams = [
    'orderNum' => 'ORDER123456',
    'payMoney' => '10000',
    'productDetail' => 'Test Payment',
    'notifyUrl' => 'https://your-domain.com/notify',
    'expiryPeriod' => '1440',
    'name' => 'John Doe',
    'email' => '[email protected]',
    'phone' => '081234567890'
];

try {
    $response = $jayapay->createFiatCollectionOrder($orderParams);
    echo "Order created successfully: " . $response['platOrderNum'];
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

$jayapay = new JayaPay($merchantCode, $privateKey, $publicKey, $sandbox, $timeout);

// Create order
$response = $jayapay->fiatCollection()->createOrder($params);

// Get supported payment methods
$methods = $jayapay->fiatCollection()->getSupportedMethods();

// Create order
$response = $jayapay->digitalCollection()->createOrder($params);

// Get supported currencies
$currencies = $jayapay->digitalCollection()->getSupportedMethods();

// Get supported networks
$networks = $jayapay->digitalCollection()->getSupportedNetworks();

// Create payment
$response = $jayapay->fiatPayment()->createPayment($params);

// Get supported bank codes
$banks = $jayapay->fiatPayment()->getSupportedBankCodes();

// Create payment
$response = $jayapay->digitalPayment()->createPayment($params);

// Get supported currencies
$currencies = $jayapay->digitalPayment()->getSupportedMethods();

// Query by order number
$response = $jayapay->queryOrder('ORDER123456', 'ORDER_QUERY');

// Query collection order
$response = $jayapay->orderQuery()->queryCollectionOrder(['orderNum' => 'ORDER123456']);

// Query payment order
$response = $jayapay->orderQuery()->queryPaymentOrder(['orderNum' => 'PAY123456']);

// Verify account
$response = $jayapay->accountVerification()->verifyByBankCode('014', '1234567890');

// Check if verification is supported
$supported = $jayapay->accountVerification()->isVerificationSupported('014');

// Get all balances
$balances = $jayapay->getBalance();

// Get specific currency balance
$idrBalance = $jayapay->getBalance('IDR');

// Parse balance data
$parsed = $jayapay->balanceInquiry()->parseBalanceData($balances);

// Handle incoming webhook
try {
    $notification = $jayapay->webhookHandler()->handleNotification($_POST);

    if ($jayapay->webhookHandler()->isPaymentSuccessful($notification)) {
        // Process successful payment
        echo $jayapay->webhookHandler()->generateSuccessResponse();
    } else {
        // Handle failed payment
        echo $jayapay->webhookHandler()->generateFailureResponse();
    }
} catch (SignatureException $e) {
    // Invalid signature
    echo $jayapay->webhookHandler()->generateFailureResponse();
}

use Taqin\Jayapay\Exceptions\ApiException;
use Taqin\Jayapay\Exceptions\ValidationException;
use Taqin\Jayapay\Exceptions\SignatureException;

try {
    $response = $jayapay->createFiatCollectionOrder($params);
} catch (ValidationException $e) {
    // Input validation failed
    $errors = $e->getErrors();
} catch (ApiException $e) {
    // API error
    $code = $e->getResponseCode();
    $message = $e->getResponseMessage();
} catch (SignatureException $e) {
    // Signature verification failed
}

$jayapay = new JayaPay($merchantCode, $privateKey, $publicKey, true); // true for sandbox

$jayapay = new JayaPay($merchantCode, $privateKey, $publicKey, false, 60); // 60 second timeout