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
6 changes: 3 additions & 3 deletions apps/hellgate/include/allocation.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
body = Body
}).

-define(allocation_trx_target_shop(OwnerID, ShopID),
-define(allocation_trx_target_shop(PartyConfigRef, ShopConfigRef),
{shop, #domain_AllocationTransactionTargetShop{
owner_id = OwnerID,
shop_id = ShopID
party_ref = PartyConfigRef,
shop_ref = ShopConfigRef
}}
).

Expand Down
2 changes: 1 addition & 1 deletion apps/hellgate/include/hg_invoice.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
invoice :: undefined | hg_invoice:invoice(),
payments = [] :: [{hg_invoice:payment_id(), hg_invoice:payment_st()}],
party :: undefined | hg_invoice:party(),
party_id :: undefined | hg_invoice:party_id()
party_config_ref :: undefined | hg_invoice:party_config_ref()
}).

-endif.
18 changes: 9 additions & 9 deletions apps/hellgate/src/hg_accounting.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
-type thrift_account() :: dmsl_accounter_thrift:'Account'().

-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
-type shop_id() :: dmsl_domain_thrift:'ShopConfigID'().
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
-type route() :: hg_route:payment_route().
-type payment_institution() :: dmsl_domain_thrift:'PaymentInstitution'().
-type provider() :: dmsl_domain_thrift:'Provider'().
Expand All @@ -48,8 +48,8 @@

