Skip to content
1 change: 1 addition & 0 deletions apps/ff_cth/include/ct_domain.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-define(LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID3, <<"ID5">>).
-define(LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID4, <<"ID6">>).
-define(LIMIT_TURNOVER_NUM_SENDER_ID1, <<"ID7">>).
-define(LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID999, <<"ID999">>).

-define(glob(), #domain_GlobalsRef{}).
-define(cur(ID), #domain_CurrencyRef{symbolic_code = ID}).
Expand Down
70 changes: 33 additions & 37 deletions apps/ff_cth/src/ct_domain.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
-export([create_wallet/5]).

-export([currency/1]).
-export([currency_data/1]).
-export([category/3]).
-export([payment_method/1]).
-export([payment_system/2]).
Expand Down Expand Up @@ -164,46 +165,41 @@ withdrawal_terminal(?trm(ID) = Ref, ?prv(ProviderID) = ProviderRef, TermSet) ->
}
}}.

-spec currency_data(SymCode :: binary()) -> dmsl_domain_thrift:'Currency'().
currency_data(<<"EUR">> = SymCode) ->
#domain_Currency{
name = <<"Europe"/utf8>>,
numeric_code = 978,
symbolic_code = SymCode,
exponent = 2
};
currency_data(<<"RUB">> = SymCode) ->
#domain_Currency{
name = <<"Яussian Яuble"/utf8>>,
numeric_code = 643,
symbolic_code = SymCode,
exponent = 2
};
currency_data(<<"USD">> = SymCode) ->
#domain_Currency{
name = <<"U$ Dollar">>,
numeric_code = 840,
symbolic_code = SymCode,
exponent = 2
};
currency_data(<<"BTC">> = SymCode) ->
#domain_Currency{
name = <<"Bitcoin">>,
numeric_code = 999,
symbolic_code = SymCode,
exponent = 10
}.

-spec currency(?DTP('CurrencyRef')) -> object().
currency(?cur(<<"EUR">> = SymCode) = Ref) ->
{currency, #domain_CurrencyObject{
ref = Ref,
data = #domain_Currency{
name = <<"Europe"/utf8>>,
numeric_code = 978,
symbolic_code = SymCode,
exponent = 2
}
}};
currency(?cur(<<"RUB">> = SymCode) = Ref) ->
currency(?cur(SymCode) = Ref) ->
{currency, #domain_CurrencyObject{
ref = Ref,
data = #domain_Currency{
name = <<"Яussian Яuble"/utf8>>,
numeric_code = 643,
symbolic_code = SymCode,
exponent = 2
}
}};
currency(?cur(<<"USD">> = SymCode) = Ref) ->
{currency, #domain_CurrencyObject{
ref = Ref,
data = #domain_Currency{
name = <<"U$ Dollar">>,
numeric_code = 840,
symbolic_code = SymCode,
exponent = 2
}
}};
currency(?cur(<<"BTC">> = SymCode) = Ref) ->
{currency, #domain_CurrencyObject{
ref = Ref,
data = #domain_Currency{
name = <<"Bitcoin">>,
numeric_code = 999,
symbolic_code = SymCode,
exponent = 10
}
data = currency_data(SymCode)
}}.

-spec category(?DTP('CategoryRef'), binary(), ?DTP('CategoryType')) -> object().
Expand Down
3 changes: 2 additions & 1 deletion apps/ff_cth/src/ct_limiter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ init_per_suite(Config) ->
{limit_config, limiter_mk_config_object_amount(?LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID2)},
{limit_config, limiter_mk_config_object_amount(?LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID3)},
{limit_config, limiter_mk_config_object_amount(?LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID4)},
{limit_config, limiter_mk_config_object_num(?LIMIT_TURNOVER_NUM_SENDER_ID1, SenderScopes)}
{limit_config, limiter_mk_config_object_num(?LIMIT_TURNOVER_NUM_SENDER_ID1, SenderScopes)},
{limit_config, limiter_mk_config_object_amount(?LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID999)}
],
dmt_client:create_author(genlib:unique(), genlib:unique())
),
Expand Down
26 changes: 26 additions & 0 deletions apps/ff_cth/src/ct_payment_system.erl
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ domain_config(Config, Options) ->
condition(cost_in, {940000, <<"RUB">>}),
?ruleset(?PAYINST1_ROUTING_POLICIES + 33)
),
delegate(
condition(cost_in, {1357, <<"RUB">>}),
?ruleset(?PAYINST1_ROUTING_POLICIES + 41)
),
delegate(
condition(cost_in, {1246, <<"RUB">>}),
?ruleset(?PAYINST1_ROUTING_POLICIES + 41)
),
delegate(
{condition,
{payment_tool,
Expand Down Expand Up @@ -739,6 +747,13 @@ domain_config(Config, Options) ->
]}
),

routing_ruleset(
?ruleset(?PAYINST1_ROUTING_POLICIES + 41),
{candidates, [
candidate({constant, true}, ?trm(4100))
]}
),

