|
2 | 2 |
|
3 | 3 | -include("hg_ct_domain.hrl"). |
4 | 4 | -include("hg_ct_json.hrl"). |
| 5 | +-include("hg_ct_invoice.hrl"). |
5 | 6 |
|
6 | 7 | -include("invoice_events.hrl"). |
7 | 8 | -include("payment_events.hrl"). |
|
18 | 19 |
|
19 | 20 | -export([first_recurrent_payment_success_test/1]). |
20 | 21 | -export([second_recurrent_payment_success_test/1]). |
| 22 | +-export([register_parent_payment_test/1]). |
21 | 23 | -export([another_shop_test/1]). |
22 | 24 | -export([not_recurring_first_test/1]). |
23 | 25 | -export([cancelled_first_payment_test/1]). |
|
34 | 36 |
|
35 | 37 | %% Macro helpers |
36 | 38 |
|
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}). |
44 | 39 | -define(evp(Pattern), fun(EvpPattern) -> |
45 | 40 | case EvpPattern of |
46 | 41 | Pattern -> true; |
@@ -73,6 +68,7 @@ groups() -> |
73 | 68 | {basic_operations, [parallel], [ |
74 | 69 | first_recurrent_payment_success_test, |
75 | 70 | second_recurrent_payment_success_test, |
| 71 | + register_parent_payment_test, |
76 | 72 | another_shop_test, |
77 | 73 | not_recurring_first_test, |
78 | 74 | cancelled_first_payment_test, |
@@ -193,6 +189,51 @@ second_recurrent_payment_success_test(C) -> |
193 | 189 | [?payment_state(?payment_w_status(Payment2ID, ?captured()))] |
194 | 190 | ) = hg_client_invoicing:get(Invoice2ID, Client). |
195 | 191 |
|
| 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 | + |
196 | 237 | -spec another_shop_test(config()) -> test_result(). |
197 | 238 | another_shop_test(C) -> |
198 | 239 | Client = cfg(client, C), |
@@ -287,6 +328,12 @@ start_proxies(Proxies) -> |
287 | 328 | ) |
288 | 329 | ). |
289 | 330 |
|
| 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 | + |
290 | 337 | setup_proxies(Proxies) -> |
291 | 338 | _ = hg_domain:upsert(Proxies), |
292 | 339 | ok. |
|
0 commit comments