PHP code example of a4anthony / coupon

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

    

a4anthony / coupon example snippets


'admin' => [
'driver' => 'eloquent',
'model' => \A4anthony\Coupon\Models\Admin::class,
]

'admin' => [
'redirectTo' => 'coupon.dashboard',
'driver' => 'session',
'provider' => 'admin',
],

    public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check()) {
        if ($guard == "admin") {
            return redirect()->route('coupon.dashboard');
        }
        return redirect(RouteServiceProvider::HOME);
    }

    return $next($request);
}

/*
|--------------------------------------------------------------------------
| Timezone
|--------------------------------------------------------------------------
|
| Here you can specify the coupon genrator timezone 
|
*/

'timezone' => 'Africa/Lagos',

/*
|--------------------------------------------------------------------------
| Currency
|--------------------------------------------------------------------------
|
| Here you can specify the coupon genrator currency 
|
*/
'currency' => 'NGN',

/*
|--------------------------------------------------------------------------
| Currency Codes
|--------------------------------------------------------------------------
|
| Here you can specify the coupon genrator currency codes 
|
*/
'currency_code' => [
    'NGN' => '&#8358;',
    'USD' => '$',
    'EUR' => '€',
    'GBP' => '£',
],
/*
|--------------------------------------------------------------------------
| Error Messages
|--------------------------------------------------------------------------
|
| Here you can specify the coupon genrator error messages 
|
*/
'error_msgs' => [
    'not_exist' => 'coupon does not exist',
    'not_valid' => 'coupon is not valid',
    'used' => 'coupon is already used by you',
    'exceeds' => 'coupon discount value is greater than amount',
]

use A4anthony\Coupon\Facades\Coupon;

$customer_email = '[email protected]';
$amount = 50000;
$discount = 0;//set discount default value
$coupon_code = 'ANTHONYQXGA4';
try {
    Coupon::validate($coupon_code, $customer_email);
    $discount = Coupon::getDiscount($coupon_code, $amount);
    echo 'Coupon accepted';
} catch (Exception $e) {
    echo 'Message: ' . $e->getMessage();
}

Coupon::callback($coupon_code, $customer_email);
bash
php artisan coupon:install
bash
php artisan coupon:install --with-dummy

composer dump-autoload
bash
php artisan coupon:admin [email protected] --create