PHP code example of sabitahmadumid / sixcash-laravel

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

    

sabitahmadumid / sixcash-laravel example snippets


return [
    'base_url' => env('SIXCASH_BASE_URL', 'https://api.sixcash.com'),
    'public_key' => env('SIXCASH_PUBLIC_KEY'),
    'secret_key' => env('SIXCASH_SECRET_KEY'),
    'merchant_number' => env('SIXCASH_MERCHANT_NUMBER'),
];

use SabitAhmad\SixCash\Facades\SixCash;

try {
    $amount = 100.50; // Payment amount
    $callbackUrl = route('payment.callback'); // Callback URL after payment
    $redirectUrl = SixCash::createPaymentOrder($amount, $callbackUrl);

    // Redirect the user to the payment page
    return redirect()->away($redirectUrl);
} catch (\SabitAhmad\SixCash\Exceptions\MerchantNotFoundException $e) {
    return back()->withErrors(['error' => 'Merchant not found']);
} catch (\Exception $e) {
    return back()->withErrors(['error' => $e->getMessage()]);
}

use SabitAhmad\SixCash\Facades\SixCash;

try {
    $transactionId = request('transaction_id'); // Get transaction ID from request
    $payment = SixCash::verifyPayment($transactionId);

    if ($payment['is_paid']) {
        // Handle successful payment
        return response()->json(['message' => 'Payment successful']);
    } else {
        // Handle pending or failed payment
        return response()->json(['message' => 'Payment not completed']);
    }
} catch (\SabitAhmad\SixCash\Exceptions\PaymentVerificationException $e) {
    return response()->json(['error' => $e->getMessage()], 422);
}

[
'id' => 'string', // Payment ID
'merchant_id' => 'int', // Merchant ID
'user_id' => 'int', // User ID
'transaction_id' => 'string', // Transaction ID
'amount' => 'float', // Payment amount
'is_paid' => 'bool', // Payment status
'expires_at' => 'Carbon', // Expiration date
'created_at' => 'Carbon' // Creation date
]

try {
    $redirectUrl = SixCash::createPaymentOrder(100, route('payment.callback'));
} catch (\SabitAhmad\SixCash\Exceptions\MerchantNotFoundException $e) {
    // Handle merchant not found
} catch (\SabitAhmad\SixCash\Exceptions\PaymentVerificationException $e) {
    // Handle verification failure
} catch (\Exception $e) {
    // Handle other errors
}
bash
php artisan vendor:publish --tag="sixcash-laravel-config"