Skip to content

Commit

Permalink
Merge 3.1.0-dev into main
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
  • Loading branch information
miroslavs committed Jul 25, 2024
2 parents e6789c5 + c49f9be commit b6038f2
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 212 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# WooCommerce Extension Changelog

# 3.1.0
```
* Added custom hook 'nuvei_pfwc_after_rebilling_payment' at the end of DMN Rebilling payment logic.
* Fixed the problem when the merchant create an order from the admin, and the client try to pay for it from the Store.
```

# 3.0.3
```
* Fixed the problem when a Guest user come for the first time on Blocks Checkout and get "Unexpected error" message.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ PHP:

Wordpress:
- Minimum v4.7.
- Tested up to v6.5.5.
- Tested up to v6.6.1.

WooCommerce:
- Minimum v 3.0.
- Minimum v3.0.
- Tested up to v9.1.2.

Merchant configuration:
Expand Down
122 changes: 87 additions & 35 deletions assets/js/nuvei_public.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var nuveiCheckoutSdkParams = {};
var nuveiCheckoutSdkParams = {};
var nuveiCheckoutImplementation = {}; // shortcode, blocks or order-pay

/**
* An object to holds in it checkout-blocks methods.
Expand All @@ -17,7 +18,6 @@ var nuveiCheckoutBlocks = {
try {
console.log(jQuery('body #nuvei_checkout_container').length);

// place Checkout container out of the forms START
// if #nuvei_checkout_container does not exists - create it.
if(jQuery('body #nuvei_checkout_container').length == 0) {
jQuery('div.wp-block-woocommerce-checkout')
Expand All @@ -38,12 +38,6 @@ var nuveiCheckoutBlocks = {
jQuery('form.wc-block-components-form')
.append('<input id="nuvei_session_token" type="hidden" name="nuvei_session_token" value="" />');
}
// place Checkout container out of the forms END

// jQuery('input[name=radio-control-wc-payment-method-options]').on('change', function() {
//// nuveiCheckoutBlocks.changePaymentBtn(jQuery(this).val());
// console.log(jQuery(this).val());
// });
}
catch(_e) {
console.log('WC blocks logic fail.');
Expand Down Expand Up @@ -183,16 +177,19 @@ function nuveiAfterSdkResponse(resp) {
jQuery('#nuvei_transaction_id').val(resp.transactionId);
jQuery('#nuvei_checkout_container').html('<img class="nuvei_loader" src="' + scTrans.loaderUrl + '" />');

// short-code checkout
if (typeof wc == 'undefined') {
jQuery('form.checkout').trigger('submit');
}
// blocks checkout
else {
jQuery('.wc-block-components-checkout-place-order-button').trigger('click');
switch(nuveiCheckoutImplementation.name) {
case 'shortcode':
jQuery('form.checkout').trigger('submit');
return;

case 'blocks':
jQuery('.wc-block-components-checkout-place-order-button').trigger('click');
return;

case 'order-pay':
jQuery('#place_order').trigger('click');
return;
}

return;
}

if (resp.result == 'DECLINED') {
Expand Down Expand Up @@ -243,8 +240,13 @@ function showNuveiCheckout(_params) {
nuveiCheckoutSdkParams.pmWhitelist = ['cc_card'];
}

nuveiCheckoutSdkParams.prePayment = nuveiPrePayment;
nuveiCheckoutSdkParams.onResult = nuveiAfterSdkResponse;
if (nuveiCheckoutImplementation
&& nuveiCheckoutImplementation.hasOwnProperty('name')
&& 'order-pay' !== nuveiCheckoutImplementation.name) {
nuveiCheckoutSdkParams.prePayment = nuveiPrePayment;
}

nuveiCheckoutSdkParams.onResult = nuveiAfterSdkResponse;

simplyConnect(nuveiCheckoutSdkParams);

Expand Down Expand Up @@ -352,7 +354,7 @@ function nuveiWcShortcode() {
);
}

// id nuvei inputs doee not exists - creat them
// if nuvei inputs doesnot exists - creat them
if(jQuery('.woocommerce #nuvei_transaction_id').length == 0) {
jQuery('form.woocommerce-checkout')
.append('<input id="nuvei_transaction_id" type="hidden" name="nuvei_transaction_id" value="" />');
Expand All @@ -373,21 +375,53 @@ function nuveiWcShortcode() {
}
}

function nuveiPayForExistingOrder() {
console.log('nuveiPayForExistingOrder');

// place Checkout container
// if #nuvei_checkout_container does not exists - create it.
if(jQuery('form#order_review #nuvei_checkout_container').length == 0) {
jQuery('form#order_review')
.before('<div id="nuvei_checkout_errors"></div>');

jQuery('form#order_review .payment_box.payment_method_nuvei').append(
'<div id="nuvei_checkout_container" style="display: none;">'
+ '<div id="nuvei_checkout">Loading...</div>'
+ '</div>'
);
}

// if nuvei inputs does not exists - creat them
if(jQuery('form#order_review #nuvei_transaction_id').length == 0) {
jQuery('form#order_review')
.append('<input id="nuvei_transaction_id" type="hidden" name="nuvei_transaction_id" value="" />');
}

showNuveiCheckout();

// set event on Place order button
jQuery('input[name=payment_method]').on('change', function() {
var _self = jQuery(this);

if(_self.val() == scTrans.paymentGatewayName) {
jQuery('#place_order').hide();
}
else {
jQuery('#place_order').show();
}
});

// hide Place order button if need to
if (jQuery('input[name=payment_method]').val() == scTrans.paymentGatewayName) {
jQuery('#place_order').hide();
}
}

jQuery(function() {
if('no' === scTrans.isPluginActive) {
return;
}

// add Simply Connect to the page
// let nuveiSdkScript = '<script src="'+ scTrans.simplyConnectUrl +'" id="nuvei-simply-connect-js"></script>';
//
// if (jQuery('#wc-checkout-js').length > 0) {
// jQuery('#wc-checkout-js').before(nuveiSdkScript);
// }
// else if (jQuery('#wc-blocks-checkout-js').length > 0) {
// jQuery('#wc-blocks-checkout-js').before(nuveiSdkScript);
// }

// Multistep checkout does not support WC Blocks
// when on multistep checkout -> Checkout SDK view, someone click on previous/next button
jQuery('body').on('click', '#wpmc-prev', function(e) {
Expand All @@ -409,14 +443,32 @@ jQuery(function() {
// document ready function END

window.onload = function() {
// loocks like this object is available only for checkout blocks
if (typeof wc == 'object') {
console.log('blocks checkout');
// search for WC Shortcode form
if (jQuery('form.woocommerce-checkout').length > 0) {
nuveiCheckoutImplementation.name = 'shortcode';

Object.freeze(nuveiCheckoutImplementation);
nuveiWcShortcode();
}
// search for WC Blocks
else if (jQuery('div.wp-block-woocommerce-checkout').length > 0) {
nuveiCheckoutImplementation.name = 'blocks';

Object.freeze(nuveiCheckoutImplementation);
nuveiCheckoutBlocks.prepareNuveiComponents();
nuveiCheckoutBlocks.changePaymentBtn();
}
else { // Classic Checkout
nuveiWcShortcode();
// pay for an order created from the admin
else if (jQuery('form#order_review').length > 0
&& jQuery('button#place_order').length > 0
) {
nuveiCheckoutImplementation.name = 'order-pay';

Object.freeze(nuveiCheckoutImplementation);
nuveiPayForExistingOrder();
}
else {
console.log('No Checkout container found.');
}

}
64 changes: 0 additions & 64 deletions assets/js/nuvei_reorder.js

This file was deleted.

2 changes: 0 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
const NUVEI_TRANSACTIONS = '_nuveiTransactions';
const NUVEI_ORDER_SUBSCR = '_nuveiSubscr';
const NUVEI_DCC_DATA = '_nuveiDccData';

//const NUVEI_CUID_POSTFIX = '_sandbox_apm'; // postfix for Sandbox APM payments
const NUVEI_PREV_TRANS_STATUS = '_nuveiPrevTransactionStatus';

const NUVEI_SOURCE_APPLICATION = 'WOOCOMMERCE_PLUGIN';
Expand Down
Loading

0 comments on commit b6038f2

Please sign in to comment.