Review fixes

This commit is contained in:
Rustem Shaydullin 2022-10-14 02:33:25 +03:00
parent 6ddd47d140
commit 9d2b57782b
No known key found for this signature in database
GPG Key ID: 098B14A3236B5DFD
4 changed files with 141 additions and 153 deletions

View File

@ -1,4 +1,4 @@
-module(hg_invoice_tests_utils).
-module(hg_ct_invoice_tests_utils).
-include("hg_ct_domain.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
@ -12,9 +12,9 @@
-export([make_payment_params/3]).
-export([make_wallet_payment_params/1]).
-export([start_invoice/4]).
-export([start_invoice/5]).
-export([start_invoice/6]).
-export([start_and_check_invoice/4]).
-export([start_and_check_invoice/5]).
-export([start_and_check_invoice/6]).
-export([create_invoice/2]).
-export([next_event/2]).
-export([next_event/3]).
@ -151,18 +151,18 @@ make_wallet_payment_params(PmtSrv) ->
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool(digital_wallet, PmtSrv),
make_payment_params(PaymentTool, Session, instant).
-spec start_invoice(binary(), timestamp(), amount(), ct_suite:ct_config()) -> invoice_id().
start_invoice(Product, Due, Amount, C) ->
start_invoice(hg_ct_helper:cfg(shop_id, C), Product, Due, Amount, C).
-spec start_and_check_invoice(binary(), timestamp(), amount(), ct_suite:ct_config()) -> invoice_id().
start_and_check_invoice(Product, Due, Amount, C) ->
start_and_check_invoice(hg_ct_helper:cfg(shop_id, C), Product, Due, Amount, C).
-spec start_invoice(shop_id(), binary(), timestamp(), amount(), ct_suite:ct_config()) -> invoice_id().
start_invoice(ShopID, Product, Due, Amount, C) ->
-spec start_and_check_invoice(shop_id(), binary(), timestamp(), amount(), ct_suite:ct_config()) -> invoice_id().
start_and_check_invoice(ShopID, Product, Due, Amount, C) ->
Client = hg_ct_helper:cfg(client, C),
PartyID = hg_ct_helper:cfg(party_id, C),
start_invoice(PartyID, ShopID, Product, Due, Amount, Client).
start_and_check_invoice(PartyID, ShopID, Product, Due, Amount, Client).
-spec start_invoice(party_id(), shop_id(), binary(), timestamp(), amount(), pid()) -> invoice_id().
start_invoice(PartyID, ShopID, Product, Due, Amount, Client) ->
-spec start_and_check_invoice(party_id(), shop_id(), binary(), timestamp(), amount(), pid()) -> invoice_id().
start_and_check_invoice(PartyID, ShopID, Product, Due, Amount, Client) ->
InvoiceParams =
hg_ct_helper:make_invoice_params(PartyID, ShopID, Product, Due, hg_ct_helper:make_cash(Amount, <<"RUB">>)),
InvoiceID = create_invoice(InvoiceParams, Client),

View File

@ -2,7 +2,7 @@
%%% - Do not share state between test cases
%%% - Run cases in parallel
-module(hg_invoice_parallel_tests_SUITE).
-module(hg_invoice_payment_tools_tests_SUITE).
-include("hg_ct_domain.hrl").
@ -44,30 +44,18 @@ init([]) ->
-type group_name() :: hg_ct_helper:group_name().
-type test_return() :: _ | no_return().
-define(PARTY_ID_WITH_LIMIT, <<"bIg merch limit">>).
-define(PARTY_ID_WITH_SEVERAL_LIMITS, <<"bIg merch limit cascading">>).
-define(PARTYID_EXTERNAL, <<"DUBTV">>).
-define(LIMIT_ID, <<"ID">>).
-define(LIMIT_ID2, <<"ID2">>).
-define(LIMIT_ID3, <<"ID3">>).
-define(LIMIT_UPPER_BOUNDARY, 100000).
cfg(Key, C) ->
hg_ct_helper:cfg(Key, C).
-spec all() -> [test_case_name() | {group, group_name()}].
all() ->
[
{group, all_non_destructive_tests}
{group, base_payments}
].
-spec groups() -> [{group_name(), list(), [test_case_name()]}].
groups() ->
[
{all_non_destructive_tests, [], [
{group, base_payments}
]},
{base_payments, [parallel], [
payment_success,
payment_success_empty_cvv,
@ -82,8 +70,6 @@ groups() ->
-spec init_per_suite(config()) -> config().
init_per_suite(C) ->
CowboySpec = hg_dummy_provider:get_http_cowboy_spec(),
{Apps, Ret} = hg_ct_helper:start_apps([
woody,
scoper,
@ -92,8 +78,7 @@ init_per_suite(C) ->
party_client,
hg_proto,
hellgate,
snowflake,
{cowboy, CowboySpec}
snowflake
]),
_ = hg_domain:insert(construct_domain_fixture()),
@ -114,7 +99,7 @@ init_per_suite(C) ->
| C
],
ok = hg_invoice_tests_utils:start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
ok = hg_ct_invoice_tests_utils:start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
NewC.
-spec end_per_suite(config()) -> _.
@ -129,35 +114,16 @@ end_per_suite(C) ->
-include("payment_events.hrl").
-include("customer_events.hrl").
-define(invoice(ID), #domain_Invoice{id = ID}).
-define(payment(ID), #domain_InvoicePayment{id = ID}).
-define(payment(ID, Revision), #domain_InvoicePayment{id = ID, party_revision = Revision}).
-define(adjustment(ID), #domain_InvoicePaymentAdjustment{id = ID}).
-define(adjustment(ID, Status), #domain_InvoicePaymentAdjustment{id = ID, status = Status}).
-define(adjustment_revision(Revision), #domain_InvoicePaymentAdjustment{party_revision = Revision}).
-define(adjustment_reason(Reason), #domain_InvoicePaymentAdjustment{reason = Reason}).
-define(invoice_state(Invoice), #payproc_Invoice{invoice = Invoice}).
-define(invoice_state(Invoice, Payments), #payproc_Invoice{invoice = Invoice, payments = Payments}).
-define(payment_state(Payment), #payproc_InvoicePayment{payment = Payment}).
-define(payment_state(Payment, Refunds), #payproc_InvoicePayment{payment = Payment, refunds = Refunds}).
-define(payment_route(Route), #payproc_InvoicePayment{route = Route}).
-define(refund_state(Refund), #payproc_InvoicePaymentRefund{refund = Refund}).
-define(payment_cashflow(CashFlow), #payproc_InvoicePayment{cash_flow = CashFlow}).
-define(payment_last_trx(Trx), #payproc_InvoicePayment{last_transaction_info = Trx}).
-define(invoice_w_status(Status), #domain_Invoice{status = Status}).
-define(invoice_w_revision(Revision), #domain_Invoice{party_revision = Revision}).
-define(payment_w_status(Status), #domain_InvoicePayment{status = Status}).
-define(payment_w_status(ID, Status), #domain_InvoicePayment{id = ID, status = Status}).
-define(invoice_payment_refund(Cash, Status), #domain_InvoicePaymentRefund{cash = Cash, status = Status}).
-define(trx_info(ID), #domain_TransactionInfo{id = ID}).
-define(trx_info(ID, Extra), #domain_TransactionInfo{id = ID, extra = Extra}).
-define(refund_id(RefundID), #domain_InvoicePaymentRefund{id = RefundID}).
-define(refund_id(RefundID, ExternalID), #domain_InvoicePaymentRefund{id = RefundID, external_id = ExternalID}).
-define(CB_PROVIDER_LEVY, 50).
-define(merchant_to_system_share_1, ?share(45, 1000, operation_amount)).
-define(merchant_to_system_share_2, ?share(100, 1000, operation_amount)).
-define(merchant_to_system_share_3, ?share(40, 1000, operation_amount)).
-spec init_per_group(group_name(), config()) -> config().
init_per_group(_, C) ->
@ -186,7 +152,7 @@ end_per_testcase(_Name, _C) ->
-spec payment_success(config()) -> test_return().
payment_success(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
Context = #base_Content{
type = <<"application/x-erlang-binary">>,
data = erlang:term_to_binary({you, 643, "not", [<<"welcome">>, here]})
@ -194,12 +160,12 @@ payment_success(C) ->
PayerSessionInfo = #domain_PayerSessionInfo{
redirect_url = RedirectURL = <<"https://redirectly.io/merchant">>
},
PaymentParams = (hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)))#payproc_InvoicePaymentParams{
PaymentParams = (hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)))#payproc_InvoicePaymentParams{
payer_session_info = PayerSessionInfo,
context = Context
},
PaymentID = hg_invoice_tests_utils:process_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
PaymentID = hg_ct_invoice_tests_utils:process_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
?invoice_state(
?invoice_w_status(?invoice_paid()),
[PaymentSt = ?payment_state(Payment)]
@ -225,10 +191,17 @@ payment_success(C) ->
-spec payment_success_empty_cvv(config()) -> test_return().
payment_success_empty_cvv(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
PaymentID = hg_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentTool = {bank_card, #domain_BankCard{
token = <<"empty_cvv">>,
bin = <<"424242">>,
last_digits = <<"4242">>,
payment_system = ?pmt_sys(<<"visa-ref">>),
is_cvv_empty = true
}},
Session = <<"Session42">>,
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
PaymentID = hg_ct_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
?invoice_state(
?invoice_w_status(?invoice_paid()),
[?payment_state(?payment_w_status(PaymentID, ?captured()))]
@ -237,23 +210,30 @@ payment_success_empty_cvv(C) ->
-spec payment_success_additional_info(config()) -> test_return().
payment_success_additional_info(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool(empty_cvv, ?pmt_sys(<<"visa-ref">>)),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
PaymentID = hg_invoice_tests_utils:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentTool = {bank_card, #domain_BankCard{
token = <<"empty_cvv">>,
bin = <<"424242">>,
last_digits = <<"4242">>,
payment_system = ?pmt_sys(<<"visa-ref">>),
is_cvv_empty = true
}},
Session = <<"Session42">>,
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
PaymentID = hg_ct_invoice_tests_utils:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
[
?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(Trx))),
?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
#domain_TransactionInfo{additional_info = AdditionalInfo} = Trx,
AdditionalInfo = hg_ct_fixture:construct_dummy_additional_info(),
[
?payment_ev(PaymentID, ?payment_status_changed(?processed()))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
?invoice_state(
?invoice_w_status(?invoice_paid()),
[?payment_state(?payment_w_status(PaymentID, ?captured()))]
@ -263,9 +243,10 @@ payment_success_additional_info(C) ->
payment_w_crypto_currency_success(C) ->
Client = cfg(client, C),
PayCash = 2000,
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"cryptoduck">>, make_due_date(10), PayCash, C),
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool(crypto_currency, ?crypta(<<"bitcoin-ref">>)),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"cryptoduck">>, make_due_date(10), PayCash, C),
PaymentTool = {crypto_currency, ?crypta(<<"bitcoin-ref">>)},
Session = <<"Session42">>,
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
?payment_state(#domain_InvoicePayment{
id = PaymentID,
owner_id = PartyID,
@ -273,16 +254,16 @@ payment_w_crypto_currency_success(C) ->
}) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client),
[
?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending())))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
{CF, Route} = hg_invoice_tests_utils:await_payment_cash_flow(InvoiceID, PaymentID, Client),
CFContext = hg_invoice_tests_utils:construct_ta_context(PartyID, ShopID, Route),
?cash(PayCash, <<"RUB">>) = hg_invoice_tests_utils:get_cashflow_volume(
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
{CF, Route} = hg_ct_invoice_tests_utils:await_payment_cash_flow(InvoiceID, PaymentID, Client),
CFContext = hg_ct_invoice_tests_utils:construct_ta_context(PartyID, ShopID, Route),
?cash(PayCash, <<"RUB">>) = hg_ct_invoice_tests_utils:get_cashflow_volume(
{provider, settlement}, {merchant, settlement}, CF, CFContext
),
?cash(40, <<"RUB">>) = hg_invoice_tests_utils:get_cashflow_volume(
?cash(40, <<"RUB">>) = hg_ct_invoice_tests_utils:get_cashflow_volume(
{system, settlement}, {provider, settlement}, CF, CFContext
),
?cash(90, <<"RUB">>) = hg_invoice_tests_utils:get_cashflow_volume(
?cash(90, <<"RUB">>) = hg_ct_invoice_tests_utils:get_cashflow_volume(
{merchant, settlement}, {system, settlement}, CF, CFContext
).
@ -290,28 +271,35 @@ payment_w_crypto_currency_success(C) ->
payment_w_mobile_commerce(C) ->
Client = cfg(client, C),
PayCash = 1001,
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"oatmeal">>, make_due_date(10), PayCash, C),
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool({mobile_commerce, success}, ?mob(<<"mts-ref">>)),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"oatmeal">>, make_due_date(10), PayCash, C),
PaymentTool = {mobile_commerce, #domain_MobileCommerce{
operator = ?mob(<<"mts-ref">>),
phone = #domain_MobilePhone{
cc = <<"7">>,
ctn = <<"9876543211">>
}
}},
Session = <<"Session42">>,
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client),
[
?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending())))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
_ = hg_invoice_tests_utils:await_payment_cash_flow(InvoiceID, PaymentID, Client),
PaymentID = hg_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
_ = hg_ct_invoice_tests_utils:await_payment_cash_flow(InvoiceID, PaymentID, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
[
?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
[
?payment_ev(PaymentID, ?payment_status_changed(?processed()))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client).
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client).
%%
-spec payment_w_wallet_success(config()) -> _ | no_return().
payment_w_wallet_success(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"bubbleblob">>, make_due_date(10), 42000, C),
PaymentParams = hg_invoice_tests_utils:make_wallet_payment_params(?pmt_srv(<<"qiwi-ref">>)),
PaymentID = hg_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"bubbleblob">>, make_due_date(10), 42000, C),
PaymentParams = hg_ct_invoice_tests_utils:make_wallet_payment_params(?pmt_srv(<<"qiwi-ref">>)),
PaymentID = hg_ct_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
?invoice_state(
?invoice_w_status(?invoice_paid()),
[?payment_state(?payment_w_status(PaymentID, ?captured()))]

View File

@ -487,7 +487,7 @@ init_per_suite(C) ->
| C
],
ok = hg_invoice_tests_utils:start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
ok = hg_ct_invoice_tests_utils:start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
NewC.
-spec end_per_suite(config()) -> _.
@ -930,32 +930,32 @@ invoice_cancellation(C) ->
ShopID = cfg(shop_id, C),
PartyID = cfg(party_id, C),
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_cash(10000)),
InvoiceID = hg_invoice_tests_utils:create_invoice(InvoiceParams, Client),
InvoiceID = hg_ct_invoice_tests_utils:create_invoice(InvoiceParams, Client),
?invalid_invoice_status(_) = hg_client_invoicing:fulfill(InvoiceID, <<"perfect">>, Client),
ok = hg_client_invoicing:rescind(InvoiceID, <<"whynot">>, Client).
-spec overdue_invoice_cancellation(config()) -> test_return().
overdue_invoice_cancellation(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(1), 10000, C),
[?invoice_status_changed(?invoice_cancelled(<<"overdue">>))] = hg_invoice_tests_utils:next_event(InvoiceID, Client).
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(1), 10000, C),
[?invoice_status_changed(?invoice_cancelled(<<"overdue">>))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client).
-spec invoice_cancellation_after_payment_timeout(config()) -> test_return().
invoice_cancellation_after_payment_timeout(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberdusk">>, make_due_date(3), 1000, C),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberdusk">>, make_due_date(3), 1000, C),
PaymentParams = make_tds_payment_params(instant, ?pmt_sys(<<"visa-ref">>)),
PaymentID = hg_invoice_tests_utils:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_ct_invoice_tests_utils:start_payment(InvoiceID, PaymentParams, Client),
_UserInteraction = await_payment_process_interaction(InvoiceID, PaymentID, Client),
%% wait for payment timeout
PaymentID = await_payment_process_timeout(InvoiceID, PaymentID, Client),
[?invoice_status_changed(?invoice_cancelled(<<"overdue">>))] = hg_invoice_tests_utils:next_event(InvoiceID, Client).
[?invoice_status_changed(?invoice_cancelled(<<"overdue">>))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client).
-spec invalid_payment_amount(config()) -> test_return().
invalid_payment_amount(C) ->
Client = cfg(client, C),
PaymentParams = hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
InvoiceID2 = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 430000000, C),
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
InvoiceID2 = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 430000000, C),
{exception, #base_InvalidRequest{
errors = [<<"Invalid amount, more", _/binary>>]
}} = hg_client_invoicing:start_payment(InvoiceID2, PaymentParams, Client).
@ -963,8 +963,8 @@ invalid_payment_amount(C) ->
-spec payment_start_idempotency(config()) -> test_return().
payment_start_idempotency(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentParams0 = hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentParams0 = hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
PaymentID1 = <<"1">>,
ExternalID = <<"42">>,
PaymentParams1 = PaymentParams0#payproc_InvoicePaymentParams{
@ -982,7 +982,7 @@ payment_start_idempotency(C) ->
PaymentParams2 = PaymentParams0#payproc_InvoicePaymentParams{id = <<"2">>},
{exception, #payproc_InvoicePaymentPending{id = PaymentID1}} =
hg_client_invoicing:start_payment(InvoiceID, PaymentParams2, Client),
PaymentID1 = hg_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams1, Client),
PaymentID1 = hg_ct_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams1, Client),
?payment_state(#domain_InvoicePayment{
id = PaymentID1,
external_id = ExternalID
@ -1073,20 +1073,20 @@ switch_provider_after_limit_overflow(C) ->
ok = hg_limiter_helper:assert_payment_limit_amount(PaymentAmount, Payment, Invoice),
#domain_InvoicePayment{id = PaymentID} = Payment,
InvoiceID = hg_invoice_tests_utils:start_invoice(
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(
PartyID, ShopID, <<"rubberduck">>, make_due_date(10), PaymentAmount, Client
),
?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(
InvoiceID,
hg_invoice_tests_utils:make_payment_params(PmtSys),
hg_ct_invoice_tests_utils:make_payment_params(PmtSys),
Client
),
Route = hg_invoice_tests_utils:start_payment_ev(InvoiceID, Client),
Route = hg_ct_invoice_tests_utils:start_payment_ev(InvoiceID, Client),
?assertMatch(#domain_PaymentRoute{provider = #domain_ProviderRef{id = 6}}, Route),
[?payment_ev(PaymentID2, ?cash_flow_changed(_))] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID2 = hg_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID2, Client, ?processed()),
PaymentID2 = hg_invoice_tests_utils:await_payment_process_finish(InvoiceID, PaymentID2, Client, 0).
[?payment_ev(PaymentID2, ?cash_flow_changed(_))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID2 = hg_ct_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID2, Client, ?processed()),
PaymentID2 = hg_ct_invoice_tests_utils:await_payment_process_finish(InvoiceID, PaymentID2, Client, 0).
-spec limit_not_found(config()) -> test_return().
limit_not_found(C) ->
@ -1150,7 +1150,7 @@ refund_limit_success(C) ->
payment_partial_capture_limit_success(C) ->
InitialCost = 1000 * 10,
PartialCost = 700 * 10,
PaymentParams = hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}),
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>), {hold, cancel}),
RootUrl = cfg(root_url, C),
PartyClient = cfg(party_client, C),
@ -1159,16 +1159,16 @@ payment_partial_capture_limit_success(C) ->
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(100), make_cash(InitialCost)),
InvoiceID = hg_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
InvoiceID = hg_ct_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
% start payment
?payment_state(?payment(PaymentID)) =
hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = await_payment_started(InvoiceID, PaymentID, Client),
{CF1, _} = hg_invoice_tests_utils:await_payment_cash_flow(InvoiceID, PaymentID, Client),
PaymentID = hg_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
PaymentID = hg_invoice_tests_utils:await_payment_process_finish(InvoiceID, PaymentID, Client),
{CF1, _} = hg_ct_invoice_tests_utils:await_payment_cash_flow(InvoiceID, PaymentID, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
PaymentID = hg_ct_invoice_tests_utils:await_payment_process_finish(InvoiceID, PaymentID, Client),
% do a partial capture
Cash = ?cash(PartialCost, <<"RUB">>),
Reason = <<"ok">>,
@ -1188,18 +1188,18 @@ payment_partial_capture_limit_success(C) ->
create_payment(PartyID, ShopID, Amount, Client, PmtSys) ->
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(Amount)),
InvoiceID = hg_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
InvoiceID = hg_ct_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PmtSys),
_PaymentID = hg_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PmtSys),
_PaymentID = hg_ct_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
hg_client_invoicing:get(InvoiceID, Client).
create_payment_limit_overflow(PartyID, ShopID, Amount, Client, PmtSys) ->
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(Amount)),
InvoiceID = hg_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PmtSys),
InvoiceID = hg_ct_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PmtSys),
?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = await_payment_started(InvoiceID, PaymentID, Client),
await_payment_rollback(InvoiceID, PaymentID, Client).
@ -1214,12 +1214,12 @@ payment_success_ruleset(C) ->
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)),
InvoiceID = hg_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_invoice_tests_utils:process_payment(
InvoiceID, hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)), Client
InvoiceID = hg_ct_invoice_tests_utils:create_invoice(InvoiceParams, Client),
[?invoice_created(?invoice_w_status(?invoice_unpaid()))] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_ct_invoice_tests_utils:process_payment(
InvoiceID, hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)), Client
),
PaymentID = hg_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
?invoice_state(
?invoice_w_status(?invoice_paid()),
[?payment_state(Payment)]
@ -1229,16 +1229,16 @@ payment_success_ruleset(C) ->
-spec processing_deadline_reached_test(config()) -> test_return().
processing_deadline_reached_test(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentParams0 = hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentParams0 = hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
Deadline = hg_datetime:format_now(),
PaymentParams = PaymentParams0#payproc_InvoicePaymentParams{processing_deadline = Deadline},
PaymentID = hg_invoice_tests_utils:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_invoice_tests_utils:await_sessions_restarts(PaymentID, ?processed(), InvoiceID, Client, 0),
[?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure}))] = hg_invoice_tests_utils:next_event(
PaymentID = hg_ct_invoice_tests_utils:start_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_ct_invoice_tests_utils:await_sessions_restarts(PaymentID, ?processed(), InvoiceID, Client, 0),
[?payment_ev(PaymentID, ?payment_rollback_started({failure, Failure}))] = hg_ct_invoice_tests_utils:next_event(
InvoiceID, Client
),
[?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure})))] = hg_invoice_tests_utils:next_event(
[?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure})))] = hg_ct_invoice_tests_utils:next_event(
InvoiceID, Client
),
ok = payproc_errors:match(
@ -1250,9 +1250,9 @@ processing_deadline_reached_test(C) ->
-spec payment_has_optional_fields(config()) -> test_return().
payment_has_optional_fields(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentParams = hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
PaymentID = hg_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)),
PaymentID = hg_ct_invoice_tests_utils:execute_payment(InvoiceID, PaymentParams, Client),
InvoicePayment = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client),
?payment_state(Payment) = InvoicePayment,
?payment_route(Route) = InvoicePayment,
@ -1268,38 +1268,38 @@ payment_has_optional_fields(C) ->
-spec payment_last_trx_correct(config()) -> _ | no_return().
payment_last_trx_correct(C) ->
Client = cfg(client, C),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentID = hg_invoice_tests_utils:start_payment(
InvoiceID, hg_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)), Client
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
PaymentID = hg_ct_invoice_tests_utils:start_payment(
InvoiceID, hg_ct_invoice_tests_utils:make_payment_params(?pmt_sys(<<"visa-ref">>)), Client
),
PaymentID = hg_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
PaymentID = hg_ct_invoice_tests_utils:await_payment_session_started(InvoiceID, PaymentID, Client, ?processed()),
[
?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(TrxInfo0))),
?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded())))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
[
?payment_ev(PaymentID, ?payment_status_changed(?processed()))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_ct_invoice_tests_utils:await_payment_capture(InvoiceID, PaymentID, Client),
?payment_last_trx(TrxInfo0) = hg_client_invoicing:get_payment(InvoiceID, PaymentID, Client).
-spec payment_w_misconfigured_routing_failed(config()) -> test_return().
payment_w_misconfigured_routing_failed(C) ->
Client = cfg(client, C),
Amount = 42000,
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)),
PaymentParams = hg_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
PaymentParams = hg_ct_invoice_tests_utils:make_payment_params(PaymentTool, Session, instant),
?payment_state(?payment(PaymentID)) = hg_client_invoicing:start_payment(InvoiceID, PaymentParams, Client),
[
?payment_ev(PaymentID, ?payment_started(?payment_w_status(?pending())))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
[
?payment_ev(PaymentID, ?risk_score_changed(_))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
[
?payment_ev(PaymentID, ?payment_status_changed(?failed({failure, Failure})))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
ok = payproc_errors:match(
'PaymentFailure',
Failure,
@ -1334,14 +1334,14 @@ payment_capture_failed(C) ->
Client = cfg(client, C),
Amount = 42000,
Cost = ?cash(Amount, <<"RUB">>),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
PaymentParams = make_scenario_payment_params([good, fail], ?pmt_sys(<<"visa-ref">>)),
PaymentID = hg_invoice_tests_utils:process_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_ct_invoice_tests_utils:process_payment(InvoiceID, PaymentParams, Client),
[
?payment_ev(PaymentID, ?payment_capture_started(_)),
?payment_ev(PaymentID, ?session_ev(?captured(), ?session_started()))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
timeout = hg_invoice_tests_utils:next_event(InvoiceID, 5000, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
timeout = hg_ct_invoice_tests_utils:next_event(InvoiceID, 5000, Client),
?assertException(
error,
{{woody_error, _}, _},
@ -1354,17 +1354,17 @@ payment_capture_retries_exceeded(C) ->
Client = cfg(client, C),
Amount = 42000,
Cost = ?cash(Amount, <<"RUB">>),
InvoiceID = hg_invoice_tests_utils:start_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
InvoiceID = hg_ct_invoice_tests_utils:start_and_check_invoice(<<"rubberduck">>, make_due_date(10), Amount, C),
PaymentParams = make_scenario_payment_params([good, temp, temp, temp, temp], ?pmt_sys(<<"visa-ref">>)),
PaymentID = hg_invoice_tests_utils:process_payment(InvoiceID, PaymentParams, Client),
PaymentID = hg_ct_invoice_tests_utils:process_payment(InvoiceID, PaymentParams, Client),
Reason = ?timeout_reason(),
Target = ?captured(Reason, Cost),
[
?payment_ev(PaymentID, ?payment_capture_started(Reason, Cost, _, _Allocation)),
?payment_ev(PaymentID, ?session_ev(?captured(Reason, Cost), ?session_started()))
] = hg_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_invoice_tests_utils:await_sessions_restarts(PaymentID, Target, InvoiceID, Client, 3),
timeout = hg_invoice_tests_utils:next_event(InvoiceID, 5000, Client),
] = hg_ct_invoice_tests_utils:next_event(InvoiceID, Client),
PaymentID = hg_ct_invoice_tests_utils:await_sessions_restarts(PaymentID, Target, InvoiceID, Client, 3),
timeout = hg_ct_invoice_tests_utils:next_event(InvoiceID, 5000, Client),
?assertException(
error,
{{woody_error, _}, _},

View File

@ -21,7 +21,7 @@
hg_customer_tests_SUITE,
hg_recurrent_paytools_tests_SUITE,
hg_invoice_tests_SUITE,
hg_invoice_tests_utils
hg_ct_invoice_tests_utils
]
}},
{elvis_style, no_if_expression},