Skip to content

Commit

Permalink
TD-717: Add global_allow field
Browse files Browse the repository at this point in the history
  • Loading branch information
ndiezel0 committed Sep 13, 2023
1 parent 18bba50 commit 75deeb9
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
8 changes: 8 additions & 0 deletions apps/party_management/src/pm_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ reduce_provider(Provider, VS, Rev) ->
reduce_provider_terminal_terms(Provider, Terminal, VS, Rev) ->
ProviderTerms = Provider#domain_Provider.terms,
TerminalTerms = Terminal#domain_Terminal.terms,
ct:log("ProviderTerms: ~p~nTerminalTerms: ~p~n", [ProviderTerms, TerminalTerms]),
MergedTerms = merge_provision_term_sets(ProviderTerms, TerminalTerms),
ct:log("MergedTerms: ~p~n", [MergedTerms]),
reduce_provision_term_set(MergedTerms, VS, Rev).

reduce_withdrawal_terms(undefined = Terms, _VS, _Rev) ->
Expand Down Expand Up @@ -188,6 +190,7 @@ merge_provision_term_sets(ProviderTerms, TerminalTerms) ->
merge_payment_terms(
#domain_PaymentsProvisionTerms{
allow = PAllow,
global_allow = PGAllow,
currencies = PCurrencies,
categories = PCategories,
payment_methods = PPaymentMethods,
Expand All @@ -201,6 +204,7 @@ merge_payment_terms(
},
#domain_PaymentsProvisionTerms{
allow = TAllow,
global_allow = TGAllow,
currencies = TCurrencies,
categories = TCategories,
payment_methods = TPaymentMethods,
Expand All @@ -215,6 +219,7 @@ merge_payment_terms(
) ->
#domain_PaymentsProvisionTerms{
allow = pm_utils:select_defined(TAllow, PAllow),
global_allow = pm_utils:select_defined(TGAllow, PGAllow),
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
categories = pm_utils:select_defined(TCategories, PCategories),
payment_methods = pm_utils:select_defined(TPaymentMethods, PPaymentMethods),
Expand Down Expand Up @@ -249,6 +254,7 @@ merge_wallet_terms(ProviderTerms, TerminalTerms) ->
merge_withdrawal_terms(
#domain_WithdrawalProvisionTerms{
allow = PAllow,
global_allow = PGAllow,
currencies = PCurrencies,
payout_methods = PMethods,
cash_limit = PLimit,
Expand All @@ -257,6 +263,7 @@ merge_withdrawal_terms(
},
#domain_WithdrawalProvisionTerms{
allow = TAllow,
global_allow = TGAllow,
currencies = TCurrencies,
payout_methods = TMethods,
cash_limit = TLimit,
Expand All @@ -266,6 +273,7 @@ merge_withdrawal_terms(
) ->
#domain_WithdrawalProvisionTerms{
allow = pm_utils:select_defined(TAllow, PAllow),
global_allow = pm_utils:select_defined(TGAllow, PGAllow),
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
payout_methods = pm_utils:select_defined(TMethods, PMethods),
cash_limit = pm_utils:select_defined(TLimit, PLimit),
Expand Down
83 changes: 83 additions & 0 deletions apps/party_management/test/pm_party_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

-include_lib("party_management/test/pm_ct_domain.hrl").
-include_lib("party_management/include/party_events.hrl").
-include_lib("party_management/include/domain.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("stdlib/include/assert.hrl").
-include_lib("damsel/include/dmsl_payproc_thrift.hrl").
Expand Down Expand Up @@ -100,6 +101,7 @@
-export([compute_provider_ok/1]).
-export([compute_provider_not_found/1]).
-export([compute_provider_terminal_terms_ok/1]).
-export([compute_provider_terminal_terms_global_allow_ok/1]).
-export([compute_provider_terminal_terms_not_found/1]).
-export([compute_provider_terminal_terms_undefined_terms/1]).
-export([compute_provider_terminal_ok/1]).
Expand Down Expand Up @@ -269,6 +271,7 @@ groups() ->
compute_provider_ok,
compute_provider_not_found,
compute_provider_terminal_terms_ok,
compute_provider_terminal_terms_global_allow_ok,
compute_provider_terminal_terms_not_found,
compute_provider_terminal_terms_undefined_terms,
compute_provider_terminal_ok,
Expand Down Expand Up @@ -505,6 +508,7 @@ end_per_testcase(_Name, _C) ->
-spec compute_provider_ok(config()) -> _ | no_return().
-spec compute_provider_not_found(config()) -> _ | no_return().
-spec compute_provider_terminal_terms_ok(config()) -> _ | no_return().
-spec compute_provider_terminal_terms_global_allow_ok(config()) -> _ | no_return().
-spec compute_provider_terminal_terms_not_found(config()) -> _ | no_return().
-spec compute_provider_terminal_terms_undefined_terms(config()) -> _ | no_return().
-spec compute_provider_terminal_ok(config()) -> _ | no_return().
Expand Down Expand Up @@ -1690,6 +1694,34 @@ compute_provider_terminal_terms_ok(C) ->
}
} = pm_client_party:compute_provider_terminal_terms(?prv(1), ?trm(1), DomainRevision, Varset, Client).

compute_provider_terminal_terms_global_allow_ok(C) ->
Client = cfg(client, C),
DomainRevision = pm_domain:head(),
Varset0 = #payproc_Varset{
amount = ?cash(100, <<"RUB">>),
party_id = <<"PARTYID1">>
},
#domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
allow = {constant, false},
global_allow = {constant, false}
}
} = pm_client_party:compute_provider_terminal_terms(?prv(3), ?trm(5), DomainRevision, Varset0, Client),
Varset1 = Varset0#payproc_Varset{party_id = <<"PARTYID2">>},
#domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
allow = {constant, true},
global_allow = {constant, false}
}
} = pm_client_party:compute_provider_terminal_terms(?prv(3), ?trm(5), DomainRevision, Varset1, Client),
Varset2 = Varset0#payproc_Varset{amount = ?cash(101, <<"RUB">>)},
#domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
allow = {constant, false},
global_allow = {constant, true}
}
} = pm_client_party:compute_provider_terminal_terms(?prv(3), ?trm(5), DomainRevision, Varset2, Client).

