diff --git a/1.5.x/upload/catalog/controller/payment/paystack.php b/1.5.x/upload/catalog/controller/payment/paystack.php
index c913933..2885cfa 100755
--- a/1.5.x/upload/catalog/controller/payment/paystack.php
+++ b/1.5.x/upload/catalog/controller/payment/paystack.php
@@ -25,6 +25,7 @@ protected function index()
$this->data['ref'] = uniqid('' . $this->session->data['order_id'] . '-');
$this->data['amount'] = intval($order_info['total'] * 100);
$this->data['email'] = $order_info['email'];
+ $this->data['currency'] = $order_info['currency_code'];
$this->data['callback'] = $this->url->link('payment/paystack/callback', 'trxref=' . rawurlencode($this->data['ref']), 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paystack.tpl')) {
@@ -45,12 +46,13 @@ protected function query_api_transaction_verify($reference)
$skey = $this->config->get('paystack_test_secret');
}
- $context = stream_context_create(array(
+ $context = stream_context_create(
+ array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: Bearer " . $skey,
)
- )
+ )
);
$url = 'https://api.paystack.co/transaction/verify/'. rawurlencode($reference);
$request = file_get_contents($url, false, $context);
diff --git a/1.5.x/upload/catalog/model/payment/paystack.php b/1.5.x/upload/catalog/model/payment/paystack.php
index c896b17..63a0cc3 100755
--- a/1.5.x/upload/catalog/model/payment/paystack.php
+++ b/1.5.x/upload/catalog/model/payment/paystack.php
@@ -17,9 +17,16 @@ public function getMethod($address, $total)
$status = false;
}
- // Paystack Only switches NGN for now
- if ($status && (strtoupper($this->currency->getCode())!=='NGN')) {
- $status = false;
+ // Paystack Only switches NGN, GHS and USD for now
+ if ($status && (!in_array(
+ strtoupper($this->currency->getCode()),
+ [
+ 'NGN',
+ 'GHS'
+ ]
+ ))
+ ) {
+ $status = true;
}
$method_data = array();
diff --git a/1.5.x/upload/catalog/view/theme/default/template/payment/paystack.tpl b/1.5.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
index 7f6ccc7..f53444b 100755
--- a/1.5.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
+++ b/1.5.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
@@ -17,6 +17,7 @@
key: '',
email: '',
amount: ,
+ currency: '',
ref: '',
callback: function(response){
window.location.href='';
diff --git a/2.2.x/upload/catalog/controller/payment/paystack.php b/2.2.x/upload/catalog/controller/payment/paystack.php
index f1a3ac4..29d58b2 100755
--- a/2.2.x/upload/catalog/controller/payment/paystack.php
+++ b/2.2.x/upload/catalog/controller/payment/paystack.php
@@ -25,6 +25,7 @@ public function index()
$data['ref'] = uniqid('' . $this->session->data['order_id'] . '-');
$data['amount'] = intval($order_info['total'] * 100);
$data['email'] = $order_info['email'];
+ $data['currency'] = $order_info['currency_code'];
$data['callback'] = $this->url->link('payment/paystack/callback', 'trxref=' . rawurlencode($data['ref']), 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paystack.tpl')) {
@@ -44,12 +45,13 @@ private function query_api_transaction_verify($reference)
$skey = $this->config->get('paystack_test_secret');
}
- $context = stream_context_create(array(
- 'http'=>array(
- 'method'=>"GET",
- 'header'=>"Authorization: Bearer " . $skey,
+ $context = stream_context_create(
+ array(
+ 'http'=>array(
+ 'method'=>"GET",
+ 'header'=>"Authorization: Bearer " . $skey,
+ )
)
- )
);
$url = 'https://api.paystack.co/transaction/verify/'. rawurlencode($reference);
$request = file_get_contents($url, false, $context);
diff --git a/2.2.x/upload/catalog/model/payment/paystack.php b/2.2.x/upload/catalog/model/payment/paystack.php
index f7d1999..080848d 100755
--- a/2.2.x/upload/catalog/model/payment/paystack.php
+++ b/2.2.x/upload/catalog/model/payment/paystack.php
@@ -24,9 +24,16 @@ public function getMethod($address, $total)
$status = false;
}
- // Paystack Only switches NGN for now
- if ($status && (strtoupper($this->config->get('config_currency'))!=='NGN')) {
- $status = false;
+ // Paystack only switches NGN, GHS and USD for now
+ if ($status && (!in_array(
+ strtoupper($this->config->get('config_currency')),
+ [
+ 'NGN',
+ 'GHS'
+ ]
+ ))
+ ) {
+ $status = true;
}
$method_data = array();
diff --git a/2.2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl b/2.2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
index c81f38e..fecddf0 100755
--- a/2.2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
+++ b/2.2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
@@ -16,6 +16,7 @@
key: '',
email: '',
amount: ,
+ currency: '',
ref: '',
callback: function(response){
window.location.href='';
diff --git a/2.3.x/upload/catalog/controller/extension/payment/paystack.php b/2.3.x/upload/catalog/controller/extension/payment/paystack.php
index d8aa8d4..e2a91dc 100644
--- a/2.3.x/upload/catalog/controller/extension/payment/paystack.php
+++ b/2.3.x/upload/catalog/controller/extension/payment/paystack.php
@@ -1,156 +1,117 @@
-language->load('extension/payment/paystack');
-
- $data['text_testmode'] = $this->language->get('text_testmode');
- $data['button_confirm'] = $this->language->get('button_confirm');
-
- $data['livemode'] = $this->config->get('paystack_live');
-
- if ($this->config->get('paystack_live')) {
- $data['key'] = $this->config->get('paystack_live_public');
- } else {
- $data['key'] = $this->config->get('paystack_test_public');
- }
-
- $this->load->model('checkout/order');
-
- $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
-
- if ($order_info) {
-
- $data['ref'] = uniqid('' . $this->session->data['order_id'] . '-');
- $data['amount'] = intval($order_info['total'] * 100);
- $data['email'] = $order_info['email'];
- $data['callback'] = $this->url->link('extension/payment/paystack/callback', 'trxref=' . rawurlencode($data['ref']), 'SSL');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paystack.tpl')) {
- return $this->load->view($this->config->get('config_template') . '/template/payment/paystack.tpl', $data);
- } else {
- return $this->load->view('payment/paystack.tpl', $data);
-
- }
- }
- }
-
- private function query_api_transaction_verify($reference)
- {
- if ($this->config->get('paystack_live')) {
- $skey = $this->config->get('paystack_live_secret');
- } else {
- $skey = $this->config->get('paystack_test_secret');
- }
-
- $context = stream_context_create(array(
- 'http'=>array(
- 'method'=>"GET",
- 'header'=>"Authorization: Bearer " . $skey,
- )
- )
- );
- $url = 'https://api.paystack.co/transaction/verify/'. rawurlencode($reference);
- $request = file_get_contents($url, false, $context);
- return json_decode($request, true);
- }
- // protected function query_api_transaction_verify($reference)
- // {
- // $url = 'https://api.paystack.co/transaction/verify/' . urlencode($reference);
- // $data = array();
-
- // if ($this->config->get('paystack_live')) {
- // $skey = $this->config->get('paystack_live_secret');
- // } else {
- // $skey = $this->config->get('paystack_test_secret');
- // }
-
- // //open connection
- // $ch = curl_init();
-
- // //set the url, and the header
- // curl_setopt($ch, CURLOPT_URL, $url);
- // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- // // Paystack's servers require TLSv1.2
- // // Force CURL to use this
- // if (!defined('CURL_SSLVERSION_TLSV1_2')) {
- // define('CURL_SSLVERSION_TLSV1_2', 6);
- // }
- // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSV1_2);
-
- // curl_setopt(
- // $ch, CURLOPT_HTTPHEADER, [
- // 'Authorization: Bearer ' . $skey]
- // );
-
- // //execute post
- // $result = curl_exec($ch);
-
- // //close connection
- // curl_close($ch);
-
- // if ($result) {
- // $data = json_decode($result, true);
- // }
-
- // return $data;
- // }
-
- private function redir_and_die($url, $onlymeta = false)
- {
- if (!headers_sent() && !$onlymeta) {
- header('Location: ' . $url);
- }
- echo "";
- die();
- }
-
- public function callback()
- {
- if (isset($this->request->get['trxref'])) {
- $trxref = $this->request->get['trxref'];
-
- // order id is what comes before the first dash in trxref
- $order_id = substr($trxref, 0, strpos($trxref, '-'));
- // if no dash were in transation reference, we will have an empty order_id
- if(!$order_id) {
- $order_id = 0;
- }
-
- $this->load->model('checkout/order');
-
- $order_info = $this->model_checkout_order->getOrder($order_id);
-
-
-
- if ($order_info) {
- if ($this->config->get('paystack_debug')) {
- $this->log->write('PAYSTACK :: CALLBACK DATA: ' . print_r($this->request->get, true));
- }
-
- // Callback paystack to get real transaction status
- $ps_api_response = $this->query_api_transaction_verify($trxref);
-
- $order_status_id = $this->config->get('config_order_status_id');
-
- if (array_key_exists('data', $ps_api_response) && array_key_exists('status', $ps_api_response['data']) && ($ps_api_response['data']['status'] === 'success')) {
- $order_status_id = $this->config->get('paystack_approved_status_id');
- $redir_url = $this->url->link('checkout/success');
- } else if (array_key_exists('data', $ps_api_response) && array_key_exists('status', $ps_api_response['data']) && ($ps_api_response['data']['status'] === 'failure')) {
- $order_status_id = $this->config->get('paystack_declined_status_id');
- $redir_url = $this->url->link('checkout/checkout', '', 'SSL');
- } else {
- $order_status_id = $this->config->get('paystack_error_status_id');
- $redir_url = $this->url->link('checkout/checkout', '', 'SSL');
- }
-
- $this->model_checkout_order->addOrderHistory($order_id, $order_status_id);
- $this->redir_and_die($redir_url);
- }
-
- }
-
-
- }
-}
+language->load('extension/payment/paystack');
+
+ $data['text_testmode'] = $this->language->get('text_testmode');
+ $data['button_confirm'] = $this->language->get('button_confirm');
+
+ $data['livemode'] = $this->config->get('paystack_live');
+
+ if ($this->config->get('paystack_live')) {
+ $data['key'] = $this->config->get('paystack_live_public');
+ } else {
+ $data['key'] = $this->config->get('paystack_test_public');
+ }
+
+ $this->load->model('checkout/order');
+
+ $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
+
+ if ($order_info) {
+
+ $data['ref'] = uniqid('' . $this->session->data['order_id'] . '-');
+ $data['amount'] = intval($order_info['total'] * 100);
+ $data['email'] = $order_info['email'];
+ $data['currency'] = $order_info['currency_code'];
+ $data['callback'] = $this->url->link('extension/payment/paystack/callback', 'trxref=' . rawurlencode($data['ref']), 'SSL');
+
+ if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paystack.tpl')) {
+ return $this->load->view($this->config->get('config_template') . '/template/payment/paystack.tpl', $data);
+ } else {
+ return $this->load->view('payment/paystack.tpl', $data);
+
+ }
+ }
+ }
+
+ private function query_api_transaction_verify($reference)
+ {
+ if ($this->config->get('paystack_live')) {
+ $skey = $this->config->get('paystack_live_secret');
+ } else {
+ $skey = $this->config->get('paystack_test_secret');
+ }
+
+ $context = stream_context_create(
+ array(
+ 'http'=>array(
+ 'method'=>"GET",
+ 'header'=>"Authorization: Bearer " . $skey,
+ )
+ )
+ );
+ $url = 'https://api.paystack.co/transaction/verify/'. rawurlencode($reference);
+ $request = file_get_contents($url, false, $context);
+ return json_decode($request, true);
+ }
+
+ private function redir_and_die($url, $onlymeta = false)
+ {
+ if (!headers_sent() && !$onlymeta) {
+ header('Location: ' . $url);
+ }
+ echo "";
+ die();
+ }
+
+ public function callback()
+ {
+ if (isset($this->request->get['trxref'])) {
+ $trxref = $this->request->get['trxref'];
+
+ // order id is what comes before the first dash in trxref
+ $order_id = substr($trxref, 0, strpos($trxref, '-'));
+ // if no dash were in transation reference, we will have an empty order_id
+ if (!$order_id) {
+ $order_id = 0;
+ }
+
+ $this->load->model('checkout/order');
+
+ $order_info = $this->model_checkout_order->getOrder($order_id);
+
+
+
+ if ($order_info) {
+ if ($this->config->get('paystack_debug')) {
+ $this->log->write('PAYSTACK :: CALLBACK DATA: ' . print_r($this->request->get, true));
+ }
+
+ // Callback paystack to get real transaction status
+ $ps_api_response = $this->query_api_transaction_verify($trxref);
+
+ $order_status_id = $this->config->get('config_order_status_id');
+
+ if (array_key_exists('data', $ps_api_response) && array_key_exists('status', $ps_api_response['data']) && ($ps_api_response['data']['status'] === 'success')) {
+ $order_status_id = $this->config->get('paystack_approved_status_id');
+ $redir_url = $this->url->link('checkout/success');
+ } else if (array_key_exists('data', $ps_api_response) && array_key_exists('status', $ps_api_response['data']) && ($ps_api_response['data']['status'] === 'failure')) {
+ $order_status_id = $this->config->get('paystack_declined_status_id');
+ $redir_url = $this->url->link('checkout/checkout', '', 'SSL');
+ } else {
+ $order_status_id = $this->config->get('paystack_error_status_id');
+ $redir_url = $this->url->link('checkout/checkout', '', 'SSL');
+ }
+
+ $this->model_checkout_order->addOrderHistory($order_id, $order_status_id);
+ $this->redir_and_die($redir_url);
+ }
+
+ }
+
+
+ }
+}
diff --git a/2.3.x/upload/catalog/model/payment/paystack.php b/2.3.x/upload/catalog/model/payment/paystack.php
index f7d1999..080848d 100755
--- a/2.3.x/upload/catalog/model/payment/paystack.php
+++ b/2.3.x/upload/catalog/model/payment/paystack.php
@@ -24,9 +24,16 @@ public function getMethod($address, $total)
$status = false;
}
- // Paystack Only switches NGN for now
- if ($status && (strtoupper($this->config->get('config_currency'))!=='NGN')) {
- $status = false;
+ // Paystack only switches NGN, GHS and USD for now
+ if ($status && (!in_array(
+ strtoupper($this->config->get('config_currency')),
+ [
+ 'NGN',
+ 'GHS'
+ ]
+ ))
+ ) {
+ $status = true;
}
$method_data = array();
diff --git a/2.3.x/upload/catalog/view/theme/default/template/payment/paystack.tpl b/2.3.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
index c81f38e..fecddf0 100755
--- a/2.3.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
+++ b/2.3.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
@@ -16,6 +16,7 @@
key: '',
email: '',
amount: ,
+ currency: '',
ref: '',
callback: function(response){
window.location.href='';
diff --git a/2.x/upload/catalog/controller/payment/paystack.php b/2.x/upload/catalog/controller/payment/paystack.php
index b293a1c..780e5bc 100755
--- a/2.x/upload/catalog/controller/payment/paystack.php
+++ b/2.x/upload/catalog/controller/payment/paystack.php
@@ -25,6 +25,7 @@ public function index()
$data['ref'] = uniqid('' . $this->session->data['order_id'] . '-');
$data['amount'] = intval($order_info['total'] * 100);
$data['email'] = $order_info['email'];
+ $data['currency'] = $order_info['currency_code'];
$data['callback'] = $this->url->link('payment/paystack/callback', 'trxref=' . rawurlencode($data['ref']), 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paystack.tpl')) {
@@ -43,59 +44,19 @@ private function query_api_transaction_verify($reference)
$skey = $this->config->get('paystack_test_secret');
}
- $context = stream_context_create(array(
- 'http'=>array(
- 'method'=>"GET",
- 'header'=>"Authorization: Bearer " . $skey,
+ $context = stream_context_create(
+ array(
+ 'http'=>array(
+ 'method'=>"GET",
+ 'header'=>"Authorization: Bearer " . $skey,
+ )
)
- )
);
$url = 'https://api.paystack.co/transaction/verify/'. rawurlencode($reference);
$request = file_get_contents($url, false, $context);
return json_decode($request, true);
}
- // protected function query_api_transaction_verify($reference)
- // {
- // $url = 'https://api.paystack.co/transaction/verify/' . urlencode($reference);
- // $data = array();
-
- // if ($this->config->get('paystack_live')) {
- // $skey = $this->config->get('paystack_live_secret');
- // } else {
- // $skey = $this->config->get('paystack_test_secret');
- // }
-
- // //open connection
- // $ch = curl_init();
-
- // //set the url, and the header
- // curl_setopt($ch, CURLOPT_URL, $url);
- // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- // // Paystack's servers require TLSv1.2
- // // Force CURL to use this
- // if (!defined('CURL_SSLVERSION_TLSV1_2')) {
- // define('CURL_SSLVERSION_TLSV1_2', 6);
- // }
- // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSV1_2);
-
- // curl_setopt(
- // $ch, CURLOPT_HTTPHEADER, [
- // 'Authorization: Bearer ' . $skey]
- // );
-
- // //execute post
- // $result = curl_exec($ch);
-
- // //close connection
- // curl_close($ch);
-
- // if ($result) {
- // $data = json_decode($result, true);
- // }
-
- // return $data;
- // }
+
private function redir_and_die($url, $onlymeta = false)
{
if (!headers_sent() && !$onlymeta) {
diff --git a/2.x/upload/catalog/model/payment/paystack.php b/2.x/upload/catalog/model/payment/paystack.php
index 5e2804c..69df53e 100755
--- a/2.x/upload/catalog/model/payment/paystack.php
+++ b/2.x/upload/catalog/model/payment/paystack.php
@@ -24,9 +24,16 @@ public function getMethod($address, $total)
$status = false;
}
- // Paystack Only switches NGN for now
- if ($status && (strtoupper($this->currency->getCode())!=='NGN')) {
- $status = false;
+ // Paystack only switches NGN, GHS and USD for now
+ if ($status && (!in_array(
+ strtoupper($this->currency->getCode()),
+ [
+ 'NGN',
+ 'GHS'
+ ]
+ ))
+ ) {
+ $status = true;
}
$method_data = array();
diff --git a/2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl b/2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
index c81f38e..fecddf0 100755
--- a/2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
+++ b/2.x/upload/catalog/view/theme/default/template/payment/paystack.tpl
@@ -16,6 +16,7 @@
key: '',
email: '',
amount: ,
+ currency: '',
ref: '',
callback: function(response){
window.location.href='';
diff --git a/README.md b/README.md
index 45c9b5d..5a78f32 100644
--- a/README.md
+++ b/README.md
@@ -10,12 +10,12 @@ Install to receive payments for your goods in naira from any Mastercard, Visa or
- OpenSSL v1.0.1 or more recent
## Notes
-- Paystack currently only accepts the following currencies: `NGN`.
+- Paystack currently only accepts the following currencies: `NGN`, `GHS` and `USD`.
- You need to have created an account on [paystack.com](https://dashboard.paystack.co/#/signup).
## Features:
- Paystack payment gateway integration
-- Activates payment module only when cart currency is `NGN`
+- Activates payment module only when cart currency is `NGN`, `GHS` or `USD`.
- Activate payment module only when order total reaches the amount you specified
- Captures call back notification to automatically update order status
- Simply turn on Live Mode to accept live payments.
@@ -30,7 +30,7 @@ Install to receive payments for your goods in naira from any Mastercard, Visa or
5. Configure the module accordingly.
- To get your live and test secret keys, visit [the Paystack Dashboard](https://dashboard.paystack.co/#/settings/developer).
6. Enable Paystack payment gateway on your OpenCart admin.
-7. Add and set NGN as your default store currency.
+7. Add and set NGN, GHS or USD. as your default store currency.
8. Proceed to [Paystack OpenCart Extension](http://www.opencart.com/index.php?route=extension/extension/info&extension_id=25767&filter_search=paystack) to rate our work.
## Other Configuration