Skip to content

Commit

Permalink
Merge pull request #1 from bosunolanrewaju/dev
Browse files Browse the repository at this point in the history
Add go live feature
  • Loading branch information
bosunolanrewaju authored May 15, 2017
2 parents a2db907 + 98f8d53 commit 045d052
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 15 deletions.
61 changes: 53 additions & 8 deletions ravepaymentgateway/controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,34 @@ public function postProcess()
Tools::redirect('index.php?controller=order&step=1');

// Setting data
$message = null;
$currency = $this->context->currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$amount_paid = Tools::getValue('amount');
$message = null;
$currency = $this->context->currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$amount_paid = Tools::getValue('amount');
$payment_currency = Tools::getValue('currency');
$payment_customer = Tools::getValue('customer');
$payment_status = Tools::getValue('status_code');
$payment_status = Tools::getValue('status_code');
$tx_ref = Tools::getValue('tx_ref');
$sec_key = Configuration::get('RAVE_SC_KEY');

$extra_vars = array(
'transaction_id' => Tools::getValue('tx_ref'),
'transaction_id' => $tx_ref,
);

$txn = json_decode( $this->_fetchTransaction($tx_ref, $sec_key) );
$is_successful = !empty($txn->data) && $this->_is_successful($txn->data);

$message = 'New Order Details - <br>'.
'Transaction Ref: ' . $extra_vars['transaction_id'] . ' - <br>'.
'Amount Paid: ' . $amount_paid . ' - <br>'.
'Payment Status: ' . ($payment_status == '00') ? 'successful' : 'failed' . ' - <br>'.
'Payment Status: ' . $is_successful ? 'successful' : 'failed' . ' - <br>'.
'Payment Currency: ' . $payment_currency . ' - <br>'.
'Customer: ' . $payment_customer . ' - <br>';

// Verify payment data
if ('00' === Tools::getValue('status_code')) {

if ( $is_successful ) {

$order_status_id = 'PS_OS_PAYMENT';

if ($amount_paid != $total) {
Expand All @@ -61,15 +69,21 @@ public function postProcess()
$message .= 'Attention: This order have been placed on hold and payment flagged because of incorrect payment amount. Please, look into it. - <br>';
$message .= 'Amount paid: '.$currency->iso_code.' '.$amount_paid.' - <br> Order amount: '.
$currency->iso_code.' '.$total.' - <br> Reference: ' .$extra_vars['transaction_id'];

} elseif ($payment_currency != $currency->iso_code) {

$order_status_id = 'PS_OS_RAVE_PENDING';

$message .= 'Attention: This order has been placed on hold and payment flagged because of incorrect payment currency. Please, look into it. - <br>';
$message .= 'Payment currency: '.$payment_currency.' - <br> Order currency: '.
$currency->iso_code.' - <br> Reference: ' .$extra_vars['transaction_id'];

}

} else {

$order_status_id = 'PS_OS_ERROR';

}

// Validate Order
Expand All @@ -95,4 +109,35 @@ public function postProcess()

Tools::redirect($url);
}

private function _fetchTransaction($txRef, $secretKey) {

$URL = $this->context->cookie->base_url . "flwv3-pug/getpaidx/api/verify";
$data = http_build_query(array(
'tx_ref' => $txRef,
'SECKEY' => $secretKey
));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$output = curl_exec($ch);
$failed = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
return ($failed) ? $error : $output;

}

private function _is_successful($data) {

return $data->flwMeta->chargeResponse === '00' || $data->flwMeta->chargeResponse === '0';

}
}
12 changes: 10 additions & 2 deletions ravepaymentgateway/controllers/hook/displayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,35 @@ public function __construct($module, $file, $path)
$this->module = $module;
$this->context = Context::getContext();
$this->_path = $path;
$this->context->cookie->base_url = 'http://flw-pms-dev.eu-west-1.elasticbeanstalk.com';

}

public function run ()
{
$go_live = Configuration::get('RAVE_GO_LIVE');
$btn_text = Configuration::get('RAVE_PAY_BUTTON_TEXT');

if ( $go_live ) {
$this->context->cookie->base_url = 'https://api.ravepay.co';
}

$currency_order = new Currency($this->context->cart->id_currency);
$customer = new Customer($this->context->cart->id_customer);
$this->context->smarty->assign(array(
'pb_key' => Configuration::get('RAVE_PB_KEY'),
'title' => Configuration::get('RAVE_MODAL_TITLE'),
'desc' => Configuration::get('RAVE_MODAL_DESC'),
'logo' => Configuration::get('RAVE_MODAL_LOGO'),
'btntext' => Configuration::get('RAVE_PAY_BUTTON_TEXT'),
'btntext' => $btntext ? $btntext : 'PAY NOW',
'currency'=> $currency_order->iso_code,
'country' => $this->context->country->iso_code,
'txref' => "PS_" . $this->context->cart->id . '_' . time(),
'amount' => (float)$this->context->cart->getOrderTotal(true, Cart::BOTH),
'customer_email' => $customer->email,
));
$this->context->controller->addCSS($this->_path.'views/css/ravepaymentgateway.css', 'all');
$this->context->controller->addJS('//flw-pms-dev.eu-west-1.elasticbeanstalk.com/flwv3-pug/getpaidx/api/flwpbf-inline.js');
$this->context->controller->addJS($this->context->cookie->base_url . '/flwv3-pug/getpaidx/api/flwpbf-inline.js');
$this->context->controller->addJS($this->_path.'views/js/rave.js');
return $this->module->display($this->file, 'displayPayment.tpl');
}
Expand Down
34 changes: 31 additions & 3 deletions ravepaymentgateway/controllers/hook/getContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ public function __construct($module, $file, $path)
{
$this->file = $file;
$this->module = $module;
$this->context = Context::getContext(); $this->_path = $path;
$this->context = Context::getContext();
$this->_path = $path;
}

