Skip to content

Commit 382bb1f

Browse files
authored
Merge pull request #8 from PaystackHQ/fix/currency-error
Fix/currency error
2 parents 9b445a4 + e5214bf commit 382bb1f

File tree

9 files changed

+203
-182
lines changed

9 files changed

+203
-182
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

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: 188 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -5,183 +5,199 @@
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('displayPayment') || !$this->registerHook('displayPaymentReturn') || !$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+
54+
public function installOrderState()
55+
{
56+
if (Configuration::get('PS_OS_PRESTAPAYSTACK_PAYMENT') < 1) {
57+
$order_state = new OrderState();
58+
$order_state->send_email = true;
59+
$order_state->module_name = $this->name;
60+
$order_state->invoice = false;
61+
$order_state->color = '#98c3ff';
62+
$order_state->logable = true;
63+
$order_state->shipped = false;
64+
$order_state->unremovable = false;
65+
$order_state->delivery = false;
66+
$order_state->hidden = false;
67+
$order_state->paid = false;
68+
$order_state->deleted = false;
69+
$order_state->name = array((int)Configuration::get('PS_LANG_DEFAULT') => pSQL($this->l('Paystack - Awaiting payment')));
70+
$order_state->template = array();
71+
foreach (LanguageCore::getLanguages() as $l) {
72+
$order_state->template[$l['id_lang']] = 'prestapaystack';
73+
}
74+
75+
// We copy the mails templates in mail directory
76+
foreach (LanguageCore::getLanguages() as $l) {
77+
$module_path = dirname(__FILE__).'/views/templates/mails/'.$l['iso_code'].'/';
78+
$application_path = dirname(__FILE__).'/../../mails/'.$l['iso_code'].'/';
79+
if (!copy($module_path.'prestapaystack.txt', $application_path.'prestapaystack.txt') ||
80+
!copy($module_path.'prestapaystack.html', $application_path.'prestapaystack.html')) {
81+
return false;
82+
}
83+
}
84+
85+
if ($order_state->add()) {
86+
// We save the order State ID in Configuration database
87+
Configuration::updateValue('PS_OS_PRESTAPAYSTACK_PAYMENT', $order_state->id);
88+
89+
// We copy the module logo in order state logo directory
90+
copy(dirname(__FILE__).'/logo.png', dirname(__FILE__).'/../../img/os/'.$order_state->id.'.gif');
91+
copy(dirname(__FILE__).'/logo.png', dirname(__FILE__).'/../../img/tmp/order_state_mini_'.$order_state->id.'.gif');
92+
} else {
93+
return false;
94+
}
95+
}
96+
return true;
97+
}
98+
99+
public function uninstall()
100+
{
101+
// Uninstall parent and unregister Configuration
102+
// Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'paystack_txncodes`');
103+
// $orderState = new OrderState((int)Configuration::get('VOGU_WAITING_PAYMENT'));
104+
// $orderState->delete();
105+
// Configuration::deleteByName('VOGU_WAITING_PAYMENT');
106+
if (!parent::uninstall()) {
107+
return false;
108+
}
109+
return true;
110+
}
111+
112+
public function getHookController($hook_name)
113+
{
114+
// Include the controller file
115+
require_once(dirname(__FILE__).'/controllers/hook/'.$hook_name.'.php');
116+
117+
// Build the controller name dynamically
118+
$controller_name = $this->name.$hook_name.'Controller';
119+
120+
// Instantiate controller
121+
$controller = new $controller_name($this, __FILE__, $this->_path);
122+
123+
// Return the controller
124+
return $controller;
125+
}
126+
127+
public function hookReturn($params)
128+
{
129+
$this->smarty->assign(array('vogURedirection' => Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'));
130+
131+
return $this->display(__FILE__, 'return.tpl');
132+
}
133+
134+
public function validation($verification)
135+
{
136+
$transaction = array();
137+
$t = array();
138+
if (Tools::getValue('txn_code') !== '') {
139+
$txn_code = Tools::getValue('txn_code');
140+
$amount = Tools::getValue('amounttotal');
141+
$email = Tools::getValue('email');
142+
$o_exist = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `code` = "'.$txn_code.'"');//Rproduct::where('code', '=', $code)->first();
143+
144+
if (count($o_exist) > 0) {
145+
$idCart = @$o_exist[0][cart_id];
146+
$this->context->cart = @new Cart((int)$idCart);
147+
}
148+
if ($verification->status == 'success') {
149+
$email = $verification->data->customer->email;
150+
$date = $verification->data->transaction_date;
151+
$total = $verification->data->amount/100;
152+
$status = 'approved';
153+
} else {
154+
$date = date("Y-m-d h:i:sa");
155+
$email = $email;
156+
$total = $amount;
157+
$status = 'failed';
158+
}
159+
$transaction_id = $txn_code;
160+
}
161+
162+
if (Validate::isLoadedObject($this->context->cart)) {
163+
if ($this->context->cart->getOrderTotal() != $total) {
164+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' doesn\'t have the correct amount expected during payment validation', 2, null, null, null, true);
165+
} else {
166+
$currency = new Currency((int)$this->context->cart->id_currency);
167+
if (trim(Tools::strtolower($status)) == 'approved') {
168+
$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);
169+
$new_order = new Order((int)$this->currentOrder);
170+
if (Validate::isLoadedObject($new_order)) {
171+
$payment = $new_order->getOrderPaymentCollection();
172+
$payment[0]->transaction_id = $transaction_id;
173+
$payment[0]->update();
174+
} else {
175+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' has an incorrect token given from VogU during payment validation', 2, null, null, null, true);
176+
}
177+
} else {
178+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' has an incorrect token given from VogU during payment validation', 2, null, null, null, true);
179+
}
180+
}
181+
} else {
182+
Logger::AddLog('[Paystack] The shopping card '.(int)$idCart.' was not found during the payment validation step', 2, null, null, null, true);
183+
}
184+
}
185+
public function hookDisplayPayment($params)
186+
{
187+
if (!$this->active || Configuration::get('PAYSTACK_MODE') == '') {
188+
return false;
189+
}
190+
$controller = $this->getHookController('displayPayment');
191+
return $controller->run($params);
192+
}
193+
public function hookDisplayPaymentReturn($params)
194+
{
195+
$controller = $this->getHookController('displayPaymentReturn');
196+
return $controller->run($params);
197+
}
198+
public function getContent()
199+
{
200+
$controller = $this->getHookController('getContent');
201+
return $controller->run();
202+
}
187203
}

views/img/logo2.png

6.53 KB
Loading

views/img/paystack_logo.png

23 KB
Loading

0 commit comments

Comments
 (0)