Skip to content

Commit d950df9

Browse files
authored
New routing (#201)
* import new routing engine * finish first path * fixed * fixed * fixed more * returned routing ctx * fixed after review * added requested changes * fixed dialyzer * fixed after merge * added log parse
1 parent 7013bfc commit d950df9

16 files changed

Lines changed: 2089 additions & 1466 deletions

apps/hellgate/src/hg_inspector.erl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-module(hg_inspector).
22

3+
-export([fill_blacklist/2]).
34
-export([check_blacklist/1]).
45
-export([inspect/4]).
56

@@ -26,6 +27,37 @@
2627
inspector := inspector()
2728
}.
2829

30+
-spec fill_blacklist(hg_route:t(), blacklist_context()) -> hg_route:t().
31+
fill_blacklist(Route, #{
32+
revision := Revision,
33+
token := Token,
34+
inspector := #domain_Inspector{
35+
proxy = Proxy
36+
}
37+
}) when Token =/= undefined ->
38+
#domain_ProviderRef{id = ProviderID} = hg_route:provider_ref(Route),
39+
#domain_TerminalRef{id = TerminalID} = hg_route:terminal_ref(Route),
40+
Context = #proxy_inspector_BlackListContext{
41+
first_id = genlib:to_binary(ProviderID),
42+
second_id = genlib:to_binary(TerminalID),
43+
field_name = <<"CARD_TOKEN">>,
44+
value = Token
45+
},
46+
DeadLine = woody_deadline:from_timeout(genlib_app:env(hellgate, inspect_timeout, infinity)),
47+
{ok, Check} = issue_call(
48+
'IsBlacklisted',
49+
{Context},
50+
hg_proxy:get_call_options(
51+
Proxy,
52+
Revision
53+
),
54+
false,
55+
DeadLine
56+
),
57+
hg_route:set_blacklisted(Check, Route);
58+
fill_blacklist(Route, _Ctx) ->
59+
Route.
60+
2961
-spec check_blacklist(blacklist_context()) -> boolean().
3062
check_blacklist(#{
3163
route := Route,

apps/hellgate/src/hg_invoice_payment.erl

Lines changed: 226 additions & 140 deletions
Large diffs are not rendered by default.

apps/hellgate/src/hg_invoice_payment_chargeback.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ do_create(Opts, CreateParams = ?chargeback_params(Levy, Body, _Reason)) ->
291291
ShopConfigRef = get_invoice_shop_config_ref(Invoice),
292292
ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
293293
VS = collect_validation_varset(PartyConfigRef, ShopObj, Payment, Body),
294-
PaymentsTerms = hg_routing:get_payment_terms(Route, VS, Revision),
294+
PaymentsTerms = hg_party:get_route_payment_terms(Route, VS, Revision),
295295
ProviderTerms = get_provider_chargeback_terms(PaymentsTerms, Payment),
296296
ServiceTerms = get_merchant_chargeback_terms(Party, Shop, VS, Revision, CreatedAt),
297297
_ = validate_currency(Body, Payment),
@@ -427,7 +427,7 @@ build_chargeback_final_cash_flow(State, Opts) ->
427427
ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
428428
VS = collect_validation_varset(PartyConfigRef, ShopObj, Payment, Body),
429429
ServiceTerms = get_merchant_chargeback_terms(Party, Shop, VS, Revision, CreatedAt),
430-
PaymentsTerms = hg_routing:get_payment_terms(Route, VS, Revision),
430+
PaymentsTerms = hg_party:get_route_payment_terms(Route, VS, Revision),
431431
ProviderTerms = get_provider_chargeback_terms(PaymentsTerms, Payment),
432432
ServiceCashFlow = get_chargeback_service_cash_flow(ServiceTerms),
433433
ProviderCashFlow = get_chargeback_provider_cash_flow(ProviderTerms),

apps/hellgate/src/hg_invoice_payment_refund.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ get_provider_terms(Revision, Payment, Invoice, Refund) ->
381381
ShopObj = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
382382
VS0 = construct_payment_flow(Payment),
383383
VS1 = collect_validation_varset(get_injected_party_config_ref(Refund), ShopObj, Payment, VS0),
384-
hg_routing:get_payment_terms(Route, VS1, Revision).
384+
hg_party:get_route_payment_terms(Route, VS1, Revision).
385385

386386
construct_payment_flow(Payment) ->
387387
#domain_InvoicePayment{

apps/hellgate/src/hg_invoice_registered_payment.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ get_turnover_limits(Payment, Route, St) ->
214214
PaymentTool = get_payer_payment_tool(Payer),
215215
RiskScore = hg_invoice_payment:get_risk_score(St),
216216
VS = collect_validation_varset(PartyConfigRef, ShopObj, Cost, PaymentTool, RiskScore),
217-
ProviderTerms = hg_routing:get_payment_terms(Route, VS, Revision),
217+
ProviderTerms = hg_party:get_route_payment_terms(Route, VS, Revision),
218218
hg_limiter:get_turnover_limits(ProviderTerms, strict).
219219

220220
construct_payment(

apps/hellgate/src/hg_party.erl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
44
-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl").
5+
-include_lib("hellgate/include/domain.hrl").
56

67
%% Party support functions
78

9+
-export([get_route_payment_terms/3]).
10+
-export([get_route_provision_terms/3]).
811
-export([get_party/1]).
912
-export([get_party_revision/0]).
1013
-export([checkout/2]).
@@ -21,9 +24,38 @@
2124
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
2225
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
2326
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
27+
-type payment_terms() :: dmsl_domain_thrift:'PaymentsProvisionTerms'().
28+
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
29+
-type varset() :: hg_varset:varset().
30+
-type revision() :: hg_domain:revision().
2431

2532
%% Interface
2633

34+
-spec get_route_payment_terms(hg_route:payment_route(), varset(), revision()) -> payment_terms() | undefined.
35+
get_route_payment_terms(Route, VS, Revision) ->
36+
TermsSet = get_route_provision_terms(Route, VS, Revision),
37+
TermsSet#domain_ProvisionTermSet.payments.
38+
39+
-spec get_route_provision_terms(hg_route:payment_route(), varset(), revision()) -> provision_terms() | undefined.
40+
get_route_provision_terms(?route(ProviderRef, TerminalRef), VS, Revision) ->
41+
PreparedVS = hg_varset:prepare_varset(VS),
42+
{Client, Context} = get_party_client(),
43+
{ok, TermsSet} = party_client_thrift:compute_provider_terminal_terms(
44+
ProviderRef,
45+
TerminalRef,
46+
Revision,
47+
PreparedVS,
48+
Client,
49+
Context
50+
),
51+
TermsSet.
52+
53+
get_party_client() ->
54+
HgContext = hg_context:load(),
55+
Client = hg_context:get_party_client(HgContext),
56+
Context = hg_context:get_party_client_context(HgContext),
57+
{Client, Context}.
58+
2759
-spec get_party(party_config_ref()) -> {party_config_ref(), party()} | hg_domain:get_error().
2860
get_party(PartyConfigRef) ->
2961
checkout(PartyConfigRef, get_party_revision()).

apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,8 @@ payment_w_all_blacklisted(C) ->
447447
?payment_ev(PaymentID, ?shop_limit_initiated()),
448448
?payment_ev(PaymentID, ?shop_limit_applied()),
449449
?payment_ev(PaymentID, ?risk_score_changed(_RiskScore)),
450-
?payment_ev(PaymentID, ?route_changed(_Route)),
451-
?payment_ev(PaymentID, ?payment_rollback_started({failure, _Failure}))
452-
] = next_changes(InvoiceID, 6, Client),
450+
?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure})))
451+
] = next_changes(InvoiceID, 5, Client),
453452
?invoice_state(
454453
?invoice_w_status(?invoice_unpaid()),
455454
[_PaymentSt]

apps/hellgate/test/hg_invoice_tests_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8934,8 +8934,8 @@ construct_domain_fixture(BaseLimitsRevision) ->
89348934
?ruleset(5),
89358935
<<"SubMain">>,
89368936
{candidates, [
8937-
?candidate({constant, true}, ?trm(1)),
8938-
?candidate({constant, true}, ?trm(7))
8937+
?candidate({constant, true}, ?trm(7)),
8938+
?candidate({constant, true}, ?trm(1))
89398939
]}
89408940
),
89418941
hg_ct_fixture:construct_payment_routing_ruleset(?ruleset(3), <<"Prohibitions">>, {candidates, []}),

0 commit comments

Comments
 (0)