Skip to content

Commit a41ce2d

Browse files
committed
Update meta for plugin
1 parent 9b445a4 commit a41ce2d

File tree

3 files changed

+188
-175
lines changed

3 files changed

+188
-175
lines changed

config.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<module>
33
<name>prestapaystack</name>
44
<displayName><![CDATA[Paystack]]></displayName>
5-
<version><![CDATA[1.0.4]]></version>
6-
<description><![CDATA[Paystack for prestashop, Accept online card payments in Naira.]]></description>
7-
<author><![CDATA[Douglas Kendyson]]></author>
5+
<version><![CDATA[1.0.5]]></version>
6+
<description><![CDATA[Paystack for PrestaShop, Accept online card payments on your store.]]></description>
7+
<author><![CDATA[Paystack]]></author>
88
<tab><![CDATA[payments_gateways]]></tab>
99
<is_configurable>1</is_configurable>
1010
<need_instance>1</need_instance>

logo.png

636 Bytes
Loading

prestapaystack.php

Lines changed: 185 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -5,183 +5,196 @@
55
* @author kendysonD
66
*/
77

8-
if (!defined('_CAN_LOAD_FILES_'))
9-
exit;
8+
if (!defined('_CAN_LOAD_FILES_')) {
9+
exit;
10+
}
1011
include_once(_PS_MODULE_DIR_.'prestapaystack/classes/paystackcode.php');
1112

12-
class PrestaPaystack extends PaymentModule{
13-
private $_postErrors = array();
14-
15-
public function __construct(){
16-
$this->name = 'prestapaystack';
17-
$this->tab = 'payments_gateways';
18-
$this->version = '1.0.4';
19-
$this->bootstrap = true;
20-
$this->author = 'Douglas Kendyson';
21-
$this->description = 'Paystack for prestashop, Accept online card payments in Naira.';
22-
$this->module_key = 'b3d1676652fa4e8c9be762f5ec29aa2b';
23-
parent::__construct();
24-
25-
$this->displayName = 'Paystack';
26-
27-
require(_PS_MODULE_DIR_.'prestapaystack/backward_compatibility/backward.php');
28-
$this->context->smarty->assign('base_dir', __PS_BASE_URI__);
29-
}
30-
public function install(){
31-
$this->registerHook('orderConfirmation');
32-
$this->registerHook('return');
33-
if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('return') || !$this->registerHook('orderConfirmation') ||
34-
!Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'paystack_txncodes` (
13+
class PrestaPaystack extends PaymentModule
14+
{
15+
private $_postErrors = array();
16+
17+
public function __construct()
18+
{
19+
$this->name = 'prestapaystack';
20+
$this->tab = 'payments_gateways';
21+
$this->version = '1.0.5';
22+
$this->bootstrap = true;
23+
$this->author = 'Paystack';
24+
$this->description = 'Paystack for PrestaShop. Accept online card payments on your store.';
25+
$this->module_key = 'b3d1676652fa4e8c9be762f5ec29aa2b';
26+
parent::__construct();
27+
28+
$this->displayName = 'Paystack';
29+
30+
require(_PS_MODULE_DIR_.'prestapaystack/backward_compatibility/backward.php');
31+
$this->context->smarty->assign('base_dir', __PS_BASE_URI__);
32+
}
33+
public function install()
34+
{
35+
$this->registerHook('orderConfirmation');
36+
$this->registerHook('return');
37+
if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('return') || !$this->registerHook('orderConfirmation') ||
38+
!Db::getInstance()->Execute('CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'paystack_txncodes` (
3539
`id` int(10) NOT NULL,
3640
`cart_id` int(11) NOT NULL,
3741
`code` varchar(32) DEFAULT NULL
3842
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;ALTER TABLE `'._DB_PREFIX_.'paystack_txncodes`
3943
ADD PRIMARY KEY (`id`);ALTER TABLE `'._DB_PREFIX_.'paystack_txncodes`
40-
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=24;')) // prod | test
41-
return false;
42-
43-
if (!$this->installOrderState())
44-
return false;
45-
return true;
46-
}
47-
public function uninstall(){
48-
// Uninstall parent and unregister Configuration
49-
// Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'paystack_txncodes`');
50-
// $orderState = new OrderState((int)Configuration::get('VOGU_WAITING_PAYMENT'));
51-
// $orderState->delete();
52-
// Configuration::deleteByName('VOGU_WAITING_PAYMENT');
53-
if (!parent::uninstall())
54-
return false;
55-
return true;
56-
}
57-
58-
public function getHookController($hook_name){
59-
// Include the controller file
60-
require_once(dirname(__FILE__).'/controllers/hook/'.$hook_name.'.php');
61-
62-
// Build the controller name dynamically
63-
$controller_name = $this->name.$hook_name.'Controller';
64-
65-
// Instantiate controller
66-
$controller = new $controller_name($this, __FILE__,$this->_path);
67-
68-
// Return the controller
69-
return $controller;
70-
}
71-
public function installOrderState(){
72-
if (Configuration::get('PS_OS_PRESTAPAYSTACK_PAYMENT') < 1){
73-
$order_state = new OrderState();
74-
$order_state->send_email = false;
75-
$order_state->module_name = $this->name;
76-
$order_state->invoice = false;
77-
$order_state->color = '#98c3ff';
78-
$order_state->logable = true;
79-
$order_state->shipped = false;
80-
$order_state->unremovable = false;
81-
$order_state->delivery = false;
82-
$order_state->hidden = false;
83-
$order_state->paid = false;
84-
$order_state->deleted = false;
85-
$order_state->name = array((int)Configuration::get('PS_LANG_DEFAULT') => pSQL($this->l('Paystack - Awaiting payment')));
86-
$order_state->template = array();
87-
foreach (LanguageCore::getLanguages() as $l)
88-
$order_state->template[$l['id_lang']] = 'prestapaystack';
89-
90-
// We copy the mails templates in mail directory
91-
foreach (LanguageCore::getLanguages() as $l)
92-
{
93-
$module_path = dirname(__FILE__).'/views/templates/mails/'.$l['iso_code'].'/';
94-
$application_path = dirname(__FILE__).'/../../mails/'.$l['iso_code'].'/';
95-
if (!copy($module_path.'prestapaystack.txt', $application_path.'prestapaystack.txt') ||
96-
!copy($module_path.'prestapaystack.html', $application_path.'prestapaystack.html'))
97-
return false;
98-
}
99-
100-
if ($order_state->add())
101-
{
102-
// We save the order State ID in Configuration database
103-
Configuration::updateValue('PS_OS_PRESTAPAYSTACK_PAYMENT', $order_state->id);
104-
105-
// We copy the module logo in order state logo directory
106-
copy(dirname(__FILE__).'/logo.png', dirname(__FILE__).'/../../img/os/'.$order_state->id.'.gif');
107-
copy(dirname(__FILE__).'/logo.png', dirname(__FILE__).'/../../img/tmp/order_state_mini_'.$order_state->id.'.gif');
108-
}
109-
else
110-
return false;
111-
}
112-
return true;
113-
}
114-
public function getContent()
115-
{
116-
$controller = $this->getHookController('getContent');
117-
return $controller->run();
118-
}
119-
public function hookReturn($params){
120-
$this->smarty->assign(array('vogURedirection' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'));
121-
122-
return $this->display(__FILE__, 'return.tpl');
123-
124-
}
125-
126-
public function validation($verification){
127-
$transaction = array();
128-
$t = array();
129-
if(Tools::getValue('txn_code') !== ''){
130-
$txn_code = Tools::getValue('txn_code');
131-
$amount = Tools::getValue('amounttotal');
132-
$email = Tools::getValue('email');
133-
$o_exist = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `code` = "'.$txn_code.'"');//Rproduct::where('code', '=', $code)->first();
134-
135-
if (count($o_exist) > 0) {
136-
$idCart = @$o_exist[0][cart_id];
137-
$this->context->cart = @new Cart((int)$idCart);
138-
}
139-
if ($verification->status == 'success') {
140-
$email = $verification->data->customer->email;
141-
$date = $verification->data->transaction_date;
142-
$total = $verification->data->amount/100;
143-
$status = 'approved';
144-
}else{
145-
$date = date("Y-m-d h:i:sa");
146-
$email = $email;
147-
$total = $amount;
148-
$status = 'failed';
149-
}
150-
$transaction_id = $txn_code;
151-
}
152-
153-
if (Validate::isLoadedObject($this->context->cart)){
154-
if ($this->context->cart->getOrderTotal() != $total){
155-
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' doesn\'t have the correct amount expected during payment validation', 2, null, null, null, true);
156-
}else{
157-
$currency = new Currency((int)$this->context->cart->id_currency);
158-
if (trim(Tools::strtolower($status)) == 'approved'){
159-
$this->validateOrder((int)$this->context->cart->id, (int)Configuration::get('PS_OS_PAYMENT'), (float)$this->context->cart->getOrderTotal(), $this->displayName, $transaction_id, array(), NULL, false, $this->context->cart->secure_key);
160-
$new_order = new Order((int)$this->currentOrder);
161-
if (Validate::isLoadedObject($new_order)){
162-
$payment = $new_order->getOrderPaymentCollection();
163-
$payment[0]->transaction_id = $transaction_id;
164-
$payment[0]->update();
165-
166-
}else{
167-
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' has an incorrect token given from VogU during payment validation', 2, null, null, null, true);
168-
}
169-
}else{
170-
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' has an incorrect token given from VogU during payment validation', 2, null, null, null, true);
171-
}
172-
}
173-
}else{
174-
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' was not found during the payment validation step', 2, null, null, null, true);
175-
}
176-
}
177-
public function hookDisplayPayment($params){
178-
if (!$this->active || Configuration::get('PAYSTACK_MODE') == '')
179-
return false;
180-
$controller = $this->getHookController('displayPayment');
181-
return $controller->run($params);
182-
}
183-
public function hookDisplayPaymentReturn($params){
184-
$controller = $this->getHookController('displayPaymentReturn');
185-
return $controller->run($params);
186-
}
44+
MODIFY `id` int(10) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=24;')) { // prod | test
45+
return false;
46+
}
47+
48+
if (!$this->installOrderState()) {
49+
return false;
50+
}
51+
return true;
52+
}
53+
public function uninstall()
54+
{
55+
// Uninstall parent and unregister Configuration
56+
// Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'paystack_txncodes`');
57+
// $orderState = new OrderState((int)Configuration::get('VOGU_WAITING_PAYMENT'));
58+
// $orderState->delete();
59+
// Configuration::deleteByName('VOGU_WAITING_PAYMENT');
60+
if (!parent::uninstall()) {
61+
return false;
62+
}
63+
return true;
64+
}
65+
66+
public function getHookController($hook_name)
67+
{
68+
// Include the controller file
69+
require_once(dirname(__FILE__).'/controllers/hook/'.$hook_name.'.php');
70+
71+
// Build the controller name dynamically
72+
$controller_name = $this->name.$hook_name.'Controller';
73+
74+
// Instantiate controller
75+
$controller = new $controller_name($this, __FILE__, $this->_path);
76+
77+
// Return the controller
78+
return $controller;
79+
}
80+
public function installOrderState()
81+
{
82+
if (Configuration::get('PS_OS_PRESTAPAYSTACK_PAYMENT') < 1) {
83+
$order_state = new OrderState();
84+
$order_state->send_email = false;
85+
$order_state->module_name = $this->name;
86+
$order_state->invoice = false;
87+
$order_state->color = '#98c3ff';
88+
$order_state->logable = true;
89+
$order_state->shipped = false;
90+
$order_state->unremovable = false;
91+
$order_state->delivery = false;
92+
$order_state->hidden = false;
93+
$order_state->paid = false;
94+
$order_state->deleted = false;
95+
$order_state->name = array((int)Configuration::get('PS_LANG_DEFAULT') => pSQL($this->l('Paystack - Awaiting payment')));
96+
$order_state->template = array();
97+
foreach (LanguageCore::getLanguages() as $l) {
98+
$order_state->template[$l['id_lang']] = 'prestapaystack';
99+
}
100+
101+
// We copy the mails templates in mail directory
102+
foreach (LanguageCore::getLanguages() as $l) {
103+
$module_path = dirname(__FILE__).'/views/templates/mails/'.$l['iso_code'].'/';
104+
$application_path = dirname(__FILE__).'/../../mails/'.$l['iso_code'].'/';
105+
if (!copy($module_path.'prestapaystack.txt', $application_path.'prestapaystack.txt') ||
106+
!copy($module_path.'prestapaystack.html', $application_path.'prestapaystack.html')) {
107+
return false;
108+
}
109+
}
110+
111+
if ($order_state->add()) {
112+
// We save the order State ID in Configuration database
113+
Configuration::updateValue('PS_OS_PRESTAPAYSTACK_PAYMENT', $order_state->id);
114+
115+
// We copy the module logo in order state logo directory
116+
copy(dirname(__FILE__).'/logo.png', dirname(__FILE__).'/../../img/os/'.$order_state->id.'.gif');
117+
copy(dirname(__FILE__).'/logo.png', dirname(__FILE__).'/../../img/tmp/order_state_mini_'.$order_state->id.'.gif');
118+
} else {
119+
return false;
120+
}
121+
}
122+
return true;
123+
}
124+
public function getContent()
125+
{
126+
$controller = $this->getHookController('getContent');
127+
return $controller->run();
128+
}
129+
public function hookReturn($params)
130+
{
131+
$this->smarty->assign(array('vogURedirection' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'));
132+
133+
return $this->display(__FILE__, 'return.tpl');
134+
}
135+
136+
public function validation($verification)
137+
{
138+
$transaction = array();
139+
$t = array();
140+
if (Tools::getValue('txn_code') !== '') {
141+
$txn_code = Tools::getValue('txn_code');
142+
$amount = Tools::getValue('amounttotal');
143+
$email = Tools::getValue('email');
144+
$o_exist = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `code` = "'.$txn_code.'"');//Rproduct::where('code', '=', $code)->first();
145+
146+
if (count($o_exist) > 0) {
147+
$idCart = @$o_exist[0][cart_id];
148+
$this->context->cart = @new Cart((int)$idCart);
149+
}
150+
if ($verification->status == 'success') {
151+
$email = $verification->data->customer->email;
152+
$date = $verification->data->transaction_date;
153+
$total = $verification->data->amount/100;
154+
$status = 'approved';
155+
} else {
156+
$date = date("Y-m-d h:i:sa");
157+
$email = $email;
158+
$total = $amount;
159+
$status = 'failed';
160+
}
161+
$transaction_id = $txn_code;
162+
}
163+
164+
if (Validate::isLoadedObject($this->context->cart)) {
165+
if ($this->context->cart->getOrderTotal() != $total) {
166+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' doesn\'t have the correct amount expected during payment validation', 2, null, null, null, true);
167+
} else {
168+
$currency = new Currency((int)$this->context->cart->id_currency);
169+
if (trim(Tools::strtolower($status)) == 'approved') {
170+
$this->validateOrder((int)$this->context->cart->id, (int)Configuration::get('PS_OS_PAYMENT'), (float)$this->context->cart->getOrderTotal(), $this->displayName, $transaction_id, array(), null, false, $this->context->cart->secure_key);
171+
$new_order = new Order((int)$this->currentOrder);
172+
if (Validate::isLoadedObject($new_order)) {
173+
$payment = $new_order->getOrderPaymentCollection();
174+
$payment[0]->transaction_id = $transaction_id;
175+
$payment[0]->update();
176+
} else {
177+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' has an incorrect token given from VogU during payment validation', 2, null, null, null, true);
178+
}
179+
} else {
180+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' has an incorrect token given from VogU during payment validation', 2, null, null, null, true);
181+
}
182+
}
183+
} else {
184+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' was not found during the payment validation step', 2, null, null, null, true);
185+
}
186+
}
187+
public function hookDisplayPayment($params)
188+
{
189+
if (!$this->active || Configuration::get('PAYSTACK_MODE') == '') {
190+
return false;
191+
}
192+
$controller = $this->getHookController('displayPayment');
193+
return $controller->run($params);
194+
}
195+
public function hookDisplayPaymentReturn($params)
196+
{
197+
$controller = $this->getHookController('displayPaymentReturn');
198+
return $controller->run($params);
199+
}
187200
}

0 commit comments

Comments
 (0)