From 3426c4862305ee2969f40194805b04452bea894e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Tue, 26 Feb 2019 14:46:14 +0300 Subject: [PATCH] HG-460: Empty cvv (#289) --- apps/hellgate/src/hg_payment_tool.erl | 36 +++++++++++++++++-- apps/hellgate/test/hg_invoice_tests_SUITE.erl | 12 +++++++ docker-compose.sh | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/apps/hellgate/src/hg_payment_tool.erl b/apps/hellgate/src/hg_payment_tool.erl index 8a04a36..40e1629 100644 --- a/apps/hellgate/src/hg_payment_tool.erl +++ b/apps/hellgate/src/hg_payment_tool.erl @@ -20,6 +20,8 @@ -spec get_method(t()) -> method(). +get_method({bank_card, #domain_BankCard{payment_system = PaymentSystem, is_cvv_empty = true}}) -> + #domain_PaymentMethodRef{id = {empty_cvv_bank_card, PaymentSystem}}; get_method({bank_card, #domain_BankCard{payment_system = PaymentSystem, token_provider = undefined}}) -> #domain_PaymentMethodRef{id = {bank_card, PaymentSystem}}; get_method({bank_card, #domain_BankCard{payment_system = PaymentSystem, token_provider = TokenProvider}}) -> @@ -94,7 +96,22 @@ test_bank_card_condition_def({payment_system, PaymentSystem}, V, Rev) -> test_bank_card_condition_def({issuer_country_is, IssuerCountry}, V, Rev) -> test_issuer_country_condition(IssuerCountry, V, Rev); test_bank_card_condition_def({issuer_bank_is, BankRef}, V, Rev) -> - test_issuer_bank_condition(BankRef, V, Rev). + test_issuer_bank_condition(BankRef, V, Rev); +test_bank_card_condition_def( + {empty_cvv_is, Val}, + #domain_BankCard{is_cvv_empty = Val}, + _Rev +) -> + true; +%% Для обратной совместимости с картами, у которых нет is_cvv_empty +test_bank_card_condition_def( + {empty_cvv_is, false}, + #domain_BankCard{is_cvv_empty = undefined}, + _Rev +) -> + true; +test_bank_card_condition_def({empty_cvv_is, _Val}, #domain_BankCard{}, _Rev) -> + false. test_payment_system_condition( #domain_PaymentSystemCondition{payment_system_is = Ps, token_provider_is = Tp}, @@ -161,7 +178,8 @@ marshal(bank_card = T, #domain_BankCard{} = BankCard) -> <<"token_provider">> => marshal({T, token_provider}, BankCard#domain_BankCard.token_provider), <<"issuer_country">> => marshal({T, issuer_country}, BankCard#domain_BankCard.issuer_country), <<"bank_name">> => marshal({T, bank_name}, BankCard#domain_BankCard.bank_name), - <<"metadata">> => marshal({T, metadata}, BankCard#domain_BankCard.metadata) + <<"metadata">> => marshal({T, metadata}, BankCard#domain_BankCard.metadata), + <<"is_cvv_empty">> => marshal({T, boolean}, BankCard#domain_BankCard.is_cvv_empty) }); marshal(payment_terminal = T, #domain_PaymentTerminal{terminal_type = TerminalType}) -> marshal({T, type}, TerminalType); @@ -225,6 +243,11 @@ marshal({payment_terminal, type}, euroset) -> marshal({digital_wallet, provider}, qiwi) -> <<"qiwi">>; +marshal({bank_card, boolean}, true) -> + <<"true">>; +marshal({bank_card, boolean}, false) -> + <<"false">>; + marshal(_, Other) -> Other. @@ -250,6 +273,7 @@ unmarshal(bank_card = T, #{ IssuerCountry = genlib_map:get(<<"issuer_country">>, V), BankName = genlib_map:get(<<"bank_name">>, V), MD = genlib_map:get(<<"metadata">>, V), + IsCVVEmpty = genlib_map:get(<<"is_cvv_empty">>, V), #domain_BankCard{ token = unmarshal(str, Token), payment_system = unmarshal({T, payment_system}, PaymentSystem), @@ -258,7 +282,8 @@ unmarshal(bank_card = T, #{ token_provider = unmarshal({T, token_provider}, TokenProvider), issuer_country = unmarshal({T, issuer_country}, IssuerCountry), bank_name = unmarshal({T, bank_name}, BankName), - metadata = unmarshal({T, metadata}, MD) + metadata = unmarshal({T, metadata}, MD), + is_cvv_empty = unmarshal({T, boolean}, IsCVVEmpty) }; unmarshal(payment_terminal = T, TerminalType) -> #domain_PaymentTerminal{ @@ -342,6 +367,11 @@ unmarshal({payment_terminal, type}, <<"euroset">>) -> unmarshal({digital_wallet, provider}, <<"qiwi">>) -> qiwi; +unmarshal({bank_card, boolean}, <<"true">>) -> + true; +unmarshal({bank_card, boolean}, <<"false">>) -> + false; + unmarshal(_, Other) -> Other. diff --git a/apps/hellgate/test/hg_invoice_tests_SUITE.erl b/apps/hellgate/test/hg_invoice_tests_SUITE.erl index c82df3d..7650569 100644 --- a/apps/hellgate/test/hg_invoice_tests_SUITE.erl +++ b/apps/hellgate/test/hg_invoice_tests_SUITE.erl @@ -2814,6 +2814,18 @@ construct_domain_fixture() -> ?pmt(bank_card, mastercard) ])}, cash_limit = {decisions, [ + % проверяем, что условие никогда не отрабатывает + #domain_CashLimitDecision { + if_ = {condition, {payment_tool, {bank_card, #domain_BankCardCondition{ + definition = {empty_cvv_is, true} + }}}}, + then_ = {value, + ?cashrng( + {inclusive, ?cash(0, <<"RUB">>)}, + {inclusive, ?cash(0, <<"RUB">>)} + ) + } + }, #domain_CashLimitDecision{ if_ = {condition, {currency_is, ?cur(<<"RUB">>)}}, then_ = {value, ?cashrng( diff --git a/docker-compose.sh b/docker-compose.sh index 43b5ade..5977291 100755 --- a/docker-compose.sh +++ b/docker-compose.sh @@ -17,7 +17,7 @@ services: condition: service_healthy dominant: - image: dr.rbkmoney.com/rbkmoney/dominant:3cf6c46d482f0057d117209170c831f5a238d95a + image: dr.rbkmoney.com/rbkmoney/dominant:fe8a25bacf99b00da022ff531368413579de6ace command: /opt/dominant/bin/dominant foreground depends_on: machinegun: