CAPI-32 Move to the newest images and fix missed fields (#16)

* CAPI-32 Move to the newest images and fix missed fields. Change linter code complexity change to soothe the unnecessary warnings. Add new swag version and fix ip_address source
This commit is contained in:
Artem Ocheredko 2016-10-26 16:39:32 +03:00 committed by GitHub
parent 730ad23d13
commit 26f1e2beca
11 changed files with 166 additions and 63 deletions

View File

@ -27,7 +27,7 @@ CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze test star
CALL_W_CONTAINER := $(CALL_ANYWHERE)
.PHONY: $(CALL_W_CONTAINER) all
.PHONY: $(CALL_W_CONTAINER) all cover
all: compile
@ -65,6 +65,7 @@ release: distclean $(SWAGGER_APP_TARGET)
$(REBAR) as prod release
clean:
$(REBAR) cover -r
$(REBAR) clean
distclean:
@ -86,3 +87,6 @@ $(SWAGGER_APP_TARGET): $(SWAGGER_SCHEME)
swagger_regenerate:
$(call swagger_regenerate)
cover:
$(REBAR) cover

View File

@ -84,10 +84,7 @@ process_request(OperationID = 'CreatePayment', Req, Context) ->
Token = genlib_map:get(<<"paymentToolToken">>, PaymentParams),
ContactInfo = genlib_map:get(<<"contactInfo">>, PaymentParams),
PaymentTool = decode_bank_card(Token),
#{
ip_address := IP
} = get_peer_info(Context),
PreparedIP = genlib:to_binary(inet:ntoa(IP)),
EncodedSession = genlib_map:get(<<"paymentSession">>, PaymentParams),
{ClientInfo, PaymentSession} = unwrap_session(EncodedSession),
Params = #payproc_InvoicePaymentParams{
@ -96,7 +93,7 @@ process_request(OperationID = 'CreatePayment', Req, Context) ->
session = PaymentSession,
client_info = #domain_ClientInfo{
fingerprint = maps:get(<<"fingerprint">>, ClientInfo),
ip_address = PreparedIP
ip_address = maps:get(<<"ip_address">>, ClientInfo)
},
contact_info = #domain_ContactInfo{
phone_number = genlib_map:get(<<"phoneNumber">>, ContactInfo),
@ -120,10 +117,10 @@ process_request(OperationID = 'CreatePayment', Req, Context) ->
process_request_error(OperationID, Error)
end;
process_request(OperationID = 'CreatePaymentToolToken', Req, _Context) ->
process_request(OperationID = 'CreatePaymentToolToken', Req, Context) ->
Params = maps:get('CreatePaymentToolTokenArgs', Req),
RequestID = maps:get('X-Request-ID', Req),
ClientInfo = maps:get(<<"clientInfo">>, Params),
ClientInfo0 = maps:get(<<"clientInfo">>, Params),
PaymentTool = maps:get(<<"paymentTool">>, Params),
case PaymentTool of
#{<<"paymentToolType">> := <<"CardData">>} ->
@ -150,6 +147,12 @@ process_request(OperationID = 'CreatePaymentToolToken', Req, _Context) ->
bank_card = BankCard
}} ->
Token = encode_bank_card(BankCard),
#{
ip_address := IP
} = get_peer_info(Context),
PreparedIP = genlib:to_binary(inet:ntoa(IP)),
ClientInfo = ClientInfo0#{<<"ip_address">> => PreparedIP},
Session = wrap_session(ClientInfo, PaymentSession),
Resp = #{
<<"token">> => Token,
@ -192,7 +195,7 @@ process_request(OperationID = 'GetInvoiceByID', Req, Context) ->
}}} ->
%%% InvoiceContext = jsx:decode(RawInvoiceContext, [return_maps]), @TODO deal with non json contexts
InvoiceContext = #{
<<"context">> => RawInvoiceContext
<<"context">> => decode_context(RawInvoiceContext)
},
Resp = #{
<<"id">> => InvoiceID,
@ -226,7 +229,7 @@ process_request(OperationID = 'FulfillInvoice', Req, Context) ->
create_context(RequestID)
),
case Result of
{ok, _} ->
ok ->
{200, [], #{}};
Error ->
process_request_error(OperationID, Error)
@ -247,7 +250,7 @@ process_request(OperationID = 'RescindInvoice', Req, Context) ->
create_context(RequestID)
),
case Result of
{ok, _} ->
ok ->
{200, [], #{}};
Error ->
process_request_error(OperationID, Error)
@ -281,11 +284,10 @@ process_request(OperationID = 'GetPaymentByID', Req, Context) ->
InvoiceID = maps:get(invoiceID, Req),
RequestID = maps:get('X-Request-ID', Req),
UserInfo = get_user_info(Context),
PartyID = get_party_id(Context),
{Result, _NewContext} = service_call(
invoicing,
'GetPayment',
[UserInfo, PartyID, PaymentID],
[UserInfo, InvoiceID, PaymentID],
create_context(RequestID)
),
case Result of
@ -415,8 +417,7 @@ process_request(OperationID = 'CreateShop', Req, Context) ->
ShopParams = #payproc_ShopParams{
category = encode_category_ref(genlib_map:get(<<"categoryRef">>, Params)),
details = encode_shop_details(genlib_map:get(<<"shopDetails">>, Params)),
% contractor = encode_contractor(genlib_map:get(<<"contractor">>, Params))
contractor = encode_contractor(undefined)
contractor = encode_contractor(genlib_map:get(<<"contractor">>, Params))
},
{Result, _} = prepare_party(
@ -823,7 +824,7 @@ encode_shop_details(Details = #{
}) ->
#domain_ShopDetails{
name = Name,
description = genlib_map:get(<<"details">>, Details),
description = genlib_map:get(<<"description">>, Details),
location = genlib_map:get(<<"location">>, Details)
}.
@ -844,7 +845,7 @@ encode_contractor(#{
}) ->
#domain_Contractor{
registered_name = RegisteredName,
legal_entity = undefined
legal_entity = #domain_LegalEntity{}
}.
decode_bank_card(Encoded) ->

