Try erlfmt (#479)

Co-authored-by: Sergey Yelin <elinsn@gmail.com>
This commit is contained in:
Andrey Fadeev 2020-09-25 18:14:03 +03:00 committed by GitHub
parent 52967bd114
commit 8093d04623
56 changed files with 3084 additions and 3123 deletions

View File

@ -20,7 +20,7 @@ BASE_IMAGE_TAG := da0ab769f01b650b389d18fc85e7418e727cbe96
BUILD_IMAGE_TAG := 442c2c274c1d8e484e5213089906a4271641d95e
CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze plt_update \
start devrel release clean distclean
start devrel release clean distclean format check_format
CALL_W_CONTAINER := $(CALL_ANYWHERE) test
@ -50,6 +50,12 @@ xref: submodules
lint:
elvis rock
check_format:
$(REBAR) fmt -c
format:
$(REBAR) fmt -w
dialyze: submodules
$(REBAR) dialyzer

View File

@ -3,38 +3,31 @@
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
-define(
cm_modification_unit(ModID, Timestamp, Mod, UserInfo),
#claim_management_ModificationUnit{
modification_id = ModID,
created_at = Timestamp,
modification = Mod,
user_info = UserInfo
}
).
-define(cm_modification_unit(ModID, Timestamp, Mod, UserInfo), #claim_management_ModificationUnit{
modification_id = ModID,
created_at = Timestamp,
modification = Mod,
user_info = UserInfo
}).
-define(
cm_party_modification(ModID, Timestamp, Mod, UserInfo),
-define(cm_party_modification(ModID, Timestamp, Mod, UserInfo),
?cm_modification_unit(ModID, Timestamp, {party_modification, Mod}, UserInfo)
).
%%% Contractor
-define(
cm_contractor_modification(ContractorID, Mod),
-define(cm_contractor_modification(ContractorID, Mod),
{contractor_modification, #claim_management_ContractorModificationUnit{
id = ContractorID,
id = ContractorID,
modification = Mod
}}
).
-define(
cm_contractor_creation(ContractorID, Contractor),
-define(cm_contractor_creation(ContractorID, Contractor),
?cm_contractor_modification(ContractorID, {creation, Contractor})
).
-define(
cm_identity_documents_modification(Documents),
-define(cm_identity_documents_modification(Documents),
{
identity_documents_modification,
#claim_management_ContractorIdentityDocumentsModification{
@ -43,87 +36,75 @@
}
).
-define(
cm_contractor_identity_documents_modification(ContractorID, Documents),
-define(cm_contractor_identity_documents_modification(ContractorID, Documents),
?cm_contractor_modification(ContractorID, ?cm_identity_documents_modification(Documents))
).
-define(
cm_contractor_identification_level_modification(ContractorID, Level),
-define(cm_contractor_identification_level_modification(ContractorID, Level),
?cm_contractor_modification(ContractorID, {identification_level_modification, Level})
).
%%% Contract
-define(
cm_contract_modification(ContractID, Mod),
-define(cm_contract_modification(ContractID, Mod),
{contract_modification, #claim_management_ContractModificationUnit{
id = ContractID,
id = ContractID,
modification = Mod
}}
).
-define(
cm_contract_creation(ContractID, ContractParams),
-define(cm_contract_creation(ContractID, ContractParams),
?cm_contract_modification(ContractID, {creation, ContractParams})
).
-define(cm_contract_termination(Reason),
{termination, #claim_management_ContractTermination{reason = Reason}}).
{termination, #claim_management_ContractTermination{reason = Reason}}
).
-define(
cm_payout_tool_modification(PayoutToolID, Mod),
-define(cm_payout_tool_modification(PayoutToolID, Mod),
{payout_tool_modification, #claim_management_PayoutToolModificationUnit{
payout_tool_id = PayoutToolID,
modification = Mod
modification = Mod
}}
).
-define(
cm_payout_tool_creation(PayoutToolID, PayoutToolParams),
-define(cm_payout_tool_creation(PayoutToolID, PayoutToolParams),
?cm_payout_tool_modification(PayoutToolID, {creation, PayoutToolParams})
).
-define(
cm_payout_tool_info_modification(PayoutToolID, Info),
-define(cm_payout_tool_info_modification(PayoutToolID, Info),
?cm_payout_tool_modification(PayoutToolID, {info_modification, Info})
).
-define(
cm_payout_schedule_modification(BusinessScheduleRef),
-define(cm_payout_schedule_modification(BusinessScheduleRef),
{payout_schedule_modification, #claim_management_ScheduleModification{
schedule = BusinessScheduleRef
}}
).
-define(
cm_cash_register_unit_creation(ID, Params),
-define(cm_cash_register_unit_creation(ID, Params),
{creation, #claim_management_CashRegisterParams{
cash_register_provider_id = ID,
cash_register_provider_params = Params
}}
).
-define(
cm_cash_register_modification_unit_modification(ShopID, Unit),
-define(cm_cash_register_modification_unit_modification(ShopID, Unit),
?cm_shop_modification(ShopID, {cash_register_modification_unit, Unit})
).
-define (
cm_cash_register_modification_unit(Unit),
-define(cm_cash_register_modification_unit(Unit),
{cash_register_modification_unit, Unit}
).
-define(
cm_adjustment_modification(ContractAdjustmentID, Mod),
-define(cm_adjustment_modification(ContractAdjustmentID, Mod),
{adjustment_modification, #claim_management_ContractAdjustmentModificationUnit{
adjustment_id = ContractAdjustmentID,
modification = Mod
modification = Mod
}}
).
-define(
cm_adjustment_creation(ContractAdjustmentID, ContractTemplateRef),
-define(cm_adjustment_creation(ContractAdjustmentID, ContractTemplateRef),
?cm_adjustment_modification(
ContractAdjustmentID,
{creation, #claim_management_ContractAdjustmentParams{
@ -134,40 +115,35 @@
%%% Shop
-define(
cm_shop_modification(ShopID, Mod),
-define(cm_shop_modification(ShopID, Mod),
{shop_modification, #claim_management_ShopModificationUnit{
id = ShopID,
id = ShopID,
modification = Mod
}}
).
-define(
cm_shop_contract_modification(ContractID, PayoutToolID),
-define(cm_shop_contract_modification(ContractID, PayoutToolID),
{contract_modification, #claim_management_ShopContractModification{
contract_id = ContractID,
payout_tool_id = PayoutToolID
}}
).
-define(
cm_shop_creation(ShopID, ShopParams),
-define(cm_shop_creation(ShopID, ShopParams),
?cm_shop_modification(ShopID, {creation, ShopParams})
).
-define(
cm_shop_account_creation_params(CurrencyRef),
-define(cm_shop_account_creation_params(CurrencyRef),
{shop_account_creation, #claim_management_ShopAccountParams{
currency = CurrencyRef
}}
).
-define(
cm_shop_account_creation(ShopID, CurrencyRef),
-define(cm_shop_account_creation(ShopID, CurrencyRef),
?cm_shop_modification(
ShopID,
?cm_shop_account_creation_params(CurrencyRef)
)
).
-endif.
-endif.

View File

@ -1,10 +1,8 @@
-ifndef(__pm_domain_hrl__).
-define(__pm_domain_hrl__, included).
-define(currency(SymCode),
#domain_CurrencyRef{symbolic_code = SymCode}).
-define(currency(SymCode), #domain_CurrencyRef{symbolic_code = SymCode}).
-define(cash(Amount, SymCode),
#domain_Cash{amount = Amount, currency = ?currency(SymCode)}).
-define(cash(Amount, SymCode), #domain_Cash{amount = Amount, currency = ?currency(SymCode)}).
-endif.

View File

@ -2,279 +2,204 @@
-define(__pm_legacy_party_structures_hrl__, included).
-define(legacy_party_created(Party),
{party_created, Party}).
{party_created, Party}
).
-define(legacy_party(ID, ContactInfo, CreatedAt, Blocking, Suspension, Contracts, Shops),
{domain_Party,
ID,
ContactInfo,
CreatedAt,
Blocking,
Suspension,
Contracts,
Shops
}).
{domain_Party, ID, ContactInfo, CreatedAt, Blocking, Suspension, Contracts, Shops}
).
-define(legacy_claim(
ID,
Status,
Changeset,
Revision,
CreatedAt,
UpdatedAt
),
{payproc_Claim,
ID,
Status,
Changeset,
Revision,
CreatedAt,
UpdatedAt
}
ID,
Status,
Changeset,
Revision,
CreatedAt,
UpdatedAt
),
{payproc_Claim, ID, Status, Changeset, Revision, CreatedAt, UpdatedAt}
).
-define(legacy_claim_updated(ID, Changeset, ClaimRevision, Timestamp),
{claim_updated, {payproc_ClaimUpdated, ID, Changeset, ClaimRevision, Timestamp}}).
{claim_updated, {payproc_ClaimUpdated, ID, Changeset, ClaimRevision, Timestamp}}
).
-define(legacy_contract_modification(ID, Modification),
{contract_modification, {payproc_ContractModificationUnit, ID, Modification}}).
{contract_modification, {payproc_ContractModificationUnit, ID, Modification}}
).
-define(legacy_contract_params_v1(Contractor, TemplateRef),
{payproc_ContractParams, Contractor, TemplateRef}).
{payproc_ContractParams, Contractor, TemplateRef}
).
-define(legacy_contract_params_v2(Contractor, TemplateRef, PaymentInstitutionRef),
{payproc_ContractParams, Contractor, TemplateRef, PaymentInstitutionRef}).
{payproc_ContractParams, Contractor, TemplateRef, PaymentInstitutionRef}
).
-define(legacy_contract_params_v3_4(Contractor, TemplateRef, PaymentInstitutionRef),
{payproc_ContractParams, Contractor, TemplateRef, PaymentInstitutionRef}).
{payproc_ContractParams, Contractor, TemplateRef, PaymentInstitutionRef}
).
-define(legacy_payout_tool_creation(ID, Params),
{payout_tool_modification, {payproc_PayoutToolModificationUnit, ID, {creation, Params}}}).
{payout_tool_modification, {payproc_PayoutToolModificationUnit, ID, {creation, Params}}}
).
-define(legacy_payout_tool_params(Currency, PayoutToolInfo),
{payproc_PayoutToolParams, Currency, PayoutToolInfo}).
{payproc_PayoutToolParams, Currency, PayoutToolInfo}
).
-define(legacy_russian_legal_entity(
RegisteredName,
RegisteredNumber,
Inn,
ActualAddress,
PostAddress,
RepresentativePosition,
RepresentativeFullName,
RepresentativeDocument,
BankAccount
),
{domain_RussianLegalEntity,
RegisteredName,
RegisteredNumber,
Inn,
ActualAddress,
PostAddress,
RepresentativePosition,
RepresentativeFullName,
RepresentativeDocument,
BankAccount
}).
RegisteredName,
RegisteredNumber,
Inn,
ActualAddress,
PostAddress,
RepresentativePosition,
RepresentativeFullName,
RepresentativeDocument,
BankAccount
),
{domain_RussianLegalEntity, RegisteredName, RegisteredNumber, Inn, ActualAddress, PostAddress,
RepresentativePosition, RepresentativeFullName, RepresentativeDocument, BankAccount}
).
-define(legacy_international_legal_entity(LegalName, TradingName, RegisteredAddress, ActualAddress),
{domain_InternationalLegalEntity,
LegalName,
TradingName,
RegisteredAddress,
ActualAddress
}).
{domain_InternationalLegalEntity, LegalName, TradingName, RegisteredAddress, ActualAddress}
).
-define(legacy_bank_account(Account, BankName, BankPostAccount, BankBik),
{domain_BankAccount,
Account,
BankName,
BankPostAccount,
BankBik
}).
{domain_BankAccount, Account, BankName, BankPostAccount, BankBik}
).
-define(legacy_international_bank_account(AccountHolder, BankName, BankAddress, Iban, Bic),
{domain_InternationalBankAccount,
AccountHolder,
BankName,
BankAddress,
Iban,
Bic
}).
{domain_InternationalBankAccount, AccountHolder, BankName, BankAddress, Iban, Bic}
).
-define(legacy_international_bank_account_v3_4_5(AccountHolder, BankName, BankAddress, Iban, Bic, LocalBankCode),
{domain_InternationalBankAccount,
AccountHolder,
BankName,
BankAddress,
Iban,
Bic,
LocalBankCode
}).
{domain_InternationalBankAccount, AccountHolder, BankName, BankAddress, Iban, Bic, LocalBankCode}
).
-define(legacy_shop_modification(ID, Modification),
{shop_modification, {payproc_ShopModificationUnit, ID, Modification}}).
{shop_modification, {payproc_ShopModificationUnit, ID, Modification}}
).
-define(legacy_schedule_modification(PayoutScheduleRef),
{payproc_ScheduleModification, PayoutScheduleRef}).
{payproc_ScheduleModification, PayoutScheduleRef}
).
-define(legacy_shop_effect(ID, Effect),
{shop_effect, {payproc_ShopEffectUnit, ID, Effect}}).
{shop_effect, {payproc_ShopEffectUnit, ID, Effect}}
).
-define(legacy_shop_v2(ID, CreatedAt, Blocking, Suspension, Details, Location, Category, Account, ContractID, PayoutToolID),
{domain_Shop,
ID,
CreatedAt,
Blocking,
Suspension,
Details,
Location,
Category,
Account,
ContractID,
PayoutToolID
}).
-define(legacy_shop_v2(
ID,
CreatedAt,
Blocking,
Suspension,
Details,
Location,
Category,
Account,
ContractID,
PayoutToolID
),
{domain_Shop, ID, CreatedAt, Blocking, Suspension, Details, Location, Category, Account, ContractID, PayoutToolID}
).
-define(legacy_shop_v3(
ID,
CreatedAt,
Blocking,
Suspension,
Details,
Location,
Category,
Account,
ContractID,
PayoutToolID,
PayoutScheduleRef
),
{domain_Shop,
ID,
CreatedAt,
Blocking,
Suspension,
Details,
Location,
Category,
Account,
ContractID,
PayoutToolID,
PayoutScheduleRef
}).
ID,
CreatedAt,
Blocking,
Suspension,
Details,
Location,
Category,
Account,
ContractID,
PayoutToolID,
PayoutScheduleRef
),
{domain_Shop, ID, CreatedAt, Blocking, Suspension, Details, Location, Category, Account, ContractID, PayoutToolID,
PayoutScheduleRef}
).
-define(legacy_payout_schedule_ref(ID),
{domain_PayoutScheduleRef, ID}).
{domain_PayoutScheduleRef, ID}
).
-define(legacy_schedule_changed(PayoutScheduleRef),
{payproc_ScheduleChanged, PayoutScheduleRef}).
{payproc_ScheduleChanged, PayoutScheduleRef}
).
-define(legacy_contract_effect(ID, Effect),
{contract_effect, {payproc_ContractEffectUnit, ID, Effect}}).
{contract_effect, {payproc_ContractEffectUnit, ID, Effect}}
).
-define(legacy_contract_v1(
ID,
Contractor,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement
),
{domain_Contract,
ID,
Contractor,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement
}
ID,
Contractor,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement
),
{domain_Contract, ID, Contractor, CreatedAt, ValidSince, ValidUntil, Status, Terms, Adjustments, PayoutTools,
LegalAgreement}
).
-define(legacy_contract_v2_3(
ID,
Contractor,
PaymentInstitutionRef,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement
),
{domain_Contract,
ID,
Contractor,
PaymentInstitutionRef,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement
}
ID,
Contractor,
PaymentInstitutionRef,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement
),
{domain_Contract, ID, Contractor, PaymentInstitutionRef, CreatedAt, ValidSince, ValidUntil, Status, Terms,
Adjustments, PayoutTools, LegalAgreement}
).
-define(legacy_contract_v4(
ID,
Contractor,
PaymentInstitutionRef,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement,
ReportPreferences
),
{domain_Contract,
ID,
Contractor,
PaymentInstitutionRef,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement,
ReportPreferences
}
ID,
Contractor,
PaymentInstitutionRef,
CreatedAt,
ValidSince,
ValidUntil,
Status,
Terms,
Adjustments,
PayoutTools,
LegalAgreement,
ReportPreferences
),
{domain_Contract, ID, Contractor, PaymentInstitutionRef, CreatedAt, ValidSince, ValidUntil, Status, Terms,
Adjustments, PayoutTools, LegalAgreement, ReportPreferences}
).
-define(legacy_payout_tool(
ID,
CreatedAt,
Currency,
PayoutToolInfo
),
{domain_PayoutTool,
ID,
CreatedAt,
Currency,
PayoutToolInfo
}).
ID,
CreatedAt,
Currency,
PayoutToolInfo
),
{domain_PayoutTool, ID, CreatedAt, Currency, PayoutToolInfo}
).
-define(legacy_legal_agreement(
SignedAt,
LegalAgreementID
),
{domain_LegalAgreement,
SignedAt,
LegalAgreementID
}).
SignedAt,
LegalAgreementID
),
{domain_LegalAgreement, SignedAt, LegalAgreementID}
).
-endif.

View File

