INT-915: Put changed cash to payment cash (#42)

This commit is contained in:
Артем 2024-01-16 12:43:36 +03:00 committed by GitHub
parent 3401edb1ba
commit 14a41f5526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 7 deletions

View File

@ -149,7 +149,13 @@ decode_payment(InvoiceID, Payment, Context) ->
#domain_Cash{
amount = Amount,
currency = Currency
} = Payment#domain_InvoicePayment.cost,
} =
case Payment#domain_InvoicePayment.changed_cost of
undefined ->
Payment#domain_InvoicePayment.cost;
Cost ->
Cost
end,
capi_handler_utils:merge_and_compact(
#{
<<"id">> => Payment#domain_InvoicePayment.id,

View File

@ -49,6 +49,7 @@
get_payment_status_insufficient_funds_test/1,
create_payment_ok_test/1,
create_payment_with_changed_cost_ok_test/1,
create_refund/1,
create_refund_blocked_error/1,
create_refund_expired_error/1,
@ -212,6 +213,7 @@ groups() ->
activate_shop_for_party_error_test,
create_payment_ok_test,
create_payment_with_changed_cost_ok_test,
retrieve_payment_by_external_id_test,
retrieve_payment_by_external_id_for_party_test,
check_no_payment_by_external_id_test,
@ -829,6 +831,48 @@ create_payment_ok_test(Config) ->
{ok, Payment} = capi_client_payments:create_payment(?config(context, Config), Req, ?STRING),
#{<<"transactionInfo">> := #{<<"extra_payment_info">> := _}} = Payment.
-spec create_payment_with_changed_cost_ok_test(config()) -> _.
create_payment_with_changed_cost_ok_test(Config) ->
BenderKey = <<"bender_key">>,
ExternalID = <<"merch_id">>,
ChangedCost = 1000,
_ = capi_ct_helper:mock_services(
[
{invoicing, fun
('Get', _) ->
{ok, ?PAYPROC_INVOICE};
('StartPayment', {_, PaymentParams}) ->
#payproc_InvoicePaymentParams{
id = ID,
payer = {payment_resource, _},
payer_session_info = ?PAYER_SESSION_INFO,
context = ?CONTENT
} =
PaymentParams,
{ok, ?PAYPROC_PAYMENT(?PAYMENT_W_CHANGED_COST(ID, ChangedCost))}
end},
{party_management, fun('GetShop', _) ->
{ok, ?SHOP}
end},
{bender, fun('GenerateID', _) ->
{ok, capi_ct_helper_bender:get_result(BenderKey)}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_payment_op_ctx(
<<"CreatePayment">>,
?STRING,
?STRING,
?STRING,
Config
),
PaymentTool = {bank_card, ?BANK_CARD(<<"visa">>, ?EXP_DATE(2, 2020), <<"Degus">>)},
PaymentToolToken = capi_crypto:encode_token(#{payment_tool => PaymentTool, valid_until => undefined}),
Req = ?PAYMENT_PARAMS(ExternalID, PaymentToolToken),
{ok, Payment} = capi_client_payments:create_payment(?config(context, Config), Req, ?STRING),
#{<<"amount">> := ChangedCost} = Payment.
-spec create_refund(config()) -> _.
create_refund(Config) ->
BenderKey = <<"bender_key">>,

View File

@ -39,13 +39,15 @@
bank_account = ?INVOICE_BANK_ACCOUNT
}).
-define(CASH, #domain_Cash{
amount = ?INTEGER,
-define(CASH(Amount), #domain_Cash{
amount = Amount,
currency = #domain_CurrencyRef{
symbolic_code = ?RUB
}
}).
-define(CASH, ?CASH(?INTEGER)).
-define(CONTENT, #base_Content{
type = <<"application/json">>,
data = ?JSON_SERIAL
@ -307,7 +309,7 @@
-define(PAYMENT_STATUS_PENDING, {pending, #domain_InvoicePaymentPending{}}).
-define(PAYMENT_STATUS_FAILED(F), {failed, #domain_InvoicePaymentFailed{failure = F}}).
-define(PAYMENT(ID, Status, Payer, ExternalID), #domain_InvoicePayment{
-define(PAYMENT(ID, Status, Payer, ExternalID, ChangedCost), #domain_InvoicePayment{
id = ID,
created_at = ?TIMESTAMP,
domain_revision = ?INTEGER,
@ -315,19 +317,22 @@
payer = Payer,
payer_session_info = ?PAYER_SESSION_INFO,
cost = ?CASH,
changed_cost = ChangedCost,
flow = {instant, #domain_InvoicePaymentFlowInstant{}},
context = ?CONTENT,
make_recurrent = false,
external_id = ExternalID
}).
-define(PAYMENT(ID, Status, Payer), ?PAYMENT(ID, Status, Payer, undefined)).
-define(PAYMENT(ID, Status, Payer), ?PAYMENT(ID, Status, Payer, undefined, undefined)).
-define(PAYMENT, ?PAYMENT(?STRING, ?PAYMENT_STATUS_PENDING, ?PAYER)).
-define(PAYMENT_WITH_RECURRENT_PAYER, ?PAYMENT(?STRING, ?PAYMENT_STATUS_PENDING, ?RECURRENT_PAYER)).
-define(PAYMENT_WITH_CUSTOMER_PAYER, ?PAYMENT(?STRING, ?PAYMENT_STATUS_PENDING, ?CUSTOMER_PAYER)).
-define(PAYMENT_W_EXTERNAL_ID(ID, ExternalID), ?PAYMENT(ID, ?PAYMENT_STATUS_PENDING, ?PAYER, ExternalID)).
-define(PAYMENT_W_EXTERNAL_ID(ID, ExternalID), ?PAYMENT(ID, ?PAYMENT_STATUS_PENDING, ?PAYER, ExternalID, undefined)).
-define(PAYMENT_W_CHANGED_COST(ID, Amount), ?PAYMENT(ID, ?PAYMENT_STATUS_PENDING, ?PAYER, undefined, ?CASH(Amount))).
-define(RECURRENT_PAYMENT(Status), #domain_InvoicePayment{
id = ?STRING,

View File

@ -40,7 +40,7 @@
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"958e5f023870019d5fea668e52ed74d2d45d7d42"}},
{ref,"23211ff8c0c45699fa6d78afa55f304e95dbee87"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",