Hi @Cronix
Thanks for continuing to take time out of your day to comment here.
It's not really a tax-related issue, well, I don't think it is anyway!
I've put some logging into the swap function in vendor\laravel\cashier-braintree\src\Subscription.php, only used when a user wants to switch subscriptions:
Log::debug("Subscription this: " . $this);
Log::debug("Subscription this owner: " . $this->owner);
Log::debug("Subscription this owner taxPercentage: " . $this->owner->taxPercentage());
When user billing is enabled, this is what is logged:
[2017-09-06 09:31:52] local.DEBUG: Subscription this:
{"id":59, "user_id":166, "name":"default", "braintree_id":"24xhgm", "braintree_plan":"Van-Ind-1", "quantity":1, "trial_ends_at":null, "ends_at":null, "created_at":"2017-09-06 09:31:38", "updated_at":"2017-09-06 09:31:38", "provider_plan":"Van-Ind-1"} // so, the subscription info from the subscriptions table on the database
[2017-09-06 09:31:52] local.DEBUG: Subscription this owner:
{"id":166, "name":"Peter Parker", "first_name":null, "last_name":null, "company":null, "address_line_1":null, "address_line_2":null, "city":null, "county":null, "postcode":null, "email":"[email protected]", "verified":0, "verify_token":null, "photo_url":"https:\/\/www.gravatar.com\/avatar\/37e453f2edf64ba0e2a0fd7fcda793cf.jpg?s=200&d=mm", "uses_two_factor_auth":false, "two_factor_reset_code":null, "current_team_id":null, "braintree_id":"658162114", "address_id":null, "user_braintree_id":null, "user_address_id":null, "current_billing_plan":"Van-Ind-1", "paypal_email":null, "trial_ends_at":null, "last_read_announcements_at":"2017-09-06 09:31:08", "created_at":"2017-09-06 09:31:08", "updated_at":"2017-09-06 09:31:38, "tax_rate":0}
// so, the user info from the database including an added tax_rate of 0. No idea how that got there!
[2017-09-06 09:31:52] local.DEBUG: Subscription this owner taxPercentage: 0
// so, works fine, because there is an owner.
But, with team billing enabled, this is what is logged instead:
[2017-09-06 09:41:30] local.DEBUG: Subscription this:
{"id":130, "team_id":72, "name":"default", "braintree_id":"844ngm", "braintree_plan":"Van-Team-1", "quantity":1, "trial_ends_at":null, "ends_at":null, "created_at":"2017-09-06 09:39:28", "updated_at":"2017-09-06 09:39:28", "provider_plan":"Van-Team-1"}
// so, the subscription info from the team_subscriptions table on the database
[2017-09-06 09:41:30] local.DEBUG: Subscription this owner:
// so, completely empty
[2017-09-06 09:41:30] local.ERROR:
Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function taxPercentage() on null in /var/www/vhosts/rmindr.uk/vanilla-laravel/vendor/laravel/cashier-braintree/src/Subscription.php:146
// fails because the subscription has no owner.
With both types of billing, $this returns the correct subscription from the appropriate database table. With user billing $this->owner returns the user associated with the subscription, with an added tax_rate. Because of there being an owner, the taxPercentage function works fine and returns a value of 0. But, with team billing, $this->owner returns an empty result, it's not even null, so the taxPercentage function fails to run because it has nothing to work with.
What seems to be missing, and, by the looks of it, has ALWAYS been missing, is anything that tells the swap function in the vendor\laravel\cashier-braintree\src\Subscription.php what $this->owner is. It feels like it ought to be the user that is marked in the team_users database table as the appropriate team's owner. But how to tell this function that, and why it doesn't know, 'out of the box,' I am lost!
Any ideas?
With kind regards,
Mark