Skip to content

Commit e9e05ce

Browse files
authored
TD-365: Continue trying to create a withdrawal when no binbase data is available (#38)
1 parent b0fddc1 commit e9e05ce

8 files changed

Lines changed: 98 additions & 45 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ check-format:
8080
dialyze:
8181
$(REBAR) as test dialyzer
8282

83+
static-check: check-format lint xref dialyze
84+
8385
release:
8486
$(REBAR) as prod release
8587

apps/ff_cth/src/ct_payment_system.erl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -828,19 +828,26 @@ default_termset(Options) ->
828828
},
829829
#domain_CashFlowDecision{
830830
if_ =
831-
{all_of,
831+
{any_of,
832832
?ordset([
833-
{condition, {currency_is, ?cur(<<"RUB">>)}},
834-
{condition,
835-
{payment_tool,
836-
{bank_card, #domain_BankCardCondition{
837-
definition =
838-
{payment_system, #domain_PaymentSystemCondition{
839-
payment_system_is = #domain_PaymentSystemRef{
840-
id = <<"VISA">>
841-
}
842-
}}
843-
}}}}
833+
{all_of,
834+
?ordset([
835+
{condition, {currency_is, ?cur(<<"RUB">>)}},
836+
{condition,
837+
{payment_tool,
838+
{bank_card, #domain_BankCardCondition{
839+
definition =
840+
{payment_system, #domain_PaymentSystemCondition{
841+
payment_system_is = #domain_PaymentSystemRef{
842+
id = <<"VISA">>
843+
}
844+
}}
845+
}}}}
846+
])},
847+
{all_of,
848+
?ordset([
849+
condition(cost_in, {424242, <<"RUB">>})
850+
])}
844851
])},
845852
then_ =
846853
{value, [

apps/ff_server/src/ff_withdrawal_handler.erl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ handle_function_('GetQuote', {MarshaledParams}, _Opts) ->
6060
woody_error:raise(business, #wthd_IdentityProvidersMismatch{
6161
wallet_provider = ff_codec:marshal(identity_provider, WalletProvider),
6262
destination_provider = ff_codec:marshal(identity_provider, DestinationProvider)
63-
});
64-
{error, {destination_resource, {bin_data, _}}} ->
65-
woody_error:raise(business, #wthd_NoDestinationResourceInfo{})
63+
})
6664
end;
6765
handle_function_('Create', {MarshaledParams, MarshaledContext}, Opts) ->
6866
Params = ff_withdrawal_codec:unmarshal_withdrawal_params(MarshaledParams),
@@ -107,9 +105,7 @@ handle_function_('Create', {MarshaledParams, MarshaledContext}, Opts) ->
107105
woody_error:raise(business, #wthd_IdentityProvidersMismatch{
108106
wallet_provider = ff_codec:marshal(identity_provider, WalletProvider),
109107
destination_provider = ff_codec:marshal(identity_provider, DestinationProvider)
110-
});
111-
{error, {destination_resource, {bin_data, not_found}}} ->
112-
woody_error:raise(business, #wthd_NoDestinationResourceInfo{})
108+
})
113109
end;
114110
handle_function_('Get', {ID, EventRange}, _Opts) ->
115111
ok = scoper:add_meta(#{id => ID}),

apps/ff_server/test/ff_withdrawal_handler_SUITE.erl

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
-export([create_cashlimit_validation_error_test/1]).
2323
-export([create_inconsistent_currency_validation_error_test/1]).
2424
-export([create_currency_validation_error_test/1]).
25-
-export([create_destination_resource_notfound_test/1]).
25+
-export([create_destination_resource_no_bindata_ok_test/1]).
26+
-export([create_destination_resource_no_bindata_fail_test/1]).
2627
-export([create_destination_notfound_test/1]).
2728
-export([create_destination_generic_ok_test/1]).
2829
-export([create_wallet_notfound_test/1]).
@@ -55,7 +56,8 @@ groups() ->
5556
create_cashlimit_validation_error_test,
5657
create_currency_validation_error_test,
5758
create_inconsistent_currency_validation_error_test,
58-
create_destination_resource_notfound_test,
59+
create_destination_resource_no_bindata_ok_test,
60+
create_destination_resource_no_bindata_fail_test,
5961
create_destination_notfound_test,
6062
create_destination_generic_ok_test,
6163
create_wallet_notfound_test,
@@ -280,8 +282,8 @@ create_inconsistent_currency_validation_error_test(C) ->
280282
},
281283
?assertEqual({exception, ExpectedError}, Result).
282284

