<?php

namespace Plugins\StripePlugin;

use Core\View\View;
use Core\View\ElementView;

use Apps\EeApp\Entity\EeAppPlugin;

class StripePlugin{

        
    public $Author = 'Webemyos';
    public $Version = '1.0.0.0';
    
    
    function __construct($core){
        $this->Core = $core;
    }
    
    function GetType(){
        return "Paid";
    }
    
    function Render($total, $parameters){
       
        $parameters = json_decode($parameters);
        
        $keys = explode(";", $parameters->clientId);
        
        $publicKey = $keys[0];
        $privateKey = $keys[1];
        
        $view = new View(__DIR__ . "/View/index.tpl", $this->Core);
        
        $view->AddElement(new ElementView("stripeKey",  $publicKey));
        
        $clientSecret = StripeHelper::CreatePaidSession($this->Core, $privateKey, $total);
        $view->AddElement(new ElementView("clientSecret", $clientSecret));
        
        return $view->Render();
    }
    

   /***
     * Config Form
     */
    function RenderConfigForm($pluginId){

        $view = new View(__DIR__ . "/View/config.tpl", $this->Core);
        $view->AddElement(new ElementView("pluginId", $pluginId));
       
        $plugin = new EeAppPlugin($this->Core);
        $plugin->GetById($pluginId);
        $parameters = json_decode($plugin->Parameters->Value);
       
        $view->AddElement(new ElementView("clientId", $parameters->clientId));
       
        return $view->Render();
    }
}