strangerstudios / paid-memberships-pro

WordPress membership plugin to restrict access to content and charge recurring subscriptions using Stripe, PayPal, and more. Fully open source. 100% GPL.
https://www.paidmembershipspro.com
Other
452 stars 352 forks source link

Stripe gateway wraps tax amount into total rather than setting using tax_percent field #273

Open shankie-codes opened 8 years ago

shankie-codes commented 8 years ago

For both subscriptions and single payments, the Stripe gateway adds the tax amount directly to the total rather than using Stripe's tax_percent

The two examples I've found are:

https://github.com/strangerstudios/paid-memberships-pro/blob/dev/classes/gateways/class.pmprogateway_stripe.php#L1092 https://github.com/strangerstudios/paid-memberships-pro/blob/dev/classes/gateways/class.pmprogateway_stripe.php#L1373

I'll do a bit of investigation and if I get anywhere open a PR – but any help would be kindly appreciated!

shankie-codes commented 8 years ago

I've found a solution – rather than filtering pmpro_tax (which looks to just add tax onto the total), I've instead added a tax element onto the subscription object. This is likely to be a Stripe-specific solution, so I think that the original problem still needs addressing, but this works in my case for 20% UK VAT:

// Update the tax calculation if buyer is in the UK
function customtax_region_tax_check()
{
  // check if a country is set. If it is and the country is GB, then add on VAT
  if(isset($_REQUEST['bcountry']) && $_REQUEST['bcountry'] == 'GB')
  {
    //update the session var
    $_SESSION['bcountry'] = $_REQUEST['bcountry'];  

    // Add VAT
    add_filter('pmpro_stripe_create_subscription_array', function($subscription){
      $subscription['tax_percent'] = 20;
      return $subscription;
    }, 20);
  }
}
add_action("init", "customtax_region_tax_check");
strangerstudios commented 6 years ago

We will look into passing the tax amount to Stripe separate of the total.