sabitahmadumid/sixcash-laravel

Unofficial Laravel SDK wrapper for 6Cash payment gateway script

v1.0.0 2025-02-01 20:11 UTC

This package is not auto-updated.

Last update: 2025-05-11 19:47:37 UTC


README

SixCash Laravel Package

Latest Version License Total Downloads

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

A Laravel package for seamless integration with the SixCash Payment Gateway. This package provides an easy-to-use interface for creating payment orders and verifying transactions.

Features

  • 💳 Create Payment Orders: Initiate payments and redirect users to the SixCash payment page.
  • ✅ Verify Payments: Verify transaction status using the transaction ID.
  • 🛡 Type Safety: Built with TypeScript-like type safety for robust error handling.
  • 🚦 Error Handling: Custom exceptions for merchant not found, payment verification failures, and more.
  • 🔒 Input Validation: Automatically validates input parameters.
  • 📦 Laravel Integration: Fully integrated with Laravel's service container and facades.

Installation

You can install the package via composer:

composer require sabitahmadumid/sixcash-laravel

You can publish the config file with:

php artisan vendor:publish --tag="sixcash-laravel-config"

This is the contents of the published config file:

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'),
];

Add the following environment variables to your .env file:

SIXCASH_BASE_URL=https://api.sixcash.com
SIXCASH_PUBLIC_KEY=your_public_key
SIXCASH_SECRET_KEY=your_secret_key
SIXCASH_MERCHANT_NUMBER=your_merchant_number

Usage

Initialize the Package

The package is automatically registered via the service provider. You can start using it immediately.

Create a Payment Order

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()]);
}

Verify Payment

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);
}

Payment Record Structure

[
'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
]

Error Handling

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
}

Testing

To run the tests, use the following command:

composer test

Support

For any issues, feature requests, or development assistance, feel free to contact me on Discord: Username: xcal_ibur

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.