PHP code example of ravols / laravel-everifin

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

    

ravols / laravel-everifin example snippets


return [
    'client_id' => env('EVERIFIN_CLIENT_ID'),
    'client_secret' => env('EVERIFIN_CLIENT_SECRET'),
    'client_iban' => env('EVERIFIN_CLIENT_IBAN'),
];


use Ravols\EverifinPhp\Config;
use Ravols\LaravelEverifin\Facades\LaravelEverifinOrders;

class EverifinPaymentProcessor {

    public function __construct()
    {
        Config::getInstance()->setClientSecret(config('everifin.client_secret'))->setClientIban(config('everifin.client_iban'))->setClientId(config('everifin.client_id'));
    }

    public function createPaymentLink(Order $order): string
    {
      //Your logic for ecommerce orders
      $responseData = LaravelEverifinOrders::createPayment(
            amount: 120.99,
            currency: 'EUR',
            redirectUrl: 'https://my-domain/payment/' . $order->number,
            recipientIban: Config::getInstance()->getClientIban(),
            message: 'My message',
            email: $order->user->email,
            recipientName: 'My company name',
            variableSymbol: 'Variable symbol', //For non CZ and SK sites use reference field
        );

        //$responseData contains much more than a link, feel free to check it out
        return $responseData->link;
    }
}

    use Ravols\LaravelEverifin\Facades\LaravelEverifinPayments;
    use Ravols\EverifinPhp\Exceptions\ResponseException;
    //Your logic in class

    //Get payment status
    try {
        $paymentStatus = LaravelEverifinPayments::getPayment(paymentId: request()->id);
    } catch (ResponseException $e) {
        $errors = collect($e->errors); //Here you can find errors from Everifin gateway in case request fails
        //Your logic for handling error cases
    }
    //Your logic with ifs, switch cases or any other way
    if($paymentStatus === 'BOOKED')
    {
        //Complete order logic
    }

    if($paymentStatus === 'FAILED')
    {
        //Handle error statuses.
    }

bash
php artisan vendor:publish --tag="laravel-everifin-config"