HG-149: Save party contact info upon creation (#61)

This commit is contained in:
Andrew Mayorov 2017-01-17 19:30:40 +03:00 committed by GitHub
parent 70a3658beb
commit e4c62bee37
5 changed files with 72 additions and 42 deletions

View File

@ -72,9 +72,9 @@ checkout(PartyID, Revision) ->
-spec handle_function(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) ->
term()| no_return().
handle_function('Create', [UserInfo, PartyID], _Opts) ->
handle_function('Create', [UserInfo, PartyID, PartyParams], _Opts) ->
ok = assert_party_accessible(UserInfo, PartyID),
start(PartyID);
start(PartyID, PartyParams);
handle_function('Get', [UserInfo, PartyID], _Opts) ->
ok = assert_party_accessible(UserInfo, PartyID),
@ -215,8 +215,8 @@ get_public_history(PartyID, AfterID, Limit) ->
AfterID, Limit
).
start(ID) ->
map_start_error(hg_machine:start(?NS, ID, {})).
start(ID, Args) ->
map_start_error(hg_machine:start(?NS, ID, Args)).
call(ID, Args) ->
map_error(hg_machine:call(?NS, {id, ID}, Args)).
@ -248,8 +248,14 @@ map_error({error, Reason}) ->
%%
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type party() :: dmsl_domain_thrift:'Party'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type shop_params() :: dmsl_payment_processing_thrift:'ShopParams'().
-type shop_update() :: dmsl_payment_processing_thrift:'ShopUpdate'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contract_params() :: dmsl_payment_processing_thrift:'ContractParams'().
-type adjustment_params() :: dmsl_payment_processing_thrift:'ContractAdjustmentParams'().
-type payout_account_params() :: dmsl_payment_processing_thrift:'PayoutAccountParams'().
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
@ -294,11 +300,11 @@ publish_event(_InvoiceID, _) ->
namespace() ->
?NS.
-spec init(party_id(), {}) ->
-spec init(party_id(), dmsl_payment_processing_thrift:'PartyParams'()) ->
hg_machine:result(ev()).
init(ID, {}) ->
{ok, StEvents} = create_party(ID, {#st{}, []}),
init(ID, PartyParams) ->
{ok, StEvents} = create_party(ID, PartyParams, {#st{}, []}),
Revision = hg_domain:head(),
TestContractTemplpate = get_test_template(Revision),
Changeset1 = create_contract(#payproc_ContractParams{template = TestContractTemplpate}, StEvents),
@ -340,7 +346,23 @@ process_signal({repair, _}, _History) ->
ok().
-type call() ::
{suspend | activate}.
{block, binary()} |
{unblock, binary()} |
suspend |
activate |
{create_contract, contract_params()} |
{terminate_contract, contract_id(), binary()} |
{create_contract_adjustment, contract_id(), adjustment_params()} |
{create_payout_account, payout_account_params()} |
{create_shop, shop_params()} |
{update_shop, shop_id(), shop_update()} |
{block_shop, shop_id(), binary()} |
{unblock_shop, shop_id(), binary()} |
{suspend_shop, shop_id()} |
{activate_shop, shop_id()} |
{accept_claim, shop_id()} |
{deny_claim, shop_id(), binary()} |
{revoke_claim, shop_id(), binary()}.
-type response() ::
ok | {ok, term()} | {exception, term()}.
@ -462,9 +484,10 @@ handle_call({revoke_claim, ID, Reason}, StEvents0) ->
%%
create_party(PartyID, StEvents) ->
create_party(PartyID, PartyParams, StEvents) ->
Party = #domain_Party{
id = PartyID,
contact_info = PartyParams#payproc_PartyParams.contact_info,
blocking = ?unblocked(<<>>),
suspension = ?active(),
contracts = #{},

View File

@ -23,7 +23,6 @@
-export([get_hellgate_url/0]).
-export([construct_domain_fixture/0]).
-export([construct_context/0]).
-include_lib("dmsl/include/dmsl_domain_thrift.hrl").
@ -118,11 +117,18 @@ start_apps(Apps) ->
shop_id().
create_party_and_shop(Client) ->
ok = hg_client_party:create(Client),
ok = hg_client_party:create(make_party_params(), Client),
#domain_Party{shops = Shops} = hg_client_party:get(Client),
[{ShopID, _Shop}] = maps:to_list(Shops),
ShopID.
make_party_params() ->
#payproc_PartyParams{
contact_info = #domain_PartyContactInfo{
email = <<?MODULE_STRING>>
}
}.
-spec create_shop(category(), binary(), Client :: pid()) ->
shop_id().
@ -296,8 +302,7 @@ make_due_date(LifetimeSeconds) ->
{share, #domain_CashVolumeShare{parts = #'Rational'{p = P, q = Q}, 'of' = C}}).
construct_domain_fixture() ->
Context = construct_context(),
hg_context:set(Context),
_ = hg_context:set(woody_context:new()),
Accounts = lists:foldl(
fun ({N, CurrencyCode}, M) ->
AccountID = hg_accounting:create_account(CurrencyCode),
@ -700,9 +705,3 @@ construct_domain_fixture() ->
}
}}
].
-spec construct_context() -> term().
construct_context() ->
ReqID = genlib_format:format_int_base(genlib_time:ticks(), 62),
woody_context:new(ReqID).

View File

@ -296,15 +296,16 @@ end_per_testcase(_Name, _C) ->
party_creation(C) ->
Client = ?c(client, C),
PartyID = ?c(party_id, C),
ok = hg_client_party:create(Client),
ContactInfo = #domain_PartyContactInfo{email = <<?MODULE_STRING>>},
ok = hg_client_party:create(make_party_params(ContactInfo), Client),
?party_created(?party_w_status(PartyID, ?unblocked(_), ?active())) = next_event(Client),
?claim_created(?claim(_, ?accepted(_), [_ | _])) = next_event(Client),
#domain_Party{shops = Shops} = hg_client_party:get(Client),
#domain_Party{contact_info = ContactInfo, shops = Shops} = hg_client_party:get(Client),
[{_ShopID, #domain_Shop{suspension = ?active()}}] = maps:to_list(Shops).
party_already_exists(C) ->
Client = ?c(client, C),
?party_exists() = hg_client_party:create(Client).
?party_exists() = hg_client_party:create(make_party_params(), Client).
party_not_found_on_retrieval(C) ->
Client = ?c(client, C),
@ -317,8 +318,7 @@ party_retrieval(C) ->
party_revisioning(C) ->
Client = ?c(client, C),
Context = hg_ct_helper:construct_context(),
hg_context:set(Context),
hg_context:set(woody_context:new()),
Party1 = hg_client_party:get(Client),
T1 = hg_datetime:format_now(),
Party2 = party_suspension(C),
@ -733,3 +733,10 @@ get_first_payout_account(Client) ->
make_userinfo(PartyID) ->
#payproc_UserInfo{id = PartyID, type = {external_user, #payproc_ExternalUser{}}}.
make_party_params() ->
make_party_params(#domain_PartyContactInfo{email = <<?MODULE_STRING>>}).
make_party_params(ContactInfo) ->
#payproc_PartyParams{
contact_info = ContactInfo
}.

View File

@ -5,7 +5,7 @@
-export([start_link/3]).
-export([stop/1]).
-export([create/1]).
-export([create/2]).
-export([get/1]).
-export([block/2]).
-export([unblock/2]).
@ -42,6 +42,7 @@
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_params() :: dmsl_payment_processing_thrift:'PartyParams'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
-type shop_params() :: dmsl_payment_processing_thrift:'ShopParams'().
@ -70,11 +71,11 @@ stop(Client) ->
%%
-spec create(pid()) ->
-spec create(party_params(), pid()) ->
ok | woody_error:business_error().
create(Client) ->
map_result_error(gen_server:call(Client, {call, 'Create', []})).
create(PartyParams, Client) ->
map_result_error(gen_server:call(Client, {call, 'Create', [PartyParams]})).
-spec get(pid()) ->
dmsl_domain_thrift:'Party'() | woody_error:business_error().

View File

@ -3,7 +3,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"1.0.2">>},2},
{<<"dmsl">>,
{git,"git@github.com:rbkmoney/damsel_erlang.git",
{ref,"338a6daddba9fad907def301e623a244b22be597"}},
{ref,"4b4e0910e0a8d2ac4a6abaae7a016c8269ab239e"}},
0},
{<<"dmt">>,
{git,"git@github.com:rbkmoney/dmt_core.git",