diff --git a/dist/lib/payments/stripe.js b/dist/lib/payments/stripe.js index 4d0d00b..abe290e 100644 --- a/dist/lib/payments/stripe.js +++ b/dist/lib/payments/stripe.js @@ -66,7 +66,7 @@ class StripeFacade { } async findPaymentIntent(paymentIntentId) { return this.stripe.paymentIntents.retrieve(paymentIntentId, { - expand: ['payment_method.card'], + expand: ['payment_method.card', 'charges.data.balance_transaction'], }); } } diff --git a/dist/lib/payments/stripe.js.map b/dist/lib/payments/stripe.js.map index a27be86..9e492f2 100644 --- a/dist/lib/payments/stripe.js.map +++ b/dist/lib/payments/stripe.js.map @@ -1 +1 @@ -{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../../src/lib/payments/stripe.ts"],"names":[],"mappings":";;;;;AAAA,oDAA2B;AAG3B,MAAqB,YAAY;IAG/B;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE;YACtD,UAAU,EAAE,YAAY;SACzB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE;QACzC,IAAI,MAAM,GAAG,IAAI,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;SACxC;QAED,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAA;QAErD,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;YAChD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;YAChC,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,QAAQ,CAAC,EAAE;YACrB,kBAAkB,EAAE,aAAa;SAClC,CAAC,CAAA;QAEF,OAAO,CAAC,CAAC,aAAa,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE;QAC/B,IAAI,Q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AC/B,WAAW,EAAE,IAAI;YACjB,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,eAAe;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,aAAa;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,aAAa,EAAE;YACtD,MAAM,EAAE,CAAC,qBAAqB,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;IAED,YAAY,CAAC,SAAS,EAAE,IAAI;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAA;IAChG,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,eAAe;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,eAAe,EAAE;YAC1D,MAAM,EAAE,CAAC,qBAAqB,EAAE,kCAAkC,CAAC;SACpE,CAAC,CAAA;IACJ,CAAC;CACF;AAnFD,+BAmFC"} \ No newline at end of file diff --git a/dist/lib/payments/taxes/taxes.js b/dist/lib/payments/taxes/taxes.js index 0655009..46aaefe 100644 --- a/dist/lib/payments/taxes/taxes.js +++ b/dist/lib/payments/taxes/taxes.js @@ -48,9 +48,7 @@ async function calculateFees(stripeSales, gumroadInvoices) { for (const gumroadInvoice of gumroadInvoices) { incomes += gumroadInvoice.amount; } - const rate = await quotation_1.default(moment_1.default().format('DD.MM.YYYY'), 'USD'); - const fee = utils_1.round(utils_1.round(incomes * rate) * 0.23); - return fee; + return utils_1.round(incomes * 0.23); } async function findStripeSales(services) { const customers = await services.customerRepository.findCustomersWithInvoicesLastMonth(); @@ -74,7 +72,8 @@ async function downloadStripeInvoices(services, stripeSales) { fs.writeFileSync(path.join(tmpPath, 'data', sale.blobName), invoiceBuffer); } } -async function renderInvoicesXml(services, sales) { +async function renderPohodaXml(services, sales) { + var _a, _b, _c; const id = new Date().getFullYear() + '-' + new Date().getMonth() + 'POHODA'; for (const s of sales) { const countryEnum = countries_1.default.find(c => c.name === s.accountingData.country); @@ -82,6 +81,13 @@ async function renderInvoicesXml(services, sales) { if (s.accountingData.currency === 'usd') { s.accountingData.currencyRate = await quotation_1.default(moment_1.default(s.purchaseDate).format('DD.MM.YYYY'), 'USD'); } + if (s.stripe) { + const pi = await services.stripe.findPaymentIntent(s.stripe.paymentIntentId); + if (((_a = pi.charges) === null || _a === void 0 ? void 0 : _a.data) && ((_c = (_b = pi.charges) === null || _b === void 0 ? void 0 : _b.data[0]) === null || _c === void 0 ? void 0 : _c.balance_transaction)) { + const feeInCents = pi.charges.data[0].balance_transaction.fee; + Object.assign(s.accountingData, { fee: utils_1.round(feeInCents / 100) }); + } + } } await services.renderInvoice({ id, @@ -131,7 +137,7 @@ function convertPeruInvoiceToSale(invoice) { } }; } -function createFeeSale(price) { +async function createFeeSale(price) { const vatAmount = utils_1.round(price * 0.21); const id = new Date().getFullYear() + '-' + new Date().getMonth() + 'F'; return { @@ -144,7 +150,8 @@ function createFeeSale(price) { country: 'Czech Republic', isEU: true, vatRate: 21, - currency: 'czk', + currencyRate: await quotation_1.default(moment_1.default(new Date()).format('DD.MM.YYYY'), 'USD'), + currency: 'usd', price: price, amount: utils_1.round(price + vatAmount), vatAmount, @@ -165,10 +172,10 @@ const createTaxes = (services) => async (data) => { } const stripeSales = await findStripeSales(services); const feesAmount = await calculateFees(stripeSales, data.gumroadInvoices); - const feeSale = createFeeSale(feesAmount); + const feeSale = await createFeeSale(feesAmount); await renderSale(services, feeSale, '/payments/invoice fee'); await downloadStripeInvoices(services, stripeSales); - await renderInvoicesXml(services, [peruSale, ...gumroadSales, ...stripeSales, feeSale]); + await renderPohodaXml(services, [peruSale, ...gumroadSales, ...stripeSales, feeSale]); const archive = archiver_1.default('zip'); const output = fs.createWriteStream(path.join(tmpPath, 'taxes.zip')); archive.pipe(output); diff --git a/dist/lib/payments/taxes/taxes.js.map b/dist/lib/payments/taxes/taxes.js.map index d661767..88790f7 100644 --- a/dist/lib/payments/taxes/taxes.js.map +++ b/dist/lib/payments/taxes/taxes.js.map @@ -1 +1 @@ -{"version":3,"file":"taxes.js","sourceRoot":"","sources":["../../../../src/lib/payments/taxes/taxes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAA+B;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAC3D,+CAAgC;AAChC,uCAAwB;AACxB,2CAA4B;AAC5B,uCAAwB;AACxB,oDAA2B;AAE3B,4DAAmC;AACnC,6CAAyC;AACzC,4DAA8B;AAC9B,4DAAmC;AAYnC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;AAE3D,KAAK,UAAU,UAAU,CAAC,QAAkB,EAAE,IAAU,EAAE,YAAoB;IAC1E,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;IAChD,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IAClE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,aAAa,CAAC,CAAA;AACjF,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,WAAwB,EAAE,eAA+B;IAClF,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QAClC,OAAO,IAAI,UAAU,CAAC,cAAc,CAAC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;QAC3B,OAAO,CAAC,QAAQ,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;AAC/D,CAAC,CAAA;AAjCY,QAAA,WAAW,eAiCvB"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7621f7c..bdbeec0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16226,6 +16226,7 @@ "version": "8.81.0", "resolved": "https://registry.npmjs.org/stripe/-/stripe-8.81.0.tgz", "integrity": "sha512-eGnx3WcP7fsn0uCxuPSb7UQj7U3yZLv9WE5rIU2LArgggaq54fejNvf7IbzUs1jDhoJRgUERJylc651WmbF/ow==", + "license": "MIT", "dependencies": { "@types/node": ">=8.1.0", "qs": "^6.6.0" diff --git a/src/lib/payments/customer.ts b/src/lib/payments/customer.ts index 5906e92..332eafc 100644 --- a/src/lib/payments/customer.ts +++ b/src/lib/payments/customer.ts @@ -17,7 +17,7 @@ export type AccountingData = { currencyRate?: number, isExpense?: boolean, countryCode?: string, - email: string + email: string } export type Sale = { diff --git a/src/lib/payments/stripe.ts b/src/lib/payments/stripe.ts index b754b9d..7f14fc4 100644 --- a/src/lib/payments/stripe.ts +++ b/src/lib/payments/stripe.ts @@ -81,7 +81,7 @@ export default class StripeFacade { async findPaymentIntent(paymentIntentId) { return this.stripe.paymentIntents.retrieve(paymentIntentId, { - expand: ['payment_method.card'], + expand: ['payment_method.card', 'charges.data.balance_transaction'], }) } } diff --git a/src/lib/payments/taxes/taxes.ts b/src/lib/payments/taxes/taxes.ts index 8243e91..cbc76aa 100644 --- a/src/lib/payments/taxes/taxes.ts +++ b/src/lib/payments/taxes/taxes.ts @@ -11,6 +11,7 @@ import quotation from './quotation' import { round } from '../../utils/utils' import iconv from 'iconv-lite' import countries from './countries' +import Stripe from 'stripe' declare type Invoice = { date: Date, @@ -40,10 +41,7 @@ async function calculateFees(stripeSales: Array, gumroadInvoices: Array) { +async function renderPohodaXml(services: Services, sales: Array) { const id = new Date().getFullYear() + '-' + new Date().getMonth() + 'POHODA' for (const s of sales) { @@ -83,6 +81,14 @@ async function renderInvoicesXml(services: Services, sales: Array) { if (s.accountingData.currency === 'usd') { s.accountingData.currencyRate = await quotation(moment(s.purchaseDate).format('DD.MM.YYYY'), 'USD') } + + if (s.stripe) { + const pi = await services.stripe.findPaymentIntent(s.stripe.paymentIntentId) + if (pi.charges?.data && pi.charges?.data[0]?.balance_transaction) { + const feeInCents = (pi.charges.data[0].balance_transaction).fee + Object.assign(s.accountingData, { fee: round(feeInCents / 100)}) + } + } } await services.renderInvoice({ @@ -136,7 +142,7 @@ function convertPeruInvoiceToSale(invoice: Invoice): Sale { } } -function createFeeSale(price): Sale { +async function createFeeSale(price): Promise { const vatAmount = round(price * 0.21) const id = new Date().getFullYear() + '-' + new Date().getMonth() + 'F' return { @@ -149,7 +155,8 @@ function createFeeSale(price): Sale { country: 'Czech Republic', isEU: true, vatRate: 21, - currency: 'czk', + currencyRate: await quotation(moment(new Date()).format('DD.MM.YYYY'), 'USD'), + currency: 'usd', price: price, amount: round(price + vatAmount), vatAmount, @@ -175,11 +182,11 @@ export const createTaxes = (services: Services) => async (data: TaxesRequest) => const stripeSales = await findStripeSales(services) const feesAmount = await calculateFees(stripeSales, data.gumroadInvoices) - const feeSale = createFeeSale(feesAmount) + const feeSale = await createFeeSale(feesAmount) await renderSale(services, feeSale, '/payments/invoice fee') await downloadStripeInvoices(services, stripeSales) - await renderInvoicesXml(services, [peruSale, ...gumroadSales, ...stripeSales, feeSale]) + await renderPohodaXml(services, [peruSale, ...gumroadSales, ...stripeSales, feeSale]) const archive = archiver('zip') const output = fs.createWriteStream(path.join(tmpPath, 'taxes.zip'))