Skip to content

Commit

Permalink
HG-452: Move party and claim management to its own app (#407)
Browse files Browse the repository at this point in the history
* HG-452: Move party and claim management to it's own app

* HG-452: Remove unused exports

* HG-452: Fix tests, remove old eventsink on party

* HG-452: Revert pm_event_provider

* HG-452: Remove `hg_contract`

* HG-452: Add pm_client and pm_proto

* HG-452: Fix lint

* HG-452: Move party and claim management tests to `party_management`

* HG-452: Fix dialyzer

* HG-452: Fix tests

* HG-452: Fix tests

* HG-452: Remove some includes in hg, bring back `hg_party`

* HG-452: Remove party client from party management

* HG-452: Remove `hg_payout_tool` and rename `pm_invoice_utils` => `pm_currency`

* HG-452: Add party_management config

* HG-452: Remove unused function from common test helpers

* HG-452: Remove unused function from pm_ct_helper

* HG-452: hg_selector => pm_selector

* HG-452: Fix lint

* HG-452: Strip down party_management config and bring back party_events.hrl to hellgate

* HG-452: Fix order of app loads in tests

* HG-452: Bring back `hg_client_party`

* HG-452: Fix tests

* HG-452: Use pm_party in hg, where it is appropriate

* HG-452: Remove unused `hg_client_party` code

* HG-452: Remove unused macros in `hellgate/include/party_events.hrl`

* HG-452: Remove party_management from list of services in config

* HG-452: Remove hg_client and pm_client need to get service_spec

* HG-452: Clean up `party_management/include/domain.hrl` from unused macros

* HG-452: Format `xref_checks` like `erl_opts`

* HG-452: Bring back old event_sink for party events

* HG-452: Simplify include in test

* Merge branch 'master' into HG-452/ft/party_management_new

# Conflicts:
#	apps/hellgate/src/hg_party.erl

* HG-452: Review fix
  • Loading branch information
ndiezel0 authored Feb 28, 2020
1 parent 38f908b commit 4657aeb
Show file tree
Hide file tree
Showing 75 changed files with 5,431 additions and 1,872 deletions.
133 changes: 0 additions & 133 deletions apps/hellgate/include/party_events.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -10,140 +10,7 @@
created_at = Timestamp
}}).

-define(party_blocking(Blocking), {party_blocking, Blocking}).
-define(party_suspension(Suspension), {party_suspension, Suspension}).

-define(party_meta_set(NS, Data),
{party_meta_set, #payproc_PartyMetaSet{
ns = NS,
data = Data
}}).

-define(party_meta_removed(NS), {party_meta_removed, NS}).