@ -10,7 +10,8 @@
id = PartyID,
contact_info = ContactInfo,
created_at = Timestamp
}}).
}}
).
-define(party_blocking(Blocking), {party_blocking, Blocking}).
-define(party_suspension(Suspension), {party_suspension, Suspension}).
@ -19,19 +20,26 @@
{party_meta_set, #payproc_PartyMetaSet{
ns = NS,
data = Data
}}).
}}
).
-define(party_meta_removed(NS), {party_meta_removed, NS}).
-define(shop_blocking(ID, Blocking),
{shop_blocking, #payproc_ShopBlocking{shop_id = ID, blocking = Blocking}}).
{shop_blocking, #payproc_ShopBlocking{shop_id = ID, blocking = Blocking}}
).
-define(shop_suspension(ID, Suspension),
{shop_suspension, #payproc_ShopSuspension{shop_id = ID, suspension = Suspension}}).
{shop_suspension, #payproc_ShopSuspension{shop_id = ID, suspension = Suspension}}
).
-define(wallet_blocking(ID, Blocking),
{wallet_blocking, #payproc_WalletBlocking{wallet_id = ID, blocking = Blocking}}).
{wallet_blocking, #payproc_WalletBlocking{wallet_id = ID, blocking = Blocking}}
).
-define(wallet_suspension(ID, Suspension),
{wallet_suspension, #payproc_WalletSuspension{wallet_id = ID, suspension = Suspension}}).
{wallet_suspension, #payproc_WalletSuspension{wallet_id = ID, suspension = Suspension}}
).
-define(blocked(Reason, Since), {blocked, #domain_Blocked{reason = Reason, since = Since}}).
-define(unblocked(Reason, Since), {unblocked, #domain_Unblocked{reason = Reason, since = Since}}).
@ -41,111 +49,153 @@
-define(suspended(Since), {suspended, #domain_Suspended{since = Since}}).
-define(contractor_modification(ID, Modification),
{contractor_modification, #payproc_ContractorModificationUnit{id = ID, modification = Modification}}).
{contractor_modification, #payproc_ContractorModificationUnit{id = ID, modification = Modification}}
).
-define(identity_documents_modification(Docs),
{identity_documents_modification, #payproc_ContractorIdentityDocumentsModification{
identity_documents = Docs
}}).
}}
).
-define(contractor_effect(ID, Effect),
{contractor_effect, #payproc_ContractorEffectUnit{id = ID, effect = Effect}}).
{contractor_effect, #payproc_ContractorEffectUnit{id = ID, effect = Effect}}
).
-define(contract_modification(ID, Modification),
{contract_modification, #payproc_ContractModificationUnit{id = ID, modification = Modification}}).
{contract_modification, #payproc_ContractModificationUnit{id = ID, modification = Modification}}
).
-define(contract_termination(Reason),
{termination, #payproc_ContractTermination{reason = Reason}}).
{termination, #payproc_ContractTermination{reason = Reason}}
).
-define(adjustment_creation(ID, Params),
{adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
adjustment_id = ID,
modification = {creation, Params}
}}).
}}
).
-define(payout_tool_creation(ID, Params),
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
payout_tool_id = ID,
modification = {creation, Params}
}}).
}}
).
-define(payout_tool_info_modification(ID, Info),
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
payout_tool_id = ID,
modification = {info_modification, Info}
}}).
}}
).
-define(shop_modification(ID, Modification),
{shop_modification, #payproc_ShopModificationUnit{id = ID, modification = Modification}}).
{shop_modification, #payproc_ShopModificationUnit{id = ID, modification = Modification}}
).
-define(shop_contract_modification(ContractID, PayoutToolID),
{contract_modification, #payproc_ShopContractModification{contract_id = ContractID, payout_tool_id = PayoutToolID}}).
{contract_modification, #payproc_ShopContractModification{contract_id = ContractID, payout_tool_id = PayoutToolID}}
).
-define(
shop_account_creation_params(CurrencyRef),
-define(shop_account_creation_params(CurrencyRef),
{shop_account_creation, #payproc_ShopAccountParams{
currency = CurrencyRef
}}
).
-define(proxy_modification(Proxy),
{proxy_modification, #payproc_ProxyModification{proxy = Proxy}}).
{proxy_modification, #payproc_ProxyModification{proxy = Proxy}}
).
-define(payout_schedule_modification(BusinessScheduleRef),
{payout_schedule_modification, #payproc_ScheduleModification{schedule = BusinessScheduleRef}}).
{payout_schedule_modification, #payproc_ScheduleModification{schedule = BusinessScheduleRef}}
).
-define(contract_effect(ID, Effect),
{contract_effect, #payproc_ContractEffectUnit{contract_id = ID, effect = Effect}}).
{contract_effect, #payproc_ContractEffectUnit{contract_id = ID, effect = Effect}}
).
-define(shop_effect(ID, Effect),
{shop_effect, #payproc_ShopEffectUnit{shop_id = ID, effect = Effect}}).
{shop_effect, #payproc_ShopEffectUnit{shop_id = ID, effect = Effect}}
).
-define(payout_schedule_changed(BusinessScheduleRef),
{payout_schedule_changed, #payproc_ScheduleChanged{schedule = BusinessScheduleRef}}).
{payout_schedule_changed, #payproc_ScheduleChanged{schedule = BusinessScheduleRef}}
).
-define(wallet_modification(ID, Modification),
{wallet_modification, #payproc_WalletModificationUnit{id = ID, modification = Modification}}).
{wallet_modification, #payproc_WalletModificationUnit{id = ID, modification = Modification}}
).
-define(wallet_effect(ID, Effect),
{wallet_effect, #payproc_WalletEffectUnit{id = ID, effect = Effect}}).
{wallet_effect, #payproc_WalletEffectUnit{id = ID, effect = Effect}}
).
-define(claim_created(Claim),
{claim_created, Claim}).
{claim_created, Claim}
).
-define(claim_updated(ID, Changeset, ClaimRevision, Timestamp),
{claim_updated, #payproc_ClaimUpdated{id = ID, changeset = Changeset, revision = ClaimRevision, updated_at = Timestamp}}).
{claim_updated, #payproc_ClaimUpdated{
id = ID,
changeset = Changeset,
revision = ClaimRevision,
updated_at = Timestamp
}}
).
-define(claim_status_changed(ID, Status, ClaimRevision, Timestamp),
{claim_status_changed, #payproc_ClaimStatusChanged{id = ID, status = Status, revision = ClaimRevision, changed_at = Timestamp}}).
{claim_status_changed, #payproc_ClaimStatusChanged{
id = ID,
status = Status,
revision = ClaimRevision,
changed_at = Timestamp
}}
).
-define(pending(),
{pending, #payproc_ClaimPending{}}).
{pending, #payproc_ClaimPending{}}
).
-define(accepted(Effects),
{accepted, #payproc_ClaimAccepted{effects = Effects}}).
{accepted, #payproc_ClaimAccepted{effects = Effects}}
).
-define(denied(Reason),
{denied, #payproc_ClaimDenied{reason = Reason}}).
{denied, #payproc_ClaimDenied{reason = Reason}}
).
-define(revoked(Reason),
{revoked, #payproc_ClaimRevoked{reason = Reason}}).
{revoked, #payproc_ClaimRevoked{reason = Reason}}
).
-define(account_created(ShopAccount),
{account_created, #payproc_ShopAccountCreated{account = ShopAccount}}).
{account_created, #payproc_ShopAccountCreated{account = ShopAccount}}
).
-define(revision_changed(Timestamp, Revision),
{revision_changed, #payproc_PartyRevisionChanged{
timestamp = Timestamp,
revision = Revision
}}).
}}
).
-define(invalid_shop(ID, Reason),
{invalid_shop, #payproc_InvalidShop{id = ID, reason = Reason}}).
{invalid_shop, #payproc_InvalidShop{id = ID, reason = Reason}}
).
-define(invalid_contract(ID, Reason),
{invalid_contract, #payproc_InvalidContract{id = ID, reason = Reason}}).
{invalid_contract, #payproc_InvalidContract{id = ID, reason = Reason}}
).
-define(invalid_contractor(ID, Reason),
{invalid_contractor, #payproc_InvalidContractor{id = ID, reason = Reason}}).
{invalid_contractor, #payproc_InvalidContractor{id = ID, reason = Reason}}
).
-define(invalid_wallet(ID, Reason),
{invalid_wallet, #payproc_InvalidWallet{id = ID, reason = Reason}}).
{invalid_wallet, #payproc_InvalidWallet{id = ID, reason = Reason}}
).
-endif.

View File

@ -2,6 +2,7 @@
%%% @end
-module(party_management).
-behaviour(supervisor).
-behaviour(application).
@ -16,39 +17,36 @@
-export([start/2]).
-export([stop/1]).
-define(DEFAULT_HANDLING_TIMEOUT, 30000). % 30 seconds
% 30 seconds
-define(DEFAULT_HANDLING_TIMEOUT, 30000).
%%
%% API
%%
-spec start() ->
{ok, _}.
-spec start() -> {ok, _}.
start() ->
application:ensure_all_started(?MODULE).
-spec stop() ->
ok.
-spec stop() -> ok.
stop() ->
application:stop(?MODULE).
%% Supervisor callbacks
-spec init([]) ->
{ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
init([]) ->
{ok, {
#{strategy => one_for_all, intensity => 6, period => 30}, []
}}.
{ok,
{
#{strategy => one_for_all, intensity => 6, period => 30},
[]
}}.
%% Application callbacks
-spec start(normal, any()) ->
{ok, pid()} | {error, any()}.
-spec start(normal, any()) -> {ok, pid()} | {error, any()}.
start(_StartType, _StartArgs) ->
supervisor:start_link(?MODULE, []).
-spec stop(any()) ->
ok.
-spec stop(any()) -> ok.
stop(_State) ->
ok.

View File

@ -4,14 +4,12 @@
-export([check_user/2]).
-spec check_user(woody_user_identity:user_identity(), dmsl_domain_thrift:'PartyID'())->
ok | invalid_user.
-spec check_user(woody_user_identity:user_identity(), dmsl_domain_thrift:'PartyID'()) -> ok | invalid_user.
check_user(#{id := PartyID, realm := <<"external">>}, PartyID) ->
ok;
check_user(#{id := _AnyID, realm := <<"internal">>}, _PartyID) ->
ok;
%% @TODO must be deleted when we get rid of #payproc_ServiceUser
%% @TODO must be deleted when we get rid of #payproc_ServiceUser
check_user(#{id := _AnyID, realm := <<"service">>}, _PartyID) ->
ok;
check_user(_, _) ->

View File

@ -14,13 +14,13 @@
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-include_lib("shumpune_proto/include/shumpune_shumpune_thrift.hrl").
-type amount() :: dmsl_domain_thrift:'Amount'().
-type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
-type account_id() :: dmsl_accounter_thrift:'AccountID'().
-type batch_id() :: dmsl_accounter_thrift:'BatchID'().
-type amount() :: dmsl_domain_thrift:'Amount'().
-type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
-type account_id() :: dmsl_accounter_thrift:'AccountID'().
-type batch_id() :: dmsl_accounter_thrift:'BatchID'().
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
-type batch() :: {batch_id(), final_cash_flow()}.
-type clock() :: shumpune_shumpune_thrift:'Clock'().
-type batch() :: {batch_id(), final_cash_flow()}.
-type clock() :: shumpune_shumpune_thrift:'Clock'().
-export_type([batch/0]).
@ -36,9 +36,7 @@
max_available_amount => amount()
}.
-spec get_account(account_id()) ->
account().
-spec get_account(account_id()) -> account().
get_account(AccountID) ->
case call_accounter('GetAccountByID', {AccountID}) of
{ok, Result} ->
@ -47,15 +45,11 @@ get_account(AccountID) ->
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
end.
-spec get_balance(account_id()) ->
balance().
-spec get_balance(account_id()) -> balance().
get_balance(AccountID) ->
get_balance(AccountID, {latest, #shumpune_LatestClock{}}).
-spec get_balance(account_id(), clock()) ->
balance().
-spec get_balance(account_id(), clock()) -> balance().
get_balance(AccountID, Clock) ->
case call_accounter('GetBalanceByID', {AccountID, Clock}) of
{ok, Result} ->
@ -64,21 +58,18 @@ get_balance(AccountID, Clock) ->
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
end.
-spec create_account(currency_code()) ->
account_id().
-spec create_account(currency_code()) -> account_id().
create_account(CurrencyCode) ->
create_account(CurrencyCode, undefined).
-spec create_account(currency_code(), binary() | undefined) ->
account_id().
-spec create_account(currency_code(), binary() | undefined) -> account_id().
create_account(CurrencyCode, Description) ->
case call_accounter('CreateAccount', {construct_prototype(CurrencyCode, Description)}) of
{ok, Result} ->
Result;
{exception, Exception} ->
error({accounting, Exception}) % FIXME
% FIXME
error({accounting, Exception})
end.
construct_prototype(CurrencyCode, Description) ->

View File

@ -1,20 +1,22 @@
-module(pm_cash_range).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include("domain.hrl").
-export([is_inside/2]).
-type cash_range() :: dmsl_domain_thrift:'CashRange'().
-type cash() :: dmsl_domain_thrift:'Cash'().
-spec is_inside(cash(), cash_range()) ->
within | {exceeds, lower | upper}.
-type cash() :: dmsl_domain_thrift:'Cash'().
-spec is_inside(cash(), cash_range()) -> within | {exceeds, lower | upper}.
is_inside(Cash, CashRange = #domain_CashRange{lower = Lower, upper = Upper}) ->
case {
compare_cash(fun erlang:'>'/2, Cash, Lower),
compare_cash(fun erlang:'<'/2, Cash, Upper)
} of
case
{
compare_cash(fun erlang:'>'/2, Cash, Lower),
compare_cash(fun erlang:'<'/2, Cash, Upper)
}
of
{true, true} ->
within;
{false, true} ->

View File

@ -7,13 +7,14 @@
%%% - we should probably validate final cash flow somewhere here
-module(pm_cashflow).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-type account() :: dmsl_domain_thrift:'CashFlowAccount'().
-type account_id() :: dmsl_domain_thrift:'AccountID'().
-type account_map() :: #{account() => account_id()}.
-type context() :: dmsl_domain_thrift:'CashFlowContext'().
-type cash_flow() :: dmsl_domain_thrift:'CashFlow'().
-type account() :: dmsl_domain_thrift:'CashFlowAccount'().
-type account_id() :: dmsl_domain_thrift:'AccountID'().
-type account_map() :: #{account() => account_id()}.
-type context() :: dmsl_domain_thrift:'CashFlowContext'().
-type cash_flow() :: dmsl_domain_thrift:'CashFlow'().
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
%%
@ -22,25 +23,21 @@
%%
-define(posting(Source, Destination, Volume, Details),
#domain_CashFlowPosting{
source = Source,
destination = Destination,
volume = Volume,
details = Details
}).
-define(posting(Source, Destination, Volume, Details), #domain_CashFlowPosting{
source = Source,
destination = Destination,
volume = Volume,
details = Details
}).
-define(final_posting(Source, Destination, Volume, Details),
#domain_FinalCashFlowPosting{
source = Source,
destination = Destination,
volume = Volume,
details = Details
}).
-spec finalize(cash_flow(), context(), account_map()) ->
final_cash_flow() | no_return().
-define(final_posting(Source, Destination, Volume, Details), #domain_FinalCashFlowPosting{
source = Source,
destination = Destination,
volume = Volume,
details = Details
}).
-spec finalize(cash_flow(), context(), account_map()) -> final_cash_flow() | no_return().
finalize(CF, Context, AccountMap) ->
compute_postings(CF, Context, AccountMap).
@ -51,14 +48,14 @@ compute_postings(CF, Context, AccountMap) ->
construct_final_account(Destination, AccountMap),
compute_volume(Volume, Context),
Details
) ||
?posting(Source, Destination, Volume, Details) <- CF
)
|| ?posting(Source, Destination, Volume, Details) <- CF
].
construct_final_account(AccountType, AccountMap) ->
#domain_FinalCashFlowAccount{
account_type = AccountType,
account_id = resolve_account(AccountType, AccountMap)
account_id = resolve_account(AccountType, AccountMap)
}.
resolve_account(AccountType, AccountMap) ->
@ -72,13 +69,18 @@ resolve_account(AccountType, AccountMap) ->
%%
-define(fixed(Cash),
{fixed, #domain_CashVolumeFixed{cash = Cash}}).
{fixed, #domain_CashVolumeFixed{cash = Cash}}
).
-define(share(P, Q, Of, RoundingMethod),
{share, #domain_CashVolumeShare{'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod}}).
{share, #domain_CashVolumeShare{'parts' = ?rational(P, Q), 'of' = Of, 'rounding_method' = RoundingMethod}}
).
-define(product(Fun, CVs),
{product, {Fun, CVs}}).
-define(rational(P, Q),
#'Rational'{p = P, q = Q}).
{product, {Fun, CVs}}
).
-define(rational(P, Q), #'Rational'{p = P, q = Q}).
compute_volume(?fixed(Cash), _Context) ->
Cash;
@ -93,17 +95,19 @@ compute_volume(?product(Fun, CVs) = CV0, Context) ->
end.
compute_parts_of(P, Q, Cash = #domain_Cash{amount = Amount}, RoundingMethod) ->
Cash#domain_Cash{amount = genlib_rational:round(
genlib_rational:mul(
genlib_rational:new(Amount),
genlib_rational:new(P, Q)
),
get_rounding_method(RoundingMethod)
)}.
Cash#domain_Cash{
amount = genlib_rational:round(
genlib_rational:mul(
genlib_rational:new(Amount),
genlib_rational:new(P, Q)
),
get_rounding_method(RoundingMethod)
)
}.
compute_product(Fun, [CV | CVRest], CV0, Context) ->
lists:foldl(
fun (CVN, CVMin) -> compute_product(Fun, CVN, CVMin, CV0, Context) end,
fun(CVN, CVMin) -> compute_product(Fun, CVN, CVMin, CV0, Context) end,
compute_volume(CV, Context),
CVRest
).

View File

@ -1,6 +1,7 @@
-module(pm_claim).
-include("party_events.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
@ -29,55 +30,45 @@
%% Types
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
-type claim_status() :: dmsl_payment_processing_thrift:'ClaimStatus'().
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
-type claim_status() :: dmsl_payment_processing_thrift:'ClaimStatus'().
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
-type party() :: pm_party:party().
-type party() :: pm_party:party().
-type timestamp() :: pm_datetime:timestamp().
-type revision() :: pm_domain:revision().
-type timestamp() :: pm_datetime:timestamp().
-type revision() :: pm_domain:revision().
%% Interface
-spec get_id(claim()) ->
claim_id().
-spec get_id(claim()) -> claim_id().
get_id(#payproc_Claim{id = ID}) ->
ID.
-spec get_revision(claim()) ->
claim_revision().
-spec get_revision(claim()) -> claim_revision().
get_revision(#payproc_Claim{revision = Revision}) ->
Revision.
-spec create(claim_id(), changeset(), party(), timestamp(), revision()) ->
claim() | no_return().
-spec create(claim_id(), changeset(), party(), timestamp(), revision()) -> claim() | no_return().
create(ID, Changeset, Party, Timestamp, Revision) ->
ok = assert_changeset_applicable(Changeset, Timestamp, Revision, Party),
#payproc_Claim{
id = ID,
status = ?pending(),
id = ID,
status = ?pending(),
changeset = Changeset,
revision = 1,
created_at = Timestamp
}.
-spec update(changeset(), claim(), party(), timestamp(), revision()) ->
claim() | no_return().
-spec update(changeset(), claim(), party(), timestamp(), revision()) -> claim() | no_return().
update(NewChangeset, #payproc_Claim{changeset = OldChangeset} = Claim, Party, Timestamp, Revision) ->
TmpChangeset = merge_changesets(OldChangeset, NewChangeset),
ok = assert_changeset_applicable(TmpChangeset, Timestamp, Revision, Party),
update_changeset(NewChangeset, get_next_revision(Claim), Timestamp, Claim).
-spec update_changeset(changeset(), claim_revision(), timestamp(), claim()) ->
claim().
-spec update_changeset(changeset(), claim_revision(), timestamp(), claim()) -> claim().
update_changeset(NewChangeset, NewRevision, Timestamp, #payproc_Claim{changeset = OldChangeset} = Claim) ->
Claim#payproc_Claim{
revision = NewRevision,
@ -85,29 +76,21 @@ update_changeset(NewChangeset, NewRevision, Timestamp, #payproc_Claim{changeset
changeset = merge_changesets(OldChangeset, NewChangeset)
}.
-spec accept(timestamp(), revision(), party(), claim()) ->
claim() | no_return().
-spec accept(timestamp(), revision(), party(), claim()) -> claim() | no_return().
accept(Timestamp, DomainRevision, Party, Claim) ->
ok = assert_acceptable(Claim, Timestamp, DomainRevision, Party),
Effects = make_effects(Timestamp, DomainRevision, Claim),
set_status(?accepted(Effects), get_next_revision(Claim), Timestamp, Claim).
-spec deny(binary(), timestamp(), claim()) ->
claim().
-spec deny(binary(), timestamp(), claim()) -> claim().
deny(Reason, Timestamp, Claim) ->
set_status(?denied(Reason), get_next_revision(Claim), Timestamp, Claim).
-spec revoke(binary(), timestamp(), claim()) ->
claim().
-spec revoke(binary(), timestamp(), claim()) -> claim().
revoke(Reason, Timestamp, Claim) ->
set_status(?revoked(Reason), get_next_revision(Claim), Timestamp, Claim).
-spec set_status(claim_status(), claim_revision(), timestamp(), claim()) ->
claim().
-spec set_status(claim_status(), claim_revision(), timestamp(), claim()) -> claim().
set_status(Status, NewRevision, Timestamp, Claim) ->
Claim#payproc_Claim{
revision = NewRevision,
@ -115,43 +98,31 @@ set_status(Status, NewRevision, Timestamp, Claim) ->
status = Status
}.
-spec get_status(claim()) ->
claim_status().
-spec get_status(claim()) -> claim_status().
get_status(#payproc_Claim{status = Status}) ->
Status.
-spec is_pending(claim()) ->
boolean().
-spec is_pending(claim()) -> boolean().
is_pending(#payproc_Claim{status = ?pending()}) ->
true;
is_pending(_) ->
false.
-spec is_accepted(claim()) ->
boolean().
-spec is_accepted(claim()) -> boolean().
is_accepted(#payproc_Claim{status = ?accepted(_)}) ->
true;
is_accepted(_) ->
false.
-spec is_need_acceptance(claim(), party(), revision()) ->
boolean().
-spec is_need_acceptance(claim(), party(), revision()) -> boolean().
is_need_acceptance(Claim, Party, Revision) ->
is_changeset_need_acceptance(get_changeset(Claim), Party, Revision).
-spec is_conflicting(claim(), claim(), timestamp(), revision(), party()) ->
boolean().
-spec is_conflicting(claim(), claim(), timestamp(), revision(), party()) -> boolean().
is_conflicting(Claim1, Claim2, Timestamp, Revision, Party) ->
has_changeset_conflict(get_changeset(Claim1), get_changeset(Claim2), Timestamp, Revision, Party).
-spec apply(claim(), timestamp(), party()) ->
party().
-spec apply(claim(), timestamp(), party()) -> party().
apply(#payproc_Claim{status = ?accepted(Effects)}, Timestamp, Party) ->
apply_effects(Effects, Timestamp, Party).
@ -243,20 +214,24 @@ make_effects(Timestamp, Revision, Claim) ->
make_changeset_effects(get_changeset(Claim), Timestamp, Revision).
make_changeset_effects(Changeset, Timestamp, Revision) ->
squash_effects(lists:map(
fun(Change) ->
pm_claim_effect:make(Change, Timestamp, Revision)
end,
Changeset
)).
squash_effects(
lists:map(
fun(Change) ->
pm_claim_effect:make(Change, Timestamp, Revision)
end,
Changeset
)
).
make_changeset_safe_effects(Changeset, Timestamp, Revision) ->
squash_effects(lists:map(
fun(Change) ->
pm_claim_effect:make_safe(Change, Timestamp, Revision)
end,
Changeset
)).
squash_effects(
lists:map(
fun(Change) ->
pm_claim_effect:make_safe(Change, Timestamp, Revision)
end,
Changeset
)
).
squash_effects(Effects) ->
squash_effects(Effects, []).
@ -421,37 +396,29 @@ apply_wallet_effect(ID, Effect, Party) ->
update_wallet({account_created, Account}, Wallet) ->
Wallet#domain_Wallet{account = Account}.
-spec raise_invalid_changeset(dmsl_payment_processing_thrift:'InvalidChangesetReason'()) ->
no_return().
-spec raise_invalid_changeset(dmsl_payment_processing_thrift:'InvalidChangesetReason'()) -> no_return().
raise_invalid_changeset(Reason) ->
throw(#payproc_InvalidChangeset{reason = Reason}).
%% Asserts
-spec assert_revision(claim(), claim_revision()) -> ok | no_return().
-spec assert_revision(claim(), claim_revision()) -> ok | no_return().
assert_revision(#payproc_Claim{revision = Revision}, Revision) ->
ok;
assert_revision(_, _) ->
throw(#payproc_InvalidClaimRevision{}).
-spec assert_pending(claim()) -> ok | no_return().
-spec assert_pending(claim()) -> ok | no_return().
assert_pending(#payproc_Claim{status = ?pending()}) ->
ok;
assert_pending(#payproc_Claim{status = Status}) ->
throw(#payproc_InvalidClaimStatus{status = Status}).
-spec assert_applicable(claim(), timestamp(), revision(), party()) ->
ok | no_return().
-spec assert_applicable(claim(), timestamp(), revision(), party()) -> ok | no_return().
assert_applicable(Claim, Timestamp, Revision, Party) ->
assert_changeset_applicable(get_changeset(Claim), Timestamp, Revision, Party).
-spec assert_changeset_applicable(changeset(), timestamp(), revision(), party()) ->
ok | no_return().
-spec assert_changeset_applicable(changeset(), timestamp(), revision(), party()) -> ok | no_return().
assert_changeset_applicable([Change | Others], Timestamp, Revision, Party) ->
case Change of
?contract_modification(ID, Modification) ->
@ -585,9 +552,7 @@ get_payment_institution_realm(Ref, Revision, ContractID) ->
raise_invalid_payment_institution(ContractID, Ref)
end.
-spec assert_acceptable(claim(), timestamp(), revision(), party()) ->
ok | no_return().
-spec assert_acceptable(claim(), timestamp(), revision(), party()) -> ok | no_return().
assert_acceptable(Claim, Timestamp, Revision, Party0) ->
Changeset = get_changeset(Claim),
Effects = make_changeset_safe_effects(Changeset, Timestamp, Revision),
@ -597,16 +562,16 @@ assert_acceptable(Claim, Timestamp, Revision, Party0) ->
-spec raise_invalid_payment_institution(
dmsl_domain_thrift:'ContractID'(),
dmsl_domain_thrift:'PaymentInstitutionRef'() | undefined
) ->
no_return().
) -> no_return().
raise_invalid_payment_institution(ContractID, Ref) ->
raise_invalid_changeset(?invalid_contract(
ContractID,
{invalid_object_reference, #payproc_InvalidObjectReference{
ref = make_optional_domain_ref(payment_institution, Ref)
}}
)).
raise_invalid_changeset(
?invalid_contract(
ContractID,
{invalid_object_reference, #payproc_InvalidObjectReference{
ref = make_optional_domain_ref(payment_institution, Ref)
}}
)
).
make_optional_domain_ref(_, undefined) ->
undefined;

View File

@ -1,29 +1,30 @@
-module(pm_claim_committer).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
-include("claim_management.hrl").
-include("party_events.hrl").
-export([from_claim_mgmt/1]).
-spec from_claim_mgmt(dmsl_claim_management_thrift:'Claim'()) ->
dmsl_payment_processing_thrift:'Claim'() | undefined.
-spec from_claim_mgmt(dmsl_claim_management_thrift:'Claim'()) -> dmsl_payment_processing_thrift:'Claim'() | undefined.
from_claim_mgmt(#claim_management_Claim{
id = ID,
changeset = Changeset,
revision = Revision,
id = ID,
changeset = Changeset,
revision = Revision,
created_at = CreatedAt,
updated_at = UpdatedAt
}) ->
case from_cm_changeset(Changeset) of
[] -> undefined;
[] ->
undefined;
Converted ->
#payproc_Claim{
id = ID,
status = ?pending(),
changeset = Converted,
revision = Revision,
id = ID,
status = ?pending(),
changeset = Converted,
revision = Revision,
created_at = CreatedAt,
updated_at = UpdatedAt
}
@ -33,18 +34,23 @@ from_claim_mgmt(#claim_management_Claim{
from_cm_changeset(Changeset) ->
lists:filtermap(
fun (#claim_management_ModificationUnit{
modification = {party_modification, PartyMod}
}) ->
case PartyMod of
?cm_cash_register_modification_unit_modification(_, _) ->
false;
PartyMod ->
{true, from_cm_party_mod(PartyMod)}
end;
(#claim_management_ModificationUnit{
modification = {claim_modification, _}
}) ->
fun
(
#claim_management_ModificationUnit{
modification = {party_modification, PartyMod}
}
) ->
case PartyMod of
?cm_cash_register_modification_unit_modification(_, _) ->
false;
PartyMod ->
{true, from_cm_party_mod(PartyMod)}
end;
(
#claim_management_ModificationUnit{
modification = {claim_modification, _}
}
) ->
false
end,
Changeset
@ -65,32 +71,31 @@ from_cm_party_mod(?cm_shop_modification(ShopID, ShopModification)) ->
from_cm_contract_modification(
{creation, #claim_management_ContractParams{
contractor_id = ContractorID,
template = ContractTemplateRef,
contractor_id = ContractorID,
template = ContractTemplateRef,
payment_institution = PaymentInstitutionRef
}}
) ->
{creation, #payproc_ContractParams{
contractor_id = ContractorID,
template = ContractTemplateRef,
contractor_id = ContractorID,
template = ContractTemplateRef,
payment_institution = PaymentInstitutionRef
}};
from_cm_contract_modification(?cm_contract_termination(Reason)) ->
?contract_termination(Reason);
from_cm_contract_modification(?cm_adjustment_creation(ContractAdjustmentID, ContractTemplateRef)
) ->
from_cm_contract_modification(?cm_adjustment_creation(ContractAdjustmentID, ContractTemplateRef)) ->
?adjustment_creation(
ContractAdjustmentID,
#payproc_ContractAdjustmentParams{template = ContractTemplateRef}
);
from_cm_contract_modification(
?cm_payout_tool_creation(PayoutToolID, #claim_management_PayoutToolParams{
currency = CurrencyRef,
currency = CurrencyRef,
tool_info = PayoutToolInfo
})
) ->
?payout_tool_creation(PayoutToolID, #payproc_PayoutToolParams{
currency = CurrencyRef,
currency = CurrencyRef,
tool_info = PayoutToolInfo
});
from_cm_contract_modification(
@ -106,17 +111,17 @@ from_cm_contract_modification({contractor_modification, _ContractorID} = Contrac
from_cm_shop_modification({creation, ShopParams}) ->
#claim_management_ShopParams{
category = CategoryRef,
location = ShopLocation,
details = ShopDetails,
contract_id = ContractID,
category = CategoryRef,
location = ShopLocation,
details = ShopDetails,
contract_id = ContractID,
payout_tool_id = PayoutToolID
} = ShopParams,
{creation, #payproc_ShopParams{
category = CategoryRef,
location = ShopLocation,
details = ShopDetails,
contract_id = ContractID,
category = CategoryRef,
location = ShopLocation,
details = ShopDetails,
contract_id = ContractID,
payout_tool_id = PayoutToolID
}};
from_cm_shop_modification({category_modification, _CategoryRef} = CategoryModification) ->

View File

@ -1,4 +1,5 @@
-module(pm_claim_committer_handler).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
@ -6,17 +7,14 @@
-export([handle_function/3]).
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
term()| no_return().
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
handle_function(Func, Args, Opts) ->
scoper:scope(claimmgmt,
scoper:scope(
claimmgmt,
fun() -> handle_function_(Func, Args, Opts) end
).
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
term() | no_return().
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
handle_function_(Fun, {PartyID, _Claim} = Args, _Opts) when Fun == 'Accept'; Fun == 'Commit' ->
call(PartyID, Fun, Args).

View File

@ -1,6 +1,7 @@
-module(pm_claim_effect).
-include("party_events.hrl").
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-export([make/3]).
@ -10,16 +11,14 @@
%% Interface
-type change() :: dmsl_payment_processing_thrift:'PartyModification'().
-type effect() :: dmsl_payment_processing_thrift:'ClaimEffect'().
-type timestamp() :: pm_datetime:timestamp().
-type revision() :: pm_domain:revision().
-type change() :: dmsl_payment_processing_thrift:'PartyModification'().
-type effect() :: dmsl_payment_processing_thrift:'ClaimEffect'().
-type timestamp() :: pm_datetime:timestamp().
-type revision() :: pm_domain:revision().
-spec make(change(), timestamp(), revision()) -> effect() | no_return().
make(?contractor_modification(ID, Modification), Timestamp, Revision) ->
?contractor_effect(ID, make_contractor_effect(ID, Modification, Timestamp, Revision));
make(?contract_modification(ID, Modification), Timestamp, Revision) ->
try
?contract_effect(ID, make_contract_effect(ID, Modification, Timestamp, Revision))
@ -29,21 +28,19 @@ make(?contract_modification(ID, Modification), Timestamp, Revision) ->
throw:{template_invalid, Ref} ->
raise_invalid_object_ref({contract, ID}, make_optional_domain_ref(contract_template, Ref))
end;
make(?shop_modification(ID, Modification), Timestamp, Revision) ->
?shop_effect(ID, make_shop_effect(ID, Modification, Timestamp, Revision));
make(?wallet_modification(ID, Modification), Timestamp, _Revision) ->
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp)).
-spec make_safe(change(), timestamp(), revision()) -> effect() | no_return().
make_safe(
?shop_modification(ID, {shop_account_creation, #payproc_ShopAccountParams{currency = Currency}}),
_Timestamp,
_Revision
) ->
?shop_effect(ID,
?shop_effect(
ID,
{account_created, #domain_ShopAccount{
currency = Currency,
settlement = 0,
@ -145,15 +142,12 @@ assert_valid_object_ref(Prefix, Ref, Revision) ->
-spec raise_invalid_object_ref(
{shop, dmsl_domain_thrift:'ShopID'()} | {contract, dmsl_domain_thrift:'ContractID'()},
pm_domain:ref()
) ->
no_return().
) -> no_return().
raise_invalid_object_ref(Prefix, Ref) ->
Ex = {invalid_object_reference, #payproc_InvalidObjectReference{ref = Ref}},
raise_invalid_object_ref_(Prefix, Ex).
-spec raise_invalid_object_ref_(term(), term()) -> no_return().
raise_invalid_object_ref_({shop, ID}, Ex) ->
pm_claim:raise_invalid_changeset(?invalid_shop(ID, Ex));
raise_invalid_object_ref_({contract, ID}, Ex) ->

View File

@ -1,4 +1,5 @@
-module(pm_condition).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
%%
@ -8,11 +9,9 @@
%%
-type condition() :: dmsl_domain_thrift:'Condition'().
-type varset() :: pm_selector:varset().
-spec test(condition(), varset(), pm_domain:revision()) ->
true | false | undefined.
-type varset() :: pm_selector:varset().
-spec test(condition(), varset(), pm_domain:revision()) -> true | false | undefined.
test({category_is, V1}, #{category := V2}, _) ->
V1 =:= V2;
test({currency_is, V1}, #{currency := V2}, _) ->
@ -77,14 +76,19 @@ test_p2p_tool(P2PCondition, P2PTool, Rev) ->
sender = Sender,
receiver = Receiver
} = P2PTool,
case {
test({payment_tool, SenderIs}, #{payment_tool => Sender}, Rev),
test({payment_tool, ReceiverIs}, #{payment_tool => Receiver}, Rev)
} of
{true, true} -> true;
{T1, T2} when T1 =:= undefined
orelse T2 =:= undefined -> undefined;
{_, _} -> false
case
{
test({payment_tool, SenderIs}, #{payment_tool => Sender}, Rev),
test({payment_tool, ReceiverIs}, #{payment_tool => Receiver}, Rev)
}
of
{true, true} ->
true;
{T1, T2} when
T1 =:= undefined orelse
T2 =:= undefined
->
undefined;
{_, _} ->
false
end.

View File

@ -13,6 +13,7 @@
woody_context := woody_context(),
user_identity => user_identity()
}.
-type options() :: #{
user_identity => user_identity(),
woody_context => woody_context()
@ -41,11 +42,13 @@ create(Options0) ->
-spec save(context()) -> ok.
save(Context) ->
true = try gproc:reg(?REGISTRY_KEY, Context)
catch
error:badarg ->
gproc:set_value(?REGISTRY_KEY, Context)
end,
true =
try
gproc:reg(?REGISTRY_KEY, Context)
catch
error:badarg ->
gproc:set_value(?REGISTRY_KEY, Context)
end,
ok.
-spec load() -> context() | no_return().

View File

@ -18,31 +18,30 @@
%%
-type contract() :: dmsl_domain_thrift:'Contract'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contract_params() :: dmsl_payment_processing_thrift:'ContractParams'().
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
-type adjustment() :: dmsl_domain_thrift:'ContractAdjustment'().
-type adjustment_id() :: dmsl_domain_thrift:'ContractAdjustmentID'().
-type adjustment_params() :: dmsl_payment_processing_thrift:'ContractAdjustmentParams'().
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
-type category() :: dmsl_domain_thrift:'CategoryRef'().
-type contract() :: dmsl_domain_thrift:'Contract'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contract_params() :: dmsl_payment_processing_thrift:'ContractParams'().
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
-type adjustment() :: dmsl_domain_thrift:'ContractAdjustment'().
-type adjustment_id() :: dmsl_domain_thrift:'ContractAdjustmentID'().
-type adjustment_params() :: dmsl_payment_processing_thrift:'ContractAdjustmentParams'().
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
-type category() :: dmsl_domain_thrift:'CategoryRef'().
-type contract_template_ref() :: dmsl_domain_thrift:'ContractTemplateRef'().
-type payment_inst_ref() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
-type payment_inst_ref() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
-type timestamp() :: pm_datetime:timestamp().
-type revision() :: pm_domain:revision().
-type timestamp() :: pm_datetime:timestamp().
-type revision() :: pm_domain:revision().
%%
-spec create(contract_id(), contract_params(), timestamp(), revision()) ->
contract().
-spec create(contract_id(), contract_params(), timestamp(), revision()) -> contract().
create(ID, Params, Timestamp, Revision) ->
#payproc_ContractParams{
contractor_id = ContractorID,
contractor = Contractor, %% Legacy
%% Legacy
contractor = Contractor,
template = TemplateRef,
payment_institution = PaymentInstitutionRef
} = ensure_contract_creation_params(Params, Revision),
@ -65,9 +64,7 @@ create(ID, Params, Timestamp, Revision) ->
payout_tools = []
}.
-spec update_status(contract(), timestamp()) ->
contract().
-spec update_status(contract(), timestamp()) -> contract().
update_status(
#domain_Contract{
valid_since = ValidSince,
@ -88,9 +85,7 @@ update_status(Contract, _) ->
Contract.
%% TODO should be in separate module
-spec create_adjustment(adjustment_id(), adjustment_params(), timestamp(), revision()) ->
adjustment().
-spec create_adjustment(adjustment_id(), adjustment_params(), timestamp(), revision()) -> adjustment().
create_adjustment(ID, Params, Timestamp, Revision) ->
#payproc_ContractAdjustmentParams{
template = TemplateRef
@ -110,7 +105,6 @@ create_adjustment(ID, Params, Timestamp, Revision) ->
-spec get_categories(contract() | contract_template(), timestamp(), revision()) ->
ordsets:ordset(category()) | no_return().
get_categories(Contract, Timestamp, Revision) ->
#domain_TermSet{
payments = #domain_PaymentsServiceTerms{
@ -125,9 +119,7 @@ get_categories(Contract, Timestamp, Revision) ->
error({misconfiguration, {'Empty set in category selector\'s value', CategorySelector, Revision}})
end.
-spec get_adjustment(adjustment_id(), contract()) ->
adjustment() | undefined.
-spec get_adjustment(adjustment_id(), contract()) -> adjustment() | undefined.
get_adjustment(AdjustmentID, #domain_Contract{adjustments = Adjustments}) ->
case lists:keysearch(AdjustmentID, #domain_ContractAdjustment.id, Adjustments) of
{value, Adjustment} ->
@ -136,9 +128,7 @@ get_adjustment(AdjustmentID, #domain_Contract{adjustments = Adjustments}) ->
undefined
end.
-spec get_payout_tool(payout_tool_id(), contract()) ->
payout_tool() | undefined.
-spec get_payout_tool(payout_tool_id(), contract()) -> payout_tool() | undefined.
get_payout_tool(PayoutToolID, #domain_Contract{payout_tools = PayoutTools}) ->
case lists:keysearch(PayoutToolID, #domain_PayoutTool.id, PayoutTools) of
{value, PayoutTool} ->
@ -147,25 +137,19 @@ get_payout_tool(PayoutToolID, #domain_Contract{payout_tools = PayoutTools}) ->
undefined
end.
-spec set_payout_tool(payout_tool(), contract()) ->
contract().
-spec set_payout_tool(payout_tool(), contract()) -> contract().
set_payout_tool(PayoutTool, Contract = #domain_Contract{payout_tools = PayoutTools}) ->
Contract#domain_Contract{
payout_tools = lists:keystore(PayoutTool#domain_PayoutTool.id, #domain_PayoutTool.id, PayoutTools, PayoutTool)
}.
-spec is_active(contract()) ->
boolean().
-spec is_active(contract()) -> boolean().
is_active(#domain_Contract{status = {active, _}}) ->
true;
is_active(_) ->
false.
-spec is_live(contract(), revision()) ->
boolean().
-spec is_live(contract(), revision()) -> boolean().
is_live(Contract, Revision) ->
PaymentInstitutionRef = Contract#domain_Contract.payment_institution,
PaymentInstitution = get_payment_institution(PaymentInstitutionRef, Revision),
@ -173,9 +157,7 @@ is_live(Contract, Revision) ->
%% Internals
-spec ensure_contract_creation_params(contract_params(), revision()) ->
contract_params() | no_return().
-spec ensure_contract_creation_params(contract_params(), revision()) -> contract_params() | no_return().
ensure_contract_creation_params(
#payproc_ContractParams{
template = TemplateRef,
@ -191,15 +173,12 @@ ensure_contract_creation_params(
-spec ensure_contract_template(contract_template_ref(), dmsl_domain_thrift:'PaymentInstitutionRef'(), revision()) ->
contract_template_ref() | no_return().
ensure_contract_template(#domain_ContractTemplateRef{} = TemplateRef, _, _) ->
TemplateRef;
ensure_contract_template(undefined, PaymentInstitutionRef, Revision) ->
get_default_template_ref(PaymentInstitutionRef, Revision).
-spec ensure_payment_institution(payment_inst_ref()) ->
payment_inst_ref() | no_return().
-spec ensure_payment_institution(payment_inst_ref()) -> payment_inst_ref() | no_return().
ensure_payment_institution(#domain_PaymentInstitutionRef{} = PaymentInstitutionRef) ->
PaymentInstitutionRef;
ensure_payment_institution(undefined) ->

View File

@ -2,12 +2,13 @@
%%%
-module(pm_currency).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-export([validate_currency/2]).
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
-type shop() :: dmsl_domain_thrift:'Shop'().
-type shop() :: dmsl_domain_thrift:'Shop'().
-spec validate_currency(currency(), shop()) -> ok.
validate_currency(Currency, Shop = #domain_Shop{}) ->

View File

@ -16,51 +16,45 @@
-type timestamp_interval_bound() :: dmsl_base_thrift:'TimestampIntervalBound'().
%% not exported from calendar module
-type rfc3339_time_unit() :: microsecond
| millisecond
| nanosecond
| second.
-type rfc3339_time_unit() ::
microsecond |
millisecond |
nanosecond |
second.
-export_type([timestamp/0]).
%%
-spec format_ts(unix_timestamp()) -> timestamp().
format_ts(Ts) when is_integer(Ts) ->
format_ts(Ts, second).
-spec format_now() -> timestamp().
format_now() ->
USec = erlang:system_time(microsecond),
format_ts(USec, microsecond).
-spec compare(timestamp(), timestamp()) -> later | earlier | simultaneously.
compare(T1, T2) when is_binary(T1) andalso is_binary(T2) ->
compare_int(to_integer(T1), to_integer(T2)).
% Compare inclusivly! undefined ==
-spec between(timestamp(), timestamp() | undefined, timestamp() | undefined) -> boolean().
between(Timestamp, Start, End) ->
LB = to_interval_bound(Start, inclusive),
UB = to_interval_bound(End, inclusive),
between(Timestamp, #'TimestampInterval'{lower_bound = LB, upper_bound = UB}).
-spec between(timestamp(), timestamp_interval()) -> boolean().
between(Timestamp, #'TimestampInterval'{lower_bound = LB, upper_bound = UB}) ->
check_bound(Timestamp, LB, later)
andalso
check_bound(Timestamp, UB, earlier).
check_bound(Timestamp, LB, later) andalso
check_bound(Timestamp, UB, earlier).
-spec add_interval(timestamp(), {Years, Months, Days}) -> timestamp() when
Years :: integer() | undefined,
Months :: integer() | undefined,
Days :: integer() | undefined.
add_interval(Timestamp, {YY, MM, DD}) ->
TSSeconds = erlang:convert_time_unit(to_integer(Timestamp), microsecond, second),
{Date, Time} = genlib_time:unixtime_to_daytime(TSSeconds),
@ -68,7 +62,6 @@ add_interval(Timestamp, {YY, MM, DD}) ->
format_ts(genlib_time:daytime_to_unixtime({NewDate, Time})).
-spec parse(binary(), rfc3339_time_unit()) -> integer().
parse(Bin, Precision) when is_binary(Bin) ->
Str = erlang:binary_to_list(Bin),
calendar:rfc3339_to_system_time(Str, [{unit, Precision}]).
@ -76,13 +69,11 @@ parse(Bin, Precision) when is_binary(Bin) ->
%% Internal functions
-spec format_ts(integer(), rfc3339_time_unit()) -> timestamp().
format_ts(Ts, Unit) ->
Str = calendar:system_time_to_rfc3339(Ts, [{unit, Unit}, {offset, "Z"}]),
erlang:list_to_binary(Str).
-spec to_integer(timestamp()) -> integer().
to_integer(Timestamp) ->
parse(Timestamp, microsecond).
@ -102,7 +93,6 @@ compare_int(T1, T2) ->
end.
-spec check_bound(timestamp(), timestamp_interval_bound(), later | earlier) -> boolean().
check_bound(_, undefined, _) ->
true;
check_bound(Timestamp, #'TimestampIntervalBound'{bound_type = Type, bound_time = BoundTime}, Operator) ->
@ -120,6 +110,5 @@ nvl(Val) ->
nvl(undefined, Default) ->
Default;
nvl(Val, _) ->
Val.

View File

@ -5,6 +5,7 @@
%%% domain objects
-module(pm_domain).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_config_thrift.hrl").
@ -19,6 +20,7 @@
-export([insert/1]).
-export([update/1]).
-export([cleanup/0]).
%%
-type revision() :: pos_integer().
@ -32,18 +34,15 @@
-export_type([data/0]).
-spec head() -> revision().
head() ->
dmt_client:get_last_version().
-spec all(revision()) -> dmsl_domain_thrift:'Domain'().
all(Revision) ->
#'Snapshot'{domain = Domain} = dmt_client:checkout({version, Revision}),
Domain.
-spec get(revision(), ref()) -> data() | no_return().
get(Revision, Ref) ->
try
extract_data(dmt_client:checkout_object({version, Revision}, Ref))
@ -53,7 +52,6 @@ get(Revision, Ref) ->
end.
-spec find(revision(), ref()) -> data() | notfound.
find(Revision, Ref) ->
try
extract_data(dmt_client:checkout_object({version, Revision}, Ref))
@ -63,7 +61,6 @@ find(Revision, Ref) ->
end.
-spec exists(revision(), ref()) -> boolean().
exists(Revision, Ref) ->
try
_ = dmt_client:checkout_object({version, Revision}, Ref),
@ -77,14 +74,12 @@ extract_data(#'VersionedObject'{object = {_Tag, {_Name, _Ref, Data}}}) ->
Data.
-spec commit(revision(), dmt_client:commit()) -> ok | no_return().
commit(Revision, Commit) ->
Revision = dmt_client:commit(Revision, Commit) - 1,
_ = pm_domain:all(Revision + 1),
ok.
-spec insert(object() | [object()]) -> ok | no_return().
insert(Object) when not is_list(Object) ->
insert([Object]);
insert(Objects) ->
@ -92,14 +87,13 @@ insert(Objects) ->
ops = [
{insert, #'InsertOp'{
object = Object
}} ||
Object <- Objects
}}
|| Object <- Objects
]
},
commit(head(), Commit).
-spec update(object() | [object()]) -> ok | no_return().
update(NewObject) when not is_list(NewObject) ->
update([NewObject]);
update(NewObjects) ->
@ -111,26 +105,24 @@ update(NewObjects) ->
new_object = NewObject
}}
|| NewObject = {Tag, {ObjectName, Ref, _Data}} <- NewObjects,
OldData <- [get(Revision, {Tag, Ref})]
OldData <- [get(Revision, {Tag, Ref})]
]
},
commit(Revision, Commit).
-spec remove([object()]) -> ok | no_return().
remove(Objects) ->
Commit = #'Commit'{
ops = [
{remove, #'RemoveOp'{
object = Object
}} ||
Object <- Objects
}}
|| Object <- Objects
]
},
commit(head(), Commit).
-spec cleanup() -> ok | no_return().
cleanup() ->
Domain = all(head()),
remove(maps:values(Domain)).

View File

@ -4,31 +4,28 @@
-type source_event() :: _.
-type public_event() :: {source(), payload()}.
-type source() :: dmsl_payment_processing_thrift:'EventSource'().
-type payload() :: dmsl_payment_processing_thrift:'EventPayload'().
-type source() :: dmsl_payment_processing_thrift:'EventSource'().
-type payload() :: dmsl_payment_processing_thrift:'EventPayload'().
-export_type([public_event/0]).
-callback publish_event(pm_machine:id(), source_event()) ->
public_event().
-callback publish_event(pm_machine:id(), source_event()) -> public_event().
-export([publish_event/4]).
%%
-type event_id() :: dmsl_base_thrift:'EventID'().
-type event() :: dmsl_payment_processing_thrift:'Event'().
-spec publish_event(pm_machine:ns(), event_id(), pm_machine:id(), pm_machine:event()) ->
event().
-type event() :: dmsl_payment_processing_thrift:'Event'().
-spec publish_event(pm_machine:ns(), event_id(), pm_machine:id(), pm_machine:event()) -> event().
publish_event(Ns, EventID, MachineID, {ID, Dt, Ev}) ->
Module = pm_machine:get_handler_module(Ns),
{Source, Payload} = Module:publish_event(MachineID, Ev),
#payproc_Event{
id = EventID,
source = Source,
id = EventID,
source = Source,
created_at = Dt,
payload = Payload,
sequence = ID
payload = Payload,
sequence = ID
}.

View File

@ -5,12 +5,11 @@
%% API
-export([reduce_globals/3]).
-type globals() :: dmsl_domain_thrift:'Globals'().
-type varset() :: pm_selector:varset().
-type globals() :: dmsl_domain_thrift:'Globals'().
-type varset() :: pm_selector:varset().
-type domain_revision() :: pm_domain:revision().
-spec reduce_globals(globals(), varset(), domain_revision()) -> globals().
reduce_globals(Globals, VS, DomainRevision) ->
Globals#domain_Globals{
external_account_set = pm_selector:reduce(Globals#domain_Globals.external_account_set, VS, DomainRevision)

View File

@ -2,7 +2,7 @@
-include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl").
-type msgp() :: pm_msgpack_marshalling:msgpack_value().
-type msgp() :: pm_msgpack_marshalling:msgpack_value().
-type id() :: mg_proto_base_thrift:'ID'().
-type tag() :: {tag, mg_proto_base_thrift:'Tag'()}.
@ -17,44 +17,41 @@
data := msgp(),
format_version := pos_integer() | undefined
}.
-type timestamp() :: mg_proto_base_thrift:'Timestamp'().
-type history() :: [event()].
-type auxst() :: msgp().
-type history_range() :: mg_proto_state_processing_thrift:'HistoryRange'().
-type direction() :: mg_proto_state_processing_thrift:'Direction'().
-type descriptor() :: mg_proto_state_processing_thrift:'MachineDescriptor'().
-type direction() :: mg_proto_state_processing_thrift:'Direction'().
-type descriptor() :: mg_proto_state_processing_thrift:'MachineDescriptor'().
-type machine() :: #{
id := id(),
history := history(),
aux_state := auxst()
id := id(),
history := history(),
aux_state := auxst()
}.
-type result() :: #{
events => [event_payload()],
action => pm_machine_action:t(),
auxst => auxst()
events => [event_payload()],
action => pm_machine_action:t(),
auxst => auxst()
}.
-callback namespace() ->
ns().
-callback namespace() -> ns().
-callback init(args(), machine()) ->
result().
-callback init(args(), machine()) -> result().
-type signal() ::
timeout | {repair, args()}.
-callback process_signal(signal(), machine()) ->
result().
-callback process_signal(signal(), machine()) -> result().
-type call() :: _.
-type thrift_call() :: {pm_proto_utils:thrift_fun_ref(), woody:args()}.
-type response() :: ok | {ok, term()} | {exception, term()}.
-callback process_call(call(), machine()) ->
{response(), result()}.
-callback process_call(call(), machine()) -> {response(), result()}.
-type context() :: #{
client_context => woody_context:ctx()
@ -113,13 +110,11 @@
%%
-spec start(ns(), id(), term()) ->
{ok, term()} | {error, exists | term()} | no_return().
-spec start(ns(), id(), term()) -> {ok, term()} | {error, exists | term()} | no_return().
start(Ns, ID, Args) ->
call_automaton('Start', {Ns, ID, wrap_args(Args)}).
-spec thrift_call(ns(), ref(), service_name(), function_ref(), args()) ->
response() | {error, notfound | failed}.
-spec thrift_call(ns(), ref(), service_name(), function_ref(), args()) -> response() | {error, notfound | failed}.
thrift_call(Ns, Ref, Service, FunRef, Args) ->
thrift_call(Ns, Ref, Service, FunRef, Args, undefined, undefined, forward).
@ -144,8 +139,7 @@ thrift_call(Ns, Ref, Service, FunRef, Args, After, Limit, Direction) ->
Error
end.
-spec call(ns(), ref(), Args :: term()) ->
response() | {error, notfound | failed}.
-spec call(ns(), ref(), Args :: term()) -> response() | {error, notfound | failed}.
call(Ns, Ref, Args) ->
call(Ns, Ref, Args, undefined, undefined, forward).
@ -165,28 +159,22 @@ call(Ns, Ref, Args, After, Limit, Direction) ->
Error
end.
-spec repair(ns(), ref(), term()) ->
{ok, term()} | {error, notfound | failed | working} | no_return().
-spec repair(ns(), ref(), term()) -> {ok, term()} | {error, notfound | failed | working} | no_return().
repair(Ns, Ref, Args) ->
Descriptor = prepare_descriptor(Ns, Ref, #mg_stateproc_HistoryRange{}),
call_automaton('Repair', {Descriptor, wrap_args(Args)}).
-spec get_history(ns(), ref()) ->
{ok, history()} | {error, notfound} | no_return().
-spec get_history(ns(), ref()) -> {ok, history()} | {error, notfound} | no_return().
get_history(Ns, Ref) ->
get_history(Ns, Ref, undefined, undefined, forward).
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer()) ->
{ok, history()} | {error, notfound} | no_return().
get_history(Ns, Ref, AfterID, Limit) ->
get_history(Ns, Ref, AfterID, Limit, forward).
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
{ok, history()} | {error, notfound} | no_return().
get_history(Ns, Ref, AfterID, Limit, Direction) ->
case get_machine(Ns, Ref, AfterID, Limit, Direction) of
{ok, #{history := History}} ->
@ -197,7 +185,6 @@ get_history(Ns, Ref, AfterID, Limit, Direction) ->
-spec get_machine(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
{ok, machine()} | {error, notfound} | no_return().
get_machine(Ns, Ref, AfterID, Limit, Direction) ->
Range = #mg_stateproc_HistoryRange{'after' = AfterID, limit = Limit, direction = Direction},
Descriptor = prepare_descriptor(Ns, Ref, Range),
@ -250,16 +237,14 @@ call_automaton(Function, Args) ->
-type func() :: 'ProcessSignal' | 'ProcessCall'.
-spec handle_function(func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
term() | no_return().
-spec handle_function(func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
handle_function(Func, Args, Opts) ->
scoper:scope(machine,
scoper:scope(
machine,
fun() -> handle_function_(Func, Args, Opts) end
).
-spec handle_function_(func(), woody:args(), #{ns := ns()}) -> term() | no_return().
handle_function_('ProcessSignal', {Args}, #{ns := Ns} = _Opts) ->
#mg_stateproc_SignalArgs{signal = {Type, Signal}, machine = #mg_stateproc_Machine{id = ID} = Machine} = Args,
scoper:add_meta(#{
@ -269,7 +254,6 @@ handle_function_('ProcessSignal', {Args}, #{ns := Ns} = _Opts) ->
signal => Type
}),
dispatch_signal(Ns, Signal, unmarshal_machine(Machine));
handle_function_('ProcessCall', {Args}, #{ns := Ns} = _Opts) ->
#mg_stateproc_CallArgs{arg = Payload, machine = #mg_stateproc_Machine{id = ID} = Machine} = Args,
scoper:add_meta(#{
@ -281,28 +265,24 @@ handle_function_('ProcessCall', {Args}, #{ns := Ns} = _Opts) ->
%%
-spec dispatch_signal(ns(), Signal, machine()) ->
Result when
Signal ::
mg_proto_state_processing_thrift:'InitSignal'() |
mg_proto_state_processing_thrift:'TimeoutSignal'() |
mg_proto_state_processing_thrift:'RepairSignal'(),
Result ::
mg_proto_state_processing_thrift:'SignalResult'().
-spec dispatch_signal(ns(), Signal, machine()) -> Result when
Signal ::
mg_proto_state_processing_thrift:'InitSignal'() |
mg_proto_state_processing_thrift:'TimeoutSignal'() |
mg_proto_state_processing_thrift:'RepairSignal'(),
Result ::
mg_proto_state_processing_thrift:'SignalResult'().
dispatch_signal(Ns, #mg_stateproc_InitSignal{arg = Payload}, Machine) ->
Args = unwrap_args(Payload),
_ = log_dispatch(init, Args, Machine),
Module = get_handler_module(Ns),
Result = Module:init(Args, Machine),
marshal_signal_result(Result, Machine);
dispatch_signal(Ns, #mg_stateproc_TimeoutSignal{}, Machine) ->
_ = log_dispatch(timeout, Machine),
Module = get_handler_module(Ns),
Result = Module:process_signal(timeout, Machine),
marshal_signal_result(Result, Machine);
dispatch_signal(Ns, #mg_stateproc_RepairSignal{arg = Payload}, Machine) ->
Args = unwrap_args(Payload),
_ = log_dispatch(repair, Args, Machine),
@ -321,11 +301,9 @@ marshal_signal_result(Result = #{}, #{aux_state := AuxStWas}) ->
action = maps:get(action, Result, pm_machine_action:new())
}.
-spec dispatch_call(ns(), Call, machine()) ->
Result when
Call :: mg_proto_state_processing_thrift:'Args'(),
Result :: mg_proto_state_processing_thrift:'CallResult'().
-spec dispatch_call(ns(), Call, machine()) -> Result when
Call :: mg_proto_state_processing_thrift:'Args'(),
Result :: mg_proto_state_processing_thrift:'CallResult'().
dispatch_call(Ns, Payload, Machine) ->
Args = unwrap_args(Payload),
_ = log_dispatch(call, Args, Machine),
@ -358,9 +336,7 @@ marshal_call_result(Response, Result, #{aux_state := AuxStWas}) ->
-type service_handler() ::
{Path :: string(), {woody:service(), {module(), pm_woody_wrapper:handler_opts()}}}.
-spec get_child_spec([MachineHandler :: module()]) ->
supervisor:child_spec().
-spec get_child_spec([MachineHandler :: module()]) -> supervisor:child_spec().
get_child_spec(MachineHandlers) ->
#{
id => pm_machine_dispatch,
@ -368,9 +344,7 @@ get_child_spec(MachineHandlers) ->
type => supervisor
}.
-spec get_service_handlers([MachineHandler :: module()], map()) ->
[service_handler()].
-spec get_service_handlers([MachineHandler :: module()], map()) -> [service_handler()].
get_service_handlers(MachineHandlers, Opts) ->
[get_service_handler(H, Opts) || H <- MachineHandlers].
@ -384,15 +358,11 @@ get_service_handler(MachineHandler, Opts) ->
-define(TABLE, pm_machine_dispatch).
-spec start_link([module()]) ->
{ok, pid()}.
-spec start_link([module()]) -> {ok, pid()}.
start_link(MachineHandlers) ->
supervisor:start_link(?MODULE, MachineHandlers).
-spec init([module()]) ->
{ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
-spec init([module()]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
init(MachineHandlers) ->
_ = ets:new(?TABLE, [protected, named_table, {read_concurrency, true}]),
true = ets:insert_new(?TABLE, [{MH:namespace(), MH} || MH <- MachineHandlers]),
@ -401,7 +371,6 @@ init(MachineHandlers) ->
%%
-spec get_handler_module(ns()) -> module().
get_handler_module(Ns) ->
ets:lookup_element(?TABLE, Ns, 2).
@ -420,18 +389,16 @@ log_dispatch(Operation, Args, #{id := ID, history := History, aux_state := AuxSt
unmarshal_machine(#mg_stateproc_Machine{id = ID, history = History} = Machine) ->
AuxState = get_aux_state(Machine),
#{
id => ID,
history => unmarshal_events(History),
id => ID,
history => unmarshal_events(History),
aux_state => AuxState
}.
-spec marshal_events([event_payload()]) ->
[mg_event_payload()].
-spec marshal_events([event_payload()]) -> [mg_event_payload()].
marshal_events(Events) when is_list(Events) ->
[marshal_event(Event) || Event <- Events].
-spec marshal_event(event_payload()) ->
mg_event_payload().
-spec marshal_event(event_payload()) -> mg_event_payload().
marshal_event(#{format_version := Format, data := Data}) ->
#mg_stateproc_Content{
format_version = Format,
@ -444,24 +411,21 @@ marshal_aux_st_format(AuxSt) ->
data = mg_msgpack_marshalling:marshal(AuxSt)
}.
-spec marshal_thrift_args(service_name(), function_ref(), args()) ->
binary().
-spec marshal_thrift_args(service_name(), function_ref(), args()) -> binary().
marshal_thrift_args(ServiceName, FunctionRef, Args) ->
{Service, _Function} = FunctionRef,
{Module, Service} = pm_proto:get_service(ServiceName),
FullFunctionRef = {Module, FunctionRef},
pm_proto_utils:serialize_function_args(FullFunctionRef, Args).
-spec unmarshal_thrift_args(service_name(), function_ref(), binary()) ->
args().
-spec unmarshal_thrift_args(service_name(), function_ref(), binary()) -> args().
unmarshal_thrift_args(ServiceName, FunctionRef, Args) ->
{Service, _Function} = FunctionRef,
{Module, Service} = pm_proto:get_service(ServiceName),
FullFunctionRef = {Module, FunctionRef},
pm_proto_utils:deserialize_function_args(FullFunctionRef, Args).
-spec marshal_thrift_response(service_name(), function_ref(), response()) ->
response().
-spec marshal_thrift_response(service_name(), function_ref(), response()) -> response().
marshal_thrift_response(ServiceName, FunctionRef, Response) ->
{Service, _Function} = FunctionRef,
{Module, Service} = pm_proto:get_service(ServiceName),
@ -477,8 +441,7 @@ marshal_thrift_response(ServiceName, FunctionRef, Response) ->
{exception, EncodedException}
end.
-spec unmarshal_thrift_response(service_name(), function_ref(), response()) ->
response().
-spec unmarshal_thrift_response(service_name(), function_ref(), response()) -> response().
unmarshal_thrift_response(ServiceName, FunctionRef, Response) ->
{Service, _Function} = FunctionRef,
{Module, Service} = pm_proto:get_service(ServiceName),
@ -494,8 +457,7 @@ unmarshal_thrift_response(ServiceName, FunctionRef, Response) ->
{exception, Exception}
end.
-spec marshal_schemaless_response(response()) ->
response().
-spec marshal_schemaless_response(response()) -> response().
marshal_schemaless_response(ok) ->
ok;
marshal_schemaless_response({ok, _Reply} = Response) ->
@ -503,8 +465,7 @@ marshal_schemaless_response({ok, _Reply} = Response) ->
marshal_schemaless_response({exception, _Exception} = Response) ->
Response.
-spec unmarshal_schemaless_response(response()) ->
response().
-spec unmarshal_schemaless_response(response()) -> response().
unmarshal_schemaless_response(ok) ->
ok;
unmarshal_schemaless_response({ok, _Reply} = Response) ->
@ -522,13 +483,11 @@ marshal_response({exception, _Exception} = Response) ->
unmarshal_response(Response) ->
unmarshal_term(Response).
-spec unmarshal_events([mg_event()]) ->
[event()].
-spec unmarshal_events([mg_event()]) -> [event()].
unmarshal_events(Events) when is_list(Events) ->
[unmarshal_event(Event) || Event <- Events].
-spec unmarshal_event(mg_event()) ->
event().
-spec unmarshal_event(mg_event()) -> event().
unmarshal_event(#mg_stateproc_Event{id = ID, created_at = Dt, format_version = Format, data = Payload}) ->
{ID, Dt, #{format_version => Format, data => mg_msgpack_marshalling:unmarshal(Payload)}}.

View File

@ -13,6 +13,5 @@
%%
-spec new() -> t().
new() ->
#mg_stateproc_ComplexAction{}.

View File

@ -11,21 +11,17 @@
-export_type([maybe/1]).
-spec apply(fun(), Arg :: undefined | term()) ->
term().
-spec apply(fun(), Arg :: undefined | term()) -> term().
apply(Fun, Arg) ->
pm_maybe:apply(Fun, Arg, undefined).
-spec apply(fun(), Arg :: undefined | term(), Default :: term()) ->
term().
-spec apply(fun(), Arg :: undefined | term(), Default :: term()) -> term().
apply(Fun, Arg, _Default) when Arg =/= undefined ->
Fun(Arg);
apply(_Fun, undefined, Default) ->
Default.
-spec get_defined([maybe(T)]) ->
T | no_return().
-spec get_defined([maybe(T)]) -> T | no_return().
get_defined([]) ->
erlang:error(badarg);
get_defined([Value | _Tail]) when Value =/= undefined ->
@ -33,9 +29,6 @@ get_defined([Value | _Tail]) when Value =/= undefined ->
get_defined([undefined | Tail]) ->
get_defined(Tail).
-spec get_defined(maybe(T), maybe(T)) ->
T | no_return().
-spec get_defined(maybe(T), maybe(T)) -> T | no_return().
get_defined(V1, V2) ->
get_defined([V1, V2]).

View File

@ -1,4 +1,5 @@
-module(pm_msgpack_marshalling).
-include_lib("damsel/include/dmsl_msgpack_thrift.hrl").
-include_lib("mg_proto/include/mg_proto_msgpack_thrift.hrl").
@ -23,8 +24,7 @@
%%
-spec marshal(msgpack_value()) ->
dmsl_msgpack_thrift:'Value'().
-spec marshal(msgpack_value()) -> dmsl_msgpack_thrift:'Value'().
marshal(undefined) ->
{nl, #msgpack_Nil{}};
marshal(Boolean) when is_boolean(Boolean) ->
@ -38,19 +38,18 @@ marshal(String) when is_binary(String) ->
marshal({bin, Binary}) ->
{bin, Binary};
marshal(Object) when is_map(Object) ->
{obj, maps:fold(
fun(K, V, Acc) ->
maps:put(marshal(K), marshal(V), Acc)
end,
#{},
Object
)};
{obj,
maps:fold(
fun(K, V, Acc) ->
maps:put(marshal(K), marshal(V), Acc)
end,
#{},
Object
)};
marshal(Array) when is_list(Array) ->
{arr, lists:map(fun marshal/1, Array)}.
-spec unmarshal(dmsl_msgpack_thrift:'Value'()) ->
msgpack_value().
-spec unmarshal(dmsl_msgpack_thrift:'Value'()) -> msgpack_value().
unmarshal({nl, #msgpack_Nil{}}) ->
undefined;
unmarshal({b, Boolean}) ->

View File

@ -3,7 +3,6 @@
%% * https://github.com/rbkmoney/coredocs/blob/529bc03/docs/domain/entities/merchant.md
%% * https://github.com/rbkmoney/coredocs/blob/529bc03/docs/domain/entities/contract.md
%% @TODO
%% * Deal with default shop services (will need to change thrift-protocol as well)
%% * Access check before shop creation is weird (think about adding context)
@ -11,6 +10,7 @@
-module(pm_party).
-include("party_events.hrl").
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-include_lib("damsel/include/dmsl_accounter_thrift.hrl").
@ -55,62 +55,53 @@
%%
-type party() :: dmsl_domain_thrift:'Party'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_revision() :: dmsl_domain_thrift:'PartyRevision'().
-type party_status() :: dmsl_domain_thrift:'PartyStatus'().
-type contract() :: dmsl_domain_thrift:'Contract'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contractor() :: dmsl_domain_thrift:'PartyContractor'().
-type contractor_id() :: dmsl_domain_thrift:'ContractorID'().
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
-type shop() :: dmsl_domain_thrift:'Shop'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type shop_params() :: dmsl_payment_processing_thrift:'ShopParams'().
-type wallet() :: dmsl_domain_thrift:'Wallet'().
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
-type party() :: dmsl_domain_thrift:'Party'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_revision() :: dmsl_domain_thrift:'PartyRevision'().
-type party_status() :: dmsl_domain_thrift:'PartyStatus'().
-type contract() :: dmsl_domain_thrift:'Contract'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contractor() :: dmsl_domain_thrift:'PartyContractor'().
-type contractor_id() :: dmsl_domain_thrift:'ContractorID'().
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
-type shop() :: dmsl_domain_thrift:'Shop'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type shop_params() :: dmsl_payment_processing_thrift:'ShopParams'().
-type wallet() :: dmsl_domain_thrift:'Wallet'().
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
-type blocking() :: dmsl_domain_thrift:'Blocking'().
-type suspension() :: dmsl_domain_thrift:'Suspension'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type revision() :: pm_domain:revision().
-type blocking() :: dmsl_domain_thrift:'Blocking'().
-type suspension() :: dmsl_domain_thrift:'Suspension'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type revision() :: pm_domain:revision().
%% Interface
-spec create_party(party_id(), dmsl_domain_thrift:'PartyContactInfo'(), timestamp()) ->
party().
-spec create_party(party_id(), dmsl_domain_thrift:'PartyContactInfo'(), timestamp()) -> party().
create_party(PartyID, ContactInfo, Timestamp) ->
#domain_Party{
id = PartyID,
created_at = Timestamp,
revision = 0,
contact_info = ContactInfo,
blocking = ?unblocked(Timestamp),
suspension = ?active(Timestamp),
contractors = #{},
contracts = #{},
shops = #{},
wallets = #{}
id = PartyID,
created_at = Timestamp,
revision = 0,
contact_info = ContactInfo,
blocking = ?unblocked(Timestamp),
suspension = ?active(Timestamp),
contractors = #{},
contracts = #{},
shops = #{},
wallets = #{}
}.
-spec blocking(blocking(), party()) ->
party().
-spec blocking(blocking(), party()) -> party().
blocking(Blocking, Party) ->
Party#domain_Party{blocking = Blocking}.
-spec suspension(suspension(), party()) ->
party().
-spec suspension(suspension(), party()) -> party().
suspension(Suspension, Party) ->
Party#domain_Party{suspension = Suspension}.
-spec get_status(party()) ->
party_status().
-spec get_status(party()) -> party_status().
get_status(Party) ->
#domain_PartyStatus{
id = Party#domain_Party.id,
@ -119,39 +110,28 @@ get_status(Party) ->
suspension = Party#domain_Party.suspension
}.
-spec get_contractor(contractor_id(), party()) ->
contractor() | undefined.
-spec get_contractor(contractor_id(), party()) -> contractor() | undefined.
get_contractor(ID, #domain_Party{contractors = Contractors}) ->
maps:get(ID, Contractors, undefined).
-spec set_contractor(contractor(), party()) ->
party().
-spec set_contractor(contractor(), party()) -> party().
set_contractor(Contractor = #domain_PartyContractor{id = ID}, Party = #domain_Party{contractors = Contractors}) ->
Party#domain_Party{contractors = Contractors#{ID => Contractor}}.
-spec get_contract(contract_id(), party()) ->
contract() | undefined.
-spec get_contract(contract_id(), party()) -> contract() | undefined.
get_contract(ID, #domain_Party{contracts = Contracts}) ->
maps:get(ID, Contracts, undefined).
-spec set_new_contract(contract(), timestamp(), party()) ->
party().
-spec set_new_contract(contract(), timestamp(), party()) -> party().
set_new_contract(Contract, Timestamp, Party) ->
set_contract(pm_contract:update_status(Contract, Timestamp), Party).
-spec set_contract(contract(), party()) ->
party().
-spec set_contract(contract(), party()) -> party().
set_contract(Contract = #domain_Contract{id = ID}, Party = #domain_Party{contracts = Contracts}) ->
Party#domain_Party{contracts = Contracts#{ID => Contract}}.
-spec get_terms(contract() | contract_template(), timestamp(), revision()) ->
dmsl_domain_thrift:'TermSet'() | no_return().
get_terms(#domain_Contract{} = Contract, Timestamp, Revision) ->
case compute_terms(Contract, Timestamp, Revision) of
#domain_TermSet{} = Terms ->
@ -162,51 +142,39 @@ get_terms(#domain_Contract{} = Contract, Timestamp, Revision) ->
get_terms(#domain_ContractTemplate{terms = TermSetHierarchyRef}, Timestamp, Revision) ->
get_term_set(TermSetHierarchyRef, Timestamp, Revision).
-spec create_shop(shop_id(), shop_params(), timestamp()) ->
shop().
-spec create_shop(shop_id(), shop_params(), timestamp()) -> shop().
create_shop(ID, ShopParams, Timestamp) ->
#domain_Shop{
id = ID,
created_at = Timestamp,
blocking = ?unblocked(Timestamp),
suspension = ?active(Timestamp),
category = ShopParams#payproc_ShopParams.category,
details = ShopParams#payproc_ShopParams.details,
location = ShopParams#payproc_ShopParams.location,
contract_id = ShopParams#payproc_ShopParams.contract_id,
payout_tool_id = ShopParams#payproc_ShopParams.payout_tool_id
id = ID,
created_at = Timestamp,
blocking = ?unblocked(Timestamp),
suspension = ?active(Timestamp),
category = ShopParams#payproc_ShopParams.category,
details = ShopParams#payproc_ShopParams.details,
location = ShopParams#payproc_ShopParams.location,
contract_id = ShopParams#payproc_ShopParams.contract_id,
payout_tool_id = ShopParams#payproc_ShopParams.payout_tool_id
}.
-spec get_shop(shop_id(), party()) ->
shop() | undefined.
-spec get_shop(shop_id(), party()) -> shop() | undefined.
get_shop(ID, #domain_Party{shops = Shops}) ->
maps:get(ID, Shops, undefined).
-spec set_shop(shop(), party()) ->
party().
-spec set_shop(shop(), party()) -> party().
set_shop(Shop = #domain_Shop{id = ID}, Party = #domain_Party{shops = Shops}) ->
Party#domain_Party{shops = Shops#{ID => Shop}}.
-spec shop_blocking(shop_id(), blocking(), party()) ->
party().
-spec shop_blocking(shop_id(), blocking(), party()) -> party().
shop_blocking(ID, Blocking, Party) ->
Shop = get_shop(ID, Party),
set_shop(Shop#domain_Shop{blocking = Blocking}, Party).
-spec shop_suspension(shop_id(), suspension(), party()) ->
party().
-spec shop_suspension(shop_id(), suspension(), party()) -> party().
shop_suspension(ID, Suspension, Party) ->
Shop = get_shop(ID, Party),
set_shop(Shop#domain_Shop{suspension = Suspension}, Party).
-spec get_shop_account(shop_id(), party()) ->
dmsl_domain_thrift:'ShopAccount'().
-spec get_shop_account(shop_id(), party()) -> dmsl_domain_thrift:'ShopAccount'().
get_shop_account(ShopID, Party) ->
Shop = ensure_shop(get_shop(ShopID, Party)),
get_shop_account(Shop).
@ -218,7 +186,6 @@ get_shop_account(#domain_Shop{account = Account}) ->
-spec get_account_state(dmsl_accounter_thrift:'AccountID'(), party()) ->
dmsl_payment_processing_thrift:'AccountState'().
get_account_state(AccountID, Party) ->
ok = ensure_account(AccountID, Party),
Account = pm_accounting:get_account(AccountID),
@ -241,28 +208,20 @@ get_account_state(AccountID, Party) ->
currency = Currency
}.
-spec get_wallet(wallet_id(), party()) ->
wallet() | undefined.
-spec get_wallet(wallet_id(), party()) -> wallet() | undefined.
get_wallet(ID, #domain_Party{wallets = Wallets}) ->
maps:get(ID, Wallets, undefined).
-spec set_wallet(wallet(), party()) ->
party().
-spec set_wallet(wallet(), party()) -> party().
set_wallet(Wallet = #domain_Wallet{id = ID}, Party = #domain_Party{wallets = Wallets}) ->
Party#domain_Party{wallets = Wallets#{ID => Wallet}}.
-spec wallet_blocking(wallet_id(), blocking(), party()) ->
party().
-spec wallet_blocking(wallet_id(), blocking(), party()) -> party().
wallet_blocking(ID, Blocking, Party) ->
Wallet = get_wallet(ID, Party),
set_wallet(Wallet#domain_Wallet{blocking = Blocking}, Party).
-spec wallet_suspension(wallet_id(), suspension(), party()) ->
party().
-spec wallet_suspension(wallet_id(), suspension(), party()) -> party().
wallet_suspension(ID, Suspension, Party) ->
Wallet = get_wallet(ID, Party),
set_wallet(Wallet#domain_Wallet{suspension = Suspension}, Party).
@ -277,9 +236,7 @@ ensure_shop(#domain_Shop{} = Shop) ->
ensure_shop(undefined) ->
throw(#payproc_ShopNotFound{}).
-spec reduce_terms(dmsl_domain_thrift:'TermSet'(), pm_selector:varset(), revision()) ->
dmsl_domain_thrift:'TermSet'().
-spec reduce_terms(dmsl_domain_thrift:'TermSet'(), pm_selector:varset(), revision()) -> dmsl_domain_thrift:'TermSet'().
%% TODO rework this part for more generic approach
reduce_terms(
#domain_TermSet{
@ -305,20 +262,20 @@ reduce_terms(
reduce_payments_terms(#domain_PaymentsServiceTerms{} = Terms, VS, Rev) ->
#domain_PaymentsServiceTerms{
currencies = reduce_if_defined(Terms#domain_PaymentsServiceTerms.currencies, VS, Rev),
categories = reduce_if_defined(Terms#domain_PaymentsServiceTerms.categories, VS, Rev),
currencies = reduce_if_defined(Terms#domain_PaymentsServiceTerms.currencies, VS, Rev),
categories = reduce_if_defined(Terms#domain_PaymentsServiceTerms.categories, VS, Rev),
payment_methods = reduce_if_defined(Terms#domain_PaymentsServiceTerms.payment_methods, VS, Rev),
cash_limit = reduce_if_defined(Terms#domain_PaymentsServiceTerms.cash_limit, VS, Rev),
fees = reduce_if_defined(Terms#domain_PaymentsServiceTerms.fees, VS, Rev),
holds = pm_maybe:apply(
cash_limit = reduce_if_defined(Terms#domain_PaymentsServiceTerms.cash_limit, VS, Rev),
fees = reduce_if_defined(Terms#domain_PaymentsServiceTerms.fees, VS, Rev),
holds = pm_maybe:apply(
fun(X) -> reduce_holds_terms(X, VS, Rev) end,
Terms#domain_PaymentsServiceTerms.holds
),
refunds = pm_maybe:apply(
refunds = pm_maybe:apply(
fun(X) -> reduce_refunds_terms(X, VS, Rev) end,
Terms#domain_PaymentsServiceTerms.refunds
),
chargebacks = pm_maybe:apply(
chargebacks = pm_maybe:apply(
fun(X) -> reduce_chargeback_terms(X, VS, Rev) end,
Terms#domain_PaymentsServiceTerms.chargebacks
)
@ -331,17 +288,17 @@ reduce_recurrent_paytools_terms(#domain_RecurrentPaytoolsServiceTerms{} = Terms,
reduce_holds_terms(#domain_PaymentHoldsServiceTerms{} = Terms, VS, Rev) ->
#domain_PaymentHoldsServiceTerms{
payment_methods = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.payment_methods, VS, Rev),
lifetime = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.lifetime, VS, Rev),
payment_methods = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.payment_methods, VS, Rev),
lifetime = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.lifetime, VS, Rev),
partial_captures = Terms#domain_PaymentHoldsServiceTerms.partial_captures
}.
reduce_refunds_terms(#domain_PaymentRefundsServiceTerms{} = Terms, VS, Rev) ->
#domain_PaymentRefundsServiceTerms{
payment_methods = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.payment_methods, VS, Rev),
fees = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.fees, VS, Rev),
eligibility_time = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.eligibility_time, VS, Rev),
partial_refunds = pm_maybe:apply(
payment_methods = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.payment_methods, VS, Rev),
fees = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.fees, VS, Rev),
eligibility_time = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.eligibility_time, VS, Rev),
partial_refunds = pm_maybe:apply(
fun(X) -> reduce_partial_refunds_terms(X, VS, Rev) end,
Terms#domain_PaymentRefundsServiceTerms.partial_refunds
)
@ -354,19 +311,20 @@ reduce_partial_refunds_terms(#domain_PartialRefundsServiceTerms{} = Terms, VS, R
reduce_chargeback_terms(#domain_PaymentChargebackServiceTerms{} = Terms, VS, Rev) ->
#domain_PaymentChargebackServiceTerms{
allow = pm_maybe:apply(
allow = pm_maybe:apply(
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
Terms#domain_PaymentChargebackServiceTerms.allow),
fees = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.fees, VS, Rev),
Terms#domain_PaymentChargebackServiceTerms.allow
),
fees = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.fees, VS, Rev),
eligibility_time = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.eligibility_time, VS, Rev)
}.
reduce_payout_terms(#domain_PayoutsServiceTerms{} = Terms, VS, Rev) ->
#domain_PayoutsServiceTerms{
payout_schedules = reduce_if_defined(Terms#domain_PayoutsServiceTerms.payout_schedules, VS, Rev),
payout_methods = reduce_if_defined(Terms#domain_PayoutsServiceTerms.payout_methods, VS, Rev),
cash_limit = reduce_if_defined(Terms#domain_PayoutsServiceTerms.cash_limit, VS, Rev),
fees = reduce_if_defined(Terms#domain_PayoutsServiceTerms.fees, VS, Rev)
payout_methods = reduce_if_defined(Terms#domain_PayoutsServiceTerms.payout_methods, VS, Rev),
cash_limit = reduce_if_defined(Terms#domain_PayoutsServiceTerms.cash_limit, VS, Rev),
fees = reduce_if_defined(Terms#domain_PayoutsServiceTerms.fees, VS, Rev)
}.
reduce_reports_terms(#domain_ReportsServiceTerms{acts = Acts}, VS, Rev) ->
@ -405,7 +363,8 @@ reduce_p2p_terms(#domain_P2PServiceTerms{} = Terms, VS, Rev) ->
#domain_P2PServiceTerms{
allow = pm_maybe:apply(
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
Terms#domain_P2PServiceTerms.allow),
Terms#domain_P2PServiceTerms.allow
),
currencies = reduce_if_defined(Terms#domain_P2PServiceTerms.currencies, VS, Rev),
cash_limit = reduce_if_defined(Terms#domain_P2PServiceTerms.cash_limit, VS, Rev),
cash_flow = reduce_if_defined(Terms#domain_P2PServiceTerms.cash_flow, VS, Rev),
@ -418,14 +377,16 @@ reduce_p2p_template_terms(#domain_P2PTemplateServiceTerms{} = Terms, VS, Rev) ->
#domain_P2PTemplateServiceTerms{
allow = pm_maybe:apply(
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
Terms#domain_P2PTemplateServiceTerms.allow)
Terms#domain_P2PTemplateServiceTerms.allow
)
}.
reduce_w2w_terms(#domain_W2WServiceTerms{} = Terms, VS, Rev) ->
#domain_W2WServiceTerms{
allow = pm_maybe:apply(
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
Terms#domain_W2WServiceTerms.allow),
Terms#domain_W2WServiceTerms.allow
),
currencies = reduce_if_defined(Terms#domain_W2WServiceTerms.currencies, VS, Rev),
cash_limit = reduce_if_defined(Terms#domain_W2WServiceTerms.cash_limit, VS, Rev),
cash_flow = reduce_if_defined(Terms#domain_W2WServiceTerms.cash_flow, VS, Rev),
@ -453,7 +414,6 @@ is_adjustment_active(
) ->
pm_datetime:between(Timestamp, pm_utils:select_defined(ValidSince, CreatedAt), ValidUntil).
get_term_set(TermsRef, Timestamp, Revision) ->
#domain_TermSetHierarchy{
parent_terms = ParentRef,
@ -482,7 +442,7 @@ get_active_term_set(TimedTermSets, Timestamp) ->
TimedTermSets
).
merge_term_sets(TermSets) when is_list(TermSets)->
merge_term_sets(TermSets) when is_list(TermSets) ->
lists:foldl(fun merge_term_sets/2, undefined, TermSets).
merge_term_sets(
@ -534,14 +494,14 @@ merge_payments_terms(
}
) ->
#domain_PaymentsServiceTerms{
currencies = pm_utils:select_defined(Curr1, Curr0),
categories = pm_utils:select_defined(Cat1, Cat0),
currencies = pm_utils:select_defined(Curr1, Curr0),
categories = pm_utils:select_defined(Cat1, Cat0),
payment_methods = pm_utils:select_defined(Pm1, Pm0),
cash_limit = pm_utils:select_defined(Al1, Al0),
fees = pm_utils:select_defined(Fee1, Fee0),
holds = merge_holds_terms(Hl0, Hl1),
refunds = merge_refunds_terms(Rf0, Rf1),
chargebacks = merge_chargeback_terms(CB0, CB1)
cash_limit = pm_utils:select_defined(Al1, Al0),
fees = pm_utils:select_defined(Fee1, Fee0),
holds = merge_holds_terms(Hl0, Hl1),
refunds = merge_refunds_terms(Rf0, Rf1),
chargebacks = merge_chargeback_terms(CB0, CB1)
};
merge_payments_terms(Terms0, Terms1) ->
pm_utils:select_defined(Terms1, Terms0).
@ -567,8 +527,8 @@ merge_holds_terms(
}
) ->
#domain_PaymentHoldsServiceTerms{
payment_methods = pm_utils:select_defined(Pm1, Pm0),
lifetime = pm_utils:select_defined(Lft1, Lft0),
payment_methods = pm_utils:select_defined(Pm1, Pm0),
lifetime = pm_utils:select_defined(Lft1, Lft0),
partial_captures = pm_utils:select_defined(Ptcp1, Ptcp0)
};
merge_holds_terms(Terms0, Terms1) ->
@ -589,24 +549,24 @@ merge_refunds_terms(
}
) ->
#domain_PaymentRefundsServiceTerms{
payment_methods = pm_utils:select_defined(Pm1, Pm0),
fees = pm_utils:select_defined(Fee1, Fee0),
eligibility_time = pm_utils:select_defined(ElTime1, ElTime0),
partial_refunds = merge_partial_refunds_terms(PartRef0, PartRef1)
payment_methods = pm_utils:select_defined(Pm1, Pm0),
fees = pm_utils:select_defined(Fee1, Fee0),
eligibility_time = pm_utils:select_defined(ElTime1, ElTime0),
partial_refunds = merge_partial_refunds_terms(PartRef0, PartRef1)
};
merge_refunds_terms(Terms0, Terms1) ->
pm_utils:select_defined(Terms1, Terms0).
merge_partial_refunds_terms(
#domain_PartialRefundsServiceTerms{
cash_limit = Cash0
cash_limit = Cash0
},
#domain_PartialRefundsServiceTerms{
cash_limit = Cash1
cash_limit = Cash1
}
) ->
#domain_PartialRefundsServiceTerms{
cash_limit = pm_utils:select_defined(Cash1, Cash0)
cash_limit = pm_utils:select_defined(Cash1, Cash0)
};
merge_partial_refunds_terms(Terms0, Terms1) ->
pm_utils:select_defined(Terms1, Terms0).
@ -624,9 +584,9 @@ merge_chargeback_terms(
}
) ->
#domain_PaymentChargebackServiceTerms{
allow = hg_utils:select_defined(Allow1, Allow0),
fees = hg_utils:select_defined(Fee1, Fee0),
eligibility_time = hg_utils:select_defined(ElTime1, ElTime0)
allow = hg_utils:select_defined(Allow1, Allow0),
fees = hg_utils:select_defined(Fee1, Fee0),
eligibility_time = hg_utils:select_defined(ElTime1, ElTime0)
};
merge_chargeback_terms(Terms0, Terms1) ->
hg_utils:select_defined(Terms1, Terms0).
@ -634,22 +594,22 @@ merge_chargeback_terms(Terms0, Terms1) ->
merge_payouts_terms(
#domain_PayoutsServiceTerms{
payout_schedules = Ps0,
payout_methods = Pm0,
cash_limit = Cash0,
fees = Fee0
payout_methods = Pm0,
cash_limit = Cash0,
fees = Fee0
},
#domain_PayoutsServiceTerms{
payout_schedules = Ps1,
payout_methods = Pm1,
cash_limit = Cash1,
fees = Fee1
payout_methods = Pm1,
cash_limit = Cash1,
fees = Fee1
}
) ->
#domain_PayoutsServiceTerms{
payout_schedules = pm_utils:select_defined(Ps1, Ps0),
payout_methods = pm_utils:select_defined(Pm1, Pm0),
cash_limit = pm_utils:select_defined(Cash1, Cash0),
fees = pm_utils:select_defined(Fee1, Fee0)
payout_methods = pm_utils:select_defined(Pm1, Pm0),
cash_limit = pm_utils:select_defined(Cash1, Cash0),
fees = pm_utils:select_defined(Fee1, Fee0)
};
merge_payouts_terms(Terms0, Terms1) ->
pm_utils:select_defined(Terms1, Terms0).
@ -832,7 +792,6 @@ find_shop_account(ID, [{_, #domain_Shop{account = Account}} | Rest]) ->
%% TODO there should be more concise way to express these assertions in terms of preconditions
-spec assert_party_objects_valid(timestamp(), revision(), party()) -> ok | no_return().
assert_party_objects_valid(Timestamp, Revision, Party) ->
_ = assert_contracts_valid(Timestamp, Revision, Party),
_ = assert_shops_valid(Timestamp, Revision, Party),
@ -925,15 +884,19 @@ assert_shop_payout_tool_valid(#domain_Shop{id = ID, payout_tool_id = PayoutToolI
ok;
#domain_PayoutTool{} ->
% currency missmatch
pm_claim:raise_invalid_changeset(?invalid_shop(
ID,
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
));
pm_claim:raise_invalid_changeset(
?invalid_shop(
ID,
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
)
);
undefined ->
pm_claim:raise_invalid_changeset(?invalid_shop(
ID,
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
))
pm_claim:raise_invalid_changeset(
?invalid_shop(
ID,
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
)
)
end.
assert_wallet_valid(#domain_Wallet{contract = ContractID} = Wallet, Timestamp, Revision, Party) ->
@ -992,8 +955,9 @@ assert_currency_valid(
assert_currency_valid(Prefix, ContractID, CurrencyRef, Selector, Terms, Revision) ->
Currencies = pm_selector:reduce_to_value(Selector, #{}, Revision),
_ = ordsets:is_element(CurrencyRef, Currencies) orelse
raise_contract_terms_violated(Prefix, ContractID, Terms).
_ =
ordsets:is_element(CurrencyRef, Currencies) orelse
raise_contract_terms_violated(Prefix, ContractID, Terms).
assert_category_valid(
Prefix,
@ -1005,20 +969,19 @@ assert_category_valid(
Revision
) ->
Categories = pm_selector:reduce_to_value(CategorySelector, #{}, Revision),
_ = ordsets:is_element(CategoryRef, Categories) orelse
raise_contract_terms_violated(
Prefix,
ContractID,
#domain_TermSet{payments = #domain_PaymentsServiceTerms{categories = CategorySelector}}
).
_ =
ordsets:is_element(CategoryRef, Categories) orelse
raise_contract_terms_violated(
Prefix,
ContractID,
#domain_TermSet{payments = #domain_PaymentsServiceTerms{categories = CategorySelector}}
).
-spec raise_contract_terms_violated(
{shop, shop_id()} | {wallet, wallet_id()},
contract_id(),
dmsl_domain_thrift:'TermSet'()
) ->
no_return().
) -> no_return().
raise_contract_terms_violated(Prefix, ContractID, Terms) ->
Payload = {
contract_terms_violated,
@ -1031,7 +994,6 @@ raise_contract_terms_violated(Prefix, ContractID, Terms) ->
%% ugly spec, just to cool down dialyzer
-spec raise_contract_terms_violated(term(), term()) -> no_return().
raise_contract_terms_violated({shop, ID}, Payload) ->
pm_claim:raise_invalid_changeset(?invalid_shop(ID, Payload));
raise_contract_terms_violated({wallet, ID}, Payload) ->

View File

@ -13,7 +13,6 @@
-type party_contractor() :: dmsl_domain_thrift:'PartyContractor'().
-spec create(id(), contractor()) -> party_contractor().
create(ID, Contractor) ->
#domain_PartyContractor{
id = ID,

View File

@ -10,57 +10,47 @@
%%
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
term()| no_return().
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
handle_function(Func, Args, Opts) ->
scoper:scope(partymgmt,
scoper:scope(
partymgmt,
fun() -> handle_function_(Func, Args, Opts) end
).
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
term()| no_return().
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
%% Party
handle_function_('Create', {UserInfo, PartyID, PartyParams}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:start(PartyID, PartyParams);
handle_function_('Checkout', {UserInfo, PartyID, RevisionParam}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
checkout_party(PartyID, RevisionParam, #payproc_InvalidPartyRevision{});
handle_function_('Get', {UserInfo, PartyID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_party(PartyID);
handle_function_('GetRevision', {UserInfo, PartyID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_last_revision(PartyID);
handle_function_('GetStatus', {UserInfo, PartyID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_status(PartyID);
handle_function_(Fun, Args, _Opts) when
Fun =:= 'Block' orelse
Fun =:= 'Unblock' orelse
Fun =:= 'Suspend' orelse
Fun =:= 'Activate'
Fun =:= 'Unblock' orelse
Fun =:= 'Suspend' orelse
Fun =:= 'Activate'
->
UserInfo = erlang:element(1, Args),
PartyID = erlang:element(2, Args),
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Contract
handle_function_('GetContract', {UserInfo, PartyID, ContractID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
ensure_contract(pm_party:get_contract(ContractID, Party));
handle_function_('ComputeContractTerms', Args, _Opts) ->
{UserInfo, PartyID, ContractID, Timestamp, PartyRevisionParams, DomainRevision, Varset} = Args,
ok = set_meta_and_check_access(UserInfo, PartyID),
@ -73,14 +63,12 @@ handle_function_('ComputeContractTerms', Args, _Opts) ->
VS1 = prepare_varset(PartyID, Varset, VS0),
Terms = pm_party:get_terms(Contract, Timestamp, DomainRevision),
pm_party:reduce_terms(Terms, VS1, DomainRevision);
%% Shop
handle_function_('GetShop', {UserInfo, PartyID, ID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
ensure_shop(pm_party:get_shop(ID, Party));
handle_function_('ComputeShopTerms', {UserInfo, PartyID, ShopID, Timestamp, PartyRevision}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = checkout_party(PartyID, pm_maybe:get_defined(PartyRevision, {timestamp, Timestamp})),
@ -89,24 +77,22 @@ handle_function_('ComputeShopTerms', {UserInfo, PartyID, ShopID, Timestamp, Part
Revision = pm_domain:head(),
VS = #{
party_id => PartyID,
shop_id => ShopID,
shop_id => ShopID,
category => Shop#domain_Shop.category,
currency => (Shop#domain_Shop.account)#domain_ShopAccount.currency,
identification_level => get_identification_level(Contract, Party)
},
pm_party:reduce_terms(pm_party:get_terms(Contract, Timestamp, Revision), VS, Revision);
handle_function_(Fun, Args, _Opts) when
Fun =:= 'BlockShop' orelse
Fun =:= 'UnblockShop' orelse
Fun =:= 'SuspendShop' orelse
Fun =:= 'ActivateShop'
Fun =:= 'UnblockShop' orelse
Fun =:= 'SuspendShop' orelse
Fun =:= 'ActivateShop'
->
UserInfo = erlang:element(1, Args),
PartyID = erlang:element(2, Args),
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Wallet
handle_function_('ComputeWalletTermsNew', {UserInfo, PartyID, ContractID, Timestamp, Varset}, _Opts) ->
@ -119,48 +105,41 @@ handle_function_('ComputeWalletTermsNew', {UserInfo, PartyID, ContractID, Timest
},
VS1 = prepare_varset(PartyID, Varset, VS0),
pm_party:reduce_terms(pm_party:get_terms(Contract, Timestamp, Revision), VS1, Revision);
%% Claim
handle_function_('GetClaim', {UserInfo, PartyID, ID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_claim(ID, PartyID);
handle_function_('GetClaims', {UserInfo, PartyID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_claims(PartyID);
handle_function_(Fun, Args, _Opts) when
Fun =:= 'CreateClaim' orelse
Fun =:= 'AcceptClaim' orelse
Fun =:= 'UpdateClaim' orelse
Fun =:= 'DenyClaim' orelse
Fun =:= 'RevokeClaim'
Fun =:= 'AcceptClaim' orelse
Fun =:= 'UpdateClaim' orelse
Fun =:= 'DenyClaim' orelse
Fun =:= 'RevokeClaim'
->
UserInfo = erlang:element(1, Args),
PartyID = erlang:element(2, Args),
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Event
handle_function_('GetEvents', {UserInfo, PartyID, Range}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
#payproc_EventRange{'after' = AfterID, limit = Limit} = Range,
pm_party_machine:get_public_history(PartyID, AfterID, Limit);
%% ShopAccount
handle_function_('GetAccountState', {UserInfo, PartyID, AccountID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
pm_party:get_account_state(AccountID, Party);
handle_function_('GetShopAccount', {UserInfo, PartyID, ShopID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
Party = pm_party_machine:get_party(PartyID),
pm_party:get_shop_account(ShopID, Party);
%% Providers
handle_function_('ComputeProvider', Args, _Opts) ->
@ -169,7 +148,6 @@ handle_function_('ComputeProvider', Args, _Opts) ->
Provider = get_provider(ProviderRef, DomainRevision),
VS = prepare_varset(Varset),
pm_provider:reduce_provider(Provider, VS, DomainRevision);
handle_function_('ComputeProviderTerminalTerms', Args, _Opts) ->
{UserInfo, ProviderRef, TerminalRef, DomainRevision, Varset} = Args,
ok = assume_user_identity(UserInfo),
@ -177,7 +155,6 @@ handle_function_('ComputeProviderTerminalTerms', Args, _Opts) ->
Terminal = get_terminal(TerminalRef, DomainRevision),
VS = prepare_varset(Varset),
pm_provider:reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision);
%% Globals
handle_function_('ComputeGlobals', Args, _Opts) ->
@ -186,7 +163,6 @@ handle_function_('ComputeGlobals', Args, _Opts) ->
Globals = get_globals(GlobalsRef, DomainRevision),
VS = prepare_varset(Varset),
pm_globals:reduce_globals(Globals, VS, DomainRevision);
%% RuleSets
handle_function_('ComputePaymentRoutingRuleset', Args, _Opts) ->
@ -195,26 +171,22 @@ handle_function_('ComputePaymentRoutingRuleset', Args, _Opts) ->
RuleSet = get_payment_routing_ruleset(RuleSetRef, DomainRevision),
VS = prepare_varset(Varset),
pm_ruleset:reduce_payment_routing_ruleset(RuleSet, VS, DomainRevision);
%% PartyMeta
handle_function_('GetMeta', {UserInfo, PartyID}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_meta(PartyID);
handle_function_('GetMetaData', {UserInfo, PartyID, NS}, _Opts) ->
ok = set_meta_and_check_access(UserInfo, PartyID),
pm_party_machine:get_metadata(NS, PartyID);
handle_function_(Fun, Args, _Opts) when
Fun =:= 'SetMetaData' orelse
Fun =:= 'RemoveMetaData'
Fun =:= 'RemoveMetaData'
->
UserInfo = erlang:element(1, Args),
PartyID = erlang:element(2, Args),
ok = set_meta_and_check_access(UserInfo, PartyID),
call(PartyID, Fun, Args);
%% Payment Institutions
handle_function_(
@ -229,7 +201,6 @@ handle_function_(
ContractTemplate = get_default_contract_template(PaymentInstitution, VS, Revision),
Terms = pm_party:get_terms(ContractTemplate, pm_datetime:format_now(), Revision),
pm_party:reduce_terms(Terms, VS, Revision);
%% Payouts adhocs
handle_function_(
@ -246,10 +217,10 @@ handle_function_(
PayoutTool = get_payout_tool(Shop, Contract, PayoutParams),
VS = #{
party_id => PartyID,
shop_id => ShopID,
shop_id => ShopID,
category => Shop#domain_Shop.category,
currency => Currency,
cost => Amount,
cost => Amount,
payout_method => pm_payout_tool:get_method(PayoutTool)
},
Revision = pm_domain:head(),
@ -267,9 +238,7 @@ call(PartyID, FunctionName, Args) ->
%%
get_payout_tool(_Shop, Contract, #payproc_PayoutParams{payout_tool_id = ToolID})
when ToolID =/= undefined
->
get_payout_tool(_Shop, Contract, #payproc_PayoutParams{payout_tool_id = ToolID}) when ToolID =/= undefined ->
case pm_contract:get_payout_tool(ToolID, Contract) of
undefined ->
throw(#payproc_PayoutToolNotFound{});
@ -286,9 +255,7 @@ set_meta_and_check_access(UserInfo, PartyID) ->
-spec assert_party_accessible(
dmsl_domain_thrift:'PartyID'()
) ->
ok | no_return().
) -> ok | no_return().
assert_party_accessible(PartyID) ->
UserIdentity = pm_woody_handler_utils:get_user_identity(),
case pm_access_control:check_user(UserIdentity, PartyID) of
@ -393,11 +360,11 @@ collect_payout_account_map(
PaymentInstitution = get_payment_institution(PaymentInstitutionRef, Revision),
SystemAccount = pm_payment_institution:get_system_account(Currency, VS, Revision, PaymentInstitution),
#{
{merchant , settlement} => ShopAccount#domain_ShopAccount.settlement,
{merchant , guarantee } => ShopAccount#domain_ShopAccount.guarantee,
{merchant , payout } => ShopAccount#domain_ShopAccount.payout,
{system , settlement} => SystemAccount#domain_SystemAccount.settlement,
{system , subagent } => SystemAccount#domain_SystemAccount.subagent
{merchant, settlement} => ShopAccount#domain_ShopAccount.settlement,
{merchant, guarantee} => ShopAccount#domain_ShopAccount.guarantee,
{merchant, payout} => ShopAccount#domain_ShopAccount.payout,
{system, settlement} => SystemAccount#domain_SystemAccount.settlement,
{system, subagent} => SystemAccount#domain_SystemAccount.subagent
}.
prepare_varset(#payproc_Varset{} = V) ->

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,6 @@
-export([unmarshal/1]).
-spec marshal(term()) -> pm_msgpack_marshalling:msgpack_value().
marshal(undefined) ->
undefined;
marshal(Boolean) when is_boolean(Boolean) ->
@ -31,12 +30,11 @@ marshal(V) when is_integer(V); is_float(V); is_binary(V) ->
V.
-spec unmarshal(pm_msgpack_marshalling:msgpack_value()) -> term().
unmarshal([<<":atom:">>, Atom]) ->
binary_to_existing_atom(Atom, utf8);
unmarshal([<<":tuple:">>, Tuple]) ->
list_to_tuple(lists:map(fun unmarshal/1, Tuple));
unmarshal([<<":list:">>, List])->
unmarshal([<<":list:">>, List]) ->
lists:map(fun unmarshal/1, List);
unmarshal(Map) when is_map(Map) ->
maps:fold(fun(K, V, Acc) -> maps:put(unmarshal(K), unmarshal(V), Acc) end, #{}, Map);
@ -44,5 +42,5 @@ unmarshal(undefined) ->
undefined;
unmarshal({bin, Binary}) when is_binary(Binary) ->
{bin, Binary};
unmarshal(V) when is_boolean(V); is_integer(V); is_float(V); is_binary(V)->
unmarshal(V) when is_boolean(V); is_integer(V); is_float(V); is_binary(V) ->
V.

View File

@ -7,19 +7,19 @@
-export([get_system_account/4]).
-export([get_realm/1]).
-export([is_live/1]).
%%
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
-type varset() :: pm_selector:varset().
-type revision() :: pm_domain:revision().
-type payment_inst() :: dmsl_domain_thrift:'PaymentInstitution'().
-type realm() :: dmsl_domain_thrift:'PaymentInstitutionRealm'().
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
-type varset() :: pm_selector:varset().
-type revision() :: pm_domain:revision().
-type payment_inst() :: dmsl_domain_thrift:'PaymentInstitution'().
-type realm() :: dmsl_domain_thrift:'PaymentInstitutionRealm'().
%%
-spec get_system_account(currency(), varset(), revision(), payment_inst()) ->
dmsl_domain_thrift:'SystemAccount'() | no_return().
get_system_account(Currency, VS, Revision, #domain_PaymentInstitution{system_account_set = S}) ->
SystemAccountSetRef = pm_selector:reduce_to_value(S, VS, Revision),
SystemAccountSet = pm_domain:get(Revision, {system_account_set, SystemAccountSetRef}),
@ -31,11 +31,9 @@ get_system_account(Currency, VS, Revision, #domain_PaymentInstitution{system_acc
end.
-spec get_realm(payment_inst()) -> realm().
get_realm(#domain_PaymentInstitution{realm = Realm}) ->
Realm.
-spec is_live(payment_inst()) -> boolean().
is_live(#domain_PaymentInstitution{realm = Realm}) ->
Realm =:= live.

View File

@ -1,6 +1,7 @@
%%% Payment tools
-module(pm_payment_tool).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
%%
@ -15,7 +16,6 @@
-type condition() :: dmsl_domain_thrift:'PaymentToolCondition'().
-spec create_from_method(method()) -> t().
%% TODO empty strings - ugly hack for dialyzar
create_from_method(#domain_PaymentMethodRef{id = {empty_cvv_bank_card_deprecated, PaymentSystem}}) ->
{bank_card, #domain_BankCard{
@ -32,11 +32,14 @@ create_from_method(#domain_PaymentMethodRef{id = {bank_card_deprecated, PaymentS
bin = <<"">>,
last_digits = <<"">>
}};
create_from_method(#domain_PaymentMethodRef{id = {tokenized_bank_card_deprecated, #domain_TokenizedBankCard{
payment_system = PaymentSystem,
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}}}) ->
create_from_method(#domain_PaymentMethodRef{
id =
{tokenized_bank_card_deprecated, #domain_TokenizedBankCard{
payment_system = PaymentSystem,
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}}
}) ->
{bank_card, #domain_BankCard{
payment_system = PaymentSystem,
token = <<"">>,
@ -45,12 +48,15 @@ create_from_method(#domain_PaymentMethodRef{id = {tokenized_bank_card_deprecated
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}};
create_from_method(#domain_PaymentMethodRef{id = {bank_card, #domain_BankCardPaymentMethod{
payment_system = PaymentSystem,
is_cvv_empty = IsCVVEmpty,
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}}}) ->
create_from_method(#domain_PaymentMethodRef{
id =
{bank_card, #domain_BankCardPaymentMethod{
payment_system = PaymentSystem,
is_cvv_empty = IsCVVEmpty,
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}}
}) ->
{bank_card, #domain_BankCard{
payment_system = PaymentSystem,
token = <<"">>,
@ -73,7 +79,6 @@ create_from_method(#domain_PaymentMethodRef{id = {crypto_currency, CC}}) ->
%%
-spec test_condition(condition(), t(), pm_domain:revision()) -> boolean() | undefined.
test_condition({bank_card, C}, {bank_card, V = #domain_BankCard{}}, Rev) ->
test_bank_card_condition(C, V, Rev);
test_condition({payment_terminal, C}, {payment_terminal, V = #domain_PaymentTerminal{}}, Rev) ->
@ -101,7 +106,6 @@ test_bank_card_condition_def(
true;
test_bank_card_condition_def({payment_system_is, _Ps}, #domain_BankCard{}, _Rev) ->
false;
test_bank_card_condition_def({payment_system, PaymentSystem}, V, Rev) ->
test_payment_system_condition(PaymentSystem, V, Rev);
test_bank_card_condition_def({issuer_country_is, IssuerCountry}, V, Rev) ->
@ -154,7 +158,8 @@ test_issuer_bank_condition(BankRef, #domain_BankCard{bank_name = BankName, bin =
test_bank_card_patterns(Patterns, BankName);
% TODO т.к. BinBase не обладает полным объемом данных, при их отсутствии мы возвращаемся к проверкам по бинам.
% B будущем стоит избавиться от этого.
{_, _} -> test_bank_card_bins(BIN, BINs)
{_, _} ->
test_bank_card_bins(BIN, BINs)
end.
test_bank_card_category_condition(CategoryRef, #domain_BankCard{category = Category}, Rev) ->

View File

@ -1,6 +1,7 @@
%%% Payout tools
-module(pm_payout_tool).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
%%
@ -9,17 +10,15 @@
-export([get_method/1]).
%%
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
-type payout_tool_params() :: dmsl_payment_processing_thrift:'PayoutToolParams'().
-type method() :: dmsl_domain_thrift:'PayoutMethodRef'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
-type payout_tool_params() :: dmsl_payment_processing_thrift:'PayoutToolParams'().
-type method() :: dmsl_domain_thrift:'PayoutMethodRef'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
%%
-spec create(payout_tool_id(), payout_tool_params(), timestamp()) ->
payout_tool().
-spec create(payout_tool_id(), payout_tool_params(), timestamp()) -> payout_tool().
create(
ID,
#payproc_PayoutToolParams{
@ -36,7 +35,6 @@ create(
}.
-spec get_method(payout_tool()) -> method().
get_method(#domain_PayoutTool{payout_tool_info = {russian_bank_account, _}}) ->
#domain_PayoutMethodRef{id = russian_bank_account};
get_method(#domain_PayoutTool{payout_tool_info = {international_bank_account, _}}) ->

View File

@ -6,23 +6,20 @@
-export([reduce_provider/3]).
-export([reduce_provider_terminal_terms/4]).
-type provider() :: dmsl_domain_thrift:'Provider'().
-type terminal() :: dmsl_domain_thrift:'Terminal'().
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
-type varset() :: pm_selector:varset().
-type domain_revision() :: pm_domain:revision().
-type provider() :: dmsl_domain_thrift:'Provider'().
-type terminal() :: dmsl_domain_thrift:'Terminal'().
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
-type varset() :: pm_selector:varset().
-type domain_revision() :: pm_domain:revision().
-spec reduce_provider(provider(), varset(), domain_revision()) -> provider().
reduce_provider(Provider, VS, DomainRevision) ->
Provider#domain_Provider{
terminal = pm_selector:reduce(Provider#domain_Provider.terminal, VS, DomainRevision),
terms = reduce_provision_term_set(Provider#domain_Provider.terms, VS, DomainRevision)
}.
-spec reduce_provider_terminal_terms(provider(), terminal(), varset(), domain_revision()) ->
provision_terms().
-spec reduce_provider_terminal_terms(provider(), terminal(), varset(), domain_revision()) -> provision_terms().
reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision) ->
ProviderTerms = Provider#domain_Provider.terms,
TerminalTerms = Terminal#domain_Terminal.terms,
@ -74,7 +71,9 @@ reduce_payment_terms(PaymentTerms, VS, DomainRevision) ->
currencies = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.currencies, VS, DomainRevision),
categories = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.categories, VS, DomainRevision),
payment_methods = reduce_if_defined(
PaymentTerms#domain_PaymentsProvisionTerms.payment_methods, VS, DomainRevision
PaymentTerms#domain_PaymentsProvisionTerms.payment_methods,
VS,
DomainRevision
),
cash_limit = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.cash_limit, VS, DomainRevision),
cash_flow = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.cash_flow, VS, DomainRevision),
@ -107,7 +106,9 @@ reduce_partial_captures_terms(#domain_PartialCaptureProvisionTerms{} = Terms, _V
reduce_payment_refund_terms(PaymentRefundTerms, VS, DomainRevision) ->
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms{
cash_flow = reduce_if_defined(
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms.cash_flow, VS, DomainRevision
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms.cash_flow,
VS,
DomainRevision
),
partial_refunds = pm_maybe:apply(
fun(X) -> reduce_partial_refunds_terms(X, VS, DomainRevision) end,
@ -118,34 +119,46 @@ reduce_payment_refund_terms(PaymentRefundTerms, VS, DomainRevision) ->
reduce_partial_refunds_terms(PartialRefundTerms, VS, DomainRevision) ->
PartialRefundTerms#domain_PartialRefundsProvisionTerms{
cash_limit = reduce_if_defined(
PartialRefundTerms#domain_PartialRefundsProvisionTerms.cash_limit, VS, DomainRevision
PartialRefundTerms#domain_PartialRefundsProvisionTerms.cash_limit,
VS,
DomainRevision
)
}.
reduce_payment_chargeback_terms(PaymentChargebackTerms, VS, DomainRevision) ->
PaymentChargebackTerms#domain_PaymentChargebackProvisionTerms{
cash_flow = reduce_if_defined(
PaymentChargebackTerms#domain_PaymentChargebackProvisionTerms.cash_flow, VS, DomainRevision
PaymentChargebackTerms#domain_PaymentChargebackProvisionTerms.cash_flow,
VS,
DomainRevision
)
}.
reduce_recurrent_paytool_terms(RecurrentPaytoolTerms, VS, DomainRevision) ->
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms{
cash_value = reduce_if_defined(
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.cash_value, VS, DomainRevision
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.cash_value,
VS,
DomainRevision
),
categories = reduce_if_defined(
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.categories, VS, DomainRevision
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.categories,
VS,
DomainRevision
),
payment_methods = reduce_if_defined(
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.payment_methods, VS, DomainRevision
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.payment_methods,
VS,
DomainRevision
)
}.
reduce_wallet_provision(WalletProvisionTerms, VS, DomainRevision) ->
#domain_WalletProvisionTerms{
turnover_limit = reduce_if_defined(
WalletProvisionTerms#domain_WalletProvisionTerms.turnover_limit, VS, DomainRevision
WalletProvisionTerms#domain_WalletProvisionTerms.turnover_limit,
VS,
DomainRevision
),
withdrawals = pm_maybe:apply(
fun(X) -> reduce_withdrawal_terms(X, VS, DomainRevision) end,
@ -159,55 +172,56 @@ reduce_wallet_provision(WalletProvisionTerms, VS, DomainRevision) ->
merge_provision_term_sets(
#domain_ProvisionTermSet{
payments = PPayments,
payments = PPayments,
recurrent_paytools = PRecurrents,
wallet = PWallet
wallet = PWallet
},
#domain_ProvisionTermSet{
payments = TPayments,
recurrent_paytools = _TRecurrents, % TODO: Allow to define recurrent terms in terminal
wallet = TWallet
payments = TPayments,
% TODO: Allow to define recurrent terms in terminal
recurrent_paytools = _TRecurrents,
wallet = TWallet
}
) ->
#domain_ProvisionTermSet{
payments = merge_payment_terms(PPayments, TPayments),
payments = merge_payment_terms(PPayments, TPayments),
recurrent_paytools = PRecurrents,
wallet = merge_wallet_terms(PWallet, TWallet)
wallet = merge_wallet_terms(PWallet, TWallet)
};
merge_provision_term_sets(ProviderTerms, TerminalTerms) ->
pm_utils:select_defined(TerminalTerms, ProviderTerms).
merge_payment_terms(
#domain_PaymentsProvisionTerms{
currencies = PCurrencies,
categories = PCategories,
currencies = PCurrencies,
categories = PCategories,
payment_methods = PPaymentMethods,
cash_limit = PCashLimit,
cash_flow = PCashflow,
holds = PHolds,
refunds = PRefunds,
chargebacks = PChargebacks
cash_limit = PCashLimit,
cash_flow = PCashflow,
holds = PHolds,
refunds = PRefunds,
chargebacks = PChargebacks
},
#domain_PaymentsProvisionTerms{
currencies = TCurrencies,
categories = TCategories,
currencies = TCurrencies,
categories = TCategories,
payment_methods = TPaymentMethods,
cash_limit = TCashLimit,
cash_flow = TCashflow,
holds = THolds,
refunds = TRefunds,
chargebacks = TChargebacks
cash_limit = TCashLimit,
cash_flow = TCashflow,
holds = THolds,
refunds = TRefunds,
chargebacks = TChargebacks
}
) ->
#domain_PaymentsProvisionTerms{
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
categories = pm_utils:select_defined(TCategories, PCategories),
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
categories = pm_utils:select_defined(TCategories, PCategories),
payment_methods = pm_utils:select_defined(TPaymentMethods, PPaymentMethods),
cash_limit = pm_utils:select_defined(TCashLimit, PCashLimit),
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
holds = pm_utils:select_defined(THolds, PHolds),
refunds = pm_utils:select_defined(TRefunds, PRefunds),
chargebacks = pm_utils:select_defined(TChargebacks, PChargebacks)
cash_limit = pm_utils:select_defined(TCashLimit, PCashLimit),
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
holds = pm_utils:select_defined(THolds, PHolds),
refunds = pm_utils:select_defined(TRefunds, PRefunds),
chargebacks = pm_utils:select_defined(TChargebacks, PChargebacks)
};
merge_payment_terms(ProviderTerms, TerminalTerms) ->
pm_utils:select_defined(TerminalTerms, ProviderTerms).
@ -215,65 +229,65 @@ merge_payment_terms(ProviderTerms, TerminalTerms) ->
merge_wallet_terms(
#domain_WalletProvisionTerms{
turnover_limit = PLimit,
withdrawals = PWithdrawal,
p2p = PP2P
withdrawals = PWithdrawal,
p2p = PP2P
},
#domain_WalletProvisionTerms{
turnover_limit = TLimit,
withdrawals = TWithdrawal,
p2p = TP2P
withdrawals = TWithdrawal,
p2p = TP2P
}
) ->
#domain_WalletProvisionTerms{
turnover_limit = pm_utils:select_defined(TLimit, PLimit),
withdrawals = merge_withdrawal_terms(PWithdrawal, TWithdrawal),
p2p = merge_p2p_terms(PP2P, TP2P)
withdrawals = merge_withdrawal_terms(PWithdrawal, TWithdrawal),
p2p = merge_p2p_terms(PP2P, TP2P)
};
merge_wallet_terms(ProviderTerms, TerminalTerms) ->
pm_utils:select_defined(TerminalTerms, ProviderTerms).
merge_withdrawal_terms(
#domain_WithdrawalProvisionTerms{
currencies = PCurrencies,
currencies = PCurrencies,
payout_methods = PMethods,
cash_limit = PLimit,
cash_flow = PCashflow
cash_limit = PLimit,
cash_flow = PCashflow
},
#domain_WithdrawalProvisionTerms{
currencies = TCurrencies,
currencies = TCurrencies,
payout_methods = TMethods,
cash_limit = TLimit,
cash_flow = TCashflow
cash_limit = TLimit,
cash_flow = TCashflow
}
) ->
#domain_WithdrawalProvisionTerms{
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
payout_methods = pm_utils:select_defined(TMethods, PMethods),
cash_limit = pm_utils:select_defined(TLimit, PLimit),
cash_flow = pm_utils:select_defined(TCashflow, PCashflow)
cash_limit = pm_utils:select_defined(TLimit, PLimit),
cash_flow = pm_utils:select_defined(TCashflow, PCashflow)
};
merge_withdrawal_terms(ProviderTerms, TerminalTerms) ->
pm_utils:select_defined(TerminalTerms, ProviderTerms).
merge_p2p_terms(
#domain_P2PProvisionTerms{
currencies = PCurrencies,
cash_limit = PLimit,
cash_flow = PCashflow,
fees = PFees
currencies = PCurrencies,
cash_limit = PLimit,
cash_flow = PCashflow,
fees = PFees
},
#domain_P2PProvisionTerms{
currencies = TCurrencies,
cash_limit = TLimit,
cash_flow = TCashflow,
fees = TFees
currencies = TCurrencies,
cash_limit = TLimit,
cash_flow = TCashflow,
fees = TFees
}
) ->
#domain_P2PProvisionTerms{
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
cash_limit = pm_utils:select_defined(TLimit, PLimit),
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
fees = pm_utils:select_defined(TFees, PFees)
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
cash_limit = pm_utils:select_defined(TLimit, PLimit),
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
fees = pm_utils:select_defined(TFees, PFees)
};
merge_p2p_terms(ProviderTerms, TerminalTerms) ->
pm_utils:select_defined(TerminalTerms, ProviderTerms).

View File

@ -9,12 +9,11 @@
-define(const(Bool), {constant, Bool}).
-type payment_routing_ruleset() :: dmsl_domain_thrift:'PaymentRoutingRuleset'().
-type varset() :: pm_selector:varset().
-type domain_revision() :: pm_domain:revision().
-type varset() :: pm_selector:varset().
-type domain_revision() :: pm_domain:revision().
-spec reduce_payment_routing_ruleset(payment_routing_ruleset(), varset(), domain_revision()) ->
payment_routing_ruleset().
reduce_payment_routing_ruleset(RuleSet, VS, DomainRevision) ->
RuleSet#domain_PaymentRoutingRuleset{
decisions = reduce_payment_routing_decisions(RuleSet#domain_PaymentRoutingRuleset.decisions, VS, DomainRevision)
@ -47,26 +46,29 @@ reduce_payment_routing_delegates([D | Delegates], VS, Rev) ->
end.
reduce_payment_routing_candidates(Candidates, VS, Rev) ->
{candidates, lists:foldr(
fun(C, AccIn) ->
Predicate = C#domain_PaymentRoutingCandidate.allowed,
case pm_selector:reduce_predicate(Predicate, VS, Rev) of
?const(false) ->
AccIn;
?const(true) = ReducedPredicate ->
ReducedCandidate = C#domain_PaymentRoutingCandidate{
allowed = ReducedPredicate
},
[ReducedCandidate | AccIn];
_ ->
logger:warning(
"Routing rule misconfiguration, can't reduce decision. Predicate: ~p~nVarset:~n~p",
[Predicate, VS]
),
[C | AccIn]
end
end,
[], Candidates)}.
{candidates,
lists:foldr(
fun(C, AccIn) ->
Predicate = C#domain_PaymentRoutingCandidate.allowed,
case pm_selector:reduce_predicate(Predicate, VS, Rev) of
?const(false) ->
AccIn;
?const(true) = ReducedPredicate ->
ReducedCandidate = C#domain_PaymentRoutingCandidate{
allowed = ReducedPredicate
},
[ReducedCandidate | AccIn];
_ ->
logger:warning(
"Routing rule misconfiguration, can't reduce decision. Predicate: ~p~nVarset:~n~p",
[Predicate, VS]
),
[C | AccIn]
end
end,
[],
Candidates
)}.
get_payment_routing_ruleset(RuleSetRef, DomainRevision) ->
pm_domain:get(DomainRevision, {payment_routing_rules, RuleSetRef}).

View File

@ -8,6 +8,7 @@
%%% - Domain revision is out of place. An `Opts`, anyone?
-module(pm_selector).
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
%%
@ -30,21 +31,22 @@
dmsl_domain_thrift:'FeeSelector'().
-type value() ::
_. %% FIXME
%% FIXME
_.
-type varset() :: #{
category => dmsl_domain_thrift:'CategoryRef'(),
currency => dmsl_domain_thrift:'CurrencyRef'(),
cost => dmsl_domain_thrift:'Cash'(),
payment_tool => dmsl_domain_thrift:'PaymentTool'(),
party_id => dmsl_domain_thrift:'PartyID'(),
shop_id => dmsl_domain_thrift:'ShopID'(),
risk_score => dmsl_domain_thrift:'RiskScore'(),
flow => instant | {hold, dmsl_domain_thrift:'HoldLifetime'()},
payout_method => dmsl_domain_thrift:'PayoutMethodRef'(),
wallet_id => dmsl_domain_thrift:'WalletID'(),
category => dmsl_domain_thrift:'CategoryRef'(),
currency => dmsl_domain_thrift:'CurrencyRef'(),
cost => dmsl_domain_thrift:'Cash'(),
payment_tool => dmsl_domain_thrift:'PaymentTool'(),
party_id => dmsl_domain_thrift:'PartyID'(),
shop_id => dmsl_domain_thrift:'ShopID'(),
risk_score => dmsl_domain_thrift:'RiskScore'(),
flow => instant | {hold, dmsl_domain_thrift:'HoldLifetime'()},
payout_method => dmsl_domain_thrift:'PayoutMethodRef'(),
wallet_id => dmsl_domain_thrift:'WalletID'(),
identification_level => dmsl_domain_thrift:'ContractorIdentificationLevel'(),
p2p_tool => dmsl_domain_thrift:'P2PTool'()
p2p_tool => dmsl_domain_thrift:'P2PTool'()
}.
-type predicate() :: dmsl_domain_thrift:'Predicate'().
@ -61,7 +63,6 @@
%%
-spec reduce_to_value(t(), varset(), pm_domain:revision()) -> value() | no_return().
reduce_to_value(Selector, VS, Revision) ->
case reduce(Selector, VS, Revision) of
{value, Value} ->
@ -70,9 +71,7 @@ reduce_to_value(Selector, VS, Revision) ->
error({misconfiguration, {'Can\'t reduce selector to value', Selector, VS, Revision}})
end.
-spec reduce(t(), varset(), pm_domain:revision()) ->
t().
-spec reduce(t(), varset(), pm_domain:revision()) -> t().
reduce({value, _} = V, _, _) ->
V;
reduce({decisions, Ps}, VS, Rev) ->
@ -100,11 +99,10 @@ reduce_decisions([], _, _) ->
-spec reduce_predicate(predicate(), varset(), pm_domain:revision()) ->
predicate() |
{criterion, criterion()}. % for a partially reduced criterion
% for a partially reduced criterion
{criterion, criterion()}.
reduce_predicate(?const(B), _, _) ->
?const(B);
reduce_predicate({condition, C0}, VS, Rev) ->
case reduce_condition(C0, VS, Rev) of
?const(B) ->
@ -112,7 +110,6 @@ reduce_predicate({condition, C0}, VS, Rev) ->
C1 ->
{condition, C1}
end;
reduce_predicate({is_not, P0}, VS, Rev) ->
case reduce_predicate(P0, VS, Rev) of
?const(B) ->
@ -120,13 +117,10 @@ reduce_predicate({is_not, P0}, VS, Rev) ->
P1 ->
{is_not, P1}
end;
reduce_predicate({all_of, Ps}, VS, Rev) ->
reduce_combination(all_of, false, Ps, VS, Rev, []);
reduce_predicate({any_of, Ps}, VS, Rev) ->
reduce_combination(any_of, true, Ps, VS, Rev, []);
reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) ->
Criterion = pm_domain:get(Rev, {criterion, CriterionRef}),
case reduce_predicate(Criterion#domain_Criterion.predicate, VS, Rev) of
@ -165,6 +159,7 @@ reduce_condition(C, VS, Rev) ->
-spec test() -> _.
-spec p2p_provider_test() -> _.
p2p_provider_test() ->
BankCardCondition = #domain_BankCardCondition{definition = {issuer_country_is, rus}},
BankCardCondition2 = #domain_BankCardCondition{definition = {issuer_country_is, usa}},
@ -176,33 +171,34 @@ p2p_provider_test() ->
sender_is = {payment_tool, {bank_card, BankCardCondition}},
receiver_is = {payment_tool, {bank_card, BankCardCondition2}}
},
P2PProviderSelector = {decisions, [
#domain_P2PProviderDecision{
if_ = {condition, {p2p_tool, P2PCondition1}},
then_ = {value, [#domain_ProviderRef{id = 1}]}
},
#domain_P2PProviderDecision{
if_ = {condition, {p2p_tool, P2PCondition2}},
then_ = {value, [#domain_ProviderRef{id = 2}]}
}
]},
P2PProviderSelector =
{decisions, [
#domain_P2PProviderDecision{
if_ = {condition, {p2p_tool, P2PCondition1}},
then_ = {value, [#domain_ProviderRef{id = 1}]}
},
#domain_P2PProviderDecision{
if_ = {condition, {p2p_tool, P2PCondition2}},
then_ = {value, [#domain_ProviderRef{id = 2}]}
}
]},
BankCard1 = #domain_BankCard{
token = <<"TOKEN1">>,
token = <<"TOKEN1">>,
payment_system = mastercard,
bin = <<"888888">>,
last_digits = <<"888">>,
bin = <<"888888">>,
last_digits = <<"888">>,
issuer_country = rus
},
BankCard2 = #domain_BankCard{
token = <<"TOKEN2">>,
token = <<"TOKEN2">>,
payment_system = mastercard,
bin = <<"777777">>,
last_digits = <<"777">>,
bin = <<"777777">>,
last_digits = <<"777">>,
issuer_country = rus
},
Vs = #{
p2p_tool => #domain_P2PTool{
sender = {bank_card, BankCard1},
sender = {bank_card, BankCard1},
receiver = {bank_card, BankCard2}
}
},
@ -210,17 +206,22 @@ p2p_provider_test() ->
-spec p2p_allow_test() -> _.
p2p_allow_test() ->
FunGenCard = fun(PS, Country) -> #domain_BankCard{
token = <<"TOKEN1">>,
payment_system = PS,
bin = <<"888888">>,
last_digits = <<"888">>,
issuer_country = Country}
FunGenCard = fun(PS, Country) ->
#domain_BankCard{
token = <<"TOKEN1">>,
payment_system = PS,
bin = <<"888888">>,
last_digits = <<"888">>,
issuer_country = Country
}
end,
FunGenVS = fun(PS1, PS2) -> #{p2p_tool => #domain_P2PTool{
sender = {bank_card, FunGenCard(PS1, rus)},
receiver = {bank_card, FunGenCard(PS2, rus)}
}}
FunGenVS = fun(PS1, PS2) ->
#{
p2p_tool => #domain_P2PTool{
sender = {bank_card, FunGenCard(PS1, rus)},
receiver = {bank_card, FunGenCard(PS2, rus)}
}
}
end,
Condition = #domain_BankCardCondition{definition = {payment_system_is, visa}},
CardCondition1 = #domain_P2PToolCondition{

View File

@ -7,18 +7,15 @@
%%
-spec unique_id() -> dmsl_base_thrift:'ID'().
unique_id() ->
<<ID:64>> = snowflake:new(),
genlib_format:format_int_base(ID, 62).
-spec select_defined(T | undefined, T | undefined) -> T | undefined.
select_defined(V1, V2) ->
select_defined([V1, V2]).
-spec select_defined([T | undefined]) -> T | undefined.
select_defined([V | _]) when V /= undefined ->
V;
select_defined([undefined | Vs]) ->
@ -31,7 +28,6 @@ select_defined([]) ->
-spec unwrap_result
({ok, T}) -> T;
({error, _}) -> no_return().
unwrap_result({ok, V}) ->
V;
unwrap_result({error, E}) ->

View File

@ -1,6 +1,7 @@
-module(pm_wallet).
-include("party_events.hrl").
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
%%
@ -11,15 +12,13 @@
%% Interface
-type wallet() :: dmsl_domain_thrift:'Wallet'().
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
-type wallet_params() :: dmsl_payment_processing_thrift:'WalletParams'().
-type wallet_account() :: dmsl_domain_thrift:'WalletAccount'().
-type wallet_account_params() :: dmsl_payment_processing_thrift:'WalletAccountParams'().
-spec create(wallet_id(), wallet_params(), pm_datetime:timestamp()) ->
wallet().
-type wallet() :: dmsl_domain_thrift:'Wallet'().
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
-type wallet_params() :: dmsl_payment_processing_thrift:'WalletParams'().
-type wallet_account() :: dmsl_domain_thrift:'WalletAccount'().
-type wallet_account_params() :: dmsl_payment_processing_thrift:'WalletAccountParams'().
-spec create(wallet_id(), wallet_params(), pm_datetime:timestamp()) -> wallet().
create(
ID,
#payproc_WalletParams{
@ -37,9 +36,7 @@ create(
contract = ContractID
}.
-spec create_account(wallet_account_params()) ->
wallet_account().
-spec create_account(wallet_account_params()) -> wallet_account().
create_account(#payproc_WalletAccountParams{currency = Currency}) ->
SymbolicCode = Currency#domain_CurrencyRef.symbolic_code,
SettlementID = pm_accounting:create_account(SymbolicCode),
@ -50,9 +47,7 @@ create_account(#payproc_WalletAccountParams{currency = Currency}) ->
payout = PayoutID
}.
-spec create_fake_account(wallet_account_params()) ->
wallet_account().
-spec create_fake_account(wallet_account_params()) -> wallet_account().
create_fake_account(#payproc_WalletAccountParams{currency = Currency}) ->
#domain_WalletAccount{
currency = Currency,

View File

@ -3,13 +3,13 @@
%% API
-export([new/1]).
-type url() :: woody:url().
-type event_handler() :: woody:ev_handler().
-type url() :: woody:url().
-type event_handler() :: woody:ev_handler().
-type transport_opts() :: woody_client_thrift_http_transport:transport_options().
-type client() :: #{
url := url(),
event_handler := event_handler(),
url := url(),
event_handler := event_handler(),
transport_opts => transport_opts()
}.
@ -19,9 +19,7 @@
transport_opts => transport_opts()
}.
-spec new(woody:url() | opts()) ->
client().
-spec new(woody:url() | opts()) -> client().
new(Opts = #{url := _}) ->
EventHandlerOpts = genlib_app:env(party_management, scoper_event_handler_options, #{}),
maps:merge(

View File

@ -1,14 +1,14 @@
-module(pm_woody_handler_utils).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type user_identity() :: woody_user_identity:user_identity().
-export([get_user_identity/0]).
-export([assume_user_identity/1]).
-spec get_user_identity() -> woody_user_identity:user_identity() | undefined.
get_user_identity() ->
try
Context = pm_context:load(),
@ -19,12 +19,10 @@ get_user_identity() ->
end.
-spec set_user_identity(user_identity()) -> ok.
set_user_identity(UserIdentity) ->
pm_context:save(pm_context:set_user_identity(UserIdentity, pm_context:load())).
-spec assume_user_identity(user_info()) -> ok.
assume_user_identity(UserInfo) ->
case get_user_identity() of
V when V /= undefined ->
@ -41,9 +39,7 @@ map_user_info(#payproc_UserInfo{id = PartyID, type = Type}) ->
map_user_type({external_user, #payproc_ExternalUser{}}) ->
<<"external">>;
map_user_type({internal_user, #payproc_InternalUser{}}) ->
<<"internal">>;
map_user_type({service_user, #payproc_ServiceUser{}}) ->
<<"service">>.

View File

@ -5,6 +5,7 @@
-behaviour(woody_server_thrift_handler).
-export([handle_function/4]).
-export_type([handler_opts/0]).
-export_type([client_opts/0]).
@ -15,16 +16,16 @@
}.
-type client_opts() :: #{
url := woody:url(),
url := woody:url(),
transport_opts => [{_, _}]
}.
-define(DEFAULT_HANDLING_TIMEOUT, 30000). % 30 seconds
% 30 seconds
-define(DEFAULT_HANDLING_TIMEOUT, 30000).
%% Callbacks
-callback(handle_function(woody:func(), woody:args(), handler_opts()) ->
term() | no_return()).
-callback handle_function(woody:func(), woody:args(), handler_opts()) -> term() | no_return().
%% API
@ -35,9 +36,7 @@
-export([get_service_options/1]).
-spec handle_function(woody:func(), woody:args(), woody_context:ctx(), handler_opts()) ->
{ok, term()} | no_return().
-spec handle_function(woody:func(), woody:args(), woody_context:ctx(), handler_opts()) -> {ok, term()} | no_return().
handle_function(Func, Args, WoodyContext0, #{handler := Handler} = Opts) ->
WoodyContext = ensure_woody_deadline_set(WoodyContext0, Opts),
ok = pm_context:save(create_context(WoodyContext)),
@ -55,52 +54,44 @@ handle_function(Func, Args, WoodyContext0, #{handler := Handler} = Opts) ->
pm_context:cleanup()
end.
-spec call(atom(), woody:func(), woody:args()) ->
term().
-spec call(atom(), woody:func(), woody:args()) -> term().
call(ServiceName, Function, Args) ->
Opts = get_service_options(ServiceName),
Deadline = undefined,
call(ServiceName, Function, Args, Opts, Deadline).
-spec call(atom(), woody:func(), woody:args(), client_opts()) ->
term().
-spec call(atom(), woody:func(), woody:args(), client_opts()) -> term().
call(ServiceName, Function, Args, Opts) ->
Deadline = undefined,
call(ServiceName, Function, Args, Opts, Deadline).
-spec call(atom(), woody:func(), woody:args(), client_opts(), woody_deadline:deadline()) ->
term().
-spec call(atom(), woody:func(), woody:args(), client_opts(), woody_deadline:deadline()) -> term().
call(ServiceName, Function, Args, Opts, Deadline) ->
Service = get_service_modname(ServiceName),
Context = pm_context:get_woody_context(pm_context:load()),
Request = {Service, Function, Args},
woody_client:call(
Request,
Opts#{event_handler => {
scoper_woody_event_handler,
genlib_app:env(party_management, scoper_event_handler_options, #{})
}},
Opts#{
event_handler => {
scoper_woody_event_handler,
genlib_app:env(party_management, scoper_event_handler_options, #{})
}
},
attach_deadline(Deadline, Context)
).
-spec get_service_options(atom()) ->
client_opts().
-spec get_service_options(atom()) -> client_opts().
get_service_options(ServiceName) ->
construct_opts(maps:get(ServiceName, genlib_app:env(party_management, services))).
-spec attach_deadline(woody_deadline:deadline(), woody_context:ctx()) -> woody_context:ctx().
attach_deadline(undefined, Context) ->
Context;
attach_deadline(Deadline, Context) ->
woody_context:set_deadline(Deadline, Context).
-spec raise(term()) ->
no_return().
-spec raise(term()) -> no_return().
raise(Exception) ->
woody_error:raise(business, Exception).
@ -111,9 +102,7 @@ construct_opts(Opts = #{url := Url}) ->
construct_opts(Url) ->
#{url => genlib:to_binary(Url)}.
-spec get_service_modname(atom()) ->
{module(), atom()}.
-spec get_service_modname(atom()) -> {module(), atom()}.
get_service_modname(ServiceName) ->
pm_proto:get_service(ServiceName).
@ -123,9 +112,7 @@ create_context(WoodyContext) ->
},
pm_context:create(ContextOptions).
-spec ensure_woody_deadline_set(woody_context:ctx(), handler_opts()) ->
woody_context:ctx().
-spec ensure_woody_deadline_set(woody_context:ctx(), handler_opts()) -> woody_context:ctx().
ensure_woody_deadline_set(WoodyContext, Opts) ->
case woody_context:get_deadline(WoodyContext) of
undefined ->

View File

@ -2,6 +2,7 @@
-include("claim_management.hrl").
-include("pm_ct_domain.hrl").
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-export([all/0]).
@ -30,18 +31,17 @@
-type config() :: pm_ct_helper:config().
-type test_case_name() :: pm_ct_helper:test_case_name().
-define(REAL_CONTRACTOR_ID1, <<"CONTRACTOR2">>).
-define(REAL_CONTRACTOR_ID2, <<"CONTRACTOR3">>).
-define(REAL_CONTRACT_ID1, <<"CONTRACT2">>).
-define(REAL_CONTRACT_ID2, <<"CONTRACT3">>).
-define(REAL_CONTRACTOR_ID1, <<"CONTRACTOR2">>).
-define(REAL_CONTRACTOR_ID2, <<"CONTRACTOR3">>).
-define(REAL_CONTRACT_ID1, <<"CONTRACT2">>).
-define(REAL_CONTRACT_ID2, <<"CONTRACT3">>).
-define(REAL_PAYOUT_TOOL_ID1, <<"PAYOUTTOOL2">>).
-define(REAL_PAYOUT_TOOL_ID2, <<"PAYOUTTOOL3">>).
-define(REAL_SHOP_ID, <<"SHOP2">>).
-define(REAL_SHOP_ID, <<"SHOP2">>).
%%% CT
-spec all() -> [test_case_name()].
all() ->
[
party_creation,
@ -65,17 +65,15 @@ all() ->
].
-spec init_per_suite(config()) -> config().
init_per_suite(C) ->
{Apps, Ret} = pm_ct_helper:start_apps([woody, scoper, dmt_client, party_client, party_management, hellgate]),
RootUrl = maps:get(hellgate_root_url, Ret),
ok = pm_domain:insert(construct_domain_fixture()),
PartyID = erlang:list_to_binary([?MODULE_STRING, ".", erlang:integer_to_list(erlang:system_time())]),
ApiClient = pm_ct_helper:create_client(RootUrl, PartyID),
RootUrl = maps:get(hellgate_root_url, Ret),
ok = pm_domain:insert(construct_domain_fixture()),
PartyID = erlang:list_to_binary([?MODULE_STRING, ".", erlang:integer_to_list(erlang:system_time())]),
ApiClient = pm_ct_helper:create_client(RootUrl, PartyID),
[{root_url, RootUrl}, {apps, Apps}, {party_id, PartyID}, {api_client, ApiClient} | C].
-spec end_per_suite(config()) -> _.
end_per_suite(C) ->
ok = pm_domain:cleanup(),
[application:stop(App) || App <- cfg(apps, C)].
@ -83,25 +81,23 @@ end_per_suite(C) ->
%%% Tests
-spec party_creation(config()) -> _.
party_creation(C) ->
PartyID = cfg(party_id, C),
ContactInfo = #domain_PartyContactInfo{email = <<?MODULE_STRING>>},
ok = create_party(PartyID, ContactInfo, C),
{ok, Party} = get_party(PartyID, C),
#domain_Party{
id = PartyID,
id = PartyID,
contact_info = ContactInfo,
blocking = {unblocked, #domain_Unblocked{}},
suspension = {active, #domain_Active{}},
shops = Shops,
contracts = Contracts
blocking = {unblocked, #domain_Unblocked{}},
suspension = {active, #domain_Active{}},
shops = Shops,
contracts = Contracts
} = Party,
0 = maps:size(Shops),
0 = maps:size(Contracts).
-spec contractor_one_creation(config()) -> _.
contractor_one_creation(C) ->
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
ContractorID = ?REAL_CONTRACTOR_ID1,
@ -116,7 +112,6 @@ contractor_one_creation(C) ->
#domain_PartyContractor{} = pm_party:get_contractor(ContractorID, Party).
-spec contractor_two_creation(config()) -> _.
contractor_two_creation(C) ->
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
ContractorID = ?REAL_CONTRACTOR_ID2,
@ -131,7 +126,6 @@ contractor_two_creation(C) ->
#domain_PartyContractor{} = pm_party:get_contractor(ContractorID, Party).
-spec contractor_modification(config()) -> _.
contractor_modification(C) ->
ContractorID = ?REAL_CONTRACTOR_ID1,
PartyID = cfg(party_id, C),
@ -148,7 +142,6 @@ contractor_modification(C) ->
C1 /= C2 orelse error(same_contractor).
-spec contract_one_creation(config()) -> _.
contract_one_creation(C) ->
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
PayoutToolParams = make_payout_tool_params(),
@ -172,7 +165,6 @@ contract_one_creation(C) ->
true = lists:keymember(PayoutToolID2, #domain_PayoutTool.id, PayoutTools).
-spec contract_two_creation(config()) -> _.
contract_two_creation(C) ->
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
PayoutToolParams = make_payout_tool_params(),
@ -193,10 +185,9 @@ contract_two_creation(C) ->
true = lists:keymember(PayoutToolID1, #domain_PayoutTool.id, PayoutTools).
-spec contract_contractor_modification(config()) -> _.
contract_contractor_modification(C) ->
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID2,
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID2,
NewContractor = ?REAL_CONTRACTOR_ID2,
Modifications = [
?cm_contract_modification(ContractID, {contractor_modification, NewContractor})
@ -205,12 +196,11 @@ contract_contractor_modification(C) ->
ok = accept_claim(Claim, C),
ok = commit_claim(Claim, C),
{ok, #domain_Contract{
id = ContractID,
id = ContractID,
contractor_id = NewContractor
}} = get_contract(PartyID, ContractID, C).
-spec contract_adjustment_creation(config()) -> _.
contract_adjustment_creation(C) ->
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID1,
@ -227,7 +217,6 @@ contract_adjustment_creation(C) ->
true = lists:keymember(ID, #domain_ContractAdjustment.id, Adjustments).
-spec contract_legal_agreement_binding(config()) -> _.
contract_legal_agreement_binding(C) ->
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID1,
@ -245,7 +234,6 @@ contract_legal_agreement_binding(C) ->
}} = get_contract(PartyID, ContractID, C).
-spec contract_report_preferences_modification(config()) -> _.
contract_report_preferences_modification(C) ->
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID1,
@ -254,9 +242,9 @@ contract_report_preferences_modification(C) ->
service_acceptance_act_preferences = #domain_ServiceAcceptanceActPreferences{
schedule = ?bussched(1),
signer = #domain_Representative{
position = <<"69">>,
position = <<"69">>,
full_name = <<"Generic Name">>,
document = {articles_of_association, #domain_ArticlesOfAssociation{}}
document = {articles_of_association, #domain_ArticlesOfAssociation{}}
}
}
},
@ -273,11 +261,10 @@ contract_report_preferences_modification(C) ->
}} = get_contract(PartyID, ContractID, C).
-spec shop_creation(config()) -> _.
shop_creation(C) ->
PartyID = cfg(party_id, C),
Details = #domain_ShopDetails{
name = <<"SOME SHOP NAME">>,
name = <<"SOME SHOP NAME">>,
description = <<"Very meaningfull description of the shop.">>
},
Category = ?cat(2),
@ -286,10 +273,10 @@ shop_creation(C) ->
ShopID = ?REAL_SHOP_ID,
PayoutToolID1 = ?REAL_PAYOUT_TOOL_ID1,
ShopParams = #claim_management_ShopParams{
category = Category,
location = Location,
details = Details,
contract_id = ContractID,
category = Category,
location = Location,
details = Details,
contract_id = ContractID,
payout_tool_id = PayoutToolID1
},
Schedule = ?bussched(1),
@ -304,23 +291,22 @@ shop_creation(C) ->
ok = commit_claim(Claim, C),
{ok, #domain_Shop{
id = ShopID,
details = Details,
location = Location,
category = Category,
account = #domain_ShopAccount{currency = ?cur(<<"RUB">>)},
contract_id = ContractID,
payout_tool_id = PayoutToolID1,
details = Details,
location = Location,
category = Category,
account = #domain_ShopAccount{currency = ?cur(<<"RUB">>)},
contract_id = ContractID,
payout_tool_id = PayoutToolID1,
payout_schedule = Schedule
}} = get_shop(PartyID, ShopID, C).
-spec shop_complex_modification(config()) -> _.
shop_complex_modification(C) ->
PartyID = cfg(party_id, C),
ShopID = ?REAL_SHOP_ID,
NewCategory = ?cat(3),
NewDetails = #domain_ShopDetails{
name = <<"UPDATED SHOP NAME">>,
name = <<"UPDATED SHOP NAME">>,
description = <<"Updated shop description.">>
},
NewLocation = {url, <<"http://localhost">>},
@ -343,22 +329,21 @@ shop_complex_modification(C) ->
ok = accept_claim(Claim, C),
ok = commit_claim(Claim, C),
{ok, #domain_Shop{
category = NewCategory,
details = NewDetails,
location = NewLocation,
payout_tool_id = PayoutToolID2,
category = NewCategory,
details = NewDetails,
location = NewLocation,
payout_tool_id = PayoutToolID2,
payout_schedule = Schedule
}} = get_shop(PartyID, ShopID, C).
-spec shop_contract_modification(config()) -> _.
shop_contract_modification(C) ->
PartyID = cfg(party_id, C),
ShopID = ?REAL_SHOP_ID,
ContractID = ?REAL_CONTRACT_ID2,
PartyID = cfg(party_id, C),
ShopID = ?REAL_SHOP_ID,
ContractID = ?REAL_CONTRACT_ID2,
PayoutToolID = ?REAL_PAYOUT_TOOL_ID1,
ShopContractParams = #claim_management_ShopContractModification{
contract_id = ContractID,
contract_id = ContractID,
payout_tool_id = PayoutToolID
},
Modifications = [?cm_shop_modification(ShopID, {contract_modification, ShopContractParams})],
@ -366,82 +351,80 @@ shop_contract_modification(C) ->
ok = accept_claim(Claim, C),
ok = commit_claim(Claim, C),
{ok, #domain_Shop{
contract_id = ContractID,
contract_id = ContractID,
payout_tool_id = PayoutToolID
}} = get_shop(PartyID, ShopID, C).
-spec contract_termination(config()) -> _.
contract_termination(C) ->
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID1,
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
PartyID = cfg(party_id, C),
ContractID = ?REAL_CONTRACT_ID1,
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
Modifications = [?cm_contract_modification(ContractID, {termination, Reason})],
Claim = claim(Modifications, PartyID),
ok = accept_claim(Claim, C),
ok = commit_claim(Claim, C),
{ok, #domain_Contract{
id = ContractID,
id = ContractID,
status = {terminated, _}
}} = get_contract(PartyID, ContractID, C).
-spec contractor_already_exists(config()) -> _.
contractor_already_exists(C) ->
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
PartyID = cfg(party_id, C),
ContractorID = ?REAL_CONTRACTOR_ID1,
Modifications = [?cm_contractor_creation(ContractorID, ContractorParams)],
Claim = claim(Modifications, PartyID),
Reason = <<"{invalid_contractor,{payproc_InvalidContractor,<<\"", ContractorID/binary,
"\">>,{already_exists,<<\"", ContractorID/binary, "\">>}}}">>,
Reason =
<<"{invalid_contractor,{payproc_InvalidContractor,<<\"", ContractorID/binary, "\">>,{already_exists,<<\"",
ContractorID/binary, "\">>}}}">>,
{exception, #claim_management_InvalidChangeset{
reason = Reason
}} = accept_claim(Claim, C).
-spec contract_already_exists(config()) -> _.
contract_already_exists(C) ->
PartyID = cfg(party_id, C),
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
ContractID = ?REAL_CONTRACT_ID1,
Modifications = [?cm_contract_creation(ContractID, ContractParams)],
Claim = claim(Modifications, PartyID),
Reason = <<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary,
"\">>,{already_exists,<<\"", ContractID/binary, "\">>}}}">>,
Reason =
<<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary, "\">>,{already_exists,<<\"",
ContractID/binary, "\">>}}}">>,
{exception, #claim_management_InvalidChangeset{
reason = Reason
}} = accept_claim(Claim, C).
-spec contract_already_terminated(config()) -> _.
contract_already_terminated(C) ->
ContractID = ?REAL_CONTRACT_ID1,
ContractID = ?REAL_CONTRACT_ID1,
PartyID = cfg(party_id, C),
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
Modifications = [?cm_contract_modification(ContractID, {termination, Reason})],
Claim = claim(Modifications, PartyID),
ErrorReason = <<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary,
"\">>,{invalid_status,{terminated,{domain_ContractTerminated">>,
Claim = claim(Modifications, PartyID),
ErrorReason =
<<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary,
"\">>,{invalid_status,{terminated,{domain_ContractTerminated">>,
ErrorReasonSize = erlang:byte_size(ErrorReason),
{exception, #claim_management_InvalidChangeset{
reason = <<ErrorReason:ErrorReasonSize/binary, _/binary>>
}} = accept_claim(Claim, C).
-spec shop_already_exists(config()) -> _.
shop_already_exists(C) ->
Details = #domain_ShopDetails{
name = <<"SOME SHOP NAME">>,
name = <<"SOME SHOP NAME">>,
description = <<"Very meaningfull description of the shop.">>
},
ShopID = ?REAL_SHOP_ID,
PartyID = cfg(party_id, C),
ShopParams = #claim_management_ShopParams{
category = ?cat(2),
location = {url, <<"https://example.com">>},
details = Details,
contract_id = ?REAL_CONTRACT_ID1,
category = ?cat(2),
location = {url, <<"https://example.com">>},
details = Details,
contract_id = ?REAL_CONTRACT_ID1,
payout_tool_id = ?REAL_PAYOUT_TOOL_ID1
},
ScheduleParams = #claim_management_ScheduleModification{schedule = ?bussched(1)},
@ -451,8 +434,9 @@ shop_already_exists(C) ->
?cm_shop_modification(ShopID, {payout_schedule_modification, ScheduleParams})
],
Claim = claim(Modifications, PartyID),
Reason = <<"{invalid_shop,{payproc_InvalidShop,<<\"", ShopID/binary,
"\">>,{already_exists,<<\"", ShopID/binary, "\">>}}}">>,
Reason =
<<"{invalid_shop,{payproc_InvalidShop,<<\"", ShopID/binary, "\">>,{already_exists,<<\"", ShopID/binary,
"\">>}}}">>,
{exception, #claim_management_InvalidChangeset{
reason = Reason
}} = accept_claim(Claim, C).
@ -467,11 +451,11 @@ claim(PartyModifications, PartyID) ->
type = {internal_user, #claim_management_InternalUser{}}
},
#claim_management_Claim{
id = id(),
party_id = PartyID,
status = {pending, #claim_management_ClaimPending{}},
changeset = [?cm_party_modification(id(), ts(), Mod, UserInfo) || Mod <- PartyModifications],
revision = 1,
id = id(),
party_id = PartyID,
status = {pending, #claim_management_ClaimPending{}},
changeset = [?cm_party_modification(id(), ts(), Mod, UserInfo) || Mod <- PartyModifications],
revision = 1,
created_at = ts()
}.
@ -485,8 +469,8 @@ cfg(Key, C) ->
pm_ct_helper:cfg(Key, C).
call(Function, Args, C) ->
ApiClient = cfg(api_client, C),
PartyID = cfg(party_id, C),
ApiClient = cfg(api_client, C),
PartyID = cfg(party_id, C),
{Result, _} = pm_client_api:call(claim_committer, Function, [PartyID | Args], ApiClient),
map_call_result(Result).
@ -502,7 +486,7 @@ map_call_result(Other) ->
Other.
call_pm(Fun, Args, C) ->
ApiClient = cfg(api_client, C),
ApiClient = cfg(api_client, C),
{Result, _} = pm_client_api:call(party_management, Fun, [undefined | Args], ApiClient),
map_call_result(Result).
@ -527,24 +511,24 @@ make_contract_params(ContractorID, TemplateRef) ->
make_contract_params(ContractorID, TemplateRef, PaymentInstitutionRef) ->
#claim_management_ContractParams{
contractor_id = ContractorID,
template = TemplateRef,
contractor_id = ContractorID,
template = TemplateRef,
payment_institution = PaymentInstitutionRef
}.
make_payout_tool_params() ->
#claim_management_PayoutToolParams{
currency = ?cur(<<"RUB">>),
tool_info = {russian_bank_account, #domain_RussianBankAccount{
account = <<"4276300010908312893">>,
bank_name = <<"SomeBank">>,
bank_post_account = <<"123129876">>,
bank_bik = <<"66642666">>
}}
tool_info =
{russian_bank_account, #domain_RussianBankAccount{
account = <<"4276300010908312893">>,
bank_name = <<"SomeBank">>,
bank_post_account = <<"123129876">>,
bank_bik = <<"66642666">>
}}
}.
-spec construct_domain_fixture() -> [pm_domain:object()].
construct_domain_fixture() ->
TestTermSet = #domain_TermSet{
payments = #domain_PaymentsServiceTerms{
@ -554,74 +538,89 @@ construct_domain_fixture() ->
},
DefaultTermSet = #domain_TermSet{
payments = #domain_PaymentsServiceTerms{
currencies = {value, ordsets:from_list([
?cur(<<"RUB">>),
?cur(<<"USD">>)
])},
categories = {value, ordsets:from_list([
?cat(2),
?cat(3)
])},
payment_methods = {value, ordsets:from_list([
?pmt(bank_card_deprecated, visa)
])}
currencies =
{value,
ordsets:from_list([
?cur(<<"RUB">>),
?cur(<<"USD">>)
])},
categories =
{value,
ordsets:from_list([
?cat(2),
?cat(3)
])},
payment_methods =
{value,
ordsets:from_list([
?pmt(bank_card_deprecated, visa)
])}
}
},
TermSet = #domain_TermSet{
payments = #domain_PaymentsServiceTerms{
cash_limit = {value, #domain_CashRange{
lower = {inclusive, #domain_Cash{amount = 1000, currency = ?cur(<<"RUB">>)}},
upper = {exclusive, #domain_Cash{amount = 4200000, currency = ?cur(<<"RUB">>)}}
}},
fees = {value, [
?cfpost(
{merchant, settlement},
{system, settlement},
?share(45, 1000, operation_amount)
)
]}
cash_limit =
{value, #domain_CashRange{
lower = {inclusive, #domain_Cash{amount = 1000, currency = ?cur(<<"RUB">>)}},
upper = {exclusive, #domain_Cash{amount = 4200000, currency = ?cur(<<"RUB">>)}}
}},
fees =
{value, [
?cfpost(
{merchant, settlement},
{system, settlement},
?share(45, 1000, operation_amount)
)
]}
},
payouts = #domain_PayoutsServiceTerms{
payout_methods = {decisions, [
#domain_PayoutMethodDecision{
if_ = {condition, {payment_tool,
{bank_card, #domain_BankCardCondition{
definition = {issuer_bank_is, ?bank(1)}
}}
}},
then_ = {value, ordsets:from_list([?pomt(russian_bank_account), ?pomt(international_bank_account)])}
},
#domain_PayoutMethodDecision{
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{
definition = {empty_cvv_is, true}
}}}},
then_ = {value, ordsets:from_list([])}
},
#domain_PayoutMethodDecision{
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{}}}},
then_ = {value, ordsets:from_list([?pomt(russian_bank_account)])}
},
#domain_PayoutMethodDecision{
if_ = {condition, {payment_tool, {payment_terminal, #domain_PaymentTerminalCondition{}}}},
then_ = {value, ordsets:from_list([?pomt(international_bank_account)])}
},
#domain_PayoutMethodDecision{
if_ = {constant, true},
then_ = {value, ordsets:from_list([])}
}
]},
fees = {value, [
?cfpost(
{merchant, settlement},
{merchant, payout},
?share(750, 1000, operation_amount)
),
?cfpost(
{merchant, settlement},
{system, settlement},
?share(250, 1000, operation_amount)
)
]}
payout_methods =
{decisions, [
#domain_PayoutMethodDecision{
if_ =
{condition,
{payment_tool,
{bank_card, #domain_BankCardCondition{
definition = {issuer_bank_is, ?bank(1)}
}}}},
then_ =
{value, ordsets:from_list([?pomt(russian_bank_account), ?pomt(international_bank_account)])}
},
#domain_PayoutMethodDecision{
if_ =
{condition,
{payment_tool,
{bank_card, #domain_BankCardCondition{
definition = {empty_cvv_is, true}
}}}},
then_ = {value, ordsets:from_list([])}
},
#domain_PayoutMethodDecision{
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{}}}},
then_ = {value, ordsets:from_list([?pomt(russian_bank_account)])}
},
#domain_PayoutMethodDecision{
if_ = {condition, {payment_tool, {payment_terminal, #domain_PaymentTerminalCondition{}}}},
then_ = {value, ordsets:from_list([?pomt(international_bank_account)])}
},
#domain_PayoutMethodDecision{
if_ = {constant, true},
then_ = {value, ordsets:from_list([])}
}
]},
fees =
{value, [
?cfpost(
{merchant, settlement},
{merchant, payout},
?share(750, 1000, operation_amount)
),
?cfpost(
{merchant, settlement},
{system, settlement},
?share(250, 1000, operation_amount)
)
]}
},
wallets = #domain_WalletServiceTerms{
currencies = {value, ordsets:from_list([?cur(<<"RUB">>)])}
@ -727,57 +726,71 @@ construct_domain_fixture() ->
ref = ?trms(1),
data = #domain_TermSetHierarchy{
parent_terms = undefined,
term_sets = [#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = TestTermSet
}]
term_sets = [
#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = TestTermSet
}
]
}
}},
{term_set_hierarchy, #domain_TermSetHierarchyObject{
ref = ?trms(2),
data = #domain_TermSetHierarchy{
parent_terms = undefined,
term_sets = [#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = DefaultTermSet
}]
term_sets = [
#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = DefaultTermSet
}
]
}
}},
{term_set_hierarchy, #domain_TermSetHierarchyObject{
ref = ?trms(3),
data = #domain_TermSetHierarchy{
parent_terms = ?trms(2),
term_sets = [#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = TermSet
}]
term_sets = [
#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = TermSet
}
]
}
}},
{term_set_hierarchy, #domain_TermSetHierarchyObject{
ref = ?trms(4),
data = #domain_TermSetHierarchy{
parent_terms = ?trms(3),
term_sets = [#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = #domain_TermSet{
payments = #domain_PaymentsServiceTerms{
currencies = {value, ordsets:from_list([
?cur(<<"RUB">>)
])},
categories = {value, ordsets:from_list([
?cat(2)
])},
payment_methods = {value, ordsets:from_list([
?pmt(bank_card_deprecated, visa)
])}
term_sets = [
#domain_TimedTermSet{
action_time = #'TimestampInterval'{},
terms = #domain_TermSet{
payments = #domain_PaymentsServiceTerms{
currencies =
{value,
ordsets:from_list([
?cur(<<"RUB">>)
])},
categories =
{value,
ordsets:from_list([
?cat(2)
])},
payment_methods =
{value,
ordsets:from_list([
?pmt(bank_card_deprecated, visa)
])}
}
}
}
}]
]
}
}},
{bank, #domain_BankObject{
ref = ?bank(1),
data = #domain_Bank {
data = #domain_Bank{
name = <<"Test BIN range">>,
description = <<"Test BIN range">>,
bins = ordsets:from_list([<<"1234">>, <<"5678">>])

View File

@ -14,25 +14,30 @@
-type object() :: pm_domain:object().
-spec upsert(revision(), object() | [object()]) -> revision() | no_return().
upsert(Revision, NewObject) when not is_list(NewObject) ->
upsert(Revision, [NewObject]);
upsert(Revision, NewObjects) ->
Commit = #'Commit'{
ops = lists:foldl(
fun (NewObject = {Tag, {ObjectName, Ref, NewData}}, Ops) ->
fun(NewObject = {Tag, {ObjectName, Ref, NewData}}, Ops) ->
case pm_domain:find(Revision, {Tag, Ref}) of
NewData ->
Ops;
notfound ->
[{insert, #'InsertOp'{
object = NewObject
}} | Ops];
[
{insert, #'InsertOp'{
object = NewObject
}}
| Ops
];
OldData ->
[{update, #'UpdateOp'{
old_object = {Tag, {ObjectName, Ref, OldData}},
new_object = NewObject
}} | Ops]
[
{update, #'UpdateOp'{
old_object = {Tag, {ObjectName, Ref, OldData}},
new_object = NewObject
}}
| Ops
]
end
end,
[],
@ -43,22 +48,21 @@ upsert(Revision, NewObjects) ->
pm_domain:head().
-spec reset(revision()) -> ok | no_return().
reset(ToRevision) ->
upsert(hg_domain:head(), maps:values(pm_domain:all(ToRevision))).
-spec commit(revision(), dmt_client:commit()) -> ok | no_return().
commit(Revision, Commit) ->
Revision = dmt_client:commit(Revision, Commit) - 1,
_ = pm_domain:all(Revision + 1),
ok.
-spec with(object() | [object()], fun ((revision()) -> R)) -> R | no_return().
-spec with(object() | [object()], fun((revision()) -> R)) -> R | no_return().
with(NewObjects, Fun) ->
WasRevision = pm_domain:head(),
Revision = upsert(WasRevision, NewObjects),
try Fun(Revision) after
try
Fun(Revision)
after
reset(WasRevision)
end.

View File

@ -2,81 +2,83 @@
-define(__pm_ct_domain__, 42).
-include("domain.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-define(ordset(Es), ordsets:from_list(Es)).
-define(ordset(Es), ordsets:from_list(Es)).
-define(glob(), #domain_GlobalsRef{}).
-define(cur(ID), #domain_CurrencyRef{symbolic_code = ID}).
-define(pmt(C, T), #domain_PaymentMethodRef{id = {C, T}}).
-define(pomt(M), #domain_PayoutMethodRef{id = M}).
-define(cat(ID), #domain_CategoryRef{id = ID}).
-define(prx(ID), #domain_ProxyRef{id = ID}).
-define(prv(ID), #domain_ProviderRef{id = ID}).
-define(prvtrm(ID), #domain_ProviderTerminalRef{id = ID}).
-define(trm(ID), #domain_TerminalRef{id = ID}).
-define(tmpl(ID), #domain_ContractTemplateRef{id = ID}).
-define(trms(ID), #domain_TermSetHierarchyRef{id = ID}).
-define(sas(ID), #domain_SystemAccountSetRef{id = ID}).
-define(eas(ID), #domain_ExternalAccountSetRef{id = ID}).
-define(insp(ID), #domain_InspectorRef{id = ID}).
-define(pinst(ID), #domain_PaymentInstitutionRef{id = ID}).
-define(bank(ID), #domain_BankRef{id = ID}).
-define(bussched(ID), #domain_BusinessScheduleRef{id = ID}).
-define(ruleset(ID), #domain_PaymentRoutingRulesetRef{id = ID}).
-define(p2pprov(ID), #domain_P2PProviderRef{id = ID}).
-define(wtdrlprov(ID), #domain_WithdrawalProviderRef{id = ID}).
-define(crit(ID), #domain_CriterionRef{id = ID}).
-define(crp(ID), #domain_CashRegisterProviderRef{id = ID}).
-define(glob(), #domain_GlobalsRef{}).
-define(cur(ID), #domain_CurrencyRef{symbolic_code = ID}).
-define(pmt(C, T), #domain_PaymentMethodRef{id = {C, T}}).
-define(pomt(M), #domain_PayoutMethodRef{id = M}).
-define(cat(ID), #domain_CategoryRef{id = ID}).
-define(prx(ID), #domain_ProxyRef{id = ID}).
-define(prv(ID), #domain_ProviderRef{id = ID}).
-define(prvtrm(ID), #domain_ProviderTerminalRef{id = ID}).
-define(trm(ID), #domain_TerminalRef{id = ID}).
-define(tmpl(ID), #domain_ContractTemplateRef{id = ID}).
-define(trms(ID), #domain_TermSetHierarchyRef{id = ID}).
-define(sas(ID), #domain_SystemAccountSetRef{id = ID}).
-define(eas(ID), #domain_ExternalAccountSetRef{id = ID}).
-define(insp(ID), #domain_InspectorRef{id = ID}).
-define(pinst(ID), #domain_PaymentInstitutionRef{id = ID}).
-define(bank(ID), #domain_BankRef{id = ID}).
-define(bussched(ID), #domain_BusinessScheduleRef{id = ID}).
-define(ruleset(ID), #domain_PaymentRoutingRulesetRef{id = ID}).
-define(p2pprov(ID), #domain_P2PProviderRef{id = ID}).
-define(wtdrlprov(ID), #domain_WithdrawalProviderRef{id = ID}).
-define(crit(ID), #domain_CriterionRef{id = ID}).
-define(crp(ID), #domain_CashRegisterProviderRef{id = ID}).
-define(cashrng(Lower, Upper),
#domain_CashRange{lower = Lower, upper = Upper}).
-define(cashrng(Lower, Upper), #domain_CashRange{lower = Lower, upper = Upper}).
-define(prvacc(Stl), #domain_ProviderAccount{settlement = Stl}).
-define(partycond(ID, Def), {condition, {party, #domain_PartyCondition{id = ID, definition = Def}}}).
-define(fixed(Amount, Currency),
{fixed, #domain_CashVolumeFixed{cash = #domain_Cash{
amount = Amount,
currency = ?currency(Currency)
}}}).
{fixed, #domain_CashVolumeFixed{
cash = #domain_Cash{
amount = Amount,
currency = ?currency(Currency)
}
}}
).
-define(share(P, Q, C),
{share, #domain_CashVolumeShare{
parts = #'Rational'{p = P, q = Q}, 'of' = C}
}
parts = #'Rational'{p = P, q = Q},
'of' = C
}}
).
-define(share_with_rounding_method(P, Q, C, RM),
{share, #domain_CashVolumeShare{
parts = #'Rational'{p = P, q = Q}, 'of' = C, rounding_method = RM}
}
parts = #'Rational'{p = P, q = Q},
'of' = C,
rounding_method = RM
}}
).
-define(cfpost(A1, A2, V),
#domain_CashFlowPosting{
source = A1,
destination = A2,
volume = V
}
).
-define(cfpost(A1, A2, V), #domain_CashFlowPosting{
source = A1,
destination = A2,
volume = V
}).
-define(cfpost(A1, A2, V, D),
#domain_CashFlowPosting{
source = A1,
destination = A2,
volume = V,
details = D
}
).
-define(cfpost(A1, A2, V, D), #domain_CashFlowPosting{
source = A1,
destination = A2,
volume = V,
details = D
}).
-define(tkz_bank_card(PaymentSystem, TokenProvider), ?tkz_bank_card(PaymentSystem, TokenProvider, dpan)).
-define(tkz_bank_card(PaymentSystem, TokenProvider, TokenizationMethod),
#domain_TokenizedBankCard{
payment_system = PaymentSystem,
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}).
-define(tkz_bank_card(PaymentSystem, TokenProvider, TokenizationMethod), #domain_TokenizedBankCard{
payment_system = PaymentSystem,
token_provider = TokenProvider,
tokenization_method = TokenizationMethod
}).
-define(timeout_reason(), <<"Timeout">>).

View File

@ -1,8 +1,10 @@
-module(pm_ct_fixture).
-include("pm_ct_domain.hrl").
-include_lib("damsel/include/dmsl_base_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
%%
-export([construct_currency/1]).
@ -30,15 +32,15 @@
%%
-type name() :: binary().
-type category() :: dmsl_domain_thrift:'CategoryRef'().
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
-type proxy() :: dmsl_domain_thrift:'ProxyRef'().
-type inspector() :: dmsl_domain_thrift:'InspectorRef'().
-type risk_score() :: dmsl_domain_thrift:'RiskScore'().
-type template() :: dmsl_domain_thrift:'ContractTemplateRef'().
-type terms() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
-type lifetime() :: dmsl_domain_thrift:'Lifetime'() | undefined.
-type name() :: binary().
-type category() :: dmsl_domain_thrift:'CategoryRef'().
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
-type proxy() :: dmsl_domain_thrift:'ProxyRef'().
-type inspector() :: dmsl_domain_thrift:'InspectorRef'().
-type risk_score() :: dmsl_domain_thrift:'RiskScore'().
-type template() :: dmsl_domain_thrift:'ContractTemplateRef'().
-type terms() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
-type lifetime() :: dmsl_domain_thrift:'Lifetime'() | undefined.
-type payment_routing_ruleset() :: dmsl_domain_thrift:'PaymentRoutingRulesetRef'().
-type system_account_set() :: dmsl_domain_thrift:'SystemAccountSetRef'().
@ -46,8 +48,8 @@
-type business_schedule() :: dmsl_domain_thrift:'BusinessScheduleRef'().
-type criterion() :: dmsl_domain_thrift:'CriterionRef'().
-type predicate() :: dmsl_domain_thrift:'Predicate'().
-type criterion() :: dmsl_domain_thrift:'CriterionRef'().
-type predicate() :: dmsl_domain_thrift:'Predicate'().
-type term_set() :: dmsl_domain_thrift:'TermSet'().
-type term_set_hierarchy() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
@ -58,15 +60,11 @@
%%
-spec construct_currency(currency()) ->
{currency, dmsl_domain_thrift:'CurrencyObject'()}.
-spec construct_currency(currency()) -> {currency, dmsl_domain_thrift:'CurrencyObject'()}.
construct_currency(Ref) ->
construct_currency(Ref, 2).
-spec construct_currency(currency(), Exponent :: pos_integer()) ->
{currency, dmsl_domain_thrift:'CurrencyObject'()}.
-spec construct_currency(currency(), Exponent :: pos_integer()) -> {currency, dmsl_domain_thrift:'CurrencyObject'()}.
construct_currency(?cur(SymbolicCode) = Ref, Exponent) ->
{currency, #domain_CurrencyObject{
ref = Ref,
@ -78,15 +76,11 @@ construct_currency(?cur(SymbolicCode) = Ref, Exponent) ->
}
}}.
-spec construct_category(category(), name()) ->
{category, dmsl_domain_thrift:'CategoryObject'()}.
-spec construct_category(category(), name()) -> {category, dmsl_domain_thrift:'CategoryObject'()}.
construct_category(Ref, Name) ->
construct_category(Ref, Name, test).
-spec construct_category(category(), name(), test | live) ->
{category, dmsl_domain_thrift:'CategoryObject'()}.
-spec construct_category(category(), name(), test | live) -> {category, dmsl_domain_thrift:'CategoryObject'()}.
construct_category(Ref, Name, Type) ->
{category, #domain_CategoryObject{
ref = Ref,
@ -99,7 +93,6 @@ construct_category(Ref, Name, Type) ->
-spec construct_payment_method(dmsl_domain_thrift:'PaymentMethodRef'()) ->
{payment_method, dmsl_domain_thrift:'PaymentMethodObject'()}.
construct_payment_method(?pmt(_Type, ?tkz_bank_card(Name, _)) = Ref) when is_atom(Name) ->
construct_payment_method(Name, Ref);
construct_payment_method(?pmt(_Type, Name) = Ref) when is_atom(Name) ->
@ -119,7 +112,6 @@ construct_payment_method(Name, Ref) ->
-spec construct_payout_method(dmsl_domain_thrift:'PayoutMethodRef'()) ->
{payout_method, dmsl_domain_thrift:'PayoutMethodObject'()}.
construct_payout_method(?pomt(M) = Ref) ->
Def = erlang:atom_to_binary(M, unicode),
{payout_method, #domain_PayoutMethodObject{
@ -130,41 +122,33 @@ construct_payout_method(?pomt(M) = Ref) ->
}
}}.
-spec construct_proxy(proxy(), name()) ->
{proxy, dmsl_domain_thrift:'ProxyObject'()}.
-spec construct_proxy(proxy(), name()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
construct_proxy(Ref, Name) ->
construct_proxy(Ref, Name, #{}).
-spec construct_proxy(proxy(), name(), Opts :: map()) ->
{proxy, dmsl_domain_thrift:'ProxyObject'()}.
-spec construct_proxy(proxy(), name(), Opts :: map()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
construct_proxy(Ref, Name, Opts) ->
{proxy, #domain_ProxyObject{
ref = Ref,
data = #domain_ProxyDefinition{
name = Name,
name = Name,
description = Name,
url = <<>>,
options = Opts
url = <<>>,
options = Opts
}
}}.
-spec construct_inspector(inspector(), name(), proxy()) ->
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
-spec construct_inspector(inspector(), name(), proxy()) -> {inspector, dmsl_domain_thrift:'InspectorObject'()}.
construct_inspector(Ref, Name, ProxyRef) ->
construct_inspector(Ref, Name, ProxyRef, #{}).
-spec construct_inspector(inspector(), name(), proxy(), Additional :: map()) ->
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
construct_inspector(Ref, Name, ProxyRef, Additional) ->
construct_inspector(Ref, Name, ProxyRef, Additional, undefined).
-spec construct_inspector(inspector(), name(), proxy(), Additional :: map(), risk_score()) ->
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
construct_inspector(Ref, Name, ProxyRef, Additional, FallBackScore) ->
{inspector, #domain_InspectorObject{
ref = Ref,
@ -181,13 +165,11 @@ construct_inspector(Ref, Name, ProxyRef, Additional, FallBackScore) ->
-spec construct_contract_template(template(), terms()) ->
{contract_template, dmsl_domain_thrift:'ContractTemplateObject'()}.
construct_contract_template(Ref, TermsRef) ->
construct_contract_template(Ref, TermsRef, undefined, undefined).
-spec construct_contract_template(template(), terms(), ValidSince :: lifetime(), ValidUntil :: lifetime()) ->
{contract_template, dmsl_domain_thrift:'ContractTemplateObject'()}.
construct_contract_template(Ref, TermsRef, ValidSince, ValidUntil) ->
{contract_template, #domain_ContractTemplateObject{
ref = Ref,
@ -199,11 +181,10 @@ construct_contract_template(Ref, TermsRef, ValidSince, ValidUntil) ->
}}.
-spec construct_provider_account_set([currency()]) -> dmsl_domain_thrift:'ProviderAccountSet'().
construct_provider_account_set(Currencies) ->
ok = pm_context:save(pm_context:create()),
AccountSet = lists:foldl(
fun (Cur = ?cur(Code), Acc) ->
fun(Cur = ?cur(Code), Acc) ->
Acc#{Cur => ?prvacc(pm_accounting:create_account(Code))}
end,
#{},
@ -214,13 +195,11 @@ construct_provider_account_set(Currencies) ->
-spec construct_system_account_set(system_account_set()) ->
{system_account_set, dmsl_domain_thrift:'SystemAccountSetObject'()}.
construct_system_account_set(Ref) ->
construct_system_account_set(Ref, <<"Primaries">>, ?cur(<<"RUB">>)).
-spec construct_system_account_set(system_account_set(), name(), currency()) ->
{system_account_set, dmsl_domain_thrift:'SystemAccountSetObject'()}.
construct_system_account_set(Ref, Name, ?cur(CurrencyCode)) ->
ok = pm_context:save(pm_context:create()),
SettlementAccountID = pm_accounting:create_account(CurrencyCode),
@ -231,22 +210,22 @@ construct_system_account_set(Ref, Name, ?cur(CurrencyCode)) ->
data = #domain_SystemAccountSet{
name = Name,
description = Name,
accounts = #{?cur(CurrencyCode) => #domain_SystemAccount{
settlement = SettlementAccountID,
subagent = SubagentAccountID
}}
accounts = #{
?cur(CurrencyCode) => #domain_SystemAccount{
settlement = SettlementAccountID,
subagent = SubagentAccountID
}
}
}
}}.
-spec construct_external_account_set(external_account_set()) ->
{system_account_set, dmsl_domain_thrift:'ExternalAccountSetObject'()}.
construct_external_account_set(Ref) ->
construct_external_account_set(Ref, <<"Primaries">>, ?cur(<<"RUB">>)).
-spec construct_external_account_set(external_account_set(), name(), currency()) ->
{system_account_set, dmsl_domain_thrift:'ExternalAccountSetObject'()}.
construct_external_account_set(Ref, Name, ?cur(CurrencyCode)) ->
ok = pm_context:save(pm_context:create()),
AccountID1 = pm_accounting:create_account(CurrencyCode),
@ -257,16 +236,17 @@ construct_external_account_set(Ref, Name, ?cur(CurrencyCode)) ->
data = #domain_ExternalAccountSet{
name = Name,
description = Name,
accounts = #{?cur(<<"RUB">>) => #domain_ExternalAccount{
income = AccountID1,
outcome = AccountID2
}}
accounts = #{
?cur(<<"RUB">>) => #domain_ExternalAccount{
income = AccountID1,
outcome = AccountID2
}
}
}
}}.
-spec construct_business_schedule(business_schedule()) ->
{business_schedule, dmsl_domain_thrift:'BusinessScheduleObject'()}.
construct_business_schedule(Ref) ->
{business_schedule, #domain_BusinessScheduleObject{
ref = Ref,
@ -284,9 +264,7 @@ construct_business_schedule(Ref) ->
}
}}.
-spec construct_criterion(criterion(), name(), predicate()) ->
{criterion, dmsl_domain_thrift:'CriterionObject'()}.
-spec construct_criterion(criterion(), name(), predicate()) -> {criterion, dmsl_domain_thrift:'CriterionObject'()}.
construct_criterion(Ref, Name, Pred) ->
{criterion, #domain_CriterionObject{
ref = Ref,
@ -298,7 +276,6 @@ construct_criterion(Ref, Name, Pred) ->
-spec construct_term_set_hierarchy(term_set_hierarchy(), term_set_hierarchy(), term_set()) ->
{term_set_hierarchy, dmsl_domain_thrift:'TermSetHierarchyObject'()}.
construct_term_set_hierarchy(Ref, ParentRef, TermSet) ->
{term_set_hierarchy, #domain_TermSetHierarchyObject{
ref = Ref,
@ -313,10 +290,8 @@ construct_term_set_hierarchy(Ref, ParentRef, TermSet) ->
}
}}.
-spec construct_payment_routing_ruleset(payment_routing_ruleset(), name(), _) ->
dmsl_domain_thrift:'PaymentRoutingRulesetObject'().
construct_payment_routing_ruleset(Ref, Name, Decisions) ->
{payment_routing_rules, #domain_PaymentRoutingRulesObject{
ref = Ref,

View File

@ -32,6 +32,7 @@
-include("pm_ct_domain.hrl").
-include("pm_ct_json.hrl").
-include_lib("damsel/include/dmsl_base_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
@ -44,182 +45,180 @@
-define(HELLGATE_HOST, "hellgate").
-define(HELLGATE_PORT, 8022).
-type app_name() :: atom().
-spec start_app(app_name()) -> [app_name()].
start_app(scoper = AppName) ->
{start_app(AppName, [
{storage, scoper_storage_logger}
]), #{}};
{storage, scoper_storage_logger}
]), #{}};
start_app(woody = AppName) ->
{start_app(AppName, [
{acceptors_pool_size, 4}
]), #{}};
{acceptors_pool_size, 4}
]), #{}};
start_app(dmt_client = AppName) ->
{start_app(AppName, [
{cache_update_interval, 5000}, % milliseconds
{max_cache_size, #{
elements => 20,
memory => 52428800 % 50Mb
}},
{woody_event_handlers, [
{scoper_woody_event_handler, #{
% milliseconds
{cache_update_interval, 5000},
{max_cache_size, #{
elements => 20,
% 50Mb
memory => 52428800
}},
{woody_event_handlers, [
{scoper_woody_event_handler, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
}
}
}}
]},
{service_urls, #{
'Repository' => <<"http://dominant:8022/v1/domain/repository">>,
'RepositoryClient' => <<"http://dominant:8022/v1/domain/repository_client">>
}}
]), #{}};
start_app(hellgate = AppName) ->
{start_app(AppName, [
{host, ?HELLGATE_HOST},
{port, ?HELLGATE_PORT},
{default_woody_handling_timeout, 30000},
{transport_opts, #{
max_connections => 8096
}},
{scoper_event_handler_options, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
}
}
}},
{services, #{
accounter => <<"http://shumway:8022/shumpune">>,
automaton => <<"http://machinegun:8022/v1/automaton">>,
customer_management => #{
url => <<"http://hellgate:8022/v1/processing/customer_management">>,
transport_opts => #{
pool => customer_management,
max_connections => 300
}
},
eventsink => <<"http://machinegun:8022/v1/event_sink">>,
fault_detector => <<"http://127.0.0.1:20001/">>,
invoice_templating => #{
url => <<"http://hellgate:8022/v1/processing/invoice_templating">>,
transport_opts => #{
pool => invoice_templating,
max_connections => 300
}
},
invoicing => #{
url => <<"http://hellgate:8022/v1/processing/invoicing">>,
transport_opts => #{
pool => invoicing,
max_connections => 300
}
},
party_management => #{
url => <<"http://hellgate:8022/v1/processing/partymgmt">>,
transport_opts => #{
pool => party_management,
max_connections => 300
}
},
recurrent_paytool => #{
url => <<"http://hellgate:8022/v1/processing/recpaytool">>,
transport_opts => #{
pool => recurrent_paytool,
max_connections => 300
}
}
}},
{proxy_opts, #{
transport_opts => #{
max_connections => 300
}
}},
{payment_retry_policy, #{
processed => {intervals, [1, 1, 1]},
captured => {intervals, [1, 1, 1]},
refunded => {intervals, [1, 1, 1]}
}},
{inspect_timeout, 1000},
{fault_detector, #{
% very low to speed up tests
timeout => 20,
availability => #{
critical_fail_rate => 0.7,
sliding_window => 60000,
operation_time_limit => 10000,
pre_aggregation_size => 2
},
conversion => #{
critical_fail_rate => 0.7,
sliding_window => 6000000,
operation_time_limit => 1200000,
pre_aggregation_size => 2
}
}}
]},
{service_urls, #{
'Repository' => <<"http://dominant:8022/v1/domain/repository">>,
'RepositoryClient' => <<"http://dominant:8022/v1/domain/repository_client">>
}}
]), #{}};
start_app(hellgate = AppName) ->
{start_app(AppName, [
{host, ?HELLGATE_HOST},
{port, ?HELLGATE_PORT},
{default_woody_handling_timeout, 30000},
{transport_opts, #{
max_connections => 8096
}},
{scoper_event_handler_options, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
}
}}},
{services, #{
accounter => <<"http://shumway:8022/shumpune">>,
automaton => <<"http://machinegun:8022/v1/automaton">>,
customer_management => #{
url => <<"http://hellgate:8022/v1/processing/customer_management">>,
transport_opts => #{
pool => customer_management,
max_connections => 300
}
},
eventsink => <<"http://machinegun:8022/v1/event_sink">>,
fault_detector => <<"http://127.0.0.1:20001/">>,
invoice_templating => #{
url => <<"http://hellgate:8022/v1/processing/invoice_templating">>,
transport_opts => #{
pool => invoice_templating,
max_connections => 300
}
},
invoicing => #{
url => <<"http://hellgate:8022/v1/processing/invoicing">>,
transport_opts => #{
pool => invoicing,
max_connections => 300
}
},
party_management => #{
url => <<"http://hellgate:8022/v1/processing/partymgmt">>,
transport_opts => #{
pool => party_management,
max_connections => 300
}
},
recurrent_paytool => #{
url => <<"http://hellgate:8022/v1/processing/recpaytool">>,
transport_opts => #{
pool => recurrent_paytool,
max_connections => 300
}
}
}},
{proxy_opts, #{
transport_opts => #{
max_connections => 300
}
}},
{payment_retry_policy, #{
processed => {intervals, [1, 1, 1]},
captured => {intervals, [1, 1, 1]},
refunded => {intervals, [1, 1, 1]}
}},
{inspect_timeout, 1000},
{fault_detector, #{
timeout => 20, % very low to speed up tests
availability => #{
critical_fail_rate => 0.7,
sliding_window => 60000,
operation_time_limit => 10000,
pre_aggregation_size => 2
},
conversion => #{
critical_fail_rate => 0.7,
sliding_window => 6000000,
operation_time_limit => 1200000,
pre_aggregation_size => 2
}
}}
]), #{
hellgate_root_url => get_hellgate_url()
}};
]), #{
hellgate_root_url => get_hellgate_url()
}};
start_app(party_management = AppName) ->
{start_app(AppName, [
{scoper_event_handler_options, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
{scoper_event_handler_options, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
}
}
}}},
{services, #{
accounter => <<"http://shumway:8022/shumpune">>,
automaton => <<"http://machinegun:8022/v1/automaton">>,
party_management => #{
url => <<"http://hellgate:8022/v1/processing/partymgmt">>,
transport_opts => #{
pool => party_management,
max_connections => 300
}},
{services, #{
accounter => <<"http://shumway:8022/shumpune">>,
automaton => <<"http://machinegun:8022/v1/automaton">>,
party_management => #{
url => <<"http://hellgate:8022/v1/processing/partymgmt">>,
transport_opts => #{
pool => party_management,
max_connections => 300
}
},
claim_committer => #{
url => <<"http://hellgate:8022/v1/processing/claim_committer">>,
transport_opts => #{
pool => claim_committer,
max_connections => 300
}
}
},
claim_committer => #{
url => <<"http://hellgate:8022/v1/processing/claim_committer">>,
transport_opts => #{
pool => claim_committer,
max_connections => 300
}
}
}}
]), #{}};
}}
]), #{}};
start_app(party_client = AppName) ->
{start_app(AppName, [
{services, #{
party_management => "http://hellgate:8022/v1/processing/partymgmt"
}},
{woody, #{
cache_mode => safe, % disabled | safe | aggressive
options => #{
woody_client => #{
event_handler => {scoper_woody_event_handler, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
}
}
}}
{services, #{
party_management => "http://hellgate:8022/v1/processing/partymgmt"
}},
{woody, #{
% disabled | safe | aggressive
cache_mode => safe,
options => #{
woody_client => #{
event_handler =>
{scoper_woody_event_handler, #{
event_handler_opts => #{
formatter_opts => #{
max_length => 1000
}
}
}}
}
}
}
}}
]), #{}};
}}
]), #{}};
start_app(AppName) ->
{genlib_app:start_application(AppName), #{}}.
-spec start_app(app_name(), list()) -> [app_name()].
start_app(cowboy = AppName, Env) ->
#{
listener_ref := Ref,
@ -229,12 +228,10 @@ start_app(cowboy = AppName, Env) ->
} = Env,
cowboy:start_clear(Ref, [{num_acceptors, Count} | TransOpt], ProtoOpt),
[AppName];
start_app(AppName, Env) ->
genlib_app:start_application_with(AppName, Env).
-spec start_apps([app_name() | {app_name(), list()}]) -> [app_name()].
start_apps(Apps) ->
lists:foldl(
fun
@ -248,31 +245,24 @@ start_apps(Apps) ->
Apps
).
-type config() :: [{atom(), term()}].
-type test_case_name() :: atom().
-type group_name() :: atom().
-spec cfg(atom(), config()) -> term().
cfg(Key, Config) ->
case lists:keyfind(Key, 1, Config) of
{Key, V} -> V;
_ -> undefined
_ -> undefined
end.
%%
-spec create_client(woody:url(), woody_user_identity:id()) ->
pm_client_api:t().
-spec create_client(woody:url(), woody_user_identity:id()) -> pm_client_api:t().
create_client(RootUrl, UserID) ->
create_client_w_context(RootUrl, UserID, woody_context:new()).
-spec create_client(woody:url(), woody_user_identity:id(), woody:trace_id()) ->
pm_client_api:t().
-spec create_client(woody:url(), woody_user_identity:id(), woody:trace_id()) -> pm_client_api:t().
create_client(RootUrl, UserID, TraceID) ->
create_client_w_context(RootUrl, UserID, woody_context:new(TraceID)).
@ -287,15 +277,15 @@ make_user_identity(UserID) ->
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-include_lib("party_management/include/party_events.hrl").
-type account_id() :: dmsl_domain_thrift:'AccountID'().
-type account() :: map().
-type balance() :: map().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contract_tpl() :: dmsl_domain_thrift:'ContractTemplateRef'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type category() :: dmsl_domain_thrift:'CategoryRef'().
-type currency() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
-type payment_institution() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
-type account_id() :: dmsl_domain_thrift:'AccountID'().
-type account() :: map().
-type balance() :: map().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type contract_tpl() :: dmsl_domain_thrift:'ContractTemplateRef'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type category() :: dmsl_domain_thrift:'CategoryRef'().
-type currency() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
-type payment_institution() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
-spec create_party_and_shop(
category(),
@ -303,9 +293,7 @@ make_user_identity(UserID) ->
contract_tpl(),
dmsl_domain_thrift:'PaymentInstitutionRef'(),
Client :: pid()
) ->
shop_id().
) -> shop_id().
create_party_and_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Client) ->
_ = pm_client_party:create(make_party_params(), Client),
#domain_Party{} = pm_client_party:get(Client),
@ -324,9 +312,7 @@ make_party_params() ->
contract_tpl(),
payment_institution(),
Client :: pid()
) ->
shop_id().
) -> shop_id().
create_battle_ready_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Client) ->
ContractID = pm_utils:unique_id(),
ContractParams = make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef),
@ -343,15 +329,16 @@ create_battle_ready_shop(Category, Currency, TemplateRef, PaymentInstitutionRef,
ShopAccountParams = #payproc_ShopAccountParams{currency = ?cur(Currency)},
Changeset = [
{contract_modification, #payproc_ContractModificationUnit{
id = ContractID,
id = ContractID,
modification = {creation, ContractParams}
}},
{contract_modification, #payproc_ContractModificationUnit{
id = ContractID,
modification = {payout_tool_modification, #payproc_PayoutToolModificationUnit{
payout_tool_id = PayoutToolID,
modification = {creation, PayoutToolParams}
}}
id = ContractID,
modification =
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
payout_tool_id = PayoutToolID,
modification = {creation, PayoutToolParams}
}}
}},
?shop_modification(ShopID, {creation, ShopParams}),
?shop_modification(ShopID, {shop_account_creation, ShopAccountParams})
@ -360,34 +347,29 @@ create_battle_ready_shop(Category, Currency, TemplateRef, PaymentInstitutionRef,
_Shop = pm_client_party:get_shop(ShopID, Client),
ShopID.
-spec create_contract(contract_tpl(), payment_institution(), Client :: pid()) ->
contract_id().
-spec create_contract(contract_tpl(), payment_institution(), Client :: pid()) -> contract_id().
create_contract(TemplateRef, PaymentInstitutionRef, Client) ->
ContractID = pm_utils:unique_id(),
ContractParams = make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef),
Changeset = [
{contract_modification, #payproc_ContractModificationUnit{
id = ContractID,
id = ContractID,
modification = {creation, ContractParams}
}}
],
ok = ensure_claim_accepted(pm_client_party:create_claim(Changeset, Client), Client),
ContractID.
-spec get_first_contract_id(Client :: pid()) ->
contract_id().
-spec get_first_contract_id(Client :: pid()) -> contract_id().
get_first_contract_id(Client) ->
#domain_Party{contracts = Contracts} = pm_client_party:get(Client),
lists:min(maps:keys(Contracts)).
-spec get_first_battle_ready_contract_id(Client :: pid()) ->
contract_id().
-spec get_first_battle_ready_contract_id(Client :: pid()) -> contract_id().
get_first_battle_ready_contract_id(Client) ->
#domain_Party{contracts = Contracts} = pm_client_party:get(Client),
IDs = lists:foldl(fun({ID, Contract}, Acc) ->
IDs = lists:foldl(
fun({ID, Contract}, Acc) ->
case Contract of
#domain_Contract{
contractor = {legal_entity, _},
@ -409,19 +391,26 @@ get_first_battle_ready_contract_id(Client) ->
end.
-spec adjust_contract(contract_id(), contract_tpl(), Client :: pid()) -> ok.
adjust_contract(ContractID, TemplateRef, Client) ->
ensure_claim_accepted(pm_client_party:create_claim([
{contract_modification, #payproc_ContractModificationUnit{
id = ContractID,
modification = {adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
adjustment_id = pm_utils:unique_id(),
modification = {creation, #payproc_ContractAdjustmentParams{
template = TemplateRef
ensure_claim_accepted(
pm_client_party:create_claim(
[
{contract_modification, #payproc_ContractModificationUnit{
id = ContractID,
modification =
{adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
adjustment_id = pm_utils:unique_id(),
modification =
{creation, #payproc_ContractAdjustmentParams{
template = TemplateRef
}}
}}
}}
}}
}}
], Client), Client).
],
Client
),
Client
).
ensure_claim_accepted(#payproc_Claim{id = ClaimID, revision = ClaimRevision, status = Status}, Client) ->
case Status of
@ -432,20 +421,16 @@ ensure_claim_accepted(#payproc_Claim{id = ClaimID, revision = ClaimRevision, sta
end.
-spec get_account(account_id()) -> account().
get_account(AccountID) ->
% TODO we sure need to proxy this through the hellgate interfaces
pm_accounting:get_account(AccountID).
-spec get_balance(account_id()) -> balance().
get_balance(AccountID) ->
% TODO we sure need to proxy this through the hellgate interfaces
pm_accounting:get_balance(AccountID).
-spec get_first_payout_tool_id(contract_id(), Client :: pid()) ->
dmsl_domain_thrift:'PayoutToolID'().
-spec get_first_payout_tool_id(contract_id(), Client :: pid()) -> dmsl_domain_thrift:'PayoutToolID'().
get_first_payout_tool_id(ContractID, Client) ->
#domain_Contract{payout_tools = PayoutTools} = pm_client_party:get_contract(ContractID, Client),
case PayoutTools of
@ -458,9 +443,7 @@ get_first_payout_tool_id(ContractID, Client) ->
-spec make_battle_ready_contract_params(
dmsl_domain_thrift:'ContractTemplateRef'() | undefined,
dmsl_domain_thrift:'PaymentInstitutionRef'()
) ->
dmsl_payment_processing_thrift:'ContractParams'().
) -> dmsl_payment_processing_thrift:'ContractParams'().
make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef) ->
#payproc_ContractParams{
contractor = make_battle_ready_contractor(),
@ -468,9 +451,7 @@ make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef) ->
payment_institution = PaymentInstitutionRef
}.
-spec make_battle_ready_contractor() ->
dmsl_payment_processing_thrift:'Contractor'().
-spec make_battle_ready_contractor() -> dmsl_payment_processing_thrift:'Contractor'().
make_battle_ready_contractor() ->
BankAccount = #domain_RussianBankAccount{
account = <<"4276300010908312893">>,
@ -479,7 +460,7 @@ make_battle_ready_contractor() ->
bank_bik = <<"66642666">>
},
{legal_entity,
{russian_legal_entity, #domain_RussianLegalEntity {
{russian_legal_entity, #domain_RussianLegalEntity{
registered_name = <<"Hoofs & Horns OJSC">>,
registered_number = <<"1234509876">>,
inn = <<"1213456789012">>,
@ -489,50 +470,41 @@ make_battle_ready_contractor() ->
representative_full_name = <<"Someone">>,
representative_document = <<"100$ banknote">>,
russian_bank_account = BankAccount
}}
}.
-spec make_battle_ready_payout_tool_params() ->
dmsl_payment_processing_thrift:'PayoutToolParams'().
}}}.
-spec make_battle_ready_payout_tool_params() -> dmsl_payment_processing_thrift:'PayoutToolParams'().
make_battle_ready_payout_tool_params() ->
#payproc_PayoutToolParams{
currency = ?cur(<<"RUB">>),
tool_info = {russian_bank_account, #domain_RussianBankAccount{
account = <<"4276300010908312893">>,
bank_name = <<"SomeBank">>,
bank_post_account = <<"123129876">>,
bank_bik = <<"66642666">>
}}
tool_info =
{russian_bank_account, #domain_RussianBankAccount{
account = <<"4276300010908312893">>,
bank_name = <<"SomeBank">>,
bank_post_account = <<"123129876">>,
bank_bik = <<"66642666">>
}}
}.
-spec make_shop_details(binary()) ->
dmsl_domain_thrift:'ShopDetails'().
-spec make_shop_details(binary()) -> dmsl_domain_thrift:'ShopDetails'().
make_shop_details(Name) ->
make_shop_details(Name, undefined).
-spec make_shop_details(binary(), binary()) ->
dmsl_domain_thrift:'ShopDetails'().
-spec make_shop_details(binary(), binary()) -> dmsl_domain_thrift:'ShopDetails'().
make_shop_details(Name, Description) ->
#domain_ShopDetails{
name = Name,
name = Name,
description = Description
}.
-spec make_meta_ns() -> dmsl_domain_thrift:'PartyMetaNamespace'().
make_meta_ns() ->
list_to_binary(lists:concat(["NS-", erlang:system_time()])).
-spec make_meta_data() -> dmsl_domain_thrift:'PartyMetaData'().
make_meta_data() ->
make_meta_data(<<"NS-0">>).
-spec make_meta_data(dmsl_domain_thrift:'PartyMetaNamespace'()) -> dmsl_domain_thrift:'PartyMetaData'().
make_meta_data(NS) ->
{obj, #{
{str, <<"NS">>} => {str, NS},
@ -541,6 +513,5 @@ make_meta_data(NS) ->
}}.
-spec get_hellgate_url() -> string().
get_hellgate_url() ->
"http://" ++ ?HELLGATE_HOST ++ ":" ++ integer_to_list(?HELLGATE_PORT).