View File

@ -9,13 +9,11 @@
%%
-define(COWBOY_PORT, 9988).
-spec get_service_spec() ->
{Path :: string(), Service :: {module(), atom()}}.
get_service_spec() ->
{"/test/proxy/provider/dummy", {capi_proxy_provider_thrift, 'ProviderProxy'}}.
{"/test/proxy/provider/dummy", {cp_proxy_provider_thrift, 'ProviderProxy'}}.
%%
@ -26,8 +24,8 @@ get_service_spec() ->
handle_function(
'ProcessPayment',
{#'Context'{
session = #'Session'{target = Target, state = State},
{#prxprv_Context{
session = #prxprv_Session{target = Target, state = State},
payment = PaymentInfo,
options = _
}},
@ -38,8 +36,8 @@ handle_function(
handle_function(
'HandlePaymentCallback',
{_Payload, #'Context'{
session = #'Session'{target = _Target, state = _State},
{_Payload, #prxprv_Context{
session = #prxprv_Session{target = _Target, state = _State},
payment = PaymentInfo,
options = _
}},
@ -48,18 +46,20 @@ handle_function(
) ->
{{ok, respond(<<"sure">>, finish(PaymentInfo))}, Context}.
process_payment({captured, #domain_InvoicePaymentCaptured{}}, _, PaymentInfo, _, Context) ->
{{ok, finish(PaymentInfo)}, Context};
process_payment({processed, #domain_InvoicePaymentProcessed{}}, _, PaymentInfo, _, Context) ->
{{ok, finish(PaymentInfo)}, Context}.
finish(#'PaymentInfo'{payment = Payment}) ->
#'ProxyResult'{
finish(#prxprv_PaymentInfo{payment = Payment}) ->
#prxprv_ProxyResult{
intent = {finish, #'FinishIntent'{status = {ok, #'Ok'{}}}},
trx = #domain_TransactionInfo{id = Payment#domain_InvoicePayment.id}
trx = #domain_TransactionInfo{id = Payment#prxprv_InvoicePayment.id}
}.
respond(Response, Result) ->
#'CallbackResult'{
#prxprv_CallbackResult{
response = Response,
result = Result
}.

View File

@ -3,6 +3,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("cp_proto/include/cp_payment_processing_thrift.hrl").
-include_lib("cp_proto/include/cp_domain_config_thrift.hrl").
-include_lib("cp_proto/include/cp_accounter_thrift.hrl").
-export([all/0]).
@ -24,6 +25,8 @@
create_payment_tool_token_ok_test/1,
get_invoice_by_id_ok_test/1,
get_invoice_events_ok_test/1,
rescind_invoice_ok_test/1,
fulfill_invoice_ok_test/1,
get_payment_by_id_ok_test/1,
%%%%
get_invoices_stats_ok_test/1,
@ -59,6 +62,8 @@
-define(CAPI_MERCHANT_STAT_URL, "http://magista:8022/stat").
-define(CAPI_PARTY_MANAGEMENT_URL, "http://hellgate:8022/v1/processing/partymgmt").
-define(CAPI_REPOSITORY_URL, "http://dominant:8022/v1/domain/repository").
-define(CAPI_ACCOUNTER_URL, "http://shumway:8022/accounter").
-define(CAPI_HOST_NAME, "capi").
-define(MERCHANT_ID, <<"hg_tests_SUITE">>).
@ -81,6 +86,7 @@ init([]) ->
all() ->
[
{group, authorization},
{group, invoice_management},
{group, card_payment},
{group, statistics},
{group, party_management},
@ -103,11 +109,18 @@ groups() ->
authorization_error_no_header_test,
authorization_error_expired_test
]},
{card_payment, [sequence], [
{invoice_management, [sequence], [
create_invoice_badard_test,
create_invoice_ok_test,
get_invoice_by_id_ok_test,
rescind_invoice_ok_test
]},
{card_payment, [sequence], [
create_invoice_ok_test,
create_payment_tool_token_ok_test,
create_payment_ok_test,
get_payment_by_id_ok_test,
fulfill_invoice_ok_test,
get_invoice_events_ok_test
]},
{statistics, [parallel], [
@ -160,7 +173,8 @@ init_per_suite(Config) ->
invoicing => ?CAPI_INVOICING_URL,
merchant_stat => ?CAPI_MERCHANT_STAT_URL,
party_management => ?CAPI_PARTY_MANAGEMENT_URL,
repository => ?CAPI_REPOSITORY_URL
repository => ?CAPI_REPOSITORY_URL,
accounter => ?CAPI_ACCOUNTER_URL
}}
]) ++
capi_ct_helper:start_app(capi, [
@ -170,6 +184,7 @@ init_per_suite(Config) ->
{api_secret_path, filename:join(?config(data_dir, Config), "public_api_key.pem")}
]),
{ok, SupPid} = supervisor:start_link(?MODULE, []),
_ = unlink(SupPid),
NewConfig = [{apps, lists:reverse(Apps)}, {test_sup, SupPid} | Config],
ProxyUrl = start_service_handler(capi_dummy_provider, NewConfig),
populate_snapshot(ProxyUrl),
@ -179,7 +194,6 @@ init_per_suite(Config) ->
-spec end_per_suite(config()) -> _.
end_per_suite(C) ->
_ = unlink(?config(test_sup, C)),
exit(?config(test_sup, C), shutdown),
ok = cleanup(),
[application:stop(App) || App <- proplists:get_value(apps, C)].
@ -222,6 +236,24 @@ create_invoice_ok_test(Config) ->
#{<<"id">> := InvoiceID} = default_create_invoice(Config),
{save_config, InvoiceID}.
-spec fulfill_invoice_ok_test(config()) -> _.
fulfill_invoice_ok_test(Config) ->
{get_payment_by_id_ok_test,
#{invoice_id := InvoiceID} = Info
} = ?config(saved_config, Config),
#{} = default_fulfill_invoice(InvoiceID, Config),
{save_config, Info}.
-spec rescind_invoice_ok_test(config()) -> _.
rescind_invoice_ok_test(Config) ->
{get_invoice_by_id_ok_test,
InvoiceID
} = ?config(saved_config, Config),
#{} = default_rescind_invoice(InvoiceID, Config).
-spec create_payment_ok_test(config()) -> _.
create_payment_ok_test(Config) ->
@ -230,7 +262,14 @@ create_payment_ok_test(Config) ->
<<"token">> := PaymentToolToken,
<<"invoiceID">> := InvoiceID
}} = ?config(saved_config, Config),
#{<<"id">> := _PaymentID} = default_create_payment(InvoiceID, PaymentSession, PaymentToolToken, Config).
#{<<"id">> := PaymentID} = default_create_payment(
InvoiceID,
PaymentSession,
PaymentToolToken,
Config
),
{save_config, #{payment_id => PaymentID, invoice_id => InvoiceID}}.
-spec create_payment_tool_token_ok_test(config()) -> _.
@ -247,36 +286,31 @@ create_payment_tool_token_ok_test(Config) ->
-spec get_invoice_by_id_ok_test(config()) -> _.
get_invoice_by_id_ok_test(Config) ->
#{<<"id">> := InvoiceID} = default_create_invoice(Config),
{create_invoice_ok_test,
InvoiceID
} = ?config(saved_config, Config),
Path = "/v1/processing/invoices/" ++ genlib:to_list(InvoiceID),
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config),
{save_config, InvoiceID}.
-spec get_invoice_events_ok_test(config()) -> _.
get_invoice_events_ok_test(Config) ->
#{<<"id">> := InvoiceID} = default_create_invoice(Config),
#{
<<"session">> := PaymentSession,
<<"token">> := PaymentToolToken
} = default_tokenize_card(Config),
#{<<"id">> := _PaymentID} = default_create_payment(InvoiceID, PaymentSession, PaymentToolToken, Config),
timer:sleep(1000),
{fulfill_invoice_ok_test,
#{invoice_id := InvoiceID}
} = ?config(saved_config, Config),
Path = "/v1/processing/invoices/" ++ genlib:to_list(InvoiceID) ++ "/events/?limit=100",
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
-spec get_payment_by_id_ok_test(config()) -> _.
get_payment_by_id_ok_test(Config) ->
#{<<"id">> := InvoiceID} = default_create_invoice(Config),
#{
<<"session">> := PaymentSession,
<<"token">> := PaymentToolToken
} = default_tokenize_card(Config),
#{<<"id">> := PaymentID} = default_create_payment(InvoiceID, PaymentSession, PaymentToolToken, Config),
{create_payment_ok_test,
#{payment_id := PaymentID, invoice_id := InvoiceID} = Info
} = ?config(saved_config, Config),
Path = "/v1/processing/invoices/" ++ genlib:to_list(InvoiceID) ++ "/payments/" ++ genlib:to_list(PaymentID),
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config).
{ok, 200, _RespHeaders, _Body} = default_call(get, Path, #{}, Config),
{save_config, Info}.
-spec get_invoices_stats_ok_test(config()) -> _.
@ -769,6 +803,10 @@ default_create_shop(CategoryRef, Config) ->
<<"shopDetails">> => #{
<<"name">> => <<"OOOBlackMaster">>,
<<"description">> => <<"Goods for education">>
},
<<"contractor">> => #{
<<"registeredName">> => <<"DefaultRegisteredName">>,
<<"legalEntity">> => <<"DefaultLegalEntity">>
}
},
{ok, 202, _RespHeaders, Body} = default_call(post, Path, Req, Config),
@ -797,6 +835,24 @@ default_revoke_claim(ClaimID, Config) ->
{ok, 200, _RespHeaders, Body} = default_call(post, Path, Req, Config),
decode_body(Body).
default_fulfill_invoice(InvoiceID, Config) ->
Path = "/v1/processing/invoices/" ++ genlib:to_list(InvoiceID) ++ "/fulfill",
Req = #{
<<"reason">> => <<"me want dat">>
},
{ok, 200, _RespHeaders, Body} = default_call(post, Path, Req, Config),
decode_body(Body).
default_rescind_invoice(InvoiceID, Config) ->
Path = "/v1/processing/invoices/" ++ genlib:to_list(InvoiceID) ++ "/rescind",
Req = #{
<<"reason">> => <<"me want dat">>
},
{ok, 200, _RespHeaders, Body} = default_call(post, Path, Req, Config),
decode_body(Body).
%% @FIXME thats dirty
default_approve_claim(ClaimID) ->
UserInfo = #payproc_UserInfo{
@ -816,6 +872,7 @@ default_approve_claim(ClaimID) ->
-define(prv(ID), #domain_ProviderRef{id = ID}).
-define(trm(ID), #domain_TerminalRef{id = ID}).
-define(pst(ID), #domain_PaymentsServiceTermsRef{id = ID}).
-define(sas(ID), #domain_SystemAccountSetRef{id = ID}).
-define(trmacc(Cur, Rec, Com),
#domain_TerminalAccountSet{currency = ?cur(Cur), receipt = Rec, compensation = Com}).
@ -851,23 +908,44 @@ populate_snapshot(ProxyUrl) ->
ops = Ops
},
cp_proto:call_service_safe(
{{ok, _Version}, _} = cp_proto:call_service_safe(
repository,
'Commit',
[Version, Commit],
Context0
),
timer:sleep(8000).
get_domain_fixture(ProxyUrl) ->
Context = create_context(),
{Accounts, _Context} = lists:foldl(
fun ({N, CurrencyCode}, {M, C0}) ->
{AccountID, C1} = create_account(CurrencyCode, C0),
{M#{N => AccountID}, C1}
end,
{#{}, Context},
[
{system_compensation , <<"RUB">>},
{terminal_1_receipt , <<"RUB">>},
{terminal_1_compensation , <<"RUB">>}
]
),
[
{globals, #domain_GlobalsObject{
ref = #domain_GlobalsRef{},
data = #domain_Globals{
party_prototype = #domain_PartyPrototypeRef{id = 42},
providers = {value, [?prv(1)]},
system_accounts = {predicates, []}
system_accounts = {value, [?sas(1)]}
}
}},
{system_account_set, #domain_SystemAccountSetObject{
ref = ?sas(1),
data = #domain_SystemAccountSet{
name = <<"Primaries">>,
description = <<"Primaries">>,
currency = ?cur(<<"RUB">>),
compensation = maps:get(system_compensation, Accounts)
}
}},
{party_prototype, #domain_PartyPrototypeObject{
@ -955,7 +1033,11 @@ get_domain_fixture(ProxyUrl) ->
?cfpost(provider, receipt, merchant, general, ?share(1, 1, payment_amount)),
?cfpost(system, compensation, provider, compensation, ?share(18, 1000, payment_amount))
],
accounts = ?trmacc(<<"RUB">>, 10001, 10002),
accounts = ?trmacc(
<<"RUB">>,
maps:get(terminal_1_receipt, Accounts),
maps:get(terminal_1_compensation, Accounts)
),
options = #{
<<"override">> => <<"Brominal 1">>
}
@ -1027,12 +1109,11 @@ get_any_category(Config) ->
Category.
start_service_handler(Module, C) ->
IP = "127.0.0.1",
Port = get_random_port(),
Opts = #{},
ChildSpec = capi_test_proxy:get_child_spec(Module, IP, Port, Opts),
ChildSpec = capi_test_proxy:get_child_spec(Module, "0.0.0.0", Port, Opts),
{ok, _} = supervisor:start_child(?config(test_sup, C), ChildSpec),
capi_test_proxy:get_url(Module, IP, Port).
capi_test_proxy:get_url(Module, ?CAPI_HOST_NAME, Port).
get_random_port() ->
rand:uniform(32768) + 32767.
@ -1059,3 +1140,16 @@ cleanup() ->
Context0
),
ok.
create_account(CurrencyCode, Context0) ->
AccountPrototype = #accounter_AccountPrototype{
currency_sym_code = CurrencyCode
},
{{ok, AccountID}, Context} = cp_proto:call_service_safe(
accounter,
'CreateAccount',
[AccountPrototype],
Context0
),
{AccountID, Context}.

@ -1 +1 @@
Subproject commit 7a56dfce898cbc4c989f5d900ef3e50e0b8c2977
Subproject commit 557f5493cfb24728cd4171a9b3f9df86c529fa07

View File

@ -17,6 +17,7 @@
"payment_processing.thrift",
"merch_stat.thrift",
"proxy_provider.thrift",
"accounter.thrift",
"domain_config.thrift"
]},
{gen, "erlang:app_prefix=cp,scoped_typenames"}

