1717 get_user_active_membership_to_association_membership ,
1818)
1919from app .core .myeclpay import cruds_myeclpay , schemas_myeclpay
20+ from app .core .myeclpay .integrity_myeclpay import (
21+ format_cancel_log ,
22+ format_refund_log ,
23+ format_transaction_log ,
24+ format_transfer_log ,
25+ )
2026from app .core .myeclpay .models_myeclpay import Store , WalletDevice
2127from app .core .myeclpay .types_myeclpay import (
2228 HistoryType ,
7379
7480hyperion_error_logger = logging .getLogger ("hyperion.error" )
7581hyperion_security_logger = logging .getLogger ("hyperion.security" )
82+ hyperion_myeclpay_logger = logging .getLogger ("hyperion.myeclpay" )
7683
7784
7885@router .get (
@@ -1674,20 +1681,18 @@ async def add_transfer_by_admin(
16741681 status_code = 403 ,
16751682 detail = "Wallet balance would exceed the maximum allowed balance" ,
16761683 )
1677-
1678- await cruds_myeclpay .create_transfer (
1679- db = db ,
1680- transfer = schemas_myeclpay .Transfer (
1681- id = uuid .uuid4 (),
1682- type = transfer_info .transfer_type ,
1683- approver_user_id = user .id ,
1684- total = transfer_info .amount ,
1685- transfer_identifier = "" , # TODO: require to provide an identifier
1686- wallet_id = user_payment .wallet_id ,
1687- creation = datetime .now (UTC ),
1688- confirmed = True ,
1689- ),
1684+ creation_date = datetime .now (UTC )
1685+ transfer = schemas_myeclpay .Transfer (
1686+ id = uuid .uuid4 (),
1687+ type = transfer_info .transfer_type ,
1688+ approver_user_id = user .id ,
1689+ total = transfer_info .amount ,
1690+ transfer_identifier = "" , # TODO: require to provide an identifier
1691+ wallet_id = user_payment .wallet_id ,
1692+ creation = creation_date ,
1693+ confirmed = True ,
16901694 )
1695+ await cruds_myeclpay .create_transfer (transfer , db )
16911696 await cruds_myeclpay .increment_wallet_balance (
16921697 wallet_id = user_payment .wallet_id ,
16931698 amount = transfer_info .amount ,
@@ -1698,6 +1703,7 @@ async def add_transfer_by_admin(
16981703 except Exception :
16991704 await db .rollback ()
17001705 raise
1706+ hyperion_myeclpay_logger .info (format_transfer_log (transfer ))
17011707
17021708 message = Message (
17031709 title = "💳 Paiement - transfert" ,
@@ -2158,24 +2164,28 @@ async def store_scan_qrcode(
21582164 db = db ,
21592165 )
21602166 transaction_id = uuid .uuid4 ()
2161- # We create a transaction
2162- await cruds_myeclpay . create_transaction (
2163- transaction_id = transaction_id ,
2167+ creation_date = datetime . now ( UTC )
2168+ transaction = schemas_myeclpay . Transaction (
2169+ id = transaction_id ,
21642170 debited_wallet_id = debited_wallet_device .wallet_id ,
2165- debited_wallet_device_id = debited_wallet_device .id ,
21662171 credited_wallet_id = store .wallet_id ,
21672172 transaction_type = TransactionType .DIRECT ,
21682173 seller_user_id = user .id ,
21692174 total = scan_info .tot ,
2170- creation = datetime . now ( UTC ) ,
2175+ creation = creation_date ,
21712176 status = TransactionStatus .CONFIRMED ,
2177+ )
2178+ # We create a transaction
2179+ await cruds_myeclpay .create_transaction (
2180+ transaction = transaction ,
2181+ debited_wallet_device_id = debited_wallet_device .id ,
21722182 store_note = None ,
21732183 db = db ,
21742184 )
21752185
21762186 await db .commit ()
21772187
2178- # TODO: log the transaction
2188+ hyperion_myeclpay_logger . info ( format_transaction_log ( transaction ))
21792189
21802190 message = Message (
21812191 title = f"💳 Paiement - { store .name } " ,
@@ -2187,16 +2197,7 @@ async def store_scan_qrcode(
21872197 message = message ,
21882198 )
21892199
2190- return schemas_myeclpay .Transaction (
2191- id = transaction_id ,
2192- debited_wallet_id = debited_wallet_device .wallet_id ,
2193- credited_wallet_id = store .wallet_id ,
2194- transaction_type = TransactionType .DIRECT ,
2195- seller_user_id = user .id ,
2196- total = scan_info .tot ,
2197- creation = datetime .now (UTC ),
2198- status = TransactionStatus .CONFIRMED ,
2199- )
2200+ return transaction
22002201
22012202
22022203@router .post (
@@ -2325,18 +2326,21 @@ async def refund_transaction(
23252326 db = db ,
23262327 )
23272328
2329+ creation_date = datetime .now (UTC )
2330+ refund = schemas_myeclpay .RefundBase (
2331+ id = uuid .uuid4 (),
2332+ transaction_id = transaction_id ,
2333+ total = refund_amount ,
2334+ seller_user_id = user .id
2335+ if wallet_previously_credited .type == WalletType .STORE
2336+ else None ,
2337+ credited_wallet_id = wallet_previously_debited .id ,
2338+ debited_wallet_id = wallet_previously_credited .id ,
2339+ creation = creation_date ,
2340+ )
2341+
23282342 await cruds_myeclpay .create_refund (
2329- refund = schemas_myeclpay .RefundBase (
2330- id = uuid .uuid4 (),
2331- transaction_id = transaction_id ,
2332- total = refund_amount ,
2333- seller_user_id = user .id
2334- if wallet_previously_credited .type == WalletType .STORE
2335- else None ,
2336- credited_wallet_id = wallet_previously_debited .id ,
2337- debited_wallet_id = wallet_previously_credited .id ,
2338- creation = datetime .now (UTC ),
2339- ),
2343+ refund = refund ,
23402344 db = db ,
23412345 )
23422346
@@ -2355,6 +2359,8 @@ async def refund_transaction(
23552359
23562360 await db .commit ()
23572361
2362+ hyperion_myeclpay_logger .info (format_refund_log (refund ))
2363+
23582364 if wallet_previously_debited .user is not None :
23592365 message = Message (
23602366 title = "💳 Remboursement" ,
@@ -2499,6 +2505,8 @@ async def cancel_transaction(
24992505
25002506 await db .commit ()
25012507
2508+ hyperion_myeclpay_logger .info (format_cancel_log (transaction_id ))
2509+
25022510 if debited_wallet .user is not None :
25032511 message = Message (
25042512 title = "💳 Paiement annulé" ,
0 commit comments