compute_provider_terminal_terms_not_found(C) ->
Client = cfg(client, C),
DomainRevision = pm_domain:head(),
Expand Down Expand Up @@ -2863,6 +2895,32 @@ construct_domain_fixture() ->
}
}},

{provider, #domain_ProviderObject{
ref = ?prv(3),
data = #domain_Provider{
name = <<"Brovider">>,
description = <<"A provider but bro">>,
proxy = #domain_Proxy{
ref = ?prx(1),
additional = #{
<<"pro">> => <<"vader">>
}
},
terms = #domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
allow = ?partycond(<<"PARTYID1">>, undefined),
global_allow =
{condition,
{cost_in,
?cashrng(
{inclusive, ?cash(100, <<"RUB">>)},
{inclusive, ?cash(100, <<"RUB">>)}
)}}
}
}
}
}},

{terminal, #domain_TerminalObject{
ref = ?trm(1),
data = #domain_Terminal{
Expand Down Expand Up @@ -2925,5 +2983,30 @@ construct_domain_fixture() ->
description = <<"Terminal without terms">>,
provider_ref = ?prv(2)
}
}},

{terminal, #domain_TerminalObject{
ref = ?trm(5),
data = #domain_Terminal{
name = <<"Brominal 5">>,
description = <<"Brominal 5">>,
provider_ref = ?prv(3),
options = #{
<<"term">> => <<"inal">>,
<<"override_terminal">> => <<"terminal">>
},
terms = #domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
allow = ?partycond(<<"PARTYID2">>, undefined),
global_allow =
{condition,
{cost_in,
?cashrng(
{inclusive, ?cash(101, <<"RUB">>)},
{inclusive, ?cash(101, <<"RUB">>)}
)}}
}
}
}
}}
].
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{gproc, "0.9.0"},
{genlib, {git, "https://github.com/valitydev/genlib.git", {branch, "master"}}},
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "TD-717/field"}}},
{payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}},
{mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}},
{dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"bfedcb9dbb0bfdbd7a06a86417b49be6e807b98d"}},
{ref,"1b24f5fffd9be2580b2148b2ef6bc64c21d93140"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",
Expand Down

0 comments on commit 75deeb9

Please sign in to comment.