@@ -175,3 +175,75 @@ def test_provider_refund_success():
175175 provider .refund (payment )
176176
177177 assert payment .status == PaymentStatus .CONFIRMED
178+
179+
180+ def test_provider_refund_returns_currency_units ():
181+ payment = Payment ()
182+ payment .status = PaymentStatus .CONFIRMED
183+ payment .total = 30
184+ payment .currency = "USD"
185+ payment .attrs .session ["payment_intent" ] = "pi_..."
186+ provider = StripeProviderV3 (api_key = API_KEY )
187+ return_value = {
188+ "id" : "re_..." ,
189+ "payment_status" : "succeeded" ,
190+ "amount" : 3000 ,
191+ }
192+
193+ with patch ("stripe.Refund.create" , return_value = return_value ) as mock_create :
194+ result = provider .refund (payment )
195+ mock_create .assert_called_once_with (
196+ payment_intent = "pi_..." ,
197+ amount = 3000 ,
198+ reason = "requested_by_customer" ,
199+ )
200+
201+ assert result == 30
202+
203+
204+ def test_provider_refund_partial_returns_currency_units ():
205+ payment = Payment ()
206+ payment .status = PaymentStatus .CONFIRMED
207+ payment .total = 30
208+ payment .currency = "USD"
209+ payment .attrs .session ["payment_intent" ] = "pi_..."
210+ provider = StripeProviderV3 (api_key = API_KEY )
211+ return_value = {
212+ "id" : "re_..." ,
213+ "payment_status" : "succeeded" ,
214+ "amount" : 1500 ,
215+ }
216+
217+ with patch ("stripe.Refund.create" , return_value = return_value ) as mock_create :
218+ result = provider .refund (payment , amount = 15 )
219+ mock_create .assert_called_once_with (
220+ payment_intent = "pi_..." ,
221+ amount = 1500 ,
222+ reason = "requested_by_customer" ,
223+ )
224+
225+ assert result == 15
226+
227+
228+ def test_provider_refund_zero_decimal_currency_returns_currency_units ():
229+ payment = Payment ()
230+ payment .status = PaymentStatus .CONFIRMED
231+ payment .total = 3000
232+ payment .currency = "JPY"
233+ payment .attrs .session ["payment_intent" ] = "pi_..."
234+ provider = StripeProviderV3 (api_key = API_KEY )
235+ return_value = {
236+ "id" : "re_..." ,
237+ "payment_status" : "succeeded" ,
238+ "amount" : 3000 ,
239+ }
240+
241+ with patch ("stripe.Refund.create" , return_value = return_value ) as mock_create :
242+ result = provider .refund (payment , amount = 3000 )
243+ mock_create .assert_called_once_with (
244+ payment_intent = "pi_..." ,
245+ amount = 3000 ,
246+ reason = "requested_by_customer" ,
247+ )
248+
249+ assert result == 3000
0 commit comments