mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
MSPF-560 Fix legacy withdrawal and p2p events processing (#267)
This commit is contained in:
parent
d7b6297193
commit
94bc46813f
@ -113,6 +113,18 @@ maybe_migrate({created, #{version := 1} = Session}) ->
|
||||
receiver => maybe_migrate_resource(Receiver)
|
||||
}
|
||||
})});
|
||||
maybe_migrate({created, #{version := 2} = Session}) ->
|
||||
#{
|
||||
version := 2,
|
||||
provider_id := ProviderID
|
||||
} = Session,
|
||||
maybe_migrate({created, genlib_map:compact(maps:without([provider_id], Session#{
|
||||
version => 3,
|
||||
route => #{
|
||||
provider_id => ProviderID + 400
|
||||
},
|
||||
provider_id_legacy => ProviderID
|
||||
}))});
|
||||
% Other events
|
||||
maybe_migrate({callback, _Ev} = Event) ->
|
||||
p2p_callback_utils:maybe_migrate(Event);
|
||||
@ -148,6 +160,162 @@ unmarshal(Type, Value) ->
|
||||
{Result, _Context} = unmarshal(Type, Value, #{}),
|
||||
Result.
|
||||
|
||||
-spec created_v0_1_decoding_test() -> _.
|
||||
created_v0_1_decoding_test() ->
|
||||
Fees = #{fees => #{operation_amount => {100, <<"RUB">>}}},
|
||||
TransferParams = #{
|
||||
id => <<"2">>,
|
||||
body => {10000, <<"RUB">>},
|
||||
sender => {bank_card, #{bank_card => #{
|
||||
bin => <<"555555">>,
|
||||
bin_data_id => 279896,
|
||||
card_type => credit,
|
||||
cardholder_name => <<"sender">>,
|
||||
exp_date => {10, 2022},
|
||||
iso_country_code => bra,
|
||||
masked_pan => <<"4444">>,
|
||||
payment_system => mastercard,
|
||||
token => <<"token">>
|
||||
}}},
|
||||
receiver => {bank_card, #{bank_card => #{
|
||||
bin => <<"424242">>,
|
||||
bin_data_id => 279896,
|
||||
card_type => credit,
|
||||
cardholder_name => <<"receiver">>,
|
||||
exp_date => {10, 2022},
|
||||
iso_country_code => gbr,
|
||||
masked_pan => <<"4242">>,
|
||||
payment_system => visa,
|
||||
token => <<"token">>
|
||||
}}},
|
||||
provider_fees => Fees
|
||||
},
|
||||
|
||||
P2PSession = #{
|
||||
version => 3,
|
||||
id => <<"2">>,
|
||||
status => active,
|
||||
transfer_params => TransferParams,
|
||||
route => #{provider_id => 401},
|
||||
provider_id_legacy => 1,
|
||||
domain_revision => 123,
|
||||
party_revision => 321
|
||||
},
|
||||
Change = {created, P2PSession},
|
||||
Event = {ev, {{{2020, 3, 4}, {13, 27, 20}}, 136850}, Change},
|
||||
|
||||
LegacyEvent = {arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"ev">>},
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{arr, [{str, <<"tup">>}, {i, 2020}, {i, 3}, {i, 4}]},
|
||||
{arr, [{str, <<"tup">>}, {i, 13}, {i, 27}, {i, 20}]}
|
||||
]},
|
||||
{i, 136850}
|
||||
]},
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"created">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"adapter">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"event_handler">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"scoper_woody_event_handler">>},
|
||||
{arr, [
|
||||
{str, <<"map">>}, {obj, #{}}
|
||||
]}
|
||||
]},
|
||||
{str, <<"url">>} => {bin, <<"http://adapter-mockapter:8022/adapter/mockapter/p2p">>}
|
||||
}}
|
||||
]},
|
||||
{arr, [{str, <<"map">>}, {obj, #{{bin, <<"k">>} => {bin, <<"v">>}}}]}
|
||||
]},
|
||||
{str, <<"domain_revision">>} => {i, 123},
|
||||
{str, <<"id">>} => {bin, <<"2">>},
|
||||
{str, <<"party_revision">>} => {i, 321},
|
||||
{str, <<"provider_id">>} => {i, 1},
|
||||
{str, <<"status">>} => {str, <<"active">>},
|
||||
{str, <<"transfer_params">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"body">>} => {arr, [{str, <<"tup">>}, {i, 10000}, {bin, <<"RUB">>}]},
|
||||
{str, <<"id">>} => {bin, <<"2">>},
|
||||
{str, <<"provider_fees">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"fees">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"operation_amount">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{i, 100},
|
||||
{bin, <<"RUB">>}
|
||||
]}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
]},
|
||||
{str, <<"receiver">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"bank_card">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"bin">>} => {bin, <<"424242">>},
|
||||
{str, <<"bin_data_id">>} => {i, 279896},
|
||||
{str, <<"card_type">>} => {str, <<"credit">>},
|
||||
{str, <<"cardholder_name">>} => {bin, <<"receiver">>},
|
||||
{str, <<"exp_date">>} => {arr, [
|
||||
{str, <<"tup">>}, {i, 10}, {i, 2022}
|
||||
]},
|
||||
{str, <<"iso_country_code">>} => {str, <<"gbr">>},
|
||||
{str, <<"masked_pan">>} => {bin, <<"4242">>},
|
||||
{str, <<"payment_system">>} => {str, <<"visa">>},
|
||||
{str, <<"token">>} => {bin, <<"token">>}
|
||||
}}
|
||||
]}
|
||||
]},
|
||||
{str, <<"sender">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"bank_card">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"bin">>} => {bin, <<"555555">>},
|
||||
{str, <<"bin_data_id">>} => {i, 279896},
|
||||
{str, <<"card_type">>} => {str, <<"credit">>},
|
||||
{str, <<"cardholder_name">>} => {bin, <<"sender">>},
|
||||
{str, <<"exp_date">>} => {arr, [
|
||||
{str, <<"tup">>}, {i, 10}, {i, 2022}
|
||||
]},
|
||||
{str, <<"iso_country_code">>} => {str, <<"bra">>},
|
||||
{str, <<"masked_pan">>} => {bin, <<"4444">>},
|
||||
{str, <<"payment_system">>} => {str, <<"mastercard">>},
|
||||
{str, <<"token">>} => {bin, <<"token">>}
|
||||
}}
|
||||
]}
|
||||
]}
|
||||
}}
|
||||
]},
|
||||
{str, <<"version">>} => {i, 1}
|
||||
}}
|
||||
]}
|
||||
]}
|
||||
]},
|
||||
DecodedLegacy = unmarshal({event, undefined}, LegacyEvent),
|
||||
ModernizedBinary = marshal({event, 1}, DecodedLegacy),
|
||||
Decoded = unmarshal({event, 1}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec created_v0_2_decoding_test() -> _.
|
||||
created_v0_2_decoding_test() ->
|
||||
Resource = {bank_card, #{bank_card => #{
|
||||
@ -168,11 +336,12 @@ created_v0_2_decoding_test() ->
|
||||
},
|
||||
|
||||
P2PSession = #{
|
||||
version => 2,
|
||||
version => 3,
|
||||
id => <<"session">>,
|
||||
status => active,
|
||||
transfer_params => TransferParams,
|
||||
provider_id => 1,
|
||||
route => #{provider_id => 401},
|
||||
provider_id_legacy => 1,
|
||||
domain_revision => 123,
|
||||
party_revision => 321
|
||||
},
|
||||
|
@ -113,7 +113,7 @@ maybe_migrate({created, Session = #{version := 3, withdrawal := Withdrawal = #{
|
||||
receiver => try_migrate_to_adapter_identity(Receiver)
|
||||
}}),
|
||||
maybe_migrate({created, NewSession}, Context);
|
||||
maybe_migrate({created, #{version := 2} = Session}, Context) ->
|
||||
maybe_migrate({created, #{version := 2} = Session}, Context) when is_map_key(provider, Session) ->
|
||||
KnowndLegacyIDs = #{
|
||||
<<"mocketbank">> => 1,
|
||||
<<"royalpay-payout">> => 2,
|
||||
@ -141,6 +141,19 @@ maybe_migrate({created, #{version := 2} = Session}, Context) ->
|
||||
provider_legacy => LegacyProviderID
|
||||
},
|
||||
maybe_migrate({created, NewSession}, Context);
|
||||
maybe_migrate({created, #{version := 2} = Session}, Context) when not is_map_key(provider, Session) ->
|
||||
#{
|
||||
adapter := {Client, _Opts}
|
||||
} = Session,
|
||||
#{
|
||||
url := Url,
|
||||
event_handler := scoper_woody_event_handler
|
||||
} = Client,
|
||||
LegacyUrls = #{
|
||||
<<"http://adapter-royalpay:8022/adapter/royalpay/p2p-credit">> => <<"royalpay">>,
|
||||
<<"http://proxy-mocketbank:8022/proxy/mocketbank/p2p-credit">> => <<"mocketbank">>
|
||||
},
|
||||
maybe_migrate({created, Session#{provider => maps:get(Url, LegacyUrls)}}, Context);
|
||||
maybe_migrate({created, Session = #{version := 1, withdrawal := Withdrawal = #{
|
||||
sender := Sender,
|
||||
receiver := Receiver
|
||||
@ -591,6 +604,134 @@ created_v0_unknown_with_binary_provider_decoding_test() ->
|
||||
Decoded = unmarshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec created_v0_unknown_without_provider_decoding_test() -> _.
|
||||
created_v0_unknown_without_provider_decoding_test() ->
|
||||
Session = #{
|
||||
version => 4,
|
||||
id => <<"294">>,
|
||||
route => #{
|
||||
provider_id => 301
|
||||
},
|
||||
provider_legacy => <<"mocketbank">>,
|
||||
status => active,
|
||||
withdrawal => #{
|
||||
cash => {10000000, <<"RUB">>},
|
||||
id => <<"294">>,
|
||||
receiver => #{id => <<"receiver_id">>},
|
||||
sender => #{id => <<"sender_id">>},
|
||||
resource => {bank_card, #{bank_card => #{
|
||||
bin => <<"123456">>,
|
||||
masked_pan => <<"1234">>,
|
||||
payment_system => visa,
|
||||
token => <<"token">>
|
||||
}}}
|
||||
}
|
||||
},
|
||||
Change = {created, Session},
|
||||
Event = {ev, {{{2018, 9, 5}, {11, 21, 57}}, 119792}, Change},
|
||||
LegacyEvent = {arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"ev">>},
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{arr, [{str, <<"tup">>}, {i, 2018}, {i, 9}, {i, 5}]},
|
||||
{arr, [{str, <<"tup">>}, {i, 11}, {i, 21}, {i, 57}]}
|
||||
]},
|
||||
{i, 119792}
|
||||
]},
|
||||
{arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"created">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"adapter">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"event_handler">>} => {str, <<"scoper_woody_event_handler">>},
|
||||
{str, <<"url">>} => {bin,
|
||||
<<"http://proxy-mocketbank:8022/proxy/mocketbank/p2p-credit">>
|
||||
}
|
||||
}}
|
||||
]},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{}}
|
||||
]}
|
||||
]},
|
||||
{str, <<"id">>} => {bin, <<"294">>},
|
||||
{str, <<"status">>} => {str, <<"active">>},
|
||||
{str, <<"withdrawal">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"cash">>} => {arr, [{str, <<"tup">>}, {i, 10000000}, {bin, <<"RUB">>}]},
|
||||
{str, <<"destination">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"account">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"accounter_account_id">>} => {i, 11895},
|
||||
{str, <<"currency">>} => {bin, <<"RUB">>},
|
||||
{str, <<"id">>} => {bin, <<"destination">>},
|
||||
{str, <<"identity">>} => {bin, <<"destination_identity">>}
|
||||
}}
|
||||
]},
|
||||
{str, <<"name">>} => {bin, <<"Customer">>},
|
||||
{str, <<"resource">>} => {arr, [
|
||||
{str, <<"tup">>},
|
||||
{str, <<"bank_card">>},
|
||||
{arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"bin">>} => {bin, <<"123456">>},
|
||||
{str, <<"masked_pan">>} => {bin, <<"1234">>},
|
||||
{str, <<"payment_system">>} => {str, <<"visa">>},
|
||||
{str, <<"token">>} => {bin, <<"token">>}
|
||||
}}
|
||||
]}
|
||||
]},
|
||||
{str, <<"status">>} => {str, <<"authorized">>}
|
||||
}}
|
||||
]},
|
||||
{str, <<"id">>} => {bin, <<"294">>},
|
||||
{str, <<"receiver">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"class">>} => {bin, <<"person">>},
|
||||
{str, <<"contract">>} => {bin, <<"123">>},
|
||||
{str, <<"id">>} => {bin, <<"receiver_id">>},
|
||||
{str, <<"level">>} => {bin, <<"anonymous">>},
|
||||
{str, <<"party">>} => {bin, <<"123">>},
|
||||
{str, <<"provider">>} => {bin, <<"test">>}
|
||||
}}
|
||||
]},
|
||||
{str, <<"sender">>} => {arr, [
|
||||
{str, <<"map">>},
|
||||
{obj, #{
|
||||
{str, <<"class">>} => {bin, <<"person">>},
|
||||
{str, <<"contract">>} => {bin, <<"123">>},
|
||||
{str, <<"id">>} => {bin, <<"sender_id">>},
|
||||
{str, <<"level">>} => {bin, <<"anonymous">>},
|
||||
{str, <<"party">>} => {bin, <<"321">>},
|
||||
{str, <<"provider">>} => {bin, <<"test">>}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
]}
|
||||
}}
|
||||
]}
|
||||
]}
|
||||
]},
|
||||
{DecodedLegacy, _Context} = unmarshal({event, undefined}, LegacyEvent, #{bindata_fun => fun(R) -> R end}),
|
||||
ModernizedBinary = marshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, DecodedLegacy),
|
||||
Decoded = unmarshal({event, ?CURRENT_EVENT_FORMAT_VERSION}, ModernizedBinary),
|
||||
?assertEqual(Event, Decoded).
|
||||
|
||||
-spec next_state_v0_decoding_test() -> _.
|
||||
next_state_v0_decoding_test() ->
|
||||
Change = {next_state, <<"next_state">>},
|
||||
|
@ -265,19 +265,23 @@ maybe_migrate_cash_flow(#{postings := CashFlowPostings} = CashFlow, EvType) ->
|
||||
|
||||
% Some cashflow in early withdrawals has been created with binary accounter_account_id
|
||||
maybe_migrate_posting(#{
|
||||
sender := #{accounter_account_id := SenderAcc} = Sender
|
||||
sender := #{account := #{accounter_account_id := SenderAcc} = Account} = Sender
|
||||
} = Posting, EvType) when is_binary(SenderAcc) ->
|
||||
maybe_migrate_posting(Posting#{
|
||||
sender := Sender#{
|
||||
accounter_account_id := erlang:binary_to_integer(SenderAcc)
|
||||
account := Account#{
|
||||
accounter_account_id := erlang:binary_to_integer(SenderAcc)
|
||||
}
|
||||
}
|
||||
}, EvType);
|
||||
maybe_migrate_posting(#{
|
||||
receiver := #{accounter_account_id := ReceiverAcc} = Receiver
|
||||
receiver := #{account := #{accounter_account_id := ReceiverAcc} = Account} = Receiver
|
||||
} = Posting, EvType) when is_binary(ReceiverAcc) ->
|
||||
maybe_migrate_posting(Posting#{
|
||||
receiver := Receiver#{
|
||||
accounter_account_id := erlang:binary_to_integer(ReceiverAcc)
|
||||
account := Account#{
|
||||
accounter_account_id := erlang:binary_to_integer(ReceiverAcc)
|
||||
}
|
||||
}
|
||||
}, EvType);
|
||||
maybe_migrate_posting(#{receiver := Receiver, sender := Sender} = Posting, EvType) ->
|
||||
|
Loading…
Reference in New Issue
Block a user