Skip to content

Commit

Permalink
Bugfixes for Opayo and Geo Zones
Browse files Browse the repository at this point in the history
Merging latest Opayo payment extension updates from Dreamvention, with additional bugfixes.

Fixed performance issues for editing geo zones in admin backend.
  • Loading branch information
mhcwebdesign committed Feb 9, 2024
1 parent bad5aa3 commit 0f42fb6
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 183 deletions.
68 changes: 68 additions & 0 deletions upload/admin/controller/extension/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,74 @@ public function rebate() {
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}

public function recurringButtons() {
$content = '';

if (!empty($this->request->get['order_recurring_id'])) {
$this->load->language('extension/payment/opayo');

$this->load->model('sale/recurring');

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

$order_recurring_info = $this->model_sale_recurring->getRecurring($data['order_recurring_id']);

if ($order_recurring_info) {
$data['recurring_status'] = $order_recurring_info['status'];

$data['info_url'] = str_replace('&', '&', $this->url->link('extension/payment/opayo/getRecurringInfo', 'user_token=' . $this->session->data['user_token'] . '&order_recurring_id=' . $data['order_recurring_id'], true));
$data['enable_url'] = str_replace('&', '&', $this->url->link('extension/payment/opayo/enableRecurring', 'user_token=' . $this->session->data['user_token'], true));
$data['disable_url'] = str_replace('&', '&', $this->url->link('extension/payment/opayo/disableRecurring', 'user_token=' . $this->session->data['user_token'], true));

$content = $this->load->view('extension/payment/opayo/recurring', $data);
}
}

return $content;
}

public function getRecurringInfo() {
$this->response->setOutput($this->recurringButtons());
}

public function enableRecurring() {
if (!empty($this->request->post['order_recurring_id'])) {
$this->load->language('extension/payment/opayo');

$this->load->model('extension/payment/opayo');

$order_recurring_id = $this->request->post['order_recurring_id'];

$this->model_extension_payment_opayo->editRecurringStatus($order_recurring_id, 1);

$data['success'] = $this->language->get('success_enable_recurring');
}

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

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($data));
}

public function disableRecurring() {
if (!empty($this->request->post['order_recurring_id'])) {
$this->load->language('extension/payment/opayo');

$this->load->model('extension/payment/opayo');

$order_recurring_id = $this->request->post['order_recurring_id'];

$this->model_extension_payment_opayo->editRecurringStatus($order_recurring_id, 2);

$data['success'] = $this->language->get('success_disable_recurring');
}

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

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($data));
}

