Skip to content

Commit

Permalink
https://github.com/abantecart/abantecart-src/issues/1172
Browse files Browse the repository at this point in the history
  • Loading branch information
abolabo committed Nov 21, 2018
1 parent 886f64f commit 71ac4e5
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 11 deletions.
49 changes: 49 additions & 0 deletions public_html/extensions/2checkout/core/hooks.php
@@ -0,0 +1,49 @@
<?php
/*------------------------------------------------------------------------------
$Id$
AbanteCart, Ideal OpenSource Ecommerce Solution
http://www.AbanteCart.com
Copyright © 2011-2018 Belavier Commerce LLC
This source file is subject to Open Software License (OSL 3.0)
Licence details is bundled with this package in the file LICENSE.txt.
It is also available at this URL:
<http://www.opensource.org/licenses/OSL-3.0>
UPGRADE NOTE:
Do not edit or add to this file if you wish to upgrade AbanteCart to newer
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/


class Extension2Checkout extends Extension
{
//payment confirmation pending page
public function onControllerPagesCheckoutSuccess_InitData()
{
$that = $this->baseObject;
$order_id = (int)$that->session->data['order_id'];
if (!$order_id || $that->session->data['2checkout_pending_ipn_skip']) {
return null;
}
$that->loadModel('checkout/order');
$order_info = $that->model_checkout_order->getOrder($order_id);
//do nothing if order confirmed or it's not created with paypal standart
if ((int)$order_info['order_status_id'] != 0 || $order_info['payment_method_key'] != '2checkout') {
return null;
}
//set sign to prevent double redirect (see above)
$that->session->data['2checkout_pending_ipn_skip'] = true;
redirect($that->html->getSecureURL('extension/2checkout/pending_payment'));
}

//delete sign after success
public function onControllerPagesCheckoutSuccess_UpdateData()
{
unset($this->baseObject->session->data['2checkout_pending_ipn_skip']);
}

}
8 changes: 3 additions & 5 deletions public_html/extensions/2checkout/main.php
Expand Up @@ -8,7 +8,7 @@
Copyright © 2011-2018 Belavier Commerce LLC
This source file is subject to Open Software License (OSL 3.0)
Lincence details is bundled with this package in the file LICENSE.txt.
Licence details is bundled with this package in the file LICENSE.txt.
It is also available at this URL:
<http://www.opensource.org/licenses/OSL-3.0>
Expand All @@ -17,10 +17,7 @@
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/
if (!defined('DIR_CORE')) {
header('Location: static_pages/');
}

require_once(__DIR__.DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'hooks.php');
$controllers = array(
'storefront' => array('responses/extension/2checkout'),
'admin' => array(),
Expand All @@ -43,6 +40,7 @@
$templates = array(
'storefront' => array(
'responses/2checkout.tpl',
'responses/pending_ipn.tpl'
),
'admin' => array(),
);
Expand Up @@ -88,7 +88,12 @@ public function main()
'name' => $product['name'],
'description' => $product['name'],
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'], $order_info['currency'], $order_info['value'], false),
'price' => $this->currency->format(
$product['price'],
$order_info['currency'],
$order_info['value'],
false
),
);
}

Expand All @@ -115,7 +120,12 @@ public function callback()
}
$post = $this->request->post;
// hash check
if (!md5($post['sale_id'].$this->config->get('2checkout_account').$post['invoice_id'].$this->config->get('2checkout_secret')) == strtolower($post['md5_hash'])) {
if (!md5(
$post['sale_id']
.$this->config->get('2checkout_account')
.$post['invoice_id']
.$this->config->get('2checkout_secret')) == strtolower($post['md5_hash'])
){
exit;
}

Expand All @@ -128,18 +138,68 @@ public function callback()
}
$this->load->model('extension/2checkout');
if ($post['message_type'] == 'ORDER_CREATED') {
$this->model_checkout_order->confirm((int)$post['vendor_order_id'], $this->config->get('2checkout_order_status_id'));
$this->model_checkout_order->confirm(
(int)$post['vendor_order_id'],
$this->config->get('2checkout_order_status_id')
);
} elseif ($post['message_type'] == 'REFUND_ISSUED') {
$order_status_id = $this->model_extension_2checkout->getOrderStatusIdByName('failed');
$this->model_checkout_order->update((int)$post['vendor_order_id'], $order_status_id, 'Status changed by 2Checkout INS');
$this->model_checkout_order->update(
(int)$post['vendor_order_id'],
$order_status_id,
'Status changed by 2Checkout INS'
);
} elseif ($post['message_type'] == 'FRAUD_STATUS_CHANGED' && $post['fraud_status'] == 'pass') {
$order_status_id = $this->model_extension_2checkout->getOrderStatusIdByName('processing');
$this->model_checkout_order->update((int)$post['vendor_order_id'], $order_status_id, 'Status changed by 2Checkout INS');
$this->model_checkout_order->update(
(int)$post['vendor_order_id'],
$order_status_id,
'Status changed by 2Checkout INS'
);
} elseif ($post['message_type'] == 'SHIP_STATUS_CHANGED' && $post['ship_status'] == 'shipped') {
$order_status_id = $this->model_extension_2checkout->getOrderStatusIdByName('complete');
$this->model_checkout_order->update((int)$post['vendor_order_id'], $order_status_id, 'Status changed by 2Checkout INS');
$this->model_checkout_order->update(
(int)$post['vendor_order_id'],
$order_status_id,
'Status changed by 2Checkout INS'
);
} else {
redirect($this->html->getSecureURL('checkout/confirm'));
}
}

public function pending_payment()
{
$this->addChild('common/head', 'head', 'common/head.tpl');
$this->addChild('common/footer', 'footer', 'common/footer.tpl');
$this->document->setTitle('waiting for payment');
$this->view->assign('text_message', 'waiting for payment confirmation');
$this->view->assign('text_redirecting', 'redirecting');
$this->view->assign('test_url', $this->html->getSecureURL('r/extension/2checkout/is_confirmed'));
$this->view->assign('success_url', $this->html->getSecureURL('checkout/success'));
$this->processTemplate('responses/pending_ipn.tpl');
}

public function is_confirmed()
{
$order_id = (int)$this->session->data['order_id'];
if (!$order_id) {
$result = true;
} else {
$this->loadModel('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);
//do nothing if order confirmed or it's not created with paypal standart
if ((int)$order_info['order_status_id'] != 0
|| $order_info['payment_method_key'] != '2checkout'
) {
$result = true;
} else {
$result = false;
}
}

$this->load->library('json');
$this->response->addJSONHeader();
$this->response->setOutput(AJson::encode(array('result' => $result)));
}
}
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>" xml:lang="<?php echo $lang; ?>" <?php echo $this->getHookVar('hk_html_attribute'); ?>>
<head><?php echo $head; ?></head>
<body>
<div class="container-fixed">
<div class="contentpanel" style="margin-top: 5%">
<h3 class=" col-sm-5 col-sm-offset-4"><i class="fa fa-spinner fa-pulse"></i> <?php echo $text_message; ?></h3>
</div>
</div>
<script type="text/javascript" src="<?php echo $this->templateResource('/javascript/bootstrap.min.js'); ?>" defer></script>
<script language="JavaScript" type="application/javascript">
var timeout = 30;
(function worker() {
if(timeout <=0){
location = '<?php echo $success_url;?>';
return;
}
timeout -=5;
$.ajax({
url: '<?php echo $test_url;?>',
success: function (data) {
console.log(data);
if(data['result'] == true) {
$('h3').html('..redirecting');
location = '<?php echo $success_url;?>';
return false;
}
},
complete: function () {
// Schedule the next request when the current one's complete
setTimeout(worker, 5000);
}
});
})();
</script>
</body></html>

0 comments on commit 71ac4e5

Please sign in to comment.