Skip to content
Open
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
32 changes: 32 additions & 0 deletions apps/hellgate/src/hg_inspector.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-module(hg_inspector).

-export([fill_blacklist/2]).
-export([check_blacklist/1]).
-export([inspect/4]).

Expand All @@ -26,6 +27,37 @@
inspector := inspector()
}.

-spec fill_blacklist(hg_route:t(), blacklist_context()) -> hg_route:t().
fill_blacklist(Route, #{
revision := Revision,
token := Token,
inspector := #domain_Inspector{
proxy = Proxy
}
}) when Token =/= undefined ->
#domain_ProviderRef{id = ProviderID} = hg_route:provider_ref(Route),
#domain_TerminalRef{id = TerminalID} = hg_route:terminal_ref(Route),
Context = #proxy_inspector_BlackListContext{
first_id = genlib:to_binary(ProviderID),
second_id = genlib:to_binary(TerminalID),
field_name = <<"CARD_TOKEN">>,
value = Token
},
DeadLine = woody_deadline:from_timeout(genlib_app:env(hellgate, inspect_timeout, infinity)),
{ok, Check} = issue_call(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы InvalidRequest ловил и игнорил тоже.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

там же issue_call ловит все {exception, Error} ->

'IsBlacklisted',
{Context},
hg_proxy:get_call_options(
Proxy,
Revision
),
false,
DeadLine
),
hg_route:set_blacklisted(Check, Route);
fill_blacklist(Route, _Ctx) ->
Route.

-spec check_blacklist(blacklist_context()) -> boolean().
check_blacklist(#{
route := Route,
Expand Down
316 changes: 196 additions & 120 deletions apps/hellgate/src/hg_invoice_payment.erl

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/hellgate/src/hg_invoice_payment_chargeback.erl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ do_create(Opts, CreateParams = ?chargeback_params(Levy, Body, _Reason)) ->
ShopConfigRef = get_invoice_shop_config_ref(Invoice),
ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
VS = collect_validation_varset(PartyConfigRef, ShopObj, Payment, Body),
PaymentsTerms = hg_routing:get_payment_terms(Route, VS, Revision),
PaymentsTerms = hg_party:get_route_payment_terms(Route, VS, Revision),
ProviderTerms = get_provider_chargeback_terms(PaymentsTerms, Payment),
ServiceTerms = get_merchant_chargeback_terms(Party, Shop, VS, Revision, CreatedAt),
_ = validate_currency(Body, Payment),
Expand Down Expand Up @@ -427,7 +427,7 @@ build_chargeback_final_cash_flow(State, Opts) ->
ShopObj = {_, Shop} = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
VS = collect_validation_varset(PartyConfigRef, ShopObj, Payment, Body),
ServiceTerms = get_merchant_chargeback_terms(Party, Shop, VS, Revision, CreatedAt),
PaymentsTerms = hg_routing:get_payment_terms(Route, VS, Revision),
PaymentsTerms = hg_party:get_route_payment_terms(Route, VS, Revision),
ProviderTerms = get_provider_chargeback_terms(PaymentsTerms, Payment),
ServiceCashFlow = get_chargeback_service_cash_flow(ServiceTerms),
ProviderCashFlow = get_chargeback_provider_cash_flow(ProviderTerms),
Expand Down
2 changes: 1 addition & 1 deletion apps/hellgate/src/hg_invoice_payment_refund.erl
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ get_provider_terms(Revision, Payment, Invoice, Refund) ->
ShopObj = hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
VS0 = construct_payment_flow(Payment),
VS1 = collect_validation_varset(get_injected_party_config_ref(Refund), ShopObj, Payment, VS0),
hg_routing:get_payment_terms(Route, VS1, Revision).
hg_party:get_route_payment_terms(Route, VS1, Revision).

construct_payment_flow(Payment) ->
#domain_InvoicePayment{
Expand Down
2 changes: 1 addition & 1 deletion apps/hellgate/src/hg_invoice_registered_payment.erl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ get_turnover_limits(Payment, Route, St) ->
PaymentTool = get_payer_payment_tool(Payer),
RiskScore = hg_invoice_payment:get_risk_score(St),
VS = collect_validation_varset(PartyConfigRef, ShopObj, Cost, PaymentTool, RiskScore),
ProviderTerms = hg_routing:get_payment_terms(Route, VS, Revision),
ProviderTerms = hg_party:get_route_payment_terms(Route, VS, Revision),
hg_limiter:get_turnover_limits(ProviderTerms, strict).

construct_payment(
Expand Down
32 changes: 32 additions & 0 deletions apps/hellgate/src/hg_party.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_conf_v2_thrift.hrl").
-include_lib("hellgate/include/domain.hrl").

%% Party support functions

-export([get_route_payment_terms/3]).
-export([get_route_provision_terms/3]).
-export([get_party/1]).
-export([get_party_revision/0]).
-export([checkout/2]).
Expand All @@ -21,9 +24,38 @@
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
-type payment_terms() :: dmsl_domain_thrift:'PaymentsProvisionTerms'().
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
-type varset() :: hg_varset:varset().
-type revision() :: hg_domain:revision().

%% Interface

-spec get_route_payment_terms(hg_route:payment_route(), varset(), revision()) -> payment_terms() | undefined.
get_route_payment_terms(Route, VS, Revision) ->
TermsSet = get_route_provision_terms(Route, VS, Revision),
TermsSet#domain_ProvisionTermSet.payments.

-spec get_route_provision_terms(hg_route:payment_route(), varset(), revision()) -> provision_terms() | undefined.
get_route_provision_terms(?route(ProviderRef, TerminalRef), VS, Revision) ->
PreparedVS = hg_varset:prepare_varset(VS),
{Client, Context} = get_party_client(),
{ok, TermsSet} = party_client_thrift:compute_provider_terminal_terms(
ProviderRef,
TerminalRef,
Revision,
PreparedVS,
Client,
Context
),
TermsSet.
Comment on lines +34 to +51
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY. get_route_payment_terms может просто ходить в get_route_provision_terms


get_party_client() ->
HgContext = hg_context:load(),
Client = hg_context:get_party_client(HgContext),
Context = hg_context:get_party_client_context(HgContext),
{Client, Context}.

-spec get_party(party_config_ref()) -> {party_config_ref(), party()} | hg_domain:get_error().
get_party(PartyConfigRef) ->
checkout(PartyConfigRef, get_party_revision()).
Expand Down
5 changes: 2 additions & 3 deletions apps/hellgate/test/hg_invoice_lite_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,8 @@ payment_w_all_blacklisted(C) ->
?payment_ev(PaymentID, ?shop_limit_initiated()),
?payment_ev(PaymentID, ?shop_limit_applied()),
?payment_ev(PaymentID, ?risk_score_changed(_RiskScore)),
?payment_ev(PaymentID, ?route_changed(_Route)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как так получилось? Куда он делся?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

роутинг начал по другому работать - там теперь если у тебя после получения роутов пустой список то нет события с роутами, сразу идет фейл платежа

?payment_ev(PaymentID, ?payment_rollback_started({failure, _Failure}))
] = next_changes(InvoiceID, 6, Client),
?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, _Failure})))
] = next_changes(InvoiceID, 5, Client),
?invoice_state(
?invoice_w_status(?invoice_unpaid()),
[_PaymentSt]
Expand Down
4 changes: 2 additions & 2 deletions apps/hellgate/test/hg_invoice_tests_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8934,8 +8934,8 @@ construct_domain_fixture(BaseLimitsRevision) ->
?ruleset(5),
<<"SubMain">>,
{candidates, [
?candidate({constant, true}, ?trm(1)),
?candidate({constant, true}, ?trm(7))
?candidate({constant, true}, ?trm(7)),
?candidate({constant, true}, ?trm(1))
]}
),
hg_ct_fixture:construct_payment_routing_ruleset(?ruleset(3), <<"Prohibitions">>, {candidates, []}),
Expand Down
Loading
Loading