routing_ruleset(
?ruleset(?PAYINST1_ROUTING_PROHIBITIONS),
<<"PayInst1 Withdrawal Prohibitions">>,
Expand Down Expand Up @@ -1252,6 +1267,17 @@ domain_config(Config, Options) ->
}
),

ct_domain:withdrawal_terminal(?trm(4100), ?prv(1), #domain_ProvisionTermSet{
wallet = #domain_WalletProvisionTerms{
withdrawals = #domain_WithdrawalProvisionTerms{
turnover_limit =
{value, [
?trnvrlimit(?LIMIT_TURNOVER_AMOUNT_PAYTOOL_ID999, 1000000000, Config)
]}
}
}
}),

ct_domain:currency(?cur(<<"RUB">>)),
ct_domain:currency(?cur(<<"USD">>)),
ct_domain:currency(?cur(<<"EUR">>)),
Expand Down
39 changes: 34 additions & 5 deletions apps/ff_server/src/ff_withdrawal_adjustment_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ marshal(changes_plan, Plan) ->
#wthd_adj_ChangesPlan{
new_cash_flow = maybe_marshal(cash_flow_change_plan, maps:get(new_cash_flow, Plan, undefined)),
new_status = maybe_marshal(status_change_plan, maps:get(new_status, Plan, undefined)),
new_domain_revision = maybe_marshal(domain_revision_change_plan, maps:get(new_domain_revision, Plan, undefined))
new_domain_revision = maybe_marshal(
domain_revision_change_plan, maps:get(new_domain_revision, Plan, undefined)
),
new_body = maybe_marshal(body_change_plan, maps:get(new_body, Plan, undefined))
};
marshal(cash_flow_change_plan, Plan) ->
OldCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)),
Expand All @@ -67,14 +70,22 @@ marshal(domain_revision_change_plan, Plan) ->
#wthd_adj_DataRevisionChangePlan{
new_domain_revision = ff_codec:marshal(domain_revision, maps:get(new_domain_revision, Plan))
};
marshal(body_change_plan, Plan) ->
#wthd_adj_BodyChangePlan{
new_body = marshal(cash, maps:get(new_body, Plan))
};
marshal(change_request, {change_status, Status}) ->
{change_status, #wthd_adj_ChangeStatusRequest{
new_status = ff_withdrawal_status_codec:marshal(status, Status)
}};
marshal(change_request, {change_cash_flow, DomainRevision}) ->
{change_status, #wthd_adj_ChangeCashFlowRequest{
{change_cash_flow, #wthd_adj_ChangeCashFlowRequest{
domain_revision = ff_codec:marshal(domain_revision, DomainRevision)
}};
marshal(change_request, {change_body, NewBody}) ->
{change_body, #wthd_adj_ChangeBodyRequest{
new_body = marshal(cash, NewBody)
}};
marshal(T, V) ->
ff_codec:marshal(T, V).

Expand Down Expand Up @@ -111,7 +122,8 @@ unmarshal(changes_plan, Plan) ->
new_status => maybe_unmarshal(status_change_plan, Plan#wthd_adj_ChangesPlan.new_status),
new_domain_revision => maybe_unmarshal(
domain_revision_change_plan, Plan#wthd_adj_ChangesPlan.new_domain_revision
)
),
new_body => maybe_unmarshal(body_change_plan, Plan#wthd_adj_ChangesPlan.new_body)
});
unmarshal(cash_flow_change_plan, Plan) ->
OldCashFlow = Plan#wthd_adj_CashFlowChangePlan.old_cash_flow_inverted,
Expand All @@ -130,12 +142,18 @@ unmarshal(domain_revision_change_plan, Plan) ->
#{
new_domain_revision => ff_codec:unmarshal(domain_revision, DomainRevision)
};
unmarshal(body_change_plan, Plan) ->
#{
new_body => unmarshal(cash, Plan#wthd_adj_BodyChangePlan.new_body)
};
unmarshal(change_request, {change_status, Request}) ->
Status = Request#wthd_adj_ChangeStatusRequest.new_status,
{change_status, ff_withdrawal_status_codec:unmarshal(status, Status)};
unmarshal(change_request, {change_cash_flow, Request}) ->
DomainRevision = Request#wthd_adj_ChangeCashFlowRequest.domain_revision,
{change_cash_flow, ff_codec:unmarshal(domain_revision, DomainRevision)};
unmarshal(change_request, {change_body, Request}) ->
{change_body, unmarshal(cash, Request#wthd_adj_ChangeBodyRequest.new_body)};
unmarshal(T, V) ->
ff_codec:unmarshal(T, V).

Expand Down Expand Up @@ -197,7 +215,8 @@ adjustment_codec_test() ->
new_status => #{
new_status => succeeded
},
new_domain_revision => #{new_domain_revision => 123}
new_domain_revision => #{new_domain_revision => 123},
new_body => #{new_body => {50, <<"RUB">>}}
},

