Skip to content

Commit

Permalink
More updates on PayPal Checkout to match new subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed Jun 2, 2024
1 parent 21411ac commit f7bb283
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 113 deletions.
24 changes: 6 additions & 18 deletions upload/admin/controller/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3188,19 +3188,19 @@ public function cancelTracker() {
public function recurringButtons() {
$content = '';

if ($this->config->get('payment_paypal_status') && !empty($this->request->get['order_recurring_id'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->get['subscription_id'])) {
$this->load->language('extension/payment/paypal');

$this->load->model('sale/recurring');

$data['order_recurring_id'] = $this->request->get['order_recurring_id'];
$data['subscription_id'] = (int)$this->request->get['subscription_id'];

$order_recurring_info = $this->model_sale_recurring->getRecurring($data['order_recurring_id']);
$order_recurring_info = $this->model_sale_recurring->getRecurring($data['subscription_id']);

if ($order_recurring_info) {
$data['recurring_status'] = $order_recurring_info['status'];

$data['info_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/getRecurringInfo', 'user_token=' . $this->session->data['user_token'] . '&order_recurring_id=' . $data['order_recurring_id'], true));
$data['info_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/getRecurringInfo', 'user_token=' . $this->session->data['user_token'] . '&subscription_id=' . $data['subscription_id'], true));
$data['enable_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/enableRecurring', 'user_token=' . $this->session->data['user_token'], true));
$data['disable_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/disableRecurring', 'user_token=' . $this->session->data['user_token'], true));

Expand All @@ -3216,15 +3216,9 @@ public function getRecurringInfo() {
}

public function enableRecurring() {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['order_recurring_id'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['subscription_id'])) {
$this->load->language('extension/payment/paypal');

$this->load->model('extension/payment/paypal');

$order_recurring_id = $this->request->post['order_recurring_id'];

$this->model_extension_payment_paypal->editOrderRecurringStatus($order_recurring_id, 1);

$data['success'] = $this->language->get('success_enable_recurring');
}

Expand All @@ -3235,15 +3229,9 @@ public function enableRecurring() {
}

public function disableRecurring() {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['order_recurring_id'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['subscription_id'])) {
$this->load->language('extension/payment/paypal');

$this->load->model('extension/payment/paypal');

$order_recurring_id = $this->request->post['order_recurring_id'];

$this->model_extension_payment_paypal->editOrderRecurringStatus($order_recurring_id, 2);

$data['success'] = $this->language->get('success_disable_recurring');
}

Expand Down
16 changes: 6 additions & 10 deletions upload/admin/model/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getTotalSalesByMonth() {

foreach ($query->rows as $result) {
$sale_data[date('j', strtotime($result['date_added']))] = array(
'day' => date('d', strtotime($result['date_added'])),
'day' => date('d', strtotime($result['date_added'])),
'total' => $result['total'],
'paypal_total' => $result['paypal_total']
);
Expand Down Expand Up @@ -130,7 +130,7 @@ public function getTotalSalesByYear() {

foreach ($query->rows as $result) {
$sale_data[date('n', strtotime($result['date_added']))] = array(
'month' => date('M', strtotime($result['date_added'])),
'month' => date('M', strtotime($result['date_added'])),
'total' => $result['total'],
'paypal_total' => $result['paypal_total']
);
Expand Down Expand Up @@ -237,10 +237,6 @@ public function getPayPalOrder($order_id) {
}
}

public function editOrderRecurringStatus($order_recurring_id, $status) {
$this->db->query("UPDATE `" . DB_PREFIX . "order_recurring` SET `status` = '" . (int)$status . "' WHERE `order_recurring_id` = '" . (int)$order_recurring_id . "'");
}

public function setAgreeStatus() {
$this->db->query("UPDATE " . DB_PREFIX . "country SET status = '0' WHERE (iso_code_2 = 'CU' OR iso_code_2 = 'IR' OR iso_code_2 = 'SY' OR iso_code_2 = 'KP')");
$this->db->query("UPDATE " . DB_PREFIX . "zone SET status = '0' WHERE country_id = '220' AND (`code` = '43' OR `code` = '14' OR `code` = '09')");
Expand Down Expand Up @@ -360,24 +356,24 @@ public function log($data, $title = null) {
public function install() {
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_customer_token` (`customer_id` INT(11) NOT NULL, `payment_method` VARCHAR(20) NOT NULL, `vault_id` VARCHAR(50) NOT NULL, `vault_customer_id` VARCHAR(50) NOT NULL, `card_type` VARCHAR(40) NOT NULL, `card_nice_type` VARCHAR(40) NOT NULL, `card_last_digits` VARCHAR(4) NOT NULL, `card_expiry` VARCHAR(20) NOT NULL, `main_token_status` TINYINT(1) NOT NULL, PRIMARY KEY (`customer_id`, `payment_method`, `vault_id`), KEY `vault_customer_id` (`vault_customer_id`), KEY `main_token_status` (`main_token_status`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order` (`order_id` INT(11) NOT NULL, `paypal_order_id` VARCHAR(20) NOT NULL, `transaction_id` VARCHAR(20) NOT NULL, `transaction_status` VARCHAR(20) NOT NULL, `payment_method` VARCHAR(20) NOT NULL, `vault_id` VARCHAR(50) NOT NULL, `vault_customer_id` VARCHAR(50) NOT NULL, `card_type` VARCHAR(40) NOT NULL, `card_nice_type` VARCHAR(40) NOT NULL, `card_last_digits` VARCHAR(4) NOT NULL, `card_expiry` VARCHAR(20) NOT NULL, `total` DECIMAL(15,2) NOT NULL, `currency_code` VARCHAR(3) NOT NULL, `environment` VARCHAR(20) NOT NULL, `tracking_number` VARCHAR(64) NOT NULL, `carrier_name` VARCHAR(64) NOT NULL, PRIMARY KEY (`order_id`), KEY `paypal_order_id` (`paypal_order_id`), KEY `transaction_id` (`transaction_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order_recurring` (`paypal_order_recurring_id` INT(11) NOT NULL AUTO_INCREMENT, `order_id` INT(11) NOT NULL, `order_recurring_id` INT(11) NOT NULL, `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 (`paypal_order_recurring_id`), KEY (`order_id`), KEY (`order_recurring_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_subscription` (`paypal_subscription_id` INT(11) NOT NULL AUTO_INCREMENT, `order_id` INT(11) NOT NULL, `subscription_id` INT(11) NOT NULL, `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 (`paypal_subscription_id`), KEY (`order_id`), KEY (`subscription_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
}

public function uninstall() {
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_customer_token`");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order`");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order_recurring`");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_subscription`");
}

public function update() {
if ($this->config->get('paypal_version') < '3.0.0') {
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_customer_token`");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order`");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order_recurring`");
$this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "paypal_checkout_integration_subscription`");

$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_customer_token` (`customer_id` INT(11) NOT NULL, `payment_method` VARCHAR(20) NOT NULL, `vault_id` VARCHAR(50) NOT NULL, `vault_customer_id` VARCHAR(50) NOT NULL, `card_type` VARCHAR(40) NOT NULL, `card_nice_type` VARCHAR(40) NOT NULL, `card_last_digits` VARCHAR(4) NOT NULL, `card_expiry` VARCHAR(20) NOT NULL, `main_token_status` TINYINT(1) NOT NULL, PRIMARY KEY (`customer_id`, `payment_method`, `vault_id`), KEY `vault_customer_id` (`vault_customer_id`), KEY `main_token_status` (`main_token_status`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order` (`order_id` INT(11) NOT NULL, `paypal_order_id` VARCHAR(20) NOT NULL, `transaction_id` VARCHAR(20) NOT NULL, `transaction_status` VARCHAR(20) NOT NULL, `payment_method` VARCHAR(20) NOT NULL, `vault_id` VARCHAR(50) NOT NULL, `vault_customer_id` VARCHAR(50) NOT NULL, `card_type` VARCHAR(40) NOT NULL, `card_nice_type` VARCHAR(40) NOT NULL, `card_last_digits` VARCHAR(4) NOT NULL, `card_expiry` VARCHAR(20) NOT NULL, `total` DECIMAL(15,2) NOT NULL, `currency_code` VARCHAR(3) NOT NULL, `environment` VARCHAR(20) NOT NULL, `tracking_number` VARCHAR(64) NOT NULL, `carrier_name` VARCHAR(64) NOT NULL, PRIMARY KEY (`order_id`), KEY `paypal_order_id` (`paypal_order_id`), KEY `transaction_id` (`transaction_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_order_recurring` (`paypal_order_recurring_id` INT(11) NOT NULL AUTO_INCREMENT, `order_id` INT(11) NOT NULL, `order_recurring_id` INT(11) NOT NULL, `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 (`paypal_order_recurring_id`), KEY (`order_id`), KEY (`order_recurring_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paypal_checkout_integration_subscription` (`paypal_subscription_id` INT(11) NOT NULL AUTO_INCREMENT, `order_id` INT(11) NOT NULL, `subscription_id` INT(11) NOT NULL, `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 (`paypal_subscription_id`), KEY (`order_id`), KEY (`subscription_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
} elseif ($this->config->get('paypal_version') < '3.1.0') {
$this->db->query("ALTER TABLE `" . DB_PREFIX . "paypal_checkout_integration_order` ADD COLUMN `total` DECIMAL(15,2) NOT NULL AFTER `card_expiry`");
$this->db->query("ALTER TABLE `" . DB_PREFIX . "paypal_checkout_integration_order` ADD COLUMN `currency_code` VARCHAR(3) NOT NULL AFTER `total`");
Expand Down
24 changes: 6 additions & 18 deletions upload/catalog/controller/extension/recurring/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ class ControllerExtensionRecurringPayPal extends Controller {
public function index() {
$content = '';

if ($this->config->get('payment_paypal_status') && !empty($this->request->get['order_recurring_id'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->get['subscription_id'])) {
$this->load->language('extension/recurring/paypal');

$this->load->model('account/recurring');

$data['order_recurring_id'] = $this->request->get['order_recurring_id'];
$data['subscription_id'] = (int)$this->request->get['subscription_id'];

$order_recurring_info = $this->model_account_recurring->getOrderRecurring($data['order_recurring_id']);
$order_recurring_info = $this->model_account_recurring->getOrderRecurring($data['subscription_id']);

if ($order_recurring_info) {
$data['recurring_status'] = $order_recurring_info['status'];

$data['info_url'] = str_replace('&amp;', '&', $this->url->link('extension/recurring/paypal/getRecurringInfo', 'order_recurring_id=' . $data['order_recurring_id'], true));
$data['info_url'] = str_replace('&amp;', '&', $this->url->link('extension/recurring/paypal/getRecurringInfo', 'subscription_id=' . $data['subscription_id'], true));
$data['enable_url'] = str_replace('&amp;', '&', $this->url->link('extension/recurring/paypal/enableRecurring', '', true));
$data['disable_url'] = str_replace('&amp;', '&', $this->url->link('extension/recurring/paypal/disableRecurring', '', true));

Expand All @@ -33,15 +33,9 @@ public function getRecurringInfo() {
}

public function enableRecurring() {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['order_recurring_id'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['subscription_id'])) {
$this->load->language('extension/recurring/paypal');

$this->load->model('extension/payment/paypal');

$order_recurring_id = $this->request->post['order_recurring_id'];

$this->model_extension_payment_paypal->editOrderRecurringStatus($order_recurring_id, 1);

$data['success'] = $this->language->get('success_enable_recurring');
}

Expand All @@ -52,15 +46,9 @@ public function enableRecurring() {
}

public function disableRecurring() {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['order_recurring_id'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['subscription_id'])) {
$this->load->language('extension/recurring/paypal');

$this->load->model('extension/payment/paypal');

$order_recurring_id = $this->request->post['order_recurring_id'];

$this->model_extension_payment_paypal->editOrderRecurringStatus($order_recurring_id, 2);

$data['success'] = $this->language->get('success_disable_recurring');
}

Expand Down
Loading

0 comments on commit f7bb283

Please sign in to comment.