PHP code example of ndenisj / longswipe-payment

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

    

ndenisj / longswipe-payment example snippets


// PHP code block
use Longswipe\Payment\LongswipeClient;
use Longswipe\Payment\Exceptions\LongswipeException;

// Initialize the client
$client = new LongswipeClient('your-api-key', true); // true for sandbox, false for production

// Example parameters
$params = [
    'voucherCode' => 'VOUCHER123',
    'amount' => 1000,
    'receivingCurrencyId' => '2eedd32', // Replace with actual receiving currency ID,
    'lockPin' => '1234', // Optional
    'walletAddress' => '0x123...' // Optional
];

try {
    // Fetch voucher details
    $voucherDetails = $client->fetchVoucherDetails($params);

    // If details are okay, process the payment
    $paymentResult = $client->processVoucherPayment($params);

} catch (LongswipeException $e) {
    echo "Error: " . $e->getMessage();
    echo "Code: " . $e->getCode();
    var_dump($e->getData());
}

// For sandbox environment
$client = new LongswipeClient('your-api-key', true);

// For production environment
$client = new LongswipeClient('your-api-key', false);

try {
    $params = [
        'voucherCode' => 'VOUCHER123',
        'amount' => 1000,
        'receivingCurrencyId' => '2eedd32', // Replace with actual receiving currency ID,
        'lockPin' => '1234', // Optional
        'walletAddress' => '0x123...' // Optional
    ];

    $voucherDetails = $client->fetchVoucherDetails($params);

    if ($voucherDetails['status'] === 'success') {
        // Process voucher details
        $charges = $voucherDetails['data']['charges'];
        $voucher = $voucherDetails['data']['voucher'];
    }
} catch (LongswipeException $e) {
    echo "Error: " . $e->getMessage();
    if ($e->getErrorData()) {
        print_r($e->getErrorData());
    }
}

try {
    $params = [
        'voucherCode' => 'VOUCHER123',
        'amount' => 1000,
        'receivingCurrencyId' => '2eedd32', // Replace with actual receiving currency ID,
        'lockPin' => '1234', // Optional
        'walletAddress' => '0x123...' // Optional
    ];

    $paymentResult = $client->processVoucherPayment($params);

    if ($paymentResult['status'] === 'success') {
        // Payment successful
        echo "Payment processed successfully!";
    }
} catch (LongswipeException $e) {
    echo "Error: " . $e->getMessage();
    if ($e->getErrorData()) {
        print_r($e->getErrorData());
    }
}

try {
    // Your API call here
} catch (LongswipeException $e) {
    echo "Error Code: " . $e->getCode() . "\n";
    echo "Error Message: " . $e->getMessage() . "\n";
    if ($e->getErrorData()) {
        echo "Additional Error Data: ";
        print_r($e->getErrorData());
    }
}