Skip to content

Commit 84d103f

Browse files
authored
BG-268: Bump damsel (#164)
* bumped, compiled and dialyzered without tests * fixed tests compile and dialyzer * bumped deps * fixed linters * bumped deps * fixed * bumped party client * bumped pm * bumped limiter * fixed
1 parent e23c41f commit 84d103f

31 files changed

Lines changed: 431 additions & 761 deletions

apps/hellgate/include/hg_invoice.hrl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
activity :: undefined | hg_invoice:activity(),
66
invoice :: undefined | hg_invoice:invoice(),
77
payments = [] :: [{hg_invoice:payment_id(), hg_invoice:payment_st()}],
8-
party :: undefined | hg_invoice:party()
8+
party :: undefined | hg_invoice:party(),
9+
party_id :: undefined | hg_invoice:party_id()
910
}).
1011

1112
-endif.

apps/hellgate/src/hg_accounting.erl

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-export([create_account/1]).
1313
-export([create_account/2]).
1414
-export([collect_account_map/1]).
15-
-export([collect_merchant_account_map/4]).
15+
-export([collect_merchant_account_map/3]).
1616
-export([collect_provider_account_map/4]).
1717
-export([collect_system_account_map/4]).
1818
-export([collect_external_account_map/4]).
@@ -27,7 +27,6 @@
2727
-include_lib("damsel/include/dmsl_accounter_thrift.hrl").
2828

2929
-type amount() :: dmsl_domain_thrift:'Amount'().
30-
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
3130
-type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
3231
-type account_id() :: dmsl_accounter_thrift:'AccountID'().
3332
-type plan_id() :: dmsl_accounter_thrift:'PlanID'().
@@ -38,8 +37,9 @@
3837
-type thrift_account() :: dmsl_accounter_thrift:'Account'().
3938

4039
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
41-
-type party() :: dmsl_domain_thrift:'PartyConfig'().
40+
-type party_id() :: dmsl_domain_thrift:'PartyID'().
4241
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
42+
-type shop_id() :: dmsl_domain_thrift:'ShopConfigID'().
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 := party(),
52-
shop := shop(),
51+
party_id := party_id(),
52+
shop := {shop_id(), shop()},
5353
route := route(),
5454
payment_institution := payment_institution(),
5555
provider := provider(),
@@ -100,29 +100,26 @@ create_account(CurrencyCode, Description) ->
100100

