Skip to content

Commit

Permalink
Allow an order placing when business ID or VAT number validation fail…
Browse files Browse the repository at this point in the history
…s for technical reasons (#72)

* feature: allow an order creation when business ID or VAT number validation fails for technical reasons
* feature: show VAT number verification notice on orders table, move the notification in admin e-mails below to e-mail header
* update tests
* fix: check stict type
* do not use short echo tag
* add HPOS support for order listing
* add changelog

---------

Co-authored-by: Pavel Vybíral <[email protected]>
Co-authored-by: Karolína Vyskočilová <[email protected]>
  • Loading branch information
3 people committed Jun 28, 2024
1 parent 18672bc commit 68a447e
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 144 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ If you need to set it up in your theme or plugin, you can use following filters

add_filter( 'woolab_icdic_vies_check', '__return_true' );

add_filter( 'woolab_icdic_ignore_check_fail', '__return_true' );

add_filter( 'woolab_icdic_vat_exempt_enabled', function(){
return "no"; // or "yes"
} );
Expand Down
25 changes: 22 additions & 3 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@
var vies_check = $('#woolab_icdic_vies_check');

if (ares_check.length) {
enableActive(ares_check);
enableAresActive(ares_check);
enableIgnoreCheckFailActive(ares_check, vies_check);
ares_check.change(function () {
enableActive(ares_check);
enableAresActive(ares_check);
enableIgnoreCheckFailActive(ares_check, vies_check);
});
}

if (vies_check.length) {
enableIgnoreCheckFailActive(ares_check, vies_check);
vies_check.change(function () {
enableIgnoreCheckFailActive(ares_check, vies_check);
});
}

Expand All @@ -31,7 +40,7 @@
}
});

function enableActive(ares_check) {
function enableAresActive(ares_check) {
var active = $('#woolab_icdic_ares_fill');

if (ares_check.prop("checked") == true) {
Expand All @@ -40,4 +49,14 @@
active.prop("disabled", true).prop("checked", false);
}
}

function enableIgnoreCheckFailActive(ares_check, vies_check) {
var checkbox = $('#woolab_icdic_ignore_check_fail');

if (ares_check.prop('checked') || vies_check.prop('checked')) {
checkbox.prop('disabled', false);
} else {
checkbox.prop('disabled', true).prop('checked', false);
}
}
})(jQuery);
2 changes: 1 addition & 1 deletion assets/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions assets/js/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@

if (woolab.ares_fill) {
// Compatibility with Fluid Checkout for WooCommerce – Lite
// https://wordpress.org/support/topic/compatibility-with-kybernaut-ico-dic-plugin/
if ($('#billing_same_as_shipping') && $('#billing_same_as_shipping').is(':checked')) {
// Check whether the CollapsibleBlock library is available
if (window.CollapsibleBlock) {
Expand Down Expand Up @@ -290,7 +291,10 @@
}

ares_remove_disabled_from_input();
ico_class.append('<span role="alert" class="woolab-ic-dic-tip error">' + data.error + '</span>');

if (!data.internal_error || !woolab.ignore_check_fail) {
ico_class.append('<span role="alert" class="woolab-ic-dic-tip error">' + data.error + '</span>');
}
}
} else {
ares_error(ico_class);
Expand Down Expand Up @@ -325,11 +329,14 @@

function ares_error(ico_class) {
if (woolab.ares_fill) {
$('#billing_company').val('');
$('#billing_dic').val('');
$('#billing_postcode').val('');
$('#billing_city').val('');
$('#billing_address_1').val('');
if (!woolab.ignore_check_fail) {
$('#billing_company').val('');
$('#billing_dic').val('');
$('#billing_postcode').val('');
$('#billing_city').val('');
$('#billing_address_1').val('');
}

ares_remove_disabled_from_input();
}

Expand Down
2 changes: 1 addition & 1 deletion assets/js/public.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions includes/ares.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function woolab_icdic_ares( $ico = '' ) {
$body = wp_remote_retrieve_body($response);
$data = json_decode($body);

if ( $status_code == 200 && $data ) {
if ( $status_code === 200 && $data ) {

$return = array( 'error' => false );
$return['spolecnost'] = $data->obchodniJmeno ?? '';
Expand All @@ -49,14 +49,20 @@ function woolab_icdic_ares( $ico = '' ) {
$return['psc'] = $data->sidlo->psc;
$return['mesto'] = $data->sidlo->nazevMestskehoObvodu ?? $data->sidlo->nazevObce;

} elseif ( $status_code == 404 ) {
} elseif ( $status_code === 404 ) {
$return = array( 'error' => __('Entity doesn\'t exist in ARES.', 'woolab-ic-dic'));
} else {
$return = array( 'error' => __('ARES is not responding', 'woolab-ic-dic'));
$return = array(
'error' => __('ARES is not responding.', 'woolab-ic-dic'),
'internal_error' => true,
);
}

} else {
$return = array( 'error' => __('An error occured while connecting to ARES, try it again later.', 'woolab-ic-dic'));
$return = array(
'error' => __('An error occured while connecting to ARES, try it again later.', 'woolab-ic-dic'),
'internal_error' => true,
);
}

return $return;
Expand Down
Loading

0 comments on commit 68a447e

Please sign in to comment.