Skip to content

Commit 7270b84

Browse files
committed
v1.0 ready
1 parent 286cc1a commit 7270b84

File tree

16 files changed

+202
-594
lines changed

16 files changed

+202
-594
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
EftSecure
1+
Paystack

config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<name>paystack</name>
44
<displayName><![CDATA[Paystack]]></displayName>
55
<version><![CDATA[1.0.0]]></version>
6-
<description><![CDATA[Accept payments for your products via Paystack transfer.]]></description>
7-
<author><![CDATA[WCST]]></author>
6+
<description><![CDATA[Accept payments for your products via Paystack. Compatible with Prestashop 1.7 and higher]]></description>
7+
<author><![CDATA[Douglas Kendyson]]></author>
88
<tab><![CDATA[payments_gateways]]></tab>
99
<confirmUninstall><![CDATA[Are you sure about removing these details?]]></confirmUninstall>
1010
<is_configurable>1</is_configurable>

controllers/front/eftsuccess.php

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
/*
3+
* 2007-2015 PrestaShop
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License (AFL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/afl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author PrestaShop SA <contact@prestashop.com>
22+
* @copyright 2007-2015 PrestaShop SA
23+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24+
* International Registered Trademark & Property of PrestaShop SA
25+
*/
26+
27+
/**
28+
* @since 1.5.0
29+
*/
30+
class PaystackPaystacksuccessModuleFrontController extends ModuleFrontController
31+
{
32+
/**
33+
* @see FrontController::postProcess()
34+
*/
35+
public function verify_txn($code){
36+
$test_secretkey = Configuration::get('PAYSTACK_TEST_SECRETKEY');
37+
$live_secretkey = Configuration::get('PAYSTACK_LIVE_SECRETKEY');
38+
$mode = Configuration::get('PAYSTACK_MODE');
39+
40+
if ($mode == '1') {
41+
$key = $test_secretkey;
42+
}else{
43+
$key = $live_secretkey;
44+
}
45+
$key = str_replace(' ', '', $key);
46+
47+
$contextOptions = array(
48+
'http'=>array(
49+
'method'=>"GET",
50+
'header'=> array("Authorization: Bearer ".$key."\r\n")
51+
)
52+
);
53+
54+
$context = stream_context_create($contextOptions);
55+
$url = 'https://api.paystack.co/transaction/verify/'.$code;
56+
$request = Tools::file_get_contents($url, false, $context);
57+
$result = Tools::jsonDecode($request);
58+
return $result;
59+
}
60+
public function initContent()
61+
{
62+
$cart = $this->context->cart;
63+
$txn_code = Tools::getValue('reference');
64+
if(Tools::getValue('reference') == ""){
65+
$txn_code = $_POST['reference'];
66+
}
67+
$amount = Tools::getValue('amount');
68+
$email = Tools::getValue('email');
69+
$verification = $this->verify_txn($txn_code);
70+
71+
if(($verification->status===false) || (!property_exists($verification, 'data')) || ($verification->data->status !== 'success')){
72+
$date = date("Y-m-d h:i:sa");
73+
$email = $email;
74+
$total = $amount;
75+
$status = 'failed';
76+
Tools::redirect('404');
77+
} else {
78+
$email = $verification->data->customer->email;
79+
$date = $verification->data->transaction_date;
80+
$total = $verification->data->amount/100;
81+
$status = 'approved';
82+
$currency_order = new Currency($cart->id_currency);
83+
84+
$extra_vars = array(
85+
'transaction_id' => $txn_code,
86+
'id' => 1,
87+
'payment_method' => 'Paystack',
88+
'status' => 'Paid',
89+
'currency' => $currency_order->iso_code,
90+
'intent' => '$intent'
91+
);
92+
93+
$customer = new Customer($cart->id_customer);
94+
95+
$this->module->validateOrder(
96+
$cart->id,
97+
Configuration::get('PS_OS_PAYSTACK'),
98+
$total,
99+
$this->module->displayName,
100+
'Paystack Reference: '.$txn_code,
101+
$extra_vars,
102+
(int)$cart->id_currency,
103+
false,
104+
$customer->secure_key
105+
);
106+
107+
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key.'&reference='.$txn_code);
108+
}
109+
}
110+
}

controllers/front/validation.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,8 @@ public function postProcess()
5050
die($this->module->getTranslator()->trans('This payment method is not available.', array(), 'Modules.Paystack.Shop'));
5151

5252
if ((int)Tools::getValue('wcst_iframe') == 1) {
53-
Tools::redirect('index.php?controller=order&step=3&eft_iframe=1');
53+
Tools::redirect('index.php?controller=order&step=3&gateway=paystack');
5454
exit;
5555
}
56-
/* $customer = new Customer($cart->id_customer);
57-
if (!Validate::isLoadedObject($customer))
58-
Tools::redirect('index.php?controller=order&step=1');
59-
60-
$currency = $this->context->currency;
61-
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
62-
$mailVars = array(
63-
'{paystack_owner}' => Configuration::get('PAYSTACK_OWNER'),
64-
'{paystack_details}' => nl2br(Configuration::get('PAYSTACK_DETAILS')),
65-
'{paystack_address}' => nl2br(Configuration::get('PAYSTACK_ADDRESS'))
66-
);
67-
68-
$this->module->validateOrder($cart->id, Configuration::get('PS_OS_EFTSECURE'), $total, $this->module->displayName, NULL, $mailVars, (int)$currency->id, false, $customer->secure_key);
69-
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key); */
70-
}
56+
}
7157
}

paystack.css

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)