mirror of
https://github.com/valitydev/capi-v2.git
synced 2024-11-06 01:55:20 +00:00
INT-915: Put changed cash to payment cash (#42)
This commit is contained in:
parent
3401edb1ba
commit
14a41f5526
@ -149,7 +149,13 @@ decode_payment(InvoiceID, Payment, Context) ->
|
|||||||
#domain_Cash{
|
#domain_Cash{
|
||||||
amount = Amount,
|
amount = Amount,
|
||||||
currency = Currency
|
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(
|
capi_handler_utils:merge_and_compact(
|
||||||
#{
|
#{
|
||||||
<<"id">> => Payment#domain_InvoicePayment.id,
|
<<"id">> => Payment#domain_InvoicePayment.id,
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
get_payment_status_insufficient_funds_test/1,
|
get_payment_status_insufficient_funds_test/1,
|
||||||
|
|
||||||
create_payment_ok_test/1,
|
create_payment_ok_test/1,
|
||||||
|
create_payment_with_changed_cost_ok_test/1,
|
||||||
create_refund/1,
|
create_refund/1,
|
||||||
create_refund_blocked_error/1,
|
create_refund_blocked_error/1,
|
||||||
create_refund_expired_error/1,
|
create_refund_expired_error/1,
|
||||||
@ -212,6 +213,7 @@ groups() ->
|
|||||||
activate_shop_for_party_error_test,
|
activate_shop_for_party_error_test,
|
||||||
|
|
||||||
create_payment_ok_test,
|
create_payment_ok_test,
|
||||||
|
create_payment_with_changed_cost_ok_test,
|
||||||
retrieve_payment_by_external_id_test,
|
retrieve_payment_by_external_id_test,
|
||||||
retrieve_payment_by_external_id_for_party_test,
|
retrieve_payment_by_external_id_for_party_test,
|
||||||
check_no_payment_by_external_id_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),
|
{ok, Payment} = capi_client_payments:create_payment(?config(context, Config), Req, ?STRING),
|
||||||
#{<<"transactionInfo">> := #{<<"extra_payment_info">> := _}} = Payment.
|
#{<<"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()) -> _.
|
-spec create_refund(config()) -> _.
|
||||||
create_refund(Config) ->
|
create_refund(Config) ->
|
||||||
BenderKey = <<"bender_key">>,
|
BenderKey = <<"bender_key">>,
|
||||||
|
@ -39,13 +39,15 @@
|
|||||||
bank_account = ?INVOICE_BANK_ACCOUNT
|
bank_account = ?INVOICE_BANK_ACCOUNT
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-define(CASH, #domain_Cash{
|
-define(CASH(Amount), #domain_Cash{
|
||||||
amount = ?INTEGER,
|
amount = Amount,
|
||||||
currency = #domain_CurrencyRef{
|
currency = #domain_CurrencyRef{
|
||||||
symbolic_code = ?RUB
|
symbolic_code = ?RUB
|
||||||
}
|
}
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
-define(CASH, ?CASH(?INTEGER)).
|
||||||
|
|
||||||
-define(CONTENT, #base_Content{
|
-define(CONTENT, #base_Content{
|
||||||
type = <<"application/json">>,
|
type = <<"application/json">>,
|
||||||
data = ?JSON_SERIAL
|
data = ?JSON_SERIAL
|
||||||
@ -307,7 +309,7 @@
|
|||||||
-define(PAYMENT_STATUS_PENDING, {pending, #domain_InvoicePaymentPending{}}).
|
-define(PAYMENT_STATUS_PENDING, {pending, #domain_InvoicePaymentPending{}}).
|
||||||
-define(PAYMENT_STATUS_FAILED(F), {failed, #domain_InvoicePaymentFailed{failure = F}}).
|
-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,
|
id = ID,
|
||||||
created_at = ?TIMESTAMP,
|
created_at = ?TIMESTAMP,
|
||||||
domain_revision = ?INTEGER,
|
domain_revision = ?INTEGER,
|
||||||
@ -315,19 +317,22 @@
|
|||||||
payer = Payer,
|
payer = Payer,
|
||||||
payer_session_info = ?PAYER_SESSION_INFO,
|
payer_session_info = ?PAYER_SESSION_INFO,
|
||||||
cost = ?CASH,
|
cost = ?CASH,
|
||||||
|
changed_cost = ChangedCost,
|
||||||
flow = {instant, #domain_InvoicePaymentFlowInstant{}},
|
flow = {instant, #domain_InvoicePaymentFlowInstant{}},
|
||||||
context = ?CONTENT,
|
context = ?CONTENT,
|
||||||
make_recurrent = false,
|
make_recurrent = false,
|
||||||
external_id = ExternalID
|
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, ?PAYMENT(?STRING, ?PAYMENT_STATUS_PENDING, ?PAYER)).
|
||||||
|
|
||||||
-define(PAYMENT_WITH_RECURRENT_PAYER, ?PAYMENT(?STRING, ?PAYMENT_STATUS_PENDING, ?RECURRENT_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_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{
|
-define(RECURRENT_PAYMENT(Status), #domain_InvoicePayment{
|
||||||
id = ?STRING,
|
id = ?STRING,
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
|
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
|
||||||
{<<"damsel">>,
|
{<<"damsel">>,
|
||||||
{git,"https://github.com/valitydev/damsel.git",
|
{git,"https://github.com/valitydev/damsel.git",
|
||||||
{ref,"958e5f023870019d5fea668e52ed74d2d45d7d42"}},
|
{ref,"23211ff8c0c45699fa6d78afa55f304e95dbee87"}},
|
||||||
0},
|
0},
|
||||||
{<<"dmt_client">>,
|
{<<"dmt_client">>,
|
||||||
{git,"https://github.com/valitydev/dmt_client.git",
|
{git,"https://github.com/valitydev/dmt_client.git",
|
||||||
|
Loading…
Reference in New Issue
Block a user