public function processConfiguration()
{
if (Tools::isSubmit('ravepaymentgateway_form'))
{
Configuration::updateValue('RAVE_PB_KEY', Tools::getValue('RAVE_PB_KEY'));
Configuration::updateValue('RAVE_SC_KEY', Tools::getValue('RAVE_SC_KEY'));
Configuration::updateValue('RAVE_GO_LIVE', Tools::getValue('RAVE_GO_LIVE'));
Configuration::updateValue('RAVE_MODAL_TITLE', Tools::getValue('RAVE_MODAL_TITLE'));
Configuration::updateValue('RAVE_MODAL_DESC', Tools::getValue('RAVE_MODAL_DESC'));
Configuration::updateValue('RAVE_MODAL_LOGO', Tools::getValue('RAVE_MODAL_LOGO'));
Expand All @@ -28,13 +31,38 @@ public function processConfiguration()

public function renderForm()
{
$golive_option = array(
array(
'id' => 'GO_LIVE',
'name' => $this->module->l('Switch to live account'),
'val' => 1
),
);

$inputs = array(
array(
'name' => 'RAVE_PB_KEY',
'label' => $this->module->l('Pay Button Public Key'),
'desc' => 'Your Pay Button public key',
'type' => 'text'
),
array(
'name' => 'RAVE_SC_KEY',
'label' => $this->module->l('Pay Button Secret Key'),
'desc' => 'Your Pay Button secret key',
'type' => 'text'
),
array(
'name' => 'RAVE',
'label' => $this->module->l('Go Live'),
'desc' => 'Switch to live credentials (Live Public and Secret Key)',
'type' => 'checkbox',
'values'=> array(
'query' => $golive_option ,
'id' => 'id',
'name' => 'name'
)
),
array(
'name' => 'RAVE_MODAL_TITLE',
'label' => $this->module->l('Modal Title'),
Expand Down Expand Up @@ -82,12 +110,12 @@ public function renderForm()
$helper->tpl_vars = array(
'fields_value' => array(
'RAVE_PB_KEY' => Tools::getValue('RAVE_PB_KEY', Configuration::get('RAVE_PB_KEY')),
'RAVE_SC_KEY' => Tools::getValue('RAVE_SC_KEY', Configuration::get('RAVE_SC_KEY')),
'RAVE_GO_LIVE' => Tools::getValue('RAVE_GO_LIVE', Configuration::get('RAVE_GO_LIVE')),
'RAVE_MODAL_TITLE' => Tools::getValue('RAVE_MODAL_TITLE', Configuration::get('RAVE_MODAL_TITLE')),
'RAVE_MODAL_DESC' => Tools::getValue('RAVE_MODAL_DESC', Configuration::get('RAVE_MODAL_DESC')),
'RAVE_MODAL_LOGO' => Tools::getValue('RAVE_MODAL_LOGO', Configuration::get('RAVE_MODAL_LOGO')),
'RAVE_PAY_BUTTON_TEXT' => Tools::getValue('RAVE_PAY_BUTTON_TEXT', Configuration::get('RAVE_PAY_BUTTON_TEXT')),
'MYMOD_API_CRED_ID' => Tools::getValue('MYMOD_API_CRED_ID', Configuration::get('MYMOD_API_CRED_ID')),
'MYMOD_API_CRED_SALT' => Tools::getValue('MYMOD_API_CRED_SALT', Configuration::get('MYMOD_API_CRED_SALT')),
),
'languages' => $this->context->controller->getLanguages()
);
Expand Down
1 change: 0 additions & 1 deletion ravepaymentgateway/views/templates/hook/displayPayment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<button class="rave-pay-now-button pull-right">{$btntext}</button>
</span>
<script type="text/javascript">
console.log("currency: ", "{$currency}");
$('.rave-pay-now-button').click(function() {
var config = {
amount : "{$amount}",
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ With Rave, it is easy and smooth to accept card and bank account payments in you
- **Tags:** prestashop, rave, payment form, payment gateway, bank account, credit card, debit card, nigeria, kenya, international, mastercard, visa
- **Requires at least:** 1.5
- **Tested up to:** 1.6
- **Stable tag:** 0.0.1


## Description
Expand Down

0 comments on commit 045d052

Please sign in to comment.