diff --git a/apps/capi/src/capi_handler_encoder.erl b/apps/capi/src/capi_handler_encoder.erl index 2398045..e2e4929 100644 --- a/apps/capi/src/capi_handler_encoder.erl +++ b/apps/capi/src/capi_handler_encoder.erl @@ -33,7 +33,9 @@ encode_contact_info(ContactInfo) -> encode_client_info(ClientInfo) -> #domain_ClientInfo{ fingerprint = maps:get(<<"fingerprint">>, ClientInfo), - ip_address = maps:get(<<"ip">>, ClientInfo) + ip_address = maps:get(<<"ip">>, ClientInfo), + peer_ip_address = maps:get(<<"peer_ip">>, ClientInfo), + user_ip_address = maps:get(<<"user_ip">>, ClientInfo) }. -spec encode_residence(binary() | undefined) -> atom(). diff --git a/apps/capi/src/capi_handler_webhooks.erl b/apps/capi/src/capi_handler_webhooks.erl index 2d68fad..9957e56 100644 --- a/apps/capi/src/capi_handler_webhooks.erl +++ b/apps/capi/src/capi_handler_webhooks.erl @@ -263,32 +263,10 @@ decode_event_filter({customer, #webhooker_CustomerEventFilter{shop_id = ShopID, decode_invoice_event_type({created, #webhooker_InvoiceCreated{}}) -> [<<"InvoiceCreated">>]; -decode_invoice_event_type({status_changed, #webhooker_InvoiceStatusChanged{value = undefined}}) -> - % TODO seems unmaintainable - [ - decode_invoice_status_event_type(V) - || V <- [ - ?INVPAID(), - ?INVCANCELLED(), - ?INVFULFILLED() - ] - ]; decode_invoice_event_type({status_changed, #webhooker_InvoiceStatusChanged{value = Value}}) -> [decode_invoice_status_event_type(Value)]; decode_invoice_event_type({payment, {created, #webhooker_InvoicePaymentCreated{}}}) -> [<<"PaymentStarted">>]; -decode_invoice_event_type({payment, {status_changed, #webhooker_InvoicePaymentStatusChanged{value = undefined}}}) -> - % TODO seems unmaintainable - [ - decode_payment_status_event_type(V) - || V <- [ - ?PMTPROCESSED(), - ?PMTCAPTURED(), - ?PMTCANCELLED(), - ?PMTREFUNDED(), - ?PMTFAILED() - ] - ]; decode_invoice_event_type({payment, {status_changed, #webhooker_InvoicePaymentStatusChanged{value = Value}}}) -> [decode_payment_status_event_type(Value)]; decode_invoice_event_type({payment, {invoice_payment_refund_change, ?PMTRFNDCREATED()}}) -> diff --git a/apps/capi/test/capi_dummy_data.hrl b/apps/capi/test/capi_dummy_data.hrl index 87048db..507acba 100644 --- a/apps/capi/test/capi_dummy_data.hrl +++ b/apps/capi/test/capi_dummy_data.hrl @@ -1115,7 +1115,9 @@ <<"paymentSession">> => Session, <<"clientInfo">> => #{ <<"fingerprint">> => <<"test fingerprint">>, - <<"ip">> => <<"::ffff:127.0.0.1">> + <<"ip">> => <<"::ffff:127.0.0.1">>, + <<"peer_ip">> => <<"::ffff:127.0.0.1">>, + <<"user_ip">> => <<"::ffff:127.127.0.1">> } }) ). diff --git a/apps/capi/test/capi_invoice_access_token_tests_SUITE.erl b/apps/capi/test/capi_invoice_access_token_tests_SUITE.erl index 068e9a3..1c60d23 100644 --- a/apps/capi/test/capi_invoice_access_token_tests_SUITE.erl +++ b/apps/capi/test/capi_invoice_access_token_tests_SUITE.erl @@ -31,6 +31,7 @@ create_payment_crypto_ok_test/1, create_payment_mobile_commerce_ok_test/1, create_payment_with_empty_cvv_ok_test/1, + check_ip_on_payment_creation_ok_test/1, get_payments_ok_test/1, get_payment_by_id_ok_test/1, get_payment_by_id_trx_ok_test/1, @@ -77,6 +78,7 @@ invoice_access_token_tests() -> create_payment_ok_test, create_payment_expired_test, create_payment_with_empty_cvv_ok_test, + check_ip_on_payment_creation_ok_test, get_payments_ok_test, create_payment_qiwi_access_token_ok_test, create_payment_crypto_ok_test, @@ -406,6 +408,50 @@ create_payment_w_payment_tool(PaymentTool, Config) -> }, capi_client_payments:create_payment(?config(context, Config), Req, ?STRING). +-spec check_ip_on_payment_creation_ok_test(_) -> _. +check_ip_on_payment_creation_ok_test(Config) -> + PaymentTool = {bank_card, ?BANK_CARD(<<"visa">>, ?EXP_DATE(2, 2020))}, + ClientInfo = #domain_ClientInfo{ + fingerprint = <<"test fingerprint">>, + ip_address = <<"::ffff:127.0.0.1">>, + peer_ip_address = <<"::ffff:127.0.0.1">>, + user_ip_address = <<"::ffff:127.127.0.1">> + }, + _ = capi_ct_helper:mock_services( + [ + {invoicing, fun + ('Get', _) -> + {ok, ?PAYPROC_INVOICE}; + ('StartPayment', {_InvoiceID, Params}) -> + ?assertMatch( + {payment_resource, #payproc_PaymentResourcePayerParams{ + resource = #domain_DisposablePaymentResource{ + payment_tool = PaymentTool, + client_info = ClientInfo + } + }}, + Params#payproc_InvoicePaymentParams.payer + ), + {ok, ?PAYPROC_PAYMENT(?PAYMENT(?STRING, ?PAYMENT_STATUS_PENDING, ?PAYER(PaymentTool)))} + end}, + {generator, fun('GenerateID', _) -> + capi_ct_helper_bender:generate_id(?STRING) + end} + ], + Config + ), + _ = capi_ct_helper_bouncer:mock_assert_invoice_op_ctx(<<"CreatePayment">>, ?STRING, ?STRING, ?STRING, Config), + Req = #{ + <<"flow">> => #{<<"type">> => <<"PaymentFlowInstant">>}, + <<"payer">> => #{ + <<"payerType">> => <<"PaymentResourcePayer">>, + <<"paymentSession">> => ?TEST_PAYMENT_SESSION, + <<"paymentToolToken">> => encrypt_payment_tool(PaymentTool), + <<"contactInfo">> => #{<<"email">> => ?EMAIL} + } + }, + {ok, _} = capi_client_payments:create_payment(?config(context, Config), Req, ?STRING). + -spec get_payments_ok_test(config()) -> _. get_payments_ok_test(Config) -> Payment0 = ?PAYPROC_PAYMENT(?PAYMENT_WITH_CUSTOMER_PAYER, [?REFUND], [?ADJUSTMENT], [?PAYPROC_CHARGEBACK]), diff --git a/rebar.lock b/rebar.lock index f013617..998f3df 100644 --- a/rebar.lock +++ b/rebar.lock @@ -37,7 +37,7 @@ {<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},1}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"9362c08657d1681240d70f923fc04642bbfecc0a"}}, + {ref,"60474970af1d5e58752f4e5680e67c65ff64dda9"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git",