@blocklet/payment-types 1.21.13 → 1.21.14

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/lib/index.d.ts CHANGED
@@ -33,6 +33,7 @@ import { Meter, TMeter } from './meter';
33
33
  import { MeterEvent, TMeterEvent } from './meter-event';
34
34
  import { AutoRechargeConfig } from './auto-recharge-config';
35
35
  import { ProductVendor } from './product-vendor';
36
+ import { TaxRate } from './tax-rate';
36
37
  declare const models: {
37
38
  CheckoutSession: typeof CheckoutSession;
38
39
  Coupon: typeof Coupon;
@@ -68,6 +69,7 @@ declare const models: {
68
69
  MeterEvent: typeof MeterEvent;
69
70
  AutoRechargeConfig: typeof AutoRechargeConfig;
70
71
  ProductVendor: typeof ProductVendor;
72
+ TaxRate: typeof TaxRate;
71
73
  };
72
74
  export declare function initialize(sequelize: any): void;
73
75
  export default models;
@@ -106,6 +108,7 @@ export * from './meter';
106
108
  export * from './meter-event';
107
109
  export * from './auto-recharge-config';
108
110
  export * from './product-vendor';
111
+ export * from './tax-rate';
109
112
  export type TPriceExpanded = TPrice & {
110
113
  object: 'price';
111
114
  product: TProduct;
@@ -21,6 +21,7 @@ export declare class InvoiceItem extends Model<InferAttributes<InvoiceItem>, Inf
21
21
  subscription_id?: string;
22
22
  subscription_item_id?: string;
23
23
  test_clock_id?: string;
24
+ tax_rate_id?: string;
24
25
  discountable: boolean;
25
26
  discount_amounts: DiscountAmount[];
26
27
  discounts: string[];
@@ -85,6 +86,10 @@ export declare class InvoiceItem extends Model<InferAttributes<InvoiceItem>, Inf
85
86
  type: DataTypes.StringDataType;
86
87
  allowNull: boolean;
87
88
  };
89
+ tax_rate_id: {
90
+ type: DataTypes.StringDataType;
91
+ allowNull: boolean;
92
+ };
88
93
  discountable: {
89
94
  type: DataTypes.AbstractDataTypeConstructor;
90
95
  allowNull: boolean;
package/lib/price.d.ts CHANGED
@@ -46,6 +46,7 @@ export declare class Price extends Model<InferAttributes<Price>, InferCreationAt
46
46
  quantity_available: number;
47
47
  quantity_sold: number;
48
48
  quantity_limit_per_checkout: number;
49
+ tax_behavior?: LiteralUnion<'inclusive' | 'exclusive', string>;
49
50
  static readonly GENESIS_ATTRIBUTES: {
50
51
  id: {
51
52
  type: DataTypes.StringDataType;
package/lib/product.d.ts CHANGED
@@ -19,6 +19,7 @@ export declare class Product extends Model<InferAttributes<Product>, InferCreati
19
19
  metadata?: Record<string, any>;
20
20
  statement_descriptor?: string;
21
21
  nft_factory?: string;
22
+ tax_code?: string;
22
23
  cross_sell?: {
23
24
  cross_sells_to_id: string;
24
25
  };
@@ -93,6 +94,10 @@ export declare class Product extends Model<InferAttributes<Product>, InferCreati
93
94
  type: DataTypes.StringDataType;
94
95
  allowNull: boolean;
95
96
  };
97
+ tax_code: {
98
+ type: DataTypes.StringDataType;
99
+ allowNull: boolean;
100
+ };
96
101
  created_at: {
97
102
  type: DataTypes.DateDataTypeConstructor;
98
103
  defaultValue: DataTypes.AbstractDataTypeConstructor;
@@ -0,0 +1,124 @@
1
+ import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';
2
+ export declare class TaxRate extends Model<InferAttributes<TaxRate>, InferCreationAttributes<TaxRate>> {
3
+ id: CreationOptional<string>;
4
+ livemode: boolean;
5
+ active: boolean;
6
+ country: string;
7
+ state?: string;
8
+ postal_code?: string;
9
+ tax_code?: string;
10
+ percentage: number;
11
+ display_name: string;
12
+ description?: string;
13
+ metadata?: Record<string, any>;
14
+ created_at: CreationOptional<Date>;
15
+ updated_at: CreationOptional<Date>;
16
+ static readonly GENESIS_ATTRIBUTES: {
17
+ id: {
18
+ type: DataTypes.StringDataType;
19
+ primaryKey: boolean;
20
+ allowNull: boolean;
21
+ defaultValue: (size?: number) => string;
22
+ };
23
+ livemode: {
24
+ type: DataTypes.AbstractDataTypeConstructor;
25
+ allowNull: boolean;
26
+ };
27
+ active: {
28
+ type: DataTypes.AbstractDataTypeConstructor;
29
+ defaultValue: boolean;
30
+ };
31
+ country: {
32
+ type: DataTypes.StringDataType;
33
+ allowNull: boolean;
34
+ };
35
+ state: {
36
+ type: DataTypes.StringDataType;
37
+ allowNull: boolean;
38
+ };
39
+ postal_code: {
40
+ type: DataTypes.StringDataType;
41
+ allowNull: boolean;
42
+ };
43
+ tax_code: {
44
+ type: DataTypes.StringDataType;
45
+ allowNull: boolean;
46
+ };
47
+ percentage: {
48
+ type: DataTypes.DecimalDataType;
49
+ allowNull: boolean;
50
+ };
51
+ display_name: {
52
+ type: DataTypes.StringDataType;
53
+ allowNull: boolean;
54
+ };
55
+ description: {
56
+ type: DataTypes.StringDataType;
57
+ allowNull: boolean;
58
+ };
59
+ metadata: {
60
+ type: DataTypes.AbstractDataTypeConstructor;
61
+ allowNull: boolean;
62
+ };
63
+ created_at: {
64
+ type: DataTypes.DateDataTypeConstructor;
65
+ defaultValue: DataTypes.AbstractDataTypeConstructor;
66
+ allowNull: boolean;
67
+ };
68
+ updated_at: {
69
+ type: DataTypes.DateDataTypeConstructor;
70
+ defaultValue: DataTypes.AbstractDataTypeConstructor;
71
+ allowNull: boolean;
72
+ };
73
+ };
74
+ static initialize(sequelize: any): void;
75
+ static associate(): void;
76
+ /**
77
+ * Find matching tax rate for given location and tax code
78
+ *
79
+ * Uses hierarchical scoring (lexicographic ordering) to match tax rates.
80
+ * Priority: postal_code > state > tax_code
81
+ *
82
+ * Note: Country is pre-filtered to ensure postal codes are compared within
83
+ * the correct national context (e.g., prevents US 90210 from matching CA 90210).
84
+ *
85
+ * Score ranges per dimension (0-100):
86
+ * - 100: Exact match
87
+ * - 50-95: Wildcard match (e.g., "902*" prefix matching)
88
+ * - 10: General fallback (rate has no restriction)
89
+ * - 5: Both empty
90
+ */
91
+ static findMatchingRate({ country, state, postalCode, taxCode, livemode, }: {
92
+ country: string;
93
+ state?: string;
94
+ postalCode?: string;
95
+ taxCode?: string;
96
+ livemode?: boolean;
97
+ }): Promise<TaxRate | null>;
98
+ /**
99
+ * Calculate tax amount from tax-inclusive total
100
+ * Formula: tax = total × (rate / (100 + rate))
101
+ */
102
+ static calculateTaxFromInclusive(total: string, percentage: number): string;
103
+ /**
104
+ * Calculate subtotal from tax-inclusive total
105
+ * Formula: subtotal = total - tax
106
+ */
107
+ static calculateSubtotalFromInclusive(total: string, percentage: number): string;
108
+ /**
109
+ * Calculate tax amount for a single invoice item
110
+ * Formula: tax = amount × (rate / 100)
111
+ */
112
+ static calculateTaxForItem(amount: string, percentage: number): string;
113
+ /**
114
+ * Calculate total tax for multiple invoice items
115
+ */
116
+ static calculateTotalTax(items: Array<{
117
+ amount: string;
118
+ tax_rate_id?: string;
119
+ tax_rate?: {
120
+ percentage: number;
121
+ };
122
+ }>): string;
123
+ }
124
+ export type TTaxRate = InferAttributes<TaxRate>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-types",
3
- "version": "1.21.13",
3
+ "version": "1.21.14",
4
4
  "description": "Typings for Payment Kit SDK",
5
5
  "keywords": [
6
6
  "types",
@@ -48,5 +48,5 @@
48
48
  "sequelize": "^6.37.7",
49
49
  "type-fest": "^4.41.0"
50
50
  },
51
- "gitHead": "b101cbdeded522328ac7c5ccd2ba44930467fe25"
51
+ "gitHead": "31f93a8310fe5184be8dd4ff23b362906c8a66cf"
52
52
  }