private function validate() {
if (!$this->user->hasPermission('modify', 'extension/payment/opayo')) {
Expand Down
8 changes: 8 additions & 0 deletions upload/admin/controller/localisation/geo_zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ protected function getForm() {
$data['zone_to_geo_zones'] = array();
}

$geo_zone_ids = array();
foreach ($data['zone_to_geo_zones'] as $zone_to_geo_zone) {
if (!in_array($zone_to_geo_zone['geo_zone_id'],$geo_zone_ids)) {
$geo_zone_ids[] = $zone_to_geo_zone['geo_zone_id'];
}
}
$data['zones'] = $this->model_localisation_geo_zone->getZonesByGeoZones($geo_zone_ids);

$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
Expand Down
16 changes: 10 additions & 6 deletions upload/admin/language/en-gb/extension/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,20 @@
$_['button_release'] = 'Release';
$_['button_rebate'] = 'Rebate / refund';
$_['button_void'] = 'Void';
$_['button_enable_recurring'] = 'Enable Recurring';
$_['button_disable_recurring'] = 'Disable Recurring';

// Success
$_['success_save'] = 'Success: You have modified Opayo!';
$_['success_release_ok'] = 'Release was successful';
$_['success_release_ok_order'] = 'Release was successful, order status updated to success - settled';
$_['success_rebate_ok'] = 'Rebate was successful';
$_['success_rebate_ok_order'] = 'Rebate was successful, order status updated to rebated';
$_['success_void_ok'] = 'Void was successful, order status updated to voided';
$_['success_release_ok'] = 'Success: Release was successful!';
$_['success_release_ok_order'] = 'Success: Release was successful, order status updated to success - settled!';
$_['success_rebate_ok'] = 'Success: Rebate was successful!';
$_['success_rebate_ok_order'] = 'Success: Rebate was successful, order status updated to rebated!';
$_['success_void_ok'] = 'Success: Void was successful, order status updated to voided!';
$_['success_enable_recurring'] = 'Success: Recurring payment was enabled!';
$_['success_disable_recurring'] = 'Success: Recurring payment was disabled!';

// Error
$_['error_warning'] = 'Warning: Please check the form carefully for errors!';
$_['error_permission'] = 'Warning: You do not have permission to modify payment Opayo!';
$_['error_vendor'] = 'Vendor ID Required!';
$_['error_vendor'] = 'Vendor ID Required!';
20 changes: 12 additions & 8 deletions upload/admin/model/extension/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ public function getTotalRebated($opayo_order_id) {

return (float)$query->row['total'];
}

public function editRecurringStatus($order_recurring_id, $status) {
$this->db->query("UPDATE `" . DB_PREFIX . "order_recurring` SET `status` = '" . (int)$status . "' WHERE `order_recurring_id` = '" . (int)$order_recurring_id . "'");
}

public function sendCurl($url, $payment_data) {
$curl = curl_init($url);
Expand All @@ -262,14 +266,14 @@ public function sendCurl($url, $payment_data) {

$response_info = explode(chr(10), $response);

foreach ($response_info as $i => $string) {
if (strpos($string, '=') && isset($i)) {
$parts = explode('=', $string, 2);
$data['RepeatResponseData_' . $i][trim($parts[0])] = trim($parts[1]);
} elseif (strpos($string, '=')) {
$parts = explode('=', $string, 2);
$data[trim($parts[0])] = trim($parts[1]);
foreach ($response_info as $string) {
if (strpos($string, '=') === false) {
continue;
}

$parts = explode('=', $string, 2);

$data[trim($parts[0])] = trim($parts[1]);
}

return $data;
Expand All @@ -286,7 +290,7 @@ public function log($title, $data) {
if ($setting['general']['debug']) {
$log = new Log('opayo.log');

$log->write($title . ': ' . print_r($data, 1));
$log->write($title . ': ' . print_r($data, true));
}
}
}
24 changes: 23 additions & 1 deletion upload/admin/model/localisation/geo_zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getTotalGeoZones() {
}

public function getZoneToGeoZones($geo_zone_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$geo_zone_id . "'");
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$geo_zone_id . "' ORDER BY country_id ASC, zone_id ASC");

return $query->rows;
}
Expand All @@ -127,4 +127,26 @@ public function getTotalZoneToGeoZoneByZoneId($zone_id) {

return $query->row['total'];
}

public function getZonesByGeoZones($geo_zone_ids) {
if (empty($geo_zone_ids)) {
return array();
}
$sql = "SELECT DISTINCT zgz.country_id, z.zone_id, c.`name` AS country, z.`name` AS zone ";
$sql .= "FROM `".DB_PREFIX."zone_to_geo_zone` AS zgz ";
$sql .= "LEFT JOIN `".DB_PREFIX."country` c ON c.country_id=zgz.country_id ";
$sql .= "LEFT JOIN `".DB_PREFIX."zone` z ON z.country_id=c.country_id ";
$sql .= "WHERE zgz.geo_zone_id IN (".implode($geo_zone_ids).") ";
$sql .= "ORDER BY country_id ASC, zone ASC;";
$query = $this->db->query( $sql );
$results = array();
foreach ($query->rows as $row) {
$country_id = $row['country_id'];
if (!isset($results[$country_id])) {
$results[$country_id] = array();
}
$results[$country_id][$row['zone_id']] = $row['zone'];
}
return $results;
}
}
13 changes: 10 additions & 3 deletions upload/admin/view/template/localisation/geo_zone_form.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{% set zone_to_geo_zone_row = 0 %}
{% for zone_to_geo_zone in zone_to_geo_zones %}
<tr id="zone-to-geo-zone-row{{ zone_to_geo_zone_row }}">
<td class="text-left"><select name="zone_to_geo_zone[{{ zone_to_geo_zone_row }}][country_id]" class="form-control" data-index="{{ zone_to_geo_zone_row }}" data-zone-id="{{ zone_to_geo_zone.zone_id }}" disabled="disabled">
<td class="text-left"><select name="zone_to_geo_zone[{{ zone_to_geo_zone_row }}][country_id]" class="form-control" data-index="{{ zone_to_geo_zone_row }}" data-zone-id="{{ zone_to_geo_zone.zone_id }}">
{% for country in countries %}
{% if country.country_id == zone_to_geo_zone.country_id %}
<option value="{{ country.country_id }}" selected="selected">{{ country.name }}</option>
Expand All @@ -64,7 +64,15 @@
{% endif %}
{% endfor %}
</select></td>
<td class="text-left"><select name="zone_to_geo_zone[{{ zone_to_geo_zone_row }}][zone_id]" class="form-control" disabled="disabled">
<td class="text-left"><select name="zone_to_geo_zone[{{ zone_to_geo_zone_row }}][zone_id]" class="form-control">
<option value="0">{{ text_all_zones }}</option>
{% for zone_id,zone in zones[zone_to_geo_zone.country_id] %}
{% if zone_id == zone_to_geo_zone.zone_id %}
<option value="{{ zone_id }}" selected="selected">{{ zone }}</option>
{% else %}
<option value="{{ zone_id }}">{{ zone }}</option>
{% endif %}
{% endfor %}
</select></td>
<td class="text-left"><button type="button" onclick="$('#zone-to-geo-zone-row{{ zone_to_geo_zone_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
</tr>
Expand Down Expand Up @@ -149,6 +157,5 @@ $('#zone-to-geo-zone').on('change', 'select[name$=\'[country_id]\']', function()
}
});
$('select[name$=\'[country_id]\']:disabled:first').trigger('change');
//--></script></div>
{{ footer }}
Loading

0 comments on commit 0f42fb6

Please sign in to comment.