Coverage for functions \ flipdare \ payments \ dto \ transfer_dto.py: 38%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13from __future__ import annotations 

14from typing import Self 

15from stripe import Transfer as StripeTransfer 

16 

17from flipdare.generated.shared.stripe.stripe_currency_code import StripeCurrencyCode 

18from flipdare.payments.dto.safe_stripe_object import SafeStripeObject 

19 

20 

21class TransferDTO: 

22 def __init__( 

23 self, 

24 transfer_id: str, 

25 destination_id: str, 

26 amount: int, 

27 amount_reversed: int, 

28 currency_code: StripeCurrencyCode, 

29 ) -> None: 

30 self.transfer_id = transfer_id 

31 self.destination_id = destination_id 

32 self.amount = amount 

33 # this can be different to amount, e.g. stripe fees, app fees.. 

34 self.amount_reversed = amount_reversed 

35 self.currency_code = currency_code 

36 

37 @property 

38 def id(self) -> str: 

39 return self.transfer_id 

40 

41 @classmethod 

42 def from_stripe_transfer(cls, transfer: StripeTransfer) -> Self: 

43 

44 safe = SafeStripeObject(transfer) 

45 transfer_id = safe.id.unwrap() 

46 destination_id = safe.destination.unwrap() 

47 

48 amount = safe.amount.unwrap() 

49 amount_reversed = safe.amount_reversed.unwrap() 

50 currency = safe.currency.unwrap() 

51 

52 currency_code: StripeCurrencyCode | None = None 

53 try: 

54 currency_code = StripeCurrencyCode.from_stripe(currency) 

55 except ValueError as err: 

56 raise ValueError( 

57 f"Unsupported currency code: {currency} for transfer {transfer_id}" 

58 ) from err 

59 

60 return cls( 

61 transfer_id=transfer_id, 

62 destination_id=destination_id, 

63 amount=amount, 

64 amount_reversed=amount_reversed, 

65 currency_code=currency_code, 

66 )