101101
-spec collect_account_map(collect_account_context()) -> map().
102102
collect_account_map(#{
103-
payment := #domain_InvoicePayment{cost = #domain_Cash{currency = Currency}} = Payment,
104-
party := Party,
105-
shop := Shop,
103+
payment := Payment,
104+
party_id := PartyID,
105+
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(Currency, Party, Shop, #{}),
112+
Map0 = collect_merchant_account_map(PartyID, 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(currency(), party(), shop(), map()) -> map().
118-
collect_merchant_account_map(
119-
Currency, #domain_PartyConfig{id = PartyID}, #domain_ShopConfig{id = ShopID, currency_configs = Configs}, Acc
120-
) ->
121-
#{Currency := Config} = Configs,
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) ->
122119
Acc#{
123120
merchant => {PartyID, ShopID},
124-
{merchant, settlement} => Config#domain_ShopCurrencyConfig.settlement,
125-
{merchant, guarantee} => Config#domain_ShopCurrencyConfig.guarantee
121+
{merchant, settlement} => Account#domain_ShopAccount.settlement,
122+
{merchant, guarantee} => Account#domain_ShopAccount.guarantee
126123
}.
127124

128125
-spec collect_provider_account_map(payment(), provider(), route(), map()) -> map().

apps/hellgate/src/hg_cashflow_utils.erl

Lines changed: 16 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(),
14-
shop := shop(),
13+
party := {party_id(), party()},
14+
shop := {shop_id(), shop()},
1515
route := route(),
1616
payment := payment(),
1717
provider := provider(),
@@ -29,7 +29,9 @@
2929
-export([collect_cashflow/2]).
3030

3131
-type party() :: dmsl_domain_thrift:'PartyConfig'().
32+
-type party_id() :: dmsl_domain_thrift:'PartyID'().
3233
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
34+
-type shop_id() :: dmsl_domain_thrift:'ShopConfigID'().
3335
-type route() :: dmsl_domain_thrift:'PaymentRoute'().
3436
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
3537
-type refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'().
@@ -39,8 +41,8 @@
3941
-type final_cash_flow() :: hg_cashflow:final_cash_flow().
4042

4143
-spec collect_cashflow(cash_flow_context()) -> final_cash_flow().
42-
collect_cashflow(#{party := Party, shop := Shop, varset := VS, revision := Revision} = Context) ->
43-
PaymentInstitution = get_cashflow_payment_institution(Party, Shop, VS, Revision),
44+
collect_cashflow(#{shop := {_, Shop}, varset := VS, revision := Revision} = Context) ->
45+
PaymentInstitution = get_cashflow_payment_institution(Shop, VS, Revision),
4446
collect_cashflow(PaymentInstitution, Context).
4547

4648
-spec collect_cashflow(payment_institution(), cash_flow_context()) -> final_cash_flow().
@@ -62,27 +64,26 @@ collect_allocation_cash_flow(
6264
Transactions,
6365
Context = #{
6466
revision := Revision,
65-
party := Party,
66-
shop := Shop,
67+
shop := {_, Shop},
6768
varset := VS0
6869
}
6970
) ->
7071
lists:foldl(
7172
fun(?allocation_trx(_ID, Target, Amount), Acc) ->
7273
?allocation_trx_target_shop(PartyID, ShopID) = Target,
73-
TargetParty = hg_party:get_party(PartyID),
74-
TargetShop = hg_party:get_shop(ShopID, TargetParty, Revision),
74+
{PartyID, TargetParty} = hg_party:get_party(PartyID),
75+
{ShopID, TargetShop} = hg_party:get_shop(ShopID, TargetParty, Revision),
7576
VS1 = VS0#{
76-
party_id => Party#domain_PartyConfig.id,
77-
shop_id => Shop#domain_ShopConfig.id,
77+
party_id => PartyID,
78+
shop_id => ShopID,
7879
cost => Amount
7980
},
8081
AllocationPaymentInstitution =
81-
get_cashflow_payment_institution(Party, Shop, VS1, Revision),
82+
get_cashflow_payment_institution(Shop, VS1, Revision),
8283
construct_transaction_cashflow(
8384
Amount,
8485
AllocationPaymentInstitution,
85-
Context#{party => TargetParty, shop => TargetShop}
86+
Context#{party => {PartyID, TargetParty}, shop => {ShopID, TargetShop}}
8687
) ++ Acc
8788
end,
8889
[],
@@ -95,7 +96,7 @@ construct_transaction_cashflow(
9596
Context = #{
9697
revision := Revision,
9798
operation := OpType,
98-
shop := Shop,
99+
shop := {_, Shop},
99100
varset := VS
100101
}
101102
) ->
@@ -122,7 +123,6 @@ construct_final_cashflow(Cashflow, Context, AccountMap) ->
122123
hg_cashflow:finalize(Cashflow, Context, AccountMap).
123124

124125
get_cashflow_payment_institution(
125-
_Party,
126126
#domain_ShopConfig{payment_institution = PaymentInstitutionRef},
127127
VS,
128128
Revision
@@ -161,7 +161,7 @@ get_selector_value(Name, Selector) ->
161161
hg_accounting:collect_account_context().
162162
make_collect_account_context(PaymentInstitution, #{
163163
payment := Payment,
164-
party := Party,
164+
party := {PartyID, _},
165165
shop := Shop,
166166
route := Route,
167167
provider := Provider,
@@ -170,7 +170,7 @@ make_collect_account_context(PaymentInstitution, #{
170170
}) ->
171171
#{
172172
payment => Payment,
173-
party => Party,
173+
party_id => PartyID,
174174
shop => Shop,
175175
route => Route,
176176
payment_institution => PaymentInstitution,

apps/hellgate/src/hg_inspector.erl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ inspect(
100100
RiskScore.
101101

102102
get_payment_info(
103-
#domain_ShopConfig{
104-
id = ShopID,
103+
Shop = #domain_ShopConfig{
105104
category = CategoryRef,
106-
details = ShopDetails,
107105
location = Location
108106
},
109107
#domain_Invoice{
110108
owner_id = PartyID,
109+
shop_id = ShopID,
111110
id = InvoiceID,
112111
created_at = InvoiceCreatedAt,
113112
due = InvoiceDue,
@@ -133,10 +132,8 @@ get_payment_info(
133132
ProxyShop = #proxy_inspector_Shop{
134133
id = ShopID,
135134
category = ShopCategory,
136-
details = #domain_ShopDetails{
137-
name = ShopDetails#domain_Details.name,
138-
description = ShopDetails#domain_Details.description
139-
},
135+
name = Shop#domain_ShopConfig.name,
136+
description = Shop#domain_ShopConfig.description,
140137
location = Location
141138
},
142139
ProxyInvoice = #proxy_inspector_Invoice{

apps/hellgate/src/hg_invoice.erl

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
-export_type([payment_id/0]).
3232
-export_type([payment_st/0]).
3333
-export_type([party/0]).
34+
-export_type([party_id/0]).
3435

3536
%% Public interface
3637

3738
-export([get/1]).
3839
-export([get_payment/2]).
3940
-export([get_payment_opts/1]).
40-
-export([create/5]).
41+
-export([create/6]).
4142
-export([marshal_invoice/1]).
4243
-export([unmarshal_history/1]).
4344
-export([collapse_history/1]).
@@ -76,6 +77,8 @@
7677
-type invoice() :: dmsl_domain_thrift:'Invoice'().
7778
-type allocation() :: dmsl_domain_thrift:'Allocation'().
7879
-type party() :: dmsl_domain_thrift:'PartyConfig'().
80+
-type party_id() :: dmsl_domain_thrift:'PartyID'().
81+
-type revision() :: dmt_client:vsn().
7982

8083
-type payment_id() :: dmsl_domain_thrift:'InvoicePaymentID'().
8184
-type payment_st() :: hg_invoice_payment:st().
@@ -106,23 +109,28 @@ get_payment(PaymentID, St) ->
106109

107110
-spec get_payment_opts(st()) -> hg_invoice_payment:opts().
108111
get_payment_opts(St = #st{invoice = Invoice, party = undefined}) ->
112+
{PartyID, Party} = hg_party:get_party(get_party_id(St)),
109113
#{
110-
party => hg_party:get_party(get_party_id(St)),
114+
party => Party,
115+
party_id => PartyID,
111116
invoice => Invoice,
112117
timestamp => hg_datetime:format_now()
113118
};
114-
get_payment_opts(#st{invoice = Invoice, party = Party}) ->
119+
get_payment_opts(#st{invoice = Invoice, party = Party, party_id = PartyID}) ->
115120
#{
116121
party => Party,
122+
party_id => PartyID,
117123
invoice => Invoice,
118124
timestamp => hg_datetime:format_now()
119125
}.
120126

121127
-spec get_payment_opts(hg_domain:revision(), st()) ->
122128
hg_invoice_payment:opts().
123129
get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
130+
{PartyID, Party} = hg_party:checkout(get_party_id(St), Revision),
124131
#{
125-
party => hg_party:checkout(get_party_id(St), Revision),
132+
party => Party,
133+
party_id => PartyID,
126134
invoice => Invoice,
127135
timestamp => hg_datetime:format_now()
128136
}.
@@ -132,10 +140,11 @@ get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
132140
undefined | hg_machine:id(),
133141
invoice_params(),
134142
undefined | allocation(),
135-
[hg_invoice_mutation:mutation()]
143+
[hg_invoice_mutation:mutation()],
144+
revision()
136145
) ->
137146
invoice().
138-
create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations) ->
147+
create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations, DomainRevision) ->
139148
OwnerID = V#payproc_InvoiceParams.party_id,
140149
ShopID = V#payproc_InvoiceParams.shop_id,
141150
Cost = V#payproc_InvoiceParams.cost,
@@ -146,6 +155,7 @@ create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations) -
146155
created_at = hg_datetime:format_now(),
147156
status = ?invoice_unpaid(),
148157
cost = Cost,
158+
domain_revision = DomainRevision,
149159
due = V#payproc_InvoiceParams.due,
150160
details = V#payproc_InvoiceParams.details,
151161
context = V#payproc_InvoiceParams.context,
@@ -174,12 +184,12 @@ assert_invoice({status, Status}, #st{invoice = #domain_Invoice{status = {Status,
174184
assert_invoice({status, _Status}, #st{invoice = #domain_Invoice{status = Invalid}}) ->
175185
throw(?invalid_invoice_status(Invalid)).
176186

177-
assert_party_shop_operable(Shop, Party) ->
187+
assert_party_shop_operable({_ShopID, Shop}, Party) ->
178188
_ = assert_party_operable(Party),
179189
_ = assert_shop_operable(Shop),
180190
ok.
181191

182-
assert_party_shop_unblocked(Shop, Party) ->
192+
assert_party_shop_unblocked({_ShopID, Shop}, Party) ->
183193
_ = assert_party_unblocked(Party),
184194
_ = assert_shop_unblocked(Shop),
185195
ok.
@@ -381,15 +391,15 @@ process_call(Call, #{history := History}) ->
381391

382392
-spec handle_call(call(), st()) -> call_result().
383393
handle_call({{'Invoicing', 'StartPayment'}, {_InvoiceID, PaymentParams}}, St0) ->
384-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
394+
St = add_party_to_st(St0),
385395
_ = assert_invoice(operable, St),
386396
start_payment(PaymentParams, St);
387397
handle_call({{'Invoicing', 'RegisterPayment'}, {_InvoiceID, PaymentParams}}, St0) ->
388-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
398+
St = add_party_to_st(St0),
389399
_ = assert_invoice(unblocked, St),
390400
register_payment(PaymentParams, St);
391401
handle_call({{'Invoicing', 'CapturePayment'}, {_InvoiceID, PaymentID, Params}}, St0) ->
392-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
402+
St = add_party_to_st(St0),
393403
_ = assert_invoice(operable, St),
394404
#payproc_InvoicePaymentCaptureParams{
395405
reason = Reason,
@@ -406,7 +416,7 @@ handle_call({{'Invoicing', 'CapturePayment'}, {_InvoiceID, PaymentID, Params}},
406416
state => St
407417
};
408418
handle_call({{'Invoicing', 'CancelPayment'}, {_InvoiceID, PaymentID, Reason}}, St0) ->
409-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
419+
St = add_party_to_st(St0),
410420
_ = assert_invoice(operable, St),
411421
PaymentSession = get_payment_session(PaymentID, St),
412422
{ok, {Changes, Action}} = hg_invoice_payment:cancel(PaymentSession, Reason),
@@ -417,15 +427,15 @@ handle_call({{'Invoicing', 'CancelPayment'}, {_InvoiceID, PaymentID, Reason}}, S
417427
state => St
418428
};
419429
handle_call({{'Invoicing', 'Fulfill'}, {_InvoiceID, Reason}}, St0) ->
420-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
430+
St = add_party_to_st(St0),
421431
_ = assert_invoice([operable, {status, paid}], St),
422432
#{
423433
response => ok,
424434
changes => [?invoice_status_changed(?invoice_fulfilled(hg_utils:format_reason(Reason)))],
425435
state => St
426436
};
427437
handle_call({{'Invoicing', 'Rescind'}, {_InvoiceID, Reason}}, St0) ->
428-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
438+
St = add_party_to_st(St0),
429439
_ = assert_invoice([operable, {status, unpaid}], St),
430440
_ = assert_no_pending_payment(St),
431441
#{
@@ -435,12 +445,12 @@ handle_call({{'Invoicing', 'Rescind'}, {_InvoiceID, Reason}}, St0) ->
435445
state => St
436446
};
437447
handle_call({{'Invoicing', 'RefundPayment'}, {_InvoiceID, PaymentID, Params}}, St0) ->
438-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
448+
St = add_party_to_st(St0),
439449
_ = assert_invoice(operable, St),
440450
PaymentSession = get_payment_session(PaymentID, St),
441451
start_refund(refund, Params, PaymentID, PaymentSession, St);
442452
handle_call({{'Invoicing', 'CreateManualRefund'}, {_InvoiceID, PaymentID, Params}}, St0) ->
443-
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
453+
St = add_party_to_st(St0),
444454
_ = assert_invoice(operable, St),
445455
PaymentSession = get_payment_session(PaymentID, St),
446456
start_refund(manual_refund, Params, PaymentID, PaymentSession, St);
@@ -887,6 +897,10 @@ check_non_idle_payments_([{PaymentID, PaymentSession} | Rest], St) ->
887897
check_non_idle_payments_(Rest, St)
888898
end.
889899

900+
add_party_to_st(St) ->
901+
{PartyID, Party} = hg_party:get_party(get_party_id(St)),
902+
St#st{party = Party, party_id = PartyID}.
903+
890904
get_party_id(#st{invoice = #domain_Invoice{owner_id = PartyID}}) ->
891905
PartyID.
892906

0 commit comments

Comments
 (0)