Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
chore(tax-rate): Unified tax implementation for createGiftFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpLink committed Apr 26, 2024
1 parent 48f4b2b commit 341065b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/core/services/GiftService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import EmailService from "@core/services/EmailService";
import ContactsService from "@core/services/ContactsService";
import OptionsService from "@core/services/OptionsService";

import ContentTransformer from "@api/transformers/ContentTransformer";

import GiftFlow, { GiftForm } from "@models/GiftFlow";
import ContactRole from "@models/ContactRole";

Expand All @@ -27,13 +29,9 @@ export default class GiftService {
/**
* Create a gift flow and return the Stripe session ID
* @param giftForm
* @param defaultTaxRates Tax rate IDs to apply to the checkout, currently unused and untested, see https://docs.stripe.com/billing/taxes/collect-taxes?tax-calculation=tax-rates&lang=node#adding-tax-rates-to-checkout
* @returns Stripe session ID
*/
static async createGiftFlow(
giftForm: GiftForm,
defaultTaxRates?: string[]
): Promise<string> {
static async createGiftFlow(giftForm: GiftForm): Promise<string> {
log.info("Create gift flow", giftForm);

const giftFlow = await GiftService.createGiftFlowWithCode(giftForm);
Expand All @@ -59,9 +57,10 @@ export default class GiftService {
]
};

if (defaultTaxRates) {
const payment = await ContentTransformer.fetchOne("payment");
if (payment.taxRateEnabled) {
params.subscription_data = {
default_tax_rates: defaultTaxRates
default_tax_rates: [payment.stripeTaxRateId]
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/payment/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { stripe } from "@core/lib/stripe";
import { log as mainLogger } from "@core/logging";
import { PaymentForm } from "@core/utils";
import { getChargeableAmount } from "@core/utils/payment";

import ContentTransformer from "@api/transformers/ContentTransformer";

import config from "@config";
Expand Down Expand Up @@ -91,7 +92,6 @@ export async function createSubscription(
};

const payment = await ContentTransformer.fetchOne("payment");

if (payment.taxRateEnabled) {
params.default_tax_rates = [payment.stripeTaxRateId];
}
Expand Down

0 comments on commit 341065b

Please sign in to comment.