bohudur / laravel-sdk
Automate Your Personal Payments with zero cost.
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/bohudur/laravel-sdk
Requires
- php: >=7.4
Requires (Dev)
- laravel/pint: ^1.18
README
This is Bohudur Laravel Module that helps to integrate Bohudur in your Laravel project.
Table of Contents
Installation
Install the Bohudur Laravel SDK using Composer:
composer require bohudur/laravel-sdk
Usage
Initializing the SDK
Add your Bohudur API Key to the .env file:
BOHUDUR_API_KEY=your_api_key_here
Use the following code to initialize the SDK:
use Bohudur\LaravelSDK\Bohudur; $bohudur = Bohudur::make(env('BOHUDUR_API_KEY'));
Initializing a Payment
To initiate a payment:
use Bohudur\LaravelSDK\Requests\CheckoutRequest; try { $checkoutRequest = CheckoutRequest::make() ->setFullName("John Doe") ->setEmail("john@example.com") ->setAmount(10) ->setRedirectUrl(route('bohudur.execute')) ->setCancelUrl(route('bohudur.cancel')) ->setReturnType('GET') //GET or POST ->setCurrency("BDT") //optional ->setCurrencyValue(1) //optional ->setMetadata([ /*optional */ 'order_id' => 1234, 'user_id' => 5678, 'custom_note' => 'First-time purchase' ]) ->setWebhookSuccessUrl("https://yourapp.com/webhook/success") //optional ->setWebhookCancelUrl("https://yourapp.com/webhook/cancel"); //optional $response = $bohudur->checkout($checkoutRequest); if ($response->failed()) { dd($response->message()); } return redirect()->away($response->paymentURL()); } catch (\Bohudur\LaravelSDK\Exceptions\BohudurException $e) { dd("Initialization Error: " . $e->getMessage()); }
Execute a Payment
After the payment is complete, execute it using the ExecuteResponse class so that one payment key is used only one time. Also to understand the structure and available methods for processing the response:
use Bohudur\LaravelSDK\Bohudur; try { $bohudur = Bohudur::make(env('BOHUDUR_API_KEY')); $paymentKey = $request->get('payment_key'); //getting payment key using get method $response = $bohudur->execute($paymentKey); if ($response->success()) { // Handle successful status return response()->json([ 'status' => 'success', 'transaction_id' => $response->transactionId(), 'amount' => $response->amount(), ]); } elseif ($response->pending()) { // Handle pending status } elseif ($response->failed()) { // Handle failure } } catch (\Bohudur\LaravelSDK\Exceptions\BohudurException $e) { dd("Verification Error: " . $e->getMessage()); }
Verify a Payment
After the payment is complete, you can verify it using the VerifyResponse class to understand the structure and available methods for processing the response:
use Bohudur\LaravelSDK\Bohudur; try { $bohudur = Bohudur::make(env('BOHUDUR_API_KEY')); $response = $bohudur->verify('paymentkey'); if ($response->success()) { // Handle successful status return response()->json([ 'status' => 'success', 'transaction_id' => $response->transactionId(), 'amount' => $response->amount(), ]); } elseif ($response->pending()) { // Handle pending status } elseif ($response->failed()) { // Handle failure } } catch (\Bohudur\LaravelSDK\Exceptions\BohudurException $e) { dd("Verification Error: " . $e->getMessage()); }
Routes
Add the following routes to your web.php file:
use App\Http\Controllers\BohudurController; Route::get('/checkout', [BohudurController::class, 'checkout'])->name('bohudur.checkout'); Route::get('/verify', [BohudurController::class, 'verify'])->name('bohudur.verify'); Route::get('/cancel', [BohudurController::class, 'cancel'])->name('bohudur.cancel');
Notes
- Replace placeholders like
your_api_key_herewith actual credentials. - Always wrap SDK calls with
try-catchto handle errors effectively.
License
This project is open-source and available under the MIT License.