Jump to content

Prestashop Payment Gateway Development


keshab89

Recommended Posts

I am writing a payment gateway module for "atom payment gateway" so i started with a reference to a bankwire. My module is installing/uninstalling perfectly but when it is installed i am not able to see the payment option of my module when i checkout. Here is the code that i wrote. If any one is having any clue on the same please help out of this problem.

 

 

class Atompayment extends PaymentModule

{

private $_html = '';

private $_postErrors = array();

 

public $loginid;

public $pass;

public $merchant;

public $extra_mail_vars;

 

public function __construct()

{

$this->name = 'atompayment';

$this->tab = 'payments_gateways';

$this->version = '1.0.1';

$this->author = 'Keshab';

$this->controllers = array('payment', 'validation');

$this->currencies = true;

$this->currencies_mode = 'checkbox';

 

$config = Configuration::getMultiple(array('ATOMID', 'ATOMPASS', 'ATOMMERCHANT'));

if (!empty($config['ATOMID'])) {

$this->loginid = $config['ATOMID'];

}

if (!empty($config['ATOMPASS'])) {

$this->pass = $config['ATOMPASS'];

}

if (!empty($config['ATOMMERCHANT'])) {

$this->merchant = $config['ATOMMERCHANT'];

}

$this->bootstrap = true;

parent::__construct();

$this->displayName = $this->l('Atom Payment Gateway');

$this->description = $this->l('Accept payments for your products via bank wire transfer.');

$this->confirmUninstall = $this->l('Are you sure about removing these details?');

if (!isset($this->loginid) || !isset($this->pass) || !isset($this->merchant)) {

$this->warning = $this->l('Account details must be configured before using this module.');

}

if (!count(Currency::checkPaymentCurrencies($this->id))) {

$this->warning = $this->l('No currency has been set for this module.');

}

$this->extra_mail_vars = array(

'{atompayment_loginid}' => Configuration::get('ATOMID'),

'{atompayment_pass}' => nl2br(Configuration::get('ATOMPASS')),

'{atompayment_merchant}' => nl2br(Configuration::get('ATOMMERCHANT'))

);

}

 

public function install() {

if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('paymentReturn')) {

return false;

}

return true;

}

 

public function uninstall() {

if (!Configuration::deleteByName('ATOMID') || !Configuration::deleteByName('ATOMPASS') || !Configuration::deleteByName('ATOMMERCHANT') || !parent::uninstall()) {

return false;

}

return true;

}

private function _postValidation() {

if (Tools::isSubmit('btnSubmit')) {

if (!Tools::getValue('ATOMID'))

$this->_postErrors[] = $this->l('Account ID is required.');

elseif (!Tools::getValue('ATOMPASS'))

$this->_postErrors[] = $this->l('Account password is required.');

elseif (!Tools::getValue('ATOMMERCHANT'))

$this->_postErrors[] = $this->l('Merchant ID is required.');

}

}

 

private function _postProcess() {

if (Tools::isSubmit('btnSubmit')) {

Configuration::updateValue('ATOMID', Tools::getValue('ATOMID'));

Configuration::updateValue('ATOMPASS', Tools::getValue('ATOMPASS'));

Configuration::updateValue('ATOMMERCHANT', Tools::getValue('ATOMMERCHANT'));

}

$this->_html .= $this->displayConfirmation($this->l('Settings updated'));

}

 

private function _displayBankWire() {

return $this->display(__FILE__, 'infoatom.tpl');

}

public function getContent() {

if (Tools::isSubmit('btnSubmit')) {

$this->_postValidation();

if (!count($this->_postErrors)) {

$this->_postProcess();

} else {

foreach ($this->_postErrors as $err) {

$this->_html .= $this->displayError($err);

}

}

} else

$this->_html .= '<br />';

 

$this->_html .= $this->_displayBankWire();

$this->_html .= $this->renderForm();

 

return $this->_html;

}

 

public function hookPayment($params) {

 

if (!$this->active)

return;

if (!$this->checkCurrency($params['cart']))

return;

$this->smarty->assign(array(

'this_path' => $this->_path,

'this_path_cod' => $this->_path,

'this_path_ssl' => Configuration::get('PS_FO_PROTOCOL').$_SERVER['HTTP_HOST']. __PS_BASE_URI__ . 'modules/' . $this->name . '/'

));

 

return $this->display(__FILE__, 'atompayment.tpl');

}

 

public function hookPaymentReturn($params) {

 

}

 

public function checkCurrency($cart) {

$currency_order = new Currency($cart->id_currency);

$currencies_module = $this->getCurrency($cart->id_currency);

 

if (is_array($currencies_module)) {

foreach ($currencies_module as $currency_module) {

if ($currency_order->id == $currency_module['id_currency']) {

return true;

}

}

}

return false;

}

 

public function renderForm() {

$fields_form = array(

'form' => array(

'legend' => array(

'title' => $this->l('Atom Configuration'),

'icon' => 'icon-envelope'

),

'input' => array(

array(

'type' => 'text',

'label' => $this->l('Atom Login ID'),

'name' => 'ATOMID'

),

array(

'type' => 'text',

'label' => $this->l('Atom Password'),

'name' => 'ATOMPASS'

),

array(

'type' => 'text',

'label' => $this->l('Merchant ID'),

'name' => 'ATOMMERCHANT'

),

),

'submit' => array(

'title' => $this->l('Save'),

)

),

);

 

$helper = new HelperForm();

$helper->show_toolbar = false;

$helper->table = $this->table;

$lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));

$helper->default_form_language = $lang->id;

$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;

$this->fields_form = array();

$helper->id = (int) Tools::getValue('id_carrier');

$helper->identifier = $this->identifier;

$helper->submit_action = 'btnSubmit';

$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;

$helper->token = Tools::getAdminTokenLite('AdminModules');

$helper->tpl_vars = array(

'fields_value' => $this->getConfigFieldsValues(),

'languages' => $this->context->controller->getLanguages(),

'id_language' => $this->context->language->id

);

 

return $helper->generateForm(array($fields_form));

}

 

public function getConfigFieldsValues() {

return array(

'ATOMID' => Tools::getValue('ATOMID', Configuration::get('ATOMID')),

'ATOMPASS' => Tools::getValue('ATOMPASS', Configuration::get('ATOMPASS')),

'ATOMMERCHANT' => Tools::getValue('ATOMMERCHANT', Configuration::get('ATOMMERCHANT')),

);

}

 

}

atompayment.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...