From 714ed5868a33b9c92e9613ff83558687f47838e4 Mon Sep 17 00:00:00 2001 From: belikov_artem Date: Thu, 10 Aug 2023 15:52:54 +0300 Subject: [PATCH] fix: cart_id --- catalog/controller/payment/payze.php | 16 ++++++++++++---- catalog/model/payment/payze.php | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/catalog/controller/payment/payze.php b/catalog/controller/payment/payze.php index 102547f..26b1f81 100644 --- a/catalog/controller/payment/payze.php +++ b/catalog/controller/payment/payze.php @@ -87,6 +87,15 @@ public function confirm(): void { $result = $payze->justPay($payze_data); } + if (!empty($result['response']['cardId']) && $this->customer->isLogged()) { + $payze_data = array( + 'customer_id' => $this->customer->getId(), + 'card_id' => $result['response']['cardId'] + ); + + $this->model_extension_payze_payment_payze->addCustomerCard($payze_data); + } + if (!empty($result['response']['transactionUrl'])) { $data['redirect'] = $result['response']['transactionUrl']; } elseif (!empty($result['response']['transactionId'])) { @@ -249,15 +258,14 @@ public function webhook(): bool { $order_info = $this->model_checkout_order->getOrder($order_id); if ($order_info) { - $payze_data = [ + $payze_data = array( 'customer_id' => $order_info['customer_id'], - 'card_id' => $result['response']['transactionId'], 'card_brand' => $result['response']['cardBrand'], 'card_mask' => $result['response']['cardMask'], 'expiration_date' => $result['response']['expirationDate'] - ]; + ); - $this->model_extension_payze_payment_payze->addCustomerCard($payze_data); + $this->model_extension_payze_payment_payze->updateCustomerCard($payze_data); } } diff --git a/catalog/model/payment/payze.php b/catalog/model/payment/payze.php index 126cbb6..9e7b486 100644 --- a/catalog/model/payment/payze.php +++ b/catalog/model/payment/payze.php @@ -47,11 +47,16 @@ public function getMethod(array $address): array { } public function addCustomerCard(array $data): void { - $this->db->query("INSERT INTO `" . DB_PREFIX . "payze_customer_card` SET `customer_id` = '" . (int)$data['customer_id'] . "', `card_id` = '" . $this->db->escape($data['card_id']) . "', `card_brand` = '" . $this->db->escape($data['card_brand']) . "', `card_mask` = '" . $this->db->escape($data['card_mask']) . "', `expiration_date` = '" . $this->db->escape($data['expiration_date']) . "'"); + $this->db->query("DELETE FROM `" . DB_PREFIX . "payze_customer_card` WHERE `customer_id` = '" . (int)$data['customer_id'] . "' AND `card_mask` = ''"); + $this->db->query("INSERT INTO `" . DB_PREFIX . "payze_customer_card` SET `customer_id` = '" . (int)$data['customer_id'] . "', `card_id` = '" . $this->db->escape($data['card_id']) . "'"); + } + + public function updateCustomerCard(array $data): void { + $this->db->query("UPDATE `" . DB_PREFIX . "payze_customer_card` SET `card_brand` = '" . $this->db->escape($data['card_brand']) . "', `card_mask` = '" . $this->db->escape($data['card_mask']) . "', `expiration_date` = '" . $this->db->escape($data['expiration_date']) . "' WHERE `customer_id` = '" . (int)$data['customer_id'] . "' AND `card_mask` = ''"); } public function getCustomerCards(int $customer_id): array { - $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "payze_customer_card` WHERE `customer_id` = '" . (int)$customer_id . "'"); + $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "payze_customer_card` WHERE `customer_id` = '" . (int)$customer_id . "' AND `card_mask` != ''"); if ($query->num_rows) { return $query->rows;