mirror of
https://github.com/valitydev/party-management.git
synced 2024-11-06 09:15:18 +00:00
parent
52967bd114
commit
8093d04623
8
Makefile
8
Makefile
@ -20,7 +20,7 @@ BASE_IMAGE_TAG := da0ab769f01b650b389d18fc85e7418e727cbe96
|
|||||||
BUILD_IMAGE_TAG := 442c2c274c1d8e484e5213089906a4271641d95e
|
BUILD_IMAGE_TAG := 442c2c274c1d8e484e5213089906a4271641d95e
|
||||||
|
|
||||||
CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze plt_update \
|
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
|
CALL_W_CONTAINER := $(CALL_ANYWHERE) test
|
||||||
|
|
||||||
@ -50,6 +50,12 @@ xref: submodules
|
|||||||
lint:
|
lint:
|
||||||
elvis rock
|
elvis rock
|
||||||
|
|
||||||
|
check_format:
|
||||||
|
$(REBAR) fmt -c
|
||||||
|
|
||||||
|
format:
|
||||||
|
$(REBAR) fmt -w
|
||||||
|
|
||||||
dialyze: submodules
|
dialyze: submodules
|
||||||
$(REBAR) dialyzer
|
$(REBAR) dialyzer
|
||||||
|
|
||||||
|
@ -3,38 +3,31 @@
|
|||||||
|
|
||||||
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
|
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
|
||||||
|
|
||||||
-define(
|
-define(cm_modification_unit(ModID, Timestamp, Mod, UserInfo), #claim_management_ModificationUnit{
|
||||||
cm_modification_unit(ModID, Timestamp, Mod, UserInfo),
|
modification_id = ModID,
|
||||||
#claim_management_ModificationUnit{
|
created_at = Timestamp,
|
||||||
modification_id = ModID,
|
modification = Mod,
|
||||||
created_at = Timestamp,
|
user_info = UserInfo
|
||||||
modification = Mod,
|
}).
|
||||||
user_info = UserInfo
|
|
||||||
}
|
|
||||||
).
|
|
||||||
|
|
||||||
-define(
|
-define(cm_party_modification(ModID, Timestamp, Mod, UserInfo),
|
||||||
cm_party_modification(ModID, Timestamp, Mod, UserInfo),
|
|
||||||
?cm_modification_unit(ModID, Timestamp, {party_modification, Mod}, UserInfo)
|
?cm_modification_unit(ModID, Timestamp, {party_modification, Mod}, UserInfo)
|
||||||
).
|
).
|
||||||
|
|
||||||
%%% Contractor
|
%%% Contractor
|
||||||
|
|
||||||
-define(
|
-define(cm_contractor_modification(ContractorID, Mod),
|
||||||
cm_contractor_modification(ContractorID, Mod),
|
|
||||||
{contractor_modification, #claim_management_ContractorModificationUnit{
|
{contractor_modification, #claim_management_ContractorModificationUnit{
|
||||||
id = ContractorID,
|
id = ContractorID,
|
||||||
modification = Mod
|
modification = Mod
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_contractor_creation(ContractorID, Contractor),
|
||||||
cm_contractor_creation(ContractorID, Contractor),
|
|
||||||
?cm_contractor_modification(ContractorID, {creation, Contractor})
|
?cm_contractor_modification(ContractorID, {creation, Contractor})
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_identity_documents_modification(Documents),
|
||||||
cm_identity_documents_modification(Documents),
|
|
||||||
{
|
{
|
||||||
identity_documents_modification,
|
identity_documents_modification,
|
||||||
#claim_management_ContractorIdentityDocumentsModification{
|
#claim_management_ContractorIdentityDocumentsModification{
|
||||||
@ -43,87 +36,75 @@
|
|||||||
}
|
}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_contractor_identity_documents_modification(ContractorID, Documents),
|
||||||
cm_contractor_identity_documents_modification(ContractorID, Documents),
|
|
||||||
?cm_contractor_modification(ContractorID, ?cm_identity_documents_modification(Documents))
|
?cm_contractor_modification(ContractorID, ?cm_identity_documents_modification(Documents))
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_contractor_identification_level_modification(ContractorID, Level),
|
||||||
cm_contractor_identification_level_modification(ContractorID, Level),
|
|
||||||
?cm_contractor_modification(ContractorID, {identification_level_modification, Level})
|
?cm_contractor_modification(ContractorID, {identification_level_modification, Level})
|
||||||
).
|
).
|
||||||
|
|
||||||
%%% Contract
|
%%% Contract
|
||||||
|
|
||||||
-define(
|
-define(cm_contract_modification(ContractID, Mod),
|
||||||
cm_contract_modification(ContractID, Mod),
|
|
||||||
{contract_modification, #claim_management_ContractModificationUnit{
|
{contract_modification, #claim_management_ContractModificationUnit{
|
||||||
id = ContractID,
|
id = ContractID,
|
||||||
modification = Mod
|
modification = Mod
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_contract_creation(ContractID, ContractParams),
|
||||||
cm_contract_creation(ContractID, ContractParams),
|
|
||||||
?cm_contract_modification(ContractID, {creation, ContractParams})
|
?cm_contract_modification(ContractID, {creation, ContractParams})
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(cm_contract_termination(Reason),
|
-define(cm_contract_termination(Reason),
|
||||||
{termination, #claim_management_ContractTermination{reason = Reason}}).
|
{termination, #claim_management_ContractTermination{reason = Reason}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_payout_tool_modification(PayoutToolID, Mod),
|
||||||
cm_payout_tool_modification(PayoutToolID, Mod),
|
|
||||||
{payout_tool_modification, #claim_management_PayoutToolModificationUnit{
|
{payout_tool_modification, #claim_management_PayoutToolModificationUnit{
|
||||||
payout_tool_id = PayoutToolID,
|
payout_tool_id = PayoutToolID,
|
||||||
modification = Mod
|
modification = Mod
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_payout_tool_creation(PayoutToolID, PayoutToolParams),
|
||||||
cm_payout_tool_creation(PayoutToolID, PayoutToolParams),
|
|
||||||
?cm_payout_tool_modification(PayoutToolID, {creation, PayoutToolParams})
|
?cm_payout_tool_modification(PayoutToolID, {creation, PayoutToolParams})
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_payout_tool_info_modification(PayoutToolID, Info),
|
||||||
cm_payout_tool_info_modification(PayoutToolID, Info),
|
|
||||||
?cm_payout_tool_modification(PayoutToolID, {info_modification, Info})
|
?cm_payout_tool_modification(PayoutToolID, {info_modification, Info})
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_payout_schedule_modification(BusinessScheduleRef),
|
||||||
cm_payout_schedule_modification(BusinessScheduleRef),
|
|
||||||
{payout_schedule_modification, #claim_management_ScheduleModification{
|
{payout_schedule_modification, #claim_management_ScheduleModification{
|
||||||
schedule = BusinessScheduleRef
|
schedule = BusinessScheduleRef
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_cash_register_unit_creation(ID, Params),
|
||||||
cm_cash_register_unit_creation(ID, Params),
|
|
||||||
{creation, #claim_management_CashRegisterParams{
|
{creation, #claim_management_CashRegisterParams{
|
||||||
cash_register_provider_id = ID,
|
cash_register_provider_id = ID,
|
||||||
cash_register_provider_params = Params
|
cash_register_provider_params = Params
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_cash_register_modification_unit_modification(ShopID, Unit),
|
||||||
cm_cash_register_modification_unit_modification(ShopID, Unit),
|
|
||||||
?cm_shop_modification(ShopID, {cash_register_modification_unit, Unit})
|
?cm_shop_modification(ShopID, {cash_register_modification_unit, Unit})
|
||||||
).
|
).
|
||||||
|
|
||||||
-define (
|
-define(cm_cash_register_modification_unit(Unit),
|
||||||
cm_cash_register_modification_unit(Unit),
|
|
||||||
{cash_register_modification_unit, Unit}
|
{cash_register_modification_unit, Unit}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_adjustment_modification(ContractAdjustmentID, Mod),
|
||||||
cm_adjustment_modification(ContractAdjustmentID, Mod),
|
|
||||||
{adjustment_modification, #claim_management_ContractAdjustmentModificationUnit{
|
{adjustment_modification, #claim_management_ContractAdjustmentModificationUnit{
|
||||||
adjustment_id = ContractAdjustmentID,
|
adjustment_id = ContractAdjustmentID,
|
||||||
modification = Mod
|
modification = Mod
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_adjustment_creation(ContractAdjustmentID, ContractTemplateRef),
|
||||||
cm_adjustment_creation(ContractAdjustmentID, ContractTemplateRef),
|
|
||||||
?cm_adjustment_modification(
|
?cm_adjustment_modification(
|
||||||
ContractAdjustmentID,
|
ContractAdjustmentID,
|
||||||
{creation, #claim_management_ContractAdjustmentParams{
|
{creation, #claim_management_ContractAdjustmentParams{
|
||||||
@ -134,40 +115,35 @@
|
|||||||
|
|
||||||
%%% Shop
|
%%% Shop
|
||||||
|
|
||||||
-define(
|
-define(cm_shop_modification(ShopID, Mod),
|
||||||
cm_shop_modification(ShopID, Mod),
|
|
||||||
{shop_modification, #claim_management_ShopModificationUnit{
|
{shop_modification, #claim_management_ShopModificationUnit{
|
||||||
id = ShopID,
|
id = ShopID,
|
||||||
modification = Mod
|
modification = Mod
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_shop_contract_modification(ContractID, PayoutToolID),
|
||||||
cm_shop_contract_modification(ContractID, PayoutToolID),
|
|
||||||
{contract_modification, #claim_management_ShopContractModification{
|
{contract_modification, #claim_management_ShopContractModification{
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID
|
payout_tool_id = PayoutToolID
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_shop_creation(ShopID, ShopParams),
|
||||||
cm_shop_creation(ShopID, ShopParams),
|
|
||||||
?cm_shop_modification(ShopID, {creation, ShopParams})
|
?cm_shop_modification(ShopID, {creation, ShopParams})
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_shop_account_creation_params(CurrencyRef),
|
||||||
cm_shop_account_creation_params(CurrencyRef),
|
|
||||||
{shop_account_creation, #claim_management_ShopAccountParams{
|
{shop_account_creation, #claim_management_ShopAccountParams{
|
||||||
currency = CurrencyRef
|
currency = CurrencyRef
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(
|
-define(cm_shop_account_creation(ShopID, CurrencyRef),
|
||||||
cm_shop_account_creation(ShopID, CurrencyRef),
|
|
||||||
?cm_shop_modification(
|
?cm_shop_modification(
|
||||||
ShopID,
|
ShopID,
|
||||||
?cm_shop_account_creation_params(CurrencyRef)
|
?cm_shop_account_creation_params(CurrencyRef)
|
||||||
)
|
)
|
||||||
).
|
).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
-ifndef(__pm_domain_hrl__).
|
-ifndef(__pm_domain_hrl__).
|
||||||
-define(__pm_domain_hrl__, included).
|
-define(__pm_domain_hrl__, included).
|
||||||
|
|
||||||
-define(currency(SymCode),
|
-define(currency(SymCode), #domain_CurrencyRef{symbolic_code = SymCode}).
|
||||||
#domain_CurrencyRef{symbolic_code = SymCode}).
|
|
||||||
|
|
||||||
-define(cash(Amount, SymCode),
|
-define(cash(Amount, SymCode), #domain_Cash{amount = Amount, currency = ?currency(SymCode)}).
|
||||||
#domain_Cash{amount = Amount, currency = ?currency(SymCode)}).
|
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
@ -2,279 +2,204 @@
|
|||||||
-define(__pm_legacy_party_structures_hrl__, included).
|
-define(__pm_legacy_party_structures_hrl__, included).
|
||||||
|
|
||||||
-define(legacy_party_created(Party),
|
-define(legacy_party_created(Party),
|
||||||
{party_created, Party}).
|
{party_created, Party}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_party(ID, ContactInfo, CreatedAt, Blocking, Suspension, Contracts, Shops),
|
-define(legacy_party(ID, ContactInfo, CreatedAt, Blocking, Suspension, Contracts, Shops),
|
||||||
{domain_Party,
|
{domain_Party, ID, ContactInfo, CreatedAt, Blocking, Suspension, Contracts, Shops}
|
||||||
ID,
|
).
|
||||||
ContactInfo,
|
|
||||||
CreatedAt,
|
|
||||||
Blocking,
|
|
||||||
Suspension,
|
|
||||||
Contracts,
|
|
||||||
Shops
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_claim(
|
-define(legacy_claim(
|
||||||
ID,
|
ID,
|
||||||
Status,
|
Status,
|
||||||
Changeset,
|
Changeset,
|
||||||
Revision,
|
Revision,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
UpdatedAt
|
UpdatedAt
|
||||||
),
|
),
|
||||||
{payproc_Claim,
|
{payproc_Claim, ID, Status, Changeset, Revision, CreatedAt, UpdatedAt}
|
||||||
ID,
|
|
||||||
Status,
|
|
||||||
Changeset,
|
|
||||||
Revision,
|
|
||||||
CreatedAt,
|
|
||||||
UpdatedAt
|
|
||||||
}
|
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(legacy_claim_updated(ID, Changeset, ClaimRevision, Timestamp),
|
-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),
|
-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),
|
-define(legacy_contract_params_v1(Contractor, TemplateRef),
|
||||||
{payproc_ContractParams, Contractor, TemplateRef}).
|
{payproc_ContractParams, Contractor, TemplateRef}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_contract_params_v2(Contractor, TemplateRef, PaymentInstitutionRef),
|
-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),
|
-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),
|
-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),
|
-define(legacy_payout_tool_params(Currency, PayoutToolInfo),
|
||||||
{payproc_PayoutToolParams, Currency, PayoutToolInfo}).
|
{payproc_PayoutToolParams, Currency, PayoutToolInfo}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_russian_legal_entity(
|
-define(legacy_russian_legal_entity(
|
||||||
RegisteredName,
|
RegisteredName,
|
||||||
RegisteredNumber,
|
RegisteredNumber,
|
||||||
Inn,
|
Inn,
|
||||||
ActualAddress,
|
ActualAddress,
|
||||||
PostAddress,
|
PostAddress,
|
||||||
RepresentativePosition,
|
RepresentativePosition,
|
||||||
RepresentativeFullName,
|
RepresentativeFullName,
|
||||||
RepresentativeDocument,
|
RepresentativeDocument,
|
||||||
BankAccount
|
BankAccount
|
||||||
),
|
),
|
||||||
{domain_RussianLegalEntity,
|
{domain_RussianLegalEntity, RegisteredName, RegisteredNumber, Inn, ActualAddress, PostAddress,
|
||||||
RegisteredName,
|
RepresentativePosition, RepresentativeFullName, RepresentativeDocument, BankAccount}
|
||||||
RegisteredNumber,
|
).
|
||||||
Inn,
|
|
||||||
ActualAddress,
|
|
||||||
PostAddress,
|
|
||||||
RepresentativePosition,
|
|
||||||
RepresentativeFullName,
|
|
||||||
RepresentativeDocument,
|
|
||||||
BankAccount
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_international_legal_entity(LegalName, TradingName, RegisteredAddress, ActualAddress),
|
-define(legacy_international_legal_entity(LegalName, TradingName, RegisteredAddress, ActualAddress),
|
||||||
{domain_InternationalLegalEntity,
|
{domain_InternationalLegalEntity, LegalName, TradingName, RegisteredAddress, ActualAddress}
|
||||||
LegalName,
|
).
|
||||||
TradingName,
|
|
||||||
RegisteredAddress,
|
|
||||||
ActualAddress
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_bank_account(Account, BankName, BankPostAccount, BankBik),
|
-define(legacy_bank_account(Account, BankName, BankPostAccount, BankBik),
|
||||||
{domain_BankAccount,
|
{domain_BankAccount, Account, BankName, BankPostAccount, BankBik}
|
||||||
Account,
|
).
|
||||||
BankName,
|
|
||||||
BankPostAccount,
|
|
||||||
BankBik
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_international_bank_account(AccountHolder, BankName, BankAddress, Iban, Bic),
|
-define(legacy_international_bank_account(AccountHolder, BankName, BankAddress, Iban, Bic),
|
||||||
{domain_InternationalBankAccount,
|
{domain_InternationalBankAccount, AccountHolder, BankName, BankAddress, Iban, Bic}
|
||||||
AccountHolder,
|
).
|
||||||
BankName,
|
|
||||||
BankAddress,
|
|
||||||
Iban,
|
|
||||||
Bic
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_international_bank_account_v3_4_5(AccountHolder, BankName, BankAddress, Iban, Bic, LocalBankCode),
|
-define(legacy_international_bank_account_v3_4_5(AccountHolder, BankName, BankAddress, Iban, Bic, LocalBankCode),
|
||||||
{domain_InternationalBankAccount,
|
{domain_InternationalBankAccount, AccountHolder, BankName, BankAddress, Iban, Bic, LocalBankCode}
|
||||||
AccountHolder,
|
).
|
||||||
BankName,
|
|
||||||
BankAddress,
|
|
||||||
Iban,
|
|
||||||
Bic,
|
|
||||||
LocalBankCode
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_shop_modification(ID, Modification),
|
-define(legacy_shop_modification(ID, Modification),
|
||||||
{shop_modification, {payproc_ShopModificationUnit, ID, Modification}}).
|
{shop_modification, {payproc_ShopModificationUnit, ID, Modification}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_schedule_modification(PayoutScheduleRef),
|
-define(legacy_schedule_modification(PayoutScheduleRef),
|
||||||
{payproc_ScheduleModification, PayoutScheduleRef}).
|
{payproc_ScheduleModification, PayoutScheduleRef}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_shop_effect(ID, Effect),
|
-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),
|
-define(legacy_shop_v2(
|
||||||
{domain_Shop,
|
ID,
|
||||||
ID,
|
CreatedAt,
|
||||||
CreatedAt,
|
Blocking,
|
||||||
Blocking,
|
Suspension,
|
||||||
Suspension,
|
Details,
|
||||||
Details,
|
Location,
|
||||||
Location,
|
Category,
|
||||||
Category,
|
Account,
|
||||||
Account,
|
ContractID,
|
||||||
ContractID,
|
PayoutToolID
|
||||||
PayoutToolID
|
),
|
||||||
}).
|
{domain_Shop, ID, CreatedAt, Blocking, Suspension, Details, Location, Category, Account, ContractID, PayoutToolID}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_shop_v3(
|
-define(legacy_shop_v3(
|
||||||
ID,
|
ID,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
Blocking,
|
Blocking,
|
||||||
Suspension,
|
Suspension,
|
||||||
Details,
|
Details,
|
||||||
Location,
|
Location,
|
||||||
Category,
|
Category,
|
||||||
Account,
|
Account,
|
||||||
ContractID,
|
ContractID,
|
||||||
PayoutToolID,
|
PayoutToolID,
|
||||||
PayoutScheduleRef
|
PayoutScheduleRef
|
||||||
),
|
),
|
||||||
{domain_Shop,
|
{domain_Shop, ID, CreatedAt, Blocking, Suspension, Details, Location, Category, Account, ContractID, PayoutToolID,
|
||||||
ID,
|
PayoutScheduleRef}
|
||||||
CreatedAt,
|
).
|
||||||
Blocking,
|
|
||||||
Suspension,
|
|
||||||
Details,
|
|
||||||
Location,
|
|
||||||
Category,
|
|
||||||
Account,
|
|
||||||
ContractID,
|
|
||||||
PayoutToolID,
|
|
||||||
PayoutScheduleRef
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_payout_schedule_ref(ID),
|
-define(legacy_payout_schedule_ref(ID),
|
||||||
{domain_PayoutScheduleRef, ID}).
|
{domain_PayoutScheduleRef, ID}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_schedule_changed(PayoutScheduleRef),
|
-define(legacy_schedule_changed(PayoutScheduleRef),
|
||||||
{payproc_ScheduleChanged, PayoutScheduleRef}).
|
{payproc_ScheduleChanged, PayoutScheduleRef}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_contract_effect(ID, Effect),
|
-define(legacy_contract_effect(ID, Effect),
|
||||||
{contract_effect, {payproc_ContractEffectUnit, ID, Effect}}).
|
{contract_effect, {payproc_ContractEffectUnit, ID, Effect}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(legacy_contract_v1(
|
-define(legacy_contract_v1(
|
||||||
ID,
|
ID,
|
||||||
Contractor,
|
Contractor,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
ValidSince,
|
ValidSince,
|
||||||
ValidUntil,
|
ValidUntil,
|
||||||
Status,
|
Status,
|
||||||
Terms,
|
Terms,
|
||||||
Adjustments,
|
Adjustments,
|
||||||
PayoutTools,
|
PayoutTools,
|
||||||
LegalAgreement
|
LegalAgreement
|
||||||
),
|
),
|
||||||
{domain_Contract,
|
{domain_Contract, ID, Contractor, CreatedAt, ValidSince, ValidUntil, Status, Terms, Adjustments, PayoutTools,
|
||||||
ID,
|
LegalAgreement}
|
||||||
Contractor,
|
|
||||||
CreatedAt,
|
|
||||||
ValidSince,
|
|
||||||
ValidUntil,
|
|
||||||
Status,
|
|
||||||
Terms,
|
|
||||||
Adjustments,
|
|
||||||
PayoutTools,
|
|
||||||
LegalAgreement
|
|
||||||
}
|
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(legacy_contract_v2_3(
|
-define(legacy_contract_v2_3(
|
||||||
ID,
|
ID,
|
||||||
Contractor,
|
Contractor,
|
||||||
PaymentInstitutionRef,
|
PaymentInstitutionRef,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
ValidSince,
|
ValidSince,
|
||||||
ValidUntil,
|
ValidUntil,
|
||||||
Status,
|
Status,
|
||||||
Terms,
|
Terms,
|
||||||
Adjustments,
|
Adjustments,
|
||||||
PayoutTools,
|
PayoutTools,
|
||||||
LegalAgreement
|
LegalAgreement
|
||||||
),
|
),
|
||||||
{domain_Contract,
|
{domain_Contract, ID, Contractor, PaymentInstitutionRef, CreatedAt, ValidSince, ValidUntil, Status, Terms,
|
||||||
ID,
|
Adjustments, PayoutTools, LegalAgreement}
|
||||||
Contractor,
|
|
||||||
PaymentInstitutionRef,
|
|
||||||
CreatedAt,
|
|
||||||
ValidSince,
|
|
||||||
ValidUntil,
|
|
||||||
Status,
|
|
||||||
Terms,
|
|
||||||
Adjustments,
|
|
||||||
PayoutTools,
|
|
||||||
LegalAgreement
|
|
||||||
}
|
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(legacy_contract_v4(
|
-define(legacy_contract_v4(
|
||||||
ID,
|
ID,
|
||||||
Contractor,
|
Contractor,
|
||||||
PaymentInstitutionRef,
|
PaymentInstitutionRef,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
ValidSince,
|
ValidSince,
|
||||||
ValidUntil,
|
ValidUntil,
|
||||||
Status,
|
Status,
|
||||||
Terms,
|
Terms,
|
||||||
Adjustments,
|
Adjustments,
|
||||||
PayoutTools,
|
PayoutTools,
|
||||||
LegalAgreement,
|
LegalAgreement,
|
||||||
ReportPreferences
|
ReportPreferences
|
||||||
),
|
),
|
||||||
{domain_Contract,
|
{domain_Contract, ID, Contractor, PaymentInstitutionRef, CreatedAt, ValidSince, ValidUntil, Status, Terms,
|
||||||
ID,
|
Adjustments, PayoutTools, LegalAgreement, ReportPreferences}
|
||||||
Contractor,
|
|
||||||
PaymentInstitutionRef,
|
|
||||||
CreatedAt,
|
|
||||||
ValidSince,
|
|
||||||
ValidUntil,
|
|
||||||
Status,
|
|
||||||
Terms,
|
|
||||||
Adjustments,
|
|
||||||
PayoutTools,
|
|
||||||
LegalAgreement,
|
|
||||||
ReportPreferences
|
|
||||||
}
|
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(legacy_payout_tool(
|
-define(legacy_payout_tool(
|
||||||
ID,
|
ID,
|
||||||
CreatedAt,
|
CreatedAt,
|
||||||
Currency,
|
Currency,
|
||||||
PayoutToolInfo
|
PayoutToolInfo
|
||||||
),
|
),
|
||||||
{domain_PayoutTool,
|
{domain_PayoutTool, ID, CreatedAt, Currency, PayoutToolInfo}
|
||||||
ID,
|
).
|
||||||
CreatedAt,
|
|
||||||
Currency,
|
|
||||||
PayoutToolInfo
|
|
||||||
}).
|
|
||||||
|
|
||||||
-define(legacy_legal_agreement(
|
-define(legacy_legal_agreement(
|
||||||
SignedAt,
|
SignedAt,
|
||||||
LegalAgreementID
|
LegalAgreementID
|
||||||
),
|
),
|
||||||
{domain_LegalAgreement,
|
{domain_LegalAgreement, SignedAt, LegalAgreementID}
|
||||||
SignedAt,
|
).
|
||||||
LegalAgreementID
|
|
||||||
}).
|
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
id = PartyID,
|
id = PartyID,
|
||||||
contact_info = ContactInfo,
|
contact_info = ContactInfo,
|
||||||
created_at = Timestamp
|
created_at = Timestamp
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(party_blocking(Blocking), {party_blocking, Blocking}).
|
-define(party_blocking(Blocking), {party_blocking, Blocking}).
|
||||||
-define(party_suspension(Suspension), {party_suspension, Suspension}).
|
-define(party_suspension(Suspension), {party_suspension, Suspension}).
|
||||||
@ -19,19 +20,26 @@
|
|||||||
{party_meta_set, #payproc_PartyMetaSet{
|
{party_meta_set, #payproc_PartyMetaSet{
|
||||||
ns = NS,
|
ns = NS,
|
||||||
data = Data
|
data = Data
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(party_meta_removed(NS), {party_meta_removed, NS}).
|
-define(party_meta_removed(NS), {party_meta_removed, NS}).
|
||||||
|
|
||||||
-define(shop_blocking(ID, Blocking),
|
-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),
|
-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),
|
-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),
|
-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(blocked(Reason, Since), {blocked, #domain_Blocked{reason = Reason, since = Since}}).
|
||||||
-define(unblocked(Reason, Since), {unblocked, #domain_Unblocked{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(suspended(Since), {suspended, #domain_Suspended{since = Since}}).
|
||||||
|
|
||||||
-define(contractor_modification(ID, Modification),
|
-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),
|
-define(identity_documents_modification(Docs),
|
||||||
{identity_documents_modification, #payproc_ContractorIdentityDocumentsModification{
|
{identity_documents_modification, #payproc_ContractorIdentityDocumentsModification{
|
||||||
identity_documents = Docs
|
identity_documents = Docs
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(contractor_effect(ID, Effect),
|
-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),
|
-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),
|
-define(contract_termination(Reason),
|
||||||
{termination, #payproc_ContractTermination{reason = Reason}}).
|
{termination, #payproc_ContractTermination{reason = Reason}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(adjustment_creation(ID, Params),
|
-define(adjustment_creation(ID, Params),
|
||||||
{adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
|
{adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
|
||||||
adjustment_id = ID,
|
adjustment_id = ID,
|
||||||
modification = {creation, Params}
|
modification = {creation, Params}
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(payout_tool_creation(ID, Params),
|
-define(payout_tool_creation(ID, Params),
|
||||||
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
|
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
|
||||||
payout_tool_id = ID,
|
payout_tool_id = ID,
|
||||||
modification = {creation, Params}
|
modification = {creation, Params}
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(payout_tool_info_modification(ID, Info),
|
-define(payout_tool_info_modification(ID, Info),
|
||||||
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
|
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
|
||||||
payout_tool_id = ID,
|
payout_tool_id = ID,
|
||||||
modification = {info_modification, Info}
|
modification = {info_modification, Info}
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(shop_modification(ID, Modification),
|
-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),
|
-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(
|
-define(shop_account_creation_params(CurrencyRef),
|
||||||
shop_account_creation_params(CurrencyRef),
|
|
||||||
{shop_account_creation, #payproc_ShopAccountParams{
|
{shop_account_creation, #payproc_ShopAccountParams{
|
||||||
currency = CurrencyRef
|
currency = CurrencyRef
|
||||||
}}
|
}}
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(proxy_modification(Proxy),
|
-define(proxy_modification(Proxy),
|
||||||
{proxy_modification, #payproc_ProxyModification{proxy = Proxy}}).
|
{proxy_modification, #payproc_ProxyModification{proxy = Proxy}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(payout_schedule_modification(BusinessScheduleRef),
|
-define(payout_schedule_modification(BusinessScheduleRef),
|
||||||
{payout_schedule_modification, #payproc_ScheduleModification{schedule = BusinessScheduleRef}}).
|
{payout_schedule_modification, #payproc_ScheduleModification{schedule = BusinessScheduleRef}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(contract_effect(ID, Effect),
|
-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),
|
-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),
|
-define(payout_schedule_changed(BusinessScheduleRef),
|
||||||
{payout_schedule_changed, #payproc_ScheduleChanged{schedule = BusinessScheduleRef}}).
|
{payout_schedule_changed, #payproc_ScheduleChanged{schedule = BusinessScheduleRef}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(wallet_modification(ID, Modification),
|
-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),
|
-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),
|
-define(claim_created(Claim),
|
||||||
{claim_created, Claim}).
|
{claim_created, Claim}
|
||||||
|
).
|
||||||
|
|
||||||
-define(claim_updated(ID, Changeset, ClaimRevision, Timestamp),
|
-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),
|
-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(),
|
-define(pending(),
|
||||||
{pending, #payproc_ClaimPending{}}).
|
{pending, #payproc_ClaimPending{}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(accepted(Effects),
|
-define(accepted(Effects),
|
||||||
{accepted, #payproc_ClaimAccepted{effects = Effects}}).
|
{accepted, #payproc_ClaimAccepted{effects = Effects}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(denied(Reason),
|
-define(denied(Reason),
|
||||||
{denied, #payproc_ClaimDenied{reason = Reason}}).
|
{denied, #payproc_ClaimDenied{reason = Reason}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(revoked(Reason),
|
-define(revoked(Reason),
|
||||||
{revoked, #payproc_ClaimRevoked{reason = Reason}}).
|
{revoked, #payproc_ClaimRevoked{reason = Reason}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(account_created(ShopAccount),
|
-define(account_created(ShopAccount),
|
||||||
{account_created, #payproc_ShopAccountCreated{account = ShopAccount}}).
|
{account_created, #payproc_ShopAccountCreated{account = ShopAccount}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(revision_changed(Timestamp, Revision),
|
-define(revision_changed(Timestamp, Revision),
|
||||||
{revision_changed, #payproc_PartyRevisionChanged{
|
{revision_changed, #payproc_PartyRevisionChanged{
|
||||||
timestamp = Timestamp,
|
timestamp = Timestamp,
|
||||||
revision = Revision
|
revision = Revision
|
||||||
}}).
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(invalid_shop(ID, Reason),
|
-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),
|
-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),
|
-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),
|
-define(invalid_wallet(ID, Reason),
|
||||||
{invalid_wallet, #payproc_InvalidWallet{id = ID, reason = Reason}}).
|
{invalid_wallet, #payproc_InvalidWallet{id = ID, reason = Reason}}
|
||||||
|
).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(party_management).
|
-module(party_management).
|
||||||
|
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
-behaviour(application).
|
-behaviour(application).
|
||||||
|
|
||||||
@ -16,39 +17,36 @@
|
|||||||
-export([start/2]).
|
-export([start/2]).
|
||||||
-export([stop/1]).
|
-export([stop/1]).
|
||||||
|
|
||||||
-define(DEFAULT_HANDLING_TIMEOUT, 30000). % 30 seconds
|
% 30 seconds
|
||||||
|
-define(DEFAULT_HANDLING_TIMEOUT, 30000).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% API
|
%% API
|
||||||
%%
|
%%
|
||||||
-spec start() ->
|
-spec start() -> {ok, _}.
|
||||||
{ok, _}.
|
|
||||||
start() ->
|
start() ->
|
||||||
application:ensure_all_started(?MODULE).
|
application:ensure_all_started(?MODULE).
|
||||||
|
|
||||||
-spec stop() ->
|
-spec stop() -> ok.
|
||||||
ok.
|
|
||||||
stop() ->
|
stop() ->
|
||||||
application:stop(?MODULE).
|
application:stop(?MODULE).
|
||||||
|
|
||||||
%% Supervisor callbacks
|
%% Supervisor callbacks
|
||||||
|
|
||||||
-spec init([]) ->
|
-spec init([]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
|
||||||
{ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
|
|
||||||
|
|
||||||
init([]) ->
|
init([]) ->
|
||||||
{ok, {
|
{ok,
|
||||||
#{strategy => one_for_all, intensity => 6, period => 30}, []
|
{
|
||||||
}}.
|
#{strategy => one_for_all, intensity => 6, period => 30},
|
||||||
|
[]
|
||||||
|
}}.
|
||||||
|
|
||||||
%% Application callbacks
|
%% Application callbacks
|
||||||
|
|
||||||
-spec start(normal, any()) ->
|
-spec start(normal, any()) -> {ok, pid()} | {error, any()}.
|
||||||
{ok, pid()} | {error, any()}.
|
|
||||||
start(_StartType, _StartArgs) ->
|
start(_StartType, _StartArgs) ->
|
||||||
supervisor:start_link(?MODULE, []).
|
supervisor:start_link(?MODULE, []).
|
||||||
|
|
||||||
-spec stop(any()) ->
|
-spec stop(any()) -> ok.
|
||||||
ok.
|
|
||||||
stop(_State) ->
|
stop(_State) ->
|
||||||
ok.
|
ok.
|
||||||
|
@ -4,14 +4,12 @@
|
|||||||
|
|
||||||
-export([check_user/2]).
|
-export([check_user/2]).
|
||||||
|
|
||||||
-spec check_user(woody_user_identity:user_identity(), dmsl_domain_thrift:'PartyID'())->
|
-spec check_user(woody_user_identity:user_identity(), dmsl_domain_thrift:'PartyID'()) -> ok | invalid_user.
|
||||||
ok | invalid_user.
|
|
||||||
|
|
||||||
check_user(#{id := PartyID, realm := <<"external">>}, PartyID) ->
|
check_user(#{id := PartyID, realm := <<"external">>}, PartyID) ->
|
||||||
ok;
|
ok;
|
||||||
check_user(#{id := _AnyID, realm := <<"internal">>}, _PartyID) ->
|
check_user(#{id := _AnyID, realm := <<"internal">>}, _PartyID) ->
|
||||||
ok;
|
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) ->
|
check_user(#{id := _AnyID, realm := <<"service">>}, _PartyID) ->
|
||||||
ok;
|
ok;
|
||||||
check_user(_, _) ->
|
check_user(_, _) ->
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
-include_lib("shumpune_proto/include/shumpune_shumpune_thrift.hrl").
|
-include_lib("shumpune_proto/include/shumpune_shumpune_thrift.hrl").
|
||||||
|
|
||||||
-type amount() :: dmsl_domain_thrift:'Amount'().
|
-type amount() :: dmsl_domain_thrift:'Amount'().
|
||||||
-type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
|
-type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
|
||||||
-type account_id() :: dmsl_accounter_thrift:'AccountID'().
|
-type account_id() :: dmsl_accounter_thrift:'AccountID'().
|
||||||
-type batch_id() :: dmsl_accounter_thrift:'BatchID'().
|
-type batch_id() :: dmsl_accounter_thrift:'BatchID'().
|
||||||
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
|
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
|
||||||
-type batch() :: {batch_id(), final_cash_flow()}.
|
-type batch() :: {batch_id(), final_cash_flow()}.
|
||||||
-type clock() :: shumpune_shumpune_thrift:'Clock'().
|
-type clock() :: shumpune_shumpune_thrift:'Clock'().
|
||||||
|
|
||||||
-export_type([batch/0]).
|
-export_type([batch/0]).
|
||||||
|
|
||||||
@ -36,9 +36,7 @@
|
|||||||
max_available_amount => amount()
|
max_available_amount => amount()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_account(account_id()) ->
|
-spec get_account(account_id()) -> account().
|
||||||
account().
|
|
||||||
|
|
||||||
get_account(AccountID) ->
|
get_account(AccountID) ->
|
||||||
case call_accounter('GetAccountByID', {AccountID}) of
|
case call_accounter('GetAccountByID', {AccountID}) of
|
||||||
{ok, Result} ->
|
{ok, Result} ->
|
||||||
@ -47,15 +45,11 @@ get_account(AccountID) ->
|
|||||||
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
|
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_balance(account_id()) ->
|
-spec get_balance(account_id()) -> balance().
|
||||||
balance().
|
|
||||||
|
|
||||||
get_balance(AccountID) ->
|
get_balance(AccountID) ->
|
||||||
get_balance(AccountID, {latest, #shumpune_LatestClock{}}).
|
get_balance(AccountID, {latest, #shumpune_LatestClock{}}).
|
||||||
|
|
||||||
-spec get_balance(account_id(), clock()) ->
|
-spec get_balance(account_id(), clock()) -> balance().
|
||||||
balance().
|
|
||||||
|
|
||||||
get_balance(AccountID, Clock) ->
|
get_balance(AccountID, Clock) ->
|
||||||
case call_accounter('GetBalanceByID', {AccountID, Clock}) of
|
case call_accounter('GetBalanceByID', {AccountID, Clock}) of
|
||||||
{ok, Result} ->
|
{ok, Result} ->
|
||||||
@ -64,21 +58,18 @@ get_balance(AccountID, Clock) ->
|
|||||||
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
|
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec create_account(currency_code()) ->
|
-spec create_account(currency_code()) -> account_id().
|
||||||
account_id().
|
|
||||||
|
|
||||||
create_account(CurrencyCode) ->
|
create_account(CurrencyCode) ->
|
||||||
create_account(CurrencyCode, undefined).
|
create_account(CurrencyCode, undefined).
|
||||||
|
|
||||||
-spec create_account(currency_code(), binary() | undefined) ->
|
-spec create_account(currency_code(), binary() | undefined) -> account_id().
|
||||||
account_id().
|
|
||||||
|
|
||||||
create_account(CurrencyCode, Description) ->
|
create_account(CurrencyCode, Description) ->
|
||||||
case call_accounter('CreateAccount', {construct_prototype(CurrencyCode, Description)}) of
|
case call_accounter('CreateAccount', {construct_prototype(CurrencyCode, Description)}) of
|
||||||
{ok, Result} ->
|
{ok, Result} ->
|
||||||
Result;
|
Result;
|
||||||
{exception, Exception} ->
|
{exception, Exception} ->
|
||||||
error({accounting, Exception}) % FIXME
|
% FIXME
|
||||||
|
error({accounting, Exception})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
construct_prototype(CurrencyCode, Description) ->
|
construct_prototype(CurrencyCode, Description) ->
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
-module(pm_cash_range).
|
-module(pm_cash_range).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
-include("domain.hrl").
|
-include("domain.hrl").
|
||||||
|
|
||||||
-export([is_inside/2]).
|
-export([is_inside/2]).
|
||||||
|
|
||||||
-type cash_range() :: dmsl_domain_thrift:'CashRange'().
|
-type cash_range() :: dmsl_domain_thrift:'CashRange'().
|
||||||
-type cash() :: dmsl_domain_thrift:'Cash'().
|
-type cash() :: dmsl_domain_thrift:'Cash'().
|
||||||
|
|
||||||
-spec is_inside(cash(), cash_range()) ->
|
|
||||||
within | {exceeds, lower | upper}.
|
|
||||||
|
|
||||||
|
-spec is_inside(cash(), cash_range()) -> within | {exceeds, lower | upper}.
|
||||||
is_inside(Cash, CashRange = #domain_CashRange{lower = Lower, upper = Upper}) ->
|
is_inside(Cash, CashRange = #domain_CashRange{lower = Lower, upper = Upper}) ->
|
||||||
case {
|
case
|
||||||
compare_cash(fun erlang:'>'/2, Cash, Lower),
|
{
|
||||||
compare_cash(fun erlang:'<'/2, Cash, Upper)
|
compare_cash(fun erlang:'>'/2, Cash, Lower),
|
||||||
} of
|
compare_cash(fun erlang:'<'/2, Cash, Upper)
|
||||||
|
}
|
||||||
|
of
|
||||||
{true, true} ->
|
{true, true} ->
|
||||||
within;
|
within;
|
||||||
{false, true} ->
|
{false, true} ->
|
||||||
|
@ -7,13 +7,14 @@
|
|||||||
%%% - we should probably validate final cash flow somewhere here
|
%%% - we should probably validate final cash flow somewhere here
|
||||||
|
|
||||||
-module(pm_cashflow).
|
-module(pm_cashflow).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
-type account() :: dmsl_domain_thrift:'CashFlowAccount'().
|
-type account() :: dmsl_domain_thrift:'CashFlowAccount'().
|
||||||
-type account_id() :: dmsl_domain_thrift:'AccountID'().
|
-type account_id() :: dmsl_domain_thrift:'AccountID'().
|
||||||
-type account_map() :: #{account() => account_id()}.
|
-type account_map() :: #{account() => account_id()}.
|
||||||
-type context() :: dmsl_domain_thrift:'CashFlowContext'().
|
-type context() :: dmsl_domain_thrift:'CashFlowContext'().
|
||||||
-type cash_flow() :: dmsl_domain_thrift:'CashFlow'().
|
-type cash_flow() :: dmsl_domain_thrift:'CashFlow'().
|
||||||
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
|
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@ -22,25 +23,21 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-define(posting(Source, Destination, Volume, Details),
|
-define(posting(Source, Destination, Volume, Details), #domain_CashFlowPosting{
|
||||||
#domain_CashFlowPosting{
|
source = Source,
|
||||||
source = Source,
|
destination = Destination,
|
||||||
destination = Destination,
|
volume = Volume,
|
||||||
volume = Volume,
|
details = Details
|
||||||
details = Details
|
}).
|
||||||
}).
|
|
||||||
|
|
||||||
-define(final_posting(Source, Destination, Volume, Details),
|
-define(final_posting(Source, Destination, Volume, Details), #domain_FinalCashFlowPosting{
|
||||||
#domain_FinalCashFlowPosting{
|
source = Source,
|
||||||
source = Source,
|
destination = Destination,
|
||||||
destination = Destination,
|
volume = Volume,
|
||||||
volume = Volume,
|
details = Details
|
||||||
details = Details
|
}).
|
||||||
}).
|
|
||||||
|
|
||||||
-spec finalize(cash_flow(), context(), account_map()) ->
|
|
||||||
final_cash_flow() | no_return().
|
|
||||||
|
|
||||||
|
-spec finalize(cash_flow(), context(), account_map()) -> final_cash_flow() | no_return().
|
||||||
finalize(CF, Context, AccountMap) ->
|
finalize(CF, Context, AccountMap) ->
|
||||||
compute_postings(CF, Context, AccountMap).
|
compute_postings(CF, Context, AccountMap).
|
||||||
|
|
||||||
@ -51,14 +48,14 @@ compute_postings(CF, Context, AccountMap) ->
|
|||||||
construct_final_account(Destination, AccountMap),
|
construct_final_account(Destination, AccountMap),
|
||||||
compute_volume(Volume, Context),
|
compute_volume(Volume, Context),
|
||||||
Details
|
Details
|
||||||
) ||
|
)
|
||||||
?posting(Source, Destination, Volume, Details) <- CF
|
|| ?posting(Source, Destination, Volume, Details) <- CF
|
||||||
].
|
].
|
||||||
|
|
||||||
construct_final_account(AccountType, AccountMap) ->
|
construct_final_account(AccountType, AccountMap) ->
|
||||||
#domain_FinalCashFlowAccount{
|
#domain_FinalCashFlowAccount{
|
||||||
account_type = AccountType,
|
account_type = AccountType,
|
||||||
account_id = resolve_account(AccountType, AccountMap)
|
account_id = resolve_account(AccountType, AccountMap)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
resolve_account(AccountType, AccountMap) ->
|
resolve_account(AccountType, AccountMap) ->
|
||||||
@ -72,13 +69,18 @@ resolve_account(AccountType, AccountMap) ->
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-define(fixed(Cash),
|
-define(fixed(Cash),
|
||||||
{fixed, #domain_CashVolumeFixed{cash = Cash}}).
|
{fixed, #domain_CashVolumeFixed{cash = Cash}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(share(P, Q, Of, RoundingMethod),
|
-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),
|
-define(product(Fun, CVs),
|
||||||
{product, {Fun, CVs}}).
|
{product, {Fun, CVs}}
|
||||||
-define(rational(P, Q),
|
).
|
||||||
#'Rational'{p = P, q = Q}).
|
|
||||||
|
-define(rational(P, Q), #'Rational'{p = P, q = Q}).
|
||||||
|
|
||||||
compute_volume(?fixed(Cash), _Context) ->
|
compute_volume(?fixed(Cash), _Context) ->
|
||||||
Cash;
|
Cash;
|
||||||
@ -93,17 +95,19 @@ compute_volume(?product(Fun, CVs) = CV0, Context) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
compute_parts_of(P, Q, Cash = #domain_Cash{amount = Amount}, RoundingMethod) ->
|
compute_parts_of(P, Q, Cash = #domain_Cash{amount = Amount}, RoundingMethod) ->
|
||||||
Cash#domain_Cash{amount = genlib_rational:round(
|
Cash#domain_Cash{
|
||||||
genlib_rational:mul(
|
amount = genlib_rational:round(
|
||||||
genlib_rational:new(Amount),
|
genlib_rational:mul(
|
||||||
genlib_rational:new(P, Q)
|
genlib_rational:new(Amount),
|
||||||
),
|
genlib_rational:new(P, Q)
|
||||||
get_rounding_method(RoundingMethod)
|
),
|
||||||
)}.
|
get_rounding_method(RoundingMethod)
|
||||||
|
)
|
||||||
|
}.
|
||||||
|
|
||||||
compute_product(Fun, [CV | CVRest], CV0, Context) ->
|
compute_product(Fun, [CV | CVRest], CV0, Context) ->
|
||||||
lists:foldl(
|
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),
|
compute_volume(CV, Context),
|
||||||
CVRest
|
CVRest
|
||||||
).
|
).
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
-module(pm_claim).
|
-module(pm_claim).
|
||||||
|
|
||||||
-include("party_events.hrl").
|
-include("party_events.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
@ -29,55 +30,45 @@
|
|||||||
|
|
||||||
%% Types
|
%% Types
|
||||||
|
|
||||||
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
|
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
|
||||||
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
|
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
|
||||||
-type claim_status() :: dmsl_payment_processing_thrift:'ClaimStatus'().
|
-type claim_status() :: dmsl_payment_processing_thrift:'ClaimStatus'().
|
||||||
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
|
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
|
||||||
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
|
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
|
||||||
|
|
||||||
-type party() :: pm_party:party().
|
-type party() :: pm_party:party().
|
||||||
|
|
||||||
-type timestamp() :: pm_datetime:timestamp().
|
-type timestamp() :: pm_datetime:timestamp().
|
||||||
-type revision() :: pm_domain:revision().
|
-type revision() :: pm_domain:revision().
|
||||||
|
|
||||||
%% Interface
|
%% Interface
|
||||||
|
|
||||||
-spec get_id(claim()) ->
|
-spec get_id(claim()) -> claim_id().
|
||||||
claim_id().
|
|
||||||
|
|
||||||
get_id(#payproc_Claim{id = ID}) ->
|
get_id(#payproc_Claim{id = ID}) ->
|
||||||
ID.
|
ID.
|
||||||
|
|
||||||
-spec get_revision(claim()) ->
|
-spec get_revision(claim()) -> claim_revision().
|
||||||
claim_revision().
|
|
||||||
|
|
||||||
get_revision(#payproc_Claim{revision = Revision}) ->
|
get_revision(#payproc_Claim{revision = Revision}) ->
|
||||||
Revision.
|
Revision.
|
||||||
|
|
||||||
-spec create(claim_id(), changeset(), party(), timestamp(), revision()) ->
|
-spec create(claim_id(), changeset(), party(), timestamp(), revision()) -> claim() | no_return().
|
||||||
claim() | no_return().
|
|
||||||
|
|
||||||
create(ID, Changeset, Party, Timestamp, Revision) ->
|
create(ID, Changeset, Party, Timestamp, Revision) ->
|
||||||
ok = assert_changeset_applicable(Changeset, Timestamp, Revision, Party),
|
ok = assert_changeset_applicable(Changeset, Timestamp, Revision, Party),
|
||||||
#payproc_Claim{
|
#payproc_Claim{
|
||||||
id = ID,
|
id = ID,
|
||||||
status = ?pending(),
|
status = ?pending(),
|
||||||
changeset = Changeset,
|
changeset = Changeset,
|
||||||
revision = 1,
|
revision = 1,
|
||||||
created_at = Timestamp
|
created_at = Timestamp
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec update(changeset(), claim(), party(), timestamp(), revision()) ->
|
-spec update(changeset(), claim(), party(), timestamp(), revision()) -> claim() | no_return().
|
||||||
claim() | no_return().
|
|
||||||
|
|
||||||
update(NewChangeset, #payproc_Claim{changeset = OldChangeset} = Claim, Party, Timestamp, Revision) ->
|
update(NewChangeset, #payproc_Claim{changeset = OldChangeset} = Claim, Party, Timestamp, Revision) ->
|
||||||
TmpChangeset = merge_changesets(OldChangeset, NewChangeset),
|
TmpChangeset = merge_changesets(OldChangeset, NewChangeset),
|
||||||
ok = assert_changeset_applicable(TmpChangeset, Timestamp, Revision, Party),
|
ok = assert_changeset_applicable(TmpChangeset, Timestamp, Revision, Party),
|
||||||
update_changeset(NewChangeset, get_next_revision(Claim), Timestamp, Claim).
|
update_changeset(NewChangeset, get_next_revision(Claim), Timestamp, Claim).
|
||||||
|
|
||||||
-spec update_changeset(changeset(), claim_revision(), timestamp(), claim()) ->
|
-spec update_changeset(changeset(), claim_revision(), timestamp(), claim()) -> claim().
|
||||||
claim().
|
|
||||||
|
|
||||||
update_changeset(NewChangeset, NewRevision, Timestamp, #payproc_Claim{changeset = OldChangeset} = Claim) ->
|
update_changeset(NewChangeset, NewRevision, Timestamp, #payproc_Claim{changeset = OldChangeset} = Claim) ->
|
||||||
Claim#payproc_Claim{
|
Claim#payproc_Claim{
|
||||||
revision = NewRevision,
|
revision = NewRevision,
|
||||||
@ -85,29 +76,21 @@ update_changeset(NewChangeset, NewRevision, Timestamp, #payproc_Claim{changeset
|
|||||||
changeset = merge_changesets(OldChangeset, NewChangeset)
|
changeset = merge_changesets(OldChangeset, NewChangeset)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec accept(timestamp(), revision(), party(), claim()) ->
|
-spec accept(timestamp(), revision(), party(), claim()) -> claim() | no_return().
|
||||||
claim() | no_return().
|
|
||||||
|
|
||||||
accept(Timestamp, DomainRevision, Party, Claim) ->
|
accept(Timestamp, DomainRevision, Party, Claim) ->
|
||||||
ok = assert_acceptable(Claim, Timestamp, DomainRevision, Party),
|
ok = assert_acceptable(Claim, Timestamp, DomainRevision, Party),
|
||||||
Effects = make_effects(Timestamp, DomainRevision, Claim),
|
Effects = make_effects(Timestamp, DomainRevision, Claim),
|
||||||
set_status(?accepted(Effects), get_next_revision(Claim), Timestamp, Claim).
|
set_status(?accepted(Effects), get_next_revision(Claim), Timestamp, Claim).
|
||||||
|
|
||||||
-spec deny(binary(), timestamp(), claim()) ->
|
-spec deny(binary(), timestamp(), claim()) -> claim().
|
||||||
claim().
|
|
||||||
|
|
||||||
deny(Reason, Timestamp, Claim) ->
|
deny(Reason, Timestamp, Claim) ->
|
||||||
set_status(?denied(Reason), get_next_revision(Claim), Timestamp, Claim).
|
set_status(?denied(Reason), get_next_revision(Claim), Timestamp, Claim).
|
||||||
|
|
||||||
-spec revoke(binary(), timestamp(), claim()) ->
|
-spec revoke(binary(), timestamp(), claim()) -> claim().
|
||||||
claim().
|
|
||||||
|
|
||||||
revoke(Reason, Timestamp, Claim) ->
|
revoke(Reason, Timestamp, Claim) ->
|
||||||
set_status(?revoked(Reason), get_next_revision(Claim), Timestamp, Claim).
|
set_status(?revoked(Reason), get_next_revision(Claim), Timestamp, Claim).
|
||||||
|
|
||||||
-spec set_status(claim_status(), claim_revision(), timestamp(), claim()) ->
|
-spec set_status(claim_status(), claim_revision(), timestamp(), claim()) -> claim().
|
||||||
claim().
|
|
||||||
|
|
||||||
set_status(Status, NewRevision, Timestamp, Claim) ->
|
set_status(Status, NewRevision, Timestamp, Claim) ->
|
||||||
Claim#payproc_Claim{
|
Claim#payproc_Claim{
|
||||||
revision = NewRevision,
|
revision = NewRevision,
|
||||||
@ -115,43 +98,31 @@ set_status(Status, NewRevision, Timestamp, Claim) ->
|
|||||||
status = Status
|
status = Status
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_status(claim()) ->
|
-spec get_status(claim()) -> claim_status().
|
||||||
claim_status().
|
|
||||||
|
|
||||||
get_status(#payproc_Claim{status = Status}) ->
|
get_status(#payproc_Claim{status = Status}) ->
|
||||||
Status.
|
Status.
|
||||||
|
|
||||||
-spec is_pending(claim()) ->
|
-spec is_pending(claim()) -> boolean().
|
||||||
boolean().
|
|
||||||
|
|
||||||
is_pending(#payproc_Claim{status = ?pending()}) ->
|
is_pending(#payproc_Claim{status = ?pending()}) ->
|
||||||
true;
|
true;
|
||||||
is_pending(_) ->
|
is_pending(_) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
-spec is_accepted(claim()) ->
|
-spec is_accepted(claim()) -> boolean().
|
||||||
boolean().
|
|
||||||
|
|
||||||
is_accepted(#payproc_Claim{status = ?accepted(_)}) ->
|
is_accepted(#payproc_Claim{status = ?accepted(_)}) ->
|
||||||
true;
|
true;
|
||||||
is_accepted(_) ->
|
is_accepted(_) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
-spec is_need_acceptance(claim(), party(), revision()) ->
|
-spec is_need_acceptance(claim(), party(), revision()) -> boolean().
|
||||||
boolean().
|
|
||||||
|
|
||||||
is_need_acceptance(Claim, Party, Revision) ->
|
is_need_acceptance(Claim, Party, Revision) ->
|
||||||
is_changeset_need_acceptance(get_changeset(Claim), Party, Revision).
|
is_changeset_need_acceptance(get_changeset(Claim), Party, Revision).
|
||||||
|
|
||||||
-spec is_conflicting(claim(), claim(), timestamp(), revision(), party()) ->
|
-spec is_conflicting(claim(), claim(), timestamp(), revision(), party()) -> boolean().
|
||||||
boolean().
|
|
||||||
|
|
||||||
is_conflicting(Claim1, Claim2, Timestamp, Revision, Party) ->
|
is_conflicting(Claim1, Claim2, Timestamp, Revision, Party) ->
|
||||||
has_changeset_conflict(get_changeset(Claim1), get_changeset(Claim2), Timestamp, Revision, Party).
|
has_changeset_conflict(get_changeset(Claim1), get_changeset(Claim2), Timestamp, Revision, Party).
|
||||||
|
|
||||||
-spec apply(claim(), timestamp(), party()) ->
|
-spec apply(claim(), timestamp(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
apply(#payproc_Claim{status = ?accepted(Effects)}, Timestamp, Party) ->
|
apply(#payproc_Claim{status = ?accepted(Effects)}, Timestamp, Party) ->
|
||||||
apply_effects(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(get_changeset(Claim), Timestamp, Revision).
|
||||||
|
|
||||||
make_changeset_effects(Changeset, Timestamp, Revision) ->
|
make_changeset_effects(Changeset, Timestamp, Revision) ->
|
||||||
squash_effects(lists:map(
|
squash_effects(
|
||||||
fun(Change) ->
|
lists:map(
|
||||||
pm_claim_effect:make(Change, Timestamp, Revision)
|
fun(Change) ->
|
||||||
end,
|
pm_claim_effect:make(Change, Timestamp, Revision)
|
||||||
Changeset
|
end,
|
||||||
)).
|
Changeset
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
make_changeset_safe_effects(Changeset, Timestamp, Revision) ->
|
make_changeset_safe_effects(Changeset, Timestamp, Revision) ->
|
||||||
squash_effects(lists:map(
|
squash_effects(
|
||||||
fun(Change) ->
|
lists:map(
|
||||||
pm_claim_effect:make_safe(Change, Timestamp, Revision)
|
fun(Change) ->
|
||||||
end,
|
pm_claim_effect:make_safe(Change, Timestamp, Revision)
|
||||||
Changeset
|
end,
|
||||||
)).
|
Changeset
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
squash_effects(Effects) ->
|
squash_effects(Effects) ->
|
||||||
squash_effects(Effects, []).
|
squash_effects(Effects, []).
|
||||||
@ -421,37 +396,29 @@ apply_wallet_effect(ID, Effect, Party) ->
|
|||||||
update_wallet({account_created, Account}, Wallet) ->
|
update_wallet({account_created, Account}, Wallet) ->
|
||||||
Wallet#domain_Wallet{account = Account}.
|
Wallet#domain_Wallet{account = Account}.
|
||||||
|
|
||||||
-spec raise_invalid_changeset(dmsl_payment_processing_thrift:'InvalidChangesetReason'()) ->
|
-spec raise_invalid_changeset(dmsl_payment_processing_thrift:'InvalidChangesetReason'()) -> no_return().
|
||||||
no_return().
|
|
||||||
|
|
||||||
raise_invalid_changeset(Reason) ->
|
raise_invalid_changeset(Reason) ->
|
||||||
throw(#payproc_InvalidChangeset{reason = Reason}).
|
throw(#payproc_InvalidChangeset{reason = Reason}).
|
||||||
|
|
||||||
%% Asserts
|
%% 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) ->
|
assert_revision(#payproc_Claim{revision = Revision}, Revision) ->
|
||||||
ok;
|
ok;
|
||||||
assert_revision(_, _) ->
|
assert_revision(_, _) ->
|
||||||
throw(#payproc_InvalidClaimRevision{}).
|
throw(#payproc_InvalidClaimRevision{}).
|
||||||
|
|
||||||
-spec assert_pending(claim()) -> ok | no_return().
|
-spec assert_pending(claim()) -> ok | no_return().
|
||||||
|
|
||||||
assert_pending(#payproc_Claim{status = ?pending()}) ->
|
assert_pending(#payproc_Claim{status = ?pending()}) ->
|
||||||
ok;
|
ok;
|
||||||
assert_pending(#payproc_Claim{status = Status}) ->
|
assert_pending(#payproc_Claim{status = Status}) ->
|
||||||
throw(#payproc_InvalidClaimStatus{status = Status}).
|
throw(#payproc_InvalidClaimStatus{status = Status}).
|
||||||
|
|
||||||
-spec assert_applicable(claim(), timestamp(), revision(), party()) ->
|
-spec assert_applicable(claim(), timestamp(), revision(), party()) -> ok | no_return().
|
||||||
ok | no_return().
|
|
||||||
|
|
||||||
assert_applicable(Claim, Timestamp, Revision, Party) ->
|
assert_applicable(Claim, Timestamp, Revision, Party) ->
|
||||||
assert_changeset_applicable(get_changeset(Claim), Timestamp, Revision, Party).
|
assert_changeset_applicable(get_changeset(Claim), Timestamp, Revision, Party).
|
||||||
|
|
||||||
-spec assert_changeset_applicable(changeset(), timestamp(), revision(), party()) ->
|
-spec assert_changeset_applicable(changeset(), timestamp(), revision(), party()) -> ok | no_return().
|
||||||
ok | no_return().
|
|
||||||
|
|
||||||
assert_changeset_applicable([Change | Others], Timestamp, Revision, Party) ->
|
assert_changeset_applicable([Change | Others], Timestamp, Revision, Party) ->
|
||||||
case Change of
|
case Change of
|
||||||
?contract_modification(ID, Modification) ->
|
?contract_modification(ID, Modification) ->
|
||||||
@ -585,9 +552,7 @@ get_payment_institution_realm(Ref, Revision, ContractID) ->
|
|||||||
raise_invalid_payment_institution(ContractID, Ref)
|
raise_invalid_payment_institution(ContractID, Ref)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec assert_acceptable(claim(), timestamp(), revision(), party()) ->
|
-spec assert_acceptable(claim(), timestamp(), revision(), party()) -> ok | no_return().
|
||||||
ok | no_return().
|
|
||||||
|
|
||||||
assert_acceptable(Claim, Timestamp, Revision, Party0) ->
|
assert_acceptable(Claim, Timestamp, Revision, Party0) ->
|
||||||
Changeset = get_changeset(Claim),
|
Changeset = get_changeset(Claim),
|
||||||
Effects = make_changeset_safe_effects(Changeset, Timestamp, Revision),
|
Effects = make_changeset_safe_effects(Changeset, Timestamp, Revision),
|
||||||
@ -597,16 +562,16 @@ assert_acceptable(Claim, Timestamp, Revision, Party0) ->
|
|||||||
-spec raise_invalid_payment_institution(
|
-spec raise_invalid_payment_institution(
|
||||||
dmsl_domain_thrift:'ContractID'(),
|
dmsl_domain_thrift:'ContractID'(),
|
||||||
dmsl_domain_thrift:'PaymentInstitutionRef'() | undefined
|
dmsl_domain_thrift:'PaymentInstitutionRef'() | undefined
|
||||||
) ->
|
) -> no_return().
|
||||||
no_return().
|
|
||||||
|
|
||||||
raise_invalid_payment_institution(ContractID, Ref) ->
|
raise_invalid_payment_institution(ContractID, Ref) ->
|
||||||
raise_invalid_changeset(?invalid_contract(
|
raise_invalid_changeset(
|
||||||
ContractID,
|
?invalid_contract(
|
||||||
{invalid_object_reference, #payproc_InvalidObjectReference{
|
ContractID,
|
||||||
ref = make_optional_domain_ref(payment_institution, Ref)
|
{invalid_object_reference, #payproc_InvalidObjectReference{
|
||||||
}}
|
ref = make_optional_domain_ref(payment_institution, Ref)
|
||||||
)).
|
}}
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
make_optional_domain_ref(_, undefined) ->
|
make_optional_domain_ref(_, undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
|
@ -1,29 +1,30 @@
|
|||||||
-module(pm_claim_committer).
|
-module(pm_claim_committer).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
|
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
|
||||||
|
|
||||||
-include("claim_management.hrl").
|
-include("claim_management.hrl").
|
||||||
-include("party_events.hrl").
|
-include("party_events.hrl").
|
||||||
|
|
||||||
-export([from_claim_mgmt/1]).
|
-export([from_claim_mgmt/1]).
|
||||||
|
|
||||||
-spec from_claim_mgmt(dmsl_claim_management_thrift:'Claim'()) ->
|
-spec from_claim_mgmt(dmsl_claim_management_thrift:'Claim'()) -> dmsl_payment_processing_thrift:'Claim'() | undefined.
|
||||||
dmsl_payment_processing_thrift:'Claim'() | undefined.
|
|
||||||
|
|
||||||
from_claim_mgmt(#claim_management_Claim{
|
from_claim_mgmt(#claim_management_Claim{
|
||||||
id = ID,
|
id = ID,
|
||||||
changeset = Changeset,
|
changeset = Changeset,
|
||||||
revision = Revision,
|
revision = Revision,
|
||||||
created_at = CreatedAt,
|
created_at = CreatedAt,
|
||||||
updated_at = UpdatedAt
|
updated_at = UpdatedAt
|
||||||
}) ->
|
}) ->
|
||||||
case from_cm_changeset(Changeset) of
|
case from_cm_changeset(Changeset) of
|
||||||
[] -> undefined;
|
[] ->
|
||||||
|
undefined;
|
||||||
Converted ->
|
Converted ->
|
||||||
#payproc_Claim{
|
#payproc_Claim{
|
||||||
id = ID,
|
id = ID,
|
||||||
status = ?pending(),
|
status = ?pending(),
|
||||||
changeset = Converted,
|
changeset = Converted,
|
||||||
revision = Revision,
|
revision = Revision,
|
||||||
created_at = CreatedAt,
|
created_at = CreatedAt,
|
||||||
updated_at = UpdatedAt
|
updated_at = UpdatedAt
|
||||||
}
|
}
|
||||||
@ -33,18 +34,23 @@ from_claim_mgmt(#claim_management_Claim{
|
|||||||
|
|
||||||
from_cm_changeset(Changeset) ->
|
from_cm_changeset(Changeset) ->
|
||||||
lists:filtermap(
|
lists:filtermap(
|
||||||
fun (#claim_management_ModificationUnit{
|
fun
|
||||||
modification = {party_modification, PartyMod}
|
(
|
||||||
}) ->
|
#claim_management_ModificationUnit{
|
||||||
case PartyMod of
|
modification = {party_modification, PartyMod}
|
||||||
?cm_cash_register_modification_unit_modification(_, _) ->
|
}
|
||||||
false;
|
) ->
|
||||||
PartyMod ->
|
case PartyMod of
|
||||||
{true, from_cm_party_mod(PartyMod)}
|
?cm_cash_register_modification_unit_modification(_, _) ->
|
||||||
end;
|
false;
|
||||||
(#claim_management_ModificationUnit{
|
PartyMod ->
|
||||||
modification = {claim_modification, _}
|
{true, from_cm_party_mod(PartyMod)}
|
||||||
}) ->
|
end;
|
||||||
|
(
|
||||||
|
#claim_management_ModificationUnit{
|
||||||
|
modification = {claim_modification, _}
|
||||||
|
}
|
||||||
|
) ->
|
||||||
false
|
false
|
||||||
end,
|
end,
|
||||||
Changeset
|
Changeset
|
||||||
@ -65,32 +71,31 @@ from_cm_party_mod(?cm_shop_modification(ShopID, ShopModification)) ->
|
|||||||
|
|
||||||
from_cm_contract_modification(
|
from_cm_contract_modification(
|
||||||
{creation, #claim_management_ContractParams{
|
{creation, #claim_management_ContractParams{
|
||||||
contractor_id = ContractorID,
|
contractor_id = ContractorID,
|
||||||
template = ContractTemplateRef,
|
template = ContractTemplateRef,
|
||||||
payment_institution = PaymentInstitutionRef
|
payment_institution = PaymentInstitutionRef
|
||||||
}}
|
}}
|
||||||
) ->
|
) ->
|
||||||
{creation, #payproc_ContractParams{
|
{creation, #payproc_ContractParams{
|
||||||
contractor_id = ContractorID,
|
contractor_id = ContractorID,
|
||||||
template = ContractTemplateRef,
|
template = ContractTemplateRef,
|
||||||
payment_institution = PaymentInstitutionRef
|
payment_institution = PaymentInstitutionRef
|
||||||
}};
|
}};
|
||||||
from_cm_contract_modification(?cm_contract_termination(Reason)) ->
|
from_cm_contract_modification(?cm_contract_termination(Reason)) ->
|
||||||
?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(
|
?adjustment_creation(
|
||||||
ContractAdjustmentID,
|
ContractAdjustmentID,
|
||||||
#payproc_ContractAdjustmentParams{template = ContractTemplateRef}
|
#payproc_ContractAdjustmentParams{template = ContractTemplateRef}
|
||||||
);
|
);
|
||||||
from_cm_contract_modification(
|
from_cm_contract_modification(
|
||||||
?cm_payout_tool_creation(PayoutToolID, #claim_management_PayoutToolParams{
|
?cm_payout_tool_creation(PayoutToolID, #claim_management_PayoutToolParams{
|
||||||
currency = CurrencyRef,
|
currency = CurrencyRef,
|
||||||
tool_info = PayoutToolInfo
|
tool_info = PayoutToolInfo
|
||||||
})
|
})
|
||||||
) ->
|
) ->
|
||||||
?payout_tool_creation(PayoutToolID, #payproc_PayoutToolParams{
|
?payout_tool_creation(PayoutToolID, #payproc_PayoutToolParams{
|
||||||
currency = CurrencyRef,
|
currency = CurrencyRef,
|
||||||
tool_info = PayoutToolInfo
|
tool_info = PayoutToolInfo
|
||||||
});
|
});
|
||||||
from_cm_contract_modification(
|
from_cm_contract_modification(
|
||||||
@ -106,17 +111,17 @@ from_cm_contract_modification({contractor_modification, _ContractorID} = Contrac
|
|||||||
|
|
||||||
from_cm_shop_modification({creation, ShopParams}) ->
|
from_cm_shop_modification({creation, ShopParams}) ->
|
||||||
#claim_management_ShopParams{
|
#claim_management_ShopParams{
|
||||||
category = CategoryRef,
|
category = CategoryRef,
|
||||||
location = ShopLocation,
|
location = ShopLocation,
|
||||||
details = ShopDetails,
|
details = ShopDetails,
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID
|
payout_tool_id = PayoutToolID
|
||||||
} = ShopParams,
|
} = ShopParams,
|
||||||
{creation, #payproc_ShopParams{
|
{creation, #payproc_ShopParams{
|
||||||
category = CategoryRef,
|
category = CategoryRef,
|
||||||
location = ShopLocation,
|
location = ShopLocation,
|
||||||
details = ShopDetails,
|
details = ShopDetails,
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID
|
payout_tool_id = PayoutToolID
|
||||||
}};
|
}};
|
||||||
from_cm_shop_modification({category_modification, _CategoryRef} = CategoryModification) ->
|
from_cm_shop_modification({category_modification, _CategoryRef} = CategoryModification) ->
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-module(pm_claim_committer_handler).
|
-module(pm_claim_committer_handler).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
|
-include_lib("damsel/include/dmsl_claim_management_thrift.hrl").
|
||||||
|
|
||||||
@ -6,17 +7,14 @@
|
|||||||
|
|
||||||
-export([handle_function/3]).
|
-export([handle_function/3]).
|
||||||
|
|
||||||
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
|
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
term()| no_return().
|
|
||||||
|
|
||||||
handle_function(Func, Args, Opts) ->
|
handle_function(Func, Args, Opts) ->
|
||||||
scoper:scope(claimmgmt,
|
scoper:scope(
|
||||||
|
claimmgmt,
|
||||||
fun() -> handle_function_(Func, Args, Opts) end
|
fun() -> handle_function_(Func, Args, Opts) end
|
||||||
).
|
).
|
||||||
|
|
||||||
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
|
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
term() | no_return().
|
|
||||||
|
|
||||||
handle_function_(Fun, {PartyID, _Claim} = Args, _Opts) when Fun == 'Accept'; Fun == 'Commit' ->
|
handle_function_(Fun, {PartyID, _Claim} = Args, _Opts) when Fun == 'Accept'; Fun == 'Commit' ->
|
||||||
call(PartyID, Fun, Args).
|
call(PartyID, Fun, Args).
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
-module(pm_claim_effect).
|
-module(pm_claim_effect).
|
||||||
|
|
||||||
-include("party_events.hrl").
|
-include("party_events.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([make/3]).
|
-export([make/3]).
|
||||||
@ -10,16 +11,14 @@
|
|||||||
|
|
||||||
%% Interface
|
%% Interface
|
||||||
|
|
||||||
-type change() :: dmsl_payment_processing_thrift:'PartyModification'().
|
-type change() :: dmsl_payment_processing_thrift:'PartyModification'().
|
||||||
-type effect() :: dmsl_payment_processing_thrift:'ClaimEffect'().
|
-type effect() :: dmsl_payment_processing_thrift:'ClaimEffect'().
|
||||||
-type timestamp() :: pm_datetime:timestamp().
|
-type timestamp() :: pm_datetime:timestamp().
|
||||||
-type revision() :: pm_domain:revision().
|
-type revision() :: pm_domain:revision().
|
||||||
|
|
||||||
-spec make(change(), timestamp(), revision()) -> effect() | no_return().
|
-spec make(change(), timestamp(), revision()) -> effect() | no_return().
|
||||||
|
|
||||||
make(?contractor_modification(ID, Modification), Timestamp, Revision) ->
|
make(?contractor_modification(ID, Modification), Timestamp, Revision) ->
|
||||||
?contractor_effect(ID, make_contractor_effect(ID, Modification, Timestamp, Revision));
|
?contractor_effect(ID, make_contractor_effect(ID, Modification, Timestamp, Revision));
|
||||||
|
|
||||||
make(?contract_modification(ID, Modification), Timestamp, Revision) ->
|
make(?contract_modification(ID, Modification), Timestamp, Revision) ->
|
||||||
try
|
try
|
||||||
?contract_effect(ID, make_contract_effect(ID, Modification, Timestamp, Revision))
|
?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} ->
|
throw:{template_invalid, Ref} ->
|
||||||
raise_invalid_object_ref({contract, ID}, make_optional_domain_ref(contract_template, Ref))
|
raise_invalid_object_ref({contract, ID}, make_optional_domain_ref(contract_template, Ref))
|
||||||
end;
|
end;
|
||||||
|
|
||||||
make(?shop_modification(ID, Modification), Timestamp, Revision) ->
|
make(?shop_modification(ID, Modification), Timestamp, Revision) ->
|
||||||
?shop_effect(ID, make_shop_effect(ID, Modification, Timestamp, Revision));
|
?shop_effect(ID, make_shop_effect(ID, Modification, Timestamp, Revision));
|
||||||
|
|
||||||
make(?wallet_modification(ID, Modification), Timestamp, _Revision) ->
|
make(?wallet_modification(ID, Modification), Timestamp, _Revision) ->
|
||||||
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp)).
|
?wallet_effect(ID, make_wallet_effect(ID, Modification, Timestamp)).
|
||||||
|
|
||||||
-spec make_safe(change(), timestamp(), revision()) -> effect() | no_return().
|
-spec make_safe(change(), timestamp(), revision()) -> effect() | no_return().
|
||||||
|
|
||||||
make_safe(
|
make_safe(
|
||||||
?shop_modification(ID, {shop_account_creation, #payproc_ShopAccountParams{currency = Currency}}),
|
?shop_modification(ID, {shop_account_creation, #payproc_ShopAccountParams{currency = Currency}}),
|
||||||
_Timestamp,
|
_Timestamp,
|
||||||
_Revision
|
_Revision
|
||||||
) ->
|
) ->
|
||||||
?shop_effect(ID,
|
?shop_effect(
|
||||||
|
ID,
|
||||||
{account_created, #domain_ShopAccount{
|
{account_created, #domain_ShopAccount{
|
||||||
currency = Currency,
|
currency = Currency,
|
||||||
settlement = 0,
|
settlement = 0,
|
||||||
@ -145,15 +142,12 @@ assert_valid_object_ref(Prefix, Ref, Revision) ->
|
|||||||
-spec raise_invalid_object_ref(
|
-spec raise_invalid_object_ref(
|
||||||
{shop, dmsl_domain_thrift:'ShopID'()} | {contract, dmsl_domain_thrift:'ContractID'()},
|
{shop, dmsl_domain_thrift:'ShopID'()} | {contract, dmsl_domain_thrift:'ContractID'()},
|
||||||
pm_domain:ref()
|
pm_domain:ref()
|
||||||
) ->
|
) -> no_return().
|
||||||
no_return().
|
|
||||||
|
|
||||||
raise_invalid_object_ref(Prefix, Ref) ->
|
raise_invalid_object_ref(Prefix, Ref) ->
|
||||||
Ex = {invalid_object_reference, #payproc_InvalidObjectReference{ref = Ref}},
|
Ex = {invalid_object_reference, #payproc_InvalidObjectReference{ref = Ref}},
|
||||||
raise_invalid_object_ref_(Prefix, Ex).
|
raise_invalid_object_ref_(Prefix, Ex).
|
||||||
|
|
||||||
-spec raise_invalid_object_ref_(term(), term()) -> no_return().
|
-spec raise_invalid_object_ref_(term(), term()) -> no_return().
|
||||||
|
|
||||||
raise_invalid_object_ref_({shop, ID}, Ex) ->
|
raise_invalid_object_ref_({shop, ID}, Ex) ->
|
||||||
pm_claim:raise_invalid_changeset(?invalid_shop(ID, Ex));
|
pm_claim:raise_invalid_changeset(?invalid_shop(ID, Ex));
|
||||||
raise_invalid_object_ref_({contract, ID}, Ex) ->
|
raise_invalid_object_ref_({contract, ID}, Ex) ->
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-module(pm_condition).
|
-module(pm_condition).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@ -8,11 +9,9 @@
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-type condition() :: dmsl_domain_thrift:'Condition'().
|
-type condition() :: dmsl_domain_thrift:'Condition'().
|
||||||
-type varset() :: pm_selector:varset().
|
-type varset() :: pm_selector:varset().
|
||||||
|
|
||||||
-spec test(condition(), varset(), pm_domain:revision()) ->
|
|
||||||
true | false | undefined.
|
|
||||||
|
|
||||||
|
-spec test(condition(), varset(), pm_domain:revision()) -> true | false | undefined.
|
||||||
test({category_is, V1}, #{category := V2}, _) ->
|
test({category_is, V1}, #{category := V2}, _) ->
|
||||||
V1 =:= V2;
|
V1 =:= V2;
|
||||||
test({currency_is, V1}, #{currency := V2}, _) ->
|
test({currency_is, V1}, #{currency := V2}, _) ->
|
||||||
@ -77,14 +76,19 @@ test_p2p_tool(P2PCondition, P2PTool, Rev) ->
|
|||||||
sender = Sender,
|
sender = Sender,
|
||||||
receiver = Receiver
|
receiver = Receiver
|
||||||
} = P2PTool,
|
} = P2PTool,
|
||||||
case {
|
case
|
||||||
test({payment_tool, SenderIs}, #{payment_tool => Sender}, Rev),
|
{
|
||||||
test({payment_tool, ReceiverIs}, #{payment_tool => Receiver}, Rev)
|
test({payment_tool, SenderIs}, #{payment_tool => Sender}, Rev),
|
||||||
} of
|
test({payment_tool, ReceiverIs}, #{payment_tool => Receiver}, Rev)
|
||||||
{true, true} -> true;
|
}
|
||||||
{T1, T2} when T1 =:= undefined
|
of
|
||||||
orelse T2 =:= undefined -> undefined;
|
{true, true} ->
|
||||||
{_, _} -> false
|
true;
|
||||||
|
{T1, T2} when
|
||||||
|
T1 =:= undefined orelse
|
||||||
|
T2 =:= undefined
|
||||||
|
->
|
||||||
|
undefined;
|
||||||
|
{_, _} ->
|
||||||
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
woody_context := woody_context(),
|
woody_context := woody_context(),
|
||||||
user_identity => user_identity()
|
user_identity => user_identity()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type options() :: #{
|
-type options() :: #{
|
||||||
user_identity => user_identity(),
|
user_identity => user_identity(),
|
||||||
woody_context => woody_context()
|
woody_context => woody_context()
|
||||||
@ -41,11 +42,13 @@ create(Options0) ->
|
|||||||
|
|
||||||
-spec save(context()) -> ok.
|
-spec save(context()) -> ok.
|
||||||
save(Context) ->
|
save(Context) ->
|
||||||
true = try gproc:reg(?REGISTRY_KEY, Context)
|
true =
|
||||||
catch
|
try
|
||||||
error:badarg ->
|
gproc:reg(?REGISTRY_KEY, Context)
|
||||||
gproc:set_value(?REGISTRY_KEY, Context)
|
catch
|
||||||
end,
|
error:badarg ->
|
||||||
|
gproc:set_value(?REGISTRY_KEY, Context)
|
||||||
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec load() -> context() | no_return().
|
-spec load() -> context() | no_return().
|
||||||
|
@ -18,31 +18,30 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type contract() :: dmsl_domain_thrift:'Contract'().
|
-type contract() :: dmsl_domain_thrift:'Contract'().
|
||||||
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
||||||
-type contract_params() :: dmsl_payment_processing_thrift:'ContractParams'().
|
-type contract_params() :: dmsl_payment_processing_thrift:'ContractParams'().
|
||||||
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
|
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
|
||||||
-type adjustment() :: dmsl_domain_thrift:'ContractAdjustment'().
|
-type adjustment() :: dmsl_domain_thrift:'ContractAdjustment'().
|
||||||
-type adjustment_id() :: dmsl_domain_thrift:'ContractAdjustmentID'().
|
-type adjustment_id() :: dmsl_domain_thrift:'ContractAdjustmentID'().
|
||||||
-type adjustment_params() :: dmsl_payment_processing_thrift:'ContractAdjustmentParams'().
|
-type adjustment_params() :: dmsl_payment_processing_thrift:'ContractAdjustmentParams'().
|
||||||
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
|
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
|
||||||
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
|
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
|
||||||
-type category() :: dmsl_domain_thrift:'CategoryRef'().
|
-type category() :: dmsl_domain_thrift:'CategoryRef'().
|
||||||
-type contract_template_ref() :: dmsl_domain_thrift:'ContractTemplateRef'().
|
-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 timestamp() :: pm_datetime:timestamp().
|
||||||
-type revision() :: pm_domain:revision().
|
-type revision() :: pm_domain:revision().
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec create(contract_id(), contract_params(), timestamp(), revision()) ->
|
-spec create(contract_id(), contract_params(), timestamp(), revision()) -> contract().
|
||||||
contract().
|
|
||||||
|
|
||||||
create(ID, Params, Timestamp, Revision) ->
|
create(ID, Params, Timestamp, Revision) ->
|
||||||
#payproc_ContractParams{
|
#payproc_ContractParams{
|
||||||
contractor_id = ContractorID,
|
contractor_id = ContractorID,
|
||||||
contractor = Contractor, %% Legacy
|
%% Legacy
|
||||||
|
contractor = Contractor,
|
||||||
template = TemplateRef,
|
template = TemplateRef,
|
||||||
payment_institution = PaymentInstitutionRef
|
payment_institution = PaymentInstitutionRef
|
||||||
} = ensure_contract_creation_params(Params, Revision),
|
} = ensure_contract_creation_params(Params, Revision),
|
||||||
@ -65,9 +64,7 @@ create(ID, Params, Timestamp, Revision) ->
|
|||||||
payout_tools = []
|
payout_tools = []
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec update_status(contract(), timestamp()) ->
|
-spec update_status(contract(), timestamp()) -> contract().
|
||||||
contract().
|
|
||||||
|
|
||||||
update_status(
|
update_status(
|
||||||
#domain_Contract{
|
#domain_Contract{
|
||||||
valid_since = ValidSince,
|
valid_since = ValidSince,
|
||||||
@ -88,9 +85,7 @@ update_status(Contract, _) ->
|
|||||||
Contract.
|
Contract.
|
||||||
|
|
||||||
%% TODO should be in separate module
|
%% TODO should be in separate module
|
||||||
-spec create_adjustment(adjustment_id(), adjustment_params(), timestamp(), revision()) ->
|
-spec create_adjustment(adjustment_id(), adjustment_params(), timestamp(), revision()) -> adjustment().
|
||||||
adjustment().
|
|
||||||
|
|
||||||
create_adjustment(ID, Params, Timestamp, Revision) ->
|
create_adjustment(ID, Params, Timestamp, Revision) ->
|
||||||
#payproc_ContractAdjustmentParams{
|
#payproc_ContractAdjustmentParams{
|
||||||
template = TemplateRef
|
template = TemplateRef
|
||||||
@ -110,7 +105,6 @@ create_adjustment(ID, Params, Timestamp, Revision) ->
|
|||||||
|
|
||||||
-spec get_categories(contract() | contract_template(), timestamp(), revision()) ->
|
-spec get_categories(contract() | contract_template(), timestamp(), revision()) ->
|
||||||
ordsets:ordset(category()) | no_return().
|
ordsets:ordset(category()) | no_return().
|
||||||
|
|
||||||
get_categories(Contract, Timestamp, Revision) ->
|
get_categories(Contract, Timestamp, Revision) ->
|
||||||
#domain_TermSet{
|
#domain_TermSet{
|
||||||
payments = #domain_PaymentsServiceTerms{
|
payments = #domain_PaymentsServiceTerms{
|
||||||
@ -125,9 +119,7 @@ get_categories(Contract, Timestamp, Revision) ->
|
|||||||
error({misconfiguration, {'Empty set in category selector\'s value', CategorySelector, Revision}})
|
error({misconfiguration, {'Empty set in category selector\'s value', CategorySelector, Revision}})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_adjustment(adjustment_id(), contract()) ->
|
-spec get_adjustment(adjustment_id(), contract()) -> adjustment() | undefined.
|
||||||
adjustment() | undefined.
|
|
||||||
|
|
||||||
get_adjustment(AdjustmentID, #domain_Contract{adjustments = Adjustments}) ->
|
get_adjustment(AdjustmentID, #domain_Contract{adjustments = Adjustments}) ->
|
||||||
case lists:keysearch(AdjustmentID, #domain_ContractAdjustment.id, Adjustments) of
|
case lists:keysearch(AdjustmentID, #domain_ContractAdjustment.id, Adjustments) of
|
||||||
{value, Adjustment} ->
|
{value, Adjustment} ->
|
||||||
@ -136,9 +128,7 @@ get_adjustment(AdjustmentID, #domain_Contract{adjustments = Adjustments}) ->
|
|||||||
undefined
|
undefined
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_payout_tool(payout_tool_id(), contract()) ->
|
-spec get_payout_tool(payout_tool_id(), contract()) -> payout_tool() | undefined.
|
||||||
payout_tool() | undefined.
|
|
||||||
|
|
||||||
get_payout_tool(PayoutToolID, #domain_Contract{payout_tools = PayoutTools}) ->
|
get_payout_tool(PayoutToolID, #domain_Contract{payout_tools = PayoutTools}) ->
|
||||||
case lists:keysearch(PayoutToolID, #domain_PayoutTool.id, PayoutTools) of
|
case lists:keysearch(PayoutToolID, #domain_PayoutTool.id, PayoutTools) of
|
||||||
{value, PayoutTool} ->
|
{value, PayoutTool} ->
|
||||||
@ -147,25 +137,19 @@ get_payout_tool(PayoutToolID, #domain_Contract{payout_tools = PayoutTools}) ->
|
|||||||
undefined
|
undefined
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec set_payout_tool(payout_tool(), contract()) ->
|
-spec set_payout_tool(payout_tool(), contract()) -> contract().
|
||||||
contract().
|
|
||||||
|
|
||||||
set_payout_tool(PayoutTool, Contract = #domain_Contract{payout_tools = PayoutTools}) ->
|
set_payout_tool(PayoutTool, Contract = #domain_Contract{payout_tools = PayoutTools}) ->
|
||||||
Contract#domain_Contract{
|
Contract#domain_Contract{
|
||||||
payout_tools = lists:keystore(PayoutTool#domain_PayoutTool.id, #domain_PayoutTool.id, PayoutTools, PayoutTool)
|
payout_tools = lists:keystore(PayoutTool#domain_PayoutTool.id, #domain_PayoutTool.id, PayoutTools, PayoutTool)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec is_active(contract()) ->
|
-spec is_active(contract()) -> boolean().
|
||||||
boolean().
|
|
||||||
|
|
||||||
is_active(#domain_Contract{status = {active, _}}) ->
|
is_active(#domain_Contract{status = {active, _}}) ->
|
||||||
true;
|
true;
|
||||||
is_active(_) ->
|
is_active(_) ->
|
||||||
false.
|
false.
|
||||||
|
|
||||||
-spec is_live(contract(), revision()) ->
|
-spec is_live(contract(), revision()) -> boolean().
|
||||||
boolean().
|
|
||||||
|
|
||||||
is_live(Contract, Revision) ->
|
is_live(Contract, Revision) ->
|
||||||
PaymentInstitutionRef = Contract#domain_Contract.payment_institution,
|
PaymentInstitutionRef = Contract#domain_Contract.payment_institution,
|
||||||
PaymentInstitution = get_payment_institution(PaymentInstitutionRef, Revision),
|
PaymentInstitution = get_payment_institution(PaymentInstitutionRef, Revision),
|
||||||
@ -173,9 +157,7 @@ is_live(Contract, Revision) ->
|
|||||||
|
|
||||||
%% Internals
|
%% Internals
|
||||||
|
|
||||||
-spec ensure_contract_creation_params(contract_params(), revision()) ->
|
-spec ensure_contract_creation_params(contract_params(), revision()) -> contract_params() | no_return().
|
||||||
contract_params() | no_return().
|
|
||||||
|
|
||||||
ensure_contract_creation_params(
|
ensure_contract_creation_params(
|
||||||
#payproc_ContractParams{
|
#payproc_ContractParams{
|
||||||
template = TemplateRef,
|
template = TemplateRef,
|
||||||
@ -191,15 +173,12 @@ ensure_contract_creation_params(
|
|||||||
|
|
||||||
-spec ensure_contract_template(contract_template_ref(), dmsl_domain_thrift:'PaymentInstitutionRef'(), revision()) ->
|
-spec ensure_contract_template(contract_template_ref(), dmsl_domain_thrift:'PaymentInstitutionRef'(), revision()) ->
|
||||||
contract_template_ref() | no_return().
|
contract_template_ref() | no_return().
|
||||||
|
|
||||||
ensure_contract_template(#domain_ContractTemplateRef{} = TemplateRef, _, _) ->
|
ensure_contract_template(#domain_ContractTemplateRef{} = TemplateRef, _, _) ->
|
||||||
TemplateRef;
|
TemplateRef;
|
||||||
ensure_contract_template(undefined, PaymentInstitutionRef, Revision) ->
|
ensure_contract_template(undefined, PaymentInstitutionRef, Revision) ->
|
||||||
get_default_template_ref(PaymentInstitutionRef, Revision).
|
get_default_template_ref(PaymentInstitutionRef, Revision).
|
||||||
|
|
||||||
-spec ensure_payment_institution(payment_inst_ref()) ->
|
-spec ensure_payment_institution(payment_inst_ref()) -> payment_inst_ref() | no_return().
|
||||||
payment_inst_ref() | no_return().
|
|
||||||
|
|
||||||
ensure_payment_institution(#domain_PaymentInstitutionRef{} = PaymentInstitutionRef) ->
|
ensure_payment_institution(#domain_PaymentInstitutionRef{} = PaymentInstitutionRef) ->
|
||||||
PaymentInstitutionRef;
|
PaymentInstitutionRef;
|
||||||
ensure_payment_institution(undefined) ->
|
ensure_payment_institution(undefined) ->
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
%%%
|
%%%
|
||||||
|
|
||||||
-module(pm_currency).
|
-module(pm_currency).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([validate_currency/2]).
|
-export([validate_currency/2]).
|
||||||
|
|
||||||
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
|
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
|
||||||
-type shop() :: dmsl_domain_thrift:'Shop'().
|
-type shop() :: dmsl_domain_thrift:'Shop'().
|
||||||
|
|
||||||
-spec validate_currency(currency(), shop()) -> ok.
|
-spec validate_currency(currency(), shop()) -> ok.
|
||||||
validate_currency(Currency, Shop = #domain_Shop{}) ->
|
validate_currency(Currency, Shop = #domain_Shop{}) ->
|
||||||
|
@ -16,51 +16,45 @@
|
|||||||
-type timestamp_interval_bound() :: dmsl_base_thrift:'TimestampIntervalBound'().
|
-type timestamp_interval_bound() :: dmsl_base_thrift:'TimestampIntervalBound'().
|
||||||
|
|
||||||
%% not exported from calendar module
|
%% not exported from calendar module
|
||||||
-type rfc3339_time_unit() :: microsecond
|
-type rfc3339_time_unit() ::
|
||||||
| millisecond
|
microsecond |
|
||||||
| nanosecond
|
millisecond |
|
||||||
| second.
|
nanosecond |
|
||||||
|
second.
|
||||||
|
|
||||||
-export_type([timestamp/0]).
|
-export_type([timestamp/0]).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec format_ts(unix_timestamp()) -> timestamp().
|
-spec format_ts(unix_timestamp()) -> timestamp().
|
||||||
|
|
||||||
format_ts(Ts) when is_integer(Ts) ->
|
format_ts(Ts) when is_integer(Ts) ->
|
||||||
format_ts(Ts, second).
|
format_ts(Ts, second).
|
||||||
|
|
||||||
-spec format_now() -> timestamp().
|
-spec format_now() -> timestamp().
|
||||||
|
|
||||||
format_now() ->
|
format_now() ->
|
||||||
USec = erlang:system_time(microsecond),
|
USec = erlang:system_time(microsecond),
|
||||||
format_ts(USec, microsecond).
|
format_ts(USec, microsecond).
|
||||||
|
|
||||||
-spec compare(timestamp(), timestamp()) -> later | earlier | simultaneously.
|
-spec compare(timestamp(), timestamp()) -> later | earlier | simultaneously.
|
||||||
|
|
||||||
compare(T1, T2) when is_binary(T1) andalso is_binary(T2) ->
|
compare(T1, T2) when is_binary(T1) andalso is_binary(T2) ->
|
||||||
compare_int(to_integer(T1), to_integer(T2)).
|
compare_int(to_integer(T1), to_integer(T2)).
|
||||||
|
|
||||||
% Compare inclusivly! undefined == ∞
|
% Compare inclusivly! undefined == ∞
|
||||||
-spec between(timestamp(), timestamp() | undefined, timestamp() | undefined) -> boolean().
|
-spec between(timestamp(), timestamp() | undefined, timestamp() | undefined) -> boolean().
|
||||||
|
|
||||||
between(Timestamp, Start, End) ->
|
between(Timestamp, Start, End) ->
|
||||||
LB = to_interval_bound(Start, inclusive),
|
LB = to_interval_bound(Start, inclusive),
|
||||||
UB = to_interval_bound(End, inclusive),
|
UB = to_interval_bound(End, inclusive),
|
||||||
between(Timestamp, #'TimestampInterval'{lower_bound = LB, upper_bound = UB}).
|
between(Timestamp, #'TimestampInterval'{lower_bound = LB, upper_bound = UB}).
|
||||||
|
|
||||||
-spec between(timestamp(), timestamp_interval()) -> boolean().
|
-spec between(timestamp(), timestamp_interval()) -> boolean().
|
||||||
|
|
||||||
between(Timestamp, #'TimestampInterval'{lower_bound = LB, upper_bound = UB}) ->
|
between(Timestamp, #'TimestampInterval'{lower_bound = LB, upper_bound = UB}) ->
|
||||||
check_bound(Timestamp, LB, later)
|
check_bound(Timestamp, LB, later) andalso
|
||||||
andalso
|
check_bound(Timestamp, UB, earlier).
|
||||||
check_bound(Timestamp, UB, earlier).
|
|
||||||
|
|
||||||
-spec add_interval(timestamp(), {Years, Months, Days}) -> timestamp() when
|
-spec add_interval(timestamp(), {Years, Months, Days}) -> timestamp() when
|
||||||
Years :: integer() | undefined,
|
Years :: integer() | undefined,
|
||||||
Months :: integer() | undefined,
|
Months :: integer() | undefined,
|
||||||
Days :: integer() | undefined.
|
Days :: integer() | undefined.
|
||||||
|
|
||||||
add_interval(Timestamp, {YY, MM, DD}) ->
|
add_interval(Timestamp, {YY, MM, DD}) ->
|
||||||
TSSeconds = erlang:convert_time_unit(to_integer(Timestamp), microsecond, second),
|
TSSeconds = erlang:convert_time_unit(to_integer(Timestamp), microsecond, second),
|
||||||
{Date, Time} = genlib_time:unixtime_to_daytime(TSSeconds),
|
{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})).
|
format_ts(genlib_time:daytime_to_unixtime({NewDate, Time})).
|
||||||
|
|
||||||
-spec parse(binary(), rfc3339_time_unit()) -> integer().
|
-spec parse(binary(), rfc3339_time_unit()) -> integer().
|
||||||
|
|
||||||
parse(Bin, Precision) when is_binary(Bin) ->
|
parse(Bin, Precision) when is_binary(Bin) ->
|
||||||
Str = erlang:binary_to_list(Bin),
|
Str = erlang:binary_to_list(Bin),
|
||||||
calendar:rfc3339_to_system_time(Str, [{unit, Precision}]).
|
calendar:rfc3339_to_system_time(Str, [{unit, Precision}]).
|
||||||
@ -76,13 +69,11 @@ parse(Bin, Precision) when is_binary(Bin) ->
|
|||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|
||||||
-spec format_ts(integer(), rfc3339_time_unit()) -> timestamp().
|
-spec format_ts(integer(), rfc3339_time_unit()) -> timestamp().
|
||||||
|
|
||||||
format_ts(Ts, Unit) ->
|
format_ts(Ts, Unit) ->
|
||||||
Str = calendar:system_time_to_rfc3339(Ts, [{unit, Unit}, {offset, "Z"}]),
|
Str = calendar:system_time_to_rfc3339(Ts, [{unit, Unit}, {offset, "Z"}]),
|
||||||
erlang:list_to_binary(Str).
|
erlang:list_to_binary(Str).
|
||||||
|
|
||||||
-spec to_integer(timestamp()) -> integer().
|
-spec to_integer(timestamp()) -> integer().
|
||||||
|
|
||||||
to_integer(Timestamp) ->
|
to_integer(Timestamp) ->
|
||||||
parse(Timestamp, microsecond).
|
parse(Timestamp, microsecond).
|
||||||
|
|
||||||
@ -102,7 +93,6 @@ compare_int(T1, T2) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec check_bound(timestamp(), timestamp_interval_bound(), later | earlier) -> boolean().
|
-spec check_bound(timestamp(), timestamp_interval_bound(), later | earlier) -> boolean().
|
||||||
|
|
||||||
check_bound(_, undefined, _) ->
|
check_bound(_, undefined, _) ->
|
||||||
true;
|
true;
|
||||||
check_bound(Timestamp, #'TimestampIntervalBound'{bound_type = Type, bound_time = BoundTime}, Operator) ->
|
check_bound(Timestamp, #'TimestampIntervalBound'{bound_type = Type, bound_time = BoundTime}, Operator) ->
|
||||||
@ -120,6 +110,5 @@ nvl(Val) ->
|
|||||||
|
|
||||||
nvl(undefined, Default) ->
|
nvl(undefined, Default) ->
|
||||||
Default;
|
Default;
|
||||||
|
|
||||||
nvl(Val, _) ->
|
nvl(Val, _) ->
|
||||||
Val.
|
Val.
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
%%% domain objects
|
%%% domain objects
|
||||||
|
|
||||||
-module(pm_domain).
|
-module(pm_domain).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_domain_config_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_config_thrift.hrl").
|
||||||
|
|
||||||
@ -19,6 +20,7 @@
|
|||||||
-export([insert/1]).
|
-export([insert/1]).
|
||||||
-export([update/1]).
|
-export([update/1]).
|
||||||
-export([cleanup/0]).
|
-export([cleanup/0]).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type revision() :: pos_integer().
|
-type revision() :: pos_integer().
|
||||||
@ -32,18 +34,15 @@
|
|||||||
-export_type([data/0]).
|
-export_type([data/0]).
|
||||||
|
|
||||||
-spec head() -> revision().
|
-spec head() -> revision().
|
||||||
|
|
||||||
head() ->
|
head() ->
|
||||||
dmt_client:get_last_version().
|
dmt_client:get_last_version().
|
||||||
|
|
||||||
-spec all(revision()) -> dmsl_domain_thrift:'Domain'().
|
-spec all(revision()) -> dmsl_domain_thrift:'Domain'().
|
||||||
|
|
||||||
all(Revision) ->
|
all(Revision) ->
|
||||||
#'Snapshot'{domain = Domain} = dmt_client:checkout({version, Revision}),
|
#'Snapshot'{domain = Domain} = dmt_client:checkout({version, Revision}),
|
||||||
Domain.
|
Domain.
|
||||||
|
|
||||||
-spec get(revision(), ref()) -> data() | no_return().
|
-spec get(revision(), ref()) -> data() | no_return().
|
||||||
|
|
||||||
get(Revision, Ref) ->
|
get(Revision, Ref) ->
|
||||||
try
|
try
|
||||||
extract_data(dmt_client:checkout_object({version, Revision}, Ref))
|
extract_data(dmt_client:checkout_object({version, Revision}, Ref))
|
||||||
@ -53,7 +52,6 @@ get(Revision, Ref) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec find(revision(), ref()) -> data() | notfound.
|
-spec find(revision(), ref()) -> data() | notfound.
|
||||||
|
|
||||||
find(Revision, Ref) ->
|
find(Revision, Ref) ->
|
||||||
try
|
try
|
||||||
extract_data(dmt_client:checkout_object({version, Revision}, Ref))
|
extract_data(dmt_client:checkout_object({version, Revision}, Ref))
|
||||||
@ -63,7 +61,6 @@ find(Revision, Ref) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec exists(revision(), ref()) -> boolean().
|
-spec exists(revision(), ref()) -> boolean().
|
||||||
|
|
||||||
exists(Revision, Ref) ->
|
exists(Revision, Ref) ->
|
||||||
try
|
try
|
||||||
_ = dmt_client:checkout_object({version, Revision}, Ref),
|
_ = dmt_client:checkout_object({version, Revision}, Ref),
|
||||||
@ -77,14 +74,12 @@ extract_data(#'VersionedObject'{object = {_Tag, {_Name, _Ref, Data}}}) ->
|
|||||||
Data.
|
Data.
|
||||||
|
|
||||||
-spec commit(revision(), dmt_client:commit()) -> ok | no_return().
|
-spec commit(revision(), dmt_client:commit()) -> ok | no_return().
|
||||||
|
|
||||||
commit(Revision, Commit) ->
|
commit(Revision, Commit) ->
|
||||||
Revision = dmt_client:commit(Revision, Commit) - 1,
|
Revision = dmt_client:commit(Revision, Commit) - 1,
|
||||||
_ = pm_domain:all(Revision + 1),
|
_ = pm_domain:all(Revision + 1),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec insert(object() | [object()]) -> ok | no_return().
|
-spec insert(object() | [object()]) -> ok | no_return().
|
||||||
|
|
||||||
insert(Object) when not is_list(Object) ->
|
insert(Object) when not is_list(Object) ->
|
||||||
insert([Object]);
|
insert([Object]);
|
||||||
insert(Objects) ->
|
insert(Objects) ->
|
||||||
@ -92,14 +87,13 @@ insert(Objects) ->
|
|||||||
ops = [
|
ops = [
|
||||||
{insert, #'InsertOp'{
|
{insert, #'InsertOp'{
|
||||||
object = Object
|
object = Object
|
||||||
}} ||
|
}}
|
||||||
Object <- Objects
|
|| Object <- Objects
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
commit(head(), Commit).
|
commit(head(), Commit).
|
||||||
|
|
||||||
-spec update(object() | [object()]) -> ok | no_return().
|
-spec update(object() | [object()]) -> ok | no_return().
|
||||||
|
|
||||||
update(NewObject) when not is_list(NewObject) ->
|
update(NewObject) when not is_list(NewObject) ->
|
||||||
update([NewObject]);
|
update([NewObject]);
|
||||||
update(NewObjects) ->
|
update(NewObjects) ->
|
||||||
@ -111,26 +105,24 @@ update(NewObjects) ->
|
|||||||
new_object = NewObject
|
new_object = NewObject
|
||||||
}}
|
}}
|
||||||
|| NewObject = {Tag, {ObjectName, Ref, _Data}} <- NewObjects,
|
|| NewObject = {Tag, {ObjectName, Ref, _Data}} <- NewObjects,
|
||||||
OldData <- [get(Revision, {Tag, Ref})]
|
OldData <- [get(Revision, {Tag, Ref})]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
commit(Revision, Commit).
|
commit(Revision, Commit).
|
||||||
|
|
||||||
-spec remove([object()]) -> ok | no_return().
|
-spec remove([object()]) -> ok | no_return().
|
||||||
|
|
||||||
remove(Objects) ->
|
remove(Objects) ->
|
||||||
Commit = #'Commit'{
|
Commit = #'Commit'{
|
||||||
ops = [
|
ops = [
|
||||||
{remove, #'RemoveOp'{
|
{remove, #'RemoveOp'{
|
||||||
object = Object
|
object = Object
|
||||||
}} ||
|
}}
|
||||||
Object <- Objects
|
|| Object <- Objects
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
commit(head(), Commit).
|
commit(head(), Commit).
|
||||||
|
|
||||||
-spec cleanup() -> ok | no_return().
|
-spec cleanup() -> ok | no_return().
|
||||||
|
|
||||||
cleanup() ->
|
cleanup() ->
|
||||||
Domain = all(head()),
|
Domain = all(head()),
|
||||||
remove(maps:values(Domain)).
|
remove(maps:values(Domain)).
|
||||||
|
@ -4,31 +4,28 @@
|
|||||||
|
|
||||||
-type source_event() :: _.
|
-type source_event() :: _.
|
||||||
-type public_event() :: {source(), payload()}.
|
-type public_event() :: {source(), payload()}.
|
||||||
-type source() :: dmsl_payment_processing_thrift:'EventSource'().
|
-type source() :: dmsl_payment_processing_thrift:'EventSource'().
|
||||||
-type payload() :: dmsl_payment_processing_thrift:'EventPayload'().
|
-type payload() :: dmsl_payment_processing_thrift:'EventPayload'().
|
||||||
|
|
||||||
-export_type([public_event/0]).
|
-export_type([public_event/0]).
|
||||||
|
|
||||||
-callback publish_event(pm_machine:id(), source_event()) ->
|
-callback publish_event(pm_machine:id(), source_event()) -> public_event().
|
||||||
public_event().
|
|
||||||
|
|
||||||
-export([publish_event/4]).
|
-export([publish_event/4]).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type event_id() :: dmsl_base_thrift:'EventID'().
|
-type event_id() :: dmsl_base_thrift:'EventID'().
|
||||||
-type event() :: dmsl_payment_processing_thrift:'Event'().
|
-type event() :: dmsl_payment_processing_thrift:'Event'().
|
||||||
|
|
||||||
-spec publish_event(pm_machine:ns(), event_id(), pm_machine:id(), pm_machine:event()) ->
|
|
||||||
event().
|
|
||||||
|
|
||||||
|
-spec publish_event(pm_machine:ns(), event_id(), pm_machine:id(), pm_machine:event()) -> event().
|
||||||
publish_event(Ns, EventID, MachineID, {ID, Dt, Ev}) ->
|
publish_event(Ns, EventID, MachineID, {ID, Dt, Ev}) ->
|
||||||
Module = pm_machine:get_handler_module(Ns),
|
Module = pm_machine:get_handler_module(Ns),
|
||||||
{Source, Payload} = Module:publish_event(MachineID, Ev),
|
{Source, Payload} = Module:publish_event(MachineID, Ev),
|
||||||
#payproc_Event{
|
#payproc_Event{
|
||||||
id = EventID,
|
id = EventID,
|
||||||
source = Source,
|
source = Source,
|
||||||
created_at = Dt,
|
created_at = Dt,
|
||||||
payload = Payload,
|
payload = Payload,
|
||||||
sequence = ID
|
sequence = ID
|
||||||
}.
|
}.
|
||||||
|
@ -5,12 +5,11 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([reduce_globals/3]).
|
-export([reduce_globals/3]).
|
||||||
|
|
||||||
-type globals() :: dmsl_domain_thrift:'Globals'().
|
-type globals() :: dmsl_domain_thrift:'Globals'().
|
||||||
-type varset() :: pm_selector:varset().
|
-type varset() :: pm_selector:varset().
|
||||||
-type domain_revision() :: pm_domain:revision().
|
-type domain_revision() :: pm_domain:revision().
|
||||||
|
|
||||||
-spec reduce_globals(globals(), varset(), domain_revision()) -> globals().
|
-spec reduce_globals(globals(), varset(), domain_revision()) -> globals().
|
||||||
|
|
||||||
reduce_globals(Globals, VS, DomainRevision) ->
|
reduce_globals(Globals, VS, DomainRevision) ->
|
||||||
Globals#domain_Globals{
|
Globals#domain_Globals{
|
||||||
external_account_set = pm_selector:reduce(Globals#domain_Globals.external_account_set, VS, DomainRevision)
|
external_account_set = pm_selector:reduce(Globals#domain_Globals.external_account_set, VS, DomainRevision)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
-include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl").
|
-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 id() :: mg_proto_base_thrift:'ID'().
|
||||||
-type tag() :: {tag, mg_proto_base_thrift:'Tag'()}.
|
-type tag() :: {tag, mg_proto_base_thrift:'Tag'()}.
|
||||||
@ -17,44 +17,41 @@
|
|||||||
data := msgp(),
|
data := msgp(),
|
||||||
format_version := pos_integer() | undefined
|
format_version := pos_integer() | undefined
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type timestamp() :: mg_proto_base_thrift:'Timestamp'().
|
-type timestamp() :: mg_proto_base_thrift:'Timestamp'().
|
||||||
-type history() :: [event()].
|
-type history() :: [event()].
|
||||||
-type auxst() :: msgp().
|
-type auxst() :: msgp().
|
||||||
|
|
||||||
-type history_range() :: mg_proto_state_processing_thrift:'HistoryRange'().
|
-type history_range() :: mg_proto_state_processing_thrift:'HistoryRange'().
|
||||||
-type direction() :: mg_proto_state_processing_thrift:'Direction'().
|
-type direction() :: mg_proto_state_processing_thrift:'Direction'().
|
||||||
-type descriptor() :: mg_proto_state_processing_thrift:'MachineDescriptor'().
|
-type descriptor() :: mg_proto_state_processing_thrift:'MachineDescriptor'().
|
||||||
|
|
||||||
-type machine() :: #{
|
-type machine() :: #{
|
||||||
id := id(),
|
id := id(),
|
||||||
history := history(),
|
history := history(),
|
||||||
aux_state := auxst()
|
aux_state := auxst()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type result() :: #{
|
-type result() :: #{
|
||||||
events => [event_payload()],
|
events => [event_payload()],
|
||||||
action => pm_machine_action:t(),
|
action => pm_machine_action:t(),
|
||||||
auxst => auxst()
|
auxst => auxst()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-callback namespace() ->
|
-callback namespace() -> ns().
|
||||||
ns().
|
|
||||||
|
|
||||||
-callback init(args(), machine()) ->
|
-callback init(args(), machine()) -> result().
|
||||||
result().
|
|
||||||
|
|
||||||
-type signal() ::
|
-type signal() ::
|
||||||
timeout | {repair, args()}.
|
timeout | {repair, args()}.
|
||||||
|
|
||||||
-callback process_signal(signal(), machine()) ->
|
-callback process_signal(signal(), machine()) -> result().
|
||||||
result().
|
|
||||||
|
|
||||||
-type call() :: _.
|
-type call() :: _.
|
||||||
-type thrift_call() :: {pm_proto_utils:thrift_fun_ref(), woody:args()}.
|
-type thrift_call() :: {pm_proto_utils:thrift_fun_ref(), woody:args()}.
|
||||||
-type response() :: ok | {ok, term()} | {exception, term()}.
|
-type response() :: ok | {ok, term()} | {exception, term()}.
|
||||||
|
|
||||||
-callback process_call(call(), machine()) ->
|
-callback process_call(call(), machine()) -> {response(), result()}.
|
||||||
{response(), result()}.
|
|
||||||
|
|
||||||
-type context() :: #{
|
-type context() :: #{
|
||||||
client_context => woody_context:ctx()
|
client_context => woody_context:ctx()
|
||||||
@ -113,13 +110,11 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec start(ns(), id(), term()) ->
|
-spec start(ns(), id(), term()) -> {ok, term()} | {error, exists | term()} | no_return().
|
||||||
{ok, term()} | {error, exists | term()} | no_return().
|
|
||||||
start(Ns, ID, Args) ->
|
start(Ns, ID, Args) ->
|
||||||
call_automaton('Start', {Ns, ID, wrap_args(Args)}).
|
call_automaton('Start', {Ns, ID, wrap_args(Args)}).
|
||||||
|
|
||||||
-spec thrift_call(ns(), ref(), service_name(), function_ref(), args()) ->
|
-spec thrift_call(ns(), ref(), service_name(), function_ref(), args()) -> response() | {error, notfound | failed}.
|
||||||
response() | {error, notfound | failed}.
|
|
||||||
thrift_call(Ns, Ref, Service, FunRef, Args) ->
|
thrift_call(Ns, Ref, Service, FunRef, Args) ->
|
||||||
thrift_call(Ns, Ref, Service, FunRef, Args, undefined, undefined, forward).
|
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
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec call(ns(), ref(), Args :: term()) ->
|
-spec call(ns(), ref(), Args :: term()) -> response() | {error, notfound | failed}.
|
||||||
response() | {error, notfound | failed}.
|
|
||||||
call(Ns, Ref, Args) ->
|
call(Ns, Ref, Args) ->
|
||||||
call(Ns, Ref, Args, undefined, undefined, forward).
|
call(Ns, Ref, Args, undefined, undefined, forward).
|
||||||
|
|
||||||
@ -165,28 +159,22 @@ call(Ns, Ref, Args, After, Limit, Direction) ->
|
|||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec repair(ns(), ref(), term()) ->
|
-spec repair(ns(), ref(), term()) -> {ok, term()} | {error, notfound | failed | working} | no_return().
|
||||||
{ok, term()} | {error, notfound | failed | working} | no_return().
|
|
||||||
|
|
||||||
repair(Ns, Ref, Args) ->
|
repair(Ns, Ref, Args) ->
|
||||||
Descriptor = prepare_descriptor(Ns, Ref, #mg_stateproc_HistoryRange{}),
|
Descriptor = prepare_descriptor(Ns, Ref, #mg_stateproc_HistoryRange{}),
|
||||||
call_automaton('Repair', {Descriptor, wrap_args(Args)}).
|
call_automaton('Repair', {Descriptor, wrap_args(Args)}).
|
||||||
|
|
||||||
-spec get_history(ns(), ref()) ->
|
-spec get_history(ns(), ref()) -> {ok, history()} | {error, notfound} | no_return().
|
||||||
{ok, history()} | {error, notfound} | no_return().
|
|
||||||
|
|
||||||
get_history(Ns, Ref) ->
|
get_history(Ns, Ref) ->
|
||||||
get_history(Ns, Ref, undefined, undefined, forward).
|
get_history(Ns, Ref, undefined, undefined, forward).
|
||||||
|
|
||||||
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer()) ->
|
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer()) ->
|
||||||
{ok, history()} | {error, notfound} | no_return().
|
{ok, history()} | {error, notfound} | no_return().
|
||||||
|
|
||||||
get_history(Ns, Ref, AfterID, Limit) ->
|
get_history(Ns, Ref, AfterID, Limit) ->
|
||||||
get_history(Ns, Ref, AfterID, Limit, forward).
|
get_history(Ns, Ref, AfterID, Limit, forward).
|
||||||
|
|
||||||
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
|
-spec get_history(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
|
||||||
{ok, history()} | {error, notfound} | no_return().
|
{ok, history()} | {error, notfound} | no_return().
|
||||||
|
|
||||||
get_history(Ns, Ref, AfterID, Limit, Direction) ->
|
get_history(Ns, Ref, AfterID, Limit, Direction) ->
|
||||||
case get_machine(Ns, Ref, AfterID, Limit, Direction) of
|
case get_machine(Ns, Ref, AfterID, Limit, Direction) of
|
||||||
{ok, #{history := History}} ->
|
{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()) ->
|
-spec get_machine(ns(), ref(), undefined | event_id(), undefined | non_neg_integer(), direction()) ->
|
||||||
{ok, machine()} | {error, notfound} | no_return().
|
{ok, machine()} | {error, notfound} | no_return().
|
||||||
|
|
||||||
get_machine(Ns, Ref, AfterID, Limit, Direction) ->
|
get_machine(Ns, Ref, AfterID, Limit, Direction) ->
|
||||||
Range = #mg_stateproc_HistoryRange{'after' = AfterID, limit = Limit, direction = Direction},
|
Range = #mg_stateproc_HistoryRange{'after' = AfterID, limit = Limit, direction = Direction},
|
||||||
Descriptor = prepare_descriptor(Ns, Ref, Range),
|
Descriptor = prepare_descriptor(Ns, Ref, Range),
|
||||||
@ -250,16 +237,14 @@ call_automaton(Function, Args) ->
|
|||||||
|
|
||||||
-type func() :: 'ProcessSignal' | 'ProcessCall'.
|
-type func() :: 'ProcessSignal' | 'ProcessCall'.
|
||||||
|
|
||||||
-spec handle_function(func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
|
-spec handle_function(func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
term() | no_return().
|
|
||||||
|
|
||||||
handle_function(Func, Args, Opts) ->
|
handle_function(Func, Args, Opts) ->
|
||||||
scoper:scope(machine,
|
scoper:scope(
|
||||||
|
machine,
|
||||||
fun() -> handle_function_(Func, Args, Opts) end
|
fun() -> handle_function_(Func, Args, Opts) end
|
||||||
).
|
).
|
||||||
|
|
||||||
-spec handle_function_(func(), woody:args(), #{ns := ns()}) -> term() | no_return().
|
-spec handle_function_(func(), woody:args(), #{ns := ns()}) -> term() | no_return().
|
||||||
|
|
||||||
handle_function_('ProcessSignal', {Args}, #{ns := Ns} = _Opts) ->
|
handle_function_('ProcessSignal', {Args}, #{ns := Ns} = _Opts) ->
|
||||||
#mg_stateproc_SignalArgs{signal = {Type, Signal}, machine = #mg_stateproc_Machine{id = ID} = Machine} = Args,
|
#mg_stateproc_SignalArgs{signal = {Type, Signal}, machine = #mg_stateproc_Machine{id = ID} = Machine} = Args,
|
||||||
scoper:add_meta(#{
|
scoper:add_meta(#{
|
||||||
@ -269,7 +254,6 @@ handle_function_('ProcessSignal', {Args}, #{ns := Ns} = _Opts) ->
|
|||||||
signal => Type
|
signal => Type
|
||||||
}),
|
}),
|
||||||
dispatch_signal(Ns, Signal, unmarshal_machine(Machine));
|
dispatch_signal(Ns, Signal, unmarshal_machine(Machine));
|
||||||
|
|
||||||
handle_function_('ProcessCall', {Args}, #{ns := Ns} = _Opts) ->
|
handle_function_('ProcessCall', {Args}, #{ns := Ns} = _Opts) ->
|
||||||
#mg_stateproc_CallArgs{arg = Payload, machine = #mg_stateproc_Machine{id = ID} = Machine} = Args,
|
#mg_stateproc_CallArgs{arg = Payload, machine = #mg_stateproc_Machine{id = ID} = Machine} = Args,
|
||||||
scoper:add_meta(#{
|
scoper:add_meta(#{
|
||||||
@ -281,28 +265,24 @@ handle_function_('ProcessCall', {Args}, #{ns := Ns} = _Opts) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec dispatch_signal(ns(), Signal, machine()) ->
|
-spec dispatch_signal(ns(), Signal, machine()) -> Result when
|
||||||
Result when
|
Signal ::
|
||||||
Signal ::
|
mg_proto_state_processing_thrift:'InitSignal'() |
|
||||||
mg_proto_state_processing_thrift:'InitSignal'() |
|
mg_proto_state_processing_thrift:'TimeoutSignal'() |
|
||||||
mg_proto_state_processing_thrift:'TimeoutSignal'() |
|
mg_proto_state_processing_thrift:'RepairSignal'(),
|
||||||
mg_proto_state_processing_thrift:'RepairSignal'(),
|
Result ::
|
||||||
Result ::
|
mg_proto_state_processing_thrift:'SignalResult'().
|
||||||
mg_proto_state_processing_thrift:'SignalResult'().
|
|
||||||
|
|
||||||
dispatch_signal(Ns, #mg_stateproc_InitSignal{arg = Payload}, Machine) ->
|
dispatch_signal(Ns, #mg_stateproc_InitSignal{arg = Payload}, Machine) ->
|
||||||
Args = unwrap_args(Payload),
|
Args = unwrap_args(Payload),
|
||||||
_ = log_dispatch(init, Args, Machine),
|
_ = log_dispatch(init, Args, Machine),
|
||||||
Module = get_handler_module(Ns),
|
Module = get_handler_module(Ns),
|
||||||
Result = Module:init(Args, Machine),
|
Result = Module:init(Args, Machine),
|
||||||
marshal_signal_result(Result, Machine);
|
marshal_signal_result(Result, Machine);
|
||||||
|
|
||||||
dispatch_signal(Ns, #mg_stateproc_TimeoutSignal{}, Machine) ->
|
dispatch_signal(Ns, #mg_stateproc_TimeoutSignal{}, Machine) ->
|
||||||
_ = log_dispatch(timeout, Machine),
|
_ = log_dispatch(timeout, Machine),
|
||||||
Module = get_handler_module(Ns),
|
Module = get_handler_module(Ns),
|
||||||
Result = Module:process_signal(timeout, Machine),
|
Result = Module:process_signal(timeout, Machine),
|
||||||
marshal_signal_result(Result, Machine);
|
marshal_signal_result(Result, Machine);
|
||||||
|
|
||||||
dispatch_signal(Ns, #mg_stateproc_RepairSignal{arg = Payload}, Machine) ->
|
dispatch_signal(Ns, #mg_stateproc_RepairSignal{arg = Payload}, Machine) ->
|
||||||
Args = unwrap_args(Payload),
|
Args = unwrap_args(Payload),
|
||||||
_ = log_dispatch(repair, Args, Machine),
|
_ = 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())
|
action = maps:get(action, Result, pm_machine_action:new())
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec dispatch_call(ns(), Call, machine()) ->
|
-spec dispatch_call(ns(), Call, machine()) -> Result when
|
||||||
Result when
|
Call :: mg_proto_state_processing_thrift:'Args'(),
|
||||||
Call :: mg_proto_state_processing_thrift:'Args'(),
|
Result :: mg_proto_state_processing_thrift:'CallResult'().
|
||||||
Result :: mg_proto_state_processing_thrift:'CallResult'().
|
|
||||||
|
|
||||||
dispatch_call(Ns, Payload, Machine) ->
|
dispatch_call(Ns, Payload, Machine) ->
|
||||||
Args = unwrap_args(Payload),
|
Args = unwrap_args(Payload),
|
||||||
_ = log_dispatch(call, Args, Machine),
|
_ = log_dispatch(call, Args, Machine),
|
||||||
@ -358,9 +336,7 @@ marshal_call_result(Response, Result, #{aux_state := AuxStWas}) ->
|
|||||||
-type service_handler() ::
|
-type service_handler() ::
|
||||||
{Path :: string(), {woody:service(), {module(), pm_woody_wrapper:handler_opts()}}}.
|
{Path :: string(), {woody:service(), {module(), pm_woody_wrapper:handler_opts()}}}.
|
||||||
|
|
||||||
-spec get_child_spec([MachineHandler :: module()]) ->
|
-spec get_child_spec([MachineHandler :: module()]) -> supervisor:child_spec().
|
||||||
supervisor:child_spec().
|
|
||||||
|
|
||||||
get_child_spec(MachineHandlers) ->
|
get_child_spec(MachineHandlers) ->
|
||||||
#{
|
#{
|
||||||
id => pm_machine_dispatch,
|
id => pm_machine_dispatch,
|
||||||
@ -368,9 +344,7 @@ get_child_spec(MachineHandlers) ->
|
|||||||
type => supervisor
|
type => supervisor
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_service_handlers([MachineHandler :: module()], map()) ->
|
-spec get_service_handlers([MachineHandler :: module()], map()) -> [service_handler()].
|
||||||
[service_handler()].
|
|
||||||
|
|
||||||
get_service_handlers(MachineHandlers, Opts) ->
|
get_service_handlers(MachineHandlers, Opts) ->
|
||||||
[get_service_handler(H, Opts) || H <- MachineHandlers].
|
[get_service_handler(H, Opts) || H <- MachineHandlers].
|
||||||
|
|
||||||
@ -384,15 +358,11 @@ get_service_handler(MachineHandler, Opts) ->
|
|||||||
|
|
||||||
-define(TABLE, pm_machine_dispatch).
|
-define(TABLE, pm_machine_dispatch).
|
||||||
|
|
||||||
-spec start_link([module()]) ->
|
-spec start_link([module()]) -> {ok, pid()}.
|
||||||
{ok, pid()}.
|
|
||||||
|
|
||||||
start_link(MachineHandlers) ->
|
start_link(MachineHandlers) ->
|
||||||
supervisor:start_link(?MODULE, MachineHandlers).
|
supervisor:start_link(?MODULE, MachineHandlers).
|
||||||
|
|
||||||
-spec init([module()]) ->
|
-spec init([module()]) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
|
||||||
{ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
|
|
||||||
|
|
||||||
init(MachineHandlers) ->
|
init(MachineHandlers) ->
|
||||||
_ = ets:new(?TABLE, [protected, named_table, {read_concurrency, true}]),
|
_ = ets:new(?TABLE, [protected, named_table, {read_concurrency, true}]),
|
||||||
true = ets:insert_new(?TABLE, [{MH:namespace(), MH} || MH <- MachineHandlers]),
|
true = ets:insert_new(?TABLE, [{MH:namespace(), MH} || MH <- MachineHandlers]),
|
||||||
@ -401,7 +371,6 @@ init(MachineHandlers) ->
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-spec get_handler_module(ns()) -> module().
|
-spec get_handler_module(ns()) -> module().
|
||||||
|
|
||||||
get_handler_module(Ns) ->
|
get_handler_module(Ns) ->
|
||||||
ets:lookup_element(?TABLE, Ns, 2).
|
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) ->
|
unmarshal_machine(#mg_stateproc_Machine{id = ID, history = History} = Machine) ->
|
||||||
AuxState = get_aux_state(Machine),
|
AuxState = get_aux_state(Machine),
|
||||||
#{
|
#{
|
||||||
id => ID,
|
id => ID,
|
||||||
history => unmarshal_events(History),
|
history => unmarshal_events(History),
|
||||||
aux_state => AuxState
|
aux_state => AuxState
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec marshal_events([event_payload()]) ->
|
-spec marshal_events([event_payload()]) -> [mg_event_payload()].
|
||||||
[mg_event_payload()].
|
|
||||||
marshal_events(Events) when is_list(Events) ->
|
marshal_events(Events) when is_list(Events) ->
|
||||||
[marshal_event(Event) || Event <- Events].
|
[marshal_event(Event) || Event <- Events].
|
||||||
|
|
||||||
-spec marshal_event(event_payload()) ->
|
-spec marshal_event(event_payload()) -> mg_event_payload().
|
||||||
mg_event_payload().
|
|
||||||
marshal_event(#{format_version := Format, data := Data}) ->
|
marshal_event(#{format_version := Format, data := Data}) ->
|
||||||
#mg_stateproc_Content{
|
#mg_stateproc_Content{
|
||||||
format_version = Format,
|
format_version = Format,
|
||||||
@ -444,24 +411,21 @@ marshal_aux_st_format(AuxSt) ->
|
|||||||
data = mg_msgpack_marshalling:marshal(AuxSt)
|
data = mg_msgpack_marshalling:marshal(AuxSt)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec marshal_thrift_args(service_name(), function_ref(), args()) ->
|
-spec marshal_thrift_args(service_name(), function_ref(), args()) -> binary().
|
||||||
binary().
|
|
||||||
marshal_thrift_args(ServiceName, FunctionRef, Args) ->
|
marshal_thrift_args(ServiceName, FunctionRef, Args) ->
|
||||||
{Service, _Function} = FunctionRef,
|
{Service, _Function} = FunctionRef,
|
||||||
{Module, Service} = pm_proto:get_service(ServiceName),
|
{Module, Service} = pm_proto:get_service(ServiceName),
|
||||||
FullFunctionRef = {Module, FunctionRef},
|
FullFunctionRef = {Module, FunctionRef},
|
||||||
pm_proto_utils:serialize_function_args(FullFunctionRef, Args).
|
pm_proto_utils:serialize_function_args(FullFunctionRef, Args).
|
||||||
|
|
||||||
-spec unmarshal_thrift_args(service_name(), function_ref(), binary()) ->
|
-spec unmarshal_thrift_args(service_name(), function_ref(), binary()) -> args().
|
||||||
args().
|
|
||||||
unmarshal_thrift_args(ServiceName, FunctionRef, Args) ->
|
unmarshal_thrift_args(ServiceName, FunctionRef, Args) ->
|
||||||
{Service, _Function} = FunctionRef,
|
{Service, _Function} = FunctionRef,
|
||||||
{Module, Service} = pm_proto:get_service(ServiceName),
|
{Module, Service} = pm_proto:get_service(ServiceName),
|
||||||
FullFunctionRef = {Module, FunctionRef},
|
FullFunctionRef = {Module, FunctionRef},
|
||||||
pm_proto_utils:deserialize_function_args(FullFunctionRef, Args).
|
pm_proto_utils:deserialize_function_args(FullFunctionRef, Args).
|
||||||
|
|
||||||
-spec marshal_thrift_response(service_name(), function_ref(), response()) ->
|
-spec marshal_thrift_response(service_name(), function_ref(), response()) -> response().
|
||||||
response().
|
|
||||||
marshal_thrift_response(ServiceName, FunctionRef, Response) ->
|
marshal_thrift_response(ServiceName, FunctionRef, Response) ->
|
||||||
{Service, _Function} = FunctionRef,
|
{Service, _Function} = FunctionRef,
|
||||||
{Module, Service} = pm_proto:get_service(ServiceName),
|
{Module, Service} = pm_proto:get_service(ServiceName),
|
||||||
@ -477,8 +441,7 @@ marshal_thrift_response(ServiceName, FunctionRef, Response) ->
|
|||||||
{exception, EncodedException}
|
{exception, EncodedException}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec unmarshal_thrift_response(service_name(), function_ref(), response()) ->
|
-spec unmarshal_thrift_response(service_name(), function_ref(), response()) -> response().
|
||||||
response().
|
|
||||||
unmarshal_thrift_response(ServiceName, FunctionRef, Response) ->
|
unmarshal_thrift_response(ServiceName, FunctionRef, Response) ->
|
||||||
{Service, _Function} = FunctionRef,
|
{Service, _Function} = FunctionRef,
|
||||||
{Module, Service} = pm_proto:get_service(ServiceName),
|
{Module, Service} = pm_proto:get_service(ServiceName),
|
||||||
@ -494,8 +457,7 @@ unmarshal_thrift_response(ServiceName, FunctionRef, Response) ->
|
|||||||
{exception, Exception}
|
{exception, Exception}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec marshal_schemaless_response(response()) ->
|
-spec marshal_schemaless_response(response()) -> response().
|
||||||
response().
|
|
||||||
marshal_schemaless_response(ok) ->
|
marshal_schemaless_response(ok) ->
|
||||||
ok;
|
ok;
|
||||||
marshal_schemaless_response({ok, _Reply} = Response) ->
|
marshal_schemaless_response({ok, _Reply} = Response) ->
|
||||||
@ -503,8 +465,7 @@ marshal_schemaless_response({ok, _Reply} = Response) ->
|
|||||||
marshal_schemaless_response({exception, _Exception} = Response) ->
|
marshal_schemaless_response({exception, _Exception} = Response) ->
|
||||||
Response.
|
Response.
|
||||||
|
|
||||||
-spec unmarshal_schemaless_response(response()) ->
|
-spec unmarshal_schemaless_response(response()) -> response().
|
||||||
response().
|
|
||||||
unmarshal_schemaless_response(ok) ->
|
unmarshal_schemaless_response(ok) ->
|
||||||
ok;
|
ok;
|
||||||
unmarshal_schemaless_response({ok, _Reply} = Response) ->
|
unmarshal_schemaless_response({ok, _Reply} = Response) ->
|
||||||
@ -522,13 +483,11 @@ marshal_response({exception, _Exception} = Response) ->
|
|||||||
unmarshal_response(Response) ->
|
unmarshal_response(Response) ->
|
||||||
unmarshal_term(Response).
|
unmarshal_term(Response).
|
||||||
|
|
||||||
-spec unmarshal_events([mg_event()]) ->
|
-spec unmarshal_events([mg_event()]) -> [event()].
|
||||||
[event()].
|
|
||||||
unmarshal_events(Events) when is_list(Events) ->
|
unmarshal_events(Events) when is_list(Events) ->
|
||||||
[unmarshal_event(Event) || Event <- Events].
|
[unmarshal_event(Event) || Event <- Events].
|
||||||
|
|
||||||
-spec unmarshal_event(mg_event()) ->
|
-spec unmarshal_event(mg_event()) -> event().
|
||||||
event().
|
|
||||||
unmarshal_event(#mg_stateproc_Event{id = ID, created_at = Dt, format_version = Format, data = Payload}) ->
|
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)}}.
|
{ID, Dt, #{format_version => Format, data => mg_msgpack_marshalling:unmarshal(Payload)}}.
|
||||||
|
|
||||||
|
@ -13,6 +13,5 @@
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-spec new() -> t().
|
-spec new() -> t().
|
||||||
|
|
||||||
new() ->
|
new() ->
|
||||||
#mg_stateproc_ComplexAction{}.
|
#mg_stateproc_ComplexAction{}.
|
||||||
|
@ -11,21 +11,17 @@
|
|||||||
|
|
||||||
-export_type([maybe/1]).
|
-export_type([maybe/1]).
|
||||||
|
|
||||||
-spec apply(fun(), Arg :: undefined | term()) ->
|
-spec apply(fun(), Arg :: undefined | term()) -> term().
|
||||||
term().
|
|
||||||
apply(Fun, Arg) ->
|
apply(Fun, Arg) ->
|
||||||
pm_maybe:apply(Fun, Arg, undefined).
|
pm_maybe:apply(Fun, Arg, undefined).
|
||||||
|
|
||||||
-spec apply(fun(), Arg :: undefined | term(), Default :: term()) ->
|
-spec apply(fun(), Arg :: undefined | term(), Default :: term()) -> term().
|
||||||
term().
|
|
||||||
apply(Fun, Arg, _Default) when Arg =/= undefined ->
|
apply(Fun, Arg, _Default) when Arg =/= undefined ->
|
||||||
Fun(Arg);
|
Fun(Arg);
|
||||||
apply(_Fun, undefined, Default) ->
|
apply(_Fun, undefined, Default) ->
|
||||||
Default.
|
Default.
|
||||||
|
|
||||||
-spec get_defined([maybe(T)]) ->
|
-spec get_defined([maybe(T)]) -> T | no_return().
|
||||||
T | no_return().
|
|
||||||
|
|
||||||
get_defined([]) ->
|
get_defined([]) ->
|
||||||
erlang:error(badarg);
|
erlang:error(badarg);
|
||||||
get_defined([Value | _Tail]) when Value =/= undefined ->
|
get_defined([Value | _Tail]) when Value =/= undefined ->
|
||||||
@ -33,9 +29,6 @@ get_defined([Value | _Tail]) when Value =/= undefined ->
|
|||||||
get_defined([undefined | Tail]) ->
|
get_defined([undefined | Tail]) ->
|
||||||
get_defined(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) ->
|
||||||
get_defined([V1, V2]).
|
get_defined([V1, V2]).
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-module(pm_msgpack_marshalling).
|
-module(pm_msgpack_marshalling).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_msgpack_thrift.hrl").
|
-include_lib("damsel/include/dmsl_msgpack_thrift.hrl").
|
||||||
-include_lib("mg_proto/include/mg_proto_msgpack_thrift.hrl").
|
-include_lib("mg_proto/include/mg_proto_msgpack_thrift.hrl").
|
||||||
|
|
||||||
@ -23,8 +24,7 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec marshal(msgpack_value()) ->
|
-spec marshal(msgpack_value()) -> dmsl_msgpack_thrift:'Value'().
|
||||||
dmsl_msgpack_thrift:'Value'().
|
|
||||||
marshal(undefined) ->
|
marshal(undefined) ->
|
||||||
{nl, #msgpack_Nil{}};
|
{nl, #msgpack_Nil{}};
|
||||||
marshal(Boolean) when is_boolean(Boolean) ->
|
marshal(Boolean) when is_boolean(Boolean) ->
|
||||||
@ -38,19 +38,18 @@ marshal(String) when is_binary(String) ->
|
|||||||
marshal({bin, Binary}) ->
|
marshal({bin, Binary}) ->
|
||||||
{bin, Binary};
|
{bin, Binary};
|
||||||
marshal(Object) when is_map(Object) ->
|
marshal(Object) when is_map(Object) ->
|
||||||
{obj, maps:fold(
|
{obj,
|
||||||
fun(K, V, Acc) ->
|
maps:fold(
|
||||||
maps:put(marshal(K), marshal(V), Acc)
|
fun(K, V, Acc) ->
|
||||||
end,
|
maps:put(marshal(K), marshal(V), Acc)
|
||||||
#{},
|
end,
|
||||||
Object
|
#{},
|
||||||
)};
|
Object
|
||||||
|
)};
|
||||||
marshal(Array) when is_list(Array) ->
|
marshal(Array) when is_list(Array) ->
|
||||||
{arr, lists:map(fun marshal/1, Array)}.
|
{arr, lists:map(fun marshal/1, Array)}.
|
||||||
|
|
||||||
-spec unmarshal(dmsl_msgpack_thrift:'Value'()) ->
|
-spec unmarshal(dmsl_msgpack_thrift:'Value'()) -> msgpack_value().
|
||||||
msgpack_value().
|
|
||||||
|
|
||||||
unmarshal({nl, #msgpack_Nil{}}) ->
|
unmarshal({nl, #msgpack_Nil{}}) ->
|
||||||
undefined;
|
undefined;
|
||||||
unmarshal({b, Boolean}) ->
|
unmarshal({b, Boolean}) ->
|
||||||
|
@ -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/merchant.md
|
||||||
%% * https://github.com/rbkmoney/coredocs/blob/529bc03/docs/domain/entities/contract.md
|
%% * https://github.com/rbkmoney/coredocs/blob/529bc03/docs/domain/entities/contract.md
|
||||||
|
|
||||||
|
|
||||||
%% @TODO
|
%% @TODO
|
||||||
%% * Deal with default shop services (will need to change thrift-protocol as well)
|
%% * Deal with default shop services (will need to change thrift-protocol as well)
|
||||||
%% * Access check before shop creation is weird (think about adding context)
|
%% * Access check before shop creation is weird (think about adding context)
|
||||||
@ -11,6 +10,7 @@
|
|||||||
-module(pm_party).
|
-module(pm_party).
|
||||||
|
|
||||||
-include("party_events.hrl").
|
-include("party_events.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_accounter_thrift.hrl").
|
-include_lib("damsel/include/dmsl_accounter_thrift.hrl").
|
||||||
|
|
||||||
@ -55,62 +55,53 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type party() :: dmsl_domain_thrift:'Party'().
|
-type party() :: dmsl_domain_thrift:'Party'().
|
||||||
-type party_id() :: dmsl_domain_thrift:'PartyID'().
|
-type party_id() :: dmsl_domain_thrift:'PartyID'().
|
||||||
-type party_revision() :: dmsl_domain_thrift:'PartyRevision'().
|
-type party_revision() :: dmsl_domain_thrift:'PartyRevision'().
|
||||||
-type party_status() :: dmsl_domain_thrift:'PartyStatus'().
|
-type party_status() :: dmsl_domain_thrift:'PartyStatus'().
|
||||||
-type contract() :: dmsl_domain_thrift:'Contract'().
|
-type contract() :: dmsl_domain_thrift:'Contract'().
|
||||||
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
||||||
-type contractor() :: dmsl_domain_thrift:'PartyContractor'().
|
-type contractor() :: dmsl_domain_thrift:'PartyContractor'().
|
||||||
-type contractor_id() :: dmsl_domain_thrift:'ContractorID'().
|
-type contractor_id() :: dmsl_domain_thrift:'ContractorID'().
|
||||||
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
|
-type contract_template() :: dmsl_domain_thrift:'ContractTemplate'().
|
||||||
-type shop() :: dmsl_domain_thrift:'Shop'().
|
-type shop() :: dmsl_domain_thrift:'Shop'().
|
||||||
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
|
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
|
||||||
-type shop_params() :: dmsl_payment_processing_thrift:'ShopParams'().
|
-type shop_params() :: dmsl_payment_processing_thrift:'ShopParams'().
|
||||||
-type wallet() :: dmsl_domain_thrift:'Wallet'().
|
-type wallet() :: dmsl_domain_thrift:'Wallet'().
|
||||||
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
|
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
|
||||||
|
|
||||||
-type blocking() :: dmsl_domain_thrift:'Blocking'().
|
-type blocking() :: dmsl_domain_thrift:'Blocking'().
|
||||||
-type suspension() :: dmsl_domain_thrift:'Suspension'().
|
-type suspension() :: dmsl_domain_thrift:'Suspension'().
|
||||||
|
|
||||||
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
|
|
||||||
-type revision() :: pm_domain:revision().
|
|
||||||
|
|
||||||
|
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
|
||||||
|
-type revision() :: pm_domain:revision().
|
||||||
|
|
||||||
%% Interface
|
%% Interface
|
||||||
|
|
||||||
-spec create_party(party_id(), dmsl_domain_thrift:'PartyContactInfo'(), timestamp()) ->
|
-spec create_party(party_id(), dmsl_domain_thrift:'PartyContactInfo'(), timestamp()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
create_party(PartyID, ContactInfo, Timestamp) ->
|
create_party(PartyID, ContactInfo, Timestamp) ->
|
||||||
#domain_Party{
|
#domain_Party{
|
||||||
id = PartyID,
|
id = PartyID,
|
||||||
created_at = Timestamp,
|
created_at = Timestamp,
|
||||||
revision = 0,
|
revision = 0,
|
||||||
contact_info = ContactInfo,
|
contact_info = ContactInfo,
|
||||||
blocking = ?unblocked(Timestamp),
|
blocking = ?unblocked(Timestamp),
|
||||||
suspension = ?active(Timestamp),
|
suspension = ?active(Timestamp),
|
||||||
contractors = #{},
|
contractors = #{},
|
||||||
contracts = #{},
|
contracts = #{},
|
||||||
shops = #{},
|
shops = #{},
|
||||||
wallets = #{}
|
wallets = #{}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec blocking(blocking(), party()) ->
|
-spec blocking(blocking(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
blocking(Blocking, Party) ->
|
blocking(Blocking, Party) ->
|
||||||
Party#domain_Party{blocking = Blocking}.
|
Party#domain_Party{blocking = Blocking}.
|
||||||
|
|
||||||
-spec suspension(suspension(), party()) ->
|
-spec suspension(suspension(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
suspension(Suspension, Party) ->
|
suspension(Suspension, Party) ->
|
||||||
Party#domain_Party{suspension = Suspension}.
|
Party#domain_Party{suspension = Suspension}.
|
||||||
|
|
||||||
-spec get_status(party()) ->
|
-spec get_status(party()) -> party_status().
|
||||||
party_status().
|
|
||||||
|
|
||||||
get_status(Party) ->
|
get_status(Party) ->
|
||||||
#domain_PartyStatus{
|
#domain_PartyStatus{
|
||||||
id = Party#domain_Party.id,
|
id = Party#domain_Party.id,
|
||||||
@ -119,39 +110,28 @@ get_status(Party) ->
|
|||||||
suspension = Party#domain_Party.suspension
|
suspension = Party#domain_Party.suspension
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_contractor(contractor_id(), party()) ->
|
-spec get_contractor(contractor_id(), party()) -> contractor() | undefined.
|
||||||
contractor() | undefined.
|
|
||||||
|
|
||||||
get_contractor(ID, #domain_Party{contractors = Contractors}) ->
|
get_contractor(ID, #domain_Party{contractors = Contractors}) ->
|
||||||
maps:get(ID, Contractors, undefined).
|
maps:get(ID, Contractors, undefined).
|
||||||
|
|
||||||
-spec set_contractor(contractor(), party()) ->
|
-spec set_contractor(contractor(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
set_contractor(Contractor = #domain_PartyContractor{id = ID}, Party = #domain_Party{contractors = Contractors}) ->
|
set_contractor(Contractor = #domain_PartyContractor{id = ID}, Party = #domain_Party{contractors = Contractors}) ->
|
||||||
Party#domain_Party{contractors = Contractors#{ID => Contractor}}.
|
Party#domain_Party{contractors = Contractors#{ID => Contractor}}.
|
||||||
|
|
||||||
-spec get_contract(contract_id(), party()) ->
|
-spec get_contract(contract_id(), party()) -> contract() | undefined.
|
||||||
contract() | undefined.
|
|
||||||
|
|
||||||
get_contract(ID, #domain_Party{contracts = Contracts}) ->
|
get_contract(ID, #domain_Party{contracts = Contracts}) ->
|
||||||
maps:get(ID, Contracts, undefined).
|
maps:get(ID, Contracts, undefined).
|
||||||
|
|
||||||
-spec set_new_contract(contract(), timestamp(), party()) ->
|
-spec set_new_contract(contract(), timestamp(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
set_new_contract(Contract, Timestamp, Party) ->
|
set_new_contract(Contract, Timestamp, Party) ->
|
||||||
set_contract(pm_contract:update_status(Contract, Timestamp), Party).
|
set_contract(pm_contract:update_status(Contract, Timestamp), Party).
|
||||||
|
|
||||||
-spec set_contract(contract(), party()) ->
|
-spec set_contract(contract(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
set_contract(Contract = #domain_Contract{id = ID}, Party = #domain_Party{contracts = Contracts}) ->
|
set_contract(Contract = #domain_Contract{id = ID}, Party = #domain_Party{contracts = Contracts}) ->
|
||||||
Party#domain_Party{contracts = Contracts#{ID => Contract}}.
|
Party#domain_Party{contracts = Contracts#{ID => Contract}}.
|
||||||
|
|
||||||
-spec get_terms(contract() | contract_template(), timestamp(), revision()) ->
|
-spec get_terms(contract() | contract_template(), timestamp(), revision()) ->
|
||||||
dmsl_domain_thrift:'TermSet'() | no_return().
|
dmsl_domain_thrift:'TermSet'() | no_return().
|
||||||
|
|
||||||
get_terms(#domain_Contract{} = Contract, Timestamp, Revision) ->
|
get_terms(#domain_Contract{} = Contract, Timestamp, Revision) ->
|
||||||
case compute_terms(Contract, Timestamp, Revision) of
|
case compute_terms(Contract, Timestamp, Revision) of
|
||||||
#domain_TermSet{} = Terms ->
|
#domain_TermSet{} = Terms ->
|
||||||
@ -162,51 +142,39 @@ get_terms(#domain_Contract{} = Contract, Timestamp, Revision) ->
|
|||||||
get_terms(#domain_ContractTemplate{terms = TermSetHierarchyRef}, Timestamp, Revision) ->
|
get_terms(#domain_ContractTemplate{terms = TermSetHierarchyRef}, Timestamp, Revision) ->
|
||||||
get_term_set(TermSetHierarchyRef, Timestamp, Revision).
|
get_term_set(TermSetHierarchyRef, Timestamp, Revision).
|
||||||
|
|
||||||
-spec create_shop(shop_id(), shop_params(), timestamp()) ->
|
-spec create_shop(shop_id(), shop_params(), timestamp()) -> shop().
|
||||||
shop().
|
|
||||||
|
|
||||||
create_shop(ID, ShopParams, Timestamp) ->
|
create_shop(ID, ShopParams, Timestamp) ->
|
||||||
#domain_Shop{
|
#domain_Shop{
|
||||||
id = ID,
|
id = ID,
|
||||||
created_at = Timestamp,
|
created_at = Timestamp,
|
||||||
blocking = ?unblocked(Timestamp),
|
blocking = ?unblocked(Timestamp),
|
||||||
suspension = ?active(Timestamp),
|
suspension = ?active(Timestamp),
|
||||||
category = ShopParams#payproc_ShopParams.category,
|
category = ShopParams#payproc_ShopParams.category,
|
||||||
details = ShopParams#payproc_ShopParams.details,
|
details = ShopParams#payproc_ShopParams.details,
|
||||||
location = ShopParams#payproc_ShopParams.location,
|
location = ShopParams#payproc_ShopParams.location,
|
||||||
contract_id = ShopParams#payproc_ShopParams.contract_id,
|
contract_id = ShopParams#payproc_ShopParams.contract_id,
|
||||||
payout_tool_id = ShopParams#payproc_ShopParams.payout_tool_id
|
payout_tool_id = ShopParams#payproc_ShopParams.payout_tool_id
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_shop(shop_id(), party()) ->
|
-spec get_shop(shop_id(), party()) -> shop() | undefined.
|
||||||
shop() | undefined.
|
|
||||||
|
|
||||||
get_shop(ID, #domain_Party{shops = Shops}) ->
|
get_shop(ID, #domain_Party{shops = Shops}) ->
|
||||||
maps:get(ID, Shops, undefined).
|
maps:get(ID, Shops, undefined).
|
||||||
|
|
||||||
-spec set_shop(shop(), party()) ->
|
-spec set_shop(shop(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
set_shop(Shop = #domain_Shop{id = ID}, Party = #domain_Party{shops = Shops}) ->
|
set_shop(Shop = #domain_Shop{id = ID}, Party = #domain_Party{shops = Shops}) ->
|
||||||
Party#domain_Party{shops = Shops#{ID => Shop}}.
|
Party#domain_Party{shops = Shops#{ID => Shop}}.
|
||||||
|
|
||||||
-spec shop_blocking(shop_id(), blocking(), party()) ->
|
-spec shop_blocking(shop_id(), blocking(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
shop_blocking(ID, Blocking, Party) ->
|
shop_blocking(ID, Blocking, Party) ->
|
||||||
Shop = get_shop(ID, Party),
|
Shop = get_shop(ID, Party),
|
||||||
set_shop(Shop#domain_Shop{blocking = Blocking}, Party).
|
set_shop(Shop#domain_Shop{blocking = Blocking}, Party).
|
||||||
|
|
||||||
-spec shop_suspension(shop_id(), suspension(), party()) ->
|
-spec shop_suspension(shop_id(), suspension(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
shop_suspension(ID, Suspension, Party) ->
|
shop_suspension(ID, Suspension, Party) ->
|
||||||
Shop = get_shop(ID, Party),
|
Shop = get_shop(ID, Party),
|
||||||
set_shop(Shop#domain_Shop{suspension = Suspension}, Party).
|
set_shop(Shop#domain_Shop{suspension = Suspension}, Party).
|
||||||
|
|
||||||
-spec get_shop_account(shop_id(), party()) ->
|
-spec get_shop_account(shop_id(), party()) -> dmsl_domain_thrift:'ShopAccount'().
|
||||||
dmsl_domain_thrift:'ShopAccount'().
|
|
||||||
|
|
||||||
get_shop_account(ShopID, Party) ->
|
get_shop_account(ShopID, Party) ->
|
||||||
Shop = ensure_shop(get_shop(ShopID, Party)),
|
Shop = ensure_shop(get_shop(ShopID, Party)),
|
||||||
get_shop_account(Shop).
|
get_shop_account(Shop).
|
||||||
@ -218,7 +186,6 @@ get_shop_account(#domain_Shop{account = Account}) ->
|
|||||||
|
|
||||||
-spec get_account_state(dmsl_accounter_thrift:'AccountID'(), party()) ->
|
-spec get_account_state(dmsl_accounter_thrift:'AccountID'(), party()) ->
|
||||||
dmsl_payment_processing_thrift:'AccountState'().
|
dmsl_payment_processing_thrift:'AccountState'().
|
||||||
|
|
||||||
get_account_state(AccountID, Party) ->
|
get_account_state(AccountID, Party) ->
|
||||||
ok = ensure_account(AccountID, Party),
|
ok = ensure_account(AccountID, Party),
|
||||||
Account = pm_accounting:get_account(AccountID),
|
Account = pm_accounting:get_account(AccountID),
|
||||||
@ -241,28 +208,20 @@ get_account_state(AccountID, Party) ->
|
|||||||
currency = Currency
|
currency = Currency
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_wallet(wallet_id(), party()) ->
|
-spec get_wallet(wallet_id(), party()) -> wallet() | undefined.
|
||||||
wallet() | undefined.
|
|
||||||
|
|
||||||
get_wallet(ID, #domain_Party{wallets = Wallets}) ->
|
get_wallet(ID, #domain_Party{wallets = Wallets}) ->
|
||||||
maps:get(ID, Wallets, undefined).
|
maps:get(ID, Wallets, undefined).
|
||||||
|
|
||||||
-spec set_wallet(wallet(), party()) ->
|
-spec set_wallet(wallet(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
set_wallet(Wallet = #domain_Wallet{id = ID}, Party = #domain_Party{wallets = Wallets}) ->
|
set_wallet(Wallet = #domain_Wallet{id = ID}, Party = #domain_Party{wallets = Wallets}) ->
|
||||||
Party#domain_Party{wallets = Wallets#{ID => Wallet}}.
|
Party#domain_Party{wallets = Wallets#{ID => Wallet}}.
|
||||||
|
|
||||||
-spec wallet_blocking(wallet_id(), blocking(), party()) ->
|
-spec wallet_blocking(wallet_id(), blocking(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
wallet_blocking(ID, Blocking, Party) ->
|
wallet_blocking(ID, Blocking, Party) ->
|
||||||
Wallet = get_wallet(ID, Party),
|
Wallet = get_wallet(ID, Party),
|
||||||
set_wallet(Wallet#domain_Wallet{blocking = Blocking}, Party).
|
set_wallet(Wallet#domain_Wallet{blocking = Blocking}, Party).
|
||||||
|
|
||||||
-spec wallet_suspension(wallet_id(), suspension(), party()) ->
|
-spec wallet_suspension(wallet_id(), suspension(), party()) -> party().
|
||||||
party().
|
|
||||||
|
|
||||||
wallet_suspension(ID, Suspension, Party) ->
|
wallet_suspension(ID, Suspension, Party) ->
|
||||||
Wallet = get_wallet(ID, Party),
|
Wallet = get_wallet(ID, Party),
|
||||||
set_wallet(Wallet#domain_Wallet{suspension = Suspension}, Party).
|
set_wallet(Wallet#domain_Wallet{suspension = Suspension}, Party).
|
||||||
@ -277,9 +236,7 @@ ensure_shop(#domain_Shop{} = Shop) ->
|
|||||||
ensure_shop(undefined) ->
|
ensure_shop(undefined) ->
|
||||||
throw(#payproc_ShopNotFound{}).
|
throw(#payproc_ShopNotFound{}).
|
||||||
|
|
||||||
-spec reduce_terms(dmsl_domain_thrift:'TermSet'(), pm_selector:varset(), revision()) ->
|
-spec reduce_terms(dmsl_domain_thrift:'TermSet'(), pm_selector:varset(), revision()) -> dmsl_domain_thrift:'TermSet'().
|
||||||
dmsl_domain_thrift:'TermSet'().
|
|
||||||
|
|
||||||
%% TODO rework this part for more generic approach
|
%% TODO rework this part for more generic approach
|
||||||
reduce_terms(
|
reduce_terms(
|
||||||
#domain_TermSet{
|
#domain_TermSet{
|
||||||
@ -305,20 +262,20 @@ reduce_terms(
|
|||||||
|
|
||||||
reduce_payments_terms(#domain_PaymentsServiceTerms{} = Terms, VS, Rev) ->
|
reduce_payments_terms(#domain_PaymentsServiceTerms{} = Terms, VS, Rev) ->
|
||||||
#domain_PaymentsServiceTerms{
|
#domain_PaymentsServiceTerms{
|
||||||
currencies = reduce_if_defined(Terms#domain_PaymentsServiceTerms.currencies, VS, Rev),
|
currencies = reduce_if_defined(Terms#domain_PaymentsServiceTerms.currencies, VS, Rev),
|
||||||
categories = reduce_if_defined(Terms#domain_PaymentsServiceTerms.categories, VS, Rev),
|
categories = reduce_if_defined(Terms#domain_PaymentsServiceTerms.categories, VS, Rev),
|
||||||
payment_methods = reduce_if_defined(Terms#domain_PaymentsServiceTerms.payment_methods, 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),
|
cash_limit = reduce_if_defined(Terms#domain_PaymentsServiceTerms.cash_limit, VS, Rev),
|
||||||
fees = reduce_if_defined(Terms#domain_PaymentsServiceTerms.fees, VS, Rev),
|
fees = reduce_if_defined(Terms#domain_PaymentsServiceTerms.fees, VS, Rev),
|
||||||
holds = pm_maybe:apply(
|
holds = pm_maybe:apply(
|
||||||
fun(X) -> reduce_holds_terms(X, VS, Rev) end,
|
fun(X) -> reduce_holds_terms(X, VS, Rev) end,
|
||||||
Terms#domain_PaymentsServiceTerms.holds
|
Terms#domain_PaymentsServiceTerms.holds
|
||||||
),
|
),
|
||||||
refunds = pm_maybe:apply(
|
refunds = pm_maybe:apply(
|
||||||
fun(X) -> reduce_refunds_terms(X, VS, Rev) end,
|
fun(X) -> reduce_refunds_terms(X, VS, Rev) end,
|
||||||
Terms#domain_PaymentsServiceTerms.refunds
|
Terms#domain_PaymentsServiceTerms.refunds
|
||||||
),
|
),
|
||||||
chargebacks = pm_maybe:apply(
|
chargebacks = pm_maybe:apply(
|
||||||
fun(X) -> reduce_chargeback_terms(X, VS, Rev) end,
|
fun(X) -> reduce_chargeback_terms(X, VS, Rev) end,
|
||||||
Terms#domain_PaymentsServiceTerms.chargebacks
|
Terms#domain_PaymentsServiceTerms.chargebacks
|
||||||
)
|
)
|
||||||
@ -331,17 +288,17 @@ reduce_recurrent_paytools_terms(#domain_RecurrentPaytoolsServiceTerms{} = Terms,
|
|||||||
|
|
||||||
reduce_holds_terms(#domain_PaymentHoldsServiceTerms{} = Terms, VS, Rev) ->
|
reduce_holds_terms(#domain_PaymentHoldsServiceTerms{} = Terms, VS, Rev) ->
|
||||||
#domain_PaymentHoldsServiceTerms{
|
#domain_PaymentHoldsServiceTerms{
|
||||||
payment_methods = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.payment_methods, VS, Rev),
|
payment_methods = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.payment_methods, VS, Rev),
|
||||||
lifetime = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.lifetime, VS, Rev),
|
lifetime = reduce_if_defined(Terms#domain_PaymentHoldsServiceTerms.lifetime, VS, Rev),
|
||||||
partial_captures = Terms#domain_PaymentHoldsServiceTerms.partial_captures
|
partial_captures = Terms#domain_PaymentHoldsServiceTerms.partial_captures
|
||||||
}.
|
}.
|
||||||
|
|
||||||
reduce_refunds_terms(#domain_PaymentRefundsServiceTerms{} = Terms, VS, Rev) ->
|
reduce_refunds_terms(#domain_PaymentRefundsServiceTerms{} = Terms, VS, Rev) ->
|
||||||
#domain_PaymentRefundsServiceTerms{
|
#domain_PaymentRefundsServiceTerms{
|
||||||
payment_methods = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.payment_methods, VS, Rev),
|
payment_methods = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.payment_methods, VS, Rev),
|
||||||
fees = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.fees, VS, Rev),
|
fees = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.fees, VS, Rev),
|
||||||
eligibility_time = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.eligibility_time, VS, Rev),
|
eligibility_time = reduce_if_defined(Terms#domain_PaymentRefundsServiceTerms.eligibility_time, VS, Rev),
|
||||||
partial_refunds = pm_maybe:apply(
|
partial_refunds = pm_maybe:apply(
|
||||||
fun(X) -> reduce_partial_refunds_terms(X, VS, Rev) end,
|
fun(X) -> reduce_partial_refunds_terms(X, VS, Rev) end,
|
||||||
Terms#domain_PaymentRefundsServiceTerms.partial_refunds
|
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) ->
|
reduce_chargeback_terms(#domain_PaymentChargebackServiceTerms{} = Terms, VS, Rev) ->
|
||||||
#domain_PaymentChargebackServiceTerms{
|
#domain_PaymentChargebackServiceTerms{
|
||||||
allow = pm_maybe:apply(
|
allow = pm_maybe:apply(
|
||||||
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
|
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
|
||||||
Terms#domain_PaymentChargebackServiceTerms.allow),
|
Terms#domain_PaymentChargebackServiceTerms.allow
|
||||||
fees = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.fees, VS, Rev),
|
),
|
||||||
|
fees = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.fees, VS, Rev),
|
||||||
eligibility_time = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.eligibility_time, VS, Rev)
|
eligibility_time = reduce_if_defined(Terms#domain_PaymentChargebackServiceTerms.eligibility_time, VS, Rev)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
reduce_payout_terms(#domain_PayoutsServiceTerms{} = Terms, VS, Rev) ->
|
reduce_payout_terms(#domain_PayoutsServiceTerms{} = Terms, VS, Rev) ->
|
||||||
#domain_PayoutsServiceTerms{
|
#domain_PayoutsServiceTerms{
|
||||||
payout_schedules = reduce_if_defined(Terms#domain_PayoutsServiceTerms.payout_schedules, VS, Rev),
|
payout_schedules = reduce_if_defined(Terms#domain_PayoutsServiceTerms.payout_schedules, VS, Rev),
|
||||||
payout_methods = reduce_if_defined(Terms#domain_PayoutsServiceTerms.payout_methods, 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),
|
cash_limit = reduce_if_defined(Terms#domain_PayoutsServiceTerms.cash_limit, VS, Rev),
|
||||||
fees = reduce_if_defined(Terms#domain_PayoutsServiceTerms.fees, VS, Rev)
|
fees = reduce_if_defined(Terms#domain_PayoutsServiceTerms.fees, VS, Rev)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
reduce_reports_terms(#domain_ReportsServiceTerms{acts = Acts}, 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{
|
#domain_P2PServiceTerms{
|
||||||
allow = pm_maybe:apply(
|
allow = pm_maybe:apply(
|
||||||
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
|
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),
|
currencies = reduce_if_defined(Terms#domain_P2PServiceTerms.currencies, VS, Rev),
|
||||||
cash_limit = reduce_if_defined(Terms#domain_P2PServiceTerms.cash_limit, 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),
|
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{
|
#domain_P2PTemplateServiceTerms{
|
||||||
allow = pm_maybe:apply(
|
allow = pm_maybe:apply(
|
||||||
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
|
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) ->
|
reduce_w2w_terms(#domain_W2WServiceTerms{} = Terms, VS, Rev) ->
|
||||||
#domain_W2WServiceTerms{
|
#domain_W2WServiceTerms{
|
||||||
allow = pm_maybe:apply(
|
allow = pm_maybe:apply(
|
||||||
fun(X) -> pm_selector:reduce_predicate(X, VS, Rev) end,
|
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),
|
currencies = reduce_if_defined(Terms#domain_W2WServiceTerms.currencies, VS, Rev),
|
||||||
cash_limit = reduce_if_defined(Terms#domain_W2WServiceTerms.cash_limit, 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),
|
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).
|
pm_datetime:between(Timestamp, pm_utils:select_defined(ValidSince, CreatedAt), ValidUntil).
|
||||||
|
|
||||||
|
|
||||||
get_term_set(TermsRef, Timestamp, Revision) ->
|
get_term_set(TermsRef, Timestamp, Revision) ->
|
||||||
#domain_TermSetHierarchy{
|
#domain_TermSetHierarchy{
|
||||||
parent_terms = ParentRef,
|
parent_terms = ParentRef,
|
||||||
@ -482,7 +442,7 @@ get_active_term_set(TimedTermSets, Timestamp) ->
|
|||||||
TimedTermSets
|
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).
|
lists:foldl(fun merge_term_sets/2, undefined, TermSets).
|
||||||
|
|
||||||
merge_term_sets(
|
merge_term_sets(
|
||||||
@ -534,14 +494,14 @@ merge_payments_terms(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PaymentsServiceTerms{
|
#domain_PaymentsServiceTerms{
|
||||||
currencies = pm_utils:select_defined(Curr1, Curr0),
|
currencies = pm_utils:select_defined(Curr1, Curr0),
|
||||||
categories = pm_utils:select_defined(Cat1, Cat0),
|
categories = pm_utils:select_defined(Cat1, Cat0),
|
||||||
payment_methods = pm_utils:select_defined(Pm1, Pm0),
|
payment_methods = pm_utils:select_defined(Pm1, Pm0),
|
||||||
cash_limit = pm_utils:select_defined(Al1, Al0),
|
cash_limit = pm_utils:select_defined(Al1, Al0),
|
||||||
fees = pm_utils:select_defined(Fee1, Fee0),
|
fees = pm_utils:select_defined(Fee1, Fee0),
|
||||||
holds = merge_holds_terms(Hl0, Hl1),
|
holds = merge_holds_terms(Hl0, Hl1),
|
||||||
refunds = merge_refunds_terms(Rf0, Rf1),
|
refunds = merge_refunds_terms(Rf0, Rf1),
|
||||||
chargebacks = merge_chargeback_terms(CB0, CB1)
|
chargebacks = merge_chargeback_terms(CB0, CB1)
|
||||||
};
|
};
|
||||||
merge_payments_terms(Terms0, Terms1) ->
|
merge_payments_terms(Terms0, Terms1) ->
|
||||||
pm_utils:select_defined(Terms1, Terms0).
|
pm_utils:select_defined(Terms1, Terms0).
|
||||||
@ -567,8 +527,8 @@ merge_holds_terms(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PaymentHoldsServiceTerms{
|
#domain_PaymentHoldsServiceTerms{
|
||||||
payment_methods = pm_utils:select_defined(Pm1, Pm0),
|
payment_methods = pm_utils:select_defined(Pm1, Pm0),
|
||||||
lifetime = pm_utils:select_defined(Lft1, Lft0),
|
lifetime = pm_utils:select_defined(Lft1, Lft0),
|
||||||
partial_captures = pm_utils:select_defined(Ptcp1, Ptcp0)
|
partial_captures = pm_utils:select_defined(Ptcp1, Ptcp0)
|
||||||
};
|
};
|
||||||
merge_holds_terms(Terms0, Terms1) ->
|
merge_holds_terms(Terms0, Terms1) ->
|
||||||
@ -589,24 +549,24 @@ merge_refunds_terms(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PaymentRefundsServiceTerms{
|
#domain_PaymentRefundsServiceTerms{
|
||||||
payment_methods = pm_utils:select_defined(Pm1, Pm0),
|
payment_methods = pm_utils:select_defined(Pm1, Pm0),
|
||||||
fees = pm_utils:select_defined(Fee1, Fee0),
|
fees = pm_utils:select_defined(Fee1, Fee0),
|
||||||
eligibility_time = pm_utils:select_defined(ElTime1, ElTime0),
|
eligibility_time = pm_utils:select_defined(ElTime1, ElTime0),
|
||||||
partial_refunds = merge_partial_refunds_terms(PartRef0, PartRef1)
|
partial_refunds = merge_partial_refunds_terms(PartRef0, PartRef1)
|
||||||
};
|
};
|
||||||
merge_refunds_terms(Terms0, Terms1) ->
|
merge_refunds_terms(Terms0, Terms1) ->
|
||||||
pm_utils:select_defined(Terms1, Terms0).
|
pm_utils:select_defined(Terms1, Terms0).
|
||||||
|
|
||||||
merge_partial_refunds_terms(
|
merge_partial_refunds_terms(
|
||||||
#domain_PartialRefundsServiceTerms{
|
#domain_PartialRefundsServiceTerms{
|
||||||
cash_limit = Cash0
|
cash_limit = Cash0
|
||||||
},
|
},
|
||||||
#domain_PartialRefundsServiceTerms{
|
#domain_PartialRefundsServiceTerms{
|
||||||
cash_limit = Cash1
|
cash_limit = Cash1
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PartialRefundsServiceTerms{
|
#domain_PartialRefundsServiceTerms{
|
||||||
cash_limit = pm_utils:select_defined(Cash1, Cash0)
|
cash_limit = pm_utils:select_defined(Cash1, Cash0)
|
||||||
};
|
};
|
||||||
merge_partial_refunds_terms(Terms0, Terms1) ->
|
merge_partial_refunds_terms(Terms0, Terms1) ->
|
||||||
pm_utils:select_defined(Terms1, Terms0).
|
pm_utils:select_defined(Terms1, Terms0).
|
||||||
@ -624,9 +584,9 @@ merge_chargeback_terms(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PaymentChargebackServiceTerms{
|
#domain_PaymentChargebackServiceTerms{
|
||||||
allow = hg_utils:select_defined(Allow1, Allow0),
|
allow = hg_utils:select_defined(Allow1, Allow0),
|
||||||
fees = hg_utils:select_defined(Fee1, Fee0),
|
fees = hg_utils:select_defined(Fee1, Fee0),
|
||||||
eligibility_time = hg_utils:select_defined(ElTime1, ElTime0)
|
eligibility_time = hg_utils:select_defined(ElTime1, ElTime0)
|
||||||
};
|
};
|
||||||
merge_chargeback_terms(Terms0, Terms1) ->
|
merge_chargeback_terms(Terms0, Terms1) ->
|
||||||
hg_utils:select_defined(Terms1, Terms0).
|
hg_utils:select_defined(Terms1, Terms0).
|
||||||
@ -634,22 +594,22 @@ merge_chargeback_terms(Terms0, Terms1) ->
|
|||||||
merge_payouts_terms(
|
merge_payouts_terms(
|
||||||
#domain_PayoutsServiceTerms{
|
#domain_PayoutsServiceTerms{
|
||||||
payout_schedules = Ps0,
|
payout_schedules = Ps0,
|
||||||
payout_methods = Pm0,
|
payout_methods = Pm0,
|
||||||
cash_limit = Cash0,
|
cash_limit = Cash0,
|
||||||
fees = Fee0
|
fees = Fee0
|
||||||
},
|
},
|
||||||
#domain_PayoutsServiceTerms{
|
#domain_PayoutsServiceTerms{
|
||||||
payout_schedules = Ps1,
|
payout_schedules = Ps1,
|
||||||
payout_methods = Pm1,
|
payout_methods = Pm1,
|
||||||
cash_limit = Cash1,
|
cash_limit = Cash1,
|
||||||
fees = Fee1
|
fees = Fee1
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PayoutsServiceTerms{
|
#domain_PayoutsServiceTerms{
|
||||||
payout_schedules = pm_utils:select_defined(Ps1, Ps0),
|
payout_schedules = pm_utils:select_defined(Ps1, Ps0),
|
||||||
payout_methods = pm_utils:select_defined(Pm1, Pm0),
|
payout_methods = pm_utils:select_defined(Pm1, Pm0),
|
||||||
cash_limit = pm_utils:select_defined(Cash1, Cash0),
|
cash_limit = pm_utils:select_defined(Cash1, Cash0),
|
||||||
fees = pm_utils:select_defined(Fee1, Fee0)
|
fees = pm_utils:select_defined(Fee1, Fee0)
|
||||||
};
|
};
|
||||||
merge_payouts_terms(Terms0, Terms1) ->
|
merge_payouts_terms(Terms0, Terms1) ->
|
||||||
pm_utils:select_defined(Terms1, Terms0).
|
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
|
%% 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().
|
-spec assert_party_objects_valid(timestamp(), revision(), party()) -> ok | no_return().
|
||||||
|
|
||||||
assert_party_objects_valid(Timestamp, Revision, Party) ->
|
assert_party_objects_valid(Timestamp, Revision, Party) ->
|
||||||
_ = assert_contracts_valid(Timestamp, Revision, Party),
|
_ = assert_contracts_valid(Timestamp, Revision, Party),
|
||||||
_ = assert_shops_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;
|
ok;
|
||||||
#domain_PayoutTool{} ->
|
#domain_PayoutTool{} ->
|
||||||
% currency missmatch
|
% currency missmatch
|
||||||
pm_claim:raise_invalid_changeset(?invalid_shop(
|
pm_claim:raise_invalid_changeset(
|
||||||
ID,
|
?invalid_shop(
|
||||||
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
|
ID,
|
||||||
));
|
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
|
||||||
|
)
|
||||||
|
);
|
||||||
undefined ->
|
undefined ->
|
||||||
pm_claim:raise_invalid_changeset(?invalid_shop(
|
pm_claim:raise_invalid_changeset(
|
||||||
ID,
|
?invalid_shop(
|
||||||
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
|
ID,
|
||||||
))
|
{payout_tool_invalid, #payproc_ShopPayoutToolInvalid{payout_tool_id = PayoutToolID}}
|
||||||
|
)
|
||||||
|
)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
assert_wallet_valid(#domain_Wallet{contract = ContractID} = Wallet, Timestamp, Revision, Party) ->
|
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) ->
|
assert_currency_valid(Prefix, ContractID, CurrencyRef, Selector, Terms, Revision) ->
|
||||||
Currencies = pm_selector:reduce_to_value(Selector, #{}, 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(
|
assert_category_valid(
|
||||||
Prefix,
|
Prefix,
|
||||||
@ -1005,20 +969,19 @@ assert_category_valid(
|
|||||||
Revision
|
Revision
|
||||||
) ->
|
) ->
|
||||||
Categories = pm_selector:reduce_to_value(CategorySelector, #{}, Revision),
|
Categories = pm_selector:reduce_to_value(CategorySelector, #{}, Revision),
|
||||||
_ = ordsets:is_element(CategoryRef, Categories) orelse
|
_ =
|
||||||
raise_contract_terms_violated(
|
ordsets:is_element(CategoryRef, Categories) orelse
|
||||||
Prefix,
|
raise_contract_terms_violated(
|
||||||
ContractID,
|
Prefix,
|
||||||
#domain_TermSet{payments = #domain_PaymentsServiceTerms{categories = CategorySelector}}
|
ContractID,
|
||||||
).
|
#domain_TermSet{payments = #domain_PaymentsServiceTerms{categories = CategorySelector}}
|
||||||
|
).
|
||||||
|
|
||||||
-spec raise_contract_terms_violated(
|
-spec raise_contract_terms_violated(
|
||||||
{shop, shop_id()} | {wallet, wallet_id()},
|
{shop, shop_id()} | {wallet, wallet_id()},
|
||||||
contract_id(),
|
contract_id(),
|
||||||
dmsl_domain_thrift:'TermSet'()
|
dmsl_domain_thrift:'TermSet'()
|
||||||
) ->
|
) -> no_return().
|
||||||
no_return().
|
|
||||||
|
|
||||||
raise_contract_terms_violated(Prefix, ContractID, Terms) ->
|
raise_contract_terms_violated(Prefix, ContractID, Terms) ->
|
||||||
Payload = {
|
Payload = {
|
||||||
contract_terms_violated,
|
contract_terms_violated,
|
||||||
@ -1031,7 +994,6 @@ raise_contract_terms_violated(Prefix, ContractID, Terms) ->
|
|||||||
|
|
||||||
%% ugly spec, just to cool down dialyzer
|
%% ugly spec, just to cool down dialyzer
|
||||||
-spec raise_contract_terms_violated(term(), term()) -> no_return().
|
-spec raise_contract_terms_violated(term(), term()) -> no_return().
|
||||||
|
|
||||||
raise_contract_terms_violated({shop, ID}, Payload) ->
|
raise_contract_terms_violated({shop, ID}, Payload) ->
|
||||||
pm_claim:raise_invalid_changeset(?invalid_shop(ID, Payload));
|
pm_claim:raise_invalid_changeset(?invalid_shop(ID, Payload));
|
||||||
raise_contract_terms_violated({wallet, ID}, Payload) ->
|
raise_contract_terms_violated({wallet, ID}, Payload) ->
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
-type party_contractor() :: dmsl_domain_thrift:'PartyContractor'().
|
-type party_contractor() :: dmsl_domain_thrift:'PartyContractor'().
|
||||||
|
|
||||||
-spec create(id(), contractor()) -> party_contractor().
|
-spec create(id(), contractor()) -> party_contractor().
|
||||||
|
|
||||||
create(ID, Contractor) ->
|
create(ID, Contractor) ->
|
||||||
#domain_PartyContractor{
|
#domain_PartyContractor{
|
||||||
id = ID,
|
id = ID,
|
||||||
|
@ -10,57 +10,47 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
|
-spec handle_function(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
term()| no_return().
|
|
||||||
|
|
||||||
handle_function(Func, Args, Opts) ->
|
handle_function(Func, Args, Opts) ->
|
||||||
scoper:scope(partymgmt,
|
scoper:scope(
|
||||||
|
partymgmt,
|
||||||
fun() -> handle_function_(Func, Args, Opts) end
|
fun() -> handle_function_(Func, Args, Opts) end
|
||||||
).
|
).
|
||||||
|
|
||||||
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) ->
|
-spec handle_function_(woody:func(), woody:args(), pm_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
term()| no_return().
|
|
||||||
|
|
||||||
%% Party
|
%% Party
|
||||||
|
|
||||||
handle_function_('Create', {UserInfo, PartyID, PartyParams}, _Opts) ->
|
handle_function_('Create', {UserInfo, PartyID, PartyParams}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:start(PartyID, PartyParams);
|
pm_party_machine:start(PartyID, PartyParams);
|
||||||
|
|
||||||
handle_function_('Checkout', {UserInfo, PartyID, RevisionParam}, _Opts) ->
|
handle_function_('Checkout', {UserInfo, PartyID, RevisionParam}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
checkout_party(PartyID, RevisionParam, #payproc_InvalidPartyRevision{});
|
checkout_party(PartyID, RevisionParam, #payproc_InvalidPartyRevision{});
|
||||||
|
|
||||||
handle_function_('Get', {UserInfo, PartyID}, _Opts) ->
|
handle_function_('Get', {UserInfo, PartyID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_party(PartyID);
|
pm_party_machine:get_party(PartyID);
|
||||||
|
|
||||||
handle_function_('GetRevision', {UserInfo, PartyID}, _Opts) ->
|
handle_function_('GetRevision', {UserInfo, PartyID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_last_revision(PartyID);
|
pm_party_machine:get_last_revision(PartyID);
|
||||||
|
|
||||||
handle_function_('GetStatus', {UserInfo, PartyID}, _Opts) ->
|
handle_function_('GetStatus', {UserInfo, PartyID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_status(PartyID);
|
pm_party_machine:get_status(PartyID);
|
||||||
|
|
||||||
handle_function_(Fun, Args, _Opts) when
|
handle_function_(Fun, Args, _Opts) when
|
||||||
Fun =:= 'Block' orelse
|
Fun =:= 'Block' orelse
|
||||||
Fun =:= 'Unblock' orelse
|
Fun =:= 'Unblock' orelse
|
||||||
Fun =:= 'Suspend' orelse
|
Fun =:= 'Suspend' orelse
|
||||||
Fun =:= 'Activate'
|
Fun =:= 'Activate'
|
||||||
->
|
->
|
||||||
UserInfo = erlang:element(1, Args),
|
UserInfo = erlang:element(1, Args),
|
||||||
PartyID = erlang:element(2, Args),
|
PartyID = erlang:element(2, Args),
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
call(PartyID, Fun, Args);
|
call(PartyID, Fun, Args);
|
||||||
|
|
||||||
%% Contract
|
%% Contract
|
||||||
|
|
||||||
handle_function_('GetContract', {UserInfo, PartyID, ContractID}, _Opts) ->
|
handle_function_('GetContract', {UserInfo, PartyID, ContractID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
Party = pm_party_machine:get_party(PartyID),
|
Party = pm_party_machine:get_party(PartyID),
|
||||||
ensure_contract(pm_party:get_contract(ContractID, Party));
|
ensure_contract(pm_party:get_contract(ContractID, Party));
|
||||||
|
|
||||||
handle_function_('ComputeContractTerms', Args, _Opts) ->
|
handle_function_('ComputeContractTerms', Args, _Opts) ->
|
||||||
{UserInfo, PartyID, ContractID, Timestamp, PartyRevisionParams, DomainRevision, Varset} = Args,
|
{UserInfo, PartyID, ContractID, Timestamp, PartyRevisionParams, DomainRevision, Varset} = Args,
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
@ -73,14 +63,12 @@ handle_function_('ComputeContractTerms', Args, _Opts) ->
|
|||||||
VS1 = prepare_varset(PartyID, Varset, VS0),
|
VS1 = prepare_varset(PartyID, Varset, VS0),
|
||||||
Terms = pm_party:get_terms(Contract, Timestamp, DomainRevision),
|
Terms = pm_party:get_terms(Contract, Timestamp, DomainRevision),
|
||||||
pm_party:reduce_terms(Terms, VS1, DomainRevision);
|
pm_party:reduce_terms(Terms, VS1, DomainRevision);
|
||||||
|
|
||||||
%% Shop
|
%% Shop
|
||||||
|
|
||||||
handle_function_('GetShop', {UserInfo, PartyID, ID}, _Opts) ->
|
handle_function_('GetShop', {UserInfo, PartyID, ID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
Party = pm_party_machine:get_party(PartyID),
|
Party = pm_party_machine:get_party(PartyID),
|
||||||
ensure_shop(pm_party:get_shop(ID, Party));
|
ensure_shop(pm_party:get_shop(ID, Party));
|
||||||
|
|
||||||
handle_function_('ComputeShopTerms', {UserInfo, PartyID, ShopID, Timestamp, PartyRevision}, _Opts) ->
|
handle_function_('ComputeShopTerms', {UserInfo, PartyID, ShopID, Timestamp, PartyRevision}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
Party = checkout_party(PartyID, pm_maybe:get_defined(PartyRevision, {timestamp, Timestamp})),
|
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(),
|
Revision = pm_domain:head(),
|
||||||
VS = #{
|
VS = #{
|
||||||
party_id => PartyID,
|
party_id => PartyID,
|
||||||
shop_id => ShopID,
|
shop_id => ShopID,
|
||||||
category => Shop#domain_Shop.category,
|
category => Shop#domain_Shop.category,
|
||||||
currency => (Shop#domain_Shop.account)#domain_ShopAccount.currency,
|
currency => (Shop#domain_Shop.account)#domain_ShopAccount.currency,
|
||||||
identification_level => get_identification_level(Contract, Party)
|
identification_level => get_identification_level(Contract, Party)
|
||||||
},
|
},
|
||||||
pm_party:reduce_terms(pm_party:get_terms(Contract, Timestamp, Revision), VS, Revision);
|
pm_party:reduce_terms(pm_party:get_terms(Contract, Timestamp, Revision), VS, Revision);
|
||||||
|
|
||||||
handle_function_(Fun, Args, _Opts) when
|
handle_function_(Fun, Args, _Opts) when
|
||||||
Fun =:= 'BlockShop' orelse
|
Fun =:= 'BlockShop' orelse
|
||||||
Fun =:= 'UnblockShop' orelse
|
Fun =:= 'UnblockShop' orelse
|
||||||
Fun =:= 'SuspendShop' orelse
|
Fun =:= 'SuspendShop' orelse
|
||||||
Fun =:= 'ActivateShop'
|
Fun =:= 'ActivateShop'
|
||||||
->
|
->
|
||||||
UserInfo = erlang:element(1, Args),
|
UserInfo = erlang:element(1, Args),
|
||||||
PartyID = erlang:element(2, Args),
|
PartyID = erlang:element(2, Args),
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
call(PartyID, Fun, Args);
|
call(PartyID, Fun, Args);
|
||||||
|
|
||||||
%% Wallet
|
%% Wallet
|
||||||
|
|
||||||
handle_function_('ComputeWalletTermsNew', {UserInfo, PartyID, ContractID, Timestamp, Varset}, _Opts) ->
|
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),
|
VS1 = prepare_varset(PartyID, Varset, VS0),
|
||||||
pm_party:reduce_terms(pm_party:get_terms(Contract, Timestamp, Revision), VS1, Revision);
|
pm_party:reduce_terms(pm_party:get_terms(Contract, Timestamp, Revision), VS1, Revision);
|
||||||
|
|
||||||
%% Claim
|
%% Claim
|
||||||
|
|
||||||
handle_function_('GetClaim', {UserInfo, PartyID, ID}, _Opts) ->
|
handle_function_('GetClaim', {UserInfo, PartyID, ID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_claim(ID, PartyID);
|
pm_party_machine:get_claim(ID, PartyID);
|
||||||
|
|
||||||
handle_function_('GetClaims', {UserInfo, PartyID}, _Opts) ->
|
handle_function_('GetClaims', {UserInfo, PartyID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_claims(PartyID);
|
pm_party_machine:get_claims(PartyID);
|
||||||
|
|
||||||
handle_function_(Fun, Args, _Opts) when
|
handle_function_(Fun, Args, _Opts) when
|
||||||
Fun =:= 'CreateClaim' orelse
|
Fun =:= 'CreateClaim' orelse
|
||||||
Fun =:= 'AcceptClaim' orelse
|
Fun =:= 'AcceptClaim' orelse
|
||||||
Fun =:= 'UpdateClaim' orelse
|
Fun =:= 'UpdateClaim' orelse
|
||||||
Fun =:= 'DenyClaim' orelse
|
Fun =:= 'DenyClaim' orelse
|
||||||
Fun =:= 'RevokeClaim'
|
Fun =:= 'RevokeClaim'
|
||||||
->
|
->
|
||||||
UserInfo = erlang:element(1, Args),
|
UserInfo = erlang:element(1, Args),
|
||||||
PartyID = erlang:element(2, Args),
|
PartyID = erlang:element(2, Args),
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
call(PartyID, Fun, Args);
|
call(PartyID, Fun, Args);
|
||||||
|
|
||||||
%% Event
|
%% Event
|
||||||
|
|
||||||
handle_function_('GetEvents', {UserInfo, PartyID, Range}, _Opts) ->
|
handle_function_('GetEvents', {UserInfo, PartyID, Range}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
#payproc_EventRange{'after' = AfterID, limit = Limit} = Range,
|
#payproc_EventRange{'after' = AfterID, limit = Limit} = Range,
|
||||||
pm_party_machine:get_public_history(PartyID, AfterID, Limit);
|
pm_party_machine:get_public_history(PartyID, AfterID, Limit);
|
||||||
|
|
||||||
%% ShopAccount
|
%% ShopAccount
|
||||||
|
|
||||||
handle_function_('GetAccountState', {UserInfo, PartyID, AccountID}, _Opts) ->
|
handle_function_('GetAccountState', {UserInfo, PartyID, AccountID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
Party = pm_party_machine:get_party(PartyID),
|
Party = pm_party_machine:get_party(PartyID),
|
||||||
pm_party:get_account_state(AccountID, Party);
|
pm_party:get_account_state(AccountID, Party);
|
||||||
|
|
||||||
handle_function_('GetShopAccount', {UserInfo, PartyID, ShopID}, _Opts) ->
|
handle_function_('GetShopAccount', {UserInfo, PartyID, ShopID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
Party = pm_party_machine:get_party(PartyID),
|
Party = pm_party_machine:get_party(PartyID),
|
||||||
pm_party:get_shop_account(ShopID, Party);
|
pm_party:get_shop_account(ShopID, Party);
|
||||||
|
|
||||||
%% Providers
|
%% Providers
|
||||||
|
|
||||||
handle_function_('ComputeProvider', Args, _Opts) ->
|
handle_function_('ComputeProvider', Args, _Opts) ->
|
||||||
@ -169,7 +148,6 @@ handle_function_('ComputeProvider', Args, _Opts) ->
|
|||||||
Provider = get_provider(ProviderRef, DomainRevision),
|
Provider = get_provider(ProviderRef, DomainRevision),
|
||||||
VS = prepare_varset(Varset),
|
VS = prepare_varset(Varset),
|
||||||
pm_provider:reduce_provider(Provider, VS, DomainRevision);
|
pm_provider:reduce_provider(Provider, VS, DomainRevision);
|
||||||
|
|
||||||
handle_function_('ComputeProviderTerminalTerms', Args, _Opts) ->
|
handle_function_('ComputeProviderTerminalTerms', Args, _Opts) ->
|
||||||
{UserInfo, ProviderRef, TerminalRef, DomainRevision, Varset} = Args,
|
{UserInfo, ProviderRef, TerminalRef, DomainRevision, Varset} = Args,
|
||||||
ok = assume_user_identity(UserInfo),
|
ok = assume_user_identity(UserInfo),
|
||||||
@ -177,7 +155,6 @@ handle_function_('ComputeProviderTerminalTerms', Args, _Opts) ->
|
|||||||
Terminal = get_terminal(TerminalRef, DomainRevision),
|
Terminal = get_terminal(TerminalRef, DomainRevision),
|
||||||
VS = prepare_varset(Varset),
|
VS = prepare_varset(Varset),
|
||||||
pm_provider:reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision);
|
pm_provider:reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision);
|
||||||
|
|
||||||
%% Globals
|
%% Globals
|
||||||
|
|
||||||
handle_function_('ComputeGlobals', Args, _Opts) ->
|
handle_function_('ComputeGlobals', Args, _Opts) ->
|
||||||
@ -186,7 +163,6 @@ handle_function_('ComputeGlobals', Args, _Opts) ->
|
|||||||
Globals = get_globals(GlobalsRef, DomainRevision),
|
Globals = get_globals(GlobalsRef, DomainRevision),
|
||||||
VS = prepare_varset(Varset),
|
VS = prepare_varset(Varset),
|
||||||
pm_globals:reduce_globals(Globals, VS, DomainRevision);
|
pm_globals:reduce_globals(Globals, VS, DomainRevision);
|
||||||
|
|
||||||
%% RuleSets
|
%% RuleSets
|
||||||
|
|
||||||
handle_function_('ComputePaymentRoutingRuleset', Args, _Opts) ->
|
handle_function_('ComputePaymentRoutingRuleset', Args, _Opts) ->
|
||||||
@ -195,26 +171,22 @@ handle_function_('ComputePaymentRoutingRuleset', Args, _Opts) ->
|
|||||||
RuleSet = get_payment_routing_ruleset(RuleSetRef, DomainRevision),
|
RuleSet = get_payment_routing_ruleset(RuleSetRef, DomainRevision),
|
||||||
VS = prepare_varset(Varset),
|
VS = prepare_varset(Varset),
|
||||||
pm_ruleset:reduce_payment_routing_ruleset(RuleSet, VS, DomainRevision);
|
pm_ruleset:reduce_payment_routing_ruleset(RuleSet, VS, DomainRevision);
|
||||||
|
|
||||||
%% PartyMeta
|
%% PartyMeta
|
||||||
|
|
||||||
handle_function_('GetMeta', {UserInfo, PartyID}, _Opts) ->
|
handle_function_('GetMeta', {UserInfo, PartyID}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_meta(PartyID);
|
pm_party_machine:get_meta(PartyID);
|
||||||
|
|
||||||
handle_function_('GetMetaData', {UserInfo, PartyID, NS}, _Opts) ->
|
handle_function_('GetMetaData', {UserInfo, PartyID, NS}, _Opts) ->
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
pm_party_machine:get_metadata(NS, PartyID);
|
pm_party_machine:get_metadata(NS, PartyID);
|
||||||
|
|
||||||
handle_function_(Fun, Args, _Opts) when
|
handle_function_(Fun, Args, _Opts) when
|
||||||
Fun =:= 'SetMetaData' orelse
|
Fun =:= 'SetMetaData' orelse
|
||||||
Fun =:= 'RemoveMetaData'
|
Fun =:= 'RemoveMetaData'
|
||||||
->
|
->
|
||||||
UserInfo = erlang:element(1, Args),
|
UserInfo = erlang:element(1, Args),
|
||||||
PartyID = erlang:element(2, Args),
|
PartyID = erlang:element(2, Args),
|
||||||
ok = set_meta_and_check_access(UserInfo, PartyID),
|
ok = set_meta_and_check_access(UserInfo, PartyID),
|
||||||
call(PartyID, Fun, Args);
|
call(PartyID, Fun, Args);
|
||||||
|
|
||||||
%% Payment Institutions
|
%% Payment Institutions
|
||||||
|
|
||||||
handle_function_(
|
handle_function_(
|
||||||
@ -229,7 +201,6 @@ handle_function_(
|
|||||||
ContractTemplate = get_default_contract_template(PaymentInstitution, VS, Revision),
|
ContractTemplate = get_default_contract_template(PaymentInstitution, VS, Revision),
|
||||||
Terms = pm_party:get_terms(ContractTemplate, pm_datetime:format_now(), Revision),
|
Terms = pm_party:get_terms(ContractTemplate, pm_datetime:format_now(), Revision),
|
||||||
pm_party:reduce_terms(Terms, VS, Revision);
|
pm_party:reduce_terms(Terms, VS, Revision);
|
||||||
|
|
||||||
%% Payouts adhocs
|
%% Payouts adhocs
|
||||||
|
|
||||||
handle_function_(
|
handle_function_(
|
||||||
@ -246,10 +217,10 @@ handle_function_(
|
|||||||
PayoutTool = get_payout_tool(Shop, Contract, PayoutParams),
|
PayoutTool = get_payout_tool(Shop, Contract, PayoutParams),
|
||||||
VS = #{
|
VS = #{
|
||||||
party_id => PartyID,
|
party_id => PartyID,
|
||||||
shop_id => ShopID,
|
shop_id => ShopID,
|
||||||
category => Shop#domain_Shop.category,
|
category => Shop#domain_Shop.category,
|
||||||
currency => Currency,
|
currency => Currency,
|
||||||
cost => Amount,
|
cost => Amount,
|
||||||
payout_method => pm_payout_tool:get_method(PayoutTool)
|
payout_method => pm_payout_tool:get_method(PayoutTool)
|
||||||
},
|
},
|
||||||
Revision = pm_domain:head(),
|
Revision = pm_domain:head(),
|
||||||
@ -267,9 +238,7 @@ call(PartyID, FunctionName, Args) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
get_payout_tool(_Shop, Contract, #payproc_PayoutParams{payout_tool_id = ToolID})
|
get_payout_tool(_Shop, Contract, #payproc_PayoutParams{payout_tool_id = ToolID}) when ToolID =/= undefined ->
|
||||||
when ToolID =/= undefined
|
|
||||||
->
|
|
||||||
case pm_contract:get_payout_tool(ToolID, Contract) of
|
case pm_contract:get_payout_tool(ToolID, Contract) of
|
||||||
undefined ->
|
undefined ->
|
||||||
throw(#payproc_PayoutToolNotFound{});
|
throw(#payproc_PayoutToolNotFound{});
|
||||||
@ -286,9 +255,7 @@ set_meta_and_check_access(UserInfo, PartyID) ->
|
|||||||
|
|
||||||
-spec assert_party_accessible(
|
-spec assert_party_accessible(
|
||||||
dmsl_domain_thrift:'PartyID'()
|
dmsl_domain_thrift:'PartyID'()
|
||||||
) ->
|
) -> ok | no_return().
|
||||||
ok | no_return().
|
|
||||||
|
|
||||||
assert_party_accessible(PartyID) ->
|
assert_party_accessible(PartyID) ->
|
||||||
UserIdentity = pm_woody_handler_utils:get_user_identity(),
|
UserIdentity = pm_woody_handler_utils:get_user_identity(),
|
||||||
case pm_access_control:check_user(UserIdentity, PartyID) of
|
case pm_access_control:check_user(UserIdentity, PartyID) of
|
||||||
@ -393,11 +360,11 @@ collect_payout_account_map(
|
|||||||
PaymentInstitution = get_payment_institution(PaymentInstitutionRef, Revision),
|
PaymentInstitution = get_payment_institution(PaymentInstitutionRef, Revision),
|
||||||
SystemAccount = pm_payment_institution:get_system_account(Currency, VS, Revision, PaymentInstitution),
|
SystemAccount = pm_payment_institution:get_system_account(Currency, VS, Revision, PaymentInstitution),
|
||||||
#{
|
#{
|
||||||
{merchant , settlement} => ShopAccount#domain_ShopAccount.settlement,
|
{merchant, settlement} => ShopAccount#domain_ShopAccount.settlement,
|
||||||
{merchant , guarantee } => ShopAccount#domain_ShopAccount.guarantee,
|
{merchant, guarantee} => ShopAccount#domain_ShopAccount.guarantee,
|
||||||
{merchant , payout } => ShopAccount#domain_ShopAccount.payout,
|
{merchant, payout} => ShopAccount#domain_ShopAccount.payout,
|
||||||
{system , settlement} => SystemAccount#domain_SystemAccount.settlement,
|
{system, settlement} => SystemAccount#domain_SystemAccount.settlement,
|
||||||
{system , subagent } => SystemAccount#domain_SystemAccount.subagent
|
{system, subagent} => SystemAccount#domain_SystemAccount.subagent
|
||||||
}.
|
}.
|
||||||
|
|
||||||
prepare_varset(#payproc_Varset{} = V) ->
|
prepare_varset(#payproc_Varset{} = V) ->
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,6 @@
|
|||||||
-export([unmarshal/1]).
|
-export([unmarshal/1]).
|
||||||
|
|
||||||
-spec marshal(term()) -> pm_msgpack_marshalling:msgpack_value().
|
-spec marshal(term()) -> pm_msgpack_marshalling:msgpack_value().
|
||||||
|
|
||||||
marshal(undefined) ->
|
marshal(undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
marshal(Boolean) when is_boolean(Boolean) ->
|
marshal(Boolean) when is_boolean(Boolean) ->
|
||||||
@ -31,12 +30,11 @@ marshal(V) when is_integer(V); is_float(V); is_binary(V) ->
|
|||||||
V.
|
V.
|
||||||
|
|
||||||
-spec unmarshal(pm_msgpack_marshalling:msgpack_value()) -> term().
|
-spec unmarshal(pm_msgpack_marshalling:msgpack_value()) -> term().
|
||||||
|
|
||||||
unmarshal([<<":atom:">>, Atom]) ->
|
unmarshal([<<":atom:">>, Atom]) ->
|
||||||
binary_to_existing_atom(Atom, utf8);
|
binary_to_existing_atom(Atom, utf8);
|
||||||
unmarshal([<<":tuple:">>, Tuple]) ->
|
unmarshal([<<":tuple:">>, Tuple]) ->
|
||||||
list_to_tuple(lists:map(fun unmarshal/1, Tuple));
|
list_to_tuple(lists:map(fun unmarshal/1, Tuple));
|
||||||
unmarshal([<<":list:">>, List])->
|
unmarshal([<<":list:">>, List]) ->
|
||||||
lists:map(fun unmarshal/1, List);
|
lists:map(fun unmarshal/1, List);
|
||||||
unmarshal(Map) when is_map(Map) ->
|
unmarshal(Map) when is_map(Map) ->
|
||||||
maps:fold(fun(K, V, Acc) -> maps:put(unmarshal(K), unmarshal(V), Acc) end, #{}, Map);
|
maps:fold(fun(K, V, Acc) -> maps:put(unmarshal(K), unmarshal(V), Acc) end, #{}, Map);
|
||||||
@ -44,5 +42,5 @@ unmarshal(undefined) ->
|
|||||||
undefined;
|
undefined;
|
||||||
unmarshal({bin, Binary}) when is_binary(Binary) ->
|
unmarshal({bin, Binary}) when is_binary(Binary) ->
|
||||||
{bin, 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.
|
V.
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
-export([get_system_account/4]).
|
-export([get_system_account/4]).
|
||||||
-export([get_realm/1]).
|
-export([get_realm/1]).
|
||||||
-export([is_live/1]).
|
-export([is_live/1]).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
|
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
|
||||||
-type varset() :: pm_selector:varset().
|
-type varset() :: pm_selector:varset().
|
||||||
-type revision() :: pm_domain:revision().
|
-type revision() :: pm_domain:revision().
|
||||||
-type payment_inst() :: dmsl_domain_thrift:'PaymentInstitution'().
|
-type payment_inst() :: dmsl_domain_thrift:'PaymentInstitution'().
|
||||||
-type realm() :: dmsl_domain_thrift:'PaymentInstitutionRealm'().
|
-type realm() :: dmsl_domain_thrift:'PaymentInstitutionRealm'().
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec get_system_account(currency(), varset(), revision(), payment_inst()) ->
|
-spec get_system_account(currency(), varset(), revision(), payment_inst()) ->
|
||||||
dmsl_domain_thrift:'SystemAccount'() | no_return().
|
dmsl_domain_thrift:'SystemAccount'() | no_return().
|
||||||
|
|
||||||
get_system_account(Currency, VS, Revision, #domain_PaymentInstitution{system_account_set = S}) ->
|
get_system_account(Currency, VS, Revision, #domain_PaymentInstitution{system_account_set = S}) ->
|
||||||
SystemAccountSetRef = pm_selector:reduce_to_value(S, VS, Revision),
|
SystemAccountSetRef = pm_selector:reduce_to_value(S, VS, Revision),
|
||||||
SystemAccountSet = pm_domain:get(Revision, {system_account_set, SystemAccountSetRef}),
|
SystemAccountSet = pm_domain:get(Revision, {system_account_set, SystemAccountSetRef}),
|
||||||
@ -31,11 +31,9 @@ get_system_account(Currency, VS, Revision, #domain_PaymentInstitution{system_acc
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_realm(payment_inst()) -> realm().
|
-spec get_realm(payment_inst()) -> realm().
|
||||||
|
|
||||||
get_realm(#domain_PaymentInstitution{realm = Realm}) ->
|
get_realm(#domain_PaymentInstitution{realm = Realm}) ->
|
||||||
Realm.
|
Realm.
|
||||||
|
|
||||||
-spec is_live(payment_inst()) -> boolean().
|
-spec is_live(payment_inst()) -> boolean().
|
||||||
|
|
||||||
is_live(#domain_PaymentInstitution{realm = Realm}) ->
|
is_live(#domain_PaymentInstitution{realm = Realm}) ->
|
||||||
Realm =:= live.
|
Realm =:= live.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
%%% Payment tools
|
%%% Payment tools
|
||||||
|
|
||||||
-module(pm_payment_tool).
|
-module(pm_payment_tool).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@ -15,7 +16,6 @@
|
|||||||
-type condition() :: dmsl_domain_thrift:'PaymentToolCondition'().
|
-type condition() :: dmsl_domain_thrift:'PaymentToolCondition'().
|
||||||
|
|
||||||
-spec create_from_method(method()) -> t().
|
-spec create_from_method(method()) -> t().
|
||||||
|
|
||||||
%% TODO empty strings - ugly hack for dialyzar
|
%% TODO empty strings - ugly hack for dialyzar
|
||||||
create_from_method(#domain_PaymentMethodRef{id = {empty_cvv_bank_card_deprecated, PaymentSystem}}) ->
|
create_from_method(#domain_PaymentMethodRef{id = {empty_cvv_bank_card_deprecated, PaymentSystem}}) ->
|
||||||
{bank_card, #domain_BankCard{
|
{bank_card, #domain_BankCard{
|
||||||
@ -32,11 +32,14 @@ create_from_method(#domain_PaymentMethodRef{id = {bank_card_deprecated, PaymentS
|
|||||||
bin = <<"">>,
|
bin = <<"">>,
|
||||||
last_digits = <<"">>
|
last_digits = <<"">>
|
||||||
}};
|
}};
|
||||||
create_from_method(#domain_PaymentMethodRef{id = {tokenized_bank_card_deprecated, #domain_TokenizedBankCard{
|
create_from_method(#domain_PaymentMethodRef{
|
||||||
payment_system = PaymentSystem,
|
id =
|
||||||
token_provider = TokenProvider,
|
{tokenized_bank_card_deprecated, #domain_TokenizedBankCard{
|
||||||
tokenization_method = TokenizationMethod
|
payment_system = PaymentSystem,
|
||||||
}}}) ->
|
token_provider = TokenProvider,
|
||||||
|
tokenization_method = TokenizationMethod
|
||||||
|
}}
|
||||||
|
}) ->
|
||||||
{bank_card, #domain_BankCard{
|
{bank_card, #domain_BankCard{
|
||||||
payment_system = PaymentSystem,
|
payment_system = PaymentSystem,
|
||||||
token = <<"">>,
|
token = <<"">>,
|
||||||
@ -45,12 +48,15 @@ create_from_method(#domain_PaymentMethodRef{id = {tokenized_bank_card_deprecated
|
|||||||
token_provider = TokenProvider,
|
token_provider = TokenProvider,
|
||||||
tokenization_method = TokenizationMethod
|
tokenization_method = TokenizationMethod
|
||||||
}};
|
}};
|
||||||
create_from_method(#domain_PaymentMethodRef{id = {bank_card, #domain_BankCardPaymentMethod{
|
create_from_method(#domain_PaymentMethodRef{
|
||||||
payment_system = PaymentSystem,
|
id =
|
||||||
is_cvv_empty = IsCVVEmpty,
|
{bank_card, #domain_BankCardPaymentMethod{
|
||||||
token_provider = TokenProvider,
|
payment_system = PaymentSystem,
|
||||||
tokenization_method = TokenizationMethod
|
is_cvv_empty = IsCVVEmpty,
|
||||||
}}}) ->
|
token_provider = TokenProvider,
|
||||||
|
tokenization_method = TokenizationMethod
|
||||||
|
}}
|
||||||
|
}) ->
|
||||||
{bank_card, #domain_BankCard{
|
{bank_card, #domain_BankCard{
|
||||||
payment_system = PaymentSystem,
|
payment_system = PaymentSystem,
|
||||||
token = <<"">>,
|
token = <<"">>,
|
||||||
@ -73,7 +79,6 @@ create_from_method(#domain_PaymentMethodRef{id = {crypto_currency, CC}}) ->
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-spec test_condition(condition(), t(), pm_domain:revision()) -> boolean() | undefined.
|
-spec test_condition(condition(), t(), pm_domain:revision()) -> boolean() | undefined.
|
||||||
|
|
||||||
test_condition({bank_card, C}, {bank_card, V = #domain_BankCard{}}, Rev) ->
|
test_condition({bank_card, C}, {bank_card, V = #domain_BankCard{}}, Rev) ->
|
||||||
test_bank_card_condition(C, V, Rev);
|
test_bank_card_condition(C, V, Rev);
|
||||||
test_condition({payment_terminal, C}, {payment_terminal, V = #domain_PaymentTerminal{}}, Rev) ->
|
test_condition({payment_terminal, C}, {payment_terminal, V = #domain_PaymentTerminal{}}, Rev) ->
|
||||||
@ -101,7 +106,6 @@ test_bank_card_condition_def(
|
|||||||
true;
|
true;
|
||||||
test_bank_card_condition_def({payment_system_is, _Ps}, #domain_BankCard{}, _Rev) ->
|
test_bank_card_condition_def({payment_system_is, _Ps}, #domain_BankCard{}, _Rev) ->
|
||||||
false;
|
false;
|
||||||
|
|
||||||
test_bank_card_condition_def({payment_system, PaymentSystem}, V, Rev) ->
|
test_bank_card_condition_def({payment_system, PaymentSystem}, V, Rev) ->
|
||||||
test_payment_system_condition(PaymentSystem, V, Rev);
|
test_payment_system_condition(PaymentSystem, V, Rev);
|
||||||
test_bank_card_condition_def({issuer_country_is, IssuerCountry}, 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);
|
test_bank_card_patterns(Patterns, BankName);
|
||||||
% TODO т.к. BinBase не обладает полным объемом данных, при их отсутствии мы возвращаемся к проверкам по бинам.
|
% TODO т.к. BinBase не обладает полным объемом данных, при их отсутствии мы возвращаемся к проверкам по бинам.
|
||||||
% B будущем стоит избавиться от этого.
|
% B будущем стоит избавиться от этого.
|
||||||
{_, _} -> test_bank_card_bins(BIN, BINs)
|
{_, _} ->
|
||||||
|
test_bank_card_bins(BIN, BINs)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
test_bank_card_category_condition(CategoryRef, #domain_BankCard{category = Category}, Rev) ->
|
test_bank_card_category_condition(CategoryRef, #domain_BankCard{category = Category}, Rev) ->
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
%%% Payout tools
|
%%% Payout tools
|
||||||
|
|
||||||
-module(pm_payout_tool).
|
-module(pm_payout_tool).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@ -9,17 +10,15 @@
|
|||||||
-export([get_method/1]).
|
-export([get_method/1]).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
|
-type payout_tool() :: dmsl_domain_thrift:'PayoutTool'().
|
||||||
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
|
-type payout_tool_id() :: dmsl_domain_thrift:'PayoutToolID'().
|
||||||
-type payout_tool_params() :: dmsl_payment_processing_thrift:'PayoutToolParams'().
|
-type payout_tool_params() :: dmsl_payment_processing_thrift:'PayoutToolParams'().
|
||||||
-type method() :: dmsl_domain_thrift:'PayoutMethodRef'().
|
-type method() :: dmsl_domain_thrift:'PayoutMethodRef'().
|
||||||
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
|
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec create(payout_tool_id(), payout_tool_params(), timestamp()) ->
|
-spec create(payout_tool_id(), payout_tool_params(), timestamp()) -> payout_tool().
|
||||||
payout_tool().
|
|
||||||
|
|
||||||
create(
|
create(
|
||||||
ID,
|
ID,
|
||||||
#payproc_PayoutToolParams{
|
#payproc_PayoutToolParams{
|
||||||
@ -36,7 +35,6 @@ create(
|
|||||||
}.
|
}.
|
||||||
|
|
||||||
-spec get_method(payout_tool()) -> method().
|
-spec get_method(payout_tool()) -> method().
|
||||||
|
|
||||||
get_method(#domain_PayoutTool{payout_tool_info = {russian_bank_account, _}}) ->
|
get_method(#domain_PayoutTool{payout_tool_info = {russian_bank_account, _}}) ->
|
||||||
#domain_PayoutMethodRef{id = russian_bank_account};
|
#domain_PayoutMethodRef{id = russian_bank_account};
|
||||||
get_method(#domain_PayoutTool{payout_tool_info = {international_bank_account, _}}) ->
|
get_method(#domain_PayoutTool{payout_tool_info = {international_bank_account, _}}) ->
|
||||||
|
@ -6,23 +6,20 @@
|
|||||||
-export([reduce_provider/3]).
|
-export([reduce_provider/3]).
|
||||||
-export([reduce_provider_terminal_terms/4]).
|
-export([reduce_provider_terminal_terms/4]).
|
||||||
|
|
||||||
-type provider() :: dmsl_domain_thrift:'Provider'().
|
-type provider() :: dmsl_domain_thrift:'Provider'().
|
||||||
-type terminal() :: dmsl_domain_thrift:'Terminal'().
|
-type terminal() :: dmsl_domain_thrift:'Terminal'().
|
||||||
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
|
-type provision_terms() :: dmsl_domain_thrift:'ProvisionTermSet'().
|
||||||
-type varset() :: pm_selector:varset().
|
-type varset() :: pm_selector:varset().
|
||||||
-type domain_revision() :: pm_domain:revision().
|
-type domain_revision() :: pm_domain:revision().
|
||||||
|
|
||||||
-spec reduce_provider(provider(), varset(), domain_revision()) -> provider().
|
-spec reduce_provider(provider(), varset(), domain_revision()) -> provider().
|
||||||
|
|
||||||
reduce_provider(Provider, VS, DomainRevision) ->
|
reduce_provider(Provider, VS, DomainRevision) ->
|
||||||
Provider#domain_Provider{
|
Provider#domain_Provider{
|
||||||
terminal = pm_selector:reduce(Provider#domain_Provider.terminal, VS, DomainRevision),
|
terminal = pm_selector:reduce(Provider#domain_Provider.terminal, VS, DomainRevision),
|
||||||
terms = reduce_provision_term_set(Provider#domain_Provider.terms, VS, DomainRevision)
|
terms = reduce_provision_term_set(Provider#domain_Provider.terms, VS, DomainRevision)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec reduce_provider_terminal_terms(provider(), terminal(), varset(), domain_revision()) ->
|
-spec reduce_provider_terminal_terms(provider(), terminal(), varset(), domain_revision()) -> provision_terms().
|
||||||
provision_terms().
|
|
||||||
|
|
||||||
reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision) ->
|
reduce_provider_terminal_terms(Provider, Terminal, VS, DomainRevision) ->
|
||||||
ProviderTerms = Provider#domain_Provider.terms,
|
ProviderTerms = Provider#domain_Provider.terms,
|
||||||
TerminalTerms = Terminal#domain_Terminal.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),
|
currencies = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.currencies, VS, DomainRevision),
|
||||||
categories = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.categories, VS, DomainRevision),
|
categories = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.categories, VS, DomainRevision),
|
||||||
payment_methods = reduce_if_defined(
|
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_limit = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.cash_limit, VS, DomainRevision),
|
||||||
cash_flow = reduce_if_defined(PaymentTerms#domain_PaymentsProvisionTerms.cash_flow, 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) ->
|
reduce_payment_refund_terms(PaymentRefundTerms, VS, DomainRevision) ->
|
||||||
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms{
|
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms{
|
||||||
cash_flow = reduce_if_defined(
|
cash_flow = reduce_if_defined(
|
||||||
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms.cash_flow, VS, DomainRevision
|
PaymentRefundTerms#domain_PaymentRefundsProvisionTerms.cash_flow,
|
||||||
|
VS,
|
||||||
|
DomainRevision
|
||||||
),
|
),
|
||||||
partial_refunds = pm_maybe:apply(
|
partial_refunds = pm_maybe:apply(
|
||||||
fun(X) -> reduce_partial_refunds_terms(X, VS, DomainRevision) end,
|
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) ->
|
reduce_partial_refunds_terms(PartialRefundTerms, VS, DomainRevision) ->
|
||||||
PartialRefundTerms#domain_PartialRefundsProvisionTerms{
|
PartialRefundTerms#domain_PartialRefundsProvisionTerms{
|
||||||
cash_limit = reduce_if_defined(
|
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) ->
|
reduce_payment_chargeback_terms(PaymentChargebackTerms, VS, DomainRevision) ->
|
||||||
PaymentChargebackTerms#domain_PaymentChargebackProvisionTerms{
|
PaymentChargebackTerms#domain_PaymentChargebackProvisionTerms{
|
||||||
cash_flow = reduce_if_defined(
|
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) ->
|
reduce_recurrent_paytool_terms(RecurrentPaytoolTerms, VS, DomainRevision) ->
|
||||||
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms{
|
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms{
|
||||||
cash_value = reduce_if_defined(
|
cash_value = reduce_if_defined(
|
||||||
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.cash_value, VS, DomainRevision
|
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.cash_value,
|
||||||
|
VS,
|
||||||
|
DomainRevision
|
||||||
),
|
),
|
||||||
categories = reduce_if_defined(
|
categories = reduce_if_defined(
|
||||||
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.categories, VS, DomainRevision
|
RecurrentPaytoolTerms#domain_RecurrentPaytoolsProvisionTerms.categories,
|
||||||
|
VS,
|
||||||
|
DomainRevision
|
||||||
),
|
),
|
||||||
payment_methods = reduce_if_defined(
|
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) ->
|
reduce_wallet_provision(WalletProvisionTerms, VS, DomainRevision) ->
|
||||||
#domain_WalletProvisionTerms{
|
#domain_WalletProvisionTerms{
|
||||||
turnover_limit = reduce_if_defined(
|
turnover_limit = reduce_if_defined(
|
||||||
WalletProvisionTerms#domain_WalletProvisionTerms.turnover_limit, VS, DomainRevision
|
WalletProvisionTerms#domain_WalletProvisionTerms.turnover_limit,
|
||||||
|
VS,
|
||||||
|
DomainRevision
|
||||||
),
|
),
|
||||||
withdrawals = pm_maybe:apply(
|
withdrawals = pm_maybe:apply(
|
||||||
fun(X) -> reduce_withdrawal_terms(X, VS, DomainRevision) end,
|
fun(X) -> reduce_withdrawal_terms(X, VS, DomainRevision) end,
|
||||||
@ -159,55 +172,56 @@ reduce_wallet_provision(WalletProvisionTerms, VS, DomainRevision) ->
|
|||||||
|
|
||||||
merge_provision_term_sets(
|
merge_provision_term_sets(
|
||||||
#domain_ProvisionTermSet{
|
#domain_ProvisionTermSet{
|
||||||
payments = PPayments,
|
payments = PPayments,
|
||||||
recurrent_paytools = PRecurrents,
|
recurrent_paytools = PRecurrents,
|
||||||
wallet = PWallet
|
wallet = PWallet
|
||||||
},
|
},
|
||||||
#domain_ProvisionTermSet{
|
#domain_ProvisionTermSet{
|
||||||
payments = TPayments,
|
payments = TPayments,
|
||||||
recurrent_paytools = _TRecurrents, % TODO: Allow to define recurrent terms in terminal
|
% TODO: Allow to define recurrent terms in terminal
|
||||||
wallet = TWallet
|
recurrent_paytools = _TRecurrents,
|
||||||
|
wallet = TWallet
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_ProvisionTermSet{
|
#domain_ProvisionTermSet{
|
||||||
payments = merge_payment_terms(PPayments, TPayments),
|
payments = merge_payment_terms(PPayments, TPayments),
|
||||||
recurrent_paytools = PRecurrents,
|
recurrent_paytools = PRecurrents,
|
||||||
wallet = merge_wallet_terms(PWallet, TWallet)
|
wallet = merge_wallet_terms(PWallet, TWallet)
|
||||||
};
|
};
|
||||||
merge_provision_term_sets(ProviderTerms, TerminalTerms) ->
|
merge_provision_term_sets(ProviderTerms, TerminalTerms) ->
|
||||||
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
||||||
|
|
||||||
merge_payment_terms(
|
merge_payment_terms(
|
||||||
#domain_PaymentsProvisionTerms{
|
#domain_PaymentsProvisionTerms{
|
||||||
currencies = PCurrencies,
|
currencies = PCurrencies,
|
||||||
categories = PCategories,
|
categories = PCategories,
|
||||||
payment_methods = PPaymentMethods,
|
payment_methods = PPaymentMethods,
|
||||||
cash_limit = PCashLimit,
|
cash_limit = PCashLimit,
|
||||||
cash_flow = PCashflow,
|
cash_flow = PCashflow,
|
||||||
holds = PHolds,
|
holds = PHolds,
|
||||||
refunds = PRefunds,
|
refunds = PRefunds,
|
||||||
chargebacks = PChargebacks
|
chargebacks = PChargebacks
|
||||||
},
|
},
|
||||||
#domain_PaymentsProvisionTerms{
|
#domain_PaymentsProvisionTerms{
|
||||||
currencies = TCurrencies,
|
currencies = TCurrencies,
|
||||||
categories = TCategories,
|
categories = TCategories,
|
||||||
payment_methods = TPaymentMethods,
|
payment_methods = TPaymentMethods,
|
||||||
cash_limit = TCashLimit,
|
cash_limit = TCashLimit,
|
||||||
cash_flow = TCashflow,
|
cash_flow = TCashflow,
|
||||||
holds = THolds,
|
holds = THolds,
|
||||||
refunds = TRefunds,
|
refunds = TRefunds,
|
||||||
chargebacks = TChargebacks
|
chargebacks = TChargebacks
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_PaymentsProvisionTerms{
|
#domain_PaymentsProvisionTerms{
|
||||||
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
|
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
|
||||||
categories = pm_utils:select_defined(TCategories, PCategories),
|
categories = pm_utils:select_defined(TCategories, PCategories),
|
||||||
payment_methods = pm_utils:select_defined(TPaymentMethods, PPaymentMethods),
|
payment_methods = pm_utils:select_defined(TPaymentMethods, PPaymentMethods),
|
||||||
cash_limit = pm_utils:select_defined(TCashLimit, PCashLimit),
|
cash_limit = pm_utils:select_defined(TCashLimit, PCashLimit),
|
||||||
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
|
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
|
||||||
holds = pm_utils:select_defined(THolds, PHolds),
|
holds = pm_utils:select_defined(THolds, PHolds),
|
||||||
refunds = pm_utils:select_defined(TRefunds, PRefunds),
|
refunds = pm_utils:select_defined(TRefunds, PRefunds),
|
||||||
chargebacks = pm_utils:select_defined(TChargebacks, PChargebacks)
|
chargebacks = pm_utils:select_defined(TChargebacks, PChargebacks)
|
||||||
};
|
};
|
||||||
merge_payment_terms(ProviderTerms, TerminalTerms) ->
|
merge_payment_terms(ProviderTerms, TerminalTerms) ->
|
||||||
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
||||||
@ -215,65 +229,65 @@ merge_payment_terms(ProviderTerms, TerminalTerms) ->
|
|||||||
merge_wallet_terms(
|
merge_wallet_terms(
|
||||||
#domain_WalletProvisionTerms{
|
#domain_WalletProvisionTerms{
|
||||||
turnover_limit = PLimit,
|
turnover_limit = PLimit,
|
||||||
withdrawals = PWithdrawal,
|
withdrawals = PWithdrawal,
|
||||||
p2p = PP2P
|
p2p = PP2P
|
||||||
},
|
},
|
||||||
#domain_WalletProvisionTerms{
|
#domain_WalletProvisionTerms{
|
||||||
turnover_limit = TLimit,
|
turnover_limit = TLimit,
|
||||||
withdrawals = TWithdrawal,
|
withdrawals = TWithdrawal,
|
||||||
p2p = TP2P
|
p2p = TP2P
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_WalletProvisionTerms{
|
#domain_WalletProvisionTerms{
|
||||||
turnover_limit = pm_utils:select_defined(TLimit, PLimit),
|
turnover_limit = pm_utils:select_defined(TLimit, PLimit),
|
||||||
withdrawals = merge_withdrawal_terms(PWithdrawal, TWithdrawal),
|
withdrawals = merge_withdrawal_terms(PWithdrawal, TWithdrawal),
|
||||||
p2p = merge_p2p_terms(PP2P, TP2P)
|
p2p = merge_p2p_terms(PP2P, TP2P)
|
||||||
};
|
};
|
||||||
merge_wallet_terms(ProviderTerms, TerminalTerms) ->
|
merge_wallet_terms(ProviderTerms, TerminalTerms) ->
|
||||||
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
||||||
|
|
||||||
merge_withdrawal_terms(
|
merge_withdrawal_terms(
|
||||||
#domain_WithdrawalProvisionTerms{
|
#domain_WithdrawalProvisionTerms{
|
||||||
currencies = PCurrencies,
|
currencies = PCurrencies,
|
||||||
payout_methods = PMethods,
|
payout_methods = PMethods,
|
||||||
cash_limit = PLimit,
|
cash_limit = PLimit,
|
||||||
cash_flow = PCashflow
|
cash_flow = PCashflow
|
||||||
},
|
},
|
||||||
#domain_WithdrawalProvisionTerms{
|
#domain_WithdrawalProvisionTerms{
|
||||||
currencies = TCurrencies,
|
currencies = TCurrencies,
|
||||||
payout_methods = TMethods,
|
payout_methods = TMethods,
|
||||||
cash_limit = TLimit,
|
cash_limit = TLimit,
|
||||||
cash_flow = TCashflow
|
cash_flow = TCashflow
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_WithdrawalProvisionTerms{
|
#domain_WithdrawalProvisionTerms{
|
||||||
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
|
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
|
||||||
payout_methods = pm_utils:select_defined(TMethods, PMethods),
|
payout_methods = pm_utils:select_defined(TMethods, PMethods),
|
||||||
cash_limit = pm_utils:select_defined(TLimit, PLimit),
|
cash_limit = pm_utils:select_defined(TLimit, PLimit),
|
||||||
cash_flow = pm_utils:select_defined(TCashflow, PCashflow)
|
cash_flow = pm_utils:select_defined(TCashflow, PCashflow)
|
||||||
};
|
};
|
||||||
merge_withdrawal_terms(ProviderTerms, TerminalTerms) ->
|
merge_withdrawal_terms(ProviderTerms, TerminalTerms) ->
|
||||||
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
||||||
|
|
||||||
merge_p2p_terms(
|
merge_p2p_terms(
|
||||||
#domain_P2PProvisionTerms{
|
#domain_P2PProvisionTerms{
|
||||||
currencies = PCurrencies,
|
currencies = PCurrencies,
|
||||||
cash_limit = PLimit,
|
cash_limit = PLimit,
|
||||||
cash_flow = PCashflow,
|
cash_flow = PCashflow,
|
||||||
fees = PFees
|
fees = PFees
|
||||||
},
|
},
|
||||||
#domain_P2PProvisionTerms{
|
#domain_P2PProvisionTerms{
|
||||||
currencies = TCurrencies,
|
currencies = TCurrencies,
|
||||||
cash_limit = TLimit,
|
cash_limit = TLimit,
|
||||||
cash_flow = TCashflow,
|
cash_flow = TCashflow,
|
||||||
fees = TFees
|
fees = TFees
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
#domain_P2PProvisionTerms{
|
#domain_P2PProvisionTerms{
|
||||||
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
|
currencies = pm_utils:select_defined(TCurrencies, PCurrencies),
|
||||||
cash_limit = pm_utils:select_defined(TLimit, PLimit),
|
cash_limit = pm_utils:select_defined(TLimit, PLimit),
|
||||||
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
|
cash_flow = pm_utils:select_defined(TCashflow, PCashflow),
|
||||||
fees = pm_utils:select_defined(TFees, PFees)
|
fees = pm_utils:select_defined(TFees, PFees)
|
||||||
};
|
};
|
||||||
merge_p2p_terms(ProviderTerms, TerminalTerms) ->
|
merge_p2p_terms(ProviderTerms, TerminalTerms) ->
|
||||||
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
pm_utils:select_defined(TerminalTerms, ProviderTerms).
|
||||||
|
@ -9,12 +9,11 @@
|
|||||||
-define(const(Bool), {constant, Bool}).
|
-define(const(Bool), {constant, Bool}).
|
||||||
|
|
||||||
-type payment_routing_ruleset() :: dmsl_domain_thrift:'PaymentRoutingRuleset'().
|
-type payment_routing_ruleset() :: dmsl_domain_thrift:'PaymentRoutingRuleset'().
|
||||||
-type varset() :: pm_selector:varset().
|
-type varset() :: pm_selector:varset().
|
||||||
-type domain_revision() :: pm_domain:revision().
|
-type domain_revision() :: pm_domain:revision().
|
||||||
|
|
||||||
-spec reduce_payment_routing_ruleset(payment_routing_ruleset(), varset(), domain_revision()) ->
|
-spec reduce_payment_routing_ruleset(payment_routing_ruleset(), varset(), domain_revision()) ->
|
||||||
payment_routing_ruleset().
|
payment_routing_ruleset().
|
||||||
|
|
||||||
reduce_payment_routing_ruleset(RuleSet, VS, DomainRevision) ->
|
reduce_payment_routing_ruleset(RuleSet, VS, DomainRevision) ->
|
||||||
RuleSet#domain_PaymentRoutingRuleset{
|
RuleSet#domain_PaymentRoutingRuleset{
|
||||||
decisions = reduce_payment_routing_decisions(RuleSet#domain_PaymentRoutingRuleset.decisions, VS, DomainRevision)
|
decisions = reduce_payment_routing_decisions(RuleSet#domain_PaymentRoutingRuleset.decisions, VS, DomainRevision)
|
||||||
@ -47,26 +46,29 @@ reduce_payment_routing_delegates([D | Delegates], VS, Rev) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
reduce_payment_routing_candidates(Candidates, VS, Rev) ->
|
reduce_payment_routing_candidates(Candidates, VS, Rev) ->
|
||||||
{candidates, lists:foldr(
|
{candidates,
|
||||||
fun(C, AccIn) ->
|
lists:foldr(
|
||||||
Predicate = C#domain_PaymentRoutingCandidate.allowed,
|
fun(C, AccIn) ->
|
||||||
case pm_selector:reduce_predicate(Predicate, VS, Rev) of
|
Predicate = C#domain_PaymentRoutingCandidate.allowed,
|
||||||
?const(false) ->
|
case pm_selector:reduce_predicate(Predicate, VS, Rev) of
|
||||||
AccIn;
|
?const(false) ->
|
||||||
?const(true) = ReducedPredicate ->
|
AccIn;
|
||||||
ReducedCandidate = C#domain_PaymentRoutingCandidate{
|
?const(true) = ReducedPredicate ->
|
||||||
allowed = ReducedPredicate
|
ReducedCandidate = C#domain_PaymentRoutingCandidate{
|
||||||
},
|
allowed = ReducedPredicate
|
||||||
[ReducedCandidate | AccIn];
|
},
|
||||||
_ ->
|
[ReducedCandidate | AccIn];
|
||||||
logger:warning(
|
_ ->
|
||||||
"Routing rule misconfiguration, can't reduce decision. Predicate: ~p~nVarset:~n~p",
|
logger:warning(
|
||||||
[Predicate, VS]
|
"Routing rule misconfiguration, can't reduce decision. Predicate: ~p~nVarset:~n~p",
|
||||||
),
|
[Predicate, VS]
|
||||||
[C | AccIn]
|
),
|
||||||
end
|
[C | AccIn]
|
||||||
end,
|
end
|
||||||
[], Candidates)}.
|
end,
|
||||||
|
[],
|
||||||
|
Candidates
|
||||||
|
)}.
|
||||||
|
|
||||||
get_payment_routing_ruleset(RuleSetRef, DomainRevision) ->
|
get_payment_routing_ruleset(RuleSetRef, DomainRevision) ->
|
||||||
pm_domain:get(DomainRevision, {payment_routing_rules, RuleSetRef}).
|
pm_domain:get(DomainRevision, {payment_routing_rules, RuleSetRef}).
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
%%% - Domain revision is out of place. An `Opts`, anyone?
|
%%% - Domain revision is out of place. An `Opts`, anyone?
|
||||||
|
|
||||||
-module(pm_selector).
|
-module(pm_selector).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@ -30,21 +31,22 @@
|
|||||||
dmsl_domain_thrift:'FeeSelector'().
|
dmsl_domain_thrift:'FeeSelector'().
|
||||||
|
|
||||||
-type value() ::
|
-type value() ::
|
||||||
_. %% FIXME
|
%% FIXME
|
||||||
|
_.
|
||||||
|
|
||||||
-type varset() :: #{
|
-type varset() :: #{
|
||||||
category => dmsl_domain_thrift:'CategoryRef'(),
|
category => dmsl_domain_thrift:'CategoryRef'(),
|
||||||
currency => dmsl_domain_thrift:'CurrencyRef'(),
|
currency => dmsl_domain_thrift:'CurrencyRef'(),
|
||||||
cost => dmsl_domain_thrift:'Cash'(),
|
cost => dmsl_domain_thrift:'Cash'(),
|
||||||
payment_tool => dmsl_domain_thrift:'PaymentTool'(),
|
payment_tool => dmsl_domain_thrift:'PaymentTool'(),
|
||||||
party_id => dmsl_domain_thrift:'PartyID'(),
|
party_id => dmsl_domain_thrift:'PartyID'(),
|
||||||
shop_id => dmsl_domain_thrift:'ShopID'(),
|
shop_id => dmsl_domain_thrift:'ShopID'(),
|
||||||
risk_score => dmsl_domain_thrift:'RiskScore'(),
|
risk_score => dmsl_domain_thrift:'RiskScore'(),
|
||||||
flow => instant | {hold, dmsl_domain_thrift:'HoldLifetime'()},
|
flow => instant | {hold, dmsl_domain_thrift:'HoldLifetime'()},
|
||||||
payout_method => dmsl_domain_thrift:'PayoutMethodRef'(),
|
payout_method => dmsl_domain_thrift:'PayoutMethodRef'(),
|
||||||
wallet_id => dmsl_domain_thrift:'WalletID'(),
|
wallet_id => dmsl_domain_thrift:'WalletID'(),
|
||||||
identification_level => dmsl_domain_thrift:'ContractorIdentificationLevel'(),
|
identification_level => dmsl_domain_thrift:'ContractorIdentificationLevel'(),
|
||||||
p2p_tool => dmsl_domain_thrift:'P2PTool'()
|
p2p_tool => dmsl_domain_thrift:'P2PTool'()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type predicate() :: dmsl_domain_thrift:'Predicate'().
|
-type predicate() :: dmsl_domain_thrift:'Predicate'().
|
||||||
@ -61,7 +63,6 @@
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-spec reduce_to_value(t(), varset(), pm_domain:revision()) -> value() | no_return().
|
-spec reduce_to_value(t(), varset(), pm_domain:revision()) -> value() | no_return().
|
||||||
|
|
||||||
reduce_to_value(Selector, VS, Revision) ->
|
reduce_to_value(Selector, VS, Revision) ->
|
||||||
case reduce(Selector, VS, Revision) of
|
case reduce(Selector, VS, Revision) of
|
||||||
{value, Value} ->
|
{value, Value} ->
|
||||||
@ -70,9 +71,7 @@ reduce_to_value(Selector, VS, Revision) ->
|
|||||||
error({misconfiguration, {'Can\'t reduce selector to value', Selector, VS, Revision}})
|
error({misconfiguration, {'Can\'t reduce selector to value', Selector, VS, Revision}})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec reduce(t(), varset(), pm_domain:revision()) ->
|
-spec reduce(t(), varset(), pm_domain:revision()) -> t().
|
||||||
t().
|
|
||||||
|
|
||||||
reduce({value, _} = V, _, _) ->
|
reduce({value, _} = V, _, _) ->
|
||||||
V;
|
V;
|
||||||
reduce({decisions, Ps}, VS, Rev) ->
|
reduce({decisions, Ps}, VS, Rev) ->
|
||||||
@ -100,11 +99,10 @@ reduce_decisions([], _, _) ->
|
|||||||
|
|
||||||
-spec reduce_predicate(predicate(), varset(), pm_domain:revision()) ->
|
-spec reduce_predicate(predicate(), varset(), pm_domain:revision()) ->
|
||||||
predicate() |
|
predicate() |
|
||||||
{criterion, criterion()}. % for a partially reduced criterion
|
% for a partially reduced criterion
|
||||||
|
{criterion, criterion()}.
|
||||||
reduce_predicate(?const(B), _, _) ->
|
reduce_predicate(?const(B), _, _) ->
|
||||||
?const(B);
|
?const(B);
|
||||||
|
|
||||||
reduce_predicate({condition, C0}, VS, Rev) ->
|
reduce_predicate({condition, C0}, VS, Rev) ->
|
||||||
case reduce_condition(C0, VS, Rev) of
|
case reduce_condition(C0, VS, Rev) of
|
||||||
?const(B) ->
|
?const(B) ->
|
||||||
@ -112,7 +110,6 @@ reduce_predicate({condition, C0}, VS, Rev) ->
|
|||||||
C1 ->
|
C1 ->
|
||||||
{condition, C1}
|
{condition, C1}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
reduce_predicate({is_not, P0}, VS, Rev) ->
|
reduce_predicate({is_not, P0}, VS, Rev) ->
|
||||||
case reduce_predicate(P0, VS, Rev) of
|
case reduce_predicate(P0, VS, Rev) of
|
||||||
?const(B) ->
|
?const(B) ->
|
||||||
@ -120,13 +117,10 @@ reduce_predicate({is_not, P0}, VS, Rev) ->
|
|||||||
P1 ->
|
P1 ->
|
||||||
{is_not, P1}
|
{is_not, P1}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
reduce_predicate({all_of, Ps}, VS, Rev) ->
|
reduce_predicate({all_of, Ps}, VS, Rev) ->
|
||||||
reduce_combination(all_of, false, Ps, VS, Rev, []);
|
reduce_combination(all_of, false, Ps, VS, Rev, []);
|
||||||
|
|
||||||
reduce_predicate({any_of, Ps}, VS, Rev) ->
|
reduce_predicate({any_of, Ps}, VS, Rev) ->
|
||||||
reduce_combination(any_of, true, Ps, VS, Rev, []);
|
reduce_combination(any_of, true, Ps, VS, Rev, []);
|
||||||
|
|
||||||
reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) ->
|
reduce_predicate({criterion, CriterionRef = #domain_CriterionRef{}}, VS, Rev) ->
|
||||||
Criterion = pm_domain:get(Rev, {criterion, CriterionRef}),
|
Criterion = pm_domain:get(Rev, {criterion, CriterionRef}),
|
||||||
case reduce_predicate(Criterion#domain_Criterion.predicate, VS, Rev) of
|
case reduce_predicate(Criterion#domain_Criterion.predicate, VS, Rev) of
|
||||||
@ -165,6 +159,7 @@ reduce_condition(C, VS, Rev) ->
|
|||||||
-spec test() -> _.
|
-spec test() -> _.
|
||||||
|
|
||||||
-spec p2p_provider_test() -> _.
|
-spec p2p_provider_test() -> _.
|
||||||
|
|
||||||
p2p_provider_test() ->
|
p2p_provider_test() ->
|
||||||
BankCardCondition = #domain_BankCardCondition{definition = {issuer_country_is, rus}},
|
BankCardCondition = #domain_BankCardCondition{definition = {issuer_country_is, rus}},
|
||||||
BankCardCondition2 = #domain_BankCardCondition{definition = {issuer_country_is, usa}},
|
BankCardCondition2 = #domain_BankCardCondition{definition = {issuer_country_is, usa}},
|
||||||
@ -176,33 +171,34 @@ p2p_provider_test() ->
|
|||||||
sender_is = {payment_tool, {bank_card, BankCardCondition}},
|
sender_is = {payment_tool, {bank_card, BankCardCondition}},
|
||||||
receiver_is = {payment_tool, {bank_card, BankCardCondition2}}
|
receiver_is = {payment_tool, {bank_card, BankCardCondition2}}
|
||||||
},
|
},
|
||||||
P2PProviderSelector = {decisions, [
|
P2PProviderSelector =
|
||||||
#domain_P2PProviderDecision{
|
{decisions, [
|
||||||
if_ = {condition, {p2p_tool, P2PCondition1}},
|
#domain_P2PProviderDecision{
|
||||||
then_ = {value, [#domain_ProviderRef{id = 1}]}
|
if_ = {condition, {p2p_tool, P2PCondition1}},
|
||||||
},
|
then_ = {value, [#domain_ProviderRef{id = 1}]}
|
||||||
#domain_P2PProviderDecision{
|
},
|
||||||
if_ = {condition, {p2p_tool, P2PCondition2}},
|
#domain_P2PProviderDecision{
|
||||||
then_ = {value, [#domain_ProviderRef{id = 2}]}
|
if_ = {condition, {p2p_tool, P2PCondition2}},
|
||||||
}
|
then_ = {value, [#domain_ProviderRef{id = 2}]}
|
||||||
]},
|
}
|
||||||
|
]},
|
||||||
BankCard1 = #domain_BankCard{
|
BankCard1 = #domain_BankCard{
|
||||||
token = <<"TOKEN1">>,
|
token = <<"TOKEN1">>,
|
||||||
payment_system = mastercard,
|
payment_system = mastercard,
|
||||||
bin = <<"888888">>,
|
bin = <<"888888">>,
|
||||||
last_digits = <<"888">>,
|
last_digits = <<"888">>,
|
||||||
issuer_country = rus
|
issuer_country = rus
|
||||||
},
|
},
|
||||||
BankCard2 = #domain_BankCard{
|
BankCard2 = #domain_BankCard{
|
||||||
token = <<"TOKEN2">>,
|
token = <<"TOKEN2">>,
|
||||||
payment_system = mastercard,
|
payment_system = mastercard,
|
||||||
bin = <<"777777">>,
|
bin = <<"777777">>,
|
||||||
last_digits = <<"777">>,
|
last_digits = <<"777">>,
|
||||||
issuer_country = rus
|
issuer_country = rus
|
||||||
},
|
},
|
||||||
Vs = #{
|
Vs = #{
|
||||||
p2p_tool => #domain_P2PTool{
|
p2p_tool => #domain_P2PTool{
|
||||||
sender = {bank_card, BankCard1},
|
sender = {bank_card, BankCard1},
|
||||||
receiver = {bank_card, BankCard2}
|
receiver = {bank_card, BankCard2}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -210,17 +206,22 @@ p2p_provider_test() ->
|
|||||||
|
|
||||||
-spec p2p_allow_test() -> _.
|
-spec p2p_allow_test() -> _.
|
||||||
p2p_allow_test() ->
|
p2p_allow_test() ->
|
||||||
FunGenCard = fun(PS, Country) -> #domain_BankCard{
|
FunGenCard = fun(PS, Country) ->
|
||||||
token = <<"TOKEN1">>,
|
#domain_BankCard{
|
||||||
payment_system = PS,
|
token = <<"TOKEN1">>,
|
||||||
bin = <<"888888">>,
|
payment_system = PS,
|
||||||
last_digits = <<"888">>,
|
bin = <<"888888">>,
|
||||||
issuer_country = Country}
|
last_digits = <<"888">>,
|
||||||
|
issuer_country = Country
|
||||||
|
}
|
||||||
end,
|
end,
|
||||||
FunGenVS = fun(PS1, PS2) -> #{p2p_tool => #domain_P2PTool{
|
FunGenVS = fun(PS1, PS2) ->
|
||||||
sender = {bank_card, FunGenCard(PS1, rus)},
|
#{
|
||||||
receiver = {bank_card, FunGenCard(PS2, rus)}
|
p2p_tool => #domain_P2PTool{
|
||||||
}}
|
sender = {bank_card, FunGenCard(PS1, rus)},
|
||||||
|
receiver = {bank_card, FunGenCard(PS2, rus)}
|
||||||
|
}
|
||||||
|
}
|
||||||
end,
|
end,
|
||||||
Condition = #domain_BankCardCondition{definition = {payment_system_is, visa}},
|
Condition = #domain_BankCardCondition{definition = {payment_system_is, visa}},
|
||||||
CardCondition1 = #domain_P2PToolCondition{
|
CardCondition1 = #domain_P2PToolCondition{
|
||||||
|
@ -7,18 +7,15 @@
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-spec unique_id() -> dmsl_base_thrift:'ID'().
|
-spec unique_id() -> dmsl_base_thrift:'ID'().
|
||||||
|
|
||||||
unique_id() ->
|
unique_id() ->
|
||||||
<<ID:64>> = snowflake:new(),
|
<<ID:64>> = snowflake:new(),
|
||||||
genlib_format:format_int_base(ID, 62).
|
genlib_format:format_int_base(ID, 62).
|
||||||
|
|
||||||
-spec select_defined(T | undefined, T | undefined) -> T | undefined.
|
-spec select_defined(T | undefined, T | undefined) -> T | undefined.
|
||||||
|
|
||||||
select_defined(V1, V2) ->
|
select_defined(V1, V2) ->
|
||||||
select_defined([V1, V2]).
|
select_defined([V1, V2]).
|
||||||
|
|
||||||
-spec select_defined([T | undefined]) -> T | undefined.
|
-spec select_defined([T | undefined]) -> T | undefined.
|
||||||
|
|
||||||
select_defined([V | _]) when V /= undefined ->
|
select_defined([V | _]) when V /= undefined ->
|
||||||
V;
|
V;
|
||||||
select_defined([undefined | Vs]) ->
|
select_defined([undefined | Vs]) ->
|
||||||
@ -31,7 +28,6 @@ select_defined([]) ->
|
|||||||
-spec unwrap_result
|
-spec unwrap_result
|
||||||
({ok, T}) -> T;
|
({ok, T}) -> T;
|
||||||
({error, _}) -> no_return().
|
({error, _}) -> no_return().
|
||||||
|
|
||||||
unwrap_result({ok, V}) ->
|
unwrap_result({ok, V}) ->
|
||||||
V;
|
V;
|
||||||
unwrap_result({error, E}) ->
|
unwrap_result({error, E}) ->
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
-module(pm_wallet).
|
-module(pm_wallet).
|
||||||
|
|
||||||
-include("party_events.hrl").
|
-include("party_events.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@ -11,15 +12,13 @@
|
|||||||
|
|
||||||
%% Interface
|
%% Interface
|
||||||
|
|
||||||
-type wallet() :: dmsl_domain_thrift:'Wallet'().
|
-type wallet() :: dmsl_domain_thrift:'Wallet'().
|
||||||
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
|
-type wallet_id() :: dmsl_domain_thrift:'WalletID'().
|
||||||
-type wallet_params() :: dmsl_payment_processing_thrift:'WalletParams'().
|
-type wallet_params() :: dmsl_payment_processing_thrift:'WalletParams'().
|
||||||
-type wallet_account() :: dmsl_domain_thrift:'WalletAccount'().
|
-type wallet_account() :: dmsl_domain_thrift:'WalletAccount'().
|
||||||
-type wallet_account_params() :: dmsl_payment_processing_thrift:'WalletAccountParams'().
|
-type wallet_account_params() :: dmsl_payment_processing_thrift:'WalletAccountParams'().
|
||||||
|
|
||||||
-spec create(wallet_id(), wallet_params(), pm_datetime:timestamp()) ->
|
|
||||||
wallet().
|
|
||||||
|
|
||||||
|
-spec create(wallet_id(), wallet_params(), pm_datetime:timestamp()) -> wallet().
|
||||||
create(
|
create(
|
||||||
ID,
|
ID,
|
||||||
#payproc_WalletParams{
|
#payproc_WalletParams{
|
||||||
@ -37,9 +36,7 @@ create(
|
|||||||
contract = ContractID
|
contract = ContractID
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec create_account(wallet_account_params()) ->
|
-spec create_account(wallet_account_params()) -> wallet_account().
|
||||||
wallet_account().
|
|
||||||
|
|
||||||
create_account(#payproc_WalletAccountParams{currency = Currency}) ->
|
create_account(#payproc_WalletAccountParams{currency = Currency}) ->
|
||||||
SymbolicCode = Currency#domain_CurrencyRef.symbolic_code,
|
SymbolicCode = Currency#domain_CurrencyRef.symbolic_code,
|
||||||
SettlementID = pm_accounting:create_account(SymbolicCode),
|
SettlementID = pm_accounting:create_account(SymbolicCode),
|
||||||
@ -50,9 +47,7 @@ create_account(#payproc_WalletAccountParams{currency = Currency}) ->
|
|||||||
payout = PayoutID
|
payout = PayoutID
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec create_fake_account(wallet_account_params()) ->
|
-spec create_fake_account(wallet_account_params()) -> wallet_account().
|
||||||
wallet_account().
|
|
||||||
|
|
||||||
create_fake_account(#payproc_WalletAccountParams{currency = Currency}) ->
|
create_fake_account(#payproc_WalletAccountParams{currency = Currency}) ->
|
||||||
#domain_WalletAccount{
|
#domain_WalletAccount{
|
||||||
currency = Currency,
|
currency = Currency,
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([new/1]).
|
-export([new/1]).
|
||||||
|
|
||||||
-type url() :: woody:url().
|
-type url() :: woody:url().
|
||||||
-type event_handler() :: woody:ev_handler().
|
-type event_handler() :: woody:ev_handler().
|
||||||
-type transport_opts() :: woody_client_thrift_http_transport:transport_options().
|
-type transport_opts() :: woody_client_thrift_http_transport:transport_options().
|
||||||
|
|
||||||
-type client() :: #{
|
-type client() :: #{
|
||||||
url := url(),
|
url := url(),
|
||||||
event_handler := event_handler(),
|
event_handler := event_handler(),
|
||||||
transport_opts => transport_opts()
|
transport_opts => transport_opts()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
@ -19,9 +19,7 @@
|
|||||||
transport_opts => transport_opts()
|
transport_opts => transport_opts()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec new(woody:url() | opts()) ->
|
-spec new(woody:url() | opts()) -> client().
|
||||||
client().
|
|
||||||
|
|
||||||
new(Opts = #{url := _}) ->
|
new(Opts = #{url := _}) ->
|
||||||
EventHandlerOpts = genlib_app:env(party_management, scoper_event_handler_options, #{}),
|
EventHandlerOpts = genlib_app:env(party_management, scoper_event_handler_options, #{}),
|
||||||
maps:merge(
|
maps:merge(
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
-module(pm_woody_handler_utils).
|
-module(pm_woody_handler_utils).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-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().
|
-type user_identity() :: woody_user_identity:user_identity().
|
||||||
|
|
||||||
-export([get_user_identity/0]).
|
-export([get_user_identity/0]).
|
||||||
-export([assume_user_identity/1]).
|
-export([assume_user_identity/1]).
|
||||||
|
|
||||||
-spec get_user_identity() -> woody_user_identity:user_identity() | undefined.
|
-spec get_user_identity() -> woody_user_identity:user_identity() | undefined.
|
||||||
|
|
||||||
get_user_identity() ->
|
get_user_identity() ->
|
||||||
try
|
try
|
||||||
Context = pm_context:load(),
|
Context = pm_context:load(),
|
||||||
@ -19,12 +19,10 @@ get_user_identity() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec set_user_identity(user_identity()) -> ok.
|
-spec set_user_identity(user_identity()) -> ok.
|
||||||
|
|
||||||
set_user_identity(UserIdentity) ->
|
set_user_identity(UserIdentity) ->
|
||||||
pm_context:save(pm_context:set_user_identity(UserIdentity, pm_context:load())).
|
pm_context:save(pm_context:set_user_identity(UserIdentity, pm_context:load())).
|
||||||
|
|
||||||
-spec assume_user_identity(user_info()) -> ok.
|
-spec assume_user_identity(user_info()) -> ok.
|
||||||
|
|
||||||
assume_user_identity(UserInfo) ->
|
assume_user_identity(UserInfo) ->
|
||||||
case get_user_identity() of
|
case get_user_identity() of
|
||||||
V when V /= undefined ->
|
V when V /= undefined ->
|
||||||
@ -41,9 +39,7 @@ map_user_info(#payproc_UserInfo{id = PartyID, type = Type}) ->
|
|||||||
|
|
||||||
map_user_type({external_user, #payproc_ExternalUser{}}) ->
|
map_user_type({external_user, #payproc_ExternalUser{}}) ->
|
||||||
<<"external">>;
|
<<"external">>;
|
||||||
|
|
||||||
map_user_type({internal_user, #payproc_InternalUser{}}) ->
|
map_user_type({internal_user, #payproc_InternalUser{}}) ->
|
||||||
<<"internal">>;
|
<<"internal">>;
|
||||||
|
|
||||||
map_user_type({service_user, #payproc_ServiceUser{}}) ->
|
map_user_type({service_user, #payproc_ServiceUser{}}) ->
|
||||||
<<"service">>.
|
<<"service">>.
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
-behaviour(woody_server_thrift_handler).
|
-behaviour(woody_server_thrift_handler).
|
||||||
|
|
||||||
-export([handle_function/4]).
|
-export([handle_function/4]).
|
||||||
|
|
||||||
-export_type([handler_opts/0]).
|
-export_type([handler_opts/0]).
|
||||||
-export_type([client_opts/0]).
|
-export_type([client_opts/0]).
|
||||||
|
|
||||||
@ -15,16 +16,16 @@
|
|||||||
}.
|
}.
|
||||||
|
|
||||||
-type client_opts() :: #{
|
-type client_opts() :: #{
|
||||||
url := woody:url(),
|
url := woody:url(),
|
||||||
transport_opts => [{_, _}]
|
transport_opts => [{_, _}]
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-define(DEFAULT_HANDLING_TIMEOUT, 30000). % 30 seconds
|
% 30 seconds
|
||||||
|
-define(DEFAULT_HANDLING_TIMEOUT, 30000).
|
||||||
|
|
||||||
%% Callbacks
|
%% Callbacks
|
||||||
|
|
||||||
-callback(handle_function(woody:func(), woody:args(), handler_opts()) ->
|
-callback handle_function(woody:func(), woody:args(), handler_opts()) -> term() | no_return().
|
||||||
term() | no_return()).
|
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
|
|
||||||
@ -35,9 +36,7 @@
|
|||||||
|
|
||||||
-export([get_service_options/1]).
|
-export([get_service_options/1]).
|
||||||
|
|
||||||
-spec handle_function(woody:func(), woody:args(), woody_context:ctx(), handler_opts()) ->
|
-spec handle_function(woody:func(), woody:args(), woody_context:ctx(), handler_opts()) -> {ok, term()} | no_return().
|
||||||
{ok, term()} | no_return().
|
|
||||||
|
|
||||||
handle_function(Func, Args, WoodyContext0, #{handler := Handler} = Opts) ->
|
handle_function(Func, Args, WoodyContext0, #{handler := Handler} = Opts) ->
|
||||||
WoodyContext = ensure_woody_deadline_set(WoodyContext0, Opts),
|
WoodyContext = ensure_woody_deadline_set(WoodyContext0, Opts),
|
||||||
ok = pm_context:save(create_context(WoodyContext)),
|
ok = pm_context:save(create_context(WoodyContext)),
|
||||||
@ -55,52 +54,44 @@ handle_function(Func, Args, WoodyContext0, #{handler := Handler} = Opts) ->
|
|||||||
pm_context:cleanup()
|
pm_context:cleanup()
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec call(atom(), woody:func(), woody:args()) ->
|
-spec call(atom(), woody:func(), woody:args()) -> term().
|
||||||
term().
|
|
||||||
|
|
||||||
call(ServiceName, Function, Args) ->
|
call(ServiceName, Function, Args) ->
|
||||||
Opts = get_service_options(ServiceName),
|
Opts = get_service_options(ServiceName),
|
||||||
Deadline = undefined,
|
Deadline = undefined,
|
||||||
call(ServiceName, Function, Args, Opts, Deadline).
|
call(ServiceName, Function, Args, Opts, Deadline).
|
||||||
|
|
||||||
-spec call(atom(), woody:func(), woody:args(), client_opts()) ->
|
-spec call(atom(), woody:func(), woody:args(), client_opts()) -> term().
|
||||||
term().
|
|
||||||
|
|
||||||
call(ServiceName, Function, Args, Opts) ->
|
call(ServiceName, Function, Args, Opts) ->
|
||||||
Deadline = undefined,
|
Deadline = undefined,
|
||||||
call(ServiceName, Function, Args, Opts, Deadline).
|
call(ServiceName, Function, Args, Opts, Deadline).
|
||||||
|
|
||||||
-spec call(atom(), woody:func(), woody:args(), client_opts(), woody_deadline:deadline()) ->
|
-spec call(atom(), woody:func(), woody:args(), client_opts(), woody_deadline:deadline()) -> term().
|
||||||
term().
|
|
||||||
|
|
||||||
call(ServiceName, Function, Args, Opts, Deadline) ->
|
call(ServiceName, Function, Args, Opts, Deadline) ->
|
||||||
Service = get_service_modname(ServiceName),
|
Service = get_service_modname(ServiceName),
|
||||||
Context = pm_context:get_woody_context(pm_context:load()),
|
Context = pm_context:get_woody_context(pm_context:load()),
|
||||||
Request = {Service, Function, Args},
|
Request = {Service, Function, Args},
|
||||||
woody_client:call(
|
woody_client:call(
|
||||||
Request,
|
Request,
|
||||||
Opts#{event_handler => {
|
Opts#{
|
||||||
scoper_woody_event_handler,
|
event_handler => {
|
||||||
genlib_app:env(party_management, scoper_event_handler_options, #{})
|
scoper_woody_event_handler,
|
||||||
}},
|
genlib_app:env(party_management, scoper_event_handler_options, #{})
|
||||||
|
}
|
||||||
|
},
|
||||||
attach_deadline(Deadline, Context)
|
attach_deadline(Deadline, Context)
|
||||||
).
|
).
|
||||||
|
|
||||||
-spec get_service_options(atom()) ->
|
-spec get_service_options(atom()) -> client_opts().
|
||||||
client_opts().
|
|
||||||
get_service_options(ServiceName) ->
|
get_service_options(ServiceName) ->
|
||||||
construct_opts(maps:get(ServiceName, genlib_app:env(party_management, services))).
|
construct_opts(maps:get(ServiceName, genlib_app:env(party_management, services))).
|
||||||
|
|
||||||
-spec attach_deadline(woody_deadline:deadline(), woody_context:ctx()) -> woody_context:ctx().
|
-spec attach_deadline(woody_deadline:deadline(), woody_context:ctx()) -> woody_context:ctx().
|
||||||
|
|
||||||
attach_deadline(undefined, Context) ->
|
attach_deadline(undefined, Context) ->
|
||||||
Context;
|
Context;
|
||||||
attach_deadline(Deadline, Context) ->
|
attach_deadline(Deadline, Context) ->
|
||||||
woody_context:set_deadline(Deadline, Context).
|
woody_context:set_deadline(Deadline, Context).
|
||||||
|
|
||||||
-spec raise(term()) ->
|
-spec raise(term()) -> no_return().
|
||||||
no_return().
|
|
||||||
|
|
||||||
raise(Exception) ->
|
raise(Exception) ->
|
||||||
woody_error:raise(business, Exception).
|
woody_error:raise(business, Exception).
|
||||||
|
|
||||||
@ -111,9 +102,7 @@ construct_opts(Opts = #{url := Url}) ->
|
|||||||
construct_opts(Url) ->
|
construct_opts(Url) ->
|
||||||
#{url => genlib:to_binary(Url)}.
|
#{url => genlib:to_binary(Url)}.
|
||||||
|
|
||||||
-spec get_service_modname(atom()) ->
|
-spec get_service_modname(atom()) -> {module(), atom()}.
|
||||||
{module(), atom()}.
|
|
||||||
|
|
||||||
get_service_modname(ServiceName) ->
|
get_service_modname(ServiceName) ->
|
||||||
pm_proto:get_service(ServiceName).
|
pm_proto:get_service(ServiceName).
|
||||||
|
|
||||||
@ -123,9 +112,7 @@ create_context(WoodyContext) ->
|
|||||||
},
|
},
|
||||||
pm_context:create(ContextOptions).
|
pm_context:create(ContextOptions).
|
||||||
|
|
||||||
-spec ensure_woody_deadline_set(woody_context:ctx(), handler_opts()) ->
|
-spec ensure_woody_deadline_set(woody_context:ctx(), handler_opts()) -> woody_context:ctx().
|
||||||
woody_context:ctx().
|
|
||||||
|
|
||||||
ensure_woody_deadline_set(WoodyContext, Opts) ->
|
ensure_woody_deadline_set(WoodyContext, Opts) ->
|
||||||
case woody_context:get_deadline(WoodyContext) of
|
case woody_context:get_deadline(WoodyContext) of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
-include("claim_management.hrl").
|
-include("claim_management.hrl").
|
||||||
-include("pm_ct_domain.hrl").
|
-include("pm_ct_domain.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([all/0]).
|
-export([all/0]).
|
||||||
@ -30,18 +31,17 @@
|
|||||||
-type config() :: pm_ct_helper:config().
|
-type config() :: pm_ct_helper:config().
|
||||||
-type test_case_name() :: pm_ct_helper:test_case_name().
|
-type test_case_name() :: pm_ct_helper:test_case_name().
|
||||||
|
|
||||||
-define(REAL_CONTRACTOR_ID1, <<"CONTRACTOR2">>).
|
-define(REAL_CONTRACTOR_ID1, <<"CONTRACTOR2">>).
|
||||||
-define(REAL_CONTRACTOR_ID2, <<"CONTRACTOR3">>).
|
-define(REAL_CONTRACTOR_ID2, <<"CONTRACTOR3">>).
|
||||||
-define(REAL_CONTRACT_ID1, <<"CONTRACT2">>).
|
-define(REAL_CONTRACT_ID1, <<"CONTRACT2">>).
|
||||||
-define(REAL_CONTRACT_ID2, <<"CONTRACT3">>).
|
-define(REAL_CONTRACT_ID2, <<"CONTRACT3">>).
|
||||||
-define(REAL_PAYOUT_TOOL_ID1, <<"PAYOUTTOOL2">>).
|
-define(REAL_PAYOUT_TOOL_ID1, <<"PAYOUTTOOL2">>).
|
||||||
-define(REAL_PAYOUT_TOOL_ID2, <<"PAYOUTTOOL3">>).
|
-define(REAL_PAYOUT_TOOL_ID2, <<"PAYOUTTOOL3">>).
|
||||||
-define(REAL_SHOP_ID, <<"SHOP2">>).
|
-define(REAL_SHOP_ID, <<"SHOP2">>).
|
||||||
|
|
||||||
%%% CT
|
%%% CT
|
||||||
|
|
||||||
-spec all() -> [test_case_name()].
|
-spec all() -> [test_case_name()].
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
[
|
[
|
||||||
party_creation,
|
party_creation,
|
||||||
@ -65,17 +65,15 @@ all() ->
|
|||||||
].
|
].
|
||||||
|
|
||||||
-spec init_per_suite(config()) -> config().
|
-spec init_per_suite(config()) -> config().
|
||||||
|
|
||||||
init_per_suite(C) ->
|
init_per_suite(C) ->
|
||||||
{Apps, Ret} = pm_ct_helper:start_apps([woody, scoper, dmt_client, party_client, party_management, hellgate]),
|
{Apps, Ret} = pm_ct_helper:start_apps([woody, scoper, dmt_client, party_client, party_management, hellgate]),
|
||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
ok = pm_domain:insert(construct_domain_fixture()),
|
ok = pm_domain:insert(construct_domain_fixture()),
|
||||||
PartyID = erlang:list_to_binary([?MODULE_STRING, ".", erlang:integer_to_list(erlang:system_time())]),
|
PartyID = erlang:list_to_binary([?MODULE_STRING, ".", erlang:integer_to_list(erlang:system_time())]),
|
||||||
ApiClient = pm_ct_helper:create_client(RootUrl, PartyID),
|
ApiClient = pm_ct_helper:create_client(RootUrl, PartyID),
|
||||||
[{root_url, RootUrl}, {apps, Apps}, {party_id, PartyID}, {api_client, ApiClient} | C].
|
[{root_url, RootUrl}, {apps, Apps}, {party_id, PartyID}, {api_client, ApiClient} | C].
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> _.
|
-spec end_per_suite(config()) -> _.
|
||||||
|
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
ok = pm_domain:cleanup(),
|
ok = pm_domain:cleanup(),
|
||||||
[application:stop(App) || App <- cfg(apps, C)].
|
[application:stop(App) || App <- cfg(apps, C)].
|
||||||
@ -83,25 +81,23 @@ end_per_suite(C) ->
|
|||||||
%%% Tests
|
%%% Tests
|
||||||
|
|
||||||
-spec party_creation(config()) -> _.
|
-spec party_creation(config()) -> _.
|
||||||
|
|
||||||
party_creation(C) ->
|
party_creation(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContactInfo = #domain_PartyContactInfo{email = <<?MODULE_STRING>>},
|
ContactInfo = #domain_PartyContactInfo{email = <<?MODULE_STRING>>},
|
||||||
ok = create_party(PartyID, ContactInfo, C),
|
ok = create_party(PartyID, ContactInfo, C),
|
||||||
{ok, Party} = get_party(PartyID, C),
|
{ok, Party} = get_party(PartyID, C),
|
||||||
#domain_Party{
|
#domain_Party{
|
||||||
id = PartyID,
|
id = PartyID,
|
||||||
contact_info = ContactInfo,
|
contact_info = ContactInfo,
|
||||||
blocking = {unblocked, #domain_Unblocked{}},
|
blocking = {unblocked, #domain_Unblocked{}},
|
||||||
suspension = {active, #domain_Active{}},
|
suspension = {active, #domain_Active{}},
|
||||||
shops = Shops,
|
shops = Shops,
|
||||||
contracts = Contracts
|
contracts = Contracts
|
||||||
} = Party,
|
} = Party,
|
||||||
0 = maps:size(Shops),
|
0 = maps:size(Shops),
|
||||||
0 = maps:size(Contracts).
|
0 = maps:size(Contracts).
|
||||||
|
|
||||||
-spec contractor_one_creation(config()) -> _.
|
-spec contractor_one_creation(config()) -> _.
|
||||||
|
|
||||||
contractor_one_creation(C) ->
|
contractor_one_creation(C) ->
|
||||||
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
|
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
|
||||||
ContractorID = ?REAL_CONTRACTOR_ID1,
|
ContractorID = ?REAL_CONTRACTOR_ID1,
|
||||||
@ -116,7 +112,6 @@ contractor_one_creation(C) ->
|
|||||||
#domain_PartyContractor{} = pm_party:get_contractor(ContractorID, Party).
|
#domain_PartyContractor{} = pm_party:get_contractor(ContractorID, Party).
|
||||||
|
|
||||||
-spec contractor_two_creation(config()) -> _.
|
-spec contractor_two_creation(config()) -> _.
|
||||||
|
|
||||||
contractor_two_creation(C) ->
|
contractor_two_creation(C) ->
|
||||||
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
|
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
|
||||||
ContractorID = ?REAL_CONTRACTOR_ID2,
|
ContractorID = ?REAL_CONTRACTOR_ID2,
|
||||||
@ -131,7 +126,6 @@ contractor_two_creation(C) ->
|
|||||||
#domain_PartyContractor{} = pm_party:get_contractor(ContractorID, Party).
|
#domain_PartyContractor{} = pm_party:get_contractor(ContractorID, Party).
|
||||||
|
|
||||||
-spec contractor_modification(config()) -> _.
|
-spec contractor_modification(config()) -> _.
|
||||||
|
|
||||||
contractor_modification(C) ->
|
contractor_modification(C) ->
|
||||||
ContractorID = ?REAL_CONTRACTOR_ID1,
|
ContractorID = ?REAL_CONTRACTOR_ID1,
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
@ -148,7 +142,6 @@ contractor_modification(C) ->
|
|||||||
C1 /= C2 orelse error(same_contractor).
|
C1 /= C2 orelse error(same_contractor).
|
||||||
|
|
||||||
-spec contract_one_creation(config()) -> _.
|
-spec contract_one_creation(config()) -> _.
|
||||||
|
|
||||||
contract_one_creation(C) ->
|
contract_one_creation(C) ->
|
||||||
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
|
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
|
||||||
PayoutToolParams = make_payout_tool_params(),
|
PayoutToolParams = make_payout_tool_params(),
|
||||||
@ -172,7 +165,6 @@ contract_one_creation(C) ->
|
|||||||
true = lists:keymember(PayoutToolID2, #domain_PayoutTool.id, PayoutTools).
|
true = lists:keymember(PayoutToolID2, #domain_PayoutTool.id, PayoutTools).
|
||||||
|
|
||||||
-spec contract_two_creation(config()) -> _.
|
-spec contract_two_creation(config()) -> _.
|
||||||
|
|
||||||
contract_two_creation(C) ->
|
contract_two_creation(C) ->
|
||||||
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
|
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
|
||||||
PayoutToolParams = make_payout_tool_params(),
|
PayoutToolParams = make_payout_tool_params(),
|
||||||
@ -193,10 +185,9 @@ contract_two_creation(C) ->
|
|||||||
true = lists:keymember(PayoutToolID1, #domain_PayoutTool.id, PayoutTools).
|
true = lists:keymember(PayoutToolID1, #domain_PayoutTool.id, PayoutTools).
|
||||||
|
|
||||||
-spec contract_contractor_modification(config()) -> _.
|
-spec contract_contractor_modification(config()) -> _.
|
||||||
|
|
||||||
contract_contractor_modification(C) ->
|
contract_contractor_modification(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractID = ?REAL_CONTRACT_ID2,
|
ContractID = ?REAL_CONTRACT_ID2,
|
||||||
NewContractor = ?REAL_CONTRACTOR_ID2,
|
NewContractor = ?REAL_CONTRACTOR_ID2,
|
||||||
Modifications = [
|
Modifications = [
|
||||||
?cm_contract_modification(ContractID, {contractor_modification, NewContractor})
|
?cm_contract_modification(ContractID, {contractor_modification, NewContractor})
|
||||||
@ -205,12 +196,11 @@ contract_contractor_modification(C) ->
|
|||||||
ok = accept_claim(Claim, C),
|
ok = accept_claim(Claim, C),
|
||||||
ok = commit_claim(Claim, C),
|
ok = commit_claim(Claim, C),
|
||||||
{ok, #domain_Contract{
|
{ok, #domain_Contract{
|
||||||
id = ContractID,
|
id = ContractID,
|
||||||
contractor_id = NewContractor
|
contractor_id = NewContractor
|
||||||
}} = get_contract(PartyID, ContractID, C).
|
}} = get_contract(PartyID, ContractID, C).
|
||||||
|
|
||||||
-spec contract_adjustment_creation(config()) -> _.
|
-spec contract_adjustment_creation(config()) -> _.
|
||||||
|
|
||||||
contract_adjustment_creation(C) ->
|
contract_adjustment_creation(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractID = ?REAL_CONTRACT_ID1,
|
ContractID = ?REAL_CONTRACT_ID1,
|
||||||
@ -227,7 +217,6 @@ contract_adjustment_creation(C) ->
|
|||||||
true = lists:keymember(ID, #domain_ContractAdjustment.id, Adjustments).
|
true = lists:keymember(ID, #domain_ContractAdjustment.id, Adjustments).
|
||||||
|
|
||||||
-spec contract_legal_agreement_binding(config()) -> _.
|
-spec contract_legal_agreement_binding(config()) -> _.
|
||||||
|
|
||||||
contract_legal_agreement_binding(C) ->
|
contract_legal_agreement_binding(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractID = ?REAL_CONTRACT_ID1,
|
ContractID = ?REAL_CONTRACT_ID1,
|
||||||
@ -245,7 +234,6 @@ contract_legal_agreement_binding(C) ->
|
|||||||
}} = get_contract(PartyID, ContractID, C).
|
}} = get_contract(PartyID, ContractID, C).
|
||||||
|
|
||||||
-spec contract_report_preferences_modification(config()) -> _.
|
-spec contract_report_preferences_modification(config()) -> _.
|
||||||
|
|
||||||
contract_report_preferences_modification(C) ->
|
contract_report_preferences_modification(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractID = ?REAL_CONTRACT_ID1,
|
ContractID = ?REAL_CONTRACT_ID1,
|
||||||
@ -254,9 +242,9 @@ contract_report_preferences_modification(C) ->
|
|||||||
service_acceptance_act_preferences = #domain_ServiceAcceptanceActPreferences{
|
service_acceptance_act_preferences = #domain_ServiceAcceptanceActPreferences{
|
||||||
schedule = ?bussched(1),
|
schedule = ?bussched(1),
|
||||||
signer = #domain_Representative{
|
signer = #domain_Representative{
|
||||||
position = <<"69">>,
|
position = <<"69">>,
|
||||||
full_name = <<"Generic Name">>,
|
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).
|
}} = get_contract(PartyID, ContractID, C).
|
||||||
|
|
||||||
-spec shop_creation(config()) -> _.
|
-spec shop_creation(config()) -> _.
|
||||||
|
|
||||||
shop_creation(C) ->
|
shop_creation(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
Details = #domain_ShopDetails{
|
Details = #domain_ShopDetails{
|
||||||
name = <<"SOME SHOP NAME">>,
|
name = <<"SOME SHOP NAME">>,
|
||||||
description = <<"Very meaningfull description of the shop.">>
|
description = <<"Very meaningfull description of the shop.">>
|
||||||
},
|
},
|
||||||
Category = ?cat(2),
|
Category = ?cat(2),
|
||||||
@ -286,10 +273,10 @@ shop_creation(C) ->
|
|||||||
ShopID = ?REAL_SHOP_ID,
|
ShopID = ?REAL_SHOP_ID,
|
||||||
PayoutToolID1 = ?REAL_PAYOUT_TOOL_ID1,
|
PayoutToolID1 = ?REAL_PAYOUT_TOOL_ID1,
|
||||||
ShopParams = #claim_management_ShopParams{
|
ShopParams = #claim_management_ShopParams{
|
||||||
category = Category,
|
category = Category,
|
||||||
location = Location,
|
location = Location,
|
||||||
details = Details,
|
details = Details,
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID1
|
payout_tool_id = PayoutToolID1
|
||||||
},
|
},
|
||||||
Schedule = ?bussched(1),
|
Schedule = ?bussched(1),
|
||||||
@ -304,23 +291,22 @@ shop_creation(C) ->
|
|||||||
ok = commit_claim(Claim, C),
|
ok = commit_claim(Claim, C),
|
||||||
{ok, #domain_Shop{
|
{ok, #domain_Shop{
|
||||||
id = ShopID,
|
id = ShopID,
|
||||||
details = Details,
|
details = Details,
|
||||||
location = Location,
|
location = Location,
|
||||||
category = Category,
|
category = Category,
|
||||||
account = #domain_ShopAccount{currency = ?cur(<<"RUB">>)},
|
account = #domain_ShopAccount{currency = ?cur(<<"RUB">>)},
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID1,
|
payout_tool_id = PayoutToolID1,
|
||||||
payout_schedule = Schedule
|
payout_schedule = Schedule
|
||||||
}} = get_shop(PartyID, ShopID, C).
|
}} = get_shop(PartyID, ShopID, C).
|
||||||
|
|
||||||
-spec shop_complex_modification(config()) -> _.
|
-spec shop_complex_modification(config()) -> _.
|
||||||
|
|
||||||
shop_complex_modification(C) ->
|
shop_complex_modification(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ShopID = ?REAL_SHOP_ID,
|
ShopID = ?REAL_SHOP_ID,
|
||||||
NewCategory = ?cat(3),
|
NewCategory = ?cat(3),
|
||||||
NewDetails = #domain_ShopDetails{
|
NewDetails = #domain_ShopDetails{
|
||||||
name = <<"UPDATED SHOP NAME">>,
|
name = <<"UPDATED SHOP NAME">>,
|
||||||
description = <<"Updated shop description.">>
|
description = <<"Updated shop description.">>
|
||||||
},
|
},
|
||||||
NewLocation = {url, <<"http://localhost">>},
|
NewLocation = {url, <<"http://localhost">>},
|
||||||
@ -343,22 +329,21 @@ shop_complex_modification(C) ->
|
|||||||
ok = accept_claim(Claim, C),
|
ok = accept_claim(Claim, C),
|
||||||
ok = commit_claim(Claim, C),
|
ok = commit_claim(Claim, C),
|
||||||
{ok, #domain_Shop{
|
{ok, #domain_Shop{
|
||||||
category = NewCategory,
|
category = NewCategory,
|
||||||
details = NewDetails,
|
details = NewDetails,
|
||||||
location = NewLocation,
|
location = NewLocation,
|
||||||
payout_tool_id = PayoutToolID2,
|
payout_tool_id = PayoutToolID2,
|
||||||
payout_schedule = Schedule
|
payout_schedule = Schedule
|
||||||
}} = get_shop(PartyID, ShopID, C).
|
}} = get_shop(PartyID, ShopID, C).
|
||||||
|
|
||||||
-spec shop_contract_modification(config()) -> _.
|
-spec shop_contract_modification(config()) -> _.
|
||||||
|
|
||||||
shop_contract_modification(C) ->
|
shop_contract_modification(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ShopID = ?REAL_SHOP_ID,
|
ShopID = ?REAL_SHOP_ID,
|
||||||
ContractID = ?REAL_CONTRACT_ID2,
|
ContractID = ?REAL_CONTRACT_ID2,
|
||||||
PayoutToolID = ?REAL_PAYOUT_TOOL_ID1,
|
PayoutToolID = ?REAL_PAYOUT_TOOL_ID1,
|
||||||
ShopContractParams = #claim_management_ShopContractModification{
|
ShopContractParams = #claim_management_ShopContractModification{
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID
|
payout_tool_id = PayoutToolID
|
||||||
},
|
},
|
||||||
Modifications = [?cm_shop_modification(ShopID, {contract_modification, ShopContractParams})],
|
Modifications = [?cm_shop_modification(ShopID, {contract_modification, ShopContractParams})],
|
||||||
@ -366,82 +351,80 @@ shop_contract_modification(C) ->
|
|||||||
ok = accept_claim(Claim, C),
|
ok = accept_claim(Claim, C),
|
||||||
ok = commit_claim(Claim, C),
|
ok = commit_claim(Claim, C),
|
||||||
{ok, #domain_Shop{
|
{ok, #domain_Shop{
|
||||||
contract_id = ContractID,
|
contract_id = ContractID,
|
||||||
payout_tool_id = PayoutToolID
|
payout_tool_id = PayoutToolID
|
||||||
}} = get_shop(PartyID, ShopID, C).
|
}} = get_shop(PartyID, ShopID, C).
|
||||||
|
|
||||||
-spec contract_termination(config()) -> _.
|
-spec contract_termination(config()) -> _.
|
||||||
|
|
||||||
contract_termination(C) ->
|
contract_termination(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractID = ?REAL_CONTRACT_ID1,
|
ContractID = ?REAL_CONTRACT_ID1,
|
||||||
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
|
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
|
||||||
Modifications = [?cm_contract_modification(ContractID, {termination, Reason})],
|
Modifications = [?cm_contract_modification(ContractID, {termination, Reason})],
|
||||||
Claim = claim(Modifications, PartyID),
|
Claim = claim(Modifications, PartyID),
|
||||||
ok = accept_claim(Claim, C),
|
ok = accept_claim(Claim, C),
|
||||||
ok = commit_claim(Claim, C),
|
ok = commit_claim(Claim, C),
|
||||||
{ok, #domain_Contract{
|
{ok, #domain_Contract{
|
||||||
id = ContractID,
|
id = ContractID,
|
||||||
status = {terminated, _}
|
status = {terminated, _}
|
||||||
}} = get_contract(PartyID, ContractID, C).
|
}} = get_contract(PartyID, ContractID, C).
|
||||||
|
|
||||||
-spec contractor_already_exists(config()) -> _.
|
-spec contractor_already_exists(config()) -> _.
|
||||||
|
|
||||||
contractor_already_exists(C) ->
|
contractor_already_exists(C) ->
|
||||||
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
|
ContractorParams = pm_ct_helper:make_battle_ready_contractor(),
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractorID = ?REAL_CONTRACTOR_ID1,
|
ContractorID = ?REAL_CONTRACTOR_ID1,
|
||||||
Modifications = [?cm_contractor_creation(ContractorID, ContractorParams)],
|
Modifications = [?cm_contractor_creation(ContractorID, ContractorParams)],
|
||||||
Claim = claim(Modifications, PartyID),
|
Claim = claim(Modifications, PartyID),
|
||||||
Reason = <<"{invalid_contractor,{payproc_InvalidContractor,<<\"", ContractorID/binary,
|
Reason =
|
||||||
"\">>,{already_exists,<<\"", ContractorID/binary, "\">>}}}">>,
|
<<"{invalid_contractor,{payproc_InvalidContractor,<<\"", ContractorID/binary, "\">>,{already_exists,<<\"",
|
||||||
|
ContractorID/binary, "\">>}}}">>,
|
||||||
{exception, #claim_management_InvalidChangeset{
|
{exception, #claim_management_InvalidChangeset{
|
||||||
reason = Reason
|
reason = Reason
|
||||||
}} = accept_claim(Claim, C).
|
}} = accept_claim(Claim, C).
|
||||||
|
|
||||||
-spec contract_already_exists(config()) -> _.
|
-spec contract_already_exists(config()) -> _.
|
||||||
|
|
||||||
contract_already_exists(C) ->
|
contract_already_exists(C) ->
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
|
ContractParams = make_contract_params(?REAL_CONTRACTOR_ID1),
|
||||||
ContractID = ?REAL_CONTRACT_ID1,
|
ContractID = ?REAL_CONTRACT_ID1,
|
||||||
Modifications = [?cm_contract_creation(ContractID, ContractParams)],
|
Modifications = [?cm_contract_creation(ContractID, ContractParams)],
|
||||||
Claim = claim(Modifications, PartyID),
|
Claim = claim(Modifications, PartyID),
|
||||||
Reason = <<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary,
|
Reason =
|
||||||
"\">>,{already_exists,<<\"", ContractID/binary, "\">>}}}">>,
|
<<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary, "\">>,{already_exists,<<\"",
|
||||||
|
ContractID/binary, "\">>}}}">>,
|
||||||
{exception, #claim_management_InvalidChangeset{
|
{exception, #claim_management_InvalidChangeset{
|
||||||
reason = Reason
|
reason = Reason
|
||||||
}} = accept_claim(Claim, C).
|
}} = accept_claim(Claim, C).
|
||||||
|
|
||||||
-spec contract_already_terminated(config()) -> _.
|
-spec contract_already_terminated(config()) -> _.
|
||||||
|
|
||||||
contract_already_terminated(C) ->
|
contract_already_terminated(C) ->
|
||||||
ContractID = ?REAL_CONTRACT_ID1,
|
ContractID = ?REAL_CONTRACT_ID1,
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
|
Reason = #claim_management_ContractTermination{reason = <<"Because!">>},
|
||||||
Modifications = [?cm_contract_modification(ContractID, {termination, Reason})],
|
Modifications = [?cm_contract_modification(ContractID, {termination, Reason})],
|
||||||
Claim = claim(Modifications, PartyID),
|
Claim = claim(Modifications, PartyID),
|
||||||
ErrorReason = <<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary,
|
ErrorReason =
|
||||||
"\">>,{invalid_status,{terminated,{domain_ContractTerminated">>,
|
<<"{invalid_contract,{payproc_InvalidContract,<<\"", ContractID/binary,
|
||||||
|
"\">>,{invalid_status,{terminated,{domain_ContractTerminated">>,
|
||||||
ErrorReasonSize = erlang:byte_size(ErrorReason),
|
ErrorReasonSize = erlang:byte_size(ErrorReason),
|
||||||
{exception, #claim_management_InvalidChangeset{
|
{exception, #claim_management_InvalidChangeset{
|
||||||
reason = <<ErrorReason:ErrorReasonSize/binary, _/binary>>
|
reason = <<ErrorReason:ErrorReasonSize/binary, _/binary>>
|
||||||
}} = accept_claim(Claim, C).
|
}} = accept_claim(Claim, C).
|
||||||
|
|
||||||
-spec shop_already_exists(config()) -> _.
|
-spec shop_already_exists(config()) -> _.
|
||||||
|
|
||||||
shop_already_exists(C) ->
|
shop_already_exists(C) ->
|
||||||
Details = #domain_ShopDetails{
|
Details = #domain_ShopDetails{
|
||||||
name = <<"SOME SHOP NAME">>,
|
name = <<"SOME SHOP NAME">>,
|
||||||
description = <<"Very meaningfull description of the shop.">>
|
description = <<"Very meaningfull description of the shop.">>
|
||||||
},
|
},
|
||||||
ShopID = ?REAL_SHOP_ID,
|
ShopID = ?REAL_SHOP_ID,
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
ShopParams = #claim_management_ShopParams{
|
ShopParams = #claim_management_ShopParams{
|
||||||
category = ?cat(2),
|
category = ?cat(2),
|
||||||
location = {url, <<"https://example.com">>},
|
location = {url, <<"https://example.com">>},
|
||||||
details = Details,
|
details = Details,
|
||||||
contract_id = ?REAL_CONTRACT_ID1,
|
contract_id = ?REAL_CONTRACT_ID1,
|
||||||
payout_tool_id = ?REAL_PAYOUT_TOOL_ID1
|
payout_tool_id = ?REAL_PAYOUT_TOOL_ID1
|
||||||
},
|
},
|
||||||
ScheduleParams = #claim_management_ScheduleModification{schedule = ?bussched(1)},
|
ScheduleParams = #claim_management_ScheduleModification{schedule = ?bussched(1)},
|
||||||
@ -451,8 +434,9 @@ shop_already_exists(C) ->
|
|||||||
?cm_shop_modification(ShopID, {payout_schedule_modification, ScheduleParams})
|
?cm_shop_modification(ShopID, {payout_schedule_modification, ScheduleParams})
|
||||||
],
|
],
|
||||||
Claim = claim(Modifications, PartyID),
|
Claim = claim(Modifications, PartyID),
|
||||||
Reason = <<"{invalid_shop,{payproc_InvalidShop,<<\"", ShopID/binary,
|
Reason =
|
||||||
"\">>,{already_exists,<<\"", ShopID/binary, "\">>}}}">>,
|
<<"{invalid_shop,{payproc_InvalidShop,<<\"", ShopID/binary, "\">>,{already_exists,<<\"", ShopID/binary,
|
||||||
|
"\">>}}}">>,
|
||||||
{exception, #claim_management_InvalidChangeset{
|
{exception, #claim_management_InvalidChangeset{
|
||||||
reason = Reason
|
reason = Reason
|
||||||
}} = accept_claim(Claim, C).
|
}} = accept_claim(Claim, C).
|
||||||
@ -467,11 +451,11 @@ claim(PartyModifications, PartyID) ->
|
|||||||
type = {internal_user, #claim_management_InternalUser{}}
|
type = {internal_user, #claim_management_InternalUser{}}
|
||||||
},
|
},
|
||||||
#claim_management_Claim{
|
#claim_management_Claim{
|
||||||
id = id(),
|
id = id(),
|
||||||
party_id = PartyID,
|
party_id = PartyID,
|
||||||
status = {pending, #claim_management_ClaimPending{}},
|
status = {pending, #claim_management_ClaimPending{}},
|
||||||
changeset = [?cm_party_modification(id(), ts(), Mod, UserInfo) || Mod <- PartyModifications],
|
changeset = [?cm_party_modification(id(), ts(), Mod, UserInfo) || Mod <- PartyModifications],
|
||||||
revision = 1,
|
revision = 1,
|
||||||
created_at = ts()
|
created_at = ts()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
@ -485,8 +469,8 @@ cfg(Key, C) ->
|
|||||||
pm_ct_helper:cfg(Key, C).
|
pm_ct_helper:cfg(Key, C).
|
||||||
|
|
||||||
call(Function, Args, C) ->
|
call(Function, Args, C) ->
|
||||||
ApiClient = cfg(api_client, C),
|
ApiClient = cfg(api_client, C),
|
||||||
PartyID = cfg(party_id, C),
|
PartyID = cfg(party_id, C),
|
||||||
{Result, _} = pm_client_api:call(claim_committer, Function, [PartyID | Args], ApiClient),
|
{Result, _} = pm_client_api:call(claim_committer, Function, [PartyID | Args], ApiClient),
|
||||||
map_call_result(Result).
|
map_call_result(Result).
|
||||||
|
|
||||||
@ -502,7 +486,7 @@ map_call_result(Other) ->
|
|||||||
Other.
|
Other.
|
||||||
|
|
||||||
call_pm(Fun, Args, C) ->
|
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),
|
{Result, _} = pm_client_api:call(party_management, Fun, [undefined | Args], ApiClient),
|
||||||
map_call_result(Result).
|
map_call_result(Result).
|
||||||
|
|
||||||
@ -527,24 +511,24 @@ make_contract_params(ContractorID, TemplateRef) ->
|
|||||||
|
|
||||||
make_contract_params(ContractorID, TemplateRef, PaymentInstitutionRef) ->
|
make_contract_params(ContractorID, TemplateRef, PaymentInstitutionRef) ->
|
||||||
#claim_management_ContractParams{
|
#claim_management_ContractParams{
|
||||||
contractor_id = ContractorID,
|
contractor_id = ContractorID,
|
||||||
template = TemplateRef,
|
template = TemplateRef,
|
||||||
payment_institution = PaymentInstitutionRef
|
payment_institution = PaymentInstitutionRef
|
||||||
}.
|
}.
|
||||||
|
|
||||||
make_payout_tool_params() ->
|
make_payout_tool_params() ->
|
||||||
#claim_management_PayoutToolParams{
|
#claim_management_PayoutToolParams{
|
||||||
currency = ?cur(<<"RUB">>),
|
currency = ?cur(<<"RUB">>),
|
||||||
tool_info = {russian_bank_account, #domain_RussianBankAccount{
|
tool_info =
|
||||||
account = <<"4276300010908312893">>,
|
{russian_bank_account, #domain_RussianBankAccount{
|
||||||
bank_name = <<"SomeBank">>,
|
account = <<"4276300010908312893">>,
|
||||||
bank_post_account = <<"123129876">>,
|
bank_name = <<"SomeBank">>,
|
||||||
bank_bik = <<"66642666">>
|
bank_post_account = <<"123129876">>,
|
||||||
}}
|
bank_bik = <<"66642666">>
|
||||||
|
}}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec construct_domain_fixture() -> [pm_domain:object()].
|
-spec construct_domain_fixture() -> [pm_domain:object()].
|
||||||
|
|
||||||
construct_domain_fixture() ->
|
construct_domain_fixture() ->
|
||||||
TestTermSet = #domain_TermSet{
|
TestTermSet = #domain_TermSet{
|
||||||
payments = #domain_PaymentsServiceTerms{
|
payments = #domain_PaymentsServiceTerms{
|
||||||
@ -554,74 +538,89 @@ construct_domain_fixture() ->
|
|||||||
},
|
},
|
||||||
DefaultTermSet = #domain_TermSet{
|
DefaultTermSet = #domain_TermSet{
|
||||||
payments = #domain_PaymentsServiceTerms{
|
payments = #domain_PaymentsServiceTerms{
|
||||||
currencies = {value, ordsets:from_list([
|
currencies =
|
||||||
?cur(<<"RUB">>),
|
{value,
|
||||||
?cur(<<"USD">>)
|
ordsets:from_list([
|
||||||
])},
|
?cur(<<"RUB">>),
|
||||||
categories = {value, ordsets:from_list([
|
?cur(<<"USD">>)
|
||||||
?cat(2),
|
])},
|
||||||
?cat(3)
|
categories =
|
||||||
])},
|
{value,
|
||||||
payment_methods = {value, ordsets:from_list([
|
ordsets:from_list([
|
||||||
?pmt(bank_card_deprecated, visa)
|
?cat(2),
|
||||||
])}
|
?cat(3)
|
||||||
|
])},
|
||||||
|
payment_methods =
|
||||||
|
{value,
|
||||||
|
ordsets:from_list([
|
||||||
|
?pmt(bank_card_deprecated, visa)
|
||||||
|
])}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TermSet = #domain_TermSet{
|
TermSet = #domain_TermSet{
|
||||||
payments = #domain_PaymentsServiceTerms{
|
payments = #domain_PaymentsServiceTerms{
|
||||||
cash_limit = {value, #domain_CashRange{
|
cash_limit =
|
||||||
lower = {inclusive, #domain_Cash{amount = 1000, currency = ?cur(<<"RUB">>)}},
|
{value, #domain_CashRange{
|
||||||
upper = {exclusive, #domain_Cash{amount = 4200000, currency = ?cur(<<"RUB">>)}}
|
lower = {inclusive, #domain_Cash{amount = 1000, currency = ?cur(<<"RUB">>)}},
|
||||||
}},
|
upper = {exclusive, #domain_Cash{amount = 4200000, currency = ?cur(<<"RUB">>)}}
|
||||||
fees = {value, [
|
}},
|
||||||
?cfpost(
|
fees =
|
||||||
{merchant, settlement},
|
{value, [
|
||||||
{system, settlement},
|
?cfpost(
|
||||||
?share(45, 1000, operation_amount)
|
{merchant, settlement},
|
||||||
)
|
{system, settlement},
|
||||||
]}
|
?share(45, 1000, operation_amount)
|
||||||
|
)
|
||||||
|
]}
|
||||||
},
|
},
|
||||||
payouts = #domain_PayoutsServiceTerms{
|
payouts = #domain_PayoutsServiceTerms{
|
||||||
payout_methods = {decisions, [
|
payout_methods =
|
||||||
#domain_PayoutMethodDecision{
|
{decisions, [
|
||||||
if_ = {condition, {payment_tool,
|
#domain_PayoutMethodDecision{
|
||||||
{bank_card, #domain_BankCardCondition{
|
if_ =
|
||||||
definition = {issuer_bank_is, ?bank(1)}
|
{condition,
|
||||||
}}
|
{payment_tool,
|
||||||
}},
|
{bank_card, #domain_BankCardCondition{
|
||||||
then_ = {value, ordsets:from_list([?pomt(russian_bank_account), ?pomt(international_bank_account)])}
|
definition = {issuer_bank_is, ?bank(1)}
|
||||||
},
|
}}}},
|
||||||
#domain_PayoutMethodDecision{
|
then_ =
|
||||||
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{
|
{value, ordsets:from_list([?pomt(russian_bank_account), ?pomt(international_bank_account)])}
|
||||||
definition = {empty_cvv_is, true}
|
},
|
||||||
}}}},
|
#domain_PayoutMethodDecision{
|
||||||
then_ = {value, ordsets:from_list([])}
|
if_ =
|
||||||
},
|
{condition,
|
||||||
#domain_PayoutMethodDecision{
|
{payment_tool,
|
||||||
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{}}}},
|
{bank_card, #domain_BankCardCondition{
|
||||||
then_ = {value, ordsets:from_list([?pomt(russian_bank_account)])}
|
definition = {empty_cvv_is, true}
|
||||||
},
|
}}}},
|
||||||
#domain_PayoutMethodDecision{
|
then_ = {value, ordsets:from_list([])}
|
||||||
if_ = {condition, {payment_tool, {payment_terminal, #domain_PaymentTerminalCondition{}}}},
|
},
|
||||||
then_ = {value, ordsets:from_list([?pomt(international_bank_account)])}
|
#domain_PayoutMethodDecision{
|
||||||
},
|
if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{}}}},
|
||||||
#domain_PayoutMethodDecision{
|
then_ = {value, ordsets:from_list([?pomt(russian_bank_account)])}
|
||||||
if_ = {constant, true},
|
},
|
||||||
then_ = {value, ordsets:from_list([])}
|
#domain_PayoutMethodDecision{
|
||||||
}
|
if_ = {condition, {payment_tool, {payment_terminal, #domain_PaymentTerminalCondition{}}}},
|
||||||
]},
|
then_ = {value, ordsets:from_list([?pomt(international_bank_account)])}
|
||||||
fees = {value, [
|
},
|
||||||
?cfpost(
|
#domain_PayoutMethodDecision{
|
||||||
{merchant, settlement},
|
if_ = {constant, true},
|
||||||
{merchant, payout},
|
then_ = {value, ordsets:from_list([])}
|
||||||
?share(750, 1000, operation_amount)
|
}
|
||||||
),
|
]},
|
||||||
?cfpost(
|
fees =
|
||||||
{merchant, settlement},
|
{value, [
|
||||||
{system, settlement},
|
?cfpost(
|
||||||
?share(250, 1000, operation_amount)
|
{merchant, settlement},
|
||||||
)
|
{merchant, payout},
|
||||||
]}
|
?share(750, 1000, operation_amount)
|
||||||
|
),
|
||||||
|
?cfpost(
|
||||||
|
{merchant, settlement},
|
||||||
|
{system, settlement},
|
||||||
|
?share(250, 1000, operation_amount)
|
||||||
|
)
|
||||||
|
]}
|
||||||
},
|
},
|
||||||
wallets = #domain_WalletServiceTerms{
|
wallets = #domain_WalletServiceTerms{
|
||||||
currencies = {value, ordsets:from_list([?cur(<<"RUB">>)])}
|
currencies = {value, ordsets:from_list([?cur(<<"RUB">>)])}
|
||||||
@ -727,57 +726,71 @@ construct_domain_fixture() ->
|
|||||||
ref = ?trms(1),
|
ref = ?trms(1),
|
||||||
data = #domain_TermSetHierarchy{
|
data = #domain_TermSetHierarchy{
|
||||||
parent_terms = undefined,
|
parent_terms = undefined,
|
||||||
term_sets = [#domain_TimedTermSet{
|
term_sets = [
|
||||||
action_time = #'TimestampInterval'{},
|
#domain_TimedTermSet{
|
||||||
terms = TestTermSet
|
action_time = #'TimestampInterval'{},
|
||||||
}]
|
terms = TestTermSet
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
||||||
ref = ?trms(2),
|
ref = ?trms(2),
|
||||||
data = #domain_TermSetHierarchy{
|
data = #domain_TermSetHierarchy{
|
||||||
parent_terms = undefined,
|
parent_terms = undefined,
|
||||||
term_sets = [#domain_TimedTermSet{
|
term_sets = [
|
||||||
action_time = #'TimestampInterval'{},
|
#domain_TimedTermSet{
|
||||||
terms = DefaultTermSet
|
action_time = #'TimestampInterval'{},
|
||||||
}]
|
terms = DefaultTermSet
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
||||||
ref = ?trms(3),
|
ref = ?trms(3),
|
||||||
data = #domain_TermSetHierarchy{
|
data = #domain_TermSetHierarchy{
|
||||||
parent_terms = ?trms(2),
|
parent_terms = ?trms(2),
|
||||||
term_sets = [#domain_TimedTermSet{
|
term_sets = [
|
||||||
action_time = #'TimestampInterval'{},
|
#domain_TimedTermSet{
|
||||||
terms = TermSet
|
action_time = #'TimestampInterval'{},
|
||||||
}]
|
terms = TermSet
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
||||||
ref = ?trms(4),
|
ref = ?trms(4),
|
||||||
data = #domain_TermSetHierarchy{
|
data = #domain_TermSetHierarchy{
|
||||||
parent_terms = ?trms(3),
|
parent_terms = ?trms(3),
|
||||||
term_sets = [#domain_TimedTermSet{
|
term_sets = [
|
||||||
action_time = #'TimestampInterval'{},
|
#domain_TimedTermSet{
|
||||||
terms = #domain_TermSet{
|
action_time = #'TimestampInterval'{},
|
||||||
payments = #domain_PaymentsServiceTerms{
|
terms = #domain_TermSet{
|
||||||
currencies = {value, ordsets:from_list([
|
payments = #domain_PaymentsServiceTerms{
|
||||||
?cur(<<"RUB">>)
|
currencies =
|
||||||
])},
|
{value,
|
||||||
categories = {value, ordsets:from_list([
|
ordsets:from_list([
|
||||||
?cat(2)
|
?cur(<<"RUB">>)
|
||||||
])},
|
])},
|
||||||
payment_methods = {value, ordsets:from_list([
|
categories =
|
||||||
?pmt(bank_card_deprecated, visa)
|
{value,
|
||||||
])}
|
ordsets:from_list([
|
||||||
|
?cat(2)
|
||||||
|
])},
|
||||||
|
payment_methods =
|
||||||
|
{value,
|
||||||
|
ordsets:from_list([
|
||||||
|
?pmt(bank_card_deprecated, visa)
|
||||||
|
])}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
]
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{bank, #domain_BankObject{
|
{bank, #domain_BankObject{
|
||||||
ref = ?bank(1),
|
ref = ?bank(1),
|
||||||
data = #domain_Bank {
|
data = #domain_Bank{
|
||||||
name = <<"Test BIN range">>,
|
name = <<"Test BIN range">>,
|
||||||
description = <<"Test BIN range">>,
|
description = <<"Test BIN range">>,
|
||||||
bins = ordsets:from_list([<<"1234">>, <<"5678">>])
|
bins = ordsets:from_list([<<"1234">>, <<"5678">>])
|
||||||
|
@ -14,25 +14,30 @@
|
|||||||
-type object() :: pm_domain:object().
|
-type object() :: pm_domain:object().
|
||||||
|
|
||||||
-spec upsert(revision(), object() | [object()]) -> revision() | no_return().
|
-spec upsert(revision(), object() | [object()]) -> revision() | no_return().
|
||||||
|
|
||||||
upsert(Revision, NewObject) when not is_list(NewObject) ->
|
upsert(Revision, NewObject) when not is_list(NewObject) ->
|
||||||
upsert(Revision, [NewObject]);
|
upsert(Revision, [NewObject]);
|
||||||
upsert(Revision, NewObjects) ->
|
upsert(Revision, NewObjects) ->
|
||||||
Commit = #'Commit'{
|
Commit = #'Commit'{
|
||||||
ops = lists:foldl(
|
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
|
case pm_domain:find(Revision, {Tag, Ref}) of
|
||||||
NewData ->
|
NewData ->
|
||||||
Ops;
|
Ops;
|
||||||
notfound ->
|
notfound ->
|
||||||
[{insert, #'InsertOp'{
|
[
|
||||||
object = NewObject
|
{insert, #'InsertOp'{
|
||||||
}} | Ops];
|
object = NewObject
|
||||||
|
}}
|
||||||
|
| Ops
|
||||||
|
];
|
||||||
OldData ->
|
OldData ->
|
||||||
[{update, #'UpdateOp'{
|
[
|
||||||
old_object = {Tag, {ObjectName, Ref, OldData}},
|
{update, #'UpdateOp'{
|
||||||
new_object = NewObject
|
old_object = {Tag, {ObjectName, Ref, OldData}},
|
||||||
}} | Ops]
|
new_object = NewObject
|
||||||
|
}}
|
||||||
|
| Ops
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
[],
|
[],
|
||||||
@ -43,22 +48,21 @@ upsert(Revision, NewObjects) ->
|
|||||||
pm_domain:head().
|
pm_domain:head().
|
||||||
|
|
||||||
-spec reset(revision()) -> ok | no_return().
|
-spec reset(revision()) -> ok | no_return().
|
||||||
|
|
||||||
reset(ToRevision) ->
|
reset(ToRevision) ->
|
||||||
upsert(hg_domain:head(), maps:values(pm_domain:all(ToRevision))).
|
upsert(hg_domain:head(), maps:values(pm_domain:all(ToRevision))).
|
||||||
|
|
||||||
-spec commit(revision(), dmt_client:commit()) -> ok | no_return().
|
-spec commit(revision(), dmt_client:commit()) -> ok | no_return().
|
||||||
|
|
||||||
commit(Revision, Commit) ->
|
commit(Revision, Commit) ->
|
||||||
Revision = dmt_client:commit(Revision, Commit) - 1,
|
Revision = dmt_client:commit(Revision, Commit) - 1,
|
||||||
_ = pm_domain:all(Revision + 1),
|
_ = pm_domain:all(Revision + 1),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec with(object() | [object()], fun ((revision()) -> R)) -> R | no_return().
|
-spec with(object() | [object()], fun((revision()) -> R)) -> R | no_return().
|
||||||
|
|
||||||
with(NewObjects, Fun) ->
|
with(NewObjects, Fun) ->
|
||||||
WasRevision = pm_domain:head(),
|
WasRevision = pm_domain:head(),
|
||||||
Revision = upsert(WasRevision, NewObjects),
|
Revision = upsert(WasRevision, NewObjects),
|
||||||
try Fun(Revision) after
|
try
|
||||||
|
Fun(Revision)
|
||||||
|
after
|
||||||
reset(WasRevision)
|
reset(WasRevision)
|
||||||
end.
|
end.
|
||||||
|
@ -2,81 +2,83 @@
|
|||||||
-define(__pm_ct_domain__, 42).
|
-define(__pm_ct_domain__, 42).
|
||||||
|
|
||||||
-include("domain.hrl").
|
-include("domain.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.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(glob(), #domain_GlobalsRef{}).
|
||||||
-define(cur(ID), #domain_CurrencyRef{symbolic_code = ID}).
|
-define(cur(ID), #domain_CurrencyRef{symbolic_code = ID}).
|
||||||
-define(pmt(C, T), #domain_PaymentMethodRef{id = {C, T}}).
|
-define(pmt(C, T), #domain_PaymentMethodRef{id = {C, T}}).
|
||||||
-define(pomt(M), #domain_PayoutMethodRef{id = M}).
|
-define(pomt(M), #domain_PayoutMethodRef{id = M}).
|
||||||
-define(cat(ID), #domain_CategoryRef{id = ID}).
|
-define(cat(ID), #domain_CategoryRef{id = ID}).
|
||||||
-define(prx(ID), #domain_ProxyRef{id = ID}).
|
-define(prx(ID), #domain_ProxyRef{id = ID}).
|
||||||
-define(prv(ID), #domain_ProviderRef{id = ID}).
|
-define(prv(ID), #domain_ProviderRef{id = ID}).
|
||||||
-define(prvtrm(ID), #domain_ProviderTerminalRef{id = ID}).
|
-define(prvtrm(ID), #domain_ProviderTerminalRef{id = ID}).
|
||||||
-define(trm(ID), #domain_TerminalRef{id = ID}).
|
-define(trm(ID), #domain_TerminalRef{id = ID}).
|
||||||
-define(tmpl(ID), #domain_ContractTemplateRef{id = ID}).
|
-define(tmpl(ID), #domain_ContractTemplateRef{id = ID}).
|
||||||
-define(trms(ID), #domain_TermSetHierarchyRef{id = ID}).
|
-define(trms(ID), #domain_TermSetHierarchyRef{id = ID}).
|
||||||
-define(sas(ID), #domain_SystemAccountSetRef{id = ID}).
|
-define(sas(ID), #domain_SystemAccountSetRef{id = ID}).
|
||||||
-define(eas(ID), #domain_ExternalAccountSetRef{id = ID}).
|
-define(eas(ID), #domain_ExternalAccountSetRef{id = ID}).
|
||||||
-define(insp(ID), #domain_InspectorRef{id = ID}).
|
-define(insp(ID), #domain_InspectorRef{id = ID}).
|
||||||
-define(pinst(ID), #domain_PaymentInstitutionRef{id = ID}).
|
-define(pinst(ID), #domain_PaymentInstitutionRef{id = ID}).
|
||||||
-define(bank(ID), #domain_BankRef{id = ID}).
|
-define(bank(ID), #domain_BankRef{id = ID}).
|
||||||
-define(bussched(ID), #domain_BusinessScheduleRef{id = ID}).
|
-define(bussched(ID), #domain_BusinessScheduleRef{id = ID}).
|
||||||
-define(ruleset(ID), #domain_PaymentRoutingRulesetRef{id = ID}).
|
-define(ruleset(ID), #domain_PaymentRoutingRulesetRef{id = ID}).
|
||||||
-define(p2pprov(ID), #domain_P2PProviderRef{id = ID}).
|
-define(p2pprov(ID), #domain_P2PProviderRef{id = ID}).
|
||||||
-define(wtdrlprov(ID), #domain_WithdrawalProviderRef{id = ID}).
|
-define(wtdrlprov(ID), #domain_WithdrawalProviderRef{id = ID}).
|
||||||
-define(crit(ID), #domain_CriterionRef{id = ID}).
|
-define(crit(ID), #domain_CriterionRef{id = ID}).
|
||||||
-define(crp(ID), #domain_CashRegisterProviderRef{id = ID}).
|
-define(crp(ID), #domain_CashRegisterProviderRef{id = ID}).
|
||||||
|
|
||||||
-define(cashrng(Lower, Upper),
|
-define(cashrng(Lower, Upper), #domain_CashRange{lower = Lower, upper = Upper}).
|
||||||
#domain_CashRange{lower = Lower, upper = Upper}).
|
|
||||||
|
|
||||||
-define(prvacc(Stl), #domain_ProviderAccount{settlement = Stl}).
|
-define(prvacc(Stl), #domain_ProviderAccount{settlement = Stl}).
|
||||||
-define(partycond(ID, Def), {condition, {party, #domain_PartyCondition{id = ID, definition = Def}}}).
|
-define(partycond(ID, Def), {condition, {party, #domain_PartyCondition{id = ID, definition = Def}}}).
|
||||||
|
|
||||||
-define(fixed(Amount, Currency),
|
-define(fixed(Amount, Currency),
|
||||||
{fixed, #domain_CashVolumeFixed{cash = #domain_Cash{
|
{fixed, #domain_CashVolumeFixed{
|
||||||
amount = Amount,
|
cash = #domain_Cash{
|
||||||
currency = ?currency(Currency)
|
amount = Amount,
|
||||||
}}}).
|
currency = ?currency(Currency)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
).
|
||||||
|
|
||||||
-define(share(P, Q, C),
|
-define(share(P, Q, C),
|
||||||
{share, #domain_CashVolumeShare{
|
{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),
|
-define(share_with_rounding_method(P, Q, C, RM),
|
||||||
{share, #domain_CashVolumeShare{
|
{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),
|
-define(cfpost(A1, A2, V), #domain_CashFlowPosting{
|
||||||
#domain_CashFlowPosting{
|
source = A1,
|
||||||
source = A1,
|
destination = A2,
|
||||||
destination = A2,
|
volume = V
|
||||||
volume = V
|
}).
|
||||||
}
|
|
||||||
).
|
|
||||||
|
|
||||||
-define(cfpost(A1, A2, V, D),
|
-define(cfpost(A1, A2, V, D), #domain_CashFlowPosting{
|
||||||
#domain_CashFlowPosting{
|
source = A1,
|
||||||
source = A1,
|
destination = A2,
|
||||||
destination = A2,
|
volume = V,
|
||||||
volume = V,
|
details = D
|
||||||
details = D
|
}).
|
||||||
}
|
|
||||||
).
|
|
||||||
|
|
||||||
-define(tkz_bank_card(PaymentSystem, TokenProvider), ?tkz_bank_card(PaymentSystem, TokenProvider, dpan)).
|
-define(tkz_bank_card(PaymentSystem, TokenProvider), ?tkz_bank_card(PaymentSystem, TokenProvider, dpan)).
|
||||||
|
|
||||||
-define(tkz_bank_card(PaymentSystem, TokenProvider, TokenizationMethod),
|
-define(tkz_bank_card(PaymentSystem, TokenProvider, TokenizationMethod), #domain_TokenizedBankCard{
|
||||||
#domain_TokenizedBankCard{
|
payment_system = PaymentSystem,
|
||||||
payment_system = PaymentSystem,
|
token_provider = TokenProvider,
|
||||||
token_provider = TokenProvider,
|
tokenization_method = TokenizationMethod
|
||||||
tokenization_method = TokenizationMethod
|
}).
|
||||||
}).
|
|
||||||
|
|
||||||
-define(timeout_reason(), <<"Timeout">>).
|
-define(timeout_reason(), <<"Timeout">>).
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
-module(pm_ct_fixture).
|
-module(pm_ct_fixture).
|
||||||
|
|
||||||
-include("pm_ct_domain.hrl").
|
-include("pm_ct_domain.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_base_thrift.hrl").
|
-include_lib("damsel/include/dmsl_base_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-export([construct_currency/1]).
|
-export([construct_currency/1]).
|
||||||
@ -30,15 +32,15 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type name() :: binary().
|
-type name() :: binary().
|
||||||
-type category() :: dmsl_domain_thrift:'CategoryRef'().
|
-type category() :: dmsl_domain_thrift:'CategoryRef'().
|
||||||
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
|
-type currency() :: dmsl_domain_thrift:'CurrencyRef'().
|
||||||
-type proxy() :: dmsl_domain_thrift:'ProxyRef'().
|
-type proxy() :: dmsl_domain_thrift:'ProxyRef'().
|
||||||
-type inspector() :: dmsl_domain_thrift:'InspectorRef'().
|
-type inspector() :: dmsl_domain_thrift:'InspectorRef'().
|
||||||
-type risk_score() :: dmsl_domain_thrift:'RiskScore'().
|
-type risk_score() :: dmsl_domain_thrift:'RiskScore'().
|
||||||
-type template() :: dmsl_domain_thrift:'ContractTemplateRef'().
|
-type template() :: dmsl_domain_thrift:'ContractTemplateRef'().
|
||||||
-type terms() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
|
-type terms() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
|
||||||
-type lifetime() :: dmsl_domain_thrift:'Lifetime'() | undefined.
|
-type lifetime() :: dmsl_domain_thrift:'Lifetime'() | undefined.
|
||||||
-type payment_routing_ruleset() :: dmsl_domain_thrift:'PaymentRoutingRulesetRef'().
|
-type payment_routing_ruleset() :: dmsl_domain_thrift:'PaymentRoutingRulesetRef'().
|
||||||
|
|
||||||
-type system_account_set() :: dmsl_domain_thrift:'SystemAccountSetRef'().
|
-type system_account_set() :: dmsl_domain_thrift:'SystemAccountSetRef'().
|
||||||
@ -46,8 +48,8 @@
|
|||||||
|
|
||||||
-type business_schedule() :: dmsl_domain_thrift:'BusinessScheduleRef'().
|
-type business_schedule() :: dmsl_domain_thrift:'BusinessScheduleRef'().
|
||||||
|
|
||||||
-type criterion() :: dmsl_domain_thrift:'CriterionRef'().
|
-type criterion() :: dmsl_domain_thrift:'CriterionRef'().
|
||||||
-type predicate() :: dmsl_domain_thrift:'Predicate'().
|
-type predicate() :: dmsl_domain_thrift:'Predicate'().
|
||||||
|
|
||||||
-type term_set() :: dmsl_domain_thrift:'TermSet'().
|
-type term_set() :: dmsl_domain_thrift:'TermSet'().
|
||||||
-type term_set_hierarchy() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
|
-type term_set_hierarchy() :: dmsl_domain_thrift:'TermSetHierarchyRef'().
|
||||||
@ -58,15 +60,11 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec construct_currency(currency()) ->
|
-spec construct_currency(currency()) -> {currency, dmsl_domain_thrift:'CurrencyObject'()}.
|
||||||
{currency, dmsl_domain_thrift:'CurrencyObject'()}.
|
|
||||||
|
|
||||||
construct_currency(Ref) ->
|
construct_currency(Ref) ->
|
||||||
construct_currency(Ref, 2).
|
construct_currency(Ref, 2).
|
||||||
|
|
||||||
-spec construct_currency(currency(), Exponent :: pos_integer()) ->
|
-spec construct_currency(currency(), Exponent :: pos_integer()) -> {currency, dmsl_domain_thrift:'CurrencyObject'()}.
|
||||||
{currency, dmsl_domain_thrift:'CurrencyObject'()}.
|
|
||||||
|
|
||||||
construct_currency(?cur(SymbolicCode) = Ref, Exponent) ->
|
construct_currency(?cur(SymbolicCode) = Ref, Exponent) ->
|
||||||
{currency, #domain_CurrencyObject{
|
{currency, #domain_CurrencyObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -78,15 +76,11 @@ construct_currency(?cur(SymbolicCode) = Ref, Exponent) ->
|
|||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_category(category(), name()) ->
|
-spec construct_category(category(), name()) -> {category, dmsl_domain_thrift:'CategoryObject'()}.
|
||||||
{category, dmsl_domain_thrift:'CategoryObject'()}.
|
|
||||||
|
|
||||||
construct_category(Ref, Name) ->
|
construct_category(Ref, Name) ->
|
||||||
construct_category(Ref, Name, test).
|
construct_category(Ref, Name, test).
|
||||||
|
|
||||||
-spec construct_category(category(), name(), test | live) ->
|
-spec construct_category(category(), name(), test | live) -> {category, dmsl_domain_thrift:'CategoryObject'()}.
|
||||||
{category, dmsl_domain_thrift:'CategoryObject'()}.
|
|
||||||
|
|
||||||
construct_category(Ref, Name, Type) ->
|
construct_category(Ref, Name, Type) ->
|
||||||
{category, #domain_CategoryObject{
|
{category, #domain_CategoryObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -99,7 +93,6 @@ construct_category(Ref, Name, Type) ->
|
|||||||
|
|
||||||
-spec construct_payment_method(dmsl_domain_thrift:'PaymentMethodRef'()) ->
|
-spec construct_payment_method(dmsl_domain_thrift:'PaymentMethodRef'()) ->
|
||||||
{payment_method, dmsl_domain_thrift:'PaymentMethodObject'()}.
|
{payment_method, dmsl_domain_thrift:'PaymentMethodObject'()}.
|
||||||
|
|
||||||
construct_payment_method(?pmt(_Type, ?tkz_bank_card(Name, _)) = Ref) when is_atom(Name) ->
|
construct_payment_method(?pmt(_Type, ?tkz_bank_card(Name, _)) = Ref) when is_atom(Name) ->
|
||||||
construct_payment_method(Name, Ref);
|
construct_payment_method(Name, Ref);
|
||||||
construct_payment_method(?pmt(_Type, Name) = Ref) when is_atom(Name) ->
|
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'()) ->
|
-spec construct_payout_method(dmsl_domain_thrift:'PayoutMethodRef'()) ->
|
||||||
{payout_method, dmsl_domain_thrift:'PayoutMethodObject'()}.
|
{payout_method, dmsl_domain_thrift:'PayoutMethodObject'()}.
|
||||||
|
|
||||||
construct_payout_method(?pomt(M) = Ref) ->
|
construct_payout_method(?pomt(M) = Ref) ->
|
||||||
Def = erlang:atom_to_binary(M, unicode),
|
Def = erlang:atom_to_binary(M, unicode),
|
||||||
{payout_method, #domain_PayoutMethodObject{
|
{payout_method, #domain_PayoutMethodObject{
|
||||||
@ -130,41 +122,33 @@ construct_payout_method(?pomt(M) = Ref) ->
|
|||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_proxy(proxy(), name()) ->
|
-spec construct_proxy(proxy(), name()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
|
||||||
{proxy, dmsl_domain_thrift:'ProxyObject'()}.
|
|
||||||
|
|
||||||
construct_proxy(Ref, Name) ->
|
construct_proxy(Ref, Name) ->
|
||||||
construct_proxy(Ref, Name, #{}).
|
construct_proxy(Ref, Name, #{}).
|
||||||
|
|
||||||
-spec construct_proxy(proxy(), name(), Opts :: map()) ->
|
-spec construct_proxy(proxy(), name(), Opts :: map()) -> {proxy, dmsl_domain_thrift:'ProxyObject'()}.
|
||||||
{proxy, dmsl_domain_thrift:'ProxyObject'()}.
|
|
||||||
|
|
||||||
construct_proxy(Ref, Name, Opts) ->
|
construct_proxy(Ref, Name, Opts) ->
|
||||||
{proxy, #domain_ProxyObject{
|
{proxy, #domain_ProxyObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
data = #domain_ProxyDefinition{
|
data = #domain_ProxyDefinition{
|
||||||
name = Name,
|
name = Name,
|
||||||
description = Name,
|
description = Name,
|
||||||
url = <<>>,
|
url = <<>>,
|
||||||
options = Opts
|
options = Opts
|
||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_inspector(inspector(), name(), proxy()) ->
|
-spec construct_inspector(inspector(), name(), proxy()) -> {inspector, dmsl_domain_thrift:'InspectorObject'()}.
|
||||||
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
|
|
||||||
|
|
||||||
construct_inspector(Ref, Name, ProxyRef) ->
|
construct_inspector(Ref, Name, ProxyRef) ->
|
||||||
construct_inspector(Ref, Name, ProxyRef, #{}).
|
construct_inspector(Ref, Name, ProxyRef, #{}).
|
||||||
|
|
||||||
-spec construct_inspector(inspector(), name(), proxy(), Additional :: map()) ->
|
-spec construct_inspector(inspector(), name(), proxy(), Additional :: map()) ->
|
||||||
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
|
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
|
||||||
|
|
||||||
construct_inspector(Ref, Name, ProxyRef, Additional) ->
|
construct_inspector(Ref, Name, ProxyRef, Additional) ->
|
||||||
construct_inspector(Ref, Name, ProxyRef, Additional, undefined).
|
construct_inspector(Ref, Name, ProxyRef, Additional, undefined).
|
||||||
|
|
||||||
-spec construct_inspector(inspector(), name(), proxy(), Additional :: map(), risk_score()) ->
|
-spec construct_inspector(inspector(), name(), proxy(), Additional :: map(), risk_score()) ->
|
||||||
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
|
{inspector, dmsl_domain_thrift:'InspectorObject'()}.
|
||||||
|
|
||||||
construct_inspector(Ref, Name, ProxyRef, Additional, FallBackScore) ->
|
construct_inspector(Ref, Name, ProxyRef, Additional, FallBackScore) ->
|
||||||
{inspector, #domain_InspectorObject{
|
{inspector, #domain_InspectorObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -181,13 +165,11 @@ construct_inspector(Ref, Name, ProxyRef, Additional, FallBackScore) ->
|
|||||||
|
|
||||||
-spec construct_contract_template(template(), terms()) ->
|
-spec construct_contract_template(template(), terms()) ->
|
||||||
{contract_template, dmsl_domain_thrift:'ContractTemplateObject'()}.
|
{contract_template, dmsl_domain_thrift:'ContractTemplateObject'()}.
|
||||||
|
|
||||||
construct_contract_template(Ref, TermsRef) ->
|
construct_contract_template(Ref, TermsRef) ->
|
||||||
construct_contract_template(Ref, TermsRef, undefined, undefined).
|
construct_contract_template(Ref, TermsRef, undefined, undefined).
|
||||||
|
|
||||||
-spec construct_contract_template(template(), terms(), ValidSince :: lifetime(), ValidUntil :: lifetime()) ->
|
-spec construct_contract_template(template(), terms(), ValidSince :: lifetime(), ValidUntil :: lifetime()) ->
|
||||||
{contract_template, dmsl_domain_thrift:'ContractTemplateObject'()}.
|
{contract_template, dmsl_domain_thrift:'ContractTemplateObject'()}.
|
||||||
|
|
||||||
construct_contract_template(Ref, TermsRef, ValidSince, ValidUntil) ->
|
construct_contract_template(Ref, TermsRef, ValidSince, ValidUntil) ->
|
||||||
{contract_template, #domain_ContractTemplateObject{
|
{contract_template, #domain_ContractTemplateObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -199,11 +181,10 @@ construct_contract_template(Ref, TermsRef, ValidSince, ValidUntil) ->
|
|||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_provider_account_set([currency()]) -> dmsl_domain_thrift:'ProviderAccountSet'().
|
-spec construct_provider_account_set([currency()]) -> dmsl_domain_thrift:'ProviderAccountSet'().
|
||||||
|
|
||||||
construct_provider_account_set(Currencies) ->
|
construct_provider_account_set(Currencies) ->
|
||||||
ok = pm_context:save(pm_context:create()),
|
ok = pm_context:save(pm_context:create()),
|
||||||
AccountSet = lists:foldl(
|
AccountSet = lists:foldl(
|
||||||
fun (Cur = ?cur(Code), Acc) ->
|
fun(Cur = ?cur(Code), Acc) ->
|
||||||
Acc#{Cur => ?prvacc(pm_accounting:create_account(Code))}
|
Acc#{Cur => ?prvacc(pm_accounting:create_account(Code))}
|
||||||
end,
|
end,
|
||||||
#{},
|
#{},
|
||||||
@ -214,13 +195,11 @@ construct_provider_account_set(Currencies) ->
|
|||||||
|
|
||||||
-spec construct_system_account_set(system_account_set()) ->
|
-spec construct_system_account_set(system_account_set()) ->
|
||||||
{system_account_set, dmsl_domain_thrift:'SystemAccountSetObject'()}.
|
{system_account_set, dmsl_domain_thrift:'SystemAccountSetObject'()}.
|
||||||
|
|
||||||
construct_system_account_set(Ref) ->
|
construct_system_account_set(Ref) ->
|
||||||
construct_system_account_set(Ref, <<"Primaries">>, ?cur(<<"RUB">>)).
|
construct_system_account_set(Ref, <<"Primaries">>, ?cur(<<"RUB">>)).
|
||||||
|
|
||||||
-spec construct_system_account_set(system_account_set(), name(), currency()) ->
|
-spec construct_system_account_set(system_account_set(), name(), currency()) ->
|
||||||
{system_account_set, dmsl_domain_thrift:'SystemAccountSetObject'()}.
|
{system_account_set, dmsl_domain_thrift:'SystemAccountSetObject'()}.
|
||||||
|
|
||||||
construct_system_account_set(Ref, Name, ?cur(CurrencyCode)) ->
|
construct_system_account_set(Ref, Name, ?cur(CurrencyCode)) ->
|
||||||
ok = pm_context:save(pm_context:create()),
|
ok = pm_context:save(pm_context:create()),
|
||||||
SettlementAccountID = pm_accounting:create_account(CurrencyCode),
|
SettlementAccountID = pm_accounting:create_account(CurrencyCode),
|
||||||
@ -231,22 +210,22 @@ construct_system_account_set(Ref, Name, ?cur(CurrencyCode)) ->
|
|||||||
data = #domain_SystemAccountSet{
|
data = #domain_SystemAccountSet{
|
||||||
name = Name,
|
name = Name,
|
||||||
description = Name,
|
description = Name,
|
||||||
accounts = #{?cur(CurrencyCode) => #domain_SystemAccount{
|
accounts = #{
|
||||||
settlement = SettlementAccountID,
|
?cur(CurrencyCode) => #domain_SystemAccount{
|
||||||
subagent = SubagentAccountID
|
settlement = SettlementAccountID,
|
||||||
}}
|
subagent = SubagentAccountID
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_external_account_set(external_account_set()) ->
|
-spec construct_external_account_set(external_account_set()) ->
|
||||||
{system_account_set, dmsl_domain_thrift:'ExternalAccountSetObject'()}.
|
{system_account_set, dmsl_domain_thrift:'ExternalAccountSetObject'()}.
|
||||||
|
|
||||||
construct_external_account_set(Ref) ->
|
construct_external_account_set(Ref) ->
|
||||||
construct_external_account_set(Ref, <<"Primaries">>, ?cur(<<"RUB">>)).
|
construct_external_account_set(Ref, <<"Primaries">>, ?cur(<<"RUB">>)).
|
||||||
|
|
||||||
-spec construct_external_account_set(external_account_set(), name(), currency()) ->
|
-spec construct_external_account_set(external_account_set(), name(), currency()) ->
|
||||||
{system_account_set, dmsl_domain_thrift:'ExternalAccountSetObject'()}.
|
{system_account_set, dmsl_domain_thrift:'ExternalAccountSetObject'()}.
|
||||||
|
|
||||||
construct_external_account_set(Ref, Name, ?cur(CurrencyCode)) ->
|
construct_external_account_set(Ref, Name, ?cur(CurrencyCode)) ->
|
||||||
ok = pm_context:save(pm_context:create()),
|
ok = pm_context:save(pm_context:create()),
|
||||||
AccountID1 = pm_accounting:create_account(CurrencyCode),
|
AccountID1 = pm_accounting:create_account(CurrencyCode),
|
||||||
@ -257,16 +236,17 @@ construct_external_account_set(Ref, Name, ?cur(CurrencyCode)) ->
|
|||||||
data = #domain_ExternalAccountSet{
|
data = #domain_ExternalAccountSet{
|
||||||
name = Name,
|
name = Name,
|
||||||
description = Name,
|
description = Name,
|
||||||
accounts = #{?cur(<<"RUB">>) => #domain_ExternalAccount{
|
accounts = #{
|
||||||
income = AccountID1,
|
?cur(<<"RUB">>) => #domain_ExternalAccount{
|
||||||
outcome = AccountID2
|
income = AccountID1,
|
||||||
}}
|
outcome = AccountID2
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_business_schedule(business_schedule()) ->
|
-spec construct_business_schedule(business_schedule()) ->
|
||||||
{business_schedule, dmsl_domain_thrift:'BusinessScheduleObject'()}.
|
{business_schedule, dmsl_domain_thrift:'BusinessScheduleObject'()}.
|
||||||
|
|
||||||
construct_business_schedule(Ref) ->
|
construct_business_schedule(Ref) ->
|
||||||
{business_schedule, #domain_BusinessScheduleObject{
|
{business_schedule, #domain_BusinessScheduleObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -284,9 +264,7 @@ construct_business_schedule(Ref) ->
|
|||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec construct_criterion(criterion(), name(), predicate()) ->
|
-spec construct_criterion(criterion(), name(), predicate()) -> {criterion, dmsl_domain_thrift:'CriterionObject'()}.
|
||||||
{criterion, dmsl_domain_thrift:'CriterionObject'()}.
|
|
||||||
|
|
||||||
construct_criterion(Ref, Name, Pred) ->
|
construct_criterion(Ref, Name, Pred) ->
|
||||||
{criterion, #domain_CriterionObject{
|
{criterion, #domain_CriterionObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -298,7 +276,6 @@ construct_criterion(Ref, Name, Pred) ->
|
|||||||
|
|
||||||
-spec construct_term_set_hierarchy(term_set_hierarchy(), term_set_hierarchy(), term_set()) ->
|
-spec construct_term_set_hierarchy(term_set_hierarchy(), term_set_hierarchy(), term_set()) ->
|
||||||
{term_set_hierarchy, dmsl_domain_thrift:'TermSetHierarchyObject'()}.
|
{term_set_hierarchy, dmsl_domain_thrift:'TermSetHierarchyObject'()}.
|
||||||
|
|
||||||
construct_term_set_hierarchy(Ref, ParentRef, TermSet) ->
|
construct_term_set_hierarchy(Ref, ParentRef, TermSet) ->
|
||||||
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
{term_set_hierarchy, #domain_TermSetHierarchyObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
@ -313,10 +290,8 @@ construct_term_set_hierarchy(Ref, ParentRef, TermSet) ->
|
|||||||
}
|
}
|
||||||
}}.
|
}}.
|
||||||
|
|
||||||
|
|
||||||
-spec construct_payment_routing_ruleset(payment_routing_ruleset(), name(), _) ->
|
-spec construct_payment_routing_ruleset(payment_routing_ruleset(), name(), _) ->
|
||||||
dmsl_domain_thrift:'PaymentRoutingRulesetObject'().
|
dmsl_domain_thrift:'PaymentRoutingRulesetObject'().
|
||||||
|
|
||||||
construct_payment_routing_ruleset(Ref, Name, Decisions) ->
|
construct_payment_routing_ruleset(Ref, Name, Decisions) ->
|
||||||
{payment_routing_rules, #domain_PaymentRoutingRulesObject{
|
{payment_routing_rules, #domain_PaymentRoutingRulesObject{
|
||||||
ref = Ref,
|
ref = Ref,
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
-include("pm_ct_domain.hrl").
|
-include("pm_ct_domain.hrl").
|
||||||
-include("pm_ct_json.hrl").
|
-include("pm_ct_json.hrl").
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_base_thrift.hrl").
|
-include_lib("damsel/include/dmsl_base_thrift.hrl").
|
||||||
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
|
||||||
|
|
||||||
@ -44,182 +45,180 @@
|
|||||||
-define(HELLGATE_HOST, "hellgate").
|
-define(HELLGATE_HOST, "hellgate").
|
||||||
-define(HELLGATE_PORT, 8022).
|
-define(HELLGATE_PORT, 8022).
|
||||||
|
|
||||||
|
|
||||||
-type app_name() :: atom().
|
-type app_name() :: atom().
|
||||||
|
|
||||||
-spec start_app(app_name()) -> [app_name()].
|
-spec start_app(app_name()) -> [app_name()].
|
||||||
|
|
||||||
start_app(scoper = AppName) ->
|
start_app(scoper = AppName) ->
|
||||||
{start_app(AppName, [
|
{start_app(AppName, [
|
||||||
{storage, scoper_storage_logger}
|
{storage, scoper_storage_logger}
|
||||||
]), #{}};
|
]), #{}};
|
||||||
|
|
||||||
start_app(woody = AppName) ->
|
start_app(woody = AppName) ->
|
||||||
{start_app(AppName, [
|
{start_app(AppName, [
|
||||||
{acceptors_pool_size, 4}
|
{acceptors_pool_size, 4}
|
||||||
]), #{}};
|
]), #{}};
|
||||||
|
|
||||||
start_app(dmt_client = AppName) ->
|
start_app(dmt_client = AppName) ->
|
||||||
{start_app(AppName, [
|
{start_app(AppName, [
|
||||||
{cache_update_interval, 5000}, % milliseconds
|
% milliseconds
|
||||||
{max_cache_size, #{
|
{cache_update_interval, 5000},
|
||||||
elements => 20,
|
{max_cache_size, #{
|
||||||
memory => 52428800 % 50Mb
|
elements => 20,
|
||||||
}},
|
% 50Mb
|
||||||
{woody_event_handlers, [
|
memory => 52428800
|
||||||
{scoper_woody_event_handler, #{
|
}},
|
||||||
|
{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 => #{
|
event_handler_opts => #{
|
||||||
formatter_opts => #{
|
formatter_opts => #{
|
||||||
max_length => 1000
|
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, #{
|
hellgate_root_url => get_hellgate_url()
|
||||||
'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()
|
|
||||||
}};
|
|
||||||
|
|
||||||
start_app(party_management = AppName) ->
|
start_app(party_management = AppName) ->
|
||||||
{start_app(AppName, [
|
{start_app(AppName, [
|
||||||
{scoper_event_handler_options, #{
|
{scoper_event_handler_options, #{
|
||||||
event_handler_opts => #{
|
event_handler_opts => #{
|
||||||
formatter_opts => #{
|
formatter_opts => #{
|
||||||
max_length => 1000
|
max_length => 1000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}},
|
}},
|
||||||
{services, #{
|
{services, #{
|
||||||
accounter => <<"http://shumway:8022/shumpune">>,
|
accounter => <<"http://shumway:8022/shumpune">>,
|
||||||
automaton => <<"http://machinegun:8022/v1/automaton">>,
|
automaton => <<"http://machinegun:8022/v1/automaton">>,
|
||||||
party_management => #{
|
party_management => #{
|
||||||
url => <<"http://hellgate:8022/v1/processing/partymgmt">>,
|
url => <<"http://hellgate:8022/v1/processing/partymgmt">>,
|
||||||
transport_opts => #{
|
transport_opts => #{
|
||||||
pool => party_management,
|
pool => party_management,
|
||||||
max_connections => 300
|
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(party_client = AppName) ->
|
||||||
{start_app(AppName, [
|
{start_app(AppName, [
|
||||||
{services, #{
|
{services, #{
|
||||||
party_management => "http://hellgate:8022/v1/processing/partymgmt"
|
party_management => "http://hellgate:8022/v1/processing/partymgmt"
|
||||||
}},
|
}},
|
||||||
{woody, #{
|
{woody, #{
|
||||||
cache_mode => safe, % disabled | safe | aggressive
|
% disabled | safe | aggressive
|
||||||
options => #{
|
cache_mode => safe,
|
||||||
woody_client => #{
|
options => #{
|
||||||
event_handler => {scoper_woody_event_handler, #{
|
woody_client => #{
|
||||||
event_handler_opts => #{
|
event_handler =>
|
||||||
formatter_opts => #{
|
{scoper_woody_event_handler, #{
|
||||||
max_length => 1000
|
event_handler_opts => #{
|
||||||
}
|
formatter_opts => #{
|
||||||
}
|
max_length => 1000
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}}
|
]), #{}};
|
||||||
]), #{}};
|
|
||||||
|
|
||||||
start_app(AppName) ->
|
start_app(AppName) ->
|
||||||
{genlib_app:start_application(AppName), #{}}.
|
{genlib_app:start_application(AppName), #{}}.
|
||||||
|
|
||||||
-spec start_app(app_name(), list()) -> [app_name()].
|
-spec start_app(app_name(), list()) -> [app_name()].
|
||||||
|
|
||||||
start_app(cowboy = AppName, Env) ->
|
start_app(cowboy = AppName, Env) ->
|
||||||
#{
|
#{
|
||||||
listener_ref := Ref,
|
listener_ref := Ref,
|
||||||
@ -229,12 +228,10 @@ start_app(cowboy = AppName, Env) ->
|
|||||||
} = Env,
|
} = Env,
|
||||||
cowboy:start_clear(Ref, [{num_acceptors, Count} | TransOpt], ProtoOpt),
|
cowboy:start_clear(Ref, [{num_acceptors, Count} | TransOpt], ProtoOpt),
|
||||||
[AppName];
|
[AppName];
|
||||||
|
|
||||||
start_app(AppName, Env) ->
|
start_app(AppName, Env) ->
|
||||||
genlib_app:start_application_with(AppName, Env).
|
genlib_app:start_application_with(AppName, Env).
|
||||||
|
|
||||||
-spec start_apps([app_name() | {app_name(), list()}]) -> [app_name()].
|
-spec start_apps([app_name() | {app_name(), list()}]) -> [app_name()].
|
||||||
|
|
||||||
start_apps(Apps) ->
|
start_apps(Apps) ->
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun
|
fun
|
||||||
@ -248,31 +245,24 @@ start_apps(Apps) ->
|
|||||||
Apps
|
Apps
|
||||||
).
|
).
|
||||||
|
|
||||||
|
|
||||||
-type config() :: [{atom(), term()}].
|
-type config() :: [{atom(), term()}].
|
||||||
-type test_case_name() :: atom().
|
-type test_case_name() :: atom().
|
||||||
-type group_name() :: atom().
|
-type group_name() :: atom().
|
||||||
|
|
||||||
-spec cfg(atom(), config()) -> term().
|
-spec cfg(atom(), config()) -> term().
|
||||||
|
|
||||||
cfg(Key, Config) ->
|
cfg(Key, Config) ->
|
||||||
case lists:keyfind(Key, 1, Config) of
|
case lists:keyfind(Key, 1, Config) of
|
||||||
{Key, V} -> V;
|
{Key, V} -> V;
|
||||||
_ -> undefined
|
_ -> undefined
|
||||||
end.
|
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(RootUrl, UserID) ->
|
||||||
create_client_w_context(RootUrl, UserID, woody_context:new()).
|
create_client_w_context(RootUrl, UserID, woody_context:new()).
|
||||||
|
|
||||||
-spec create_client(woody:url(), woody_user_identity:id(), woody:trace_id()) ->
|
-spec create_client(woody:url(), woody_user_identity:id(), woody:trace_id()) -> pm_client_api:t().
|
||||||
pm_client_api:t().
|
|
||||||
|
|
||||||
create_client(RootUrl, UserID, TraceID) ->
|
create_client(RootUrl, UserID, TraceID) ->
|
||||||
create_client_w_context(RootUrl, UserID, woody_context:new(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("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
-include_lib("party_management/include/party_events.hrl").
|
-include_lib("party_management/include/party_events.hrl").
|
||||||
|
|
||||||
-type account_id() :: dmsl_domain_thrift:'AccountID'().
|
-type account_id() :: dmsl_domain_thrift:'AccountID'().
|
||||||
-type account() :: map().
|
-type account() :: map().
|
||||||
-type balance() :: map().
|
-type balance() :: map().
|
||||||
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
||||||
-type contract_tpl() :: dmsl_domain_thrift:'ContractTemplateRef'().
|
-type contract_tpl() :: dmsl_domain_thrift:'ContractTemplateRef'().
|
||||||
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
|
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
|
||||||
-type category() :: dmsl_domain_thrift:'CategoryRef'().
|
-type category() :: dmsl_domain_thrift:'CategoryRef'().
|
||||||
-type currency() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
|
-type currency() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
|
||||||
-type payment_institution() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
|
-type payment_institution() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
|
||||||
|
|
||||||
-spec create_party_and_shop(
|
-spec create_party_and_shop(
|
||||||
category(),
|
category(),
|
||||||
@ -303,9 +293,7 @@ make_user_identity(UserID) ->
|
|||||||
contract_tpl(),
|
contract_tpl(),
|
||||||
dmsl_domain_thrift:'PaymentInstitutionRef'(),
|
dmsl_domain_thrift:'PaymentInstitutionRef'(),
|
||||||
Client :: pid()
|
Client :: pid()
|
||||||
) ->
|
) -> shop_id().
|
||||||
shop_id().
|
|
||||||
|
|
||||||
create_party_and_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Client) ->
|
create_party_and_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Client) ->
|
||||||
_ = pm_client_party:create(make_party_params(), Client),
|
_ = pm_client_party:create(make_party_params(), Client),
|
||||||
#domain_Party{} = pm_client_party:get(Client),
|
#domain_Party{} = pm_client_party:get(Client),
|
||||||
@ -324,9 +312,7 @@ make_party_params() ->
|
|||||||
contract_tpl(),
|
contract_tpl(),
|
||||||
payment_institution(),
|
payment_institution(),
|
||||||
Client :: pid()
|
Client :: pid()
|
||||||
) ->
|
) -> shop_id().
|
||||||
shop_id().
|
|
||||||
|
|
||||||
create_battle_ready_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Client) ->
|
create_battle_ready_shop(Category, Currency, TemplateRef, PaymentInstitutionRef, Client) ->
|
||||||
ContractID = pm_utils:unique_id(),
|
ContractID = pm_utils:unique_id(),
|
||||||
ContractParams = make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef),
|
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)},
|
ShopAccountParams = #payproc_ShopAccountParams{currency = ?cur(Currency)},
|
||||||
Changeset = [
|
Changeset = [
|
||||||
{contract_modification, #payproc_ContractModificationUnit{
|
{contract_modification, #payproc_ContractModificationUnit{
|
||||||
id = ContractID,
|
id = ContractID,
|
||||||
modification = {creation, ContractParams}
|
modification = {creation, ContractParams}
|
||||||
}},
|
}},
|
||||||
{contract_modification, #payproc_ContractModificationUnit{
|
{contract_modification, #payproc_ContractModificationUnit{
|
||||||
id = ContractID,
|
id = ContractID,
|
||||||
modification = {payout_tool_modification, #payproc_PayoutToolModificationUnit{
|
modification =
|
||||||
payout_tool_id = PayoutToolID,
|
{payout_tool_modification, #payproc_PayoutToolModificationUnit{
|
||||||
modification = {creation, PayoutToolParams}
|
payout_tool_id = PayoutToolID,
|
||||||
}}
|
modification = {creation, PayoutToolParams}
|
||||||
|
}}
|
||||||
}},
|
}},
|
||||||
?shop_modification(ShopID, {creation, ShopParams}),
|
?shop_modification(ShopID, {creation, ShopParams}),
|
||||||
?shop_modification(ShopID, {shop_account_creation, ShopAccountParams})
|
?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),
|
_Shop = pm_client_party:get_shop(ShopID, Client),
|
||||||
ShopID.
|
ShopID.
|
||||||
|
|
||||||
-spec create_contract(contract_tpl(), payment_institution(), Client :: pid()) ->
|
-spec create_contract(contract_tpl(), payment_institution(), Client :: pid()) -> contract_id().
|
||||||
contract_id().
|
|
||||||
|
|
||||||
create_contract(TemplateRef, PaymentInstitutionRef, Client) ->
|
create_contract(TemplateRef, PaymentInstitutionRef, Client) ->
|
||||||
ContractID = pm_utils:unique_id(),
|
ContractID = pm_utils:unique_id(),
|
||||||
ContractParams = make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef),
|
ContractParams = make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef),
|
||||||
Changeset = [
|
Changeset = [
|
||||||
{contract_modification, #payproc_ContractModificationUnit{
|
{contract_modification, #payproc_ContractModificationUnit{
|
||||||
id = ContractID,
|
id = ContractID,
|
||||||
modification = {creation, ContractParams}
|
modification = {creation, ContractParams}
|
||||||
}}
|
}}
|
||||||
],
|
],
|
||||||
ok = ensure_claim_accepted(pm_client_party:create_claim(Changeset, Client), Client),
|
ok = ensure_claim_accepted(pm_client_party:create_claim(Changeset, Client), Client),
|
||||||
ContractID.
|
ContractID.
|
||||||
|
|
||||||
-spec get_first_contract_id(Client :: pid()) ->
|
-spec get_first_contract_id(Client :: pid()) -> contract_id().
|
||||||
contract_id().
|
|
||||||
|
|
||||||
get_first_contract_id(Client) ->
|
get_first_contract_id(Client) ->
|
||||||
#domain_Party{contracts = Contracts} = pm_client_party:get(Client),
|
#domain_Party{contracts = Contracts} = pm_client_party:get(Client),
|
||||||
lists:min(maps:keys(Contracts)).
|
lists:min(maps:keys(Contracts)).
|
||||||
|
|
||||||
-spec get_first_battle_ready_contract_id(Client :: pid()) ->
|
-spec get_first_battle_ready_contract_id(Client :: pid()) -> contract_id().
|
||||||
contract_id().
|
|
||||||
|
|
||||||
get_first_battle_ready_contract_id(Client) ->
|
get_first_battle_ready_contract_id(Client) ->
|
||||||
#domain_Party{contracts = Contracts} = pm_client_party:get(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
|
case Contract of
|
||||||
#domain_Contract{
|
#domain_Contract{
|
||||||
contractor = {legal_entity, _},
|
contractor = {legal_entity, _},
|
||||||
@ -409,19 +391,26 @@ get_first_battle_ready_contract_id(Client) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec adjust_contract(contract_id(), contract_tpl(), Client :: pid()) -> ok.
|
-spec adjust_contract(contract_id(), contract_tpl(), Client :: pid()) -> ok.
|
||||||
|
|
||||||
adjust_contract(ContractID, TemplateRef, Client) ->
|
adjust_contract(ContractID, TemplateRef, Client) ->
|
||||||
ensure_claim_accepted(pm_client_party:create_claim([
|
ensure_claim_accepted(
|
||||||
{contract_modification, #payproc_ContractModificationUnit{
|
pm_client_party:create_claim(
|
||||||
id = ContractID,
|
[
|
||||||
modification = {adjustment_modification, #payproc_ContractAdjustmentModificationUnit{
|
{contract_modification, #payproc_ContractModificationUnit{
|
||||||
adjustment_id = pm_utils:unique_id(),
|
id = ContractID,
|
||||||
modification = {creation, #payproc_ContractAdjustmentParams{
|
modification =
|
||||||
template = TemplateRef
|
{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) ->
|
ensure_claim_accepted(#payproc_Claim{id = ClaimID, revision = ClaimRevision, status = Status}, Client) ->
|
||||||
case Status of
|
case Status of
|
||||||
@ -432,20 +421,16 @@ ensure_claim_accepted(#payproc_Claim{id = ClaimID, revision = ClaimRevision, sta
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_account(account_id()) -> account().
|
-spec get_account(account_id()) -> account().
|
||||||
|
|
||||||
get_account(AccountID) ->
|
get_account(AccountID) ->
|
||||||
% TODO we sure need to proxy this through the hellgate interfaces
|
% TODO we sure need to proxy this through the hellgate interfaces
|
||||||
pm_accounting:get_account(AccountID).
|
pm_accounting:get_account(AccountID).
|
||||||
|
|
||||||
-spec get_balance(account_id()) -> balance().
|
-spec get_balance(account_id()) -> balance().
|
||||||
|
|
||||||
get_balance(AccountID) ->
|
get_balance(AccountID) ->
|
||||||
% TODO we sure need to proxy this through the hellgate interfaces
|
% TODO we sure need to proxy this through the hellgate interfaces
|
||||||
pm_accounting:get_balance(AccountID).
|
pm_accounting:get_balance(AccountID).
|
||||||
|
|
||||||
-spec get_first_payout_tool_id(contract_id(), Client :: pid()) ->
|
-spec get_first_payout_tool_id(contract_id(), Client :: pid()) -> dmsl_domain_thrift:'PayoutToolID'().
|
||||||
dmsl_domain_thrift:'PayoutToolID'().
|
|
||||||
|
|
||||||
get_first_payout_tool_id(ContractID, Client) ->
|
get_first_payout_tool_id(ContractID, Client) ->
|
||||||
#domain_Contract{payout_tools = PayoutTools} = pm_client_party:get_contract(ContractID, Client),
|
#domain_Contract{payout_tools = PayoutTools} = pm_client_party:get_contract(ContractID, Client),
|
||||||
case PayoutTools of
|
case PayoutTools of
|
||||||
@ -458,9 +443,7 @@ get_first_payout_tool_id(ContractID, Client) ->
|
|||||||
-spec make_battle_ready_contract_params(
|
-spec make_battle_ready_contract_params(
|
||||||
dmsl_domain_thrift:'ContractTemplateRef'() | undefined,
|
dmsl_domain_thrift:'ContractTemplateRef'() | undefined,
|
||||||
dmsl_domain_thrift:'PaymentInstitutionRef'()
|
dmsl_domain_thrift:'PaymentInstitutionRef'()
|
||||||
) ->
|
) -> dmsl_payment_processing_thrift:'ContractParams'().
|
||||||
dmsl_payment_processing_thrift:'ContractParams'().
|
|
||||||
|
|
||||||
make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef) ->
|
make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef) ->
|
||||||
#payproc_ContractParams{
|
#payproc_ContractParams{
|
||||||
contractor = make_battle_ready_contractor(),
|
contractor = make_battle_ready_contractor(),
|
||||||
@ -468,9 +451,7 @@ make_battle_ready_contract_params(TemplateRef, PaymentInstitutionRef) ->
|
|||||||
payment_institution = PaymentInstitutionRef
|
payment_institution = PaymentInstitutionRef
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec make_battle_ready_contractor() ->
|
-spec make_battle_ready_contractor() -> dmsl_payment_processing_thrift:'Contractor'().
|
||||||
dmsl_payment_processing_thrift:'Contractor'().
|
|
||||||
|
|
||||||
make_battle_ready_contractor() ->
|
make_battle_ready_contractor() ->
|
||||||
BankAccount = #domain_RussianBankAccount{
|
BankAccount = #domain_RussianBankAccount{
|
||||||
account = <<"4276300010908312893">>,
|
account = <<"4276300010908312893">>,
|
||||||
@ -479,7 +460,7 @@ make_battle_ready_contractor() ->
|
|||||||
bank_bik = <<"66642666">>
|
bank_bik = <<"66642666">>
|
||||||
},
|
},
|
||||||
{legal_entity,
|
{legal_entity,
|
||||||
{russian_legal_entity, #domain_RussianLegalEntity {
|
{russian_legal_entity, #domain_RussianLegalEntity{
|
||||||
registered_name = <<"Hoofs & Horns OJSC">>,
|
registered_name = <<"Hoofs & Horns OJSC">>,
|
||||||
registered_number = <<"1234509876">>,
|
registered_number = <<"1234509876">>,
|
||||||
inn = <<"1213456789012">>,
|
inn = <<"1213456789012">>,
|
||||||
@ -489,50 +470,41 @@ make_battle_ready_contractor() ->
|
|||||||
representative_full_name = <<"Someone">>,
|
representative_full_name = <<"Someone">>,
|
||||||
representative_document = <<"100$ banknote">>,
|
representative_document = <<"100$ banknote">>,
|
||||||
russian_bank_account = BankAccount
|
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() ->
|
make_battle_ready_payout_tool_params() ->
|
||||||
#payproc_PayoutToolParams{
|
#payproc_PayoutToolParams{
|
||||||
currency = ?cur(<<"RUB">>),
|
currency = ?cur(<<"RUB">>),
|
||||||
tool_info = {russian_bank_account, #domain_RussianBankAccount{
|
tool_info =
|
||||||
account = <<"4276300010908312893">>,
|
{russian_bank_account, #domain_RussianBankAccount{
|
||||||
bank_name = <<"SomeBank">>,
|
account = <<"4276300010908312893">>,
|
||||||
bank_post_account = <<"123129876">>,
|
bank_name = <<"SomeBank">>,
|
||||||
bank_bik = <<"66642666">>
|
bank_post_account = <<"123129876">>,
|
||||||
}}
|
bank_bik = <<"66642666">>
|
||||||
|
}}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec make_shop_details(binary()) ->
|
-spec make_shop_details(binary()) -> dmsl_domain_thrift:'ShopDetails'().
|
||||||
dmsl_domain_thrift:'ShopDetails'().
|
|
||||||
|
|
||||||
make_shop_details(Name) ->
|
make_shop_details(Name) ->
|
||||||
make_shop_details(Name, undefined).
|
make_shop_details(Name, undefined).
|
||||||
|
|
||||||
-spec make_shop_details(binary(), binary()) ->
|
-spec make_shop_details(binary(), binary()) -> dmsl_domain_thrift:'ShopDetails'().
|
||||||
dmsl_domain_thrift:'ShopDetails'().
|
|
||||||
|
|
||||||
make_shop_details(Name, Description) ->
|
make_shop_details(Name, Description) ->
|
||||||
#domain_ShopDetails{
|
#domain_ShopDetails{
|
||||||
name = Name,
|
name = Name,
|
||||||
description = Description
|
description = Description
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec make_meta_ns() -> dmsl_domain_thrift:'PartyMetaNamespace'().
|
-spec make_meta_ns() -> dmsl_domain_thrift:'PartyMetaNamespace'().
|
||||||
|
|
||||||
make_meta_ns() ->
|
make_meta_ns() ->
|
||||||
list_to_binary(lists:concat(["NS-", erlang:system_time()])).
|
list_to_binary(lists:concat(["NS-", erlang:system_time()])).
|
||||||
|
|
||||||
-spec make_meta_data() -> dmsl_domain_thrift:'PartyMetaData'().
|
-spec make_meta_data() -> dmsl_domain_thrift:'PartyMetaData'().
|
||||||
|
|
||||||
make_meta_data() ->
|
make_meta_data() ->
|
||||||
make_meta_data(<<"NS-0">>).
|
make_meta_data(<<"NS-0">>).
|
||||||
|
|
||||||
-spec make_meta_data(dmsl_domain_thrift:'PartyMetaNamespace'()) -> dmsl_domain_thrift:'PartyMetaData'().
|
-spec make_meta_data(dmsl_domain_thrift:'PartyMetaNamespace'()) -> dmsl_domain_thrift:'PartyMetaData'().
|
||||||
|
|
||||||
make_meta_data(NS) ->
|
make_meta_data(NS) ->
|
||||||
{obj, #{
|
{obj, #{
|
||||||
{str, <<"NS">>} => {str, NS},
|
{str, <<"NS">>} => {str, NS},
|
||||||
@ -541,6 +513,5 @@ make_meta_data(NS) ->
|
|||||||
}}.
|
}}.
|
||||||
|
|
||||||
-spec get_hellgate_url() -> string().
|
-spec get_hellgate_url() -> string().
|
||||||
|
|
||||||
get_hellgate_url() ->
|
get_hellgate_url() ->
|
||||||
"http://" ++ ?HELLGATE_HOST ++ ":" ++ integer_to_list(?HELLGATE_PORT).
|
"http://" ++ ?HELLGATE_HOST ++ ":" ++ integer_to_list(?HELLGATE_PORT).
|
||||||
|
@ -5,4 +5,4 @@
|
|||||||
|
|
||||||
-define(null(), {nl, #json_Null{}}).
|
-define(null(), {nl, #json_Null{}}).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -11,21 +11,17 @@
|
|||||||
-type t() :: {woody:url(), woody_context:ctx()}.
|
-type t() :: {woody:url(), woody_context:ctx()}.
|
||||||
|
|
||||||
-spec new(woody:url()) -> t().
|
-spec new(woody:url()) -> t().
|
||||||
|
|
||||||
new(RootUrl) ->
|
new(RootUrl) ->
|
||||||
new(RootUrl, construct_context()).
|
new(RootUrl, construct_context()).
|
||||||
|
|
||||||
-spec new(woody:url(), woody_context:ctx()) -> t().
|
-spec new(woody:url(), woody_context:ctx()) -> t().
|
||||||
|
|
||||||
new(RootUrl, Context) ->
|
new(RootUrl, Context) ->
|
||||||
{RootUrl, Context}.
|
{RootUrl, Context}.
|
||||||
|
|
||||||
construct_context() ->
|
construct_context() ->
|
||||||
woody_context:new().
|
woody_context:new().
|
||||||
|
|
||||||
-spec call(Name :: atom(), woody:func(), [any()], t()) ->
|
-spec call(Name :: atom(), woody:func(), [any()], t()) -> {{ok, _Response} | {exception, _} | {error, _}, t()}.
|
||||||
{{ok, _Response} | {exception, _} | {error, _}, t()}.
|
|
||||||
|
|
||||||
call(ServiceName, Function, Args, {RootUrl, Context}) ->
|
call(ServiceName, Function, Args, {RootUrl, Context}) ->
|
||||||
Service = pm_proto:get_service(ServiceName),
|
Service = pm_proto:get_service(ServiceName),
|
||||||
ArgsTuple = list_to_tuple(Args),
|
ArgsTuple = list_to_tuple(Args),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-module(pm_client_event_poller).
|
-module(pm_client_event_poller).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([new/2]).
|
-export([new/2]).
|
||||||
@ -13,8 +14,8 @@
|
|||||||
-type rpc() :: {Name :: atom(), woody:func(), [_]}.
|
-type rpc() :: {Name :: atom(), woody:func(), [_]}.
|
||||||
|
|
||||||
-opaque st(Event) :: #{
|
-opaque st(Event) :: #{
|
||||||
rpc := rpc(),
|
rpc := rpc(),
|
||||||
get_event_id := get_event_id(Event),
|
get_event_id := get_event_id(Event),
|
||||||
last_event_id => integer()
|
last_event_id => integer()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
@ -22,18 +23,15 @@
|
|||||||
|
|
||||||
-define(POLL_INTERVAL, 1000).
|
-define(POLL_INTERVAL, 1000).
|
||||||
|
|
||||||
-spec new(rpc(), get_event_id(Event)) ->
|
-spec new(rpc(), get_event_id(Event)) -> st(Event).
|
||||||
st(Event).
|
|
||||||
|
|
||||||
new(RPC, GetEventID) ->
|
new(RPC, GetEventID) ->
|
||||||
#{
|
#{
|
||||||
rpc => RPC,
|
rpc => RPC,
|
||||||
get_event_id => GetEventID
|
get_event_id => GetEventID
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-spec poll(pos_integer(), non_neg_integer(), pm_client_api:t(), st(Event)) ->
|
-spec poll(pos_integer(), non_neg_integer(), pm_client_api:t(), st(Event)) ->
|
||||||
{[Event] | {exception | error, _}, 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) ->
|
||||||
poll(N, Timeout, [], Client, St).
|
poll(N, Timeout, [], Client, St).
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-module(pm_client_party).
|
-module(pm_client_party).
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([start/2]).
|
-export([start/2]).
|
||||||
@ -54,6 +55,7 @@
|
|||||||
%% GenServer
|
%% GenServer
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
-export([init/1]).
|
-export([init/1]).
|
||||||
-export([handle_call/3]).
|
-export([handle_call/3]).
|
||||||
-export([handle_cast/2]).
|
-export([handle_cast/2]).
|
||||||
@ -63,43 +65,40 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
|
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
|
||||||
-type party_id() :: dmsl_domain_thrift:'PartyID'().
|
-type party_id() :: dmsl_domain_thrift:'PartyID'().
|
||||||
-type party_params() :: dmsl_payment_processing_thrift:'PartyParams'().
|
-type party_params() :: dmsl_payment_processing_thrift:'PartyParams'().
|
||||||
-type domain_revision() :: dmsl_domain_thrift:'DataRevision'().
|
-type domain_revision() :: dmsl_domain_thrift:'DataRevision'().
|
||||||
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
-type contract_id() :: dmsl_domain_thrift:'ContractID'().
|
||||||
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
|
-type shop_id() :: dmsl_domain_thrift:'ShopID'().
|
||||||
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
|
-type claim_id() :: dmsl_payment_processing_thrift:'ClaimID'().
|
||||||
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
|
-type claim() :: dmsl_payment_processing_thrift:'Claim'().
|
||||||
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
|
-type claim_revision() :: dmsl_payment_processing_thrift:'ClaimRevision'().
|
||||||
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
|
-type changeset() :: dmsl_payment_processing_thrift:'PartyChangeset'().
|
||||||
-type shop_account_id() :: dmsl_domain_thrift:'AccountID'().
|
-type shop_account_id() :: dmsl_domain_thrift:'AccountID'().
|
||||||
-type meta() :: dmsl_domain_thrift:'PartyMeta'().
|
-type meta() :: dmsl_domain_thrift:'PartyMeta'().
|
||||||
-type meta_ns() :: dmsl_domain_thrift:'PartyMetaNamespace'().
|
-type meta_ns() :: dmsl_domain_thrift:'PartyMetaNamespace'().
|
||||||
-type meta_data() :: dmsl_domain_thrift:'PartyMetaData'().
|
-type meta_data() :: dmsl_domain_thrift:'PartyMetaData'().
|
||||||
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
|
-type timestamp() :: dmsl_base_thrift:'Timestamp'().
|
||||||
|
|
||||||
-type party_revision_param() :: dmsl_payment_processing_thrift:'PartyRevisionParam'().
|
-type party_revision_param() :: dmsl_payment_processing_thrift:'PartyRevisionParam'().
|
||||||
-type payment_intitution_ref() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
|
-type payment_intitution_ref() :: dmsl_domain_thrift:'PaymentInstitutionRef'().
|
||||||
-type varset() :: dmsl_payment_processing_thrift:'Varset'().
|
-type varset() :: dmsl_payment_processing_thrift:'Varset'().
|
||||||
|
|
||||||
-type provider_ref() :: dmsl_domain_thrift:'ProviderRef'().
|
-type provider_ref() :: dmsl_domain_thrift:'ProviderRef'().
|
||||||
-type terminal_ref() :: dmsl_domain_thrift:'TerminalRef'().
|
-type terminal_ref() :: dmsl_domain_thrift:'TerminalRef'().
|
||||||
-type globals_ref() :: dmsl_domain_thrift:'GlobalsRef'().
|
-type globals_ref() :: dmsl_domain_thrift:'GlobalsRef'().
|
||||||
-type payment_routring_ruleset_ref() :: dmsl_domain_thrift:'PaymentRoutingRulesetRef'().
|
-type payment_routring_ruleset_ref() :: dmsl_domain_thrift:'PaymentRoutingRulesetRef'().
|
||||||
|
|
||||||
-spec start(party_id(), pm_client_api:t()) -> pid().
|
-spec start(party_id(), pm_client_api:t()) -> pid().
|
||||||
|
|
||||||
start(PartyID, ApiClient) ->
|
start(PartyID, ApiClient) ->
|
||||||
start(start, undefined, PartyID, ApiClient).
|
start(start, undefined, PartyID, ApiClient).
|
||||||
|
|
||||||
-spec start(user_info(), party_id(), pm_client_api:t()) -> pid().
|
-spec start(user_info(), party_id(), pm_client_api:t()) -> pid().
|
||||||
|
|
||||||
start(UserInfo, PartyID, ApiClient) ->
|
start(UserInfo, PartyID, ApiClient) ->
|
||||||
start(start, UserInfo, PartyID, ApiClient).
|
start(start, UserInfo, PartyID, ApiClient).
|
||||||
|
|
||||||
-spec start_link(party_id(), pm_client_api:t()) -> pid().
|
-spec start_link(party_id(), pm_client_api:t()) -> pid().
|
||||||
|
|
||||||
start_link(PartyID, ApiClient) ->
|
start_link(PartyID, ApiClient) ->
|
||||||
start(start_link, undefined, PartyID, ApiClient).
|
start(start_link, undefined, PartyID, ApiClient).
|
||||||
|
|
||||||
@ -108,212 +107,152 @@ start(Mode, UserInfo, PartyID, ApiClient) ->
|
|||||||
Pid.
|
Pid.
|
||||||
|
|
||||||
-spec stop(pid()) -> ok.
|
-spec stop(pid()) -> ok.
|
||||||
|
|
||||||
stop(Client) ->
|
stop(Client) ->
|
||||||
_ = exit(Client, shutdown),
|
_ = exit(Client, shutdown),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec create(party_params(), pid()) ->
|
-spec create(party_params(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
create(PartyParams, Client) ->
|
create(PartyParams, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Create', [PartyParams]})).
|
map_result_error(gen_server:call(Client, {call, 'Create', [PartyParams]})).
|
||||||
|
|
||||||
-spec get(pid()) ->
|
-spec get(pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'Party'() | woody_error:business_error().
|
|
||||||
|
|
||||||
get(Client) ->
|
get(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Get', []})).
|
map_result_error(gen_server:call(Client, {call, 'Get', []})).
|
||||||
|
|
||||||
-spec get_revision(pid()) ->
|
-spec get_revision(pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'Party'() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_revision(Client) ->
|
get_revision(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetRevision', []})).
|
map_result_error(gen_server:call(Client, {call, 'GetRevision', []})).
|
||||||
|
|
||||||
-spec get_status(pid()) ->
|
-spec get_status(pid()) -> dmsl_domain_thrift:'PartyStatus'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'PartyStatus'() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_status(Client) ->
|
get_status(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetStatus', []})).
|
map_result_error(gen_server:call(Client, {call, 'GetStatus', []})).
|
||||||
|
|
||||||
-spec checkout(party_revision_param(), pid()) ->
|
-spec checkout(party_revision_param(), pid()) -> dmsl_domain_thrift:'Party'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'Party'() | woody_error:business_error().
|
|
||||||
|
|
||||||
checkout(PartyRevisionParam, Client) ->
|
checkout(PartyRevisionParam, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Checkout', [PartyRevisionParam]})).
|
map_result_error(gen_server:call(Client, {call, 'Checkout', [PartyRevisionParam]})).
|
||||||
|
|
||||||
-spec block(binary(), pid()) ->
|
-spec block(binary(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
block(Reason, Client) ->
|
block(Reason, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Block', [Reason]})).
|
map_result_error(gen_server:call(Client, {call, 'Block', [Reason]})).
|
||||||
|
|
||||||
-spec unblock(binary(), pid()) ->
|
-spec unblock(binary(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
unblock(Reason, Client) ->
|
unblock(Reason, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Unblock', [Reason]})).
|
map_result_error(gen_server:call(Client, {call, 'Unblock', [Reason]})).
|
||||||
|
|
||||||
-spec suspend(pid()) ->
|
-spec suspend(pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
suspend(Client) ->
|
suspend(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Suspend', []})).
|
map_result_error(gen_server:call(Client, {call, 'Suspend', []})).
|
||||||
|
|
||||||
-spec activate(pid()) ->
|
-spec activate(pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
activate(Client) ->
|
activate(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'Activate', []})).
|
map_result_error(gen_server:call(Client, {call, 'Activate', []})).
|
||||||
|
|
||||||
-spec get_meta(pid()) ->
|
-spec get_meta(pid()) -> meta() | woody_error:business_error().
|
||||||
meta() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_meta(Client) ->
|
get_meta(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetMeta', []})).
|
map_result_error(gen_server:call(Client, {call, 'GetMeta', []})).
|
||||||
|
|
||||||
-spec get_metadata(meta_ns(), pid()) ->
|
-spec get_metadata(meta_ns(), pid()) -> meta_data() | woody_error:business_error().
|
||||||
meta_data() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_metadata(NS, Client) ->
|
get_metadata(NS, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetMetaData', [NS]})).
|
map_result_error(gen_server:call(Client, {call, 'GetMetaData', [NS]})).
|
||||||
|
|
||||||
-spec set_metadata(meta_ns(), meta_data(), pid()) ->
|
-spec set_metadata(meta_ns(), meta_data(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
set_metadata(NS, Data, Client) ->
|
set_metadata(NS, Data, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'SetMetaData', [NS, Data]})).
|
map_result_error(gen_server:call(Client, {call, 'SetMetaData', [NS, Data]})).
|
||||||
|
|
||||||
-spec remove_metadata(meta_ns(), pid()) ->
|
-spec remove_metadata(meta_ns(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
remove_metadata(NS, Client) ->
|
remove_metadata(NS, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'RemoveMetaData', [NS]})).
|
map_result_error(gen_server:call(Client, {call, 'RemoveMetaData', [NS]})).
|
||||||
|
|
||||||
-spec get_contract(contract_id(), pid()) ->
|
-spec get_contract(contract_id(), pid()) -> dmsl_domain_thrift:'Contract'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'Contract'() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_contract(ID, Client) ->
|
get_contract(ID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetContract', [ID]})).
|
map_result_error(gen_server:call(Client, {call, 'GetContract', [ID]})).
|
||||||
|
|
||||||
-spec compute_contract_terms(contract_id(), timestamp(), party_revision_param(), domain_revision(), varset(), pid()) ->
|
-spec compute_contract_terms(contract_id(), timestamp(), party_revision_param(), domain_revision(), varset(), pid()) ->
|
||||||
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
|
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_contract_terms(ID, Timestamp, PartyRevision, DomainRevision, Varset, Client) ->
|
compute_contract_terms(ID, Timestamp, PartyRevision, DomainRevision, Varset, Client) ->
|
||||||
Args = [ID, Timestamp, PartyRevision, DomainRevision, Varset],
|
Args = [ID, Timestamp, PartyRevision, DomainRevision, Varset],
|
||||||
map_result_error(gen_server:call(Client, {call, 'ComputeContractTerms', Args})).
|
map_result_error(gen_server:call(Client, {call, 'ComputeContractTerms', Args})).
|
||||||
|
|
||||||
-spec compute_payment_institution_terms(payment_intitution_ref(), varset(), pid()) ->
|
-spec compute_payment_institution_terms(payment_intitution_ref(), varset(), pid()) ->
|
||||||
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
|
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_payment_institution_terms(Ref, Varset, Client) ->
|
compute_payment_institution_terms(Ref, Varset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call_without_party, 'ComputePaymentInstitutionTerms', [Ref, Varset]})).
|
map_result_error(gen_server:call(Client, {call_without_party, 'ComputePaymentInstitutionTerms', [Ref, Varset]})).
|
||||||
|
|
||||||
-spec compute_payout_cash_flow(dmsl_payment_processing_thrift:'PayoutParams'(), pid()) ->
|
-spec compute_payout_cash_flow(dmsl_payment_processing_thrift:'PayoutParams'(), pid()) ->
|
||||||
dmsl_domain_thrift:'FinalCashFlow'() | woody_error:business_error().
|
dmsl_domain_thrift:'FinalCashFlow'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_payout_cash_flow(Params, Client) ->
|
compute_payout_cash_flow(Params, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'ComputePayoutCashFlow', [Params]})).
|
map_result_error(gen_server:call(Client, {call, 'ComputePayoutCashFlow', [Params]})).
|
||||||
|
|
||||||
-spec get_shop(shop_id(), pid()) ->
|
-spec get_shop(shop_id(), pid()) -> dmsl_domain_thrift:'Shop'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'Shop'() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_shop(ID, Client) ->
|
get_shop(ID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetShop', [ID]})).
|
map_result_error(gen_server:call(Client, {call, 'GetShop', [ID]})).
|
||||||
|
|
||||||
-spec block_shop(shop_id(), binary(), pid()) ->
|
-spec block_shop(shop_id(), binary(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
block_shop(ID, Reason, Client) ->
|
block_shop(ID, Reason, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'BlockShop', [ID, Reason]})).
|
map_result_error(gen_server:call(Client, {call, 'BlockShop', [ID, Reason]})).
|
||||||
|
|
||||||
-spec unblock_shop(shop_id(), binary(), pid()) ->
|
-spec unblock_shop(shop_id(), binary(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
unblock_shop(ID, Reason, Client) ->
|
unblock_shop(ID, Reason, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'UnblockShop', [ID, Reason]})).
|
map_result_error(gen_server:call(Client, {call, 'UnblockShop', [ID, Reason]})).
|
||||||
|
|
||||||
-spec suspend_shop(shop_id(), pid()) ->
|
-spec suspend_shop(shop_id(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
suspend_shop(ID, Client) ->
|
suspend_shop(ID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'SuspendShop', [ID]})).
|
map_result_error(gen_server:call(Client, {call, 'SuspendShop', [ID]})).
|
||||||
|
|
||||||
-spec activate_shop(shop_id(), pid()) ->
|
-spec activate_shop(shop_id(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
activate_shop(ID, Client) ->
|
activate_shop(ID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'ActivateShop', [ID]})).
|
map_result_error(gen_server:call(Client, {call, 'ActivateShop', [ID]})).
|
||||||
|
|
||||||
-spec compute_shop_terms(shop_id(), timestamp(), party_revision_param(), pid()) ->
|
-spec compute_shop_terms(shop_id(), timestamp(), party_revision_param(), pid()) ->
|
||||||
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
|
dmsl_domain_thrift:'TermSet'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_shop_terms(ID, Timestamp, PartyRevision, Client) ->
|
compute_shop_terms(ID, Timestamp, PartyRevision, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'ComputeShopTerms', [ID, Timestamp, PartyRevision]})).
|
map_result_error(gen_server:call(Client, {call, 'ComputeShopTerms', [ID, Timestamp, PartyRevision]})).
|
||||||
|
|
||||||
-spec get_claim(claim_id(), pid()) ->
|
-spec get_claim(claim_id(), pid()) -> claim() | woody_error:business_error().
|
||||||
claim() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_claim(ID, Client) ->
|
get_claim(ID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetClaim', [ID]})).
|
map_result_error(gen_server:call(Client, {call, 'GetClaim', [ID]})).
|
||||||
|
|
||||||
-spec get_claims(pid()) ->
|
-spec get_claims(pid()) -> [claim()] | woody_error:business_error().
|
||||||
[claim()] | woody_error:business_error().
|
|
||||||
|
|
||||||
get_claims(Client) ->
|
get_claims(Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetClaims', []})).
|
map_result_error(gen_server:call(Client, {call, 'GetClaims', []})).
|
||||||
|
|
||||||
-spec create_claim(changeset(), pid()) ->
|
-spec create_claim(changeset(), pid()) -> claim() | woody_error:business_error().
|
||||||
claim() | woody_error:business_error().
|
|
||||||
|
|
||||||
create_claim(Changeset, Client) ->
|
create_claim(Changeset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'CreateClaim', [Changeset]})).
|
map_result_error(gen_server:call(Client, {call, 'CreateClaim', [Changeset]})).
|
||||||
|
|
||||||
-spec update_claim(claim_id(), claim_revision(), changeset(), pid()) ->
|
-spec update_claim(claim_id(), claim_revision(), changeset(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
update_claim(ID, Revision, Changeset, Client) ->
|
update_claim(ID, Revision, Changeset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'UpdateClaim', [ID, Revision, Changeset]})).
|
map_result_error(gen_server:call(Client, {call, 'UpdateClaim', [ID, Revision, Changeset]})).
|
||||||
|
|
||||||
-spec accept_claim(claim_id(), claim_revision(), pid()) ->
|
-spec accept_claim(claim_id(), claim_revision(), pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
accept_claim(ID, Revision, Client) ->
|
accept_claim(ID, Revision, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'AcceptClaim', [ID, Revision]})).
|
map_result_error(gen_server:call(Client, {call, 'AcceptClaim', [ID, Revision]})).
|
||||||
|
|
||||||
-spec deny_claim(claim_id(), claim_revision(), binary() | undefined, pid()) ->
|
-spec deny_claim(claim_id(), claim_revision(), binary() | undefined, pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
deny_claim(ID, Revision, Reason, Client) ->
|
deny_claim(ID, Revision, Reason, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'DenyClaim', [ID, Revision, Reason]})).
|
map_result_error(gen_server:call(Client, {call, 'DenyClaim', [ID, Revision, Reason]})).
|
||||||
|
|
||||||
-spec revoke_claim(claim_id(), claim_revision(), binary() | undefined, pid()) ->
|
-spec revoke_claim(claim_id(), claim_revision(), binary() | undefined, pid()) -> ok | woody_error:business_error().
|
||||||
ok | woody_error:business_error().
|
|
||||||
|
|
||||||
revoke_claim(ID, Revision, Reason, Client) ->
|
revoke_claim(ID, Revision, Reason, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'RevokeClaim', [ID, Revision, Reason]})).
|
map_result_error(gen_server:call(Client, {call, 'RevokeClaim', [ID, Revision, Reason]})).
|
||||||
|
|
||||||
-spec get_account_state(shop_account_id(), pid()) ->
|
-spec get_account_state(shop_account_id(), pid()) ->
|
||||||
dmsl_payment_processing_thrift:'AccountState'() | woody_error:business_error().
|
dmsl_payment_processing_thrift:'AccountState'() | woody_error:business_error().
|
||||||
|
|
||||||
get_account_state(AccountID, Client) ->
|
get_account_state(AccountID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetAccountState', [AccountID]})).
|
map_result_error(gen_server:call(Client, {call, 'GetAccountState', [AccountID]})).
|
||||||
|
|
||||||
-spec get_shop_account(shop_id(), pid()) ->
|
-spec get_shop_account(shop_id(), pid()) -> dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error().
|
||||||
dmsl_domain_thrift:'ShopAccount'() | woody_error:business_error().
|
|
||||||
|
|
||||||
get_shop_account(ShopID, Client) ->
|
get_shop_account(ShopID, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call, 'GetShopAccount', [ShopID]})).
|
map_result_error(gen_server:call(Client, {call, 'GetShopAccount', [ShopID]})).
|
||||||
|
|
||||||
-spec compute_provider(provider_ref(), domain_revision(), varset(), pid()) ->
|
-spec compute_provider(provider_ref(), domain_revision(), varset(), pid()) ->
|
||||||
dmsl_domain_thrift:'Provider'() | woody_error:business_error().
|
dmsl_domain_thrift:'Provider'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_provider(PaymentProviderRef, Revision, Varset, Client) ->
|
compute_provider(PaymentProviderRef, Revision, Varset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeProvider',
|
map_result_error(
|
||||||
[PaymentProviderRef, Revision, Varset]})).
|
gen_server:call(Client, {call_without_party, 'ComputeProvider', [PaymentProviderRef, Revision, Varset]})
|
||||||
|
).
|
||||||
|
|
||||||
-spec compute_provider_terminal_terms(
|
-spec compute_provider_terminal_terms(
|
||||||
provider_ref(),
|
provider_ref(),
|
||||||
@ -322,36 +261,36 @@ compute_provider(PaymentProviderRef, Revision, Varset, Client) ->
|
|||||||
varset(),
|
varset(),
|
||||||
pid()
|
pid()
|
||||||
) -> dmsl_domain_thrift:'ProvisionTermSet'() | woody_error:business_error().
|
) -> dmsl_domain_thrift:'ProvisionTermSet'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_provider_terminal_terms(PaymentProviderRef, TerminalRef, Revision, Varset, Client) ->
|
compute_provider_terminal_terms(PaymentProviderRef, TerminalRef, Revision, Varset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeProviderTerminalTerms',
|
map_result_error(
|
||||||
[PaymentProviderRef, TerminalRef, Revision, Varset]})).
|
gen_server:call(
|
||||||
|
Client,
|
||||||
|
{call_without_party, 'ComputeProviderTerminalTerms', [PaymentProviderRef, TerminalRef, Revision, Varset]}
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
-spec compute_globals(globals_ref(), domain_revision(), varset(), pid()) ->
|
-spec compute_globals(globals_ref(), domain_revision(), varset(), pid()) ->
|
||||||
dmsl_domain_thrift:'Globals'() | woody_error:business_error().
|
dmsl_domain_thrift:'Globals'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_globals(GlobalsRef, Revision, Varset, Client) ->
|
compute_globals(GlobalsRef, Revision, Varset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeGlobals',
|
map_result_error(gen_server:call(Client, {call_without_party, 'ComputeGlobals', [GlobalsRef, Revision, Varset]})).
|
||||||
[GlobalsRef, Revision, Varset]})).
|
|
||||||
|
|
||||||
-spec compute_payment_routing_ruleset(payment_routring_ruleset_ref(), domain_revision(), varset(), pid()) ->
|
-spec compute_payment_routing_ruleset(payment_routring_ruleset_ref(), domain_revision(), varset(), pid()) ->
|
||||||
dmsl_domain_thrift:'PaymentRoutingRuleset'() | woody_error:business_error().
|
dmsl_domain_thrift:'PaymentRoutingRuleset'() | woody_error:business_error().
|
||||||
|
|
||||||
compute_payment_routing_ruleset(PaymentRoutingRuleSetRef, Revision, Varset, Client) ->
|
compute_payment_routing_ruleset(PaymentRoutingRuleSetRef, Revision, Varset, Client) ->
|
||||||
map_result_error(gen_server:call(Client, {call_without_party, 'ComputePaymentRoutingRuleset',
|
map_result_error(
|
||||||
[PaymentRoutingRuleSetRef, Revision, Varset]})).
|
gen_server:call(
|
||||||
|
Client,
|
||||||
|
{call_without_party, 'ComputePaymentRoutingRuleset', [PaymentRoutingRuleSetRef, Revision, Varset]}
|
||||||
|
)
|
||||||
|
).
|
||||||
|
|
||||||
-define(DEFAULT_NEXT_EVENT_TIMEOUT, 5000).
|
-define(DEFAULT_NEXT_EVENT_TIMEOUT, 5000).
|
||||||
|
|
||||||
-spec pull_event(pid()) ->
|
-spec pull_event(pid()) -> tuple() | timeout | woody_error:business_error().
|
||||||
tuple() | timeout | woody_error:business_error().
|
|
||||||
|
|
||||||
pull_event(Client) ->
|
pull_event(Client) ->
|
||||||
pull_event(?DEFAULT_NEXT_EVENT_TIMEOUT, Client).
|
pull_event(?DEFAULT_NEXT_EVENT_TIMEOUT, Client).
|
||||||
|
|
||||||
-spec pull_event(timeout(), pid()) ->
|
-spec pull_event(timeout(), pid()) -> tuple() | timeout | woody_error:business_error().
|
||||||
tuple() | timeout | woody_error:business_error().
|
|
||||||
|
|
||||||
pull_event(Timeout, Client) ->
|
pull_event(Timeout, Client) ->
|
||||||
gen_server:call(Client, {pull_event, Timeout}, infinity).
|
gen_server:call(Client, {pull_event, Timeout}, infinity).
|
||||||
|
|
||||||
@ -368,17 +307,15 @@ map_result_error({error, Error}) ->
|
|||||||
|
|
||||||
-record(st, {
|
-record(st, {
|
||||||
user_info :: user_info(),
|
user_info :: user_info(),
|
||||||
party_id :: party_id(),
|
party_id :: party_id(),
|
||||||
poller :: pm_client_event_poller:st(event()),
|
poller :: pm_client_event_poller:st(event()),
|
||||||
client :: pm_client_api:t()
|
client :: pm_client_api:t()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type st() :: #st{}.
|
-type st() :: #st{}.
|
||||||
-type callref() :: {pid(), Tag :: reference()}.
|
-type callref() :: {pid(), Tag :: reference()}.
|
||||||
|
|
||||||
-spec init({user_info(), party_id(), pm_client_api:t()}) ->
|
-spec init({user_info(), party_id(), pm_client_api:t()}) -> {ok, st()}.
|
||||||
{ok, st()}.
|
|
||||||
|
|
||||||
init({UserInfo, PartyID, ApiClient}) ->
|
init({UserInfo, PartyID, ApiClient}) ->
|
||||||
{ok, #st{
|
{ok, #st{
|
||||||
user_info = UserInfo,
|
user_info = UserInfo,
|
||||||
@ -386,23 +323,19 @@ init({UserInfo, PartyID, ApiClient}) ->
|
|||||||
client = ApiClient,
|
client = ApiClient,
|
||||||
poller = pm_client_event_poller:new(
|
poller = pm_client_event_poller:new(
|
||||||
{party_management, 'GetEvents', [UserInfo, PartyID]},
|
{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()) ->
|
-spec handle_call(term(), callref(), st()) -> {reply, term(), st()} | {noreply, st()}.
|
||||||
{reply, term(), st()} | {noreply, st()}.
|
|
||||||
|
|
||||||
handle_call({call, Function, Args0}, _From, St = #st{client = Client}) ->
|
handle_call({call, Function, Args0}, _From, St = #st{client = Client}) ->
|
||||||
Args = [St#st.user_info, St#st.party_id | Args0],
|
Args = [St#st.user_info, St#st.party_id | Args0],
|
||||||
{Result, ClientNext} = pm_client_api:call(party_management, Function, Args, Client),
|
{Result, ClientNext} = pm_client_api:call(party_management, Function, Args, Client),
|
||||||
{reply, Result, St#st{client = ClientNext}};
|
{reply, Result, St#st{client = ClientNext}};
|
||||||
|
|
||||||
handle_call({call_without_party, Function, Args0}, _From, St = #st{client = Client}) ->
|
handle_call({call_without_party, Function, Args0}, _From, St = #st{client = Client}) ->
|
||||||
Args = [St#st.user_info | Args0],
|
Args = [St#st.user_info | Args0],
|
||||||
{Result, ClientNext} = pm_client_api:call(party_management, Function, Args, Client),
|
{Result, ClientNext} = pm_client_api:call(party_management, Function, Args, Client),
|
||||||
{reply, Result, St#st{client = ClientNext}};
|
{reply, Result, St#st{client = ClientNext}};
|
||||||
|
|
||||||
handle_call({pull_event, Timeout}, _From, St = #st{poller = Poller, client = Client}) ->
|
handle_call({pull_event, Timeout}, _From, St = #st{poller = Poller, client = Client}) ->
|
||||||
{Result, ClientNext, PollerNext} = pm_client_event_poller:poll(1, Timeout, Client, Poller),
|
{Result, ClientNext, PollerNext} = pm_client_event_poller:poll(1, Timeout, Client, Poller),
|
||||||
StNext = St#st{poller = PollerNext, client = ClientNext},
|
StNext = St#st{poller = PollerNext, client = ClientNext},
|
||||||
@ -414,35 +347,24 @@ handle_call({pull_event, Timeout}, _From, St = #st{poller = Poller, client = Cli
|
|||||||
Error ->
|
Error ->
|
||||||
{reply, Error, StNext}
|
{reply, Error, StNext}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_call(Call, _From, State) ->
|
handle_call(Call, _From, State) ->
|
||||||
_ = logger:warning("unexpected call received: ~tp", [Call]),
|
_ = logger:warning("unexpected call received: ~tp", [Call]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
-spec handle_cast(_, st()) ->
|
-spec handle_cast(_, st()) -> {noreply, st()}.
|
||||||
{noreply, st()}.
|
|
||||||
|
|
||||||
handle_cast(Cast, State) ->
|
handle_cast(Cast, State) ->
|
||||||
_ = logger:warning("unexpected cast received: ~tp", [Cast]),
|
_ = logger:warning("unexpected cast received: ~tp", [Cast]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
-spec handle_info(_, st()) ->
|
-spec handle_info(_, st()) -> {noreply, st()}.
|
||||||
{noreply, st()}.
|
|
||||||
|
|
||||||
handle_info(Info, State) ->
|
handle_info(Info, State) ->
|
||||||
_ = logger:warning("unexpected info received: ~tp", [Info]),
|
_ = logger:warning("unexpected info received: ~tp", [Info]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
-spec terminate(Reason, st()) ->
|
-spec terminate(Reason, st()) -> ok when Reason :: normal | shutdown | {shutdown, term()} | term().
|
||||||
ok when
|
|
||||||
Reason :: normal | shutdown | {shutdown, term()} | term().
|
|
||||||
|
|
||||||
terminate(_Reason, _State) ->
|
terminate(_Reason, _State) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec code_change(Vsn | {down, Vsn}, st(), term()) ->
|
-spec code_change(Vsn | {down, Vsn}, st(), term()) -> {error, noimpl} when Vsn :: term().
|
||||||
{error, noimpl} when
|
|
||||||
Vsn :: term().
|
|
||||||
|
|
||||||
code_change(_OldVsn, _State, _Extra) ->
|
code_change(_OldVsn, _State, _Extra) ->
|
||||||
{error, noimpl}.
|
{error, noimpl}.
|
||||||
|
@ -12,11 +12,10 @@
|
|||||||
|
|
||||||
-define(VERSION_PREFIX, "/v1").
|
-define(VERSION_PREFIX, "/v1").
|
||||||
|
|
||||||
-type service() :: woody:service().
|
-type service() :: woody:service().
|
||||||
-type service_spec() :: {Path :: string(), service()}.
|
-type service_spec() :: {Path :: string(), service()}.
|
||||||
|
|
||||||
-spec get_service(Name :: atom()) -> service().
|
-spec get_service(Name :: atom()) -> service().
|
||||||
|
|
||||||
get_service(claim_committer) ->
|
get_service(claim_committer) ->
|
||||||
{dmsl_claim_management_thrift, 'ClaimCommitter'};
|
{dmsl_claim_management_thrift, 'ClaimCommitter'};
|
||||||
get_service(party_management) ->
|
get_service(party_management) ->
|
||||||
@ -29,12 +28,10 @@ get_service(processor) ->
|
|||||||
{mg_proto_state_processing_thrift, 'Processor'}.
|
{mg_proto_state_processing_thrift, 'Processor'}.
|
||||||
|
|
||||||
-spec get_service_spec(Name :: atom()) -> service_spec().
|
-spec get_service_spec(Name :: atom()) -> service_spec().
|
||||||
|
|
||||||
get_service_spec(Name) ->
|
get_service_spec(Name) ->
|
||||||
get_service_spec(Name, #{}).
|
get_service_spec(Name, #{}).
|
||||||
|
|
||||||
-spec get_service_spec(Name :: atom(), Opts :: #{namespace => binary()}) -> service_spec().
|
-spec get_service_spec(Name :: atom(), Opts :: #{namespace => binary()}) -> service_spec().
|
||||||
|
|
||||||
get_service_spec(Name = claim_committer, #{}) ->
|
get_service_spec(Name = claim_committer, #{}) ->
|
||||||
{?VERSION_PREFIX ++ "/processing/claim_committer", get_service(Name)};
|
{?VERSION_PREFIX ++ "/processing/claim_committer", get_service(Name)};
|
||||||
get_service_spec(Name = party_management, #{}) ->
|
get_service_spec(Name = party_management, #{}) ->
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
thrift_struct_type().
|
thrift_struct_type().
|
||||||
|
|
||||||
-type thrift_base_type() ::
|
-type thrift_base_type() ::
|
||||||
bool |
|
bool |
|
||||||
double |
|
double |
|
||||||
i8 |
|
i8 |
|
||||||
i16 |
|
i16 |
|
||||||
i32 |
|
i32 |
|
||||||
i64 |
|
i64 |
|
||||||
string.
|
string.
|
||||||
|
|
||||||
-type thrift_collection_type() ::
|
-type thrift_collection_type() ::
|
||||||
@ -67,30 +67,23 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
|
|
||||||
-spec serialize_function_args(thrift_fun_full_ref(), woody:args()) ->
|
-spec serialize_function_args(thrift_fun_full_ref(), woody:args()) -> binary().
|
||||||
binary().
|
|
||||||
|
|
||||||
serialize_function_args({Module, {Service, Function}}, Args) when is_tuple(Args) ->
|
serialize_function_args({Module, {Service, Function}}, Args) when is_tuple(Args) ->
|
||||||
ArgsType = Module:function_info(Service, Function, params_type),
|
ArgsType = Module:function_info(Service, Function, params_type),
|
||||||
serialize(ArgsType, Args).
|
serialize(ArgsType, Args).
|
||||||
|
|
||||||
-spec serialize_function_reply(thrift_fun_full_ref(), term()) ->
|
-spec serialize_function_reply(thrift_fun_full_ref(), term()) -> binary().
|
||||||
binary().
|
|
||||||
|
|
||||||
serialize_function_reply({Module, {Service, Function}}, Data) ->
|
serialize_function_reply({Module, {Service, Function}}, Data) ->
|
||||||
ArgsType = Module:function_info(Service, Function, reply_type),
|
ArgsType = Module:function_info(Service, Function, reply_type),
|
||||||
serialize(ArgsType, Data).
|
serialize(ArgsType, Data).
|
||||||
|
|
||||||
-spec serialize_function_exception(thrift_fun_full_ref(), thrift_exception()) ->
|
-spec serialize_function_exception(thrift_fun_full_ref(), thrift_exception()) -> binary().
|
||||||
binary().
|
|
||||||
|
|
||||||
serialize_function_exception(FunctionRef, Exception) ->
|
serialize_function_exception(FunctionRef, Exception) ->
|
||||||
ExceptionType = get_fun_exception_type(FunctionRef),
|
ExceptionType = get_fun_exception_type(FunctionRef),
|
||||||
Name = find_exception_name(FunctionRef, Exception),
|
Name = find_exception_name(FunctionRef, Exception),
|
||||||
serialize(ExceptionType, {Name, Exception}).
|
serialize(ExceptionType, {Name, Exception}).
|
||||||
|
|
||||||
-spec serialize(thrift_type(), term()) -> binary().
|
-spec serialize(thrift_type(), term()) -> binary().
|
||||||
|
|
||||||
serialize(Type, Data) ->
|
serialize(Type, Data) ->
|
||||||
Codec0 = thrift_strict_binary_codec:new(),
|
Codec0 = thrift_strict_binary_codec:new(),
|
||||||
case thrift_strict_binary_codec:write(Codec0, Type, Data) of
|
case thrift_strict_binary_codec:write(Codec0, Type, Data) of
|
||||||
@ -100,9 +93,7 @@ serialize(Type, Data) ->
|
|||||||
erlang:error({thrift, {protocol, Reason}})
|
erlang:error({thrift, {protocol, Reason}})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec deserialize(thrift_type(), binary()) ->
|
-spec deserialize(thrift_type(), binary()) -> term().
|
||||||
term().
|
|
||||||
|
|
||||||
deserialize(Type, Data) ->
|
deserialize(Type, Data) ->
|
||||||
Codec0 = thrift_strict_binary_codec:new(Data),
|
Codec0 = thrift_strict_binary_codec:new(Data),
|
||||||
case thrift_strict_binary_codec:read(Codec0, Type) of
|
case thrift_strict_binary_codec:read(Codec0, Type) of
|
||||||
@ -117,23 +108,17 @@ deserialize(Type, Data) ->
|
|||||||
erlang:error({thrift, {protocol, Reason}})
|
erlang:error({thrift, {protocol, Reason}})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec deserialize_function_args(thrift_fun_full_ref(), binary()) ->
|
-spec deserialize_function_args(thrift_fun_full_ref(), binary()) -> woody:args().
|
||||||
woody:args().
|
|
||||||
|
|
||||||
deserialize_function_args({Module, {Service, Function}}, Data) ->
|
deserialize_function_args({Module, {Service, Function}}, Data) ->
|
||||||
ArgsType = Module:function_info(Service, Function, params_type),
|
ArgsType = Module:function_info(Service, Function, params_type),
|
||||||
deserialize(ArgsType, Data).
|
deserialize(ArgsType, Data).
|
||||||
|
|
||||||
-spec deserialize_function_reply(thrift_fun_full_ref(), binary()) ->
|
-spec deserialize_function_reply(thrift_fun_full_ref(), binary()) -> term().
|
||||||
term().
|
|
||||||
|
|
||||||
deserialize_function_reply({Module, {Service, Function}}, Data) ->
|
deserialize_function_reply({Module, {Service, Function}}, Data) ->
|
||||||
ArgsType = Module:function_info(Service, Function, reply_type),
|
ArgsType = Module:function_info(Service, Function, reply_type),
|
||||||
deserialize(ArgsType, Data).
|
deserialize(ArgsType, Data).
|
||||||
|
|
||||||
-spec deserialize_function_exception(thrift_fun_full_ref(), binary()) ->
|
-spec deserialize_function_exception(thrift_fun_full_ref(), binary()) -> thrift_exception().
|
||||||
thrift_exception().
|
|
||||||
|
|
||||||
deserialize_function_exception(FunctionRef, Data) ->
|
deserialize_function_exception(FunctionRef, Data) ->
|
||||||
ExceptionType = get_fun_exception_type(FunctionRef),
|
ExceptionType = get_fun_exception_type(FunctionRef),
|
||||||
{_Name, Exception} = deserialize(ExceptionType, Data),
|
{_Name, Exception} = deserialize(ExceptionType, Data),
|
||||||
@ -142,24 +127,24 @@ deserialize_function_exception(FunctionRef, Data) ->
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-spec record_to_proplist(Record :: tuple(), RecordInfo :: [atom()]) -> [{atom(), _}].
|
-spec record_to_proplist(Record :: tuple(), RecordInfo :: [atom()]) -> [{atom(), _}].
|
||||||
|
|
||||||
record_to_proplist(Record, RecordInfo) ->
|
record_to_proplist(Record, RecordInfo) ->
|
||||||
element(1, lists:foldl(
|
element(
|
||||||
fun (RecordField, {L, N}) ->
|
1,
|
||||||
case element(N, Record) of
|
lists:foldl(
|
||||||
V when V /= undefined ->
|
fun(RecordField, {L, N}) ->
|
||||||
{[{RecordField, V} | L], N + 1};
|
case element(N, Record) of
|
||||||
undefined ->
|
V when V /= undefined ->
|
||||||
{L, N + 1}
|
{[{RecordField, V} | L], N + 1};
|
||||||
end
|
undefined ->
|
||||||
end,
|
{L, N + 1}
|
||||||
{[], 1 + 1},
|
end
|
||||||
RecordInfo
|
end,
|
||||||
)).
|
{[], 1 + 1},
|
||||||
|
RecordInfo
|
||||||
-spec get_fun_exception_type(thrift_fun_full_ref()) ->
|
)
|
||||||
thrift_type().
|
).
|
||||||
|
|
||||||
|
-spec get_fun_exception_type(thrift_fun_full_ref()) -> thrift_type().
|
||||||
get_fun_exception_type({Module, {Service, Function}}) ->
|
get_fun_exception_type({Module, {Service, Function}}) ->
|
||||||
DeclaredType = Module:function_info(Service, Function, exceptions),
|
DeclaredType = Module:function_info(Service, Function, exceptions),
|
||||||
% В сгенерированном коде исключения объявлены как структура.
|
% В сгенерированном коде исключения объявлены как структура.
|
||||||
@ -167,9 +152,7 @@ get_fun_exception_type({Module, {Service, Function}}) ->
|
|||||||
{struct, struct, Exceptions} = DeclaredType,
|
{struct, struct, Exceptions} = DeclaredType,
|
||||||
{struct, union, Exceptions}.
|
{struct, union, Exceptions}.
|
||||||
|
|
||||||
-spec find_exception_name(thrift_fun_full_ref(), thrift_exception()) ->
|
-spec find_exception_name(thrift_fun_full_ref(), thrift_exception()) -> Name :: atom().
|
||||||
Name :: atom().
|
|
||||||
|
|
||||||
find_exception_name({Module, {Service, Function}}, Exception) ->
|
find_exception_name({Module, {Service, Function}}, Exception) ->
|
||||||
case thrift_processor_codec:match_exception({Module, Service}, Function, Exception) of
|
case thrift_processor_codec:match_exception({Module, Service}, Function, Exception) of
|
||||||
{ok, {_Type, Name}} ->
|
{ok, {_Type, Name}} ->
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 91587cccf7f5dbb2b0ccf4ca3b838b22c8c588a0
|
Subproject commit e6b981649e073a2dbf646ab491212a2c951aeb19
|
@ -103,6 +103,12 @@
|
|||||||
]}
|
]}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
|
||||||
{plugins, [
|
{plugins, [
|
||||||
rebar3_run
|
{erlfmt, "0.7.0"}
|
||||||
|
]}.
|
||||||
|
|
||||||
|
{erlfmt, [
|
||||||
|
{print_width, 120},
|
||||||
|
{files, "apps/*/{src,include,test}/*.{hrl,erl}"}
|
||||||
]}.
|
]}.
|
||||||
|
Loading…
Reference in New Issue
Block a user