Adjustment = #{
Expand All @@ -220,6 +239,16 @@ adjustment_codec_test() ->
{p_transfer, {created, Transfer}},
{status_changed, pending}
],
?assertEqual(Changes, [unmarshal(change, marshal(change, C)) || C <- Changes]).
?assertEqual(Changes, [unmarshal(change, marshal(change, C)) || C <- Changes]),

ChangeRequests = [
{change_status, succeeded},
{change_cash_flow, 123},
{change_body, {50, <<"RUB">>}}
],
?assertEqual(
ChangeRequests,
[unmarshal(change_request, marshal(change_request, R)) || R <- ChangeRequests]
).

-endif.
13 changes: 12 additions & 1 deletion apps/ff_server/src/ff_withdrawal_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ marshal_withdrawal_state(WithdrawalState, Context) ->
metadata = marshal(ctx, ff_withdrawal:metadata(WithdrawalState)),
quote = maybe_marshal(quote_state, ff_withdrawal:quote(WithdrawalState)),
withdrawal_validation = maybe_marshal(withdrawal_validation, ff_withdrawal:validation(WithdrawalState)),
contact_info = maybe_marshal(contact_info, ff_withdrawal:contact_info(WithdrawalState))
contact_info = maybe_marshal(contact_info, ff_withdrawal:contact_info(WithdrawalState)),
new_body = maybe_marshal(cash, ff_withdrawal:new_body(WithdrawalState))
}.

-spec marshal_event(ff_withdrawal_machine:event()) -> fistful_wthd_thrift:'Event'().
Expand Down Expand Up @@ -129,6 +130,11 @@ marshal(change, {adjustment, #{id := ID, payload := Payload}}) ->
}};
marshal(change, {validation, {Part, ValidationResult}}) when Part =:= sender; Part =:= receiver ->
{validation, {Part, marshal(validation_result, ValidationResult)}};
marshal(change, {body_changed, #{old_body := OldBody, new_body := NewBody}}) ->
{body_changed, #wthd_BodyChange{
old_body = marshal(cash, OldBody),
new_body = marshal(cash, NewBody)
}};
marshal(validation_result, {personal, #{validation_id := ValidationID, token := Token, validation_status := Status}}) ->
{
personal,
Expand Down Expand Up @@ -255,6 +261,11 @@ unmarshal(change, {adjustment, Change}) ->
}};
unmarshal(change, {validation, {Part, ValidationResult}}) when Part =:= sender; Part =:= receiver ->
{validation, {Part, unmarshal(validation_result, ValidationResult)}};
unmarshal(change, {body_changed, #wthd_BodyChange{old_body = OldBody, new_body = NewBody}}) ->
{body_changed, #{
old_body => unmarshal(cash, OldBody),
new_body => unmarshal(cash, NewBody)
}};
unmarshal(validation_result, {personal, Validation}) ->
{personal, #{
validation_id => unmarshal(id, Validation#wthd_PersonalDataValidationResult.validation_id),
Expand Down
8 changes: 8 additions & 0 deletions apps/ff_server/src/ff_withdrawal_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,13 @@ handle_function_('CreateAdjustment', {ID, MarshaledParams}, _Opts) ->
{error, {invalid_cash_flow_change, {already_has_domain_revision, DomainRevision}}} ->
woody_error:raise(business, #wthd_AlreadyHasDataRevision{
domain_revision = ff_withdrawal_codec:marshal(domain_revision, DomainRevision)
});
{error, {invalid_body_change, {already_has_body, Body}}} ->
woody_error:raise(business, #wthd_AlreadyHasBody{
body = ff_codec:marshal(cash, Body)
});
{error, {invalid_body_change, {invalid_operation_amount, Body}}} ->
woody_error:raise(business, #fistful_InvalidOperationAmount{
amount = ff_codec:marshal(cash, Body)
})
end.
14 changes: 14 additions & 0 deletions apps/ff_server/src/ff_withdrawal_session_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ marshal(change, {finished, SessionResult}) ->
{finished, marshal(session_result, SessionResult)};
marshal(change, {callback, CallbackChange}) ->
{callback, marshal(callback_change, CallbackChange)};
marshal(change, {body_changed, BodyChange}) ->
#{
old_body := OldBody,
new_body := NewBody
} = BodyChange,
{body_changed, #wthd_session_BodyChange{
old_body = marshal(cash, OldBody),
new_body = marshal(cash, NewBody)
}};
marshal(session, Session) ->
#{
id := SessionID,
Expand Down Expand Up @@ -184,6 +193,11 @@ unmarshal(change, {callback, #wthd_session_CallbackChange{tag = Tag, payload = P
tag => unmarshal(string, Tag),
payload => unmarshal(callback_event, Payload)
}};
unmarshal(change, {body_changed, #wthd_session_BodyChange{old_body = OldBody, new_body = NewBody}}) ->
{body_changed, #{
old_body => unmarshal(cash, OldBody),
new_body => unmarshal(cash, NewBody)
}};
unmarshal(session, #wthd_session_Session{
id = SessionID,
status = SessionStatus,
Expand Down
Loading
Loading