283-
-spec create_destination_resource_notfound_test(config()) -> test_return().
284-
create_destination_resource_notfound_test(C) ->
285+
-spec create_destination_resource_no_bindata_fail_test(config()) -> test_return().
286+
create_destination_resource_no_bindata_fail_test(C) ->
285287
Cash = make_cash({100, <<"RUB">>}),
286288
#{
287289
wallet_id := WalletID,
@@ -293,9 +295,27 @@ create_destination_resource_notfound_test(C) ->
293295
destination_id = DestinationID,
294296
body = Cash
295297
},
298+
?assertError(
299+
{woody_error, {external, result_unexpected, _}},
300+
call_withdrawal('Create', {Params, #{}})
301+
).
302+
303+
-spec create_destination_resource_no_bindata_ok_test(config()) -> test_return().
304+
create_destination_resource_no_bindata_ok_test(C) ->
305+
%% As per test terms this specific cash amount results in valid cashflow without bin data
306+
Cash = make_cash({424242, <<"RUB">>}),
307+
#{
308+
wallet_id := WalletID,
309+
destination_id := DestinationID
310+
} = prepare_standard_environment(Cash, <<"TEST_NOTFOUND">>, C),
311+
Params = #wthd_WithdrawalParams{
312+
id = generate_id(),
313+
wallet_id = WalletID,
314+
destination_id = DestinationID,
315+
body = Cash
316+
},
296317
Result = call_withdrawal('Create', {Params, #{}}),
297-
ExpectedError = #wthd_NoDestinationResourceInfo{},
298-
?assertEqual({exception, ExpectedError}, Result).
318+
?assertMatch({ok, _}, Result).
299319

300320
-spec create_destination_notfound_test(config()) -> test_return().
301321
create_destination_notfound_test(C) ->

apps/ff_transfer/src/ff_withdrawal.erl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,13 @@ create_resource(
464464
Identity,
465465
DomainRevision
466466
) ->
467-
case ff_resource:get_bin_data(Token, ResourceDescriptor) of
468-
{ok, BinData} ->
469-
Varset = #{
470-
bin_data => ff_dmsl_codec:marshal(bin_data, BinData)
471-
},
472-
{ok, PaymentInstitution} = get_payment_institution(Identity, Varset, DomainRevision),
473-
PaymentSystem = unwrap(ff_payment_institution:payment_system(PaymentInstitution)),
474-
ff_resource:create_bank_card_basic(ResourceBankCardParams, BinData, PaymentSystem);
475-
{error, Error} ->
476-
{error, {bin_data, Error}}
477-
end;
467+
BinData = ff_maybe:from_result(ff_resource:get_bin_data(Token, ResourceDescriptor)),
468+
Varset = #{
469+
bin_data => ff_dmsl_codec:maybe_marshal(bin_data, BinData)
470+
},
471+
{ok, PaymentInstitution} = get_payment_institution(Identity, Varset, DomainRevision),
472+
PaymentSystem = ff_maybe:from_result(ff_payment_institution:payment_system(PaymentInstitution)),
473+
ff_resource:create_bank_card_basic(ResourceBankCardParams, BinData, PaymentSystem);
478474
create_resource(ResourceParams, ResourceDescriptor, _Identity, _DomainRevision) ->
479475
ff_resource:create_resource(ResourceParams, ResourceDescriptor).
480476

apps/ff_transfer/test/ff_withdrawal_SUITE.erl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
-export([create_identity_providers_mismatch_error_test/1]).
3131
-export([create_destination_currency_validation_error_test/1]).
3232
-export([create_currency_validation_error_test/1]).
33-
-export([create_destination_resource_notfound_test/1]).
33+
-export([create_destination_resource_no_bindata_ok_test/1]).
34+
-export([create_destination_resource_no_bindata_fail_test/1]).
3435
-export([create_destination_notfound_test/1]).
3536
-export([create_wallet_notfound_test/1]).
3637
-export([create_ok_test/1]).
@@ -89,7 +90,8 @@ groups() ->
8990
create_destination_currency_validation_error_test,
9091
create_currency_validation_error_test,
9192
create_identity_providers_mismatch_error_test,
92-
create_destination_resource_notfound_test,
93+
create_destination_resource_no_bindata_ok_test,
94+
create_destination_resource_no_bindata_fail_test,
9395
create_destination_notfound_test,
9496
create_wallet_notfound_test,
9597
create_ok_test,
@@ -395,8 +397,8 @@ create_identity_providers_mismatch_error_test(C) ->
395397
Result = ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new()),
396398
?assertMatch({error, {identity_providers_mismatch, {<<"good-two">>, <<"good-one">>}}}, Result).
397399

