OPS-53: Implement ComputeProviderTerminal (#8)

* Bump to valitydev/damsel@8016313a
* Make testclient more flexible yet explicit
* Isolate exception throwing in handler module
This commit is contained in:
Andrew Mayorov 2022-03-04 19:15:50 +03:00 committed by GitHub
parent b8bc5460c6
commit 0d6ab9407d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 283 additions and 97 deletions

View File

@ -6,7 +6,7 @@ on:
- 'master'
- 'epic/**'
pull_request:
branches: [ '**' ]
branches: ['**']
jobs:
setup:

View File

@ -19,7 +19,6 @@ handle_function(Func, Args, Opts) ->
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
%% Party
handle_function_('Create', {UserInfo, PartyID, PartyParams}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:start(PartyID, PartyParams);
@ -46,7 +45,6 @@ handle_function_(Fun, Args, _Opts) when
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Contract
handle_function_('GetContract', {UserInfo, PartyID, ContractID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
@ -75,7 +73,6 @@ handle_function_('ComputeContractTerms', Args, _Opts) ->
Terms = pm_party:get_terms(Contract, Timestamp, DomainRevision),
pm_party:reduce_terms(Terms, DecodedVS, DomainRevision);
%% Shop
handle_function_('GetShop', {UserInfo, PartyID, ID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
@ -113,7 +110,6 @@ handle_function_(Fun, Args, _Opts) when
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Claim
handle_function_('GetClaim', {UserInfo, PartyID, ID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_claim(ID, PartyID);
@ -132,13 +128,11 @@ handle_function_(Fun, Args, _Opts) when
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Event
handle_function_('GetEvents', {UserInfo, PartyID, Range}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
#payproc_EventRange{'after' = AfterID, limit = Limit} = Range,
pm_party_machine:get_public_history(PartyID, AfterID, Limit);
%% ShopAccount
handle_function_('GetAccountState', {UserInfo, PartyID, AccountID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
@ -148,22 +142,48 @@ handle_function_('GetShopAccount', {UserInfo, PartyID, ShopID}, _Opts) ->
Party = pm_party_machine:get_party(PartyID),
pm_party:get_shop_account(ShopID, Party);
%% Providers
handle_function_('ComputeProvider', Args, _Opts) ->
{UserInfo, ProviderRef, DomainRevision, Varset} = Args,
ok = assume_user_identity(UserInfo),
Provider = get_provider(ProviderRef, DomainRevision),
VS = pm_varset:decode_varset(Varset),
pm_provider:reduce_provider(Provider, VS, DomainRevision);
ComputedProvider = pm_provider:reduce_provider(Provider, VS, DomainRevision),
_ = assert_provider_reduced(ComputedProvider),
ComputedProvider;
handle_function_('ComputeProviderTerminalTerms', Args, _Opts) ->
{UserInfo, ProviderRef, TerminalRef, DomainRevision, Varset} = Args,
ok = assume_user_identity(UserInfo),
Provider = get_provider(ProviderRef, DomainRevision),
Terminal = get_terminal(TerminalRef, DomainRevision),
VS = pm_varset:decode_varset(Varset),
pm_provider:reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision);
Terms = pm_provider:reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision),
_ = assert_provider_terms_reduced(Terms),
Terms;
handle_function_('ComputeProviderTerminal', {TerminalRef, DomainRevision, VarsetIn}, _Opts) ->
Terminal = get_terminal(TerminalRef, DomainRevision),
ProviderRef = Terminal#domain_Terminal.provider_ref,
Provider = get_provider(ProviderRef, DomainRevision),
Proxy = pm_provider:compute_proxy(Provider, Terminal, DomainRevision),
ComputedTerms = pm_maybe:apply(
fun(Varset) ->
VS = pm_varset:decode_varset(Varset),
pm_provider:reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision)
end,
VarsetIn
),
#payproc_ProviderTerminal{
ref = TerminalRef,
name = Terminal#domain_Terminal.name,
description = Terminal#domain_Terminal.description,
proxy = Proxy,
provider = #payproc_ProviderDetails{
ref = ProviderRef,
name = Provider#domain_Provider.name,
description = Provider#domain_Provider.description
},
terms = ComputedTerms
};
%% Globals
handle_function_('ComputeGlobals', Args, _Opts) ->
{UserInfo, DomainRevision, Varset} = Args,
ok = assume_user_identity(UserInfo),
@ -171,7 +191,6 @@ handle_function_('ComputeGlobals', Args, _Opts) ->
VS = pm_varset:decode_varset(Varset),
pm_globals:reduce_globals(Globals, VS, DomainRevision);
%% RuleSets
%% Deprecated, will be replaced by 'ComputeRoutingRuleset'
handle_function_('ComputePaymentRoutingRuleset', Args, _Opts) ->
{UserInfo, RuleSetRef, DomainRevision, Varset} = Args,
@ -285,6 +304,14 @@ assert_party_accessible(PartyID) ->
throw(#payproc_InvalidUser{})
end.
assert_provider_reduced(#domain_Provider{terms = Terms}) ->
assert_provider_terms_reduced(Terms).
assert_provider_terms_reduced(#domain_ProvisionTermSet{}) ->
ok;
assert_provider_terms_reduced(undefined) ->
throw(#payproc_ProvisionTermSetUndefined{}).
set_party_mgmt_meta(PartyID) ->
scoper:add_meta(#{party_id => PartyID}).

View File

@ -7,6 +7,8 @@
-export([reduce_provider/3]).
-export([reduce_provider_terminal_terms/4]).
-export([compute_proxy/3]).
-type provider() :: dmsl_domain_thrift:'Provider'().
-type terminal() :: dmsl_domain_thrift:'Terminal'().
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
@ -20,18 +22,13 @@ reduce_provider(Provider, VS, Rev) ->
terms = reduce_provision_term_set(Provider#domain_Provider.terms, VS, Rev)
}.
-spec reduce_provider_terminal_terms(provider(), terminal(), varset(), domain_revision()) -> provision_terms().
-spec reduce_provider_terminal_terms(provider(), terminal(), varset(), domain_revision()) ->
provision_terms() | undefined.
reduce_provider_terminal_terms(Provider, Terminal, VS, Rev) ->
ProviderTerms = Provider#domain_Provider.terms,
TerminalTerms = Terminal#domain_Terminal.terms,
MergedTerms = merge_provision_term_sets(ProviderTerms, TerminalTerms),
ReducedTerms = reduce_provision_term_set(MergedTerms, VS, Rev),
case ReducedTerms of
undefined ->
throw(#payproc_ProvisionTermSetUndefined{});
_ ->
ReducedTerms
end.
reduce_provision_term_set(MergedTerms, VS, Rev).
reduce_withdrawal_terms(undefined = Terms, _VS, _Rev) ->
Terms;
@ -268,3 +265,26 @@ merge_withdrawal_terms(ProviderTerms, TerminalTerms) ->
reduce_if_defined(Selector, VS, Rev) ->
pm_maybe:apply(fun(X) -> pm_selector:reduce(X, VS, Rev) end, Selector).
-spec compute_proxy(provider(), terminal(), domain_revision()) ->
dmsl_domain_thrift:'ProxyDefinition'().
compute_proxy(Provider, Terminal, DomainRevision) ->
Proxy = Provider#domain_Provider.proxy,
ProxyDef = pm_domain:get(DomainRevision, {proxy, Proxy#domain_Proxy.ref}),
EffectiveOptions = lists:foldl(
fun
(undefined, M) ->
M;
(M1, M) ->
maps:merge(M1, M)
end,
#{},
[
Terminal#domain_Terminal.options,
Proxy#domain_Proxy.additional,
ProxyDef#domain_ProxyDefinition.options
]
),
ProxyDef#domain_ProxyDefinition{
options = EffectiveOptions
}.

View File

@ -61,7 +61,7 @@
}}
).
-define(share_with_rounding_method(P, Q, C, RM),
-define(share(P, Q, C, RM),
{share, #domain_CashVolumeShare{
parts = #'Rational'{p = P, q = Q},
'of' = C,

View File

@ -14,7 +14,7 @@
-export([construct_payment_method/1]).
-export([construct_payout_method/1]).
-export([construct_proxy/2]).
-export([construct_proxy/3]).
-export([construct_proxy/4]).
-export([construct_inspector/3]).
-export([construct_inspector/4]).
-export([construct_inspector/5]).
@ -197,16 +197,16 @@ construct_payout_method(?pomt(M) = Ref) ->
-spec construct_proxy(proxy(), name()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
construct_proxy(Ref, Name) ->
construct_proxy(Ref, Name, #{}).
construct_proxy(Ref, Name, <<>>, #{}).
-spec construct_proxy(proxy(), name(), Opts :: map()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
construct_proxy(Ref, Name, Opts) ->
-spec construct_proxy(proxy(), name(), binary(), Opts :: map()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
construct_proxy(Ref, Name, Url, Opts) ->
{proxy, #domain_ProxyObject{
ref = Ref,
data = #domain_ProxyDefinition{
name = Name,
description = Name,
url = <<>>,
url = Url,
options = Opts
}
}}.

View File

@ -99,6 +99,9 @@
-export([compute_provider_terminal_terms_ok/1]).
-export([compute_provider_terminal_terms_not_found/1]).
-export([compute_provider_terminal_terms_undefined_terms/1]).
-export([compute_provider_terminal_ok/1]).
-export([compute_provider_terminal_empty_varset_ok/1]).
-export([compute_provider_terminal_not_found/1]).
-export([compute_globals_ok/1]).
-export([compute_payment_routing_ruleset_ok/1]).
-export([compute_payment_routing_ruleset_unreducable/1]).
@ -265,6 +268,9 @@ groups() ->
compute_provider_terminal_terms_ok,
compute_provider_terminal_terms_not_found,
compute_provider_terminal_terms_undefined_terms,
compute_provider_terminal_ok,
compute_provider_terminal_empty_varset_ok,
compute_provider_terminal_not_found,
compute_globals_ok,
compute_payment_routing_ruleset_ok,
compute_payment_routing_ruleset_unreducable,
@ -499,6 +505,9 @@ end_per_testcase(_Name, _C) ->
-spec compute_provider_terminal_terms_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().
-spec compute_provider_terminal_empty_varset_ok(config()) -> _ | no_return().
-spec compute_provider_terminal_not_found(config()) -> _ | no_return().
-spec compute_globals_ok(config()) -> _ | no_return().
-spec compute_payment_routing_ruleset_ok(config()) -> _ | no_return().
-spec compute_payment_routing_ruleset_unreducable(config()) -> _ | no_return().
@ -1627,7 +1636,7 @@ compute_provider_ok(C) ->
{min_of,
?ordset([
?fixed(10, <<"RUB">>),
?share_with_rounding_method(5, 100, operation_amount, round_half_towards_zero)
?share(5, 100, operation_amount, round_half_towards_zero)
])}}
),
#domain_Provider{
@ -1660,7 +1669,7 @@ compute_provider_terminal_terms_ok(C) ->
{min_of,
?ordset([
?fixed(10, <<"RUB">>),
?share_with_rounding_method(5, 100, operation_amount, round_half_towards_zero)
?share(5, 100, operation_amount, round_half_towards_zero)
])}}
),
PaymentMethods = ?ordset([?pmt(bank_card_deprecated, visa)]),
@ -1678,29 +1687,29 @@ compute_provider_terminal_terms_not_found(C) ->
Client = cfg(client, C),
DomainRevision = pm_domain:head(),
{exception, #payproc_TerminalNotFound{}} =
(catch pm_client_party:compute_provider_terminal_terms(
pm_client_party:compute_provider_terminal_terms(
?prv(1),
?trm(?WRONG_DMT_OBJ_ID),
DomainRevision,
#payproc_Varset{},
Client
)),
),
{exception, #payproc_ProviderNotFound{}} =
(catch pm_client_party:compute_provider_terminal_terms(
pm_client_party:compute_provider_terminal_terms(
?prv(?WRONG_DMT_OBJ_ID),
?trm(1),
DomainRevision,
#payproc_Varset{},
Client
)),
),
{exception, #payproc_ProviderNotFound{}} =
(catch pm_client_party:compute_provider_terminal_terms(
pm_client_party:compute_provider_terminal_terms(
?prv(?WRONG_DMT_OBJ_ID),
?trm(?WRONG_DMT_OBJ_ID),
DomainRevision,
#payproc_Varset{},
Client
)).
).
compute_provider_terminal_terms_undefined_terms(C) ->
Client = cfg(client, C),
@ -1716,6 +1725,95 @@ compute_provider_terminal_terms_undefined_terms(C) ->
)
).
compute_provider_terminal_ok(C) ->
Client = cfg(client, C),
Revision = pm_domain:head(),
Varset = #payproc_Varset{
currency = ?cur(<<"RUB">>)
},
ExpectedCashflow = ?cfpost(
{system, settlement},
{provider, settlement},
{product,
{min_of,
?ordset([
?fixed(10, <<"RUB">>),
?share(5, 100, operation_amount, round_half_towards_zero)
])}}
),
ExpectedPaymentMethods = ?ordset([
?pmt(bank_card_deprecated, visa)
]),
?assertMatch(
#payproc_ProviderTerminal{
ref = ?trm(1),
name = <<"Brominal 1">>,
description = <<"Brominal 1">>,
provider = #payproc_ProviderDetails{
ref = ?prv(1),
name = <<"Brovider">>,
description = <<"A provider but bro">>
},
proxy = #domain_ProxyDefinition{
name = <<"Dummy proxy">>,
url = <<"http://dummy.proxy/">>,
options = #{
<<"proxy">> := <<"def">>,
<<"pro">> := <<"vader">>,
<<"term">> := <<"inal">>,
<<"override_proxy">> := <<"proxydef">>,
<<"override_provider">> := <<"provider">>,
<<"override_terminal">> := <<"terminal">>
}
},
terms = #domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
cash_flow = {value, [ExpectedCashflow]},
payment_methods = {value, ExpectedPaymentMethods}
},
recurrent_paytools = #domain_RecurrentPaytoolsProvisionTerms{
cash_value = {value, ?cash(1000, <<"RUB">>)}
}
}
},
pm_client_party:compute_provider_terminal(?trm(1), Revision, Varset, Client)
).
compute_provider_terminal_empty_varset_ok(C) ->
Client = cfg(client, C),
Revision = pm_domain:head(),
?assertMatch(
#payproc_ProviderTerminal{
ref = ?trm(1),
provider = #payproc_ProviderDetails{
ref = ?prv(1)
},
proxy = #domain_ProxyDefinition{
url = <<"http://dummy.proxy/">>,
options = #{
<<"override_proxy">> := <<"proxydef">>,
<<"override_provider">> := <<"provider">>,
<<"override_terminal">> := <<"terminal">>
}
},
terms = undefined
},
pm_client_party:compute_provider_terminal(?trm(1), Revision, undefined, Client)
).
compute_provider_terminal_not_found(C) ->
Client = cfg(client, C),
DomainRevision = pm_domain:head(),
?assertMatch(
{exception, #payproc_TerminalNotFound{}},
pm_client_party:compute_provider_terminal(
?trm(?WRONG_DMT_OBJ_ID),
DomainRevision,
#payproc_Varset{},
Client
)
).
compute_globals_ok(C) ->
Client = cfg(client, C),
DomainRevision = pm_domain:head(),
@ -2455,7 +2553,18 @@ construct_domain_fixture() ->
pm_ct_fixture:construct_payout_method(?pomt(international_bank_account)),
pm_ct_fixture:construct_payout_method(?pomt(wallet_info)),
pm_ct_fixture:construct_proxy(?prx(1), <<"Dummy proxy">>),
pm_ct_fixture:construct_proxy(
?prx(1),
<<"Dummy proxy">>,
<<"http://dummy.proxy/">>,
#{
<<"proxy">> => <<"def">>,
<<"override_proxy">> => <<"proxydef">>,
<<"override_provider">> => <<"proxydef">>,
<<"override_terminal">> => <<"proxydef">>
}
),
pm_ct_fixture:construct_inspector(?insp(1), <<"Dummy Inspector">>, ?prx(1)),
pm_ct_fixture:construct_system_account_set(?sas(1)),
pm_ct_fixture:construct_system_account_set(?sas(2)),
@ -2584,8 +2693,14 @@ construct_domain_fixture() ->
data = #domain_Provider{
name = <<"Brovider">>,
description = <<"A provider but bro">>,
terminal = {value, [?prvtrm(1)]},
proxy = #domain_Proxy{ref = ?prx(1), additional = #{}},
proxy = #domain_Proxy{
ref = ?prx(1),
additional = #{
<<"pro">> => <<"vader">>,
<<"override_provider">> => <<"provider">>,
<<"override_terminal">> => <<"provider">>
}
},
abs_account = <<"1234567890">>,
accounts = pm_ct_fixture:construct_provider_account_set([?cur(<<"RUB">>)]),
terms = #domain_ProvisionTermSet{
@ -2617,7 +2732,7 @@ construct_domain_fixture() ->
{min_of,
?ordset([
?fixed(10, <<"RUB">>),
?share_with_rounding_method(
?share(
5,
100,
operation_amount,
@ -2638,7 +2753,7 @@ construct_domain_fixture() ->
{min_of,
?ordset([
?fixed(10, <<"USD">>),
?share_with_rounding_method(
?share(
5,
100,
operation_amount,
@ -2679,7 +2794,6 @@ construct_domain_fixture() ->
data = #domain_Provider{
name = <<"Provider 2">>,
description = <<"Provider without terms">>,
terminal = {value, [?prvtrm(4)]},
proxy = #domain_Proxy{ref = ?prx(1), additional = #{}},
abs_account = <<"1234567890">>,
accounts = pm_ct_fixture:construct_provider_account_set([?cur(<<"RUB">>)])
@ -2691,6 +2805,11 @@ construct_domain_fixture() ->
data = #domain_Terminal{
name = <<"Brominal 1">>,
description = <<"Brominal 1">>,
provider_ref = ?prv(1),
options = #{
<<"term">> => <<"inal">>,
<<"override_terminal">> => <<"terminal">>
},
terms = #domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
payment_methods =
@ -2707,6 +2826,7 @@ construct_domain_fixture() ->
data = #domain_Terminal{
name = <<"Brominal 2">>,
description = <<"Brominal 2">>,
provider_ref = ?prv(1),
terms = #domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
payment_methods =
@ -2723,6 +2843,7 @@ construct_domain_fixture() ->
data = #domain_Terminal{
name = <<"Brominal 3">>,
description = <<"Brominal 3">>,
provider_ref = ?prv(1),
terms = #domain_ProvisionTermSet{
payments = #domain_PaymentsProvisionTerms{
payment_methods =
@ -2738,7 +2859,8 @@ construct_domain_fixture() ->
ref = ?trm(4),
data = #domain_Terminal{
name = <<"Terminal 4">>,
description = <<"Terminal without terms">>
description = <<"Terminal without terms">>,
provider_ref = ?prv(2)
}
}}
].

View File

@ -49,6 +49,7 @@
-export([pull_event/2]).
-export([compute_provider/4]).
-export([compute_provider_terminal/4]).
-export([compute_provider_terminal_terms/5]).
-export([compute_globals/3]).
-export([compute_routing_ruleset/4]).
@ -117,149 +118,163 @@ stop(Client) ->
-spec create(party_params(), pid()) -> ok | woody_error:business_error().
create(PartyParams, Client) ->
map_result_error(gen_server:call(Client, {call, 'Create', [PartyParams]})).
call(Client, 'Create', with_user_info_party_id([PartyParams])).
-spec get(pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
get(Client) ->
map_result_error(gen_server:call(Client, {call, 'Get', []})).
call(Client, 'Get', with_user_info_party_id([])).
-spec get_revision(pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
get_revision(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetRevision', []})).
call(Client, 'GetRevision', with_user_info_party_id([])).
-spec get_status(pid()) -> dmsl_domain_thrift:'PartyStatus'() | woody_error:business_error().
get_status(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetStatus', []})).
call(Client, 'GetStatus', with_user_info_party_id([])).
-spec checkout(party_revision_param(), pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
checkout(PartyRevisionParam, Client) ->
map_result_error(gen_server:call(Client, {call, 'Checkout', [PartyRevisionParam]})).
call(Client, 'Checkout', with_user_info_party_id([PartyRevisionParam])).
-spec block(binary(), pid()) -> ok | woody_error:business_error().
block(Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'Block', [Reason]})).
call(Client, 'Block', with_user_info_party_id([Reason])).
-spec unblock(binary(), pid()) -> ok | woody_error:business_error().
unblock(Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'Unblock', [Reason]})).
call(Client, 'Unblock', with_user_info_party_id([Reason])).
-spec suspend(pid()) -> ok | woody_error:business_error().
suspend(Client) ->
map_result_error(gen_server:call(Client, {call, 'Suspend', []})).
call(Client, 'Suspend', with_user_info_party_id([])).
-spec activate(pid()) -> ok | woody_error:business_error().
activate(Client) ->
map_result_error(gen_server:call(Client, {call, 'Activate', []})).
call(Client, 'Activate', with_user_info_party_id([])).
-spec get_meta(pid()) -> meta() | woody_error:business_error().
get_meta(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetMeta', []})).
call(Client, 'GetMeta', with_user_info_party_id([])).
-spec get_metadata(meta_ns(), pid()) -> meta_data() | woody_error:business_error().
get_metadata(NS, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetMetaData', [NS]})).
call(Client, 'GetMetaData', with_user_info_party_id([NS])).
-spec set_metadata(meta_ns(), meta_data(), pid()) -> ok | woody_error:business_error().
set_metadata(NS, Data, Client) ->
map_result_error(gen_server:call(Client, {call, 'SetMetaData', [NS, Data]})).
call(Client, 'SetMetaData', with_user_info_party_id([NS, Data])).
-spec remove_metadata(meta_ns(), pid()) -> ok | woody_error:business_error().
remove_metadata(NS, Client) ->
map_result_error(gen_server:call(Client, {call, 'RemoveMetaData', [NS]})).
call(Client, 'RemoveMetaData', with_user_info_party_id([NS])).
-spec get_contract(contract_id(), pid()) -> dmsl_domain_thrift:'Contract'() | woody_error:business_error().
get_contract(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetContract', [ID]})).
call(Client, 'GetContract', with_user_info_party_id([ID])).
-spec compute_contract_terms(
contract_id(), timestamp(), party_revision_param(), domain_revision(), contract_terms_varset(), pid()
contract_id(),
timestamp(),
party_revision_param(),
domain_revision(),
contract_terms_varset(),
pid()
) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_contract_terms(ID, Timestamp, PartyRevision, DomainRevision, Varset, Client) ->
Args = [ID, Timestamp, PartyRevision, DomainRevision, Varset],
map_result_error(gen_server:call(Client, {call, 'ComputeContractTerms', Args})).
Args = with_user_info_party_id([ID, Timestamp, PartyRevision, DomainRevision, Varset]),
call(Client, 'ComputeContractTerms', Args).
-spec compute_payment_institution_terms(payment_intitution_ref(), varset(), pid()) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_payment_institution_terms(Ref, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputePaymentInstitutionTerms', [Ref, Varset]})).
call(Client, 'ComputePaymentInstitutionTerms', with_user_info([Ref, Varset])).
-spec compute_payout_cash_flow(dmsl_payment_processing_thrift:'PayoutParams'(), pid()) ->
dmsl_domain_thrift:'FinalCashFlow'() | woody_error:business_error().
compute_payout_cash_flow(Params, Client) ->
map_result_error(gen_server:call(Client, {call, 'ComputePayoutCashFlow', [Params]})).
call(Client, 'ComputePayoutCashFlow', with_user_info_party_id([Params])).
-spec get_shop(shop_id(), pid()) -> dmsl_domain_thrift:'Shop'() | woody_error:business_error().
get_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetShop', [ID]})).
call(Client, 'GetShop', with_user_info_party_id([ID])).
-spec get_shop_contract(shop_id(), pid()) ->
dmsl_payment_processing_thrift:'ShopContract'() | woody_error:business_error().
get_shop_contract(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetShopContract', [ID]})).
call(Client, 'GetShopContract', with_user_info_party_id([ID])).
-spec block_shop(shop_id(), binary(), pid()) -> ok | woody_error:business_error().
block_shop(ID, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'BlockShop', [ID, Reason]})).
call(Client, 'BlockShop', with_user_info_party_id([ID, Reason])).
-spec unblock_shop(shop_id(), binary(), pid()) -> ok | woody_error:business_error().
unblock_shop(ID, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'UnblockShop', [ID, Reason]})).
call(Client, 'UnblockShop', with_user_info_party_id([ID, Reason])).
-spec suspend_shop(shop_id(), pid()) -> ok | woody_error:business_error().
suspend_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'SuspendShop', [ID]})).
call(Client, 'SuspendShop', with_user_info_party_id([ID])).
-spec activate_shop(shop_id(), pid()) -> ok | woody_error:business_error().
activate_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'ActivateShop', [ID]})).
call(Client, 'ActivateShop', with_user_info_party_id([ID])).
-spec compute_shop_terms(shop_id(), timestamp(), party_revision_param(), shop_terms_varset(), pid()) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_shop_terms(ID, Timestamp, PartyRevision, VS, Client) ->
map_result_error(gen_server:call(Client, {call, 'ComputeShopTerms', [ID, Timestamp, PartyRevision, VS]})).
call(Client, 'ComputeShopTerms', with_user_info_party_id([ID, Timestamp, PartyRevision, VS])).
-spec get_claim(claim_id(), pid()) -> claim() | woody_error:business_error().
get_claim(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetClaim', [ID]})).
call(Client, 'GetClaim', with_user_info_party_id([ID])).
-spec get_claims(pid()) -> [claim()] | woody_error:business_error().
get_claims(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetClaims', []})).
call(Client, 'GetClaims', with_user_info_party_id([])).
-spec create_claim(changeset(), pid()) -> claim() | woody_error:business_error().
create_claim(Changeset, Client) ->
map_result_error(gen_server:call(Client, {call, 'CreateClaim', [Changeset]})).
call(Client, 'CreateClaim', with_user_info_party_id([Changeset])).
-spec update_claim(claim_id(), claim_revision(), changeset(), pid()) -> ok | woody_error:business_error().
update_claim(ID, Revision, Changeset, Client) ->
map_result_error(gen_server:call(Client, {call, 'UpdateClaim', [ID, Revision, Changeset]})).
call(Client, 'UpdateClaim', with_user_info_party_id([ID, Revision, Changeset])).
-spec accept_claim(claim_id(), claim_revision(), pid()) -> ok | woody_error:business_error().
accept_claim(ID, Revision, Client) ->
map_result_error(gen_server:call(Client, {call, 'AcceptClaim', [ID, Revision]})).
call(Client, 'AcceptClaim', with_user_info_party_id([ID, Revision])).
-spec deny_claim(claim_id(), claim_revision(), binary() | undefined, pid()) -> ok | woody_error:business_error().
deny_claim(ID, Revision, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'DenyClaim', [ID, Revision, Reason]})).
call(Client, 'DenyClaim', with_user_info_party_id([ID, Revision, Reason])).
-spec revoke_claim(claim_id(), claim_revision(), binary() | undefined, pid()) -> ok | woody_error:business_error().
revoke_claim(ID, Revision, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'RevokeClaim', [ID, Revision, Reason]})).
call(Client, 'RevokeClaim', with_user_info_party_id([ID, Revision, Reason])).
-spec get_account_state(shop_account_id(), pid()) ->
dmsl_payment_processing_thrift:'AccountState'() | woody_error:business_error().
get_account_state(AccountID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetAccountState', [AccountID]})).
call(Client, 'GetAccountState', with_user_info_party_id([AccountID])).
-spec get_shop_account(shop_id(), pid()) -> dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error().
get_shop_account(ShopID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetShopAccount', [ShopID]})).
call(Client, 'GetShopAccount', with_user_info_party_id([ShopID])).
-spec compute_provider(provider_ref(), domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'Provider'() | woody_error:business_error().
compute_provider(ProviderRef, Revision, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeProvider', [ProviderRef, Revision, Varset]})).
call(Client, 'ComputeProvider', with_user_info([ProviderRef, Revision, Varset])).
-spec compute_provider_terminal(
terminal_ref(),
domain_revision(),
varset() | undefined,
pid()
) -> dmsl_payment_processing_thrift:'ProviderTerminal'() | woody_error:business_error().
compute_provider_terminal(TerminalRef, Revision, Varset, Client) ->
call(Client, 'ComputeProviderTerminal', [TerminalRef, Revision, Varset]).
-spec compute_provider_terminal_terms(
provider_ref(),
@ -269,27 +284,18 @@ compute_provider(ProviderRef, Revision, Varset, Client) ->
pid()
) -> dmsl_domain_thrift:'ProvisionTermSet'() | woody_error:business_error().
compute_provider_terminal_terms(ProviderRef, TerminalRef, Revision, Varset, Client) ->
map_result_error(
gen_server:call(
Client,
{call_without_party, 'ComputeProviderTerminalTerms', [ProviderRef, TerminalRef, Revision, Varset]}
)
).
Args = with_user_info([ProviderRef, TerminalRef, Revision, Varset]),
call(Client, 'ComputeProviderTerminalTerms', Args).
-spec compute_globals(domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'Globals'() | woody_error:business_error().
compute_globals(Revision, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeGlobals', [Revision, Varset]})).
call(Client, 'ComputeGlobals', with_user_info([Revision, Varset])).
-spec compute_routing_ruleset(routing_ruleset_ref(), domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'RoutingRuleset'() | woody_error:business_error().
compute_routing_ruleset(RoutingRuleSetRef, Revision, Varset, Client) ->
map_result_error(
gen_server:call(
Client,
{call_without_party, 'ComputeRoutingRuleset', [RoutingRuleSetRef, Revision, Varset]}
)
).
call(Client, 'ComputeRoutingRuleset', with_user_info([RoutingRuleSetRef, Revision, Varset])).
-define(DEFAULT_NEXT_EVENT_TIMEOUT, 5000).
@ -301,6 +307,9 @@ pull_event(Client) ->
pull_event(Timeout, Client) ->
gen_server:call(Client, {pull_event, Timeout}, infinity).
call(Client, Function, Args) ->
map_result_error(gen_server:call(Client, {call, Function, Args})).
map_result_error({ok, Result}) ->
Result;
map_result_error({exception, _} = Exception) ->
@ -335,12 +344,14 @@ init({UserInfo, PartyID, ApiClient}) ->
}}.
-spec handle_call(term(), callref(), state()) -> {reply, term(), state()} | {noreply, state()}.
handle_call({call, Function, Args0}, _From, St = #state{client = Client}) ->
Args = [St#state.user_info, St#state.party_id | Args0],
Result = pm_client_api:call(party_management, Function, Args, Client),
{reply, Result, St};
handle_call({call_without_party, Function, Args0}, _From, St = #state{client = Client}) ->
Args = [St#state.user_info | Args0],
handle_call({call, Function, ArgsIn}, _From, St = #state{client = Client}) ->
Args = lists:map(
fun
(Fun) when is_function(Fun, 1) -> Fun(St);
(Arg) -> Arg
end,
ArgsIn
),
Result = pm_client_api:call(party_management, Function, Args, Client),
{reply, Result, St};
handle_call({pull_event, Timeout}, _From, St = #state{poller = Poller, client = Client}) ->
@ -375,3 +386,9 @@ terminate(_Reason, _State) ->
-spec code_change(Vsn | {down, Vsn}, state(), term()) -> {error, noimpl} when Vsn :: term().
code_change(_OldVsn, _State, _Extra) ->
{error, noimpl}.
with_user_info(Args) ->
[fun(St) -> St#state.user_info end | Args].
with_user_info_party_id(Args) ->
[fun(St) -> St#state.user_info end, fun(St) -> St#state.party_id end | Args].

View File

@ -9,7 +9,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"b25d3365e1f2b075ffea30b3a2e1c41eb3f6145b"}},
{ref,"8016313ab8c27a237a33927a0ee22dd58524e86c"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",