View File

@ -5,4 +5,4 @@
-define(null(), {nl, #json_Null{}}).
-endif.
-endif.

File diff suppressed because it is too large Load Diff

View File

@ -11,21 +11,17 @@
-type t() :: {woody:url(), woody_context:ctx()}.
-spec new(woody:url()) -> t().
new(RootUrl) ->
new(RootUrl, construct_context()).
-spec new(woody:url(), woody_context:ctx()) -> t().
new(RootUrl, Context) ->
{RootUrl, Context}.
construct_context() ->
woody_context:new().
-spec call(Name :: atom(), woody:func(), [any()], t()) ->
{{ok, _Response} | {exception, _} | {error, _}, t()}.
-spec call(Name :: atom(), woody:func(), [any()], t()) -> {{ok, _Response} | {exception, _} | {error, _}, t()}.
call(ServiceName, Function, Args, {RootUrl, Context}) ->
Service = pm_proto:get_service(ServiceName),
ArgsTuple = list_to_tuple(Args),

View File

@ -1,4 +1,5 @@
-module(pm_client_event_poller).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-export([new/2]).
@ -13,8 +14,8 @@
-type rpc() :: {Name :: atom(), woody:func(), [_]}.
-opaque st(Event) :: #{
rpc := rpc(),
get_event_id := get_event_id(Event),
rpc := rpc(),
get_event_id := get_event_id(Event),
last_event_id => integer()
}.
@ -22,18 +23,15 @@
-define(POLL_INTERVAL, 1000).
-spec new(rpc(), get_event_id(Event)) ->
st(Event).
-spec new(rpc(), get_event_id(Event)) -> st(Event).
new(RPC, GetEventID) ->
#{
rpc => RPC,
rpc => RPC,
get_event_id => GetEventID
}.
-spec poll(pos_integer(), non_neg_integer(), pm_client_api:t(), st(Event)) ->
{[Event] | {exception | error, _}, pm_client_api:t(), st(Event)}.
poll(N, Timeout, Client, St) ->
poll(N, Timeout, [], Client, St).

