Skip to content

Commit

Permalink
Added order recurring validation and notification in addReport
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed Jun 2, 2024
1 parent 9a7c8dc commit e34302b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
32 changes: 24 additions & 8 deletions upload/catalog/controller/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4303,6 +4303,8 @@ public function order_delete_order_before($route, $data) {
* catalog/model/extension/payment/paypal/addOrderRecurringTransaction/before
*/
public function addReport(&$route, &$args): void {
$this->load->language('checkout/recurring');

if (isset($args['order_recurring_id'])) {
$order_recurring_id = (int)$args['order_recurring_id'];
} else {
Expand All @@ -4312,15 +4314,29 @@ public function addReport(&$route, &$args): void {
if ($order_recurring_id) {
$this->load->model('checkout/recurring');

if (isset($this->request->server['HTTP_X_REAL_IP'])) {
$ip = $this->request->server['HTTP_X_REAL_IP'];
} elseif (oc_get_ip()) {
$ip = oc_get_ip();
} else {
$ip = '';
}
$recurring_info = $this->model_checkout_recurring->getOrderRecurring($order_recurring_id);

$this->model_checkout_recurring->addReport($order_recurring_id, $this->config->get('config_store_id'), $ip, $this->session->data['payment_address']['country']);
if ($recurring_info) {
$this->load->model('checkout/order');

$order_info = $this->model_checkout_order->getOrder($recurring_info['order_id']);

if ($order_info) {
if (isset($this->request->server['HTTP_X_REAL_IP'])) {
$ip = $this->request->server['HTTP_X_REAL_IP'];
} elseif (oc_get_ip()) {
$ip = oc_get_ip();
} else {
$ip = '';
}

$this->model_checkout_recurring->addReport($order_recurring_id, $this->config->get('config_store_id'), $ip, $this->session->data['payment_address']['country']);

$comment = $this->language->get('text_new_subscription');

$this->model_checkout_order->addHistory($recurring_info['order_id'], $order_info['order_status_id'], $comment, true);
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions upload/catalog/language/en-gb/checkout/recurring.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
// Text
$_['text_new_subscription'] = 'Your recurring profile has now been added to our new subscription system.';
13 changes: 13 additions & 0 deletions upload/catalog/model/checkout/recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ class ModelCheckoutRecurring extends Model {
public function addReport(int $order_recurring_id, int $store_id, string $ip, string $country): void {
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_recurring_report` SET `order_recurring_id` = '" . (int)$order_recurring_id . "', `store_id` = '" . (int)$store_id . "', `ip` = '" . $this->db->escape($ip) . "', `country` = '" . $this->db->escape($country) . "', `date_added` = NOW()");
}

/**
* Get Order Recurring
*
* @param int $order_recurring_id
*
* @return array<string, mixed>
*/
public function getOrderRecurring(int $order_recurring_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_recurring` WHERE `order_recurring_id` = '" . (int)$order_recurring_id . "'");

return $query->row;
}
}

0 comments on commit e34302b

Please sign in to comment.