@@ -80,6 +80,72 @@ def build_expected_payload(mapping_codes, negative_amount: false)
8080 end
8181 end
8282
83+ context "with Product fees" do
84+ subject ( :fees_payload ) do
85+ described_class . new ( integration :, customer :, invoice :, integration_customer :, fees :) . body . sole [ "fees" ]
86+ end
87+
88+ let ( :organization ) { create ( :organization ) }
89+ let ( :billing_entity ) { create ( :billing_entity , organization :) }
90+ let ( :integration ) { create ( :avalara_integration , organization :) }
91+ let ( :customer ) { create ( :customer , organization :, billing_entity :) }
92+ let ( :integration_customer ) { create ( :avalara_customer , integration :, customer :) }
93+ let ( :invoice ) { create ( :invoice , organization :, billing_entity :, customer :) }
94+ let ( :subscription ) { create ( :subscription , organization :, customer :) }
95+ let ( :fixed_product ) { create ( :product , :fixed , organization :) }
96+ let ( :usage_product ) { create ( :product , organization :) }
97+ let ( :fixed_rate_card ) { create ( :rate_card , organization :, product : fixed_product ) }
98+ let ( :usage_rate_card ) { create ( :rate_card , organization :, product : usage_product ) }
99+ let ( :fixed_rate ) { create ( :rate_card_rate , organization :, rate_card : fixed_rate_card ) }
100+ let ( :usage_rate ) { create ( :rate_card_rate , organization :, rate_card : usage_rate_card ) }
101+ let ( :fixed_fee ) do
102+ create ( :product_fee , invoice :, subscription :, rate_card_rate : fixed_rate , units : 2 , amount_cents : 250 )
103+ end
104+ let ( :usage_fee ) do
105+ create ( :product_fee , invoice :, subscription :, rate_card_rate : usage_rate , units : 3 , amount_cents : 375 )
106+ end
107+ let ( :fees ) { [ fixed_fee , usage_fee ] }
108+
109+ before do
110+ create (
111+ :avalara_mapping ,
112+ integration :,
113+ organization :,
114+ billing_entity :,
115+ mappable : fixed_product ,
116+ settings : { external_id : "fixed-product" }
117+ )
118+ create (
119+ :avalara_mapping ,
120+ integration :,
121+ organization :,
122+ mappable : usage_product ,
123+ settings : { external_id : "usage-product" }
124+ )
125+ end
126+
127+ it "uses Product mappings for fixed and usage fees" do
128+ expect ( fees_payload ) . to match_array (
129+ [
130+ {
131+ "item_key" => fixed_fee . item_key ,
132+ "item_id" => fixed_fee . id ,
133+ "item_code" => "fixed-product" ,
134+ "unit" => 2.0 ,
135+ "amount" => "2.5"
136+ } ,
137+ {
138+ "item_key" => usage_fee . item_key ,
139+ "item_id" => usage_fee . id ,
140+ "item_code" => "usage-product" ,
141+ "unit" => 3.0 ,
142+ "amount" => "3.75"
143+ }
144+ ]
145+ )
146+ end
147+ end
148+
83149 describe "shipping address fallback" do
84150 let ( :integration ) { create ( :avalara_integration ) }
85151 let ( :customer ) do
0 commit comments