File: /home/assibfaf/public_html/prox-modules/intasend/intasend.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 Intasend extends PaymentModule
{
/**
* Intasend configuration
*/
const INTASEND_ENABLED = 'INTASEND_ENABLED';
const INTASEND_MODE = 'INTASEND_MODE';
const INTASEND_PUBLIC_KEY = 'INTASEND_PUBLIC_KEY';
public function __construct()
{
$this->name = 'intasend';
$this->icon = 'fab fa-intasend';
$this->version = '1.0.0';
$this->prox_versions_compliancy = array('min' => '1.0.0', 'max' => Application::VERSION);
$this->author = 'Davison Pro';
$this->bootstrap = true;
parent::__construct();
$this->displayName = 'Intasend - Credit Card';
$this->description = 'Accepts payments by Intasend';
}
public function isActive() {
return Configuration::get(self::INTASEND_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([
'intasend_mode' => Configuration::get( self::INTASEND_MODE ),
'intasend_public_key' => Configuration::get( self::INTASEND_PUBLIC_KEY ),
'payee_email' => $user->email
]);
return $this->getTemplateContent('intasend.order');
}
public function processPaperCheckout($paper, $currency) {
$app = $this->application;
$smarty = $this->smarty;
$user = $app->container->user;
$smarty->assign([
'intasend_mode' => Configuration::get( self::INTASEND_MODE ),
'intasend_public_key' => Configuration::get( self::INTASEND_PUBLIC_KEY ),
'payee_email' => $user->email
]);
return $this->getTemplateContent('intasend.paper');
}
public function processAddPaymentCheckout($addPayment, $currency) {
$app = $this->application;
$smarty = $this->smarty;
$user = $app->container->user;
$smarty->assign([
'intasend_mode' => Configuration::get( self::INTASEND_MODE ),
'intasend_public_key' => Configuration::get( self::INTASEND_PUBLIC_KEY ),
'payee_email' => $user->email
]);
return $this->getTemplateContent('intasend.add-payment');
}
public function processWalletCheckout($user_id, $amount, $currency) {
$app = $this->application;
$smarty = $this->smarty;
$user = $app->container->user;
$smarty->assign([
'intasend_mode' => Configuration::get( self::INTASEND_MODE ),
'intasend_public_key' => Configuration::get( self::INTASEND_PUBLIC_KEY ),
'payee_email' => $user->email
]);
return $this->getTemplateContent('intasend.wallet');
}
public function processTipCheckout($order_id, $amount, $currency) {
$app = $this->application;
$smarty = $this->smarty;
$user = $app->container->user;
$smarty->assign([
'intasend_mode' => Configuration::get( self::INTASEND_MODE ),
'intasend_public_key' => Configuration::get( self::INTASEND_PUBLIC_KEY ),
'payee_email' => $user->email
]);
return $this->getTemplateContent('intasend.tip');
}
/**
* Hook action verify payment
* @param $params array
* @return void
*/
public function verifyPayment($node_id, $handle, $payload)
{
PaymentModule::processPayment( $node_id, $handle, $payload );
}
/**
* Hook action verify payment
* @param $params array
* @return void
*/
public function verifyPaymentAfter($params)
{
$app = $this->application;
$user = $app->container->user;
$nodeId = (int) ArrayUtils::get($params, 'nodeId');
$handle = ArrayUtils::get($params, 'handle');
$params['customer_id'] = $user->id;
PaymentModule::processPayment( $nodeId, $handle, $params );
}
}