TD-286: Remove userinfo and update protocols (#12)

This commit is contained in:
Alexey S 2022-05-16 18:13:45 +03:00 committed by GitHub
parent 8327dba201
commit cf18b3d955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 57 additions and 150 deletions

View File

@ -5,7 +5,7 @@
-type id() :: binary().
-type idempotent_key_prefix() :: binary() | atom().
-type external_id() :: binary().
-type issuer_id() :: dmsl_domain_thrift:'PartyID'() | dmsl_payment_processing_thrift:'UserID'().
-type issuer_id() :: dmsl_domain_thrift:'PartyID'().
-type idempotent_key() :: binary().
-type idempotent_key_params() :: {idempotent_key_prefix(), issuer_id(), external_id() | undefined}.

View File

@ -191,7 +191,7 @@ build_invoice_ctx(ID, WoodyCtx) when is_binary(ID) ->
maybe_with_woody_result(
invoicing,
'Get',
{_UserInfo = undefined, ID, #payproc_EventRange{}},
{ID, #payproc_EventRange{}},
WoodyCtx,
fun build_invoice_ctx/1
);
@ -219,7 +219,7 @@ build_invoice_template_ctx(ID, WoodyCtx) when is_binary(ID) ->
maybe_with_woody_result(
invoice_templating,
'Get',
{_UserInfo = undefined, ID},
{ID},
WoodyCtx,
fun build_invoice_template_ctx/1
);

View File

@ -94,8 +94,6 @@ prepare(OperationID = 'GetContractsForParty', Req, Context) ->
case capi_party:get_party(PartyID, Context) of
{ok, Party} ->
{ok, {200, #{}, decode_contracts_map(Party#domain_Party.contracts, Party#domain_Party.contractors)}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)}
end
@ -160,8 +158,6 @@ get_contract_or_fail(PartyID, ContractID, Context) ->
case capi_party:get_contract(PartyID, ContractID, Context) of
{ok, Contract} ->
Contract;
{error, #payproc_InvalidUser{}} ->
capi_handler:respond(general_error(404, <<"Party not found">>));
{error, #payproc_PartyNotFound{}} ->
capi_handler:respond(general_error(404, <<"Party not found">>));
{error, #payproc_ContractNotFound{}} ->

View File

@ -36,8 +36,6 @@ prepare('CreateCustomer' = OperationID, Req, Context) ->
case capi_handler_utils:service_call(Call, Context) of
{ok, Customer} ->
{ok, {201, #{}, make_customer_and_token(Customer, Context)}};
{exception, #payproc_InvalidUser{}} ->
{ok, logic_error('invalidPartyID', <<"Party not found">>)};
{exception, #payproc_InvalidPartyStatus{}} ->
{ok, logic_error('invalidPartyStatus', <<"Invalid party status">>)};
{exception, #payproc_InvalidShopStatus{}} ->
@ -88,8 +86,6 @@ prepare('DeleteCustomer' = OperationID, Req, Context) ->
case capi_handler_utils:service_call(Call, Context) of
{ok, _} ->
{ok, {204, #{}, undefined}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_CustomerNotFound{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_InvalidPartyStatus{}} ->
@ -156,8 +152,6 @@ prepare('CreateBinding' = OperationID, Req, Context) ->
case Result of
{ok, CustomerBinding} ->
{ok, {201, #{}, decode_customer_binding(CustomerBinding)}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_CustomerNotFound{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_InvalidPartyStatus{}} ->
@ -237,8 +231,6 @@ prepare('GetCustomerEvents' = OperationID, Req, Context) ->
case Result of
{ok, Events} when is_list(Events) ->
{ok, {200, #{}, Events}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_CustomerNotFound{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_EventNotFound{}} ->
@ -268,8 +260,6 @@ prepare('GetCustomerPaymentMethods' = OperationID, Req, Context) ->
PaymentMethods1 = capi_utils:deduplicate_payment_methods(PaymentMethods0),
PaymentMethods = capi_handler_utils:emplace_token_provider_data(Customer, PaymentMethods1, Context),
{ok, {200, #{}, PaymentMethods}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Customer not found">>)};
{exception, #payproc_CustomerNotFound{}} ->
{ok, general_error(404, <<"Customer not found">>)}
end

View File

@ -28,8 +28,7 @@ prepare('CreateInvoiceTemplate' = OperationID, Req, Context) ->
try
InvoiceTemplateID = generate_invoice_template_id(OperationID, InvoiceTemplateParams, PartyID, Context),
CallArgs = {encode_invoice_tpl_create_params(InvoiceTemplateID, PartyID, InvoiceTemplateParams)},
capi_handler_utils:service_call_with(
[user_info],
capi_handler_utils:service_call(
{invoice_templating, 'Create', CallArgs},
Context
)
@ -39,7 +38,7 @@ prepare('CreateInvoiceTemplate' = OperationID, Req, Context) ->
{exception, #'InvalidRequest'{errors = Errors}} ->
FormattedErrors = capi_handler_utils:format_request_errors(Errors),
{ok, logic_error('invalidRequest', FormattedErrors)};
{exception, #payproc_InvalidUser{}} ->
{exception, #payproc_PartyNotFound{}} ->
{ok, logic_error('invalidPartyID', <<"Party not found">>)};
{exception, #payproc_ShopNotFound{}} ->
{ok, logic_error('invalidShopID', <<"Shop not found">>)};
@ -87,12 +86,10 @@ prepare('UpdateInvoiceTemplate' = OperationID, Req, Context) ->
try
Params = encode_invoice_tpl_update_params(maps:get('InvoiceTemplateUpdateParams', Req)),
Call = {invoice_templating, 'Update', {InvoiceTemplateID, Params}},
capi_handler_utils:service_call_with([user_info], Call, Context)
capi_handler_utils:service_call(Call, Context)
of
{ok, UpdatedInvoiceTpl} ->
{ok, {200, #{}, decode_invoice_tpl(UpdatedInvoiceTpl)}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice Template not found">>)};
{exception, #'InvalidRequest'{errors = Errors}} ->
FormattedErrors = capi_handler_utils:format_request_errors(Errors),
{ok, logic_error('invalidRequest', FormattedErrors)};
@ -105,8 +102,6 @@ prepare('UpdateInvoiceTemplate' = OperationID, Req, Context) ->
{exception, #payproc_InvoiceTemplateRemoved{}} ->
{ok, general_error(404, <<"Invoice Template not found">>)}
catch
throw:#payproc_InvalidUser{} ->
{ok, general_error(404, <<"Invoice Template not found">>)};
throw:#payproc_InvoiceTemplateNotFound{} ->
{ok, general_error(404, <<"Invoice Template not found">>)};
throw:#payproc_InvoiceTemplateRemoved{} ->
@ -130,11 +125,9 @@ prepare('DeleteInvoiceTemplate' = OperationID, Req, Context) ->
end,
Process = fun() ->
Call = {invoice_templating, 'Delete', {InvoiceTemplateID}},
case capi_handler_utils:service_call_with([user_info], Call, Context) of
case capi_handler_utils:service_call(Call, Context) of
{ok, _R} ->
{ok, {204, #{}, undefined}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice Template not found">>)};
{exception, #payproc_InvalidPartyStatus{}} ->
{ok, logic_error('invalidPartyStatus', <<"Invalid party status">>)};
{exception, #payproc_InvalidShopStatus{}} ->
@ -164,8 +157,6 @@ prepare('CreateInvoiceWithTemplate' = OperationID, Req, Context) ->
try create_invoice(PartyID, InvoiceTplID, InvoiceParams, Context, OperationID) of
{ok, #'payproc_Invoice'{invoice = Invoice}} ->
{ok, {201, #{}, capi_handler_decoder_invoicing:make_invoice_and_token(Invoice, Context)}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice Template not found">>)};
{exception, #'InvalidRequest'{errors = Errors}} ->
FormattedErrors = capi_handler_utils:format_request_errors(Errors),
{ok, logic_error('invalidRequest', FormattedErrors)};
@ -216,7 +207,6 @@ prepare('GetInvoicePaymentMethodsByTemplateID' = OperationID, Req, Context) ->
),
{ok, {200, #{}, PaymentMethods}};
{exception, E} when
E == #payproc_InvalidUser{};
E == #payproc_InvoiceTemplateNotFound{};
E == #payproc_InvoiceTemplateRemoved{}
->
@ -249,11 +239,11 @@ create_invoice(PartyID, InvoiceTplID, InvoiceParams, Context, BenderPrefix) ->
InvoiceID = capi_bender:gen_snowflake(IdempotentKey, Identity, WoodyCtx),
CallArgs = {encode_invoice_params_with_tpl(InvoiceID, InvoiceTplID, InvoiceParams)},
Call = {invoicing, 'CreateWithTemplate', CallArgs},
capi_handler_utils:service_call_with([user_info], Call, Context).
capi_handler_utils:service_call(Call, Context).
get_invoice_template(ID, Context) ->
Call = {invoice_templating, 'Get', {ID}},
capi_handler_utils:service_call_with([user_info], Call, Context).
capi_handler_utils:service_call(Call, Context).
generate_invoice_template_id(OperationID, TemplateParams, PartyID, #{woody_context := WoodyContext}) ->
ExternalID = maps:get(<<"externalID">>, TemplateParams, undefined),

View File

@ -34,7 +34,7 @@ prepare('CreateInvoice' = OperationID, Req, Context) ->
case create_invoice(PartyID, InvoiceParams, Context, OperationID) of
{ok, #'payproc_Invoice'{invoice = Invoice}} ->
{ok, {201, #{}, capi_handler_decoder_invoicing:make_invoice_and_token(Invoice, Context)}};
{exception, #'payproc_InvalidUser'{}} ->
{exception, #'payproc_PartyNotFound'{}} ->
{ok, logic_error('invalidPartyID', <<"Party not found">>)};
{exception, #'InvalidRequest'{errors = Errors}} ->
FormattedErrors = capi_handler_utils:format_request_errors(Errors),
@ -142,7 +142,7 @@ prepare('FulfillInvoice' = OperationID, Req, Context) ->
Process = fun() ->
CallArgs = {InvoiceID, maps:get(<<"reason">>, maps:get('Reason', Req))},
Call = {invoicing, 'Fulfill', CallArgs},
case capi_handler_utils:service_call_with([user_info], Call, Context) of
case capi_handler_utils:service_call(Call, Context) of
{ok, _} ->
{ok, {204, #{}, undefined}};
{exception, #payproc_InvalidInvoiceStatus{}} ->
@ -151,8 +151,6 @@ prepare('FulfillInvoice' = OperationID, Req, Context) ->
{ok, logic_error('invalidPartyStatus', <<"Invalid party status">>)};
{exception, #payproc_InvalidShopStatus{}} ->
{ok, logic_error('invalidShopStatus', <<"Invalid shop status">>)};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)}
end
@ -171,7 +169,7 @@ prepare('RescindInvoice' = OperationID, Req, Context) ->
Process = fun() ->
CallArgs = {InvoiceID, maps:get(<<"reason">>, maps:get('Reason', Req))},
Call = {invoicing, 'Rescind', CallArgs},
case capi_handler_utils:service_call_with([user_info], Call, Context) of
case capi_handler_utils:service_call(Call, Context) of
{ok, _} ->
{ok, {204, #{}, undefined}};
{exception, #payproc_InvalidInvoiceStatus{}} ->
@ -182,8 +180,6 @@ prepare('RescindInvoice' = OperationID, Req, Context) ->
{ok, logic_error('invalidPartyStatus', <<"Invalid party status">>)};
{exception, #payproc_InvalidShopStatus{}} ->
{ok, logic_error('invalidShopStatus', <<"Invalid shop status">>)};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)}
end
@ -205,8 +201,7 @@ prepare('GetInvoiceEvents' = OperationID, Req, Context) ->
maps:get('limit', Req),
genlib_map:get('eventID', Req),
fun(Range) ->
capi_handler_utils:service_call_with(
[user_info],
capi_handler_utils:service_call(
{invoicing, 'GetEvents', {maps:get('invoiceID', Req), Range}},
Context
)
@ -216,8 +211,6 @@ prepare('GetInvoiceEvents' = OperationID, Req, Context) ->
case Result of
{ok, Events} when is_list(Events) ->
{ok, {200, #{}, Events}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_EventNotFound{}} ->
@ -252,8 +245,6 @@ prepare('GetInvoicePaymentMethods' = OperationID, Req, Context) ->
PaymentMethods1 = capi_utils:deduplicate_payment_methods(PaymentMethods0),
PaymentMethods = capi_handler_utils:emplace_token_provider_data(Invoice, PaymentMethods1, Context),
{ok, {200, #{}, PaymentMethods}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)}
end
@ -277,7 +268,7 @@ create_invoice(PartyID, InvoiceParams, Context, BenderPrefix) ->
Identity = capi_bender:make_identity(capi_feature_schemas:invoice(), InvoiceParams),
InvoiceID = capi_bender:gen_snowflake(IdempotentKey, Identity, WoodyCtx),
Call = {invoicing, 'Create', {encode_invoice_params(InvoiceID, PartyID, InvoiceParams)}},
capi_handler_utils:service_call_with([user_info], Call, Context).
capi_handler_utils:service_call(Call, Context).
encode_invoice_params(ID, PartyID, InvoiceParams) ->
Amount = genlib_map:get(<<"amount">>, InvoiceParams),

View File

@ -26,8 +26,6 @@ prepare('GetMyParty' = OperationID, _Req, Context) ->
{ok, Party} ->
DecodedParty = capi_handler_decoder_party:decode_party(Party),
{ok, {200, #{}, DecodedParty}};
{error, #payproc_InvalidUser{}} ->
{ok, logic_error(<<"invalidRequest">>, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, logic_error(<<"invalidRequest">>, <<"Party not found">>)}
end
@ -43,8 +41,6 @@ prepare('ActivateMyParty' = OperationID, _Req, Context) ->
case capi_party:activate_party(PartyID, Context) of
ok ->
{ok, {204, #{}, undefined}};
{error, #payproc_InvalidUser{}} ->
{ok, logic_error(<<"invalidRequest">>, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, logic_error(<<"invalidRequest">>, <<"Party not found">>)};
{error, #payproc_InvalidPartyStatus{status = {suspension, {active, _}}}} ->
@ -62,8 +58,6 @@ prepare('SuspendMyParty' = OperationID, _Req, Context) ->
case capi_party:suspend_party(PartyID, Context) of
ok ->
{ok, {204, #{}, undefined}};
{error, #payproc_InvalidUser{}} ->
{ok, logic_error(<<"invalidRequest">>, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, logic_error(<<"invalidRequest">>, <<"Party not found">>)};
{error, #payproc_InvalidPartyStatus{status = {suspension, {suspended, _}}}} ->
@ -82,8 +76,6 @@ prepare('GetPartyByID' = OperationID, Req, Context) ->
{ok, Party} ->
DecodedParty = capi_handler_decoder_party:decode_party(Party),
{ok, {200, #{}, DecodedParty}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)}
end
@ -99,8 +91,6 @@ prepare('ActivatePartyByID' = OperationID, Req, Context) ->
case capi_party:activate_party(PartyID, Context) of
ok ->
{ok, {204, #{}, undefined}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_InvalidPartyStatus{status = {suspension, {active, _}}}} ->
@ -118,8 +108,6 @@ prepare('SuspendPartyByID' = OperationID, Req, Context) ->
case capi_party:suspend_party(PartyID, Context) of
ok ->
{ok, {204, #{}, undefined}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_InvalidPartyStatus{status = {suspension, {suspended, _}}}} ->

View File

@ -49,8 +49,6 @@ prepare(OperationID = 'CreatePayment', Req, Context) ->
{ok, logic_error('invalidContractStatus', <<"Invalid contract status">>)};
{exception, #payproc_InvalidRecurrentParentPayment{}} ->
{ok, logic_error('invalidRecurrentParent', <<"Specified recurrent parent is invalid">>)};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)}
end
@ -160,7 +158,7 @@ prepare(OperationID = 'CapturePayment', Req, Context) ->
},
CallArgs = {InvoiceID, PaymentID, CaptureParams},
Call = {invoicing, 'CapturePayment', CallArgs},
capi_handler_utils:service_call_with([user_info], Call, Context)
capi_handler_utils:service_call(Call, Context)
of
{ok, _} ->
{ok, {202, #{}, undefined}};
@ -168,8 +166,6 @@ prepare(OperationID = 'CapturePayment', Req, Context) ->
{ok, general_error(404, <<"Payment not found">>)};
{exception, #payproc_InvalidPaymentStatus{}} ->
{ok, logic_error('invalidPaymentStatus', <<"Invalid payment status">>)};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #'InvalidRequest'{errors = Errors}} ->
@ -224,15 +220,13 @@ prepare(OperationID = 'CancelPayment', Req, Context) ->
Reason = maps:get(<<"reason">>, maps:get('Reason', Req)),
CallArgs = {InvoiceID, PaymentID, Reason},
Call = {invoicing, 'CancelPayment', CallArgs},
case capi_handler_utils:service_call_with([user_info], Call, Context) of
case capi_handler_utils:service_call(Call, Context) of
{ok, _} ->
{ok, {202, #{}, undefined}};
{exception, #payproc_InvoicePaymentNotFound{}} ->
{ok, general_error(404, <<"Payment not found">>)};
{exception, #payproc_InvalidPaymentStatus{}} ->
{ok, logic_error('invalidPaymentStatus', <<"Invalid payment status">>)};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #'InvalidRequest'{errors = Errors}} ->
@ -265,8 +259,6 @@ prepare(OperationID = 'CreateRefund', Req, Context) ->
of
{ok, Refund} ->
{ok, {201, #{}, capi_handler_decoder_invoicing:decode_refund(Refund)}};
{exception, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Invoice not found">>)};
{exception, #payproc_InvoicePaymentNotFound{}} ->
{ok, general_error(404, <<"Payment not found">>)};
{exception, #payproc_InvoiceNotFound{}} ->
@ -481,7 +473,7 @@ create_payment(Invoice, PaymentParams, Context, OperationID) ->
ExternalID = maps:get(<<"externalID">>, PaymentParams, undefined),
InvoicePaymentParams = encode_invoice_payment_params(PaymentID, ExternalID, PaymentParams, PaymentTool),
Call = {invoicing, 'StartPayment', {InvoiceID, InvoicePaymentParams}},
capi_handler_utils:service_call_with([user_info], Call, Context).
capi_handler_utils:service_call(Call, Context).
create_payment_id(Invoice, PaymentParams0, Context, OperationID, PaymentToolThrift) ->
InvoiceID = Invoice#domain_Invoice.id,
@ -542,8 +534,6 @@ get_invoice_by_id(InvoiceID, Context) ->
case capi_handler_utils:get_invoice_by_id(InvoiceID, Context) of
{ok, Invoice} ->
Invoice;
{exception, #payproc_InvalidUser{}} ->
undefined;
{exception, #payproc_InvoiceNotFound{}} ->
undefined
end.
@ -732,7 +722,7 @@ refund_payment(RefundID, InvoiceID, PaymentID, RefundParams, Context) ->
Params#payproc_InvoicePaymentRefundParams{id = RefundID}
},
Call = {invoicing, 'RefundPayment', CallArgs},
capi_handler_utils:service_call_with([user_info], Call, Context).
capi_handler_utils:service_call(Call, Context).
%% ED-206
%% When bouncer says "forbidden" we can't really tell the difference between "forbidden because

View File

@ -330,12 +330,12 @@ decode_bank_card_details(BankCard, V) ->
<<"tokenProvider">> => BankCardTokenServiceRef
}).
decode_payment_terminal_details(#merchstat_PaymentTerminal{terminal_type = Type}, V) ->
decode_payment_terminal_details(#merchstat_PaymentTerminal{terminal_type_deprecated = Type}, V) ->
V#{
<<"provider">> => genlib:to_binary(Type)
}.
decode_digital_wallet_details(#merchstat_DigitalWallet{provider = qiwi, id = ID}, V) ->
decode_digital_wallet_details(#merchstat_DigitalWallet{provider_deprecated = qiwi, id = ID}, V) ->
V#{
<<"digitalWalletDetailsType">> => <<"DigitalWalletDetailsQIWI">>,
<<"phoneNumberMask">> => mask_phone_number(ID)
@ -344,7 +344,7 @@ decode_digital_wallet_details(#merchstat_DigitalWallet{provider = qiwi, id = ID}
mask_phone_number(PhoneNumber) ->
capi_utils:redact(PhoneNumber, <<"^\\+\\d(\\d{1,10}?)\\d{2,4}$">>).
decode_geo_location_info(#geo_ip_LocationInfo{city_geo_id = CityID, country_geo_id = CountryID}) ->
decode_geo_location_info(#columbus_LocationInfo{city_geo_id = CityID, country_geo_id = CountryID}) ->
#{
<<"cityGeoID">> => CityID,
<<"countryGeoID">> => CountryID

View File

@ -71,6 +71,8 @@ prepare(OperationID = 'GetShopByID', Req, Context) ->
case capi_party:get_shop(PartyID, ShopID, Context) of
{ok, Shop} ->
{ok, {200, #{}, decode_shop(Shop)}};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Shop not found">>)};
{error, #payproc_ShopNotFound{}} ->
{ok, general_error(404, <<"Shop not found">>)}
end
@ -86,8 +88,6 @@ prepare(OperationID = 'GetShopsForParty', Req, Context) ->
case capi_party:get_party(PartyID, Context) of
{ok, Party} ->
{ok, {200, #{}, decode_shops_map(Party#domain_Party.shops)}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)}
end
@ -104,8 +104,6 @@ prepare(OperationID = 'GetShopByIDForParty', Req, Context) ->
case capi_party:get_shop(PartyID, ShopID, Context) of
{ok, Shop} ->
{ok, {200, #{}, decode_shop(Shop)}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_ShopNotFound{}} ->
@ -124,8 +122,6 @@ prepare(OperationID = 'ActivateShopForParty', Req, Context) ->
case capi_party:activate_shop(PartyID, ShopID, Context) of
ok ->
{ok, {204, #{}, undefined}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_ShopNotFound{}} ->
@ -146,8 +142,6 @@ prepare(OperationID = 'SuspendShopForParty', Req, Context) ->
case capi_party:suspend_shop(PartyID, ShopID, Context) of
ok ->
{ok, {204, #{}, undefined}};
{error, #payproc_InvalidUser{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_PartyNotFound{}} ->
{ok, general_error(404, <<"Party not found">>)};
{error, #payproc_ShopNotFound{}} ->

View File

@ -13,13 +13,11 @@
-export([assert_party_accessible/2]).
-export([run_if_party_accessible/3]).
-export([service_call_with/3]).
-export([service_call/2]).
-export([map_service_result/1]).
-export([get_auth_context/1]).
-export([get_woody_context/1]).
-export([get_user_info/1]).
-export([get_subject_id/1]).
-export([get_user_id/1]).
-export([get_party_id/1]).
@ -94,21 +92,6 @@ format_request_errors(Errors) -> genlib_string:join(<<"\n">>, Errors).
%%%
% Нужно быть аккуратным с флагами их порядок влияет на порядок аргументов при вызове функций!
% обычно параметры идут в порядке [user_info, party_id],
% но это зависит от damsel протокола
-spec service_call_with(list(atom()), {atom(), atom(), tuple()}, processing_context()) -> woody:result().
service_call_with(Flags, Call, Context) ->
% реверс тут чтобы в флагах писать порядок аналогично вызову функций
service_call_with_(lists:reverse(Flags), Call, Context).
service_call_with_([user_info | T], {ServiceName, Function, Args}, Context) ->
service_call_with_(T, {ServiceName, Function, append_to_tuple(get_user_info(Context), Args)}, Context);
service_call_with_([party_id | T], {ServiceName, Function, Args}, Context) ->
service_call_with_(T, {ServiceName, Function, append_to_tuple(get_party_id(Context), Args)}, Context);
service_call_with_([], Call, Context) ->
service_call(Call, Context).
-spec service_call({atom(), atom(), tuple()}, processing_context()) -> woody:result().
service_call({ServiceName, Function, Args}, #{woody_context := WoodyContext}) ->
capi_woody_client:call_service(ServiceName, Function, Args, WoodyContext).
@ -127,13 +110,6 @@ get_auth_context(#{swagger_context := #{auth_context := AuthContext}}) ->
get_woody_context(#{woody_context := WoodyContext}) ->
WoodyContext.
-spec get_user_info(processing_context()) -> dmsl_payment_processing_thrift:'UserInfo'().
get_user_info(Context) ->
#payproc_UserInfo{
id = get_user_id(Context),
type = {external_user, #payproc_ExternalUser{}}
}.
-spec get_subject_id(processing_context()) -> binary().
get_subject_id(Context) ->
capi_auth:get_subject_id(get_auth_context(Context)).
@ -152,10 +128,6 @@ get_party_id(Context) ->
%% Utils
-spec append_to_tuple(any(), tuple()) -> tuple().
append_to_tuple(Item, Tuple) ->
list_to_tuple([Item | tuple_to_list(Tuple)]).
-spec issue_access_token(token_source(), processing_context()) -> map().
issue_access_token(#domain_Invoice{} = Invoice, ProcessingContext) ->
TokenSpec = #{
@ -295,19 +267,19 @@ wrap_payment_session(ClientInfo, PaymentSession) ->
get_invoice_by_id(InvoiceID, Context) ->
EventRange = #payproc_EventRange{},
Args = {InvoiceID, EventRange},
service_call_with([user_info], {invoicing, 'Get', Args}, Context).
service_call({invoicing, 'Get', Args}, Context).
-spec get_payment_by_id(binary(), binary(), processing_context()) -> woody:result().
get_payment_by_id(InvoiceID, PaymentID, Context) ->
service_call_with([user_info], {invoicing, 'GetPayment', {InvoiceID, PaymentID}}, Context).
service_call({invoicing, 'GetPayment', {InvoiceID, PaymentID}}, Context).
-spec get_refund_by_id(binary(), binary(), binary(), processing_context()) -> woody:result().
get_refund_by_id(InvoiceID, PaymentID, RefundID, Context) ->
service_call_with([user_info], {invoicing, 'GetPaymentRefund', {InvoiceID, PaymentID, RefundID}}, Context).
service_call({invoicing, 'GetPaymentRefund', {InvoiceID, PaymentID, RefundID}}, Context).
-spec get_payment_methods(atom(), tuple(), processing_context()) -> woody:result().
get_payment_methods(ServiceName, Args, Context) ->
case service_call_with([user_info], {ServiceName, 'ComputeTerms', Args}, Context) of
case service_call({ServiceName, 'ComputeTerms', Args}, Context) of
{ok, #domain_TermSet{payments = undefined}} ->
{ok, []};
{ok, #domain_TermSet{

View File

@ -29,8 +29,6 @@ prepare('CreateWebhook' = OperationID, Req, Context) ->
case capi_party:get_shop(PartyID, ShopID, Context) of
{ok, _} ->
ok;
{error, #payproc_InvalidUser{}} ->
capi_handler:respond(logic_error('invalidPartyID', <<"Party not found">>));
{error, #payproc_ShopNotFound{}} ->
capi_handler:respond(logic_error('invalidShopID', <<"Shop not found">>))
end,

View File

@ -351,8 +351,8 @@ create_invoice_ok_test(Config) ->
create_invoice_autorization_error_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Create', {_, #payproc_InvoiceParams{party_id = <<"WrongPartyID">>}}) ->
{throwing, #payproc_InvalidUser{}}
{invoicing, fun('Create', {#payproc_InvoiceParams{party_id = <<"WrongPartyID">>}}) ->
{throwing, #payproc_PartyNotFound{}}
end},
{generator, fun('GenerateID', _) -> capi_ct_helper_bender:generate_id(<<"bender_key">>) end}
],
@ -412,7 +412,7 @@ create_invoice_access_token_ok_test(Config) ->
create_invoice_template_ok_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{invoice_templating, fun('Create', {_, #payproc_InvoiceTemplateCreateParams{party_id = ?STRING}}) ->
{invoice_templating, fun('Create', {#payproc_InvoiceTemplateCreateParams{party_id = ?STRING}}) ->
{ok, ?INVOICE_TPL}
end},
{generator, fun('GenerateID', _) -> capi_ct_helper_bender:generate_id(<<"bender_key">>) end}
@ -446,9 +446,9 @@ create_invoice_template_autorization_error_test(Config) ->
[
{invoice_templating, fun(
'Create',
{_, #payproc_InvoiceTemplateCreateParams{party_id = <<"WrongPartyID">>}}
{#payproc_InvoiceTemplateCreateParams{party_id = <<"WrongPartyID">>}}
) ->
{throwing, #payproc_InvalidUser{}}
{throwing, #payproc_PartyNotFound{}}
end},
{generator, fun('GenerateID', _) -> capi_ct_helper_bender:generate_id(<<"bender_key">>) end}
],
@ -489,7 +489,7 @@ create_invoice_with_template_test(Config) ->
end},
{invoicing, fun(
'CreateWithTemplate',
{_UserInfo, #payproc_InvoiceWithTemplateParams{id = ID, external_id = EID}}
{#payproc_InvoiceWithTemplateParams{id = ID, external_id = EID}}
) ->
{ok, ?PAYPROC_INVOICE_WITH_ID(ID, EID)}
end},
@ -556,7 +556,7 @@ create_customer_autorization_error_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{customer_management, fun('Create', {#payproc_CustomerParams{party_id = <<"WrongPartyID">>}}) ->
{throwing, #payproc_InvalidUser{}}
{throwing, #payproc_PartyNotFound{}}
end},
{generator, fun('GenerateID', _) -> capi_ct_helper_bender:generate_id(<<"bender_key">>) end}
],
@ -692,7 +692,7 @@ create_payment_ok_test(Config) ->
{invoicing, fun
('Get', _) ->
{ok, ?PAYPROC_INVOICE};
('StartPayment', {_, _, PaymentParams}) ->
('StartPayment', {_, PaymentParams}) ->
#payproc_InvoicePaymentParams{
id = ID,
external_id = EID,
@ -762,7 +762,7 @@ create_refund_blocked_error(Config) ->
('Get', _) ->
Invoice = ?PAYPROC_INVOICE,
{ok, Invoice#payproc_Invoice{payments = [?PAYPROC_PAYMENT]}};
('RefundPayment', {_, ?STRING, _, _}) ->
('RefundPayment', {?STRING, _, _}) ->
{throwing, #payproc_InvalidPartyStatus{
status = {blocking, {blocked, #domain_Blocked{reason = ?STRING, since = ?TIMESTAMP}}}
}}
@ -791,7 +791,7 @@ create_refund_expired_error(Config) ->
('Get', _) ->
Invoice = ?PAYPROC_INVOICE,
{ok, Invoice#payproc_Invoice{payments = [?PAYPROC_PAYMENT]}};
('RefundPayment', {_, ?STRING, _, _}) ->
('RefundPayment', {?STRING, _, _}) ->
{throwing, #payproc_InvalidContractStatus{status = {expired, #domain_ContractExpired{}}}}
end},
{generator, fun('GenerateID', _) -> capi_ct_helper_bender:generate_id(BenderKey) end}
@ -820,7 +820,6 @@ create_partial_refund(Config) ->
(
'RefundPayment',
{
_,
_,
_,
#payproc_InvoicePaymentRefundParams{
@ -1183,8 +1182,8 @@ get_shop_by_id_for_party_ok_test(Config) ->
get_shop_by_id_for_party_error_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{party_management, fun('GetShop', {_, <<"WrongPartyID">>, _}) ->
{throwing, #payproc_InvalidUser{}}
{party_management, fun('GetShop', {<<"WrongPartyID">>, _}) ->
{throwing, #payproc_PartyNotFound{}}
end}
],
Config
@ -1231,7 +1230,7 @@ get_shops_for_party_ok_test(Config) ->
-spec get_shops_for_party_error_test(config()) -> _.
get_shops_for_party_error_test(Config) ->
_ = capi_ct_helper:mock_services(
[{party_management, fun('GetRevision', {_, <<"WrongPartyID">>}) -> {throwing, #payproc_InvalidUser{}} end}],
[{party_management, fun('GetRevision', {<<"WrongPartyID">>}) -> {throwing, #payproc_PartyNotFound{}} end}],
Config
),
@ -1251,7 +1250,7 @@ activate_shop_ok_test(Config) ->
activate_shop_for_party_ok_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ActivateShop', {_, ?STRING, _}) -> {ok, ok} end}
{party_management, fun('ActivateShop', {?STRING, _}) -> {ok, ok} end}
],
Config
),
@ -1262,8 +1261,8 @@ activate_shop_for_party_ok_test(Config) ->
activate_shop_for_party_error_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ActivateShop', {_, <<"WrongPartyID">>, _}) ->
{throwing, #payproc_InvalidUser{}}
{party_management, fun('ActivateShop', {<<"WrongPartyID">>, _}) ->
{throwing, #payproc_PartyNotFound{}}
end}
],
Config
@ -1300,8 +1299,8 @@ suspend_shop_for_party_ok_test(Config) ->
suspend_shop_for_party_error_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{party_management, fun('SuspendShop', {_, <<"WrongPartyID">>, _}) ->
{throwing, #payproc_InvalidUser{}}
{party_management, fun('SuspendShop', {<<"WrongPartyID">>, _}) ->
{throwing, #payproc_PartyNotFound{}}
end}
],
Config

View File

@ -293,7 +293,7 @@ create_invoice_ok_test(Config) ->
ExternalID = <<"merch_id">>,
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Create', {_UserInfo, #payproc_InvoiceParams{id = ID, external_id = EID}}) ->
{invoicing, fun('Create', {#payproc_InvoiceParams{id = ID, external_id = EID}}) ->
{ok, ?PAYPROC_INVOICE_WITH_ID(ID, EID)}
end},
{bender, fun('GenerateID', _) -> {ok, capi_ct_helper_bender:get_result(BenderKey)} end}
@ -684,7 +684,7 @@ create_payment(BenderKey, Requests, Config) ->
{invoicing, fun
('Get', _) ->
{ok, ?PAYPROC_INVOICE};
('StartPayment', {_, _, IPP}) ->
('StartPayment', {_, IPP}) ->
#payproc_InvoicePaymentParams{id = ID, external_id = EID, context = ?CONTENT} = IPP,
{ok, ?PAYPROC_PAYMENT(ID, EID)}
end},
@ -710,7 +710,7 @@ create_invoices(BenderKey, Requests, Config) ->
Tid = capi_ct_helper_bender:create_storage(),
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Create', {_UserInfo, #payproc_InvoiceParams{id = ID, external_id = EID}}) ->
{invoicing, fun('Create', {#payproc_InvoiceParams{id = ID, external_id = EID}}) ->
{ok, ?PAYPROC_INVOICE_WITH_ID(ID, EID)}
end},
{bender, fun('GenerateID', {_, _, CtxMsgPack}) ->
@ -737,7 +737,7 @@ create_refunds(BenderKey, Requests, Config) ->
{ok, ?PAYPROC_INVOICE([?PAYPROC_PAYMENT])};
(
'RefundPayment',
{_, _, _, #payproc_InvoicePaymentRefundParams{id = ID, external_id = EID}}
{_, _, #payproc_InvoicePaymentRefundParams{id = ID, external_id = EID}}
) ->
{ok, ?REFUND(ID, EID)}
end},
@ -874,7 +874,7 @@ create_invoice_templates(BenderKey, Requests, Config) ->
[
{invoice_templating, fun(
'Create',
{_, #payproc_InvoiceTemplateCreateParams{template_id = TemplateID}}
{#payproc_InvoiceTemplateCreateParams{template_id = TemplateID}}
) ->
{ok, ?INVOICE_TPL(TemplateID)}
end},
@ -902,7 +902,7 @@ create_invoices_with_templates(BenderKey, Requests, Config) ->
end},
{invoicing, fun(
'CreateWithTemplate',
{_UserInfo, #payproc_InvoiceWithTemplateParams{id = ID, external_id = EID}}
{#payproc_InvoiceWithTemplateParams{id = ID, external_id = EID}}
) ->
{ok, ?PAYPROC_INVOICE_WITH_ID(ID, EID)}
end},

View File

@ -192,7 +192,7 @@ get_invoice_events_ok_test(Config) ->
_ = capi_ct_helper:mock_services(
[
{invoicing, fun
('GetEvents', {_, _, #payproc_EventRange{'after' = ID, limit = N}}) ->
('GetEvents', {_, #payproc_EventRange{'after' = ID, limit = N}}) ->
{ok,
lists:sublist(
[
@ -276,7 +276,7 @@ create_payment_ok_test(Config) ->
{invoicing, fun
('Get', _) ->
{ok, ?PAYPROC_INVOICE};
('StartPayment', {_, _, PaymentParams}) ->
('StartPayment', {_, PaymentParams}) ->
#payproc_InvoicePaymentParams{
id = ID,
external_id = EID,
@ -314,7 +314,7 @@ create_payment_expired_test(Config) ->
{invoicing, fun
('Get', _) ->
{ok, ?PAYPROC_INVOICE};
('StartPayment', {_, _, IPP}) ->
('StartPayment', {_, IPP}) ->
#payproc_InvoicePaymentParams{id = ID, external_id = EID, context = ?CONTENT} = IPP,
{ok, ?PAYPROC_PAYMENT(ID, EID)}
end}
@ -378,7 +378,7 @@ create_payment_w_payment_tool(PaymentTool, Config) ->
{invoicing, fun
('Get', _) ->
{ok, ?PAYPROC_INVOICE};
('StartPayment', {_UserInfo, _InvoiceID, Params}) ->
('StartPayment', {_InvoiceID, Params}) ->
?assertMatch(
{payment_resource, #payproc_PaymentResourcePayerParams{
resource = #domain_DisposablePaymentResource{
@ -528,7 +528,6 @@ capture_partial_payment_ok_test(Config) ->
(
'CapturePayment',
{
_,
_,
_,
#payproc_InvoicePaymentCaptureParams{

View File

@ -37,7 +37,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},1},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"b25d3365e1f2b075ffea30b3a2e1c41eb3f6145b"}},
{ref,"d384c125d16c0204e23b0d96a6ef791244a72315"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",
@ -93,7 +93,7 @@
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.4.1">>},1},
{<<"party_client">>,
{git,"https://github.com/valitydev/party-client-erlang.git",
{ref,"602d4dc87b54d2bf899ae36462853f7d7eb014ae"}},
{ref,"4097004f78a526b7fe748719045dd428c905c2f0"}},
0},
{<<"payout_manager_proto">>,
{git,"https://github.com/valitydev/payout-manager-proto.git",