mirror of
https://github.com/valitydev/fistful-server.git
synced 2024-11-06 02:35:18 +00:00
TD-454: Add allow support (#50)
* added allow support * added no reduced test * added temp fix * reverted test config * fixed * added base values to varset * updated party management * Revert "added base values to varset" This reverts commita3c1cb5277
. * Revert "fixed" This reverts commit1a9cac77bd
.
This commit is contained in:
parent
5603d671b9
commit
1e74eb0c73
@ -460,6 +460,18 @@ domain_config(Options) ->
|
||||
condition(cost_in, {903000, <<"RUB">>}),
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 19)
|
||||
),
|
||||
delegate(
|
||||
condition(cost_in, {910000, <<"RUB">>}),
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 30)
|
||||
),
|
||||
delegate(
|
||||
condition(cost_in, {920000, <<"RUB">>}),
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 31)
|
||||
),
|
||||
delegate(
|
||||
condition(cost_in, {930000, <<"RUB">>}),
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 32)
|
||||
),
|
||||
delegate(
|
||||
{condition,
|
||||
{payment_tool,
|
||||
@ -591,6 +603,27 @@ domain_config(Options) ->
|
||||
]}
|
||||
),
|
||||
|
||||
routing_ruleset(
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 30),
|
||||
{candidates, [
|
||||
candidate({constant, true}, ?trm(3000))
|
||||
]}
|
||||
),
|
||||
|
||||
routing_ruleset(
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 31),
|
||||
{candidates, [
|
||||
candidate({constant, true}, ?trm(3100))
|
||||
]}
|
||||
),
|
||||
|
||||
routing_ruleset(
|
||||
?ruleset(?PAYINST1_ROUTING_POLICIES + 32),
|
||||
{candidates, [
|
||||
candidate({constant, true}, ?trm(3200))
|
||||
]}
|
||||
),
|
||||
|
||||
routing_ruleset(
|
||||
?ruleset(?PAYINST1_ROUTING_PROHIBITIONS),
|
||||
<<"PayInst1 Withdrawal Prohibitions">>,
|
||||
@ -922,6 +955,46 @@ domain_config(Options) ->
|
||||
}
|
||||
),
|
||||
|
||||
ct_domain:withdrawal_terminal(
|
||||
?trm(3000),
|
||||
?prv(1),
|
||||
#domain_ProvisionTermSet{
|
||||
wallet = #domain_WalletProvisionTerms{
|
||||
withdrawals = #domain_WithdrawalProvisionTerms{
|
||||
allow = {constant, true}
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
ct_domain:withdrawal_terminal(
|
||||
?trm(3100),
|
||||
?prv(1),
|
||||
#domain_ProvisionTermSet{
|
||||
wallet = #domain_WalletProvisionTerms{
|
||||
withdrawals = #domain_WithdrawalProvisionTerms{
|
||||
allow = {constant, false},
|
||||
turnover_limit =
|
||||
{value, [
|
||||
?trnvrlimit(?LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID2, 123123)
|
||||
]}
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
ct_domain:withdrawal_terminal(
|
||||
?trm(3200),
|
||||
?prv(1),
|
||||
#domain_ProvisionTermSet{
|
||||
wallet = #domain_WalletProvisionTerms{
|
||||
withdrawals = #domain_WithdrawalProvisionTerms{
|
||||
allow = {condition, {category_is, ?cat(1)}}
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
ct_domain:currency(?cur(<<"RUB">>)),
|
||||
ct_domain:currency(?cur(<<"USD">>)),
|
||||
ct_domain:currency(?cur(<<"EUR">>)),
|
||||
|
@ -11,7 +11,6 @@
|
||||
-export([make_route/2]).
|
||||
-export([get_provider/1]).
|
||||
-export([get_terminal/1]).
|
||||
-export([merge_withdrawal_terms/2]).
|
||||
-export([routes/1]).
|
||||
-export([log_reject_context/1]).
|
||||
|
||||
@ -135,33 +134,6 @@ get_provider(#{provider_id := ProviderID}) ->
|
||||
get_terminal(Route) ->
|
||||
maps:get(terminal_id, Route, undefined).
|
||||
|
||||
-spec merge_withdrawal_terms(
|
||||
ff_payouts_provider:provision_terms() | undefined,
|
||||
ff_payouts_terminal:provision_terms() | undefined
|
||||
) -> ff_maybe:maybe(withdrawal_provision_terms()).
|
||||
merge_withdrawal_terms(
|
||||
#domain_WithdrawalProvisionTerms{
|
||||
currencies = PCurrencies,
|
||||
payout_methods = PPayoutMethods,
|
||||
cash_limit = PCashLimit,
|
||||
cash_flow = PCashflow
|
||||
},
|
||||
#domain_WithdrawalProvisionTerms{
|
||||
currencies = TCurrencies,
|
||||
payout_methods = TPayoutMethods,
|
||||
cash_limit = TCashLimit,
|
||||
cash_flow = TCashflow
|
||||
}
|
||||
) ->
|
||||
#domain_WithdrawalProvisionTerms{
|
||||
currencies = ff_maybe:get_defined(TCurrencies, PCurrencies),
|
||||
payout_methods = ff_maybe:get_defined(TPayoutMethods, PPayoutMethods),
|
||||
cash_limit = ff_maybe:get_defined(TCashLimit, PCashLimit),
|
||||
cash_flow = ff_maybe:get_defined(TCashflow, PCashflow)
|
||||
};
|
||||
merge_withdrawal_terms(ProviderTerms, TerminalTerms) ->
|
||||
ff_maybe:get_defined(TerminalTerms, ProviderTerms).
|
||||
|
||||
-spec routes(routing_state()) ->
|
||||
{ok, [route()]} | {error, route_not_found}.
|
||||
routes(#{routes := Routes = [_ | _]}) ->
|
||||
@ -296,6 +268,7 @@ do_validate_limits(CombinedTerms, PartyVarset, Route, RoutingContext) ->
|
||||
do_validate_terms(CombinedTerms, PartyVarset, _Route, _RoutingContext) ->
|
||||
do(fun() ->
|
||||
#domain_WithdrawalProvisionTerms{
|
||||
allow = Allow,
|
||||
currencies = CurrenciesSelector,
|
||||
%% PayoutMethodsSelector is useless for withdrawals
|
||||
%% so we can just ignore it
|
||||
@ -303,6 +276,7 @@ do_validate_terms(CombinedTerms, PartyVarset, _Route, _RoutingContext) ->
|
||||
cash_limit = CashLimitSelector
|
||||
} = CombinedTerms,
|
||||
valid = unwrap(validate_selectors_defined(CombinedTerms)),
|
||||
valid = unwrap(validate_allow(Allow)),
|
||||
valid = unwrap(validate_currencies(CurrenciesSelector, PartyVarset)),
|
||||
valid = unwrap(validate_cash_limit(CashLimitSelector, PartyVarset))
|
||||
end).
|
||||
@ -324,6 +298,18 @@ validate_selectors_defined(Terms) ->
|
||||
{error, terms_undefined}
|
||||
end.
|
||||
|
||||
validate_allow(Constant) ->
|
||||
case Constant of
|
||||
undefined ->
|
||||
{ok, valid};
|
||||
{constant, true} ->
|
||||
{ok, valid};
|
||||
{constant, false} ->
|
||||
{error, {terms_violation, terminal_forbidden}};
|
||||
Ambiguous ->
|
||||
{error, {misconfiguration, {'Could not reduce predicate to a value', {allow, Ambiguous}}}}
|
||||
end.
|
||||
|
||||
-spec validate_currencies(currency_selector(), party_varset()) ->
|
||||
{ok, valid}
|
||||
| {error, Error :: term()}.
|
||||
|
@ -32,6 +32,9 @@
|
||||
|
||||
%% Tests
|
||||
|
||||
-export([allow_route_test/1]).
|
||||
-export([not_allow_route_test/1]).
|
||||
-export([not_reduced_allow_route_test/1]).
|
||||
-export([adapter_unreachable_route_test/1]).
|
||||
-export([adapter_unreachable_route_retryable_test/1]).
|
||||
-export([adapter_unreachable_quote_test/1]).
|
||||
@ -70,6 +73,9 @@ all() ->
|
||||
groups() ->
|
||||
[
|
||||
{default, [
|
||||
allow_route_test,
|
||||
not_allow_route_test,
|
||||
not_reduced_allow_route_test,
|
||||
adapter_unreachable_route_test,
|
||||
adapter_unreachable_route_retryable_test,
|
||||
adapter_unreachable_quote_test,
|
||||
@ -116,6 +122,69 @@ end_per_testcase(_Name, _C) ->
|
||||
|
||||
%% Tests
|
||||
|
||||
-spec allow_route_test(config()) -> test_return().
|
||||
allow_route_test(C) ->
|
||||
Currency = <<"RUB">>,
|
||||
Cash = {910000, Currency},
|
||||
#{
|
||||
wallet_id := WalletID,
|
||||
destination_id := DestinationID
|
||||
} = prepare_standard_environment(Cash, C),
|
||||
WithdrawalID = generate_id(),
|
||||
WithdrawalParams = #{
|
||||
id => WithdrawalID,
|
||||
destination_id => DestinationID,
|
||||
wallet_id => WalletID,
|
||||
body => Cash,
|
||||
external_id => WithdrawalID
|
||||
},
|
||||
ok = ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new()),
|
||||
?assertEqual(succeeded, await_final_withdrawal_status(WithdrawalID)).
|
||||
|
||||
-spec not_allow_route_test(config()) -> test_return().
|
||||
not_allow_route_test(C) ->
|
||||
Currency = <<"RUB">>,
|
||||
Cash = {920000, Currency},
|
||||
#{
|
||||
wallet_id := WalletID,
|
||||
destination_id := DestinationID
|
||||
} = prepare_standard_environment(Cash, C),
|
||||
WithdrawalID = generate_id(),
|
||||
WithdrawalParams = #{
|
||||
id => WithdrawalID,
|
||||
destination_id => DestinationID,
|
||||
wallet_id => WalletID,
|
||||
body => Cash,
|
||||
external_id => WithdrawalID
|
||||
},
|
||||
ok = ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new()),
|
||||
?assertMatch(
|
||||
{failed, #{code := <<"no_route_found">>}},
|
||||
await_final_withdrawal_status(WithdrawalID)
|
||||
).
|
||||
|
||||
-spec not_reduced_allow_route_test(config()) -> test_return().
|
||||
not_reduced_allow_route_test(C) ->
|
||||
Currency = <<"RUB">>,
|
||||
Cash = {930000, Currency},
|
||||
#{
|
||||
wallet_id := WalletID,
|
||||
destination_id := DestinationID
|
||||
} = prepare_standard_environment(Cash, C),
|
||||
WithdrawalID = generate_id(),
|
||||
WithdrawalParams = #{
|
||||
id => WithdrawalID,
|
||||
destination_id => DestinationID,
|
||||
wallet_id => WalletID,
|
||||
body => Cash,
|
||||
external_id => WithdrawalID
|
||||
},
|
||||
ok = ff_withdrawal_machine:create(WithdrawalParams, ff_entity_context:new()),
|
||||
?assertMatch(
|
||||
{failed, #{code := <<"no_route_found">>}},
|
||||
await_final_withdrawal_status(WithdrawalID)
|
||||
).
|
||||
|
||||
-spec adapter_unreachable_route_test(config()) -> test_return().
|
||||
adapter_unreachable_route_test(C) ->
|
||||
Currency = <<"RUB">>,
|
||||
|
@ -28,7 +28,7 @@ services:
|
||||
command: /sbin/init
|
||||
|
||||
dominant:
|
||||
image: ghcr.io/valitydev/dominant:sha-b978f94
|
||||
image: ghcr.io/valitydev/dominant:sha-5009e22
|
||||
command: /opt/dominant/bin/dominant foreground
|
||||
depends_on:
|
||||
machinegun:
|
||||
@ -87,7 +87,7 @@ services:
|
||||
retries: 20
|
||||
|
||||
party-management:
|
||||
image: ghcr.io/valitydev/party-management:sha-bbbeae5
|
||||
image: ghcr.io/valitydev/party-management:sha-bc8368d
|
||||
command: /opt/party-management/bin/party-management foreground
|
||||
depends_on:
|
||||
machinegun:
|
||||
|
@ -22,11 +22,11 @@
|
||||
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2},
|
||||
{<<"damsel">>,
|
||||
{git,"https://github.com/valitydev/damsel.git",
|
||||
{ref,"9362c08657d1681240d70f923fc04642bbfecc0a"}},
|
||||
{ref,"d59017c42e41e2e94f79a9c2260a814fe0b0ca77"}},
|
||||
0},
|
||||
{<<"dmt_client">>,
|
||||
{git,"https://github.com/valitydev/dmt_client.git",
|
||||
{ref,"ce6678af1499230fe13f8b34258aabe8b92ac722"}},
|
||||
{ref,"19a8ded17c05140f663c7b8b30450d9a1da4f53e"}},
|
||||
0},
|
||||
{<<"dmt_core">>,
|
||||
{git,"https://github.com/valitydev/dmt-core.git",
|
||||
|
Loading…
Reference in New Issue
Block a user