Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding options to disable automatic tax calculation and the subscription tax #11

Open
wants to merge 1 commit into
base: v2/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions src/Vendr.PaymentProviders.Stripe/StripeCheckoutPaymentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,19 @@ public override async Task<PaymentFormResult> GenerateFormAsync(PaymentProviderC
// the quantity of the stripe price you want to buy.
lineItemOpts.Quantity = (long)orderLine.Quantity;

// Because we are in charge of what taxes apply, we need to setup a tax rate
// to ensure the price defined in stripe has the relevant taxes applied
var stripePricesIncludeTax = PropertyIsTrue(orderLine.Properties, "stripePriceIncludesTax");
var stripeTaxRate = GetOrCreateStripeTaxRate(ctx, "Subscription Tax", orderLineTaxRate, stripePricesIncludeTax);
if (stripeTaxRate != null)

if (!ctx.Settings.DisableSubscriptionTax)
{
lineItemOpts.TaxRates = new List<string>(new[] { stripeTaxRate.Id });
// Because we are in charge of what taxes apply, we need to setup a tax rate
// to ensure the price defined in stripe has the relevant taxes applied
var stripePricesIncludeTax = PropertyIsTrue(orderLine.Properties, "stripePriceIncludesTax");
var stripeTaxRate = GetOrCreateStripeTaxRate(ctx, "Subscription Tax", orderLineTaxRate, stripePricesIncludeTax);
if (stripeTaxRate != null)
{
lineItemOpts.TaxRates = new List<string>(new[] { stripeTaxRate.Id });
}
}

}
else
{
Expand Down Expand Up @@ -213,14 +218,18 @@ public override async Task<PaymentFormResult> GenerateFormAsync(PaymentProviderC
// as a single subscription item with one price being the line items total price
lineItemOpts.Quantity = (long)orderLine.Quantity;

// If we define the price, then create tax rates that are set to be inclusive
// as this means that we can pass prices inclusive of tax and Stripe works out
// the pre-tax price which would be less suseptable to rounding inconsistancies
var stripeTaxRate = GetOrCreateStripeTaxRate(ctx, "Subscription Tax", orderLineTaxRate, false);
if (stripeTaxRate != null)
if (!ctx.Settings.DisableSubscriptionTax)
{
lineItemOpts.TaxRates = new List<string>(new[] { stripeTaxRate.Id });
// If we define the price, then create tax rates that are set to be inclusive
// as this means that we can pass prices inclusive of tax and Stripe works out
// the pre-tax price which would be less suseptable to rounding inconsistancies
var stripeTaxRate = GetOrCreateStripeTaxRate(ctx, "Subscription Tax", orderLineTaxRate, false);
if (stripeTaxRate != null)
{
lineItemOpts.TaxRates = new List<string>(new[] { stripeTaxRate.Id });
}
}

}

lineItems.Add(lineItemOpts);
Expand Down Expand Up @@ -301,6 +310,14 @@ public override async Task<PaymentFormResult> GenerateFormAsync(PaymentProviderC
sessionOptions.PaymentIntentData.ReceiptEmail = ctx.Order.CustomerInfo.Email;
}

if (ctx.Settings.DisableAutomaticTax)
{
sessionOptions.AutomaticTax = new SessionAutomaticTaxOptions()
{
Enabled = false
};
}

var sessionService = new SessionService();
var session = await sessionService.CreateAsync(sessionOptions);

Expand Down
13 changes: 13 additions & 0 deletions src/Vendr.PaymentProviders.Stripe/StripeCheckoutSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,18 @@ public class StripeCheckoutSettings : StripeSettingsBase
IsAdvanced = true,
SortOrder = 1000400)]
public string PaymentMethodTypes { get; set; }

[PaymentProviderSetting(Name = "Disable Automatic Tax Calculation",
Description = "Flag indicating whether Stripe should automatically calculate tax on a checkout session. Ensure 'Enable automatic tax calculation' is disabled from the stripe dashboard settings.",
IsAdvanced = true,
SortOrder = 1000500)]
public bool DisableAutomaticTax { get; set; }


[PaymentProviderSetting(Name = "Disable Subscription Tax",
Description = "Flag indicating whether to disable the 'Subscription Tax' from being added by default to recurring subscription products based on the order line tax rate.",
IsAdvanced = true,
SortOrder = 1000600)]
public bool DisableSubscriptionTax { get; set; }
}
}