Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/party_management/src/pm_payment_tool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-module(pm_payment_tool).

-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_base_thrift.hrl").

%%

Expand Down Expand Up @@ -193,11 +194,41 @@ test_mobile_commerce_condition_def(
test_mobile_commerce_condition_def(_Cond, _Data) ->
false.

test_generic_condition({resource_field_matches, _}, #domain_GenericPaymentTool{data = undefined}) ->
false;
test_generic_condition(
{resource_field_matches, #domain_GenericResourceCondition{field_path = Path, value = Value}},
#domain_GenericPaymentTool{data = #base_Content{type = Type, data = Data}}
) ->
case decode_content(Type, Data) of
{ok, Result} ->
case get_field_by_path(Path, Result) of
{ok, Value} -> true;
_ -> false
end;
_ ->
false
end;
test_generic_condition({payment_service_is, Ref1}, #domain_GenericPaymentTool{payment_service = Ref2}) ->
Ref1 =:= Ref2;
test_generic_condition(_Cond, _Data) ->
false.

decode_content(<<"application/schema-instance+json; schema=", _/binary>>, Data) ->
{ok, jsx:decode(Data)};
decode_content(<<"application/json">>, Data) ->
{ok, jsx:decode(Data)};
decode_content(Type, _Data) ->
{error, {unsupported, Type}}.

get_field_by_path([], Data) ->
{ok, Data};
get_field_by_path([Key | Path], Data) ->
case maps:get(Key, Data, undefined) of
undefined -> {error, notfound};
Value -> get_field_by_path(Path, Value)
end.

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

Expand Down
2 changes: 2 additions & 0 deletions apps/party_management/test/pm_ct_domain.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
-define(crit(ID), #domain_CriterionRef{id = ID}).
-define(crp(ID), #domain_CashRegisterProviderRef{id = ID}).
-define(gnrc(PS), #domain_GenericPaymentMethod{payment_service = PS}).
-define(gnrc_cond(Path, Value), #domain_GenericResourceCondition{field_path = Path, value = Value}).
-define(gnrc_tool(PS, Data), #domain_GenericPaymentTool{payment_service = PS, data = Data}).

-define(cashrng(Lower, Upper), #domain_CashRange{lower = Lower, upper = Upper}).

Expand Down
50 changes: 41 additions & 9 deletions apps/party_management/test/pm_party_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ compute_payment_institution(C) ->
-spec check_all_payment_methods(config()) -> _.
check_all_payment_methods(C) ->
Client = cfg(client, C),
TermsFun = fun(Type, Object) ->
TermsFun0 = fun(Type, Object) ->
?assertMatch(
#domain_TermSet{
payments = #domain_PaymentsServiceTerms{
Expand All @@ -863,21 +863,47 @@ check_all_payment_methods(C) ->
),
ok
end,

TermsFun1 = fun(Type, Object, PaymentTool) ->
?assertMatch(
#domain_TermSet{
payments = #domain_PaymentsServiceTerms{
payment_methods =
{value, [_]}
}
},
pm_client_party:compute_payment_institution_terms(
?pinst(5),
#payproc_Varset{payment_method = ?pmt(Type, Object), payment_tool = PaymentTool},
Client
)
),
ok
end,
#domain_TermSet{payments = #domain_PaymentsServiceTerms{payment_methods = {value, []}}} =
pm_client_party:compute_payment_institution_terms(
?pinst(5),
#payproc_Varset{payment_method = ?pmt(digital_wallet, ?pmt_srv(<<"wrong-ref">>))},
Client
),

TermsFun(bank_card, ?bank_card(<<"visa">>)),
TermsFun(payment_terminal, ?pmt_srv(<<"alipay">>)),
TermsFun(digital_wallet, ?pmt_srv(<<"qiwi">>)),
TermsFun(mobile, ?mob(<<"mts">>)),
TermsFun(crypto_currency, ?crypta(<<"bitcoin">>)),
TermsFun(bank_card, ?token_bank_card(<<"visa">>, <<"applepay">>)),
TermsFun(bank_card, ?bank_card_no_cvv(<<"visa">>)),
TermsFun(generic, ?gnrc(?pmt_srv(<<"generic">>))).
TermsFun0(bank_card, ?bank_card(<<"visa">>)),
TermsFun0(payment_terminal, ?pmt_srv(<<"alipay">>)),
TermsFun0(digital_wallet, ?pmt_srv(<<"qiwi">>)),
TermsFun0(mobile, ?mob(<<"mts">>)),
TermsFun0(crypto_currency, ?crypta(<<"bitcoin">>)),
TermsFun0(bank_card, ?token_bank_card(<<"visa">>, <<"applepay">>)),
TermsFun0(bank_card, ?bank_card_no_cvv(<<"visa">>)),
TermsFun0(generic, ?gnrc(?pmt_srv(<<"generic">>))),
TermsFun1(
generic,
?gnrc(?pmt_srv(<<"generic1">>)),
{generic,
?gnrc_tool(?pmt_srv(<<"generic1">>), #base_Content{
type = <<"application/json">>,
data = jsx:encode(#{<<"some_path">> => <<"some_value">>})
})}
).

contract_w2w_terms(C) ->
Client = cfg(client, C),
Expand Down Expand Up @@ -2182,6 +2208,10 @@ construct_domain_fixture() ->
{generic, {payment_service_is, ?pmt_srv(<<"generic">>)}},
[?pmt(generic, ?gnrc(?pmt_srv(<<"generic">>)))]
),
mk_payment_decision(
{generic, {resource_field_matches, ?gnrc_cond([<<"some_path">>], <<"some_value">>)}},
[?pmt(generic, ?gnrc(?pmt_srv(<<"generic1">>)))]
),
#domain_PaymentMethodDecision{
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{}}}},
then_ = {value, ordsets:from_list([?pmt(bank_card, ?bank_card(<<"mastercard">>))])}
Expand Down Expand Up @@ -2490,6 +2520,7 @@ construct_domain_fixture() ->
pm_ct_fixture:construct_crypto_currency(?crypta(<<"bitcoin">>), <<"Bitcoin">>),
pm_ct_fixture:construct_tokenized_service(?token_srv(<<"applepay">>), <<"Apple Pay">>),
pm_ct_fixture:construct_payment_service(?pmt_srv(<<"generic">>), <<"Generic">>),
pm_ct_fixture:construct_payment_service(?pmt_srv(<<"generic1">>), <<"Generic1">>),

pm_ct_fixture:construct_payment_method(?pmt(bank_card, ?bank_card(<<"visa">>))),
pm_ct_fixture:construct_payment_method(?pmt(bank_card, ?bank_card(<<"mastercard">>))),
Expand All @@ -2501,6 +2532,7 @@ construct_domain_fixture() ->
pm_ct_fixture:construct_payment_method(?pmt(mobile, ?mob(<<"mts">>))),
pm_ct_fixture:construct_payment_method(?pmt(crypto_currency, ?crypta(<<"bitcoin">>))),
pm_ct_fixture:construct_payment_method(?pmt(generic, ?gnrc(?pmt_srv(<<"generic">>)))),
pm_ct_fixture:construct_payment_method(?pmt(generic, ?gnrc(?pmt_srv(<<"generic1">>)))),

pm_ct_fixture:construct_payment_method(?pmt(payment_terminal, ?pmt_srv(<<"euroset">>))),
pm_ct_fixture:construct_payment_method(?pmt(bank_card, ?bank_card_no_cvv(<<"visa">>))),
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
command: /sbin/init

dominant:
image: ghcr.io/valitydev/dominant:sha-7e33b86
image: ghcr.io/valitydev/dominant:sha-c0ebc36
depends_on:
- machinegun
ports:
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"7ed2112a6503abe9f65142e43dca6675e939d164"}},
{ref,"81d1edce2043500e4581867da3f5f4c31e682f44"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",
Expand Down
Loading