398-
-spec create_destination_resource_notfound_test(config()) -> test_return().
399-
create_destination_resource_notfound_test(C) ->
400+
-spec create_destination_resource_no_bindata_fail_test(config()) -> test_return().
401+
create_destination_resource_no_bindata_fail_test(C) ->
400402
Cash = {100, <<"RUB">>},
401403
#{
402404
wallet_id := WalletID,
@@ -409,8 +411,28 @@ create_destination_resource_notfound_test(C) ->
409411
wallet_id => WalletID,
410412
body => Cash
411413
},
414+
?assertError(
415+
{badmatch, {error, {invalid_terms, {not_reduced, _}}}},
416+
ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new())
417+
).
418+
419+
-spec create_destination_resource_no_bindata_ok_test(config()) -> test_return().
420+
create_destination_resource_no_bindata_ok_test(C) ->
421+
%% As per test terms this specific cash amount results in valid cashflow without bin data
422+
Cash = {424242, <<"RUB">>},
423+
#{
424+
wallet_id := WalletID,
425+
destination_id := DestinationID
426+
} = prepare_standard_environment(Cash, <<"TEST_NOTFOUND">>, C),
427+
WithdrawalID = generate_id(),
428+
WithdrawalParams = #{
429+
id => WithdrawalID,
430+
destination_id => DestinationID,
431+
wallet_id => WalletID,
432+
body => Cash
433+
},
412434
Result = ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new()),
413-
?assertMatch({error, {destination_resource, {bin_data, not_found}}}, Result).
435+
?assertMatch(ok, Result).
414436

415437
-spec create_destination_notfound_test(config()) -> test_return().
416438
create_destination_notfound_test(C) ->

apps/fistful/src/ff_dmsl_codec.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
-include_lib("damsel/include/dmsl_user_interaction_thrift.hrl").
55

66
-export([unmarshal/2]).
7+
-export([maybe_unmarshal/2]).
78
-export([marshal/2]).
9+
-export([maybe_marshal/2]).
810

911
%% Types
1012

@@ -211,6 +213,7 @@ unmarshal(string, V) when is_binary(V) ->
211213
unmarshal(integer, V) when is_integer(V) ->
212214
V.
213215

216+
-spec maybe_unmarshal(ff_dmsl_codec:type_name(), ff_dmsl_codec:encoded_value()) -> ff_dmsl_codec:decoded_value().
214217
maybe_unmarshal(_Type, undefined) ->
215218
undefined;
216219
maybe_unmarshal(Type, V) ->
@@ -369,6 +372,7 @@ marshal(integer, V) when is_integer(V) ->
369372
marshal(_, Other) ->
370373
Other.
371374

375+
-spec maybe_marshal(ff_dmsl_codec:type_name(), ff_dmsl_codec:decoded_value()) -> ff_dmsl_codec:encoded_value().
372376
maybe_marshal(_Type, undefined) ->
373377
undefined;
374378
maybe_marshal(Type, Value) ->

apps/fistful/src/ff_resource.erl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,15 @@ create_bank_card(#{bank_card := #{token := Token}} = ResourceBankCardParams, Res
312312
{error, {bin_data, Error}}
313313
end.
314314

315-
-spec create_bank_card_basic(resource_bank_card_params(), bin_data(), payment_system() | undefined) -> {ok, resource()}.
315+
-spec create_bank_card_basic(resource_bank_card_params(), bin_data() | undefined, payment_system() | undefined) ->
316+
{ok, resource()}.
316317
create_bank_card_basic(#{bank_card := BankCardParams0} = ResourceBankCardParams, BinData, PaymentSystem) ->
317-
KeyList = [bank_name, issuer_country, card_type, category],
318-
ExtendData0 = maps:with(KeyList, BinData),
319-
ExtendData1 = ExtendData0#{bin_data_id => ff_bin_data:id(BinData)},
318+
ExtendData = create_extended_data(BinData),
320319
BankCardParams1 = genlib_map:compact(BankCardParams0#{payment_system => PaymentSystem}),
321320
{ok,
322321
{bank_card,
323322
genlib_map:compact(#{
324-
bank_card => maps:merge(BankCardParams1, ExtendData1),
323+
bank_card => maps:merge(BankCardParams1, ExtendData),
325324
auth_data => maps:get(auth_data, ResourceBankCardParams, undefined)
326325
})}}.
327326

@@ -361,3 +360,10 @@ create_digital_wallet(#{
361360
-spec create_generic_resource(resource_generic_params()) -> {ok, resource()}.
362361
create_generic_resource(#{generic := Generic}) ->
363362
{ok, {generic, #{generic => Generic}}}.
363+
364+
create_extended_data(undefined) ->
365+
#{};
366+
create_extended_data(BinData) ->
367+
KeyList = [bank_name, issuer_country, card_type, category],
368+
ExtendData0 = maps:with(KeyList, BinData),
369+
ExtendData0#{bin_data_id => ff_bin_data:id(BinData)}.

0 commit comments

Comments
 (0)