Coverage for functions \ flipdare \ payments \ dto \ payment_intent_create_dto.py: 100%

24 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# 

12from flipdare.app_log import LOG 

13from flipdare.generated.shared.model.user.app_fee_type import AppFeeType 

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

15from stripe.params import PaymentIntentCreateParams 

16 

17from flipdare.payments.app_stripe_proxy import IS_DEBUG 

18 

19 

20class PaymentIntentCreateDTO: 

21 __slots__ = [ 

22 "_account_id", 

23 "_amount", 

24 "_currency_code", 

25 "_customer_id", 

26 "_description", 

27 "_fee_type", 

28 "_metadata", 

29 "_platform_account_id", 

30 ] 

31 

32 def __init__( 

33 self, 

34 customer_id: str, 

35 account_id: str, 

36 amount: int, 

37 currency_code: StripeCurrencyCode, 

38 fee_type: AppFeeType, 

39 ) -> None: 

40 self._amount = amount 

41 self._account_id = account_id 

42 self._currency_code = currency_code 

43 self._customer_id = customer_id 

44 self._fee_type = fee_type 

45 

46 def to_params(self) -> PaymentIntentCreateParams: 

47 amount = self._amount 

48 rcpt_currency = self._currency_code.stripe_code 

49 customer_id = self._customer_id 

50 account_id = self._account_id 

51 fee_type = self._fee_type 

52 

53 # !! IMPORTANT !! 

54 # FIXME: this needs to be enabled in production after we migrate to a US based Stripe account. 

55 # to enable 

56 # "payment_method_options": {"card": {"request_extended_authorization": "if_available"}}, 

57 # you must enable in the Stripe Dashboard. 

58 # Go to your Stripe Dashboard payment settings 

59 # Look for the "Extended authorization" or "Authorization controls" section 

60 # Enable the extended authorization feature 

61 

62 params: PaymentIntentCreateParams = { 

63 "amount": amount, 

64 "currency": rcpt_currency, 

65 "capture_method": "manual", # Auth only — no immediate capture 

66 "setup_future_usage": "off_session", # Saves payment method to customer 

67 "payment_method_types": ["card"], 

68 "customer_account": customer_id, 

69 "metadata": { 

70 "fee_type": fee_type.value, 

71 }, 

72 "transfer_data": {"destination": account_id}, 

73 # NOTE: the return url is only required for niche payment 

74 # NOTE: methods. 

75 # NOTE: and is only required if you have 

76 # "automatic_payment_methods": {"enabled": True}, 

77 # "return_url": self.stripe_config.pay_webhook_url, 

78 } 

79 

80 if IS_DEBUG: 

81 msg = ( 

82 f"Created payment intent to {account_id} from {customer_id} with details:\n" 

83 f"\t- Amount: {amount}\n" 

84 f"\t- Currency: {rcpt_currency}\n" 

85 f"\t- Fee Type: {fee_type.name}\n" 

86 f"\t- Params:\n{params}\n" 

87 ) 

88 LOG().debug(msg) 

89 

90 return params