pronamic / wp-pronamic-eu-vat-for-easy-digital-downloads

This plugin extends the Easy Digital Downloads plugin with EU VAT support. 🚨 This plugin for Easy Digital Downloads is no longer being maintained and developed. An alternative is the webshop plugin WooCommerce with good basic support for VAT.
GNU General Public License v2.0
2 stars 0 forks source link

Is "Easy Digital Downloads - EU VAT" by Barn2Media inspired on our EDD EU plugin? #2

Closed remcotolsma closed 2 years ago

remcotolsma commented 2 years ago

Is the Barn2Media's "EU VAT for Easy Digital Downloads" plugin inspired on our EDD EU plugin? Based on https://eddeuvat.barn2.com/wp-content/plugins/edd-eu-vat/assets/js/edd-eu-vat.js?ver=1.5.8 i think it is.

edd-eu-vat.js


var EDD_EU_VAT = ( function( $, window, document, params ) {

    // Back-compat
    window.euCountries = params.countries;

    function hideResult() {
        $( '#edd-vat-check-result' ).remove();
    }

    function showError( $el, message ) {
        $el.append( '<span id="edd-vat-check-result" class="edd-vat-check-result edd-vat-check-error">' + message + '</span>' );
    }

    var eddVatCheck = function( event ) {
        var $vatField = $( '#edd-card-vat-wrap' ),
            billingCountry = $( '#billing_country' ).val(),
            vatNumber = $( '#edd-vat-number' ).val();

        if ( !$vatField.length ) {
            return false;
        }

        if ( $vatField.data( 'check' ) ) {
            return false;
        }

        hideResult();

        if ( !vatNumber ) {
            showError( $vatField, params.messages.vat_number_missing );
            return false;
        }

        if ( !billingCountry ) {
            showError( $vatField, params.messages.country_missing );
            return false;
        }

        var postData = {
            action: 'edd_vat_check',
            billing_country: billingCountry,
            vat_number: vatNumber,
            nonce: $( '#edd-checkout-address-fields-nonce' ).val()
        };

        $vatField.data( 'check', true );

        var $spinner = $( '<span class="edd-loading-ajax edd-loading"></span>' );
        $( '#edd-vat-check-button' ).after( $spinner );

        $( document.body ).trigger( 'edd_eu_vat:before_vat_check', postData );

        $.ajax( {
            type: 'POST',
            data: postData,
            dataType: 'json',
            url: edd_global_vars.ajaxurl,
            xhrFields: {
                withCredentials: true
            }
        } )
            .done( function( response, textStatus, jqXHR ) {
                if ( jqXHR.status == 200 && typeof response.html !== 'undefined' ) {
                    var $updatedCart = $( $.parseHTML( response.html.trim() ) ).filter( '#edd_checkout_cart_form' );

                    // Update cart.
                    if ( $updatedCart.length ) {
                        $( '#edd_checkout_cart_form' ).replaceWith( $updatedCart );
                    }

                    // Update totals.
                    $( '.edd_cart_amount' ).html( response.total );

                    // Add VAT result message.
                    $vatField.append( response.vat_check_result );

                    // Remove EDD SL upgrade prices notices if we clear the VAT rate.
                    if ( response.tax_rate_raw === 0 && params.hide_edd_sl_notices ) {
                        $( '#edd-recurring-sl-auto-renew' ).each( function() {
                            $( this ).remove();
                        } );

                        $( '#edd-recurring-sl-cancel-replace' ).each( function() {
                            $( this ).remove();
                        } );
                    }

                    // Create tax data (in same format as EDD) and trigger edd_taxes_recalulcated to ensure everything is up to date.
                    var taxData = {
                        postdata: postData,
                        response: response
                    };

                    $( document.body )
                        .trigger( 'edd_taxes_recalculated', taxData )
                        .trigger( 'edd_eu_vat:vat_check', response );
                } else {
                    showError( $vatField, params.messages.ajax_error );
                }
            } )
            .fail( function( jqXHR, textStatus, errorThrown ) {
                showError( $vatField, params.messages.ajax_error );
            } )
            .always( function() {
                $spinner.remove();
                $vatField.data( 'check', false );

                $( document.body ).trigger( 'edd_eu_vat:vat_check_complete' );
            } );

        return false;
    };

    // Hide VAT field if country not in list of EU countries.
    function eddCountryCheck() {
        if ( !params.countries ) {
            return;
        }

        var billingCountry = $( '#billing_country' ).val();

        if ( billingCountry && -1 !== params.countries.indexOf( billingCountry ) ) {
            $( '#edd-card-vat-wrap' ).show();
        } else {
            $( '#edd-card-vat-wrap' ).hide();
            hideResult();
        }
    }

    $( function() {
        // Bind events for purchase form.
        $( '#edd_purchase_form' )
            .on( 'click', '#edd-vat-check-button', eddVatCheck )
            .on( 'change', '#billing_country', function( event ) {
                var vatData = $( '#edd-vat-check-result' ).data();

                // Clear previous VAT number and result if country is changed.
                if ( vatData && vatData.valid && vatData.country && vatData.country !== $( this ).val() ) {
                    $( '#edd-vat-number' ).val( '' );
                    hideResult();
                }

                eddCountryCheck();
            } )
            .on( 'change', '#edd-stripe-update-billing-address', function( event ) {
                // Prevent EDD Stripe hiding the VAT field when toggling the billing fields for saved addresses.
                eddCountryCheck();
            } );

    } );

    $( document.body )
        .on( 'edd_gateway_loaded', function( e, gateway ) {
            // Trigger EU country check when payment gateway loaded.
            eddCountryCheck();

            // Also check EU country when 'Add new' card option selected in EDD Stripe.
            $( '#edd-stripe-add-new' ).on( 'change', function( e ) {
                eddCountryCheck();
            } );
        } );

    return {
        checkVatNumber: eddVatCheck,
        checkCountry: eddCountryCheck
    };

}( jQuery, window, document, edd_eu_vat_params ) );

