Skip to content

Commit

Permalink
Updated PayPal Checkout extension to v3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed Jun 4, 2024
1 parent be5d5c4 commit 18c541e
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 48 deletions.
77 changes: 60 additions & 17 deletions upload/admin/controller/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,7 @@ private function getPaymentDetails($order_id) {
$data['autocomplete_carrier_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/autocompleteCarrier', 'user_token=' . $this->session->data['user_token'], true));
$data['create_tracker_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/createTracker', 'user_token=' . $this->session->data['user_token'], true));
$data['cancel_tracker_url'] = str_replace('&', '&', $this->url->link('extension/payment/paypal/cancelTracker', 'user_token=' . $this->session->data['user_token'], true));
$data['info_order_history_url'] = str_replace('&', '&', $this->url->link('sale/order/history', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $data['order_id'], true));

$data['country_code'] = '';

Expand Down Expand Up @@ -2253,7 +2254,6 @@ private function getPaymentDetails($order_id) {
if (isset($paypal_order_info['purchase_units'][0]['payments']) && !$this->error) {
$payments = $paypal_order_info['purchase_units'][0]['payments'];

$order_status_id = 0;
$transaction_id = $data['transaction_id'];
$transaction_status = $data['transaction_status'];

Expand All @@ -2262,22 +2262,18 @@ private function getPaymentDetails($order_id) {
$transaction_id = $authorization['id'];

if (($authorization['status'] == 'CREATED') || ($authorization['status'] == 'PENDING')) {
$order_status_id = $setting['order_status']['pending']['id'];
$transaction_status = 'created';
}

if ($authorization['status'] == 'CAPTURED') {
$order_status_id = $setting['order_status']['completed']['id'];
$transaction_status = 'completed';
}

if ($authorization['status'] == 'PARTIALLY_CAPTURED') {
$order_status_id = $setting['order_status']['partially_captured']['id'];
$transaction_status = 'partially_captured';
}

if ($authorization['status'] == 'VOIDED') {
$order_status_id = $setting['order_status']['voided']['id'];
$transaction_status = 'voided';
}

Expand All @@ -2290,18 +2286,15 @@ private function getPaymentDetails($order_id) {
if (!empty($payments['captures'])) {
foreach ($payments['captures'] as $capture) {
if (($capture['status'] == 'COMPLETED') && ($transaction_status == 'completed')) {
$order_status_id = $setting['order_status']['completed']['id'];
$transaction_id = $capture['id'];
$transaction_status = 'completed';
}

if ($capture['status'] == 'PARTIALLY_REFUNDED') {
$order_status_id = $setting['order_status']['partially_refunded']['id'];
$transaction_status = 'partially_refunded';
}

if ($capture['status'] == 'REFUNDED') {
$order_status_id = $setting['order_status']['refunded']['id'];
$transaction_status = 'refunded';
}

Expand Down Expand Up @@ -2360,6 +2353,14 @@ public function capturePayment() {
} else {
$final_capture = false;
}

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

if (!empty($this->request->post['notify'])) {
$notify = true;
} else {
$notify = false;
}

$order_info = $this->model_sale_order->getOrder($order_id);

Expand Down Expand Up @@ -2448,8 +2449,8 @@ public function capturePayment() {
$transaction_status = 'partially_captured';
}

if ($order_status_id && ($order_info['order_status_id'] != $order_status_id)) {
$this->model_extension_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id);
if ($order_status_id) {
$this->model_extension_paypal_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id, $comment, $notify);
}

$paypal_order_data = array();
Expand Down Expand Up @@ -2479,12 +2480,21 @@ public function reauthorizePayment() {

$order_id = (int)$this->request->post['order_id'];
$reauthorize_amount = (float)$this->request->post['reauthorize_amount'];

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

if (!empty($this->request->post['notify'])) {
$notify = true;
} else {
$notify = false;
}

$paypal_order_info = $this->model_extension_payment_paypal->getPayPalOrder($order_id);

if ($paypal_order_info) {
$transaction_id = $paypal_order_info['transaction_id'];
$currency_code = $paypal_order_info['currency_code'];
$order_status_id = 0;

$_config = new Config();
$_config->load('paypal');
Expand Down Expand Up @@ -2552,8 +2562,13 @@ public function reauthorizePayment() {
}

if (isset($result['id']) && isset($result['status']) && !$this->error) {
$order_status_id = $setting['order_status']['pending']['id'];
$transaction_id = $result['id'];
$transaction_status = 'created';

if ($order_status_id) {
$this->model_extension_paypal_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id, $comment, $notify);
}

$paypal_order_data = array(
'order_id' => $order_id,
Expand Down Expand Up @@ -2581,11 +2596,20 @@ public function voidPayment() {
$this->load->model('extension/payment/paypal');

$order_id = (int)$this->request->post['order_id'];

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

if (!empty($this->request->post['notify'])) {
$notify = true;
} else {
$notify = false;
}

$paypal_order_info = $this->model_extension_payment_paypal->getPayPalOrder($order_id);

if ($paypal_order_info) {
$transaction_id = $paypal_order_info['transaction_id'];
$order_status_id = 0;

$_config = new Config();
$_config->load('paypal');
Expand Down Expand Up @@ -2644,7 +2668,12 @@ public function voidPayment() {
}

if (!$this->error) {
$order_status_id = $setting['order_status']['voided']['id'];
$transaction_status = 'voided';

if ($order_status_id) {
$this->model_extension_paypal_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id, $comment, $notify);
}

$paypal_order_data = array(
'order_id' => $order_id,
Expand Down Expand Up @@ -2673,6 +2702,13 @@ public function refundPayment() {

$order_id = (int)$this->request->post['order_id'];
$refund_amount = (float)$this->request->post['refund_amount'];
$comment = $this->request->post['comment'];

if (!empty($this->request->post['notify'])) {
$notify = true;
} else {
$notify = false;
}

$order_info = $this->model_sale_order->getOrder($order_id);

Expand Down Expand Up @@ -2893,8 +2929,8 @@ public function refundPayment() {
$transaction_status = 'partially_refunded';
}

if ($order_status_id && ($order_info['order_status_id'] != $order_status_id)) {
$this->model_extension_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id);
if ($order_status_id) {
$this->model_extension_paypal_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id, $comment, $notify);
}

$paypal_order_data = array();
Expand Down Expand Up @@ -2952,7 +2988,7 @@ public function autocompleteCarrier() {
}

public function createTracker() {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['order_id']) && !empty($this->request->post['country_code']) && isset($this->request->post['tracking_number']) && isset($this->request->post['carrier_name'])) {
if ($this->config->get('payment_paypal_status') && !empty($this->request->post['order_id'])) {
$this->load->language('extension/payment/paypal');

$this->load->model('extension/payment/paypal');
Expand All @@ -2961,6 +2997,13 @@ public function createTracker() {
$country_code = $this->request->post['country_code'];
$tracking_number = $this->request->post['tracking_number'];
$carrier_name = $this->request->post['carrier_name'];
$comment = $this->request->post['comment'];

if (!empty($this->request->post['notify'])) {
$notify = true;
} else {
$notify = false;
}

$paypal_order_info = $this->model_extension_payment_paypal->getPayPalOrder($order_id);

Expand Down Expand Up @@ -3024,7 +3067,7 @@ public function createTracker() {
$tracker_info['capture_id'] = $transaction_id;
$tracker_info['tracking_number'] = $tracking_number;
$tracker_info['carrier'] = $carrier_code;
$tracker_info['notify_payer'] = false;
$tracker_info['notify_payer'] = $notify;

if ($carrier_code == 'OTHER') {
$tracker_info['carrier_name_other'] = $carrier_name;
Expand Down Expand Up @@ -3070,8 +3113,8 @@ public function createTracker() {
if ($order_info) {
$order_status_id = $setting['order_status']['shipped']['id'];

if ($order_info['order_status_id'] != $order_status_id) {
$this->model_extension_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id);
if ($order_status_id) {
$this->model_extension_paypal_payment_paypal->addOrderHistory($setting['general']['order_history_token'], $order_id, $order_status_id, $comment, $notify);
}
}

Expand All @@ -3087,7 +3130,7 @@ public function createTracker() {
}

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

$this->load->model('extension/payment/paypal');
Expand Down
4 changes: 4 additions & 0 deletions upload/admin/language/en-gb/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,15 @@
$_['text_transaction_refunded'] = 'A merchant refunded the payment capture.';
$_['text_transaction_partially_refunded'] = 'A merchant partially refunded the payment capture.';
$_['text_transaction_reversed'] = 'PayPal reversed the payment capture.';
$_['text_transaction_comment'] = 'Comment';
$_['text_transaction_notify'] = 'Notify Customer';
$_['text_transaction_action'] = 'Action';
$_['text_final_capture'] = 'Final Capture';
$_['text_tracker_information'] = 'Tracking Information';
$_['text_tracking_number'] = 'Tracking Number';
$_['text_carrier_name'] = 'Carrier';
$_['text_tracker_comment'] = 'Comment';
$_['text_tracker_notify'] = 'Notify Customer';
$_['text_tracker_action'] = 'Action';
$_['text_loading'] = 'Loading...';

Expand Down
13 changes: 5 additions & 8 deletions upload/admin/model/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function getAgreeStatus() {
return $agree_status;
}

public function addOrderHistory($order_history_token, $order_id, $order_status_id) {
public function addOrderHistory(string $order_history_token, int $order_id, int $order_status_id, string $comment = '', bool $notify = false): bool {
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$catalog = HTTPS_CATALOG;
} else {
Expand All @@ -269,7 +269,9 @@ public function addOrderHistory($order_history_token, $order_id, $order_status_i

$data = array(
'order_id' => $order_id,
'order_status_id' => $order_status_id
'order_status_id' => $order_status_id,
'notify' => $notify,
'comment' => $comment
);

$curl = curl_init();
Expand Down Expand Up @@ -366,19 +368,14 @@ public function uninstall() {
}

public function update() {
if ($this->config->get('paypal_version') < '3.0.0') {
if ($this->config->get('paypal_version') < '3.1.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_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_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`");
$this->db->query("ALTER TABLE `" . DB_PREFIX . "paypal_checkout_integration_order` ADD COLUMN `tracking_number` VARCHAR(64) NOT NULL AFTER `environment`");
$this->db->query("ALTER TABLE `" . DB_PREFIX . "paypal_checkout_integration_order` ADD COLUMN `carrier_name` VARCHAR(64) NOT NULL AFTER `tracking_number`");
}
}
}
Loading

0 comments on commit 18c541e

Please sign in to comment.