Skip to content

Commit

Permalink
Upgraded PayPal Checkout extension to v3.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed Jul 18, 2024
1 parent 302a8c4 commit 880b5b7
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 57 deletions.
33 changes: 18 additions & 15 deletions upload/admin/controller/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ public function capturePayment() {

$this->model_extension_payment_paypal->editPayPalOrder($paypal_order_data);

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

Expand All @@ -2480,6 +2480,7 @@ public function reauthorizePayment() {
$this->load->language('extension/payment/paypal');

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

$order_id = (int)$this->request->post['order_id'];
$reauthorize_amount = (float)$this->request->post['reauthorize_amount'];
Expand All @@ -2491,6 +2492,8 @@ public function reauthorizePayment() {
} else {
$notify = false;
}

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

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

Expand Down Expand Up @@ -2577,7 +2580,7 @@ public function reauthorizePayment() {

$this->model_extension_payment_paypal->editPayPalOrder($paypal_order_data);

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

Expand All @@ -2597,6 +2600,7 @@ public function voidPayment() {
$this->load->language('extension/payment/paypal');

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

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

Expand All @@ -2607,6 +2611,8 @@ public function voidPayment() {
} else {
$notify = false;
}

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

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

Expand Down Expand Up @@ -2681,7 +2687,7 @@ public function voidPayment() {

$this->model_extension_payment_paypal->editPayPalOrder($paypal_order_data);

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

Expand Down Expand Up @@ -2939,7 +2945,7 @@ public function refundPayment() {

$this->model_extension_payment_paypal->editPayPalOrder($paypal_order_data);

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

Expand Down Expand Up @@ -2995,6 +3001,7 @@ public function createTracker() {
$this->load->language('extension/payment/paypal');

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

$order_id = (int)$this->request->post['order_id'];
$country_code = $this->request->post['country_code'];
Expand All @@ -3007,10 +3014,12 @@ public function createTracker() {
} else {
$notify = false;
}

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

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

if ($paypal_order_info) {
if ($order_info && $paypal_order_info) {
$paypal_order_id = $paypal_order_info['paypal_order_id'];
$transaction_id = $paypal_order_info['transaction_id'];

Expand Down Expand Up @@ -3109,16 +3118,10 @@ public function createTracker() {

$this->model_extension_payment_paypal->editPayPalOrder($paypal_order_data);

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

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

if ($order_info) {
$order_status_id = $setting['order_status']['shipped']['id'];

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

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

$data['success'] = $this->language->get('success_create_tracker');
Expand Down
2 changes: 2 additions & 0 deletions upload/admin/language/en-gb/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
$_['entry_cvv'] = 'CVV';
$_['entry_message_insert_tag'] = 'Message Insert Tag';
$_['entry_message_insert_type'] = 'Message Insert Type';
$_['entry_final_order_status'] = 'Final Order Status';
$_['entry_contact_company'] = 'Company';
$_['entry_contact_first_name'] = 'First Name';
$_['entry_contact_last_name'] = 'Last Name';
Expand Down Expand Up @@ -308,6 +309,7 @@
$_['help_cron_url'] = 'Set a cron to call this URL. This integration is typically used for subscription/recurring product purchase.';
$_['help_card_secure_method'] = '3D Secure enables you to authenticate card holders through card issuers. \'SCA Always\' method trigger 3D Secure for every transaction, regardless of SCA requirements. \'SCA When Required\' method returns a 3D Secure contingency when it is a mandate in the region where you operate.';
$_['help_card_secure_scenario'] = '3D Secure authentication is performed only if the card is enrolled for the service. In scenarios where the 3D Secure authentication has not been successful, you have the option to complete the payment at your own risk, meaning that you -the merchant- will be liable in case of a chargeback.';
$_['help_final_order_status'] = 'Set the order status to final and PayPal will not be able to change it.';

// Button
$_['button_connect'] = 'Connect';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="section-content">
<div class="row">
{% for column_paypal_order_status in setting['order_status']|batch(setting['order_status']|length / 2|round(1, 'ceil')) %}
<div class="col col-md-6">
<div class="col col-md-4">
{% for paypal_order_status in column_paypal_order_status %}
<div class="form-group">
<label class="control-label" for="input_order_status_{{ paypal_order_status['code'] }}">{{ attribute(_context, paypal_order_status['name']) }}</label>
Expand All @@ -59,6 +59,21 @@
{% endfor %}
</div>
{% endfor %}
<div class="col col-md-4">
<div class="row mb-3">
<label class="col-form-label" for="input_final_order_status"><span data-bs-toggle="tooltip" title="{{ help_final_order_status }}">{{ entry_final_order_status }}</span></label>
<div class="input-group">
<div id="input_final_order_status" class="form-control form-control-list">
{% for order_status in order_statuses %}
<div class="form-check">
<input type="checkbox" name="payment_paypal_setting[final_order_status][]" value="{{ order_status['order_status_id'] }}" id="input_final_order_status_{{ order_status['order_status_id'] }}" class="form-check-input form-check-input-mini" {% if order_status['order_status_id'] in setting['final_order_status'] %} checked="checked" {% endif %} />
<label for="input_final_order_status_{{ order_status['order_status_id'] }}" class="form-check-label">{{ order_status['name'] }}</label>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
</form>
Expand All @@ -70,42 +85,42 @@
$('.payment-paypal').on('click', '.button-save', function() {
$.ajax({
type: 'post',
url: $('#form_payment').attr('action'),
data: $('#form_payment').serialize(),
dataType: 'json',
success: function(json) {
$('.payment-paypal .alert-success').remove();
if (json['success']) {
$('.payment-paypal > .container-fluid').prepend('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i><button type="button" class="close" data-dismiss="alert">&times;</button> ' + json['success'] + '</div>');
$('html, body').animate({scrollTop: $('.payment-paypal > .container-fluid .alert-success').offset().top}, 'slow');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
type: 'post',
url: $('#form_payment').attr('action'),
data: $('#form_payment').serialize(),
dataType: 'json',
success: function(json) {
$('.payment-paypal .alert-success').remove();
if (json['success']) {
$('.payment-paypal > .container-fluid').prepend('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i><button type="button" class="close" data-dismiss="alert">&times;</button> ' + json['success'] + '</div>');
$('html, body').animate({scrollTop: $('.payment-paypal > .container-fluid .alert-success').offset().top}, 'slow');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('.payment-paypal').on('click', '.button-agree', function() {
$.ajax({
type: 'post',
url: '{{ agree_url }}',
data: '',
dataType: 'json',
success: function(json) {
$('.payment-paypal .alert').remove();
$.ajax({
type: 'post',
url: '{{ agree_url }}',
data: '',
dataType: 'json',
success: function(json) {
$('.payment-paypal .alert').remove();
if (json['success']) {
$('.payment-paypal > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i><button type="button" class="close" data-dismiss="alert">&times;</button> ' + json['success'] + '</div>');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
if (json['success']) {
$('.payment-paypal > .container-fluid').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i><button type="button" class="close" data-dismiss="alert">&times;</button> ' + json['success'] + '</div>');
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
</script>
Expand Down
18 changes: 9 additions & 9 deletions upload/catalog/controller/extension/payment/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ public function approveOrder() {
$this->model_checkout_order->addHistory($this->session->data['order_id'], $order_status_id, $message);
}

if (($authorization_status == 'CREATED') || ($authorization_status == 'PENDING')) {
if ($order_status_id) {
$subscriptions = $this->model_extension_payment_paypal->getSubscriptionsByOrderId($this->session->data['order_id']);

foreach ($subscriptions as $subscription) {
Expand Down Expand Up @@ -1872,7 +1872,7 @@ public function approveOrder() {
$this->model_checkout_order->addHistory($this->session->data['order_id'], $order_status_id, $message);
}

if (($capture_status == 'COMPLETED') || ($capture_status == 'PENDING')) {
if ($order_status_id) {
$subscriptions = $this->model_extension_payment_paypal->getSubscriptionsByOrderId($this->session->data['order_id']);

foreach ($subscriptions as $subscription) {
Expand Down Expand Up @@ -3061,7 +3061,7 @@ public function completeOrder() {
}
}

if (($authorization_status == 'CREATED') || ($authorization_status == 'PENDING')) {
if ($order_status_id) {
$recurring_products = $this->cart->getSubscriptions();

foreach ($recurring_products as $recurring_product) {
Expand Down Expand Up @@ -3725,13 +3725,13 @@ public function callback() {
$transaction_status = 'pending';
}

if (($authorization_status == 'CREATED') || ($authorization_status == 'DENIED') || ($authorization_status == 'PENDING')) {
if ($order_status_id) {
$message = sprintf($this->language->get('text_order_message'), $seller_protection_status);

$this->model_checkout_order->addHistory($this->session->data['order_id'], $order_status_id, $message);
}

if (($authorization_status == 'CREATED') || ($authorization_status == 'DENIED') || ($authorization_status == 'PENDING')) {
if ($authorization_status == 'CREATED' || $authorization_status == 'PENDING') {
$this->model_extension_payment_paypal->deletePayPalOrder($this->session->data['order_id']);

$paypal_order_data = array(
Expand Down Expand Up @@ -3777,7 +3777,7 @@ public function callback() {
}
}

if (($authorization_status == 'CREATED') || ($authorization_status == 'PENDING')) {
if ($order_status_id) {
$recurring_products = $this->cart->getSubscriptions();

foreach ($recurring_products as $recurring_product) {
Expand Down Expand Up @@ -3826,13 +3826,13 @@ public function callback() {
$transaction_status = 'pending';
}

if (($capture_status == 'COMPLETED') || ($capture_status == 'DECLINED') || ($capture_status == 'PENDING')) {
if ($order_status_id) {
$message = sprintf($this->language->get('text_order_message'), $seller_protection_status);

$this->model_checkout_order->addHistory($this->session->data['order_id'], $order_status_id, $message);
}

if (($capture_status == 'COMPLETED') || ($capture_status == 'DECLINED') || ($capture_status == 'PENDING')) {
if ($capture_status == 'COMPLETED' || $capture_status == 'PENDING') {
$this->model_extension_payment_paypal->deletePayPalOrder($this->session->data['order_id']);

$paypal_order_data = array(
Expand Down Expand Up @@ -4070,7 +4070,7 @@ public function webhook() {
$order_status_id = $setting['order_status']['completed']['id'];
}

if ($order_status_id && ($order_info['order_status_id'] != $order_status_id)) {
if ($order_status_id && ($order_info['order_status_id'] != $order_status_id) && !in_array($order_info['order_status_id'], $setting['final_order_status'])) {
$this->load->model('checkout/order');

$this->model_checkout_order->addHistory($order_id, $order_status_id, '', true);
Expand Down
1 change: 1 addition & 0 deletions upload/system/config/paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
'id' => 3
)
),
'final_order_status' => [],
'contact' => array(
'oid' => '00D300000000LaY',
'retURL' => 'https://www.opencart.com/',
Expand Down

0 comments on commit 880b5b7

Please sign in to comment.