Our edd-vat.js file is less complex, but there are similarities.

function eddVatCheck() {
    jQuery( '#edd-vat-check-button' ).after('<span class="edd-cart-ajax"><i class="edd-icon-spinner edd-icon-spin"></i></span>');

    jQuery.ajax( {
        type: 'POST',
        data: {
            'action': 'edd_vat_check',
            'billing_country': jQuery( '#edd_cc_address #billing_country' ).val(),
            'vat_number': jQuery( '#edd-vat-number' ).val(),
        },
        dataType: 'json',
        url: edd_vat.ajaxurl,
        xhrFields: {
            withCredentials: true
        },
        success: function( response ) {
            /**
             * Update cart form.
             *
             * In version 2.3 the HTML element to replace the content with was changed
             * from'#edd_checkout_cart' to '#edd_checkout_cart_form'.
             *
             * @link https://github.com/easydigitaldownloads/easy-digital-downloads/commit/005dfbf12cf0d4e67f2ec71c2de6f4955df89817
             * @link https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.3/assets/js/edd-checkout-global.js#L64-L85
             * @link https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.2/assets/js/edd-checkout-global.js#L64-L84
             */
            jQuery( '#edd_checkout_cart_form' ).replaceWith( response.checkout_cart );

            jQuery( '.edd_cart_amount' ).html( response.total );

            jQuery( '#edd-vat-check-result' ).html( response.vat_check_result );

            jQuery( '.edd-cart-ajax' ).remove();
        }
    } );

    return false;
}

Especially visible in the post data.

Pronamic

{
    'action': 'edd_vat_check',
    'billing_country': jQuery( '#edd_cc_address #billing_country' ).val(),
    'vat_number': jQuery( '#edd-vat-number' ).val(),
},

Barn2Media

{
    action: 'edd_vat_check',
    billing_country: billingCountry,
    vat_number: vatNumber,
    nonce: $( '#edd-checkout-address-fields-nonce' ).val()
}

Can't be a coincidence that Barn2Media has used exactly the same naming, right?


Plugin can be found on: https://github.com/jeremycollake/edd-eu-vat.

remcotolsma commented 2 years ago

I checked our payment history and can confirm that Andy Keith from Barn2Media has bought our "Easy Digital Downloads – VAT" on 24 March 2016. How about this @Barn2Media @andykeith, you bought our plugin and started selling and developing it yourself?

andykeith commented 2 years ago

HI @remcotolsma, I'm glad to see you're working on your VAT plugin again. Yes I bought the original Pronamic EDD VAT plugin back in 2015, and we used it on our website for a couple of years as it was the best VAT plugin we found for EDD at the time. I recommended it to a number of other developers, including to the Easy Digital Downloads team themselves who were looking for a VAT solution.

Development on the plugin seemed to come to halt around 2016 IIRC and as a result there were areas which needed updating, and a few issues and bugs crept in. We also wanted it to add our own customisations to suit the specific needs of the Barn2 site, so we added these customisations to the plugin.

Later, in 2019 we decided to build our own EDD VAT plugin, and that was in part based on our customised version of the Pronamic plugin. The current plugin has moved a long way since then, but parts of the original code were definitely based on your plugin.

The EU VAT system doesn't seem to have got any easier in the intervening years and we regularly debate whether to continue supporting our plugin given the high support requirements and relatively low take up of the plugin. Would be interested to hear your take on it.

remcotolsma commented 2 years ago

Thanks for your quick response @andykeith, good to have some background information. It is a pity that we have not had contact about this before. Also a bit disappointing that you don't mention Pronamic in the plugin.

We are also doubting whether we should continue with Easy Digital Downloads. Version 3 seems to have been launched a bit hastily after the @awesomemotive takeover? And with 50,000+ installs according to WordPress.org, Easy Digital Downloads isn't very big compared to WooCommerce.

Schermafbeelding 2022-09-02 om 11 11 52

We will now also discuss internally whether we should make the switch to WooCommerce and leave Easy Digital completely behind us. I know Yoast migrated from Easy Digital Downloads to WooCommerce a few years ago: https://woocommerce.com/posts/migrating-yoast-com-from-edd-to-woocommerce/.

andykeith commented 2 years ago

Hi @remcotolsma. No problem, we will update our copyright notice for our VAT plugin to mention Pronamic.

For what it's worth, I would recommend going down the WooCommerce route rather than EDD. Whether that's for a VAT plugin or something else. As you point out, the market size for EDD is significantly smaller than WooCommerce, so it makes a lot more sense to develop extensions for Woo. We have no plans to develop any more EDD extensions.

andykeith commented 2 years ago

Hi, quick update to let you know we've updated the license terms for our EDD VAT plugin. Here's the screenshot of the updated license.txt which is bundled with the plugin:

Screenshot 2022-10-26 at 11 30 37