Skip to content

Commit 2a6747f

Browse files
committed
BG-429: Add recurrent test for registered parent
1 parent 57a4aa5 commit 2a6747f

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

apps/hellgate/test/hg_direct_recurrent_tests_SUITE.erl

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
-include("hg_ct_domain.hrl").
44
-include("hg_ct_json.hrl").
5+
-include("hg_ct_invoice.hrl").
56

67
-include("invoice_events.hrl").
78
-include("payment_events.hrl").
@@ -18,6 +19,7 @@
1819

1920
-export([first_recurrent_payment_success_test/1]).
2021
-export([second_recurrent_payment_success_test/1]).
22+
-export([register_parent_payment_test/1]).
2123
-export([another_shop_test/1]).
2224
-export([not_recurring_first_test/1]).
2325
-export([cancelled_first_payment_test/1]).
@@ -34,13 +36,6 @@
3436

3537
%% Macro helpers
3638

37-
-define(invoice(ID), #domain_Invoice{id = ID}).
38-
-define(payment(ID), #domain_InvoicePayment{id = ID}).
39-
-define(invoice_state(Invoice), #payproc_Invoice{invoice = Invoice}).
40-
-define(invoice_state(Invoice, Payments), #payproc_Invoice{invoice = Invoice, payments = Payments}).
41-
-define(payment_state(Payment), #payproc_InvoicePayment{payment = Payment}).
42-
-define(invoice_w_status(Status), #domain_Invoice{status = Status}).
43-
-define(payment_w_status(ID, Status), #domain_InvoicePayment{id = ID, status = Status}).
4439
-define(evp(Pattern), fun(EvpPattern) ->
4540
case EvpPattern of
4641
Pattern -> true;
@@ -73,6 +68,7 @@ groups() ->
7368
{basic_operations, [parallel], [
7469
first_recurrent_payment_success_test,
7570
second_recurrent_payment_success_test,
71+
register_parent_payment_test,
7672
another_shop_test,
7773
not_recurring_first_test,
7874
cancelled_first_payment_test,
@@ -193,6 +189,51 @@ second_recurrent_payment_success_test(C) ->
193189
[?payment_state(?payment_w_status(Payment2ID, ?captured()))]
194190
) = hg_client_invoicing:get(Invoice2ID, Client).
195191

192+
-define(recurrent_token, <<"recurrent_token">>).
193+
194+
-spec register_parent_payment_test(config()) -> test_result().
195+
register_parent_payment_test(C) ->
196+
Client = cfg(client, C),
197+
Invoice1ID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
198+
%% first payment in recurrent session
199+
Route = ?route(?prv(1), ?trm(1)),
200+
{PaymentTool, Session} = hg_dummy_provider:make_payment_tool(no_preauth, ?pmt_sys(<<"visa-ref">>)),
201+
PaymentParams = #payproc_RegisterInvoicePaymentParams{
202+
payer_params =
203+
{payment_resource, #payproc_PaymentResourcePayerParams{
204+
resource = #domain_DisposablePaymentResource{
205+
payment_tool = PaymentTool,
206+
payment_session_id = Session,
207+
client_info = #domain_ClientInfo{}
208+
},
209+
contact_info = ?contact_info()
210+
}},
211+
route = Route,
212+
transaction_info = ?trx_info(<<"1">>, #{}),
213+
recurrent_token = ?recurrent_token
214+
},
215+
Payment1ID = register_payment(Invoice1ID, PaymentParams, false, Client),
216+
Payment1ID = await_payment_session_started(Invoice1ID, Payment1ID, Client, ?processed()),
217+
218+
[
219+
?payment_ev(PaymentID, ?rec_token_acquired(?recurrent_token)),
220+
?payment_ev(PaymentID, ?session_ev(?processed(), ?trx_bound(?trx_info(_)))),
221+
?payment_ev(PaymentID, ?session_ev(?processed(), ?session_finished(?session_succeeded()))),
222+
?payment_ev(PaymentID, ?payment_status_changed(?processed()))
223+
] = hg_invoice_helper:next_changes(Invoice1ID, 4, Client),
224+
Payment1ID = await_payment_capture(Invoice1ID, Payment1ID, Client),
225+
226+
%% second recurrent payment
227+
Invoice2ID = start_invoice(<<"rubberduck">>, make_due_date(10), 42000, C),
228+
RecurrentParent = ?recurrent_parent(Invoice1ID, Payment1ID),
229+
Payment2Params = make_recurrent_payment_params(true, RecurrentParent, ?pmt_sys(<<"visa-ref">>)),
230+
{ok, Payment2ID} = start_payment(Invoice2ID, Payment2Params, Client),
231+
Payment2ID = await_payment_capture(Invoice2ID, Payment2ID, Client),
232+
?invoice_state(
233+
?invoice_w_status(?invoice_paid()),
234+
[?payment_state(?payment_w_status(Payment2ID, ?captured()))]
235+
) = hg_client_invoicing:get(Invoice2ID, Client).
236+
196237
-spec another_shop_test(config()) -> test_result().
197238
another_shop_test(C) ->
198239
Client = cfg(client, C),
@@ -287,6 +328,12 @@ start_proxies(Proxies) ->
287328
)
288329
).
289330

331+
register_payment(InvoiceID, RegisterPaymentParams, WithRiskScoring, Client) ->
332+
hg_invoice_helper:register_payment(InvoiceID, RegisterPaymentParams, WithRiskScoring, Client).
333+
334+
await_payment_session_started(InvoiceID, PaymentID, Client, Target) ->
335+
hg_invoice_helper:await_payment_session_started(InvoiceID, PaymentID, Client, Target).
336+
290337
setup_proxies(Proxies) ->
291338
_ = hg_domain:upsert(Proxies),
292339
ok.

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
command: /sbin/init
2828

2929
dmt:
30-
image: ghcr.io/valitydev/dominant-v2:sha-4fb87ed-epic-fix_remove
30+
image: ghcr.io/valitydev/dominant-v2:sha-1705fe8
3131
command: /opt/dmt/bin/dmt foreground
3232
healthcheck:
3333
test: "/opt/dmt/bin/dmt ping"

0 commit comments

Comments
 (0)