Skip to content

Commit

Permalink
fix: bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
artembelfox committed Jan 15, 2024
1 parent 8b57602 commit 5e21d4c
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 184 deletions.
35 changes: 7 additions & 28 deletions admin/model/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ public function install(): void {
PRIMARY KEY (`opayo_order_transaction_id`),
KEY (`opayo_order_id`)
) ENGINE=MyISAM DEFAULT COLLATE=utf8_general_ci;");

$this->db->query("
CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "opayo_order_subscription` (
`opayo_order_subscription_id` INT(11) NOT NULL AUTO_INCREMENT,
`order_id` INT(11) NOT NULL,
`subscription_id` INT(11) NOT NULL,
`VPSTxId` VARCHAR(50),
`VendorTxCode` VARCHAR(50) NOT NULL,
`SecurityKey` CHAR(50) NOT NULL,
`TxAuthNo` INT(50),
`date_added` DATETIME NOT NULL,
`date_modified` DATETIME NOT NULL,
`next_payment` DATETIME NOT NULL,
`trial_end` DATETIME DEFAULT NULL,
`subscription_end` DATETIME DEFAULT NULL,
`currency_code` CHAR(3) NOT NULL,
`total` DECIMAL( 10, 2 ) NOT NULL,
PRIMARY KEY (`opayo_order_subscription_id`),
KEY (`order_id`)
) ENGINE=MyISAM DEFAULT COLLATE=utf8_general_ci;");

$this->db->query("
CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "opayo_card` (
Expand All @@ -72,7 +52,6 @@ public function install(): void {
public function uninstall(): void {
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "opayo_order`;");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "opayo_order_transaction`;");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "opayo_order_subscription`;");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "opayo_card`;");
}

Expand Down Expand Up @@ -268,13 +247,13 @@ public function sendCurl(string $url, array $payment_data): array {
$response_info = explode(chr(10), $response);

foreach ($response_info as $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]);
if (strpos($string, '=') === false) {
continue;
}

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

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

return $data;
Expand All @@ -292,7 +271,7 @@ public function log(string $title, array|string $data): void {
if ($setting['general']['debug']) {
$log = new \Opencart\System\Library\Log('opayo.log');

$log->write($title . ': ' . print_r($data, 1));
$log->write($title . ': ' . print_r($data, true));
}
}
}
2 changes: 1 addition & 1 deletion admin/view/template/payment/opayo.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="card">
<div class="card-header"><i class="fas fa-pencil-alt"></i> {{ text_edit }}</div>
<div class="card-body">
<form action="{{ save }}" method="post" enctype="multipart/form-data" id="form-payment" data-oc-toggle="ajax">
<form action="{{ save }}" method="post" id="form-payment" data-oc-toggle="ajax">
<ul class="nav nav-tabs">
<li class="nav-item"><a href="#tab-general" data-bs-toggle="tab" class="nav-link active">{{ text_tab_general }}</a></li>
<li class="nav-item"><a href="#tab-cron" data-bs-toggle="tab" class="nav-link">{{ text_tab_cron }}</a></li>
Expand Down
16 changes: 8 additions & 8 deletions catalog/controller/payment/opayo.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function confirm(): void {
$payment_data['BillingCountry'] = $order_info['payment_iso_code_2'];

if ($order_info['payment_iso_code_2'] == 'US') {
$payment_data['BillingState'] = $order_info['payment_zone_code'];
$payment_data['BillingState'] = $order_info['payment_zone'];
}

$payment_data['BillingPhone'] = substr($order_info['telephone'], 0, 20);
Expand All @@ -158,7 +158,7 @@ public function confirm(): void {
$payment_data['DeliveryCountry'] = $order_info['shipping_iso_code_2'];

if ($order_info['shipping_iso_code_2'] == 'US') {
$payment_data['DeliveryState'] = $order_info['shipping_zone_code'];
$payment_data['DeliveryState'] = $order_info['shipping_zone'];
}

$payment_data['CustomerName'] = substr($order_info['firstname'] . ' ' . $order_info['lastname'], 0, 100);
Expand All @@ -177,7 +177,7 @@ public function confirm(): void {
$payment_data['DeliveryCountry'] = $order_info['payment_iso_code_2'];

if ($order_info['payment_iso_code_2'] == 'US') {
$payment_data['DeliveryState'] = $order_info['payment_zone_code'];
$payment_data['DeliveryState'] = $order_info['payment_zone'];
}

$payment_data['DeliveryPhone'] = $order_info['telephone'];
Expand Down Expand Up @@ -333,12 +333,12 @@ public function confirm(): void {
$this->model_checkout_order->addHistory($this->session->data['order_id'], $setting['general']['order_status_id'], $message, false);

if ($setting['general']['transaction_method'] == 'PAYMENT') {
$subscriptions = $this->cart->getSubscription();

$subscriptions = $this->model_extension_opayo_payment_opayo->getSubscriptionsByOrderId($order_info['order_id']);
//loop through any products that are subscription items
foreach ($subscriptions as $item) {
$this->model_extension_opayo_payment_opayo->subscriptionPayment($item, $payment_data['VendorTxCode']);
}
}
}

$json['redirect'] = $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'));
Expand Down Expand Up @@ -431,12 +431,12 @@ public function threeDSnotify(): void {
}

if ($setting['general']['transaction_method'] == 'PAYMENT') {
$subscriptions = $this->cart->getSubscription();
$subscriptions = $this->model_extension_opayo_payment_opayo->getSubscriptionsByOrderId($this->request->get['order_id']);

//loop through any products that are subscription items
foreach ($subscriptions as $item) {
$this->model_extension_opayo_payment_opayo->subscriptionPayment($item, $payment_data['VendorTxCode']);
}
}
}

$this->response->redirect($this->url->link('checkout/success', 'language=' . $this->config->get('config_language')));
Expand Down
Loading

0 comments on commit 5e21d4c

Please sign in to comment.