Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# You SHOULD specify point releases here so that build time and run time Erlang/OTPs
# are the same. See: https://github.com/erlware/relx/pull/902
SERVICE_NAME=capi
OTP_VERSION=24.3.4
REBAR_VERSION=3.18
OTP_VERSION=27.1.2
REBAR_VERSION=3.24
THRIFT_VERSION=0.14.2.3
4 changes: 2 additions & 2 deletions apps/capi/src/capi_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
-spec get_subject_id(auth_context()) -> binary() | undefined.
get_subject_id(AuthContext) ->
case get_party_id(AuthContext) of
PartyId when is_binary(PartyId) ->
PartyId;
PartyID when is_binary(PartyID) ->
PartyID;
undefined ->
get_user_id(AuthContext)
end.
Expand Down
14 changes: 7 additions & 7 deletions apps/capi/src/capi_bender.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ build_bender_ctx(Features, Ctx) ->
get_external_id({_BenderPrefix, _PartyOrUserID, ExternalID}) ->
ExternalID.

try_generate_id(BenderIdSchema, IdempotentKey, Identity, WoodyContext, CtxData) ->
case generate_id(BenderIdSchema, IdempotentKey, Identity, WoodyContext, CtxData) of
try_generate_id(BenderIDSchema, IdempotentKey, Identity, WoodyContext, CtxData) ->
case generate_id(BenderIDSchema, IdempotentKey, Identity, WoodyContext, CtxData) of
{ok, ID} ->
ID;
{error, {external_id_conflict, ID, Difference, Schema}} ->
Expand All @@ -158,14 +158,14 @@ try_generate_id(BenderIdSchema, IdempotentKey, Identity, WoodyContext, CtxData)
throw({external_id_conflict, ID, SourceID, Schema})
end.

generate_id(BenderIdSchema, IdempKeyParams, Identity, WoodyContext, CtxData) ->
generate_id(BenderIDSchema, IdempKeyParams, Identity, WoodyContext, CtxData) ->
IdempKey = make_idempotent_key(IdempKeyParams),
case IdempKey of
undefined ->
ID = generator_generate_id(BenderIdSchema, WoodyContext),
ID = generator_generate_id(BenderIDSchema, WoodyContext),
{ok, ID};
IdempKey ->
bender_generate_id(BenderIdSchema, IdempKey, Identity, WoodyContext, CtxData)
bender_generate_id(BenderIDSchema, IdempKey, Identity, WoodyContext, CtxData)
end.

-spec make_idempotent_key(idempotent_key_params()) -> idempotent_key() | undefined.
Expand All @@ -177,10 +177,10 @@ make_idempotent_key({_Prefix, _PartyID, undefined}) ->
make_idempotent_key({Prefix, PartyID, ExternalID}) ->
bender_client:get_idempotent_key(?BENDER_NAMESPACE, Prefix, PartyID, ExternalID).