-type collect_account_context() :: #{
payment := payment(),
party_id := party_id(),
shop := {shop_id(), shop()},
party_config_ref := party_config_ref(),
shop := {shop_config_ref(), shop()},
route := route(),
payment_institution := payment_institution(),
provider := provider(),
Expand Down Expand Up @@ -101,23 +101,23 @@ create_account(CurrencyCode, Description) ->
-spec collect_account_map(collect_account_context()) -> map().
collect_account_map(#{
payment := Payment,
party_id := PartyID,
party_config_ref := PartyConfigRef,
shop := ShopObj,
route := Route,
payment_institution := PaymentInstitution,
provider := Provider,
varset := VS,
revision := Revision
}) ->
Map0 = collect_merchant_account_map(PartyID, ShopObj, #{}),
Map0 = collect_merchant_account_map(PartyConfigRef, ShopObj, #{}),
Map1 = collect_provider_account_map(Payment, Provider, Route, Map0),
Map2 = collect_system_account_map(Payment, PaymentInstitution, Revision, Map1),
collect_external_account_map(Payment, VS, Revision, Map2).

-spec collect_merchant_account_map(party_id(), {shop_id(), shop()}, map()) -> map().
collect_merchant_account_map(PartyID, {ShopID, #domain_ShopConfig{account = Account}}, Acc) ->
-spec collect_merchant_account_map(party_config_ref(), {shop_config_ref(), shop()}, map()) -> map().
collect_merchant_account_map(PartyConfigRef, {ShopConfigRef, #domain_ShopConfig{account = Account}}, Acc) ->
Acc#{
merchant => {PartyID, ShopID},
merchant => {PartyConfigRef, ShopConfigRef},
{merchant, settlement} => Account#domain_ShopAccount.settlement,
{merchant, guarantee} => Account#domain_ShopAccount.guarantee
}.
Expand Down
20 changes: 10 additions & 10 deletions apps/hellgate/src/hg_allocation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

-type party() :: dmsl_domain_thrift:'PartyConfig'().
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
-type party_id() :: dmsl_payproc_thrift:'PartyID'().
-type shop_id() :: dmsl_payproc_thrift:'ShopID'().
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
-type target_map() :: #{
party_id => party_id(),
shop_id => shop_id()
party_config_ref => party_config_ref(),
shop_config_ref => shop_config_ref()
}.

-type sub_errors() ::
Expand Down Expand Up @@ -85,14 +85,14 @@ assert_allocatable(_Allocation, _PaymentAllocationServiceTerms, _Party, _Shop, _
{error, allocation_not_allowed}.

-spec construct_target(target_map()) -> target().
construct_target(#{party_id := PartyID, shop_id := ShopID}) ->
?allocation_trx_target_shop(PartyID, ShopID).
construct_target(#{party_config_ref := PartyConfigRef, shop_config_ref := ShopConfigRef}) ->
?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef).

-spec calculate(allocation_prototype(), party_id(), shop_id(), cash()) -> allocation().
calculate(AllocationPrototype, PartyID, ShopID, Cost) ->
-spec calculate(allocation_prototype(), party_config_ref(), shop_config_ref(), cash()) -> allocation().
calculate(AllocationPrototype, PartyConfigRef, ShopConfigRef, Cost) ->
FeeTarget = construct_target(#{
party_id => PartyID,
shop_id => ShopID
party_config_ref => PartyConfigRef,
shop_config_ref => ShopConfigRef
}),
calculate(AllocationPrototype, FeeTarget, Cost).

Expand Down
12 changes: 6 additions & 6 deletions apps/hellgate/src/hg_cashflow.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-type account_id() :: dmsl_domain_thrift:'AccountID'().
-type account_map() :: #{
account() => account_id(),
merchant := {party_id(), shop_id()},
merchant := {party_config_ref(), shop_config_ref()},
provider := route()
}.
-type context() :: dmsl_domain_thrift:'CashFlowContext'().
Expand All @@ -27,8 +27,8 @@
-type cash_volume() :: dmsl_domain_thrift:'CashVolume'().
-type final_cash_flow_account() :: dmsl_domain_thrift:'FinalCashFlowAccount'().

-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
-type route() :: hg_route:payment_route().

%%
Expand Down Expand Up @@ -80,10 +80,10 @@ construct_final_account(AccountType, AccountMap) ->
transaction_account = construct_transaction_account(AccountType, AccountMap)
}.

construct_transaction_account({merchant, MerchantFlowAccount}, #{merchant := {PartyID, ShopID}}) ->
construct_transaction_account({merchant, MerchantFlowAccount}, #{merchant := {PartyConfigRef, ShopConfigRef}}) ->
AccountOwner = #domain_MerchantTransactionAccountOwner{
party_id = PartyID,
shop_id = ShopID
party_ref = PartyConfigRef,
shop_ref = ShopConfigRef
},
{merchant, #domain_MerchantTransactionAccount{
type = MerchantFlowAccount,
Expand Down
25 changes: 13 additions & 12 deletions apps/hellgate/src/hg_cashflow_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
-type cash_flow_context() :: #{
operation := refund | payment,
provision_terms := dmsl_domain_thrift:'PaymentsProvisionTerms'(),
party := {party_id(), party()},
shop := {shop_id(), shop()},
party := {party_config_ref(), party()},
shop := {shop_config_ref(), shop()},
route := route(),
payment := payment(),
provider := provider(),
Expand All @@ -29,9 +29,9 @@
-export([collect_cashflow/2]).

-type party() :: dmsl_domain_thrift:'PartyConfig'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
-type shop() :: dmsl_domain_thrift:'ShopConfig'().
-type shop_id() :: dmsl_domain_thrift:'ShopConfigID'().
-type shop_config_ref() :: dmsl_domain_thrift:'ShopConfigRef'().
-type route() :: dmsl_domain_thrift:'PaymentRoute'().
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
-type refund() :: dmsl_domain_thrift:'InvoicePaymentRefund'().
Expand Down Expand Up @@ -70,20 +70,21 @@ collect_allocation_cash_flow(
) ->
lists:foldl(
fun(?allocation_trx(_ID, Target, Amount), Acc) ->
?allocation_trx_target_shop(PartyID, ShopID) = Target,
{PartyID, TargetParty} = hg_party:get_party(PartyID),
{ShopID, TargetShop} = hg_party:get_shop(ShopID, TargetParty, Revision),
?allocation_trx_target_shop(PartyConfigRef, ShopConfigRef) = Target,
{PartyConfigRef, TargetParty} = hg_party:get_party(PartyConfigRef),
{#domain_ShopConfigRef{id = ShopConfigID} = ShopConfigRef, TargetShop} =
hg_party:get_shop(ShopConfigRef, PartyConfigRef, Revision),
VS1 = VS0#{
party_id => PartyID,
shop_id => ShopID,
party_config_ref => PartyConfigRef,
shop_id => ShopConfigID,
cost => Amount
},
AllocationPaymentInstitution =
get_cashflow_payment_institution(Shop, VS1, Revision),
construct_transaction_cashflow(
Amount,
AllocationPaymentInstitution,
Context#{party => {PartyID, TargetParty}, shop => {ShopID, TargetShop}}
Context#{party => {PartyConfigRef, TargetParty}, shop => {ShopConfigRef, TargetShop}}
) ++ Acc
end,
[],
Expand Down Expand Up @@ -161,7 +162,7 @@ get_selector_value(Name, Selector) ->
hg_accounting:collect_account_context().
make_collect_account_context(PaymentInstitution, #{
payment := Payment,
party := {PartyID, _},
party := {PartyConfigRef, _},
shop := Shop,
route := Route,
provider := Provider,
Expand All @@ -170,7 +171,7 @@ make_collect_account_context(PaymentInstitution, #{
}) ->
#{
payment => Payment,
party_id => PartyID,
party_config_ref => PartyConfigRef,
shop => Shop,
route => Route,
payment_institution => PaymentInstitution,
Expand Down
8 changes: 4 additions & 4 deletions apps/hellgate/src/hg_inspector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ get_payment_info(
location = Location
},
#domain_Invoice{
owner_id = PartyID,
shop_id = ShopID,
party_ref = PartyConfigRef,
shop_ref = ShopConfigRef,
id = InvoiceID,
created_at = InvoiceCreatedAt,
due = InvoiceDue,
Expand All @@ -123,14 +123,14 @@ get_payment_info(
}
) ->
Party = #proxy_inspector_Party{
party_id = PartyID
party_ref = PartyConfigRef
},
ShopCategory = hg_domain:get(
Revision,
{category, CategoryRef}
),
ProxyShop = #proxy_inspector_Shop{
id = ShopID,
shop_ref = ShopConfigRef,
category = ShopCategory,
name = Shop#domain_ShopConfig.name,
description = Shop#domain_ShopConfig.description,
Expand Down
51 changes: 28 additions & 23 deletions apps/hellgate/src/hg_invoice.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
-export_type([payment_id/0]).
-export_type([payment_st/0]).
-export_type([party/0]).
-export_type([party_id/0]).
-export_type([party_config_ref/0]).

%% Public interface

Expand Down Expand Up @@ -77,7 +77,7 @@
-type invoice() :: dmsl_domain_thrift:'Invoice'().
-type allocation() :: dmsl_domain_thrift:'Allocation'().
-type party() :: dmsl_domain_thrift:'PartyConfig'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_config_ref() :: dmsl_domain_thrift:'PartyConfigRef'().
-type revision() :: dmt_client:vsn().

-type payment_id() :: dmsl_domain_thrift:'InvoicePaymentID'().
Expand Down Expand Up @@ -109,28 +109,28 @@ get_payment(PaymentID, St) ->

-spec get_payment_opts(st()) -> hg_invoice_payment:opts().
get_payment_opts(St = #st{invoice = Invoice, party = undefined}) ->
{PartyID, Party} = hg_party:get_party(get_party_id(St)),
{PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)),
#{
party => Party,
party_id => PartyID,
party_config_ref => PartyConfigRef,
invoice => Invoice,
timestamp => hg_datetime:format_now()
};
get_payment_opts(#st{invoice = Invoice, party = Party, party_id = PartyID}) ->
get_payment_opts(#st{invoice = Invoice, party = Party, party_config_ref = PartyConfigRef}) ->
#{
party => Party,
party_id => PartyID,
party_config_ref => PartyConfigRef,
invoice => Invoice,
timestamp => hg_datetime:format_now()
}.

-spec get_payment_opts(hg_domain:revision(), st()) ->
hg_invoice_payment:opts().
get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
{PartyID, Party} = hg_party:checkout(get_party_id(St), Revision),
{PartyConfigRef, Party} = hg_party:checkout(get_party_config_ref(St), Revision),
#{
party => Party,
party_id => PartyID,
party_config_ref => PartyConfigRef,
invoice => Invoice,
timestamp => hg_datetime:format_now()
}.
Expand All @@ -145,13 +145,13 @@ get_payment_opts(Revision, St = #st{invoice = Invoice}) ->
) ->
invoice().
create(ID, InvoiceTplID, V = #payproc_InvoiceParams{}, _Allocation, Mutations, DomainRevision) ->
OwnerID = V#payproc_InvoiceParams.party_id,
ShopID = V#payproc_InvoiceParams.shop_id,
PartyConfigRef = V#payproc_InvoiceParams.party_id,
ShopConfigRef = V#payproc_InvoiceParams.shop_id,
Cost = V#payproc_InvoiceParams.cost,
hg_invoice_mutation:apply_mutations(Mutations, #domain_Invoice{
id = ID,
shop_id = ShopID,
owner_id = OwnerID,
party_ref = PartyConfigRef,
shop_ref = ShopConfigRef,
created_at = hg_datetime:format_now(),
status = ?invoice_unpaid(),
cost = Cost,
Expand All @@ -169,13 +169,13 @@ assert_invoice(Checks, #st{} = St) when is_list(Checks) ->
lists:foldl(fun assert_invoice/2, St, Checks);
assert_invoice(operable, #st{party = Party} = St) when Party =/= undefined ->
assert_party_shop_operable(
hg_party:get_shop(get_shop_id(St), Party, hg_party:get_party_revision()),
hg_party:get_shop(get_shop_config_ref(St), get_party_config_ref(St), hg_party:get_party_revision()),
Party
),
St;
assert_invoice(unblocked, #st{party = Party} = St) when Party =/= undefined ->
assert_party_shop_unblocked(
hg_party:get_shop(get_shop_id(St), Party, hg_party:get_party_revision()),
hg_party:get_shop(get_shop_config_ref(St), get_party_config_ref(St), hg_party:get_party_revision()),
Party
),
St;
Expand Down Expand Up @@ -898,14 +898,14 @@ check_non_idle_payments_([{PaymentID, PaymentSession} | Rest], St) ->
end.

add_party_to_st(St) ->
{PartyID, Party} = hg_party:get_party(get_party_id(St)),
St#st{party = Party, party_id = PartyID}.
{PartyConfigRef, Party} = hg_party:get_party(get_party_config_ref(St)),
St#st{party = Party, party_config_ref = PartyConfigRef}.

get_party_id(#st{invoice = #domain_Invoice{owner_id = PartyID}}) ->
PartyID.
get_party_config_ref(#st{invoice = #domain_Invoice{party_ref = PartyConfigRef}}) ->
PartyConfigRef.

get_shop_id(#st{invoice = #domain_Invoice{shop_id = ShopID}}) ->
ShopID.
get_shop_config_ref(#st{invoice = #domain_Invoice{shop_ref = ShopConfigRef}}) ->
ShopConfigRef.

get_payment_session(PaymentID, St) ->
case try_get_payment_session(PaymentID, St) of
Expand Down Expand Up @@ -970,11 +970,16 @@ get_invoice_event_log(EventType, StatusName, Invoice) ->
get_invoice_params(Invoice) ->
#domain_Invoice{
id = ID,
owner_id = PartyID,
cost = ?cash(Amount, Currency),
shop_id = ShopID
party_ref = PartyConfigRef,
shop_ref = ShopConfigRef
} = Invoice,
[{id, ID}, {owner_id, PartyID}, {cost, [{amount, Amount}, {currency, Currency}]}, {shop_id, ShopID}].
[
{id, ID},
{party_ref, PartyConfigRef},
{shop_ref, ShopConfigRef},
{cost, [{amount, Amount}, {currency, Currency}]}
].

get_message(invoice_created) ->
"Invoice is created";
Expand Down
Loading
Loading