v1.0.0
This commit is contained in:
Executable
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Opencart\Catalog\Model\Extension\PayAnyWay\Payment;
|
||||
|
||||
class PayAnyWay extends \Opencart\System\Engine\Model
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $address
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getMethods(array $address = []): array
|
||||
{
|
||||
$this->load->language('extension/payanyway/payment/payanyway');
|
||||
|
||||
if (!$this->isModuleEnabled() ||
|
||||
!$this->isCurrencySupported() ||
|
||||
!$this->isGeoZoneValid($address)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => 'payanyway',
|
||||
'name' => $this->language->get('text_title'),
|
||||
'option' => [
|
||||
'payanyway' => [
|
||||
'code' => 'payanyway.payanyway',
|
||||
'name' => $this->language->get('text_title')
|
||||
]
|
||||
],
|
||||
'sort_order' => $this->config->get('payment_payanyway_sort_order'),
|
||||
];
|
||||
}
|
||||
|
||||
private function isModuleEnabled(): bool
|
||||
{
|
||||
return (bool)$this->config->get('payment_payanyway_status');
|
||||
}
|
||||
|
||||
private function isCurrencySupported(): bool
|
||||
{
|
||||
$shopCurrency = $this->session->data['currency'] ?? '';
|
||||
|
||||
return $shopCurrency === $this->config->get('payment_payanyway_currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $address
|
||||
*/
|
||||
private function isGeoZoneValid(array $address): bool
|
||||
{
|
||||
$geoZoneId = (int)$this->config->get('payment_payanyway_geo_zone_id');
|
||||
|
||||
if ($geoZoneId === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone
|
||||
WHERE geo_zone_id = '" . (int)$geoZoneId . "'
|
||||
AND country_id = '" . (int)($address['country_id'] ?? 0) . "'
|
||||
AND (zone_id = '" . (int)($address['zone_id'] ?? 0) . "' OR zone_id = '0')";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->num_rows > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user