HEX
Server: LiteSpeed
System: Linux s917.lon1.mysecurecloudhost.com 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: assibfaf (3034)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/assibfaf/www/prox-modules/flutterwave/flutterwave.php
<?php
use Proxim\Application;
use Proxim\Configuration;
use Proxim\Module\Module;
use Proxim\Module\PaymentModule;
use Proxim\Site\Site;
use Proxim\Util\ArrayUtils;
use Proxim\Validate;

class Flutterwave extends PaymentModule
{
    /**
    * Flutterwave configuration
    */
    const FLUTTERWAVE_ENABLED = 'FLUTTERWAVE_ENABLED';
    const FLUTTERWAVE_KEY = 'FLUTTERWAVE_KEY';

    public function __construct()
    {
        $this->name = 'flutterwave';
        $this->icon = 'fa fa-credit-card';
        $this->version = '1.0.0';
        $this->prox_versions_compliancy = array('min' => '1.0.0', 'max' => Application::VERSION);
        $this->author = 'Davison Pro';
        $this->displayName = 'Flutterwave';
        $this->description = 'Set up Flutterwave as a payment method on your website';

        $this->bootstrap = true;
        parent::__construct();
    }

    public function checkAccess() {
        $user = $this->application->container->user;
        return $user->is_admin === true;
    }

    public function isActive() {
        return Configuration::get(self::FLUTTERWAVE_ENABLED);
    }

    /**
     * Echoes a template.
     *
     * @param string $templateName Template name
     */
    public function showTemplate($templateName)
    {
        echo $this->getTemplateContent($templateName);
    }

    /**
     * Return a template.
     *
     * @param string $templateName          Template name
     * @param array  $additionnalParameters Additionnal parameters to inject on the Twig template
     *
     * @return string Parsed template
     */
    private function getTemplateContent($templateName, $additionnalParameters = array())
    {
        $this->smarty->assign($additionnalParameters);
        return $this->fetch(__DIR__ . '/views/' . $templateName.'.tpl');
    }

    public function processOrderCheckout($order, $currency) {
        $app = $this->application;
        $smarty = $this->smarty;
        $user = $app->container->user;

        $smarty->assign([
            'flutterwave_key' => Configuration::get( self::FLUTTERWAVE_KEY ),
            'payee_email' => $user->email
        ]);
        
        return $this->getTemplateContent('flutterwave.order');
    }

    public function processPaperCheckout($paper, $currency) {
        $app = $this->application;
        $smarty = $this->smarty;
        $user = $app->container->user;

        $smarty->assign([
            'flutterwave_key' => Configuration::get( self::FLUTTERWAVE_KEY ),
            'payee_email' => $user->email
        ]);
        
        return $this->getTemplateContent('flutterwave.paper');
    }

    public function processAddPaymentCheckout($addPayment, $currency) {
        $app = $this->application;
        $smarty = $this->smarty;
        $user = $app->container->user;

        $smarty->assign([
            'flutterwave_key' => Configuration::get( self::FLUTTERWAVE_KEY ),
            'payee_email' => $user->email
        ]);
        
        return $this->getTemplateContent('flutterwave.add-payment');
    }

    public function processWalletCheckout($user_id, $amount, $currency) {
        $app = $this->application;
        $smarty = $this->smarty;
        $user = $app->container->user;

        $smarty->assign([
            'flutterwave_key' => Configuration::get( self::FLUTTERWAVE_KEY ),
            'payee_email' => $user->email
        ]);
        
        return $this->getTemplateContent('flutterwave.wallet');
    }

    public function processTipCheckout($order_id, $amount, $currency) {
        $app = $this->application;
        $smarty = $this->smarty;
        $user = $app->container->user;

        $smarty->assign([
            'flutterwave_key' => Configuration::get( self::FLUTTERWAVE_KEY ),
            'payee_email' => $user->email
        ]);
        
        return $this->getTemplateContent('flutterwave.tip');
    }

    /**
    * Hook action verify payment
    * @param $params array
    * @return void
    */
    public function verifyPayment($node_id, $handle, $payload) 
    {
        PaymentModule::processPayment( $node_id, $handle, $payload );
    }
}