|
4 | 4 |
|
5 | 5 | class PrestaPaystackPaymentModuleFrontController extends ModuleFrontController |
6 | 6 | { |
7 | | - public $display_column_left = false; |
8 | | - |
9 | | - public $ssl = true; |
10 | | - |
11 | | - public function initContent() |
12 | | - { |
13 | | - // Call parent init content method |
14 | | - parent::initContent(); |
15 | | - |
16 | | - $this->display_column_left = false; |
17 | | - $this->display_column_right = false; |
18 | | - $this->context->smarty->assign(array( |
19 | | - 'nb_products' => $this->context->cart->nbProducts(), |
20 | | - 'cart_currency' => $this->context->cart->id_currency, |
21 | | - 'currencies' => $this->module->getCurrency((int)$this->context->cart->id_currency), |
22 | | - 'total_amount' =>$this->context->cart->getOrderTotal(true, Cart::BOTH), |
23 | | - 'path' => $this->module->getPathUri(), |
24 | | - )); |
25 | | - $test_publickey = Configuration::get('PAYSTACK_TEST_PUBLICKEY'); |
26 | | - $live_publickey = Configuration::get('PAYSTACK_LIVE_PUBLICKEY'); |
27 | | - $mode = Configuration::get('PAYSTACK_MODE'); |
28 | | - $style = Configuration::get('PAYSTACK_STYLE'); |
29 | | - if ($mode == 'test') { |
30 | | - $key = $test_publickey; |
31 | | - }else{ |
32 | | - $key = $live_publickey; |
| 7 | + public $display_column_left = false; |
| 8 | + |
| 9 | + public $ssl = true; |
| 10 | + |
| 11 | + public function initContent() |
| 12 | + { |
| 13 | + // Call parent init content method |
| 14 | + parent::initContent(); |
| 15 | + |
| 16 | + $this->display_column_left = false; |
| 17 | + $this->display_column_right = false; |
| 18 | + $this->context->smarty->assign( |
| 19 | + array( |
| 20 | + 'nb_products' => $this->context->cart->nbProducts(), |
| 21 | + 'cart_currency' => $this->context->cart->id_currency, |
| 22 | + 'currencies' => $this->module->getCurrency((int)$this->context->cart->id_currency), |
| 23 | + 'total_amount' =>$this->context->cart->getOrderTotal(true, Cart::BOTH), |
| 24 | + 'path' => $this->module->getPathUri(), |
| 25 | + ) |
| 26 | + ); |
| 27 | + $test_publickey = Configuration::get('PAYSTACK_TEST_PUBLICKEY'); |
| 28 | + $live_publickey = Configuration::get('PAYSTACK_LIVE_PUBLICKEY'); |
| 29 | + $mode = Configuration::get('PAYSTACK_MODE'); |
| 30 | + $style = Configuration::get('PAYSTACK_STYLE'); |
| 31 | + if ($mode == 'test') { |
| 32 | + $key = $test_publickey; |
| 33 | + } else { |
| 34 | + $key = $live_publickey; |
| 35 | + } |
| 36 | + $key = str_replace(' ', '', $key); |
| 37 | + |
| 38 | + $this->context->smarty->assign('key', $key); |
| 39 | + $this->context->smarty->assign('style', $style); |
| 40 | + $cart = $this->context->cart; |
| 41 | + $cart_id = $cart->id; |
| 42 | + |
| 43 | + $pcode = $this->getPaystackcode($cart_id); |
| 44 | + // die($cart_id); |
| 45 | + if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 ||!$this->module->active) { |
| 46 | + Tools::redirect('index.php?controller=order&step=1'); |
| 47 | + } |
| 48 | + ///// |
| 49 | + $authorized = false; |
| 50 | + foreach (Module::getPaymentModules() as $module) { |
| 51 | + if ($module['name'] == $this->module->name) { |
| 52 | + $authorized = true; |
| 53 | + } |
| 54 | + } |
| 55 | + if (!$authorized) { |
| 56 | + die('This payment method is not available.'); |
| 57 | + } |
| 58 | + $customer = new Customer($cart->id_customer); |
| 59 | + if (!Validate::isLoadedObject($customer)) { |
| 60 | + Tools::redirect('index.php?controller=order&step=1'); |
| 61 | + } |
| 62 | + ////////// |
| 63 | + $all_products = self::$cart->getProducts(); |
| 64 | + $this->context->smarty->assign( |
| 65 | + array( |
| 66 | + 'nbProducts' => $cart->nbProducts(), |
| 67 | + 'email' => $this->context->customer->email, |
| 68 | + 'code' => $pcode->code, |
| 69 | + 'products' => $all_products, |
| 70 | + ) |
| 71 | + ); |
| 72 | + |
| 73 | + $this->setTemplate('payment.tpl'); |
33 | 74 | } |
34 | | - $key = str_replace(' ', '', $key); |
35 | 75 |
|
36 | | - $this->context->smarty->assign('key', $key); |
37 | | - $this->context->smarty->assign('style', $style); |
38 | | - $cart = $this->context->cart; |
39 | | - $cart_id = $cart->id; |
| 76 | + private function getPaystackcode($cart_id) { |
| 77 | + $o_exist = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `cart_id` = "'.$cart_id.'"'); |
40 | 78 |
|
41 | | - $pcode = $this->getPaystackcode($cart_id); |
42 | | - // die($cart_id); |
43 | | - if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 ||!$this->module->active){ |
44 | | - Tools::redirect('index.php?controller=order&step=1'); |
45 | | - } |
46 | | - ///// |
47 | | - $authorized = false; |
48 | | - foreach (Module::getPaymentModules() as $module){ |
49 | | - if ($module['name'] == $this->module->name){ |
50 | | - $authorized = true; |
51 | | - } |
52 | | - } |
53 | | - if (!$authorized){ |
54 | | - die('This payment method is not available.'); |
55 | | - } |
56 | | - $customer = new Customer($cart->id_customer); |
57 | | - if (!Validate::isLoadedObject($customer)){ |
58 | | - Tools::redirect('index.php?controller=order&step=1'); |
59 | | - } |
60 | | - ////////// |
61 | | - $all_products = self::$cart->getProducts(); |
62 | | - $this->context->smarty->assign(array( |
63 | | - 'nbProducts' => $cart->nbProducts(), |
64 | | - 'email' => $this->context->customer->email, |
65 | | - 'code' => $pcode->code, |
66 | | - 'products' => $all_products, |
67 | | - |
68 | | - )); |
69 | | - |
70 | | - $this->setTemplate('payment.tpl'); |
71 | | - } |
| 79 | + if (count($o_exist) == 0) { |
| 80 | + $pcode = new Paystackcode(); |
| 81 | + $pcode->id = null; |
| 82 | + $pcode->cart_id = (int)$cart_id; |
| 83 | + $pcode->code = $pcode->generate_code(); |
| 84 | + $pcode->add(); |
72 | 85 |
|
73 | | - private function getPaystackcode($cart_id){ |
74 | | - $o_exist = Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `cart_id` = "'.$cart_id.'"'); |
| 86 | + } else { |
| 87 | + $acode = new Paystackcode(); |
| 88 | + $newcode = $acode->generate_code(); |
| 89 | + // Db::getInstance()->execute($sql); |
| 90 | + $newref = @Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'paystack_txncodes` SET `code` = "'.$newcode.'" WHERE `cart_id` = "'.$cart_id.'"'); |
| 91 | + //SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `code` = "'.$code.'"');//Rproduct::where('code', '=', $code)-> |
75 | 92 |
|
76 | | - if (count($o_exist) == 0) { |
77 | | - $pcode = new Paystackcode(); |
78 | | - $pcode->id = NULL; |
79 | | - $pcode->cart_id = (int)$cart_id; |
80 | | - $pcode->code = $pcode->generate_code(); |
81 | | - $pcode->add(); |
| 93 | + $pcode = @new Paystackcode((int)$o_exist[0][id]); |
| 94 | + // print_r($o_exist); |
82 | 95 |
|
83 | | - } else { |
84 | | - $acode = new Paystackcode(); |
85 | | - $newcode = $acode->generate_code(); |
86 | | - // Db::getInstance()->execute($sql); |
87 | | - $newref = @Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'paystack_txncodes` SET `code` = "'.$newcode.'" WHERE `cart_id` = "'.$cart_id.'"'); |
88 | | -//SELECT * FROM `'._DB_PREFIX_.'paystack_txncodes` WHERE `code` = "'.$code.'"');//Rproduct::where('code', '=', $code)-> |
| 96 | + } |
89 | 97 |
|
90 | | - $pcode = @new Paystackcode((int)$o_exist[0][id]); |
91 | | - // print_r($o_exist); |
92 | 98 |
|
| 99 | + return $pcode; |
93 | 100 | } |
94 | | - |
95 | | - |
96 | | - return $pcode; |
97 | | - } |
98 | 101 | } |
0 commit comments