tom-microservice 3.9.17 → 3.9.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -144,23 +144,6 @@ For the rest, **tom** 🐶 will notify you on execution time if any specific con
144
144
 
145
145
  Additionally, you can setup some extra company fields to unlock certain **tom** workflows.
146
146
 
147
- #### Tax Rates
148
-
149
- !> Open an issue for requesting more tax rates strategies!
150
-
151
- If you define `country` and `tax_type` in your company configuration, then customers bills will generated considering the company tax rate declared
152
-
153
- ```yaml
154
- company:
155
- # ... rest of company configuration
156
- country: es
157
- tax_type: vatmoss
158
- ```
159
-
160
- Current strategies supported are:
161
-
162
- - `vatmos`: Use [VATMOSS](https://support.quaderno.io/article/15-eu-vat-compliance-for-digital-products#vatmoss) EU VAT Compliance for Digital Products.
163
-
164
147
  ## Event System
165
148
 
166
149
  !> Event System is only supported with `tom.config.js` configuration file.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tom-microservice",
3
3
  "description": "Tom creates customers, subscriptions plans & send notifications.",
4
4
  "homepage": "https://tom.js.org",
5
- "version": "3.9.17",
5
+ "version": "3.9.18",
6
6
  "main": "src",
7
7
  "bin": {
8
8
  "tom": "bin/index.js"
@@ -44,14 +44,12 @@
44
44
  "acho": "~4.0.6",
45
45
  "beauty-error": "~1.2.15",
46
46
  "cors": "~2.8.5",
47
- "country-vat": "~1.0.8",
48
47
  "got": "~11.8.6",
49
48
  "helmet": "~7.1.0",
50
49
  "http-body": "~1.0.4",
51
50
  "http-compression": "~1.0.5",
52
51
  "import-modules": "~2.1.0",
53
52
  "is-buffer": "~2.0.5",
54
- "is-european": "~1.0.4",
55
53
  "joycon": "~3.1.1",
56
54
  "lodash": "~4.17.21",
57
55
  "mailgen": "~2.0.27",
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
3
  const createStripe = require('stripe')
4
+
4
5
  const { get } = require('lodash')
5
6
 
6
7
  const { wardCredential, ward, is } = require('../../ward')
7
- const createGetTaxRate = require('../../get-tax-rate')
8
8
  const getMetadata = require('../../get-metadata')
9
9
 
10
10
  module.exports = ({ config }) => {
@@ -15,7 +15,6 @@ module.exports = ({ config }) => {
15
15
  if (errFn) return errFn
16
16
 
17
17
  const stripe = createStripe(get(config, 'payment.stripe_key'))
18
- const getTaxRate = createGetTaxRate({ config, stripe })
19
18
 
20
19
  const session = async ({
21
20
  ipAddress,
@@ -30,7 +29,6 @@ module.exports = ({ config }) => {
30
29
  })
31
30
 
32
31
  const metadata = await getMetadata({ ipAddress, headers })
33
- const taxRate = await getTaxRate(metadata)
34
32
 
35
33
  const session = await stripe.checkout.sessions.create({
36
34
  billing_address_collection: 'required',
@@ -38,16 +36,15 @@ module.exports = ({ config }) => {
38
36
  line_items: [
39
37
  {
40
38
  price: planId,
41
- quantity: 1,
42
- tax_rates: taxRate ? [taxRate.id] : undefined
39
+ quantity: 1
43
40
  }
44
41
  ],
45
- subscription_data: {
46
- default_tax_rates: taxRate ? [taxRate.id] : undefined
47
- },
48
42
  tax_id_collection: {
49
43
  enabled: true
50
44
  },
45
+ automatic_tax: {
46
+ enabled: true
47
+ },
51
48
  success_url: successUrl,
52
49
  cancel_url: cancelUrl,
53
50
  metadata: { ...metadata, planId }
@@ -1,60 +0,0 @@
1
- 'use strict'
2
-
3
- const { eeaMember, getCountry } = require('is-european')
4
- const countryVat = require('country-vat')
5
- const { noop } = require('lodash')
6
-
7
- const MAX_TAX_RATES_LIMIT = 100
8
-
9
- const getCountryTaxRate = country => countryVat(country) * 100
10
-
11
- const createTaxRateFactory = stripe => ({ name, alpha2, percentage }) =>
12
- stripe.taxRates.create({
13
- display_name: 'VAT',
14
- description: `VAT ${name}`,
15
- jurisdiction: alpha2,
16
- percentage,
17
- inclusive: true
18
- })
19
-
20
- const vatmoss = ({ config, stripe, getCountryTaxRate }) => {
21
- const createTaxRate = createTaxRateFactory(stripe)
22
-
23
- return async ({ country } = {}) => {
24
- if (!eeaMember(country)) return
25
-
26
- const companyCountry = getCountry(config.company.country)
27
-
28
- const { data: taxRates } = await stripe.taxRates.list({
29
- limit: MAX_TAX_RATES_LIMIT
30
- })
31
-
32
- const taxRate = taxRates.find(
33
- taxRate =>
34
- taxRate.active &&
35
- taxRate.inclusive &&
36
- taxRate.display_name === 'VAT' &&
37
- taxRate.jurisdiction === companyCountry.alpha2
38
- )
39
-
40
- return (
41
- taxRate ||
42
- createTaxRate({
43
- ...companyCountry,
44
- percentage: getCountryTaxRate(config.company.country)
45
- })
46
- )
47
- }
48
- }
49
-
50
- const strategies = { vatmoss }
51
-
52
- module.exports = ({ config, stripe }) => {
53
- const { tax_type: taxType } = config.company
54
- if (taxType === undefined) return noop
55
-
56
- const createStrategy = strategies[taxType]
57
- if (!createStrategy) throw new TypeError('Tax rate strategy not found.')
58
-
59
- return createStrategy({ config, stripe, getCountryTaxRate })
60
- }