View File

@ -27,5 +27,7 @@ get_service_modname(merchant_stat) ->
{cp_merch_stat_thrift, 'MerchantStatistics'};
get_service_modname(repository) ->
{cp_domain_config_thrift, 'Repository'};
get_service_modname(accounter) ->
{cp_accounter_thrift, 'Accounter'};
get_service_modname(party_management) ->
{cp_payment_processing_thrift, 'PartyManagement'}.

View File

@ -21,7 +21,7 @@ services:
- SERVICE_NAME=capi
hellgate:
image: dr.rbkmoney.com/rbkmoney/hellgate:235513c47205ed190d3276fdb2c7948893b57cbd
image: dr.rbkmoney.com/rbkmoney/hellgate:ef9864b17f88d98a2b851a7cc090c3cfc4c19d4b
restart: always
command: /opt/hellgate/bin/hellgate foreground
depends_on:
@ -29,7 +29,7 @@ services:
- shumway
cds:
image: dr.rbkmoney.com/rbkmoney/cds:fe3751a508600af87e67cc5add133d178a403fd6
image: dr.rbkmoney.com/rbkmoney/cds:538659226317356bc42529299037fe6cfa651694
restart: always
command: /opt/cds/bin/cds foreground
@ -115,7 +115,7 @@ services:
- SERVICE_NAME=shumway-db
dominant:
image: dr.rbkmoney.com/rbkmoney/dominant:f3c72168d9dfeb4da241d4eb5d6a29787c81faef
image: dr.rbkmoney.com/rbkmoney/dominant:9e6db27120f970707b77aa492fb218eb1bd40055
restart: always
command: /opt/dominant/bin/dominant foreground
depends_on:

View File

@ -25,7 +25,7 @@
{elvis_style, state_record_and_type},
{elvis_style, no_spec_with_records},
{elvis_style, dont_repeat_yourself, #{
min_complexity => 10,
min_complexity => 15,
ignore => [
capi_tests_mock_SUITE,
capi_tests_real_SUITE

View File

@ -106,6 +106,7 @@
]}
]},
{test, [
{cover_enabled, true},
{deps, []}
]}
]}.

@ -1 +1 @@
Subproject commit 78917f0ae966089ff97e0d2ae4c720b965e64902
Subproject commit f10087c324134da223154f76bbae4e414a475bdb