strangerstudios / pmpro-vat-tax

Calculate VAT tax at membership checkout with Paid Memberships Pro. Allows customers with a VAT Number to avoid the tax.
https://www.paidmembershipspro.com/add-ons/vat-tax/
8 stars 20 forks source link

Fatal error: Uncaught Error: Call to a member function checkVat() #51

Closed michaelbeil closed 7 months ago

michaelbeil commented 2 years ago

Describe the bug As reported in ticket 414552 (moderators only), there is an error after purchasing a membership.

To Reproduce Steps to reproduce the behavior:

  1. Make a purchase with the VAT Add On activated, select a country, and pay by check.
  2. See error: Fatal error: Uncaught Error: Call to a member function checkVat() on null in /test/app/public/wp-content/plugins/pmpro-vat-tax/includes/vatValidation.class.php on line 30

Screenshots image Expected behavior There should not be an error shown.

Isolating the problem:

WordPress Environment

``` Paid Memberships Pro 2.7.5, Pay by Check Add On 0.10, VAT Add On 0.7.1, Twenty Twenty-One 1.4, WordPress 5.9.3, and PHP 7.4.1. ```
michaelbeil commented 2 years ago

When creating a new order without using a VAT number, the tax is charged as it should. But if someone tries to buy the plan using a valid VAT number it gives the 500 error.

TRACE: Vat Translation Error SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' : failed to load external entity "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl" 

( ! )  Fatal error: Uncaught Error: Call to a member function checkVat() on  null in /Users/xxyy/Local  Sites/test/app/public/wp-content/plugins/pmpro-vat-tax-refactor/includes/lib/vat-validation/vatValidation.class.php  on line 30
--  

1 | 0.0005 | 378408 | {main}(  ) | .../index.php:0
2 | 0.0005 | 378688 | require( '/Users/xxyy/Local Sites/test/app/public/wp-blog-header.php' ) | .../index.php:17
3 | 0.1910 | 5467368 | wp(  ) | .../wp-blog-header.php:16
4 | 0.1910 | 5467400 | WP->main(  ) | .../functions.php:1310
5 | 0.1955 | 5527440 | do_action_ref_array(  ) | .../class-wp.php:771
6 | 0.1955 | 5527440 | WP_Hook->do_action(  ) | .../plugin.php:522
7 | 0.1955 | 5527440 | WP_Hook->apply_filters(  ) | .../class-wp-hook.php:331
8 | 0.1971 | 5531624 | pmpro_wp(  ) | .../class-wp-hook.php:307
9 | 0.1971 | 5536040 | require_once( '/Users/xxyy/Local Sites/test/app/public/wp-content/plugins/paid-memberships-pro/preheaders/checkout.php' ) | .../init.php:76
10 | 0.2013 | 5556792 | pmpro_build_order_for_checkout(  ) | .../checkout.php:444
11 | 0.2552 | 6700648 | MemberOrder->getTaxForPrice(  ) | .../functions.php:3681
12 | 0.2556 | 6717952 | apply_filters(  ) | .../class.memberorder.php:613
13 | 0.2556 | 6718360 | WP_Hook->apply_filters(  ) | .../plugin.php:189
14 | 0.2556 | 6719864 | pmprovat_pmpro_tax(  ) | .../class-wp-hook.php:307
15 | 0.2556 | 6719864 | pmprovat_verify_vat_number(  ) | .../checkout.php:332
16 | 0.8381 | 6722760 | vatValidation->check(  ) | .../functions.php:79
michaelbeil commented 2 years ago

A customer (ticket 436932) is experiencing this. Installing https://github.com/strangerstudios/pmpro-vat-tax/pull/49 resolves the issue.

andrewlimaza commented 1 year ago

I don't think these tickets are related, and the change has no changes to the validation class (files have just been moved around).

I'll continue to reference the original ticket (414552) to try and test that VAT number (if it's still valid) and continue to monitor this. The issue is they're passing a null value to the checkVat() method.

This sounds more like a specific site issue for some reason.

michaelbeil commented 1 year ago

For what it's worth, your commit to dev resolves this.