5555-include_lib (" fistful_proto/include/fistful_fistful_thrift.hrl" ).
5656-include_lib (" fistful_proto/include/fistful_wthd_thrift.hrl" ).
5757-include_lib (" fistful_proto/include/fistful_wthd_status_thrift.hrl" ).
58+ -include_lib (" fistful_proto/include/fistful_cashflow_thrift.hrl" ).
5859
5960% % Pipeline
6061
@@ -455,9 +456,11 @@ unmarshal(withdrawal, #wthd_WithdrawalState{
455456 created_at = CreatedAt ,
456457 metadata = Metadata ,
457458 quote = Quote ,
458- contact_info = ContactInfo
459+ contact_info = ContactInfo ,
460+ effective_final_cash_flow = EffectiveFinalCashFlow
459461}) ->
460462 UnmarshaledMetadata = maybe_unmarshal (context , Metadata ),
463+ Fee = maybe_unmarshal_fee (Status , EffectiveFinalCashFlow ),
461464 genlib_map :compact (
462465 maps :merge (
463466 #{
@@ -470,7 +473,8 @@ unmarshal(withdrawal, #wthd_WithdrawalState{
470473 <<" externalID" >> => ExternalID ,
471474 <<" metadata" >> => UnmarshaledMetadata ,
472475 <<" quote" >> => maybe_unmarshal (quote_state , Quote ),
473- <<" contactInfo" >> => maybe_unmarshal (contact_info , ContactInfo )
476+ <<" contactInfo" >> => maybe_unmarshal (contact_info , ContactInfo ),
477+ <<" fee" >> => Fee
474478 },
475479 unmarshal_status (Status )
476480 )
@@ -544,3 +548,49 @@ unmarshal_status({failed, #wthd_status_Failed{failure = BaseFailure}}) ->
544548 wapi_codec :convert (withdrawal_status , {failed , BaseFailure });
545549unmarshal_status (Status ) ->
546550 wapi_codec :convert (withdrawal_status , Status ).
551+
552+ maybe_unmarshal_fee ({succeeded , _ }, EffectiveFinalCashFlow ) ->
553+ cashflow_wallet_to_system_fee (EffectiveFinalCashFlow );
554+ maybe_unmarshal_fee (_ , _ ) ->
555+ undefined .
556+
557+ cashflow_wallet_to_system_fee (# cashflow_FinalCashFlow {postings = Postings }) ->
558+ FeeAcc = lists :foldl (fun accumulate_wallet_to_system_fee /2 , undefined , Postings ),
559+ case FeeAcc of
560+ undefined ->
561+ undefined ;
562+ {Currency , Amount } ->
563+ #{
564+ <<" amount" >> => Amount ,
565+ <<" currency" >> => Currency
566+ }
567+ end .
568+
569+ accumulate_wallet_to_system_fee (
570+ # cashflow_FinalCashFlowPosting {
571+ source = # cashflow_FinalCashFlowAccount {account_type = {wallet , _ }},
572+ destination = # cashflow_FinalCashFlowAccount {account_type = {system , _ }},
573+ volume = Cash
574+ },
575+ Acc
576+ ) ->
577+ add_cash_amount (Cash , Acc );
578+ accumulate_wallet_to_system_fee (_ , Acc ) ->
579+ Acc .
580+
581+ add_cash_amount (
582+ # 'fistful_base_Cash' {
583+ amount = Amount ,
584+ currency = # 'fistful_base_CurrencyRef' {symbolic_code = Currency }
585+ },
586+ undefined
587+ ) ->
588+ {Currency , Amount };
589+ add_cash_amount (
590+ # 'fistful_base_Cash' {
591+ amount = Amount ,
592+ currency = # 'fistful_base_CurrencyRef' {symbolic_code = Currency }
593+ },
594+ {Currency , Total }
595+ ) ->
596+ {Currency , Total + Amount }.
0 commit comments