-define(shop_blocking(ID, Blocking),
{shop_blocking, #payproc_ShopBlocking{shop_id = ID, blocking = Blocking}}).
-define(shop_suspension(ID, Suspension),
{shop_suspension, #payproc_ShopSuspension{shop_id = ID, suspension = Suspension}}).

-define(wallet_blocking(ID, Blocking),
{wallet_blocking, #payproc_WalletBlocking{wallet_id = ID, blocking = Blocking}}).
-define(wallet_suspension(ID, Suspension),
{wallet_suspension, #payproc_WalletSuspension{wallet_id = ID, suspension = Suspension}}).

-define(blocked(Reason, Since), {blocked, #domain_Blocked{reason = Reason, since = Since}}).
-define(unblocked(Reason, Since), {unblocked, #domain_Unblocked{reason = Reason, since = Since}}).
-define(unblocked(Since), {unblocked, #domain_Unblocked{reason = <<"">>, since = Since}}).

-define(active(Since), {active, #domain_Active{since = Since}}).
-define(suspended(Since), {suspended, #domain_Suspended{since = Since}}).

-define(contractor_modification(ID, Modification),
{contractor_modification, #payproc_ContractorModificationUnit{id = ID, modification = Modification}}).

-define(identity_documents_modification(Docs),
{identity_documents_modification, #payproc_ContractorIdentityDocumentsModification{
identity_documents = Docs
}}).

-define(contractor_effect(ID, Effect),
{contractor_effect, #payproc_ContractorEffectUnit{id = ID, effect = Effect}}).

-define(contract_modification(ID, Modification),
{contract_modification, #payproc_ContractModificationUnit{id = ID, modification = Modification}}).

-define(contract_termination(Reason),
{termination, #payproc_ContractTermination{reason = Reason}}).

-define(adjustment_creation(ID, Params),
{adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
adjustment_id = ID,
modification = {creation, Params}
}}).

-define(payout_tool_creation(ID, Params),
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
payout_tool_id = ID,
modification = {creation, Params}
}}).

-define(payout_tool_info_modification(ID, Info),
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
payout_tool_id = ID,
modification = {info_modification, Info}
}}).

-define(shop_modification(ID, Modification),
{shop_modification, #payproc_ShopModificationUnit{id = ID, modification = Modification}}).

-define(shop_contract_modification(ContractID, PayoutToolID),
{contract_modification, #payproc_ShopContractModification{contract_id = ContractID, payout_tool_id = PayoutToolID}}).

-define(
shop_account_creation_params(CurrencyRef),
{shop_account_creation, #payproc_ShopAccountParams{
currency = CurrencyRef
}}
).

-define(proxy_modification(Proxy),
{proxy_modification, #payproc_ProxyModification{proxy = Proxy}}).

-define(payout_schedule_modification(BusinessScheduleRef),
{payout_schedule_modification, #payproc_ScheduleModification{schedule = BusinessScheduleRef}}).

-define(contract_effect(ID, Effect),
{contract_effect, #payproc_ContractEffectUnit{contract_id = ID, effect = Effect}}).

-define(shop_effect(ID, Effect),
{shop_effect, #payproc_ShopEffectUnit{shop_id = ID, effect = Effect}}).

-define(payout_schedule_changed(BusinessScheduleRef),
{payout_schedule_changed, #payproc_ScheduleChanged{schedule = BusinessScheduleRef}}).

-define(wallet_modification(ID, Modification),
{wallet_modification, #payproc_WalletModificationUnit{id = ID, modification = Modification}}).

-define(wallet_effect(ID, Effect),
{wallet_effect, #payproc_WalletEffectUnit{id = ID, effect = Effect}}).

-define(claim_created(Claim),
{claim_created, Claim}).

-define(claim_updated(ID, Changeset, ClaimRevision, Timestamp),
{claim_updated, #payproc_ClaimUpdated{id = ID, changeset = Changeset, revision = ClaimRevision, updated_at = Timestamp}}).

-define(claim_status_changed(ID, Status, ClaimRevision, Timestamp),
{claim_status_changed, #payproc_ClaimStatusChanged{id = ID, status = Status, revision = ClaimRevision, changed_at = Timestamp}}).

-define(pending(),
{pending, #payproc_ClaimPending{}}).
-define(accepted(Effects),
{accepted, #payproc_ClaimAccepted{effects = Effects}}).
-define(denied(Reason),
{denied, #payproc_ClaimDenied{reason = Reason}}).
-define(revoked(Reason),
{revoked, #payproc_ClaimRevoked{reason = Reason}}).

-define(account_created(ShopAccount),
{account_created, #payproc_ShopAccountCreated{account = ShopAccount}}).

-define(revision_changed(Timestamp, Revision),
{revision_changed, #payproc_PartyRevisionChanged{
timestamp = Timestamp,
revision = Revision
}}).

-define(invalid_shop(ID, Reason),
{invalid_shop, #payproc_InvalidShop{id = ID, reason = Reason}}).

-define(invalid_contract(ID, Reason),
{invalid_contract, #payproc_InvalidContract{id = ID, reason = Reason}}).

-define(invalid_contractor(ID, Reason),
{invalid_contractor, #payproc_InvalidContractor{id = ID, reason = Reason}}).

-define(invalid_wallet(ID, Reason),
{invalid_wallet, #payproc_InvalidWallet{id = ID, reason = Reason}}).

-endif.
3 changes: 2 additions & 1 deletion apps/hellgate/src/hellgate.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
party_client,
woody_user_identity,
payproc_errors,
erl_health
erl_health,
party_management
]},
{env, []},
{modules, []},
Expand Down
23 changes: 16 additions & 7 deletions apps/hellgate/src/hellgate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ stop() ->

init([]) ->
MachineHandlers = [
hg_party_machine,
hg_invoice,
hg_invoice_template,
hg_customer,
hg_recurrent_paytool
],
PMMachineHandlers = [
pm_party_machine
],
PartyClient = party_client:create_client(),
DefaultTimeout = genlib_app:env(hellgate, default_woody_handling_timeout, ?DEFAULT_HANDLING_TIMEOUT),
Opts = #{
Expand All @@ -55,11 +57,12 @@ init([]) ->
[
party_client:child_spec(party_client, PartyClient),
hg_machine:get_child_spec(MachineHandlers),
get_api_child_spec(MachineHandlers, Opts)
pm_machine:get_child_spec(PMMachineHandlers),
get_api_child_spec(MachineHandlers, PMMachineHandlers, Opts)
]
}}.

get_api_child_spec(MachineHandlers, Opts) ->
get_api_child_spec(MachineHandlers, PMMachineHandlers, Opts) ->
{ok, Ip} = inet:parse_address(genlib_app:env(?MODULE, ip, "::")),
HealthRoutes = construct_health_routes(genlib_app:env(?MODULE, health_check, #{})),
EventHandlerOpts = genlib_app:env(?MODULE, scoper_event_handler_options, #{}),
Expand All @@ -71,9 +74,10 @@ get_api_child_spec(MachineHandlers, Opts) ->
transport_opts => genlib_app:env(?MODULE, transport_opts, #{}),
protocol_opts => genlib_app:env(?MODULE, protocol_opts, #{}),
event_handler => {scoper_woody_event_handler, EventHandlerOpts},
handlers => hg_machine:get_service_handlers(MachineHandlers, Opts) ++ [
construct_service_handler(claim_committer , hg_claim_committer_handler, Opts),
construct_service_handler(party_management , hg_party_woody_handler , Opts),
handlers => hg_machine:get_service_handlers(MachineHandlers, Opts) ++
pm_machine:get_service_handlers(PMMachineHandlers, Opts) ++ [
construct_service_handler_pm(claim_committer , pm_claim_committer_handler, Opts),
construct_service_handler_pm(party_management , pm_party_handler , Opts),
construct_service_handler(invoicing , hg_invoice , Opts),
construct_service_handler(invoice_templating , hg_invoice_template , Opts),
construct_service_handler(customer_management , hg_customer , Opts),
Expand All @@ -99,12 +103,17 @@ construct_service_handler(Name, Module, Opts) ->
{Path, Service} = hg_proto:get_service_spec(Name),
{Path, {Service, {hg_woody_wrapper, FullOpts}}}.

construct_service_handler_pm(Name, Module, Opts) ->
FullOpts = maps:merge(#{handler => Module}, Opts),
{Path, Service} = pm_proto:get_service_spec(Name),
{Path, {Service, {pm_woody_wrapper, FullOpts}}}.

%% Application callbacks

-spec start(normal, any()) ->
{ok, pid()} | {error, any()}.
start(_StartType, _StartArgs) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
supervisor:start_link(?MODULE, []).

-spec stop(any()) ->
ok.
Expand Down
31 changes: 30 additions & 1 deletion apps/hellgate/src/hg_event_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
event().

publish_event(Ns, EventID, MachineID, {ID, Dt, Ev}) ->
Module = hg_machine:get_handler_module(Ns),
Module = get_handler_module(Ns),
{Source, Payload} = Module:publish_event(MachineID, Ev),
#payproc_Event{
id = EventID,
Expand All @@ -32,3 +32,32 @@ publish_event(Ns, EventID, MachineID, {ID, Dt, Ev}) ->
payload = Payload,
sequence = ID
}.

get_handler_module(NS) ->
Machines = [hg_machine, pm_machine],
{value, Handler} = search_and_return(
fun (Machine) ->
try Machine:get_handler_module(NS) of
Result ->
{true, Result}
catch
error:badarg ->
false
end
end,
Machines),
Handler.

-spec search_and_return(Pred, List) -> {value, Value} | false when
Pred :: fun((T) -> {true, Value} | false),
List :: [T],
Value :: T | any().
search_and_return(Pred, [Head | Tail]) ->
case Pred(Head) of
{true, Result} ->
{value, Result};
false ->
search_and_return(Pred, Tail)
end;
search_and_return(Pred, []) when is_function(Pred, 1) ->
false.
2 changes: 1 addition & 1 deletion apps/hellgate/src/hg_invoice.erl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ handle_function_('ComputeTerms', [UserInfo, InvoiceID, PartyRevision0], _Opts) -
),
Revision = hg_domain:head(),
Cash = get_cost(St),
hg_party:reduce_terms(ShopTerms, #{cost => Cash}, Revision);
pm_party:reduce_terms(ShopTerms, #{cost => Cash}, Revision);

handle_function_(Fun, [UserInfo, InvoiceID | _Tail] = Args, _Opts) when
Fun =:= 'StartPayment' orelse
Expand Down
6 changes: 3 additions & 3 deletions apps/hellgate/src/hg_invoice_payment.erl
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ get_merchant_terms(Opts, Revision, Timestamp) ->
Shop = hg_party:get_shop(get_invoice_shop_id(Invoice), Party),
Contract = hg_party:get_contract(Shop#domain_Shop.contract_id, Party),
ok = assert_contract_active(Contract),
hg_party:get_terms(Contract, Timestamp, Revision).
pm_party:get_terms(Contract, Timestamp, Revision).

get_provider_payments_terms(Route, Revision) ->
hg_routing:get_payments_terms(Route, Revision).
Expand Down Expand Up @@ -889,7 +889,7 @@ choose_provider_account(Currency, Accounts) ->
choose_external_account(Currency, VS, Revision) ->
Globals = hg_domain:get(Revision, {globals, #domain_GlobalsRef{}}),
ExternalAccountSetSelector = Globals#domain_Globals.external_account_set,
case hg_selector:reduce(ExternalAccountSetSelector, VS, Revision) of
case pm_selector:reduce(ExternalAccountSetSelector, VS, Revision) of
{value, ExternalAccountSetRef} ->
ExternalAccountSet = hg_domain:get(Revision, {external_account_set, ExternalAccountSetRef}),
genlib_map:get(
Expand Down Expand Up @@ -926,7 +926,7 @@ construct_payment_plan_id(Invoice, Payment) ->
]).

reduce_selector(Name, Selector, VS, Revision) ->
case hg_selector:reduce(Selector, VS, Revision) of
case pm_selector:reduce(Selector, VS, Revision) of
{value, V} ->
V;
Ambiguous ->
Expand Down
2 changes: 1 addition & 1 deletion apps/hellgate/src/hg_invoice_template.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ handle_function_('ComputeTerms', [UserInfo, TplID, Timestamp, PartyRevision0], _
case Tpl#domain_InvoiceTemplate.details of
{product, #domain_InvoiceTemplateProduct{price = {fixed, Cash}}} ->
Revision = hg_domain:head(),
hg_party:reduce_terms(ShopTerms, #{cost => Cash}, Revision);
pm_party:reduce_terms(ShopTerms, #{cost => Cash}, Revision);
_ ->
ShopTerms
end.
Expand Down
Loading

0 comments on commit 4657aeb

Please sign in to comment.