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
2 changes: 1 addition & 1 deletion apps/hellgate/src/hellgate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ construct_health_routes(readiness, Check) ->

enable_health_logging(Check) ->
EvHandler = {erl_health_event_handler, []},
maps:map(fun(_, V = {_, _, _}) -> #{runner => V, event_handler => EvHandler} end, Check).
maps:map(fun(_, {_, _, _} = V) -> #{runner => V, event_handler => EvHandler} end, Check).

construct_service_handler(Name, Module, Opts) ->
FullOpts = maps:merge(#{handler => Module}, Opts),
Expand Down
27 changes: 15 additions & 12 deletions apps/hellgate/src/hg_allocation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,21 @@
-spec calculate(allocation_prototype(), party(), shop(), cash(), allocation_terms()) ->
{error, calculate_errors()}.
calculate(AllocationPrototype, Party, Shop, Cost, PaymentAllocationServiceTerms) ->
case assert_allocatable(AllocationPrototype, PaymentAllocationServiceTerms, Party, Shop, Cost) of
% ok ->
% try calculate(AllocationPrototype, Party#domain_PartyConfig.id, Shop#domain_ShopConfig.id, Cost) of
% Result ->
% {ok, Result}
% catch
% throw:Error ->
% {error, Error}
% end;
{error, Error} ->
{error, Error}
end.
%% NOTE Allocation is temporarily disabled.
%% case assert_allocatable(AllocationPrototype, PaymentAllocationServiceTerms, Party, Shop, Cost) of
%% ok ->
%% try calculate(AllocationPrototype, Party#domain_PartyConfig.id, Shop#domain_ShopConfig.id, Cost) of
%% Result ->
%% {ok, Result}
%% catch
%% throw:Error ->
%% {error, Error}
%% end;
%% {error, Error} ->
%% {error, Error}
%% end.
{error, Error} = assert_allocatable(AllocationPrototype, PaymentAllocationServiceTerms, Party, Shop, Cost),
{error, Error}.

-spec sub(allocation(), allocation()) -> {ok, allocation()} | {error, sub_errors()}.
sub(Allocation, SubAllocation) ->
Expand Down
4 changes: 2 additions & 2 deletions apps/hellgate/src/hg_cashflow.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ compute_volume(?product(Fun, CVs) = CV0, Context) ->
error({misconfiguration, {'Cash volume product over empty set', CV0}})
end.

compute_parts_of(P, Q, Cash = #domain_Cash{amount = Amount}, RoundingMethod) ->
compute_parts_of(P, Q, #domain_Cash{amount = Amount} = Cash, RoundingMethod) ->
Cash#domain_Cash{
amount = genlib_rational:round(
genlib_rational:mul(
Expand All @@ -182,7 +182,7 @@ compute_product(Fun, [CV | CVRest], CV0, Context) ->
CVRest
).

compute_product(Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context) ->
compute_product(Fun, CV, #domain_Cash{amount = AmountMin, currency = Currency} = CVMin, CV0, Context) ->
case compute_volume(CV, Context) of
#domain_Cash{amount = Amount, currency = Currency} ->
CVMin#domain_Cash{amount = compute_product_fun(Fun, AmountMin, Amount)};
Expand Down
6 changes: 3 additions & 3 deletions apps/hellgate/src/hg_cashflow_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ collect_allocation_cash_flow(
construct_transaction_cashflow(
Amount,
PaymentInstitution,
Context = #{
#{
revision := Revision,
operation := OpType,
shop := {_, Shop},
varset := VS
}
} = Context
) ->
MerchantPaymentsTerms1 =
case maps:get(merchant_terms, Context, undefined) of
Expand All @@ -114,7 +114,7 @@ construct_transaction_cashflow(
AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)),
construct_final_cashflow(MerchantCashflow, #{operation_amount => Amount}, AccountMap).

construct_provider_cashflow(PaymentInstitution, Context = #{provision_terms := ProvisionTerms}) ->
construct_provider_cashflow(PaymentInstitution, #{provision_terms := ProvisionTerms} = Context) ->
ProviderCashflowSelector = get_provider_cashflow_selector(ProvisionTerms),
ProviderCashflow = get_selector_value(provider_payment_cash_flow, ProviderCashflowSelector),
AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)),
Expand Down
2 changes: 1 addition & 1 deletion apps/hellgate/src/hg_datetime.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
%%

-spec format_dt(datetime()) -> timestamp().
format_dt(Dt = {_, _}) ->
format_dt({_, _} = Dt) ->
Ts = genlib_time:daytime_to_unixtime(Dt),
format_ts(Ts).

Expand Down
32 changes: 16 additions & 16 deletions apps/hellgate/src/hg_fault_detector_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,24 @@ build_operation_id(ServiceType, IDs) ->
hg_utils:construct_complex_id(lists:flatten([<<"hellgate_operation">>, genlib:to_binary(ServiceType), MappedIDs])).

-spec init_service(service_id(), service_config()) -> {ok, initialised} | {error, any()} | disabled.
init_service(ServiceId, ServiceConfig) ->
call('InitService', {ServiceId, ServiceConfig}).
init_service(ServiceID, ServiceConfig) ->
call('InitService', {ServiceID, ServiceConfig}).

-spec get_statistics([service_id()]) -> [service_stats()].
get_statistics(ServiceIds) when is_list(ServiceIds) ->
call('GetStatistics', {ServiceIds}).
get_statistics(ServiceIDs) when is_list(ServiceIDs) ->
call('GetStatistics', {ServiceIDs}).

-spec register_operation(operation_status(), service_id(), operation_id(), service_config()) ->
{ok, registered} | {error, not_found} | {error, any()} | disabled.
register_operation(Status, ServiceId, OperationId, ServiceConfig) ->
register_operation(Status, ServiceID, OperationID, ServiceConfig) ->
OperationState =
case Status of
start -> {Status, ?state_start(hg_datetime:format_now())};
error -> {Status, ?state_error(hg_datetime:format_now())};
finish -> {Status, ?state_finish(hg_datetime:format_now())}
end,
Operation = ?operation(OperationId, OperationState),
call('RegisterOperation', {ServiceId, Operation, ServiceConfig}).
Operation = ?operation(OperationID, OperationState),
call('RegisterOperation', {ServiceID, Operation, ServiceConfig}).

%% PRIVATE

Expand All @@ -125,7 +125,7 @@ maybe_call(false = _FDEnabled, 'GetStatistics', _Args, _Opts, _Deadline) ->
maybe_call(false = _FDEnabled, _Service, _Args, _Opts, _Deadline) ->
disabled.

do_call('InitService', {ServiceId, _ServiceConfig} = Args, Opts, Deadline) ->
do_call('InitService', {ServiceID, _ServiceConfig} = Args, Opts, Deadline) ->
try hg_woody_wrapper:call(fault_detector, 'InitService', Args, Opts, Deadline) of
{ok, _Result} -> {ok, initialised}
catch
Expand All @@ -134,14 +134,14 @@ do_call('InitService', {ServiceId, _ServiceConfig} = Args, Opts, Deadline) ->
Class =:= result_unknown
->
ErrorText = "Unable to init service ~p in fault detector, ~p:~p",
_ = logger:warning(ErrorText, [ServiceId, error, Reason]),
_ = logger:warning(ErrorText, [ServiceID, error, Reason]),
{error, Reason};
error:{woody_error, {_Source, result_unexpected, _Details}} = Reason ->
ErrorText = "Unable to init service ~p in fault detector, ~p:~p",
_ = logger:error(ErrorText, [ServiceId, error, Reason]),
_ = logger:error(ErrorText, [ServiceID, error, Reason]),
{error, Reason}
end;
do_call('GetStatistics', {ServiceIds} = Args, Opts, Deadline) ->
do_call('GetStatistics', {ServiceIDs} = Args, Opts, Deadline) ->
try hg_woody_wrapper:call(fault_detector, 'GetStatistics', Args, Opts, Deadline) of
{ok, Stats} -> Stats
catch
Expand All @@ -150,14 +150,14 @@ do_call('GetStatistics', {ServiceIds} = Args, Opts, Deadline) ->
Class =:= result_unknown
->
String = "Unable to get statistics for services ~p from fault detector, ~p:~p",
_ = logger:warning(String, [ServiceIds, error, Reason]),
_ = logger:warning(String, [ServiceIDs, error, Reason]),
[];
error:{woody_error, {_Source, result_unexpected, _Details}} = Reason ->
String = "Unable to get statistics for services ~p from fault detector, ~p:~p",
_ = logger:error(String, [ServiceIds, error, Reason]),
_ = logger:error(String, [ServiceIDs, error, Reason]),
[]
end;
do_call('RegisterOperation', {ServiceId, OperationId, _ServiceConfig} = Args, Opts, Deadline) ->
do_call('RegisterOperation', {ServiceID, OperationID, _ServiceConfig} = Args, Opts, Deadline) ->
try hg_woody_wrapper:call(fault_detector, 'RegisterOperation', Args, Opts, Deadline) of
{ok, _Result} ->
{ok, registered};
Expand All @@ -169,10 +169,10 @@ do_call('RegisterOperation', {ServiceId, OperationId, _ServiceConfig} = Args, Op
Class =:= result_unknown
->
ErrorText = "Unable to register operation ~p for service ~p in fault detector, ~p:~p",
_ = logger:warning(ErrorText, [OperationId, ServiceId, error, Reason]),
_ = logger:warning(ErrorText, [OperationID, ServiceID, error, Reason]),
{error, Reason};
error:{woody_error, {_Source, result_unexpected, _Details}} = Reason ->
ErrorText = "Unable to register operation ~p for service ~p in fault detector, ~p:~p",
_ = logger:error(ErrorText, [OperationId, ServiceId, error, Reason]),
_ = logger:error(ErrorText, [OperationID, ServiceID, error, Reason]),
{error, Reason}
end.
4 changes: 2 additions & 2 deletions apps/hellgate/src/hg_inspector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ inspect(
RiskScore.

get_payment_info(
Shop = #domain_ShopConfig{
#domain_ShopConfig{
category = CategoryRef,
location = Location
},
} = Shop,
#domain_Invoice{
party_ref = PartyConfigRef,
shop_ref = ShopConfigRef,
Expand Down
32 changes: 16 additions & 16 deletions apps/hellgate/src/hg_invoice.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
%% API

-spec get(hg_machine:id()) -> {ok, st()} | {error, notfound}.
get(Id) ->
case hg_machine:get_history(?NS, Id) of
get(ID) ->
case hg_machine:get_history(?NS, ID) of
{ok, History} ->
{ok, collapse_history(unmarshal_history(History))};
Error ->
Expand All @@ -108,7 +108,7 @@ get_payment(PaymentID, St) ->
end.

-spec get_payment_opts(st()) -> hg_invoice_payment:opts().
get_payment_opts(St = #st{invoice = Invoice, party = undefined}) ->
get_payment_opts(#st{invoice = Invoice, party = undefined} = St) ->
{PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)),
#{
party => Party,
Expand All @@ -126,7 +126,7 @@ get_payment_opts(#st{invoice = Invoice, party = Party, party_config_ref = PartyC

-spec get_payment_opts(hg_domain:revision(), st()) ->
hg_invoice_payment:opts().
get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
get_payment_opts(Revision, #st{invoice = Invoice} = St) ->
{PartyConfigRef, Party} = hg_party:checkout(get_party_config_ref(St), Revision),
#{
party => Party,
Expand All @@ -144,7 +144,7 @@ get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
revision()
) ->
invoice().
create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations, DomainRevision) ->
create(ID, InvoiceTplID, #payproc_InvoiceParams{} = V, _Allocation, Mutations, DomainRevision) ->
PartyConfigRef = V#payproc_InvoiceParams.party_id,
ShopConfigRef = V#payproc_InvoiceParams.shop_id,
Cost = V#payproc_InvoiceParams.cost,
Expand Down Expand Up @@ -262,8 +262,8 @@ process_with_tag(Tag, F) ->
%%

-spec fail(hg_machine:id()) -> ok.
fail(Id) ->
try hg_machine:call(?NS, Id, fail) of
fail(ID) ->
try hg_machine:call(?NS, ID, fail) of
{error, failed} ->
ok;
{error, Error} ->
Expand Down Expand Up @@ -315,7 +315,7 @@ handle_repair({changes, Changes, RepairAction, Params}, St) ->
};
handle_repair({scenario, _}, #st{activity = Activity}) when Activity =:= invoice orelse Activity =:= undefined ->
throw({exception, invoice_has_no_active_payment});
handle_repair({scenario, Scenario}, St = #st{activity = {payment, PaymentID}}) ->
handle_repair({scenario, Scenario}, #st{activity = {payment, PaymentID}} = St) ->
PaymentSession = get_payment_session(PaymentID, St),
Activity = hg_invoice_payment:get_activity(PaymentSession),
case {Scenario, Activity} of
Expand All @@ -329,11 +329,11 @@ handle_repair({scenario, Scenario}, St = #st{activity = {payment, PaymentID}}) -
process_signal(Signal, #{history := History}) ->
handle_result(handle_signal(Signal, collapse_history(unmarshal_history(History)))).

handle_signal(timeout, St = #st{activity = {payment, PaymentID}}) ->
handle_signal(timeout, #st{activity = {payment, PaymentID}} = St) ->
% there's a payment pending
PaymentSession = get_payment_session(PaymentID, St),
process_payment_signal(timeout, PaymentID, PaymentSession, St);
handle_signal(timeout, St = #st{activity = invoice}) ->
handle_signal(timeout, #st{activity = invoice} = St) ->
% invoice is expired
handle_expiration(St).

Expand Down Expand Up @@ -493,10 +493,10 @@ handle_call({session_change, _Tag, _SessionChange} = Call, St) ->

-spec dispatch_to_session({callback, tag(), callback()} | {session_change, tag(), session_change()}, st()) ->
call_result().
dispatch_to_session({callback, Tag, {provider, Payload}}, St = #st{activity = {payment, PaymentID}}) ->
dispatch_to_session({callback, Tag, {provider, Payload}}, #st{activity = {payment, PaymentID}} = St) ->
PaymentSession = get_payment_session(PaymentID, St),
process_payment_call({callback, Tag, Payload}, PaymentID, PaymentSession, St);
dispatch_to_session({session_change, _Tag, _SessionChange} = Call, St = #st{activity = {payment, PaymentID}}) ->
dispatch_to_session({session_change, _Tag, _SessionChange} = Call, #st{activity = {payment, PaymentID}} = St) ->
PaymentSession = get_payment_session(PaymentID, St),
process_payment_call(Call, PaymentID, PaymentSession, St);
dispatch_to_session(_Call, _St) ->
Expand Down Expand Up @@ -733,7 +733,7 @@ define_refund_id(#payproc_InvoicePaymentRefundParams{id = ID}, _PaymentSession)
-define(MANUAL_REFUND_ID_PREFIX, "m").

%% If something breaks - this is why
force_refund_id_format(manual_refund, Correct = <<?MANUAL_REFUND_ID_PREFIX, _Rest/binary>>) ->
force_refund_id_format(manual_refund, <<?MANUAL_REFUND_ID_PREFIX, _Rest/binary>> = Correct) ->
Correct;
force_refund_id_format(manual_refund, Incorrect) ->
<<?MANUAL_REFUND_ID_PREFIX, Incorrect/binary>>;
Expand Down Expand Up @@ -816,7 +816,7 @@ try_to_get_repair_state({complex, #payproc_InvoiceRepairComplex{scenarios = Scen
try_to_get_repair_state(Scenario, St) ->
repair_scenario(Scenario, St).

repair_complex([], St = #st{activity = {payment, PaymentID}}) ->
repair_complex([], #st{activity = {payment, PaymentID}} = St) ->
PaymentSession = get_payment_session(PaymentID, St),
Activity = hg_invoice_payment:get_activity(PaymentSession),
throw({exception, {activity_not_compatible_with_complex_scenario, Activity}});
Expand All @@ -828,7 +828,7 @@ repair_complex([Scenario | Rest], St) ->
repair_complex(Rest, St)
end.

repair_scenario(Scenario, St = #st{activity = {payment, PaymentID}}) ->
repair_scenario(Scenario, #st{activity = {payment, PaymentID}} = St) ->
PaymentSession = get_payment_session(PaymentID, St),
Activity = hg_invoice_payment:get_activity(PaymentSession),
NewActivity =
Expand Down Expand Up @@ -923,7 +923,7 @@ try_get_payment_session(PaymentID, #st{payments = Payments}) ->
undefined
end.

set_payment_session(PaymentID, PaymentSession, St = #st{payments = Payments}) ->
set_payment_session(PaymentID, PaymentSession, #st{payments = Payments} = St) ->
St#st{payments = lists:keystore(PaymentID, 1, Payments, {PaymentID, PaymentSession})}.

%%
Expand Down
6 changes: 3 additions & 3 deletions apps/hellgate/src/hg_invoice_mutation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cart_is_not_valid_for_mutation(Lines) ->
apply_mutations(Mutations, Invoice) ->
lists:foldl(fun apply_mutation/2, Invoice, genlib:define(Mutations, [])).

apply_mutation(Mutation = {amount, #domain_InvoiceAmountMutation{mutated = NewAmount}}, Invoice) ->
apply_mutation({amount, #domain_InvoiceAmountMutation{mutated = NewAmount}} = Mutation, Invoice) ->
#domain_Invoice{cost = Cost, mutations = Mutations} = Invoice,
update_invoice_details_price(NewAmount, Invoice#domain_Invoice{
cost = Cost#domain_Cash{amount = NewAmount},
Expand All @@ -76,7 +76,7 @@ apply_mutation(Mutation = {amount, #domain_InvoiceAmountMutation{mutated = NewAm
apply_mutation(_, Invoice) ->
Invoice.

update_invoice_details_price(NewAmount, Invoice = #domain_Invoice{details = Details}) ->
update_invoice_details_price(NewAmount, #domain_Invoice{details = Details} = Invoice) ->
case Details#domain_InvoiceDetails.cart of
Cart = #domain_InvoiceCart{lines = [Line]} ->
NewCart = Cart#domain_InvoiceCart{
Expand All @@ -89,7 +89,7 @@ update_invoice_details_price(NewAmount, Invoice = #domain_Invoice{details = Deta
Invoice
end.

update_invoice_line_price(NewAmount, Line = #domain_InvoiceLine{price = Price}) ->
update_invoice_line_price(NewAmount, #domain_InvoiceLine{price = Price} = Line) ->
Line#domain_InvoiceLine{price = Price#domain_Cash{amount = NewAmount}}.

-spec make_mutations([mutation_params()], mutation_context()) -> [mutation()].
Expand Down
Loading
Loading