bender_generate_id(BenderIdSchema, IdempKey, Identity, WoodyContext, CtxData) ->
bender_generate_id(BenderIDSchema, IdempKey, Identity, WoodyContext, CtxData) ->
{identity, Features, Schema} = Identity,
BenderCtx = build_bender_ctx(Features, CtxData),
case bender_client:gen_id(IdempKey, BenderIdSchema, WoodyContext, BenderCtx) of
case bender_client:gen_id(IdempKey, BenderIDSchema, WoodyContext, BenderCtx) of
{ok, ID} ->
{ok, ID};
{ok, ID, #{<<"version">> := ?SCHEMA_VER3} = SavedBenderCtx} ->
Expand Down
16 changes: 8 additions & 8 deletions apps/capi/src/capi_bouncer_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ build(Prototypes, {Acc0, External}, WoodyCtx) ->
Acc1 = lists:foldl(fun({T, Params}, Acc) -> build(T, Params, Acc, WoodyCtx) end, Acc0, Prototypes),
{Acc1, External}.

build(operation, Params = #{id := OperationID}, Acc, _WoodyCtx) ->
build(operation, #{id := OperationID} = Params, Acc, _WoodyCtx) ->
Acc#ctx_v1_ContextFragment{
capi = #ctx_v1_ContextCommonAPI{
op = #ctx_v1_CommonAPIOperation{
Expand All @@ -105,7 +105,7 @@ build(operation, Params = #{id := OperationID}, Acc, _WoodyCtx) ->
}
}
};
build(payproc, Params = #{}, Acc, WoodyCtx) ->
build(payproc, #{} = Params, Acc, WoodyCtx) ->
Acc#ctx_v1_ContextFragment{
payment_processing = #ctx_v1_ContextPaymentProcessing{
invoice = maybe_with(
Expand All @@ -125,7 +125,7 @@ build(payproc, Params = #{}, Acc, WoodyCtx) ->
)
}
};
build(webhooks, Params = #{}, Acc, WoodyCtx) ->
build(webhooks, #{} = Params, Acc, WoodyCtx) ->
Acc#ctx_v1_ContextFragment{
webhooks = #ctx_v1_ContextWebhooks{
webhook = maybe_with(
Expand Down Expand Up @@ -229,21 +229,21 @@ build_webhook_filter({Type, Filter}) ->
build_webhook_filter_details(#webhooker_PartyEventFilter{}, Ctx) ->
Ctx;
build_webhook_filter_details(#webhooker_InvoiceEventFilter{shop_id = ShopID}, Ctx) ->
Ctx#ctx_v1_WebhookFilter{shop = maybe(ShopID, fun build_entity/1)};
Ctx#ctx_v1_WebhookFilter{shop = 'maybe'(ShopID, fun build_entity/1)};
build_webhook_filter_details(#webhooker_CustomerEventFilter{shop_id = ShopID}, Ctx) ->
Ctx#ctx_v1_WebhookFilter{shop = maybe(ShopID, fun build_entity/1)};
Ctx#ctx_v1_WebhookFilter{shop = 'maybe'(ShopID, fun build_entity/1)};
build_webhook_filter_details(#webhooker_WalletEventFilter{}, Ctx) ->
Ctx.

%%

maybe(undefined, _Then) ->
'maybe'(undefined, _Then) ->
undefined;
maybe(V, Then) ->
'maybe'(V, Then) ->
Then(V).

maybe_with(Name, Params, Then) ->
maybe(maps:get(Name, Params, undefined), Then).
'maybe'(maps:get(Name, Params, undefined), Then).

maybe_with_woody_result(ServiceName, Function, Args, WoodyCtx, Then) ->
% TODO
Expand Down
2 changes: 1 addition & 1 deletion apps/capi/src/capi_domain.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extract_type(Name) when is_atom(Name) ->
{dmsl_domain_thrift, Name};
extract_type({_ID, _Kind, TypeInfo, _Field, _Default}) ->
extract_type(TypeInfo);
extract_type(Type = {Module, Name}) when is_atom(Module), is_atom(Name) ->
extract_type({Module, Name} = Type) when is_atom(Module), is_atom(Name) ->
Type;
extract_type({struct, struct, Type = {Module, Name}}) when is_atom(Module), is_atom(Name) ->
Type;
Expand Down
6 changes: 3 additions & 3 deletions apps/capi/src/capi_feature_schemas.erl
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ compare_customer_binding_features_test() ->
Request1 = payment_resource(Session1, Tool1),

Session2 = ?TEST_PAYMENT_SESSION(<<"Session2">>),
Tool2 = ?TEST_PAYMENT_TOOL(<<"mastercard">>)#{<<"exp_date">> => <<"01/2020">>},
Tool2 = maps:merge(?TEST_PAYMENT_TOOL(<<"mastercard">>), #{<<"exp_date">> => <<"01/2020">>}),
Request2 = payment_resource(Session2, Tool2),

common_compare_tests(customer_binding(), Request1, Request2, [
Expand Down Expand Up @@ -864,7 +864,7 @@ read_allocation_transaction_test_() ->
-spec compare_allocation_transaction_test() -> _.
compare_allocation_transaction_test() ->
Request1 = ?ALLOCATION_TRANSACTION_PARAMS,
Request2 = ?ALLOCATION_TRANSACTION_PARAMS#{
Request2 = maps:merge(?ALLOCATION_TRANSACTION_PARAMS, #{
<<"total">> => 1024,
<<"amount">> => 512,
<<"fee">> => #{
Expand All @@ -873,7 +873,7 @@ compare_allocation_transaction_test() ->
<<"amount">> => ?INTEGER,
<<"share">> => undefined
}
},
}),
%% Request3 = #{
%% <<"target">> => ?ALLOCATION_TARGET#{<<"shopID">> => <<"SomeShop">>},
%% <<"allocationBodyType">> => <<"AllocationBodyAmount">>,
Expand Down
2 changes: 1 addition & 1 deletion apps/capi/src/capi_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ respond_if_forbidden(allowed, _Response) ->
get_auth_context(#{auth_context := AuthContext}) ->
AuthContext.

do_authorize_api_key(SwagContext = #{auth_context := PreAuthContext}, WoodyContext) ->
do_authorize_api_key(#{auth_context := PreAuthContext} = SwagContext, WoodyContext) ->
case capi_auth:authorize_api_key(PreAuthContext, make_token_context(SwagContext), WoodyContext) of
{ok, AuthContext} ->
SwagContext#{auth_context => AuthContext};
Expand Down
4 changes: 2 additions & 2 deletions apps/capi/src/capi_handler_categories.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Req :: capi_handler:request_data(),
Context :: capi_handler:processing_context()
) -> {ok, capi_handler:request_state()} | {error, noimpl}.
prepare(OperationID = 'GetCategories', _Req, Context) ->
prepare('GetCategories' = OperationID, _Req, Context) ->
Authorize = fun() ->
Prototypes = [{operation, #{id => OperationID}}],
{ok, capi_auth:authorize_operation(Prototypes, Context)}
Expand All @@ -23,7 +23,7 @@ prepare(OperationID = 'GetCategories', _Req, Context) ->
{ok, {200, #{}, [decode_category(C) || C <- Categories]}}
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetCategoryByRef', Req, Context) ->
prepare('GetCategoryByRef' = OperationID, Req, Context) ->
Authorize = fun() ->
Prototypes = [{operation, #{id => OperationID}}],
{ok, capi_auth:authorize_operation(Prototypes, Context)}
Expand Down
17 changes: 8 additions & 9 deletions apps/capi/src/capi_handler_contracts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

-include_lib("damsel/include/dmsl_payproc_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_base_thrift.hrl").

-behaviour(capi_handler).

Expand All @@ -15,7 +14,7 @@
Req :: capi_handler:request_data(),
Context :: capi_handler:processing_context()
) -> {ok, capi_handler:request_state()} | {error, noimpl}.
prepare(OperationID = 'GetContracts', _Req, Context) ->
prepare('GetContracts' = OperationID, _Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
Authorize = fun() ->
Prototypes = [
Expand All @@ -28,7 +27,7 @@ prepare(OperationID = 'GetContracts', _Req, Context) ->
{ok, {200, #{}, decode_contracts_map(Party#domain_Party.contracts, Party#domain_Party.contractors)}}
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractByID', Req, Context) ->
prepare('GetContractByID' = OperationID, Req, Context) ->
ContractID = maps:get('contractID', Req),
PartyID = capi_handler_utils:get_party_id(Context),
Authorize = fun() ->
Expand All @@ -48,7 +47,7 @@ prepare(OperationID = 'GetContractByID', Req, Context) ->
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractAdjustments', Req, Context) ->
prepare('GetContractAdjustments' = OperationID, Req, Context) ->
ContractID = maps:get('contractID', Req),
PartyID = capi_handler_utils:get_party_id(Context),
Authorize = fun() ->
Expand All @@ -63,7 +62,7 @@ prepare(OperationID = 'GetContractAdjustments', Req, Context) ->
{ok, {200, #{}, Resp}}
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractAdjustmentByID', Req, Context) ->
prepare('GetContractAdjustmentByID' = OperationID, Req, Context) ->
ContractID = maps:get('contractID', Req),
PartyID = capi_handler_utils:get_party_id(Context),
Authorize = fun() ->
Expand All @@ -84,7 +83,7 @@ prepare(OperationID = 'GetContractAdjustmentByID', Req, Context) ->
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractsForParty', Req, Context) ->
prepare('GetContractsForParty' = OperationID, Req, Context) ->
PartyID = maps:get('partyID', Req),
Authorize = fun() ->
Prototypes = [
Expand All @@ -101,7 +100,7 @@ prepare(OperationID = 'GetContractsForParty', Req, Context) ->
end
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractByIDForParty', Req, Context) ->
prepare('GetContractByIDForParty' = OperationID, Req, Context) ->
ContractID = maps:get('contractID', Req),
PartyID = maps:get('partyID', Req),
Authorize = fun() ->
Expand All @@ -117,7 +116,7 @@ prepare(OperationID = 'GetContractByIDForParty', Req, Context) ->
{ok, {200, #{}, decode_contract(Contract, Party#domain_Party.contractors)}}
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractAdjustmentsForParty', Req, Context) ->
prepare('GetContractAdjustmentsForParty' = OperationID, Req, Context) ->
ContractID = maps:get('contractID', Req),
PartyID = maps:get('partyID', Req),
Authorize = fun() ->
Expand All @@ -132,7 +131,7 @@ prepare(OperationID = 'GetContractAdjustmentsForParty', Req, Context) ->
{ok, {200, #{}, Resp}}
end,
{ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetContractAdjustmentByIDForParty', Req, Context) ->
prepare('GetContractAdjustmentByIDForParty' = OperationID, Req, Context) ->
ContractID = maps:get('contractID', Req),
PartyID = maps:get('partyID', Req),
Authorize = fun() ->
Expand Down
4 changes: 2 additions & 2 deletions apps/capi/src/capi_handler_countries.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ decode_trade_bloc_refs(undefined) ->
undefined;
decode_trade_bloc_refs(TradeBlocRefs) ->
lists:map(
fun(#domain_TradeBlocRef{id = Id}) ->
Id
fun(#domain_TradeBlocRef{id = ID}) ->
ID
end,
ordsets:to_list(TradeBlocRefs)
).
5 changes: 2 additions & 3 deletions apps/capi/src/capi_handler_customers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

-include_lib("damsel/include/dmsl_payproc_thrift.hrl").
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
-include_lib("damsel/include/dmsl_base_thrift.hrl").

-behaviour(capi_handler).

Expand Down Expand Up @@ -302,7 +301,7 @@ encode_customer_params(CustomerID, PartyID, Params) ->
encode_customer_metadata(Meta) ->
capi_json_marshalling:marshal(Meta).

generate_binding_ids(OperationID, CustomerBindingParams, Context = #{woody_context := WoodyContext}) ->
generate_binding_ids(OperationID, CustomerBindingParams, #{woody_context := WoodyContext} = Context) ->
ExternalID = maps:get(<<"externalID">>, CustomerBindingParams, undefined),
PartyID = capi_handler_utils:get_party_id(Context),

Expand Down Expand Up @@ -424,7 +423,7 @@ decode_customer_binding_status({Status, StatusInfo}) ->
<<"error">> => Error
}.

decode_customer_event(Event = #payproc_Event{source = {customer_id, _}, payload = Payload}) ->
decode_customer_event(#payproc_Event{source = {customer_id, _}, payload = Payload} = Event) ->
case decode_customer_changes(Payload) of
[_Something | _] = Changes ->
{true, #{
Expand Down
10 changes: 5 additions & 5 deletions apps/capi/src/capi_handler_decoder_invoicing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ decode_crypto_amount(#'user_interaction_CryptoCurrencyTransferRequest'{crypto_ca
ensure_correct_exponent(#base_Rational{q = Q}) ->
Log = math:log10(Q),
case Log - trunc(Log) of
0.0 -> ok;
V when V == 0 -> ok;
_ -> error('expected a power of 10 denominator')
end.

Expand All @@ -111,7 +111,7 @@ decode_fractional_part(#base_Rational{p = P, q = Q}) ->
get_exponent(Q) ->
erlang:trunc(math:log10(Q)).

build_fractional(_Fractional, _Exponent = 0) ->
build_fractional(_Fractional, 0 = _Exponent) ->
<<>>;
build_fractional(Fractional, Exponent) ->
BinaryFractional = erlang:integer_to_binary(Fractional),
Expand Down Expand Up @@ -177,7 +177,7 @@ decode_payment(InvoiceID, Payment, Context) ->

-spec decode_invoice_payment(binary(), capi_handler_encoder:encode_data(), processing_context()) ->
decode_data().
decode_invoice_payment(InvoiceID, InvoicePayment = #payproc_InvoicePayment{payment = Payment}, Context) ->
decode_invoice_payment(InvoiceID, #payproc_InvoicePayment{payment = Payment} = InvoicePayment, Context) ->
capi_handler_utils:merge_and_compact(
decode_payment(InvoiceID, Payment, Context),
#{
Expand Down Expand Up @@ -528,7 +528,7 @@ decode_invoice_cart(#domain_InvoiceCart{lines = Lines}) ->
decode_invoice_cart(undefined) ->
undefined.

decode_invoice_line(InvoiceLine = #domain_InvoiceLine{quantity = Quantity, price = #domain_Cash{amount = Price}}) ->
decode_invoice_line(#domain_InvoiceLine{quantity = Quantity, price = #domain_Cash{amount = Price}} = InvoiceLine) ->
genlib_map:compact(#{
<<"product">> => InvoiceLine#domain_InvoiceLine.product,
<<"quantity">> => Quantity,
Expand Down Expand Up @@ -691,7 +691,7 @@ decode_bank_card_details(BankCard, V) ->
<<"first6">> => Bin,
<<"cardNumberMask">> => capi_handler_decoder_utils:decode_masked_pan(Bin, LastDigits),
<<"paymentSystem">> => capi_handler_decoder_utils:decode_payment_system_ref(PaymentSystem),
<<"tokenProvider">> => capi_utils:maybe(
<<"tokenProvider">> => capi_utils:'maybe'(
TokenProvider,
fun capi_handler_decoder_utils:decode_bank_card_token_service_ref/1
)
Expand Down
4 changes: 2 additions & 2 deletions apps/capi/src/capi_handler_invoice_templates.erl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ get_product_from_tpl_details({cart, #domain_InvoiceCart{lines = [FirstLine | _]}
get_product_from_tpl_details(undefined) ->
undefined.

encode_optional_context(Params = #{<<"metadata">> := _}) ->
encode_optional_context(#{<<"metadata">> := _} = Params) ->
capi_handler_encoder:encode_invoice_context(Params);
encode_optional_context(#{}) ->
undefined.
Expand Down Expand Up @@ -340,7 +340,7 @@ encode_invoice_tpl_product(Details) ->
metadata = capi_handler_encoder:encode_invoice_line_meta(Details)
}.

encode_optional_invoice_cost(Params = #{<<"amount">> := _, <<"currency">> := _}) ->
encode_optional_invoice_cost(#{<<"amount">> := _, <<"currency">> := _} = Params) ->
capi_handler_encoder:encode_cash(Params);
encode_optional_invoice_cost(#{<<"amount">> := _}) ->
throw({bad_invoice_params, amount_no_currency});
Expand Down
Loading
Loading