Skip to content

Commit ed2b268

Browse files
committed
BG-360: Bump damsel
1 parent 84d103f commit ed2b268

32 files changed

Lines changed: 3678 additions & 1683 deletions

apps/hellgate/include/allocation.hrl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
body = Body
7474
}).
7575

76-
-define(allocation_trx_target_shop(OwnerID, ShopID),
76+
-define(allocation_trx_target_shop(PartyConfigRef, ShopConfigRef),
7777
{shop, #domain_AllocationTransactionTargetShop{
78-
owner_id = OwnerID,
79-
shop_id = ShopID
78+
party_ref = PartyConfigRef,
79+
shop_ref = ShopConfigRef
8080
}}
8181
).
8282

apps/hellgate/include/hg_invoice.hrl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
invoice :: undefined | hg_invoice:invoice(),
77
payments = [] :: [{hg_invoice:payment_id(), hg_invoice:payment_st()}],
88
party :: undefined | hg_invoice:party(),
9-
party_id :: undefined | hg_invoice:party_id()
9+
party_config_ref :: undefined | hg_invoice:party_config_ref()
1010
}).
1111

1212
-endif.

apps/hellgate/src/hg_accounting.erl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
-type thrift_account() :: dmsl_accounter_thrift:'Account'().
3838

3939
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
40-
-type party_id() :: dmsl_domain_thrift:'PartyID'().
40+
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
4141
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
42-
-type shop_id() :: dmsl_domain_thrift:'ShopConfigID'().
42+
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
4343
-type route() :: hg_route:payment_route().
4444
-type payment_institution() :: dmsl_domain_thrift:'PaymentInstitution'().
4545
-type provider() :: dmsl_domain_thrift:'Provider'().
@@ -48,8 +48,8 @@
4848

