Prompt Title: SSL Commerce Integration Laravel

Created 1 year ago
Votes 0
Views 219 times
0
Human: ssl commerce payment intregration laravel
ChatGPT:

To integrate SSL Commerce payment in Laravel, you can follow these steps:

  1. Install the SSL Commerce package using Composer. You can do this by running the following command in your terminal:

    bash
    composer require sslcommerz/sslcommerz
  2. Add the package's service provider to your config/app.php file:

    arduino
    'providers' => [ // ... Sslcommerz\SslcommerzServiceProvider::class, ],
  3. Publish the package's configuration file using the following command:

    arduino
    php artisan vendor:publish --provider="Sslcommerz\SslcommerzServiceProvider"
  4. Update the config/sslcommerz.php file with your SSL Commerce account details, including the store ID, store password, and other necessary information.

  5. Create a route and a controller method to initiate the payment process:

    arduino
    Route::post('/payment', [PaymentController::class, 'initiatePayment']);
    php
    use Sslcommerz\SslCommerzNotification; use Illuminate\Http\Request; class PaymentController extends Controller { public function initiatePayment(Request $request) { $postData = [ 'total_amount' => $request->input('amount'), 'currency' => 'BDT', 'tran_id' => uniqid(), 'success_url' => url('/payment/success'), 'fail_url' => url('/payment/fail'), 'cancel_url' => url('/payment/cancel'), ]; $sslcommerz = new SslCommerzNotification(); $sslcommerz->initiate($postData); } }
  6. Create three more routes and methods for handling the success, fail, and cancel callbacks:

    arduino
    Route::get('/payment/success', [PaymentController::class, 'paymentSuccess']); Route::get('/payment/fail', [PaymentController::class, 'paymentFail']); Route::get('/payment/cancel', [PaymentController::class, 'paymentCancel']);
    php
    public function paymentSuccess(Request $request) { $transactionData = $request->all(); // Process the payment success } public function paymentFail(Request $request) { $transactionData = $request->all(); // Process the payment fail } public function paymentCancel(Request $request) { $transactionData = $request->all(); // Process the payment cancel }
  7. Finally, update your payment form to submit the payment data to the /payment route:

    bash
    <form action="{{ url('/payment') }}" method="post"> @csrf <input type="hidden" name="amount" value="{{ $amount }}"> <button type="submit">Pay Now</button> </form>

That's it! You should now be able to initiate and process payments using SSL Commerce in Laravel.

avatar
Shuvo
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts