Git Product home page Git Product logo

pronamic / wp-pronamic-eu-vat-for-easy-digital-downloads Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 54 KB

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.

License: GNU General Public License v2.0

PHP 100.00%
easy-digital-downloads pronamic pronamic-pay tax vat vat-number vat-validation woocommerce wordpress wordpress-plugin

wp-pronamic-eu-vat-for-easy-digital-downloads's Introduction

Pronamic - EU VAT for Easy Digital Downloads

Important

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.

This plugin extends the Easy Digital Downloads plugin with EU VAT support.

Alternatives

Easy Digital Downloads - VAT by Pronamic

Legacy EU VAT for Easy Digital Downloads by Pronamic. It can be found on a private GitLab repository: https://gitlab.com/pronamic-plugins/edd-vat

EU VAT for Easy Digital Downloads by Barn2

https://barn2.com/wordpress-plugins/easy-digital-downloads-eu-vat/

This project is a fork of our legacy EU VAT for Easy Digital Downloads plugin: #2 (comment)

https://github.com/jeremycollake/edd-eu-vat

Links

wp-pronamic-eu-vat-for-easy-digital-downloads's People

Contributors

remcotolsma avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

wp-pronamic-eu-vat-for-easy-digital-downloads's Issues

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

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.

Plugin name

Our previous EU VAT plugin for Easy Digital Downloads was named "Easy Digital Downloads - VAT". Because of the "Plugins must respect trademarks, copyrights, and project names." guideline our new Easy Digital Downloads 3.0 plugin for EU VAT is named "Pronamic - EU VAT for Easy Digital Downloads".

17. Plugins must respect trademarks, copyrights, and project names.

The use of trademarks or other projects as the sole or initial term of a plugin slug is prohibited unless proof of legal ownership/representation can be confirmed. For example, the WordPress Foundation has trademarked the term “WordPress” and it is a violation to use “wordpress” in a domain name. This policy extends to plugin slugs, and we will not permit a slug to begin with another product’s term.

For example only employees of Super Sandbox should use the slug “super-sandbox,” or their brand in a context such as “Super Sandbox Dancing Sloths.” Non-employees should use a format such as “Dancing Sloths for Superbox” instead to avoid potentially misleading users into believing the plugin was developed by Super Sandbox. Similarly, if you don’t represent the “MellowYellowSandbox.js” project, it’s inappropriate to use that as the name of your plugin.

Original branding is recommended as it not only helps to avoid confusion, but is more memorable to the user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.