4949
-type collect_account_context() :: #{
5050
payment := payment(),
51-
party_id := party_id(),
52-
shop := {shop_id(), shop()},
51+
party_config_ref := party_config_ref(),
52+
shop := {shop_config_ref(), shop()},
5353
route := route(),
5454
payment_institution := payment_institution(),
5555
provider := provider(),
@@ -101,23 +101,25 @@ create_account(CurrencyCode, Description) ->
101101
-spec collect_account_map(collect_account_context()) -> map().
102102
collect_account_map(#{
103103
payment := Payment,
104-
party_id := PartyID,
104+
party_config_ref := PartyConfigRef,
105105
shop := ShopObj,
106106
route := Route,
107107
payment_institution := PaymentInstitution,
108108
provider := Provider,
109109
varset := VS,
110110
revision := Revision
111111
}) ->
112-
Map0 = collect_merchant_account_map(PartyID, ShopObj, #{}),
112+
Map0 = collect_merchant_account_map(PartyConfigRef, ShopObj, #{}),
113113
Map1 = collect_provider_account_map(Payment, Provider, Route, Map0),
114114
Map2 = collect_system_account_map(Payment, PaymentInstitution, Revision, Map1),
115115
collect_external_account_map(Payment, VS, Revision, Map2).
116116

117-
-spec collect_merchant_account_map(party_id(), {shop_id(), shop()}, map()) -> map().
118-
collect_merchant_account_map(PartyID, {ShopID, #domain_ShopConfig{account = Account}}, Acc) ->
117+
-spec collect_merchant_account_map(party_config_ref(), {shop_config_ref(), shop()}, map()) -> map().
118+
collect_merchant_account_map(
119+
PartyConfigRef, {ShopConfigRef, #domain_ShopConfig{account = Account}}, Acc
120+
) ->
119121
Acc#{
120-
merchant => {PartyID, ShopID},
122+
merchant => {PartyConfigRef, ShopConfigRef},
121123
{merchant, settlement} => Account#domain_ShopAccount.settlement,
122124
{merchant, guarantee} => Account#domain_ShopAccount.guarantee
123125
}.
@@ -134,7 +136,9 @@ collect_provider_account_map(Payment, #domain_Provider{accounts = ProviderAccoun
134136
-spec collect_system_account_map(payment(), payment_institution(), revision(), map()) -> map().
135137
collect_system_account_map(Payment, PaymentInstitution, Revision, Acc) ->
136138
Currency = get_currency(get_payment_cost(Payment)),
137-
SystemAccount = hg_payment_institution:get_system_account(Currency, Revision, PaymentInstitution),
139+
SystemAccount = hg_payment_institution:get_system_account(
140+
Currency, Revision, PaymentInstitution
141+
),
138142
Acc#{
139143
{system, settlement} => SystemAccount#domain_SystemAccount.settlement,
140144
{system, subagent} => SystemAccount#domain_SystemAccount.subagent

apps/hellgate/src/hg_allocation.erl

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
-type party() :: dmsl_domain_thrift:'PartyConfig'().
2424
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
25-
-type party_id() :: dmsl_payproc_thrift:'PartyID'().
26-
-type shop_id() :: dmsl_payproc_thrift:'ShopID'().
25+
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
26+
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
2727
-type target_map() :: #{
28-
party_id => party_id(),
29-
shop_id => shop_id()
28+
party_config_ref => party_config_ref(),
29+
shop_config_ref => shop_config_ref()
3030
}.
3131

3232
-type sub_errors() ::
@@ -85,14 +85,18 @@ assert_allocatable(_Allocation, _PaymentAllocationServiceTerms, _Party, _Shop, _
8585
{error, allocation_not_allowed}.
8686

8787
-spec construct_target(target_map()) -> target().
88-
construct_target(#{party_id := PartyID, shop_id := ShopID}) ->
89-
?allocation_trx_target_shop(PartyID, ShopID).
90-
91-
-spec calculate(allocation_prototype(), party_id(), shop_id(), cash()) -> allocation().
92-
calculate(AllocationPrototype, PartyID, ShopID, Cost) ->
88+
construct_target(#{
89+
party_config_ref := PartyConfigRef,
90+
shop_config_ref := ShopConfigRef
91+
}) ->
92+
?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef).
93+
94+
-spec calculate(allocation_prototype(), party_config_ref(), shop_config_ref(), cash()) ->
95+
allocation().
96+
calculate(AllocationPrototype, PartyConfigRef, ShopConfigRef, Cost) ->
9397
FeeTarget = construct_target(#{
94-
party_id => PartyID,
95-
shop_id => ShopID
98+
party_config_ref => PartyConfigRef,
99+
shop_config_ref => ShopConfigRef
96100
}),
97101
calculate(AllocationPrototype, FeeTarget, Cost).
98102

@@ -177,7 +181,9 @@ calculate_trxs([Head | Transactions], FeeTarget, CostLeft, FeeAcc, ID0, Acc0) ->
177181
construct_positive_trx(ID, Target, Amount, Details, Body) ->
178182
case construct_trx(ID, Target, Amount, Details, Body) of
179183
undefined ->
180-
throw({invalid_transaction, ?allocation_trx(ID, Target, Amount, Details, Body), zero_amount});
184+
throw(
185+
{invalid_transaction, ?allocation_trx(ID, Target, Amount, Details, Body), zero_amount}
186+
);
181187
Trx ->
182188
Trx
183189
end.
@@ -215,7 +221,9 @@ add_fee(undefined, FeeAmount) ->
215221
add_fee(FeeCost, FeeAmount) ->
216222
hg_cash:add(FeeCost, FeeAmount).
217223

218-
calculate_trxs_body(?allocation_trx_prototype_body_amount(?cash(_, SymCode) = Amount), _FeeTarget, _TP) ->
224+
calculate_trxs_body(
225+
?allocation_trx_prototype_body_amount(?cash(_, SymCode) = Amount), _FeeTarget, _TP
226+
) ->
219227
{undefined, Amount, ?cash(0, SymCode)};
220228
calculate_trxs_body(?allocation_trx_prototype_body_total(Total, Fee), FeeTarget, TP) ->
221229
CalculatedFee = calculate_trxs_fee(Fee, Total),
@@ -229,7 +237,9 @@ calculate_trxs_body(?allocation_trx_prototype_body_total(Total, Fee), FeeTarget,
229237

230238
calculate_trxs_fee(?allocation_trx_prototype_fee_fixed(Amount), _Total) ->
231239
Amount;
232-
calculate_trxs_fee(?allocation_trx_prototype_fee_share(P, Q, RoundingMethod0), ?cash(Total, SymCode)) ->
240+
calculate_trxs_fee(
241+
?allocation_trx_prototype_fee_share(P, Q, RoundingMethod0), ?cash(Total, SymCode)
242+
) ->
233243
RoundingMethod1 = genlib:define(RoundingMethod0, round_half_away_from_zero),
234244
R = genlib_rational:new(P * Total, Q),
235245
Amount = ?cash(genlib_rational:round(R, RoundingMethod1), SymCode),

apps/hellgate/src/hg_cashflow.erl

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
-type account_id() :: dmsl_domain_thrift:'AccountID'().
1818
-type account_map() :: #{
1919
account() => account_id(),
20-
merchant := {party_id(), shop_id()},
20+
merchant := {party_config_ref(), shop_config_ref()},
2121
provider := route()
2222
}.
2323
-type context() :: dmsl_domain_thrift:'CashFlowContext'().
@@ -27,8 +27,8 @@
2727
-type cash_volume() :: dmsl_domain_thrift:'CashVolume'().
2828
-type final_cash_flow_account() :: dmsl_domain_thrift:'FinalCashFlowAccount'().
2929

30-
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
31-
-type party_id() :: dmsl_domain_thrift:'PartyID'().
30+
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
31+
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
3232
-type route() :: hg_route:payment_route().
3333

3434
%%
@@ -80,10 +80,12 @@ construct_final_account(AccountType, AccountMap) ->
8080
transaction_account = construct_transaction_account(AccountType, AccountMap)
8181
}.
8282

83-
construct_transaction_account({merchant, MerchantFlowAccount}, #{merchant := {PartyID, ShopID}}) ->
83+
construct_transaction_account({merchant, MerchantFlowAccount}, #{
84+
merchant := {PartyConfigRef, ShopConfigRef}
85+
}) ->
8486
AccountOwner = #domain_MerchantTransactionAccountOwner{
85-
party_id = PartyID,
86-
shop_id = ShopID
87+
party_ref = PartyConfigRef,
88+
shop_ref = ShopConfigRef
8789
},
8890
{merchant, #domain_MerchantTransactionAccount{
8991
type = MerchantFlowAccount,
@@ -117,7 +119,9 @@ resolve_account(AccountType, AccountMap) ->
117119
#{AccountType := V} ->
118120
V;
119121
#{} ->
120-
error({misconfiguration, {'Cash flow account can not be mapped', {AccountType, AccountMap}}})
122+
error(
123+
{misconfiguration, {'Cash flow account can not be mapped', {AccountType, AccountMap}}}
124+
)
121125
end.
122126

123127
%%
@@ -142,7 +146,9 @@ revert_details(Details) ->
142146
).
143147

144148
-define(share(P, Q, Of, RoundingMethod),
145-
{share, #domain_CashVolumeShare{'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod}}
149+
{share, #domain_CashVolumeShare{
150+
'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod
151+
}}
146152
).
147153

148154
-define(product(Fun, CVs),
@@ -182,12 +188,16 @@ compute_product(Fun, [CV | CVRest], CV0, Context) ->
182188
CVRest
183189
).
184190

185-
compute_product(Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context) ->
191+
compute_product(
192+
Fun, CV, CVMin = #domain_Cash{amount = AmountMin, currency = Currency}, CV0, Context
193+
) ->
186194
case compute_volume(CV, Context) of
187195
#domain_Cash{amount = Amount, currency = Currency} ->
188196
CVMin#domain_Cash{amount = compute_product_fun(Fun, AmountMin, Amount)};
189197
_ ->
190-
error({misconfiguration, {'Cash volume product over volumes of different currencies', CV0}})
198+
error(
199+
{misconfiguration, {'Cash volume product over volumes of different currencies', CV0}}
200+
)
191201
end.
192202

193203
compute_product_fun(min_of, V1, V2) ->
@@ -232,7 +242,9 @@ increment_remainder(AccountType, Cash, Acc) ->
232242
decrement_remainder(AccountType, ?cash(Amount, Currency), Acc) ->
233243
modify_remainder(AccountType, ?cash(-Amount, Currency), Acc).
234244

235-
modify_remainder(#domain_FinalCashFlowAccount{account_type = AccountType}, ?cash(Amount, Currency), Acc) ->
245+
modify_remainder(
246+
#domain_FinalCashFlowAccount{account_type = AccountType}, ?cash(Amount, Currency), Acc
247+
) ->
236248
maps:update_with(
237249
AccountType,
238250
fun(?cash(A, C)) when C == Currency ->

apps/hellgate/src/hg_cashflow_utils.erl

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
-type cash_flow_context() :: #{
1111
operation := refund | payment,
1212
provision_terms := dmsl_domain_thrift:'PaymentsProvisionTerms'(),
13-
party := {party_id(), party()},
14-
shop := {shop_id(), shop()},
13+
party := {party_config_ref(), party()},
14+
shop := {shop_config_ref(), shop()},
1515
route := route(),
1616
payment := payment(),
1717
provider := provider(),
@@ -29,9 +29,9 @@
2929
-export([collect_cashflow/2]).
3030

3131
-type party() :: dmsl_domain_thrift:'PartyConfig'().
32-
-type party_id() :: dmsl_domain_thrift:'PartyID'().
32+
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
3333
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
34-
-type shop_id() :: dmsl_domain_thrift:'ShopConfigID'().
34+
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
3535
-type route() :: dmsl_domain_thrift:'PaymentRoute'().
3636
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
3737
-type refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'().
@@ -70,20 +70,24 @@ collect_allocation_cash_flow(
7070
) ->
7171
lists:foldl(
7272
fun(?allocation_trx(_ID, Target, Amount), Acc) ->
73-
?allocation_trx_target_shop(PartyID, ShopID) = Target,
74-
{PartyID, TargetParty} = hg_party:get_party(PartyID),
75-
{ShopID, TargetShop} = hg_party:get_shop(ShopID, TargetParty, Revision),
73+
?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef) = Target,
74+
{PartyConfigRef, TargetParty} = hg_party:get_party(PartyConfigRef),
75+
{#domain_ShopConfigRef{id = ShopConfigID} = ShopConfigRef, TargetShop} = hg_party:get_shop(
76+
ShopConfigRef, PartyConfigRef, Revision
77+
),
7678
VS1 = VS0#{
77-
party_id => PartyID,
78-
shop_id => ShopID,
79+
party_config_ref => PartyConfigRef,
80+
shop_id => ShopConfigID,
7981
cost => Amount
8082
},
8183
AllocationPaymentInstitution =
8284
get_cashflow_payment_institution(Shop, VS1, Revision),
8385
construct_transaction_cashflow(
8486
Amount,
8587
AllocationPaymentInstitution,
86-
Context#{party => {PartyID, TargetParty}, shop => {ShopID, TargetShop}}
88+
Context#{
89+
party => {PartyConfigRef, TargetParty}, shop => {ShopConfigRef, TargetShop}
90+
}
8791
) ++ Acc
8892
end,
8993
[],
@@ -110,14 +114,20 @@ construct_transaction_cashflow(
110114
end,
111115
MerchantCashflowSelector = get_terms_cashflow(OpType, MerchantPaymentsTerms1),
112116
MerchantCashflow = get_selector_value(merchant_payment_fees, MerchantCashflowSelector),
113-
AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)),
117+
AccountMap = hg_accounting:collect_account_map(
118+
make_collect_account_context(PaymentInstitution, Context)
119+
),
114120
construct_final_cashflow(MerchantCashflow, #{operation_amount => Amount}, AccountMap).
115121

116122
construct_provider_cashflow(PaymentInstitution, Context = #{provision_terms := ProvisionTerms}) ->
117123
ProviderCashflowSelector = get_provider_cashflow_selector(ProvisionTerms),
118124
ProviderCashflow = get_selector_value(provider_payment_cash_flow, ProviderCashflowSelector),
119-
AccountMap = hg_accounting:collect_account_map(make_collect_account_context(PaymentInstitution, Context)),
120-
construct_final_cashflow(ProviderCashflow, #{operation_amount => get_amount(Context)}, AccountMap).
125+
AccountMap = hg_accounting:collect_account_map(
126+
make_collect_account_context(PaymentInstitution, Context)
127+
),
128+
construct_final_cashflow(
129+
ProviderCashflow, #{operation_amount => get_amount(Context)}, AccountMap
130+
).
121131

122132
construct_final_cashflow(Cashflow, Context, AccountMap) ->
123133
hg_cashflow:finalize(Cashflow, Context, AccountMap).
@@ -140,7 +150,9 @@ get_amount(#{payment := #domain_InvoicePayment{cost = Cost}}) ->
140150

141151
get_provider_cashflow_selector(#domain_PaymentsProvisionTerms{cash_flow = ProviderCashflowSelector}) ->
142152
ProviderCashflowSelector;
143-
get_provider_cashflow_selector(#domain_PaymentRefundsProvisionTerms{cash_flow = ProviderCashflowSelector}) ->
153+
get_provider_cashflow_selector(#domain_PaymentRefundsProvisionTerms{
154+
cash_flow = ProviderCashflowSelector
155+
}) ->
144156
ProviderCashflowSelector.
145157

146158
get_terms_cashflow(payment, MerchantPaymentsTerms) ->
@@ -161,7 +173,7 @@ get_selector_value(Name, Selector) ->
161173
hg_accounting:collect_account_context().
162174
make_collect_account_context(PaymentInstitution, #{
163175
payment := Payment,
164-
party := {PartyID, _},
176+
party := {PartyConfigRef, _},
165177
shop := Shop,
166178
route := Route,
167179
provider := Provider,
@@ -170,7 +182,7 @@ make_collect_account_context(PaymentInstitution, #{
170182
}) ->
171183
#{
172184
payment => Payment,
173-
party_id => PartyID,
185+
party_config_ref => PartyConfigRef,
174186
shop => Shop,
175187
route => Route,
176188
payment_institution => PaymentInstitution,

apps/hellgate/src/hg_inspector.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ get_payment_info(
105105
location = Location
106106
},
107107
#domain_Invoice{
108-
owner_id = PartyID,
109-
shop_id = ShopID,
108+
party_ref = PartyConfigRef,
109+
shop_ref = ShopConfigRef,
110110
id = InvoiceID,
111111
created_at = InvoiceCreatedAt,
112112
due = InvoiceDue,
@@ -123,14 +123,14 @@ get_payment_info(
123123
}
124124
) ->
125125
Party = #proxy_inspector_Party{
126-
party_id = PartyID
126+
party_ref = PartyConfigRef
127127
},
128128
ShopCategory = hg_domain:get(
129129
Revision,
130130
{category, CategoryRef}
131131
),
132132
ProxyShop = #proxy_inspector_Shop{
133-
id = ShopID,
133+
shop_ref = ShopConfigRef,
134134
category = ShopCategory,
135135
name = Shop#domain_ShopConfig.name,
136136
description = Shop#domain_ShopConfig.description,

0 commit comments

Comments
 (0)