View File

@ -1,4 +1,5 @@
-module(pm_client_party).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-export([start/2]).
@ -54,6 +55,7 @@
%% GenServer
-behaviour(gen_server).
-export([init/1]).
-export([handle_call/3]).
-export([handle_cast/2]).
@ -63,43 +65,40 @@
%%
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_params() :: dmsl_payment_processing_thrift:'PartyParams'().
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
-type party_id() :: dmsl_domain_thrift:'PartyID'().
-type party_params() :: dmsl_payment_processing_thrift:'PartyParams'().
-type domain_revision() :: dmsl_domain_thrift:'DataRevision'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
-type shop_account_id() :: dmsl_domain_thrift:'AccountID'().
-type meta() :: dmsl_domain_thrift:'PartyMeta'().
-type meta_ns() :: dmsl_domain_thrift:'PartyMetaNamespace'().
-type meta_data() :: dmsl_domain_thrift:'PartyMetaData'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type meta() :: dmsl_domain_thrift:'PartyMeta'().
-type meta_ns() :: dmsl_domain_thrift:'PartyMetaNamespace'().
-type meta_data() :: dmsl_domain_thrift:'PartyMetaData'().
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
-type party_revision_param() :: dmsl_payment_processing_thrift:'PartyRevisionParam'().
-type payment_intitution_ref() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
-type varset() :: dmsl_payment_processing_thrift:'Varset'().
-type provider_ref() :: dmsl_domain_thrift:'ProviderRef'().
-type terminal_ref() :: dmsl_domain_thrift:'TerminalRef'().
-type globals_ref() :: dmsl_domain_thrift:'GlobalsRef'().
-type provider_ref() :: dmsl_domain_thrift:'ProviderRef'().
-type terminal_ref() :: dmsl_domain_thrift:'TerminalRef'().
-type globals_ref() :: dmsl_domain_thrift:'GlobalsRef'().
-type payment_routring_ruleset_ref() :: dmsl_domain_thrift:'PaymentRoutingRulesetRef'().
-spec start(party_id(), pm_client_api:t()) -> pid().
start(PartyID, ApiClient) ->
start(start, undefined, PartyID, ApiClient).
-spec start(user_info(), party_id(), pm_client_api:t()) -> pid().
start(UserInfo, PartyID, ApiClient) ->
start(start, UserInfo, PartyID, ApiClient).
-spec start_link(party_id(), pm_client_api:t()) -> pid().
start_link(PartyID, ApiClient) ->
start(start_link, undefined, PartyID, ApiClient).
@ -108,212 +107,152 @@ start(Mode, UserInfo, PartyID, ApiClient) ->
Pid.
-spec stop(pid()) -> ok.
stop(Client) ->
_ = exit(Client, shutdown),
ok.
%%
-spec create(party_params(), pid()) ->
ok | woody_error:business_error().
-spec create(party_params(), pid()) -> ok | woody_error:business_error().
create(PartyParams, Client) ->
map_result_error(gen_server:call(Client, {call, 'Create', [PartyParams]})).
-spec get(pid()) ->
dmsl_domain_thrift:'Party'() | woody_error:business_error().
-spec get(pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
get(Client) ->
map_result_error(gen_server:call(Client, {call, 'Get', []})).
-spec get_revision(pid()) ->
dmsl_domain_thrift:'Party'() | woody_error:business_error().
-spec get_revision(pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
get_revision(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetRevision', []})).
-spec get_status(pid()) ->
dmsl_domain_thrift:'PartyStatus'() | woody_error:business_error().
-spec get_status(pid()) -> dmsl_domain_thrift:'PartyStatus'() | woody_error:business_error().
get_status(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetStatus', []})).
-spec checkout(party_revision_param(), pid()) ->
dmsl_domain_thrift:'Party'() | woody_error:business_error().
-spec checkout(party_revision_param(), pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
checkout(PartyRevisionParam, Client) ->
map_result_error(gen_server:call(Client, {call, 'Checkout', [PartyRevisionParam]})).
-spec block(binary(), pid()) ->
ok | woody_error:business_error().
-spec block(binary(), pid()) -> ok | woody_error:business_error().
block(Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'Block', [Reason]})).
-spec unblock(binary(), pid()) ->
ok | woody_error:business_error().
-spec unblock(binary(), pid()) -> ok | woody_error:business_error().
unblock(Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'Unblock', [Reason]})).
-spec suspend(pid()) ->
ok | woody_error:business_error().
-spec suspend(pid()) -> ok | woody_error:business_error().
suspend(Client) ->
map_result_error(gen_server:call(Client, {call, 'Suspend', []})).
-spec activate(pid()) ->
ok | woody_error:business_error().
-spec activate(pid()) -> ok | woody_error:business_error().
activate(Client) ->
map_result_error(gen_server:call(Client, {call, 'Activate', []})).
-spec get_meta(pid()) ->
meta() | woody_error:business_error().
-spec get_meta(pid()) -> meta() | woody_error:business_error().
get_meta(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetMeta', []})).
-spec get_metadata(meta_ns(), pid()) ->
meta_data() | woody_error:business_error().
-spec get_metadata(meta_ns(), pid()) -> meta_data() | woody_error:business_error().
get_metadata(NS, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetMetaData', [NS]})).
-spec set_metadata(meta_ns(), meta_data(), pid()) ->
ok | woody_error:business_error().
-spec set_metadata(meta_ns(), meta_data(), pid()) -> ok | woody_error:business_error().
set_metadata(NS, Data, Client) ->
map_result_error(gen_server:call(Client, {call, 'SetMetaData', [NS, Data]})).
-spec remove_metadata(meta_ns(), pid()) ->
ok | woody_error:business_error().
-spec remove_metadata(meta_ns(), pid()) -> ok | woody_error:business_error().
remove_metadata(NS, Client) ->
map_result_error(gen_server:call(Client, {call, 'RemoveMetaData', [NS]})).
-spec get_contract(contract_id(), pid()) ->
dmsl_domain_thrift:'Contract'() | woody_error:business_error().
-spec get_contract(contract_id(), pid()) -> dmsl_domain_thrift:'Contract'() | woody_error:business_error().
get_contract(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetContract', [ID]})).
-spec compute_contract_terms(contract_id(), timestamp(), party_revision_param(), domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_contract_terms(ID, Timestamp, PartyRevision, DomainRevision, Varset, Client) ->
Args = [ID, Timestamp, PartyRevision, DomainRevision, Varset],
map_result_error(gen_server:call(Client, {call, 'ComputeContractTerms', Args})).
-spec compute_payment_institution_terms(payment_intitution_ref(), varset(), pid()) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_payment_institution_terms(Ref, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputePaymentInstitutionTerms', [Ref, Varset]})).
-spec compute_payout_cash_flow(dmsl_payment_processing_thrift:'PayoutParams'(), pid()) ->
dmsl_domain_thrift:'FinalCashFlow'() | woody_error:business_error().
compute_payout_cash_flow(Params, Client) ->
map_result_error(gen_server:call(Client, {call, 'ComputePayoutCashFlow', [Params]})).
-spec get_shop(shop_id(), pid()) ->
dmsl_domain_thrift:'Shop'() | woody_error:business_error().
-spec get_shop(shop_id(), pid()) -> dmsl_domain_thrift:'Shop'() | woody_error:business_error().
get_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetShop', [ID]})).
-spec block_shop(shop_id(), binary(), pid()) ->
ok | woody_error:business_error().
-spec block_shop(shop_id(), binary(), pid()) -> ok | woody_error:business_error().
block_shop(ID, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'BlockShop', [ID, Reason]})).
-spec unblock_shop(shop_id(), binary(), pid()) ->
ok | woody_error:business_error().
-spec unblock_shop(shop_id(), binary(), pid()) -> ok | woody_error:business_error().
unblock_shop(ID, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'UnblockShop', [ID, Reason]})).
-spec suspend_shop(shop_id(), pid()) ->
ok | woody_error:business_error().
-spec suspend_shop(shop_id(), pid()) -> ok | woody_error:business_error().
suspend_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'SuspendShop', [ID]})).
-spec activate_shop(shop_id(), pid()) ->
ok | woody_error:business_error().
-spec activate_shop(shop_id(), pid()) -> ok | woody_error:business_error().
activate_shop(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'ActivateShop', [ID]})).
-spec compute_shop_terms(shop_id(), timestamp(), party_revision_param(), pid()) ->
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
compute_shop_terms(ID, Timestamp, PartyRevision, Client) ->
map_result_error(gen_server:call(Client, {call, 'ComputeShopTerms', [ID, Timestamp, PartyRevision]})).
-spec get_claim(claim_id(), pid()) ->
claim() | woody_error:business_error().
-spec get_claim(claim_id(), pid()) -> claim() | woody_error:business_error().
get_claim(ID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetClaim', [ID]})).
-spec get_claims(pid()) ->
[claim()] | woody_error:business_error().
-spec get_claims(pid()) -> [claim()] | woody_error:business_error().
get_claims(Client) ->
map_result_error(gen_server:call(Client, {call, 'GetClaims', []})).
-spec create_claim(changeset(), pid()) ->
claim() | woody_error:business_error().
-spec create_claim(changeset(), pid()) -> claim() | woody_error:business_error().
create_claim(Changeset, Client) ->
map_result_error(gen_server:call(Client, {call, 'CreateClaim', [Changeset]})).
-spec update_claim(claim_id(), claim_revision(), changeset(), pid()) ->
ok | woody_error:business_error().
-spec update_claim(claim_id(), claim_revision(), changeset(), pid()) -> ok | woody_error:business_error().
update_claim(ID, Revision, Changeset, Client) ->
map_result_error(gen_server:call(Client, {call, 'UpdateClaim', [ID, Revision, Changeset]})).
-spec accept_claim(claim_id(), claim_revision(), pid()) ->
ok | woody_error:business_error().
-spec accept_claim(claim_id(), claim_revision(), pid()) -> ok | woody_error:business_error().
accept_claim(ID, Revision, Client) ->
map_result_error(gen_server:call(Client, {call, 'AcceptClaim', [ID, Revision]})).
-spec deny_claim(claim_id(), claim_revision(), binary() | undefined, pid()) ->
ok | woody_error:business_error().
-spec deny_claim(claim_id(), claim_revision(), binary() | undefined, pid()) -> ok | woody_error:business_error().
deny_claim(ID, Revision, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'DenyClaim', [ID, Revision, Reason]})).
-spec revoke_claim(claim_id(), claim_revision(), binary() | undefined, pid()) ->
ok | woody_error:business_error().
-spec revoke_claim(claim_id(), claim_revision(), binary() | undefined, pid()) -> ok | woody_error:business_error().
revoke_claim(ID, Revision, Reason, Client) ->
map_result_error(gen_server:call(Client, {call, 'RevokeClaim', [ID, Revision, Reason]})).
-spec get_account_state(shop_account_id(), pid()) ->
dmsl_payment_processing_thrift:'AccountState'() | woody_error:business_error().
get_account_state(AccountID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetAccountState', [AccountID]})).
-spec get_shop_account(shop_id(), pid()) ->
dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error().
-spec get_shop_account(shop_id(), pid()) -> dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error().
get_shop_account(ShopID, Client) ->
map_result_error(gen_server:call(Client, {call, 'GetShopAccount', [ShopID]})).
-spec compute_provider(provider_ref(), domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'Provider'() | woody_error:business_error().
compute_provider(PaymentProviderRef, Revision, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeProvider',
[PaymentProviderRef, Revision, Varset]})).
map_result_error(
gen_server:call(Client, {call_without_party, 'ComputeProvider', [PaymentProviderRef, Revision, Varset]})
).
-spec compute_provider_terminal_terms(
provider_ref(),
@ -322,36 +261,36 @@ compute_provider(PaymentProviderRef, Revision, Varset, Client) ->
varset(),
pid()
) -> dmsl_domain_thrift:'ProvisionTermSet'() | woody_error:business_error().
compute_provider_terminal_terms(PaymentProviderRef, TerminalRef, Revision, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeProviderTerminalTerms',
[PaymentProviderRef, TerminalRef, Revision, Varset]})).
map_result_error(
gen_server:call(
Client,
{call_without_party, 'ComputeProviderTerminalTerms', [PaymentProviderRef, TerminalRef, Revision, Varset]}
)
).
-spec compute_globals(globals_ref(), domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'Globals'() | woody_error:business_error().
compute_globals(GlobalsRef, Revision, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeGlobals',
[GlobalsRef, Revision, Varset]})).
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeGlobals', [GlobalsRef, Revision, Varset]})).
-spec compute_payment_routing_ruleset(payment_routring_ruleset_ref(), domain_revision(), varset(), pid()) ->
dmsl_domain_thrift:'PaymentRoutingRuleset'() | woody_error:business_error().
compute_payment_routing_ruleset(PaymentRoutingRuleSetRef, Revision, Varset, Client) ->
map_result_error(gen_server:call(Client, {call_without_party, 'ComputePaymentRoutingRuleset',
[PaymentRoutingRuleSetRef, Revision, Varset]})).
map_result_error(
gen_server:call(
Client,
{call_without_party, 'ComputePaymentRoutingRuleset', [PaymentRoutingRuleSetRef, Revision, Varset]}
)
).
-define(DEFAULT_NEXT_EVENT_TIMEOUT, 5000).
-spec pull_event(pid()) ->
tuple() | timeout | woody_error:business_error().
-spec pull_event(pid()) -> tuple() | timeout | woody_error:business_error().
pull_event(Client) ->
pull_event(?DEFAULT_NEXT_EVENT_TIMEOUT, Client).
-spec pull_event(timeout(), pid()) ->
tuple() | timeout | woody_error:business_error().
-spec pull_event(timeout(), pid()) -> tuple() | timeout | woody_error:business_error().
pull_event(Timeout, Client) ->
gen_server:call(Client, {pull_event, Timeout}, infinity).
@ -368,17 +307,15 @@ map_result_error({error, Error}) ->
-record(st, {
user_info :: user_info(),
party_id :: party_id(),
poller :: pm_client_event_poller:st(event()),
client :: pm_client_api:t()
party_id :: party_id(),
poller :: pm_client_event_poller:st(event()),
client :: pm_client_api:t()
}).
-type st() :: #st{}.
-type callref() :: {pid(), Tag :: reference()}.
-spec init({user_info(), party_id(), pm_client_api:t()}) ->
{ok, st()}.
-spec init({user_info(), party_id(), pm_client_api:t()}) -> {ok, st()}.
init({UserInfo, PartyID, ApiClient}) ->
{ok, #st{
user_info = UserInfo,
@ -386,23 +323,19 @@ init({UserInfo, PartyID, ApiClient}) ->
client = ApiClient,
poller = pm_client_event_poller:new(
{party_management, 'GetEvents', [UserInfo, PartyID]},
fun (Event) -> Event#payproc_Event.id end
fun(Event) -> Event#payproc_Event.id end
)
}}.
-spec handle_call(term(), callref(), st()) ->
{reply, term(), st()} | {noreply, st()}.
-spec handle_call(term(), callref(), st()) -> {reply, term(), st()} | {noreply, st()}.
handle_call({call, Function, Args0}, _From, St = #st{client = Client}) ->
Args = [St#st.user_info, St#st.party_id | Args0],
{Result, ClientNext} = pm_client_api:call(party_management, Function, Args, Client),
{reply, Result, St#st{client = ClientNext}};
handle_call({call_without_party, Function, Args0}, _From, St = #st{client = Client}) ->
Args = [St#st.user_info | Args0],
{Result, ClientNext} = pm_client_api:call(party_management, Function, Args, Client),
{reply, Result, St#st{client = ClientNext}};
handle_call({pull_event, Timeout}, _From, St = #st{poller = Poller, client = Client}) ->
{Result, ClientNext, PollerNext} = pm_client_event_poller:poll(1, Timeout, Client, Poller),
StNext = St#st{poller = PollerNext, client = ClientNext},
@ -414,35 +347,24 @@ handle_call({pull_event, Timeout}, _From, St = #st{poller = Poller, client = Cli
Error ->
{reply, Error, StNext}
end;
handle_call(Call, _From, State) ->
_ = logger:warning("unexpected call received: ~tp", [Call]),
{noreply, State}.
-spec handle_cast(_, st()) ->
{noreply, st()}.
-spec handle_cast(_, st()) -> {noreply, st()}.
handle_cast(Cast, State) ->
_ = logger:warning("unexpected cast received: ~tp", [Cast]),
{noreply, State}.
-spec handle_info(_, st()) ->
{noreply, st()}.
-spec handle_info(_, st()) -> {noreply, st()}.
handle_info(Info, State) ->
_ = logger:warning("unexpected info received: ~tp", [Info]),
{noreply, State}.
-spec terminate(Reason, st()) ->
ok when
Reason :: normal | shutdown | {shutdown, term()} | term().
-spec terminate(Reason, st()) -> ok when Reason :: normal | shutdown | {shutdown, term()} | term().
terminate(_Reason, _State) ->
ok.
-spec code_change(Vsn | {down, Vsn}, st(), term()) ->
{error, noimpl} when
Vsn :: term().
-spec code_change(Vsn | {down, Vsn}, st(), term()) -> {error, noimpl} when Vsn :: term().
code_change(_OldVsn, _State, _Extra) ->
{error, noimpl}.

View File

@ -12,11 +12,10 @@
-define(VERSION_PREFIX, "/v1").
-type service() :: woody:service().
-type service() :: woody:service().
-type service_spec() :: {Path :: string(), service()}.
-spec get_service(Name :: atom()) -> service().
get_service(claim_committer) ->
{dmsl_claim_management_thrift, 'ClaimCommitter'};
get_service(party_management) ->
@ -29,12 +28,10 @@ get_service(processor) ->
{mg_proto_state_processing_thrift, 'Processor'}.
-spec get_service_spec(Name :: atom()) -> service_spec().
get_service_spec(Name) ->
get_service_spec(Name, #{}).
-spec get_service_spec(Name :: atom(), Opts :: #{namespace => binary()}) -> service_spec().
get_service_spec(Name = claim_committer, #{}) ->
{?VERSION_PREFIX ++ "/processing/claim_committer", get_service(Name)};
get_service_spec(Name = party_management, #{}) ->

View File

@ -25,12 +25,12 @@
thrift_struct_type().
-type thrift_base_type() ::
bool |
bool |
double |
i8 |
i16 |
i32 |
i64 |
i8 |
i16 |
i32 |
i64 |
string.
-type thrift_collection_type() ::
@ -67,30 +67,23 @@
%% API
-spec serialize_function_args(thrift_fun_full_ref(), woody:args()) ->
binary().
-spec serialize_function_args(thrift_fun_full_ref(), woody:args()) -> binary().
serialize_function_args({Module, {Service, Function}}, Args) when is_tuple(Args) ->
ArgsType = Module:function_info(Service, Function, params_type),
serialize(ArgsType, Args).
-spec serialize_function_reply(thrift_fun_full_ref(), term()) ->
binary().
-spec serialize_function_reply(thrift_fun_full_ref(), term()) -> binary().
serialize_function_reply({Module, {Service, Function}}, Data) ->
ArgsType = Module:function_info(Service, Function, reply_type),
serialize(ArgsType, Data).
-spec serialize_function_exception(thrift_fun_full_ref(), thrift_exception()) ->
binary().
-spec serialize_function_exception(thrift_fun_full_ref(), thrift_exception()) -> binary().
serialize_function_exception(FunctionRef, Exception) ->
ExceptionType = get_fun_exception_type(FunctionRef),
Name = find_exception_name(FunctionRef, Exception),
serialize(ExceptionType, {Name, Exception}).
-spec serialize(thrift_type(), term()) -> binary().
serialize(Type, Data) ->
Codec0 = thrift_strict_binary_codec:new(),
case thrift_strict_binary_codec:write(Codec0, Type, Data) of
@ -100,9 +93,7 @@ serialize(Type, Data) ->
erlang:error({thrift, {protocol, Reason}})
end.
-spec deserialize(thrift_type(), binary()) ->
term().
-spec deserialize(thrift_type(), binary()) -> term().
deserialize(Type, Data) ->
Codec0 = thrift_strict_binary_codec:new(Data),
case thrift_strict_binary_codec:read(Codec0, Type) of
@ -117,23 +108,17 @@ deserialize(Type, Data) ->
erlang:error({thrift, {protocol, Reason}})
end.
-spec deserialize_function_args(thrift_fun_full_ref(), binary()) ->
woody:args().
-spec deserialize_function_args(thrift_fun_full_ref(), binary()) -> woody:args().
deserialize_function_args({Module, {Service, Function}}, Data) ->
ArgsType = Module:function_info(Service, Function, params_type),
deserialize(ArgsType, Data).
-spec deserialize_function_reply(thrift_fun_full_ref(), binary()) ->
term().
-spec deserialize_function_reply(thrift_fun_full_ref(), binary()) -> term().
deserialize_function_reply({Module, {Service, Function}}, Data) ->
ArgsType = Module:function_info(Service, Function, reply_type),
deserialize(ArgsType, Data).
-spec deserialize_function_exception(thrift_fun_full_ref(), binary()) ->
thrift_exception().
-spec deserialize_function_exception(thrift_fun_full_ref(), binary()) -> thrift_exception().
deserialize_function_exception(FunctionRef, Data) ->
ExceptionType = get_fun_exception_type(FunctionRef),
{_Name, Exception} = deserialize(ExceptionType, Data),
@ -142,24 +127,24 @@ deserialize_function_exception(FunctionRef, Data) ->
%%
-spec record_to_proplist(Record :: tuple(), RecordInfo :: [atom()]) -> [{atom(), _}].
record_to_proplist(Record, RecordInfo) ->
element(1, lists:foldl(
fun (RecordField, {L, N}) ->
case element(N, Record) of
V when V /= undefined ->
{[{RecordField, V} | L], N + 1};
undefined ->
{L, N + 1}
end
end,
{[], 1 + 1},
RecordInfo
)).
-spec get_fun_exception_type(thrift_fun_full_ref()) ->
thrift_type().
element(
1,
lists:foldl(
fun(RecordField, {L, N}) ->
case element(N, Record) of
V when V /= undefined ->
{[{RecordField, V} | L], N + 1};
undefined ->
{L, N + 1}
end
end,
{[], 1 + 1},
RecordInfo
)
).
-spec get_fun_exception_type(thrift_fun_full_ref()) -> thrift_type().
get_fun_exception_type({Module, {Service, Function}}) ->
DeclaredType = Module:function_info(Service, Function, exceptions),
% В сгенерированном коде исключения объявлены как структура.
@ -167,9 +152,7 @@ get_fun_exception_type({Module, {Service, Function}}) ->
{struct, struct, Exceptions} = DeclaredType,
{struct, union, Exceptions}.
-spec find_exception_name(thrift_fun_full_ref(), thrift_exception()) ->
Name :: atom().
-spec find_exception_name(thrift_fun_full_ref(), thrift_exception()) -> Name :: atom().
find_exception_name({Module, {Service, Function}}, Exception) ->
case thrift_processor_codec:match_exception({Module, Service}, Function, Exception) of
{ok, {_Type, Name}} ->

@ -1 +1 @@
Subproject commit 91587cccf7f5dbb2b0ccf4ca3b838b22c8c588a0
Subproject commit e6b981649e073a2dbf646ab491212a2c951aeb19

View File

@ -103,6 +103,12 @@
]}
]}.
{plugins, [
rebar3_run
{erlfmt, "0.7.0"}
]}.
{erlfmt, [
{print_width, 120},
{files, "apps/*/{src,include,test}/*.{hrl,erl}"}
]}.