Skip to content

Commit

Permalink
fix: cart_id
Browse files Browse the repository at this point in the history
  • Loading branch information
artembelfox committed Aug 10, 2023
1 parent 40fe8e8 commit 714ed58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 12 additions & 4 deletions catalog/controller/payment/payze.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
9 changes: 7 additions & 2 deletions catalog/model/payment/payze.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 714ed58

Please sign in to comment.