Skip to content

Commit

Permalink
feat: support 4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
artembelfox committed May 29, 2023
1 parent 66df978 commit 0f7952b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
19 changes: 16 additions & 3 deletions admin/controller/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
namespace Opencart\Admin\Controller\Extension\Opayo\Payment;
class Opayo extends \Opencart\System\Engine\Controller {
private $error = [];
private $separator = '';

public function __construct($registry) {
parent::__construct($registry);

if (VERSION >= '4.0.2.0') {
$this->separator = '.';
} else {
$this->separator = '|';
}
}

public function index(): void {
$this->load->language('extension/opayo/payment/opayo');
Expand All @@ -25,7 +36,7 @@ public function index(): void {
'href' => $this->url->link('extension/opayo/payment/opayo', 'user_token=' . $this->session->data['user_token'])
];

$data['save'] = $this->url->link('extension/opayo/payment/opayo|save', 'user_token=' . $this->session->data['user_token']);
$data['save'] = $this->url->link('extension/opayo/payment/opayo' . $this->separator . 'save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment');

$server = HTTP_SERVER;
Expand Down Expand Up @@ -60,7 +71,7 @@ public function index(): void {
}

if (!$data['setting']['cron']['url']) {
$data['setting']['cron']['url'] = $catalog . 'index.php?route=extension/opayo/payment|cron&token=' . $data['setting']['cron']['token'];
$data['setting']['cron']['url'] = $catalog . 'index.php?route=extension/opayo/payment' . $this->separator . 'cron&token=' . $data['setting']['cron']['token'];
}

$data['header'] = $this->load->controller('common/header');
Expand Down Expand Up @@ -120,8 +131,10 @@ public function order(): string {
$data['order_id'] = $this->request->get['order_id'];

$data['user_token'] = $this->request->get['user_token'];

$data['separator'] = $this->separator;

return $this->load->view('extension/opayo/payment/opayo_order', $data);
return $this->load->view('extension/opayo/payment/order', $data);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions admin/view/template/payment/order.twig
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ $('#button-void').click(function() {
type: 'POST',
dataType: 'json',
data: {'order_id': {{ order_id }}},
url: 'index.php?route=extension/opayo/payment/opayo|void&user_token={{ user_token }}',
url: 'index.php?route=extension/opayo/payment/opayo{{ separator }}void&user_token={{ user_token }}',
beforeSend: function() {
$('#button-void').hide();
$('#img-loading-void').show();
Expand Down Expand Up @@ -145,7 +145,7 @@ $('#button-release').click(function() {
type: 'POST',
dataType: 'json',
data: {'order_id': {{ order_id }}, 'amount': $('#release-amount').val()},
url: 'index.php?route=extension/opayo/payment/opayo|release&user_token={{ user_token }}',
url: 'index.php?route=extension/opayo/payment/opayo{{ separator }}release&user_token={{ user_token }}',
beforeSend: function() {
$('#button-release').hide();
$('#release-amount').hide();
Expand Down Expand Up @@ -206,7 +206,7 @@ $('#button-rebate').click(function() {
type: 'POST',
dataType: 'json',
data: {'order_id': {{ order_id }}, 'amount': $('#rebate-amount').val()},
url: 'index.php?route=extension/opayo/payment/opayo|rebate&user_token={{ user_token }}',
url: 'index.php?route=extension/opayo/payment/opayo{{ separator }}rebate&user_token={{ user_token }}',
beforeSend: function() {
$('#button-rebate').hide();
$('#rebate-amount').hide();
Expand Down
18 changes: 16 additions & 2 deletions catalog/controller/payment/opayo.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?php
namespace Opencart\Catalog\Controller\Extension\Opayo\Payment;
class Opayo extends \Opencart\System\Engine\Controller {
private $separator = '';

public function __construct($registry) {
parent::__construct($registry);

if (VERSION >= '4.0.2.0') {
$this->separator = '.';
} else {
$this->separator = '|';
}
}

public function index(): string {
if ($this->config->get('payment_opayo_vendor')) {
Expand Down Expand Up @@ -48,6 +59,8 @@ public function index(): string {
);
}

$data['separator'] = $this->separator;

$data['language'] = $this->config->get('config_language');

return $this->load->view('extension/opayo/payment/opayo', $data);
Expand Down Expand Up @@ -201,8 +214,9 @@ public function confirm(): void {
$payment_data['ClientIPAddress'] = $this->request->server['REMOTE_ADDR'];
$payment_data['ChallengeWindowSize'] = '01';
$payment_data['Apply3DSecure'] = '0';
$payment_data['ThreeDSNotificationURL'] = str_replace('&amp;', '&', $this->url->link('extension/opayo/payment/opayo|threeDSnotify', 'order_id=' . $this->session->data['order_id'] . '&language=' . $this->config->get('config_language')));

$payment_data['ThreeDSNotificationURL'] = str_replace('&amp;', '&', $this->url->link('extension/opayo/payment/opayo' . $this->separator . 'threeDSnotify', 'order_id=' . $this->session->data['order_id'] . '&language=' . $this->config->get('config_language')));

$payment_data['InitiatedType'] = 'CIT';

$browser_languages = explode(',', $this->request->server['HTTP_ACCEPT_LANGUAGE']);
Expand Down Expand Up @@ -257,7 +271,7 @@ public function confirm(): void {
$this->model_extension_opayo_payment_opayo->log('Payment data', $payment_data);
$this->model_extension_opayo_payment_opayo->log('Order Id', $this->session->data['order_id']);

$json['TermUrl'] = str_replace('&amp;', '&', $this->url->link('extension/opayo/payment/opayo|threeDSnotify', 'order_id=' . $this->session->data['order_id'] . '&language=' . $this->config->get('config_language'), true));
$json['TermUrl'] = str_replace('&amp;', '&', $this->url->link('extension/opayo/payment/opayo' . $this->separator . 'threeDSnotify', 'order_id=' . $this->session->data['order_id'] . '&language=' . $this->config->get('config_language'), true));
} elseif ($response_data['Status'] == 'OK' || $response_data['Status'] == 'AUTHENTICATED' || $response_data['Status'] == 'REGISTERED') {
$message = '';

Expand Down
34 changes: 34 additions & 0 deletions catalog/model/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,40 @@ public function getMethod(array $address): array {
return $method_data;
}

public function getMethods(array $address = []): array {
$this->load->language('extension/opayo/payment/opayo');

if (!$this->config->get('config_checkout_payment_address')) {
$status = true;
} elseif (!$this->config->get('payment_opayo_geo_zone_id')) {
$status = true;
} else {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('payment_opayo_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");

if ($query->num_rows) {
$status = true;
} else {
$status = false;
}
}

if ($status) {
$option_data['opayo'] = [
'code' => 'opayo.opayo',
'name' => $this->language->get('text_title')
];

$method_data = [
'code' => 'opayo',
'name' => $this->language->get('text_title'),
'option' => $option_data,
'sort_order' => $this->config->get('payment_opayo_sort_orderr')
];
}

return $method_data;
}

public function getCards(int $customer_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "opayo_card` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `card_id`");

Expand Down
6 changes: 3 additions & 3 deletions catalog/view/template/payment/opayo.twig
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function updateOpayo() {
$('#opayo-form #opayo-button-delete-card').on('click', function () {
if (confirm('{{ text_confirm_delete }}')) {
$.ajax({
url: 'index.php?route=extension/opayo/payment/opayo|deleteCard&language={{ language }}',
url: 'index.php?route=extension/opayo/payment/opayo{{ separator }}deleteCard&language={{ language }}',
type: 'post',
data: $('#opayo-card-existing :input[name=\'opayo_card_token\']'),
dataType: 'json',
Expand All @@ -131,7 +131,7 @@ function updateOpayo() {
}
if (json['success']) {
$('#opayo-form').load('index.php?route=extension/opayo/payment/opayo|getForm&language={{ language }} #opayo-form >', function() {
$('#opayo-form').load('index.php?route=extension/opayo/payment/opayo{{ separator }}getForm&language={{ language }} #opayo-form >', function() {
updateOpayo();
});
}
Expand All @@ -154,7 +154,7 @@ function updateOpayo() {
$.ajax({
type: 'post',
url: 'index.php?route=extension/opayo/payment/opayo|confirm&language={{ language }}',
url: 'index.php?route=extension/opayo/payment/opayo{{ separator }}confirm&language={{ language }}',
data: $('#opayo-form input[type="radio"]:checked, #opayo-form input[type="checkbox"]:checked, #opayo-form input[type="text"], #opayo-form input[type="hidden"], #opayo-form select'),
dataType: 'json',
cache: false,
Expand Down

0 comments on commit 0f7952b

Please sign in to comment.