PHP code example of karim007 / sslcommerz-laravel

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

    

karim007 / sslcommerz-laravel example snippets


Route::group(['middleware'=>[config('sslcommerz.middleware','web')]], function () {
    Route::get('/sslcommerz/example1', [SslCommerzPaymentController::class, 'exampleEasyCheckout']);
    Route::get('/sslcommerz/example2', [SslCommerzPaymentController::class, 'exampleHostedCheckout']);

    Route::post('/sslcommerz/pay', [SslCommerzPaymentController::class, 'index']);
    Route::post('/sslcommerz/pay-via-ajax', [SslCommerzPaymentController::class, 'payViaAjax']);

    Route::post('/sslcommerz/success', [SslCommerzPaymentController::class, 'success']);
    Route::post('/sslcommerz/fail', [SslCommerzPaymentController::class, 'fail']);
    Route::post('/sslcommerz/cancel', [SslCommerzPaymentController::class, 'cancel']);

    Route::post('/sslcommerz/ipn', [SslCommerzPaymentController::class, 'ipn']);
});

protected $except = [
    '/sslcommerz/*',
];

$post_data = array();
$post_data['total_amount'] = '10'; # You cant not pay less than 10
$post_data['currency'] = "BDT";
$post_data['tran_id'] = uniqid(); // tran_id must be unique

$sslc = new SslCommerzNotification();

//for hosted payment
$payment_options = $sslc->makePayment($post_data, 'hosted');
#or
//for api/popup payment
$payment_options = $sslc->makePayment($post_data, 'checkout', 'json');

    $post_data = array();
    $post_data['total_amount'] = '10'; # You cant not pay less than 10
    $post_data['currency'] = "BDT";
    $post_data['tran_id'] = uniqid(); // tran_id must be unique

    $customer = array();
    $customer['name'] = 'Ab Karim';
    $customer['email'] = '[email protected]';
    $customer['address_1'] = 'Dhaka';
    $customer['address_2'] = "";
    $customer['city'] = "";
    $customer['state'] = "";
    $customer['postcode'] = "";
    $customer['country'] = "Bangladesh";
    $customer['phone'] = '8801XXXXXXXXX';
    $customer['fax'] = "";

    $s_info = array();
    $s_info['shipping_method'] = 'Yes'; // string (50)	Mandatory - Shipping method of the order. Example: YES or NO or Courier
    $s_info['num_of_item'] = 1; // integer (1)	Mandatory - No of product will be shipped. Example: 1 or 2 or etc
    $s_info['ship_name'] = 'Abc'; // string (50)	Mandatory, if shipping_method is YES - Shipping Address of your order. Not mandatory but useful if provided
    $s_info['ship_add1'] = 'Dhaka';; // string (50)	Mandatory, if shipping_method is YES - Additional Shipping Address of your order. Not mandatory but useful if provided
    $s_info['ship_add2'] = ''; // string (50)	Additional Shipping Address of your order. Not mandatory but useful if provided
    $s_info['ship_city'] = 'Dhaka'; // string (50)	Mandatory, if shipping_method is YES - Shipping city of your order. Not mandatory but useful if provided
    $s_info['ship_state'] = ''; // string (50)	Shipping state of your order. Not mandatory but useful if provided
    $s_info['ship_postcode'] = '1215'; // string (50)	Mandatory, if shipping_method is YES - Shipping postcode of your order. Not mandatory but useful if provided
    $s_info['ship_country'] = 'Bangladesh'; // string (50)	Mandatory, if shipping_method is YES - Shipping country of your order. Not mandatory but useful if provided

    $sslc = new SslCommerzNotification();
    $sslc->setCustomerInfo($customer)->setShipmentInfo($s_info);
    
    //then you can call
    $sslc->makePayment($post_data, 'hosted');
    //or
    $sslc->makePayment($post_data, 'checkout', 'json');