Skip to content
Open
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
18 changes: 18 additions & 0 deletions .github/workflows/tag-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Create Tag

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- uses: valitydev/action-tagger@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
with-v: true
1 change: 0 additions & 1 deletion apps/capi/src/capi.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
bouncer_client,
token_keeper_client,
party_client,
magista_proto,
opentelemetry_api,
opentelemetry_exporter,
opentelemetry
Expand Down
22 changes: 11 additions & 11 deletions apps/capi/src/capi_allocation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ transaction_error(#payproc_AllocationInvalidTransaction{reason = Reason, transac
ShopID =
case Transaction of
{transaction, #domain_AllocationTransaction{target = {shop, Target}}} ->
Target#domain_AllocationTransactionTargetShop.shop_id;
Target#domain_AllocationTransactionTargetShop.shop_ref#domain_ShopConfigRef.id;
{transaction_prototype, #domain_AllocationTransactionPrototype{target = {shop, Target}}} ->
Target#domain_AllocationTransactionTargetShop.shop_id
Target#domain_AllocationTransactionTargetShop.shop_ref#domain_ShopConfigRef.id
end,
Message = io_lib:format("Invalid allocation transaction with shop_id \"~ts\" and error \"~ts\"", [ShopID, Reason]),
genlib:to_binary(Message).
Expand All @@ -56,8 +56,8 @@ encode_transaction(PartyID, Transaction) ->

encode_target(PartyID, #{<<"allocationTargetType">> := <<"AllocationTargetShop">>} = Target) ->
{shop, #domain_AllocationTransactionTargetShop{
owner_id = PartyID,
shop_id = maps:get(<<"shopID">>, Target)
party_ref = #domain_PartyConfigRef{id = PartyID},
shop_ref = #domain_ShopConfigRef{id = maps:get(<<"shopID">>, Target)}
}}.

encode_details(#{<<"cart">> := _Cart} = Transaction) ->
Expand Down Expand Up @@ -123,7 +123,7 @@ decode_transaction(Transaction) ->
decode_target({shop, AllocationShop}) ->
#{
<<"allocationTargetType">> => <<"AllocationTargetShop">>,
<<"shopID">> => AllocationShop#domain_AllocationTransactionTargetShop.shop_id
<<"shopID">> => AllocationShop#domain_AllocationTransactionTargetShop.shop_ref#domain_ShopConfigRef.id
}.

decode_details(undefined) ->
Expand Down Expand Up @@ -239,8 +239,8 @@ encode_test() ->
#domain_AllocationTransactionPrototype{
target =
{shop, #domain_AllocationTransactionTargetShop{
owner_id = <<"partyID">>,
shop_id = <<"shopID1">>
party_ref = #domain_PartyConfigRef{id = <<"partyID">>},
shop_ref = #domain_ShopConfigRef{id = <<"shopID1">>}
}},
body =
{total, #domain_AllocationTransactionPrototypeBodyTotal{
Expand Down Expand Up @@ -285,15 +285,15 @@ decode_test() ->
id = <<"0">>,
target =
{shop, #domain_AllocationTransactionTargetShop{
owner_id = <<"partyID1">>,
shop_id = <<"shopID1">>
party_ref = #domain_PartyConfigRef{id = <<"partyID1">>},
shop_ref = #domain_ShopConfigRef{id = <<"shopID1">>}
}},
amount = make_cash(32),
body = #domain_AllocationTransactionBodyTotal{
fee_target =
{shop, #domain_AllocationTransactionTargetShop{
owner_id = <<"partyID2">>,
shop_id = <<"shopID2">>
party_ref = #domain_PartyConfigRef{id = <<"partyID2">>},
shop_ref = #domain_ShopConfigRef{id = <<"shopID2">>}
}},
total = make_cash(16),
fee_amount = make_cash(8),
Expand Down
10 changes: 2 additions & 8 deletions apps/capi/src/capi_auth.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
-type consumer() :: client | merchant | provider.
-type token_spec() :: #{
party := binary(),
scope := {invoice | invoice_template | customer, binary()},
scope := {invoice | invoice_template, binary()},
shop => binary(),
lifetime => pos_integer() | unlimited,
metadata => token_keeper_client:metadata()
Expand Down Expand Up @@ -132,7 +132,6 @@ issue_access_token(TokenSpec, WoodyContext) ->
%%

-define(DEFAULT_INVOICE_ACCESS_TOKEN_LIFETIME, 259200).
-define(DEFAULT_CUSTOMER_ACCESS_TOKEN_LIFETIME, 259200).

-include_lib("bouncer_proto/include/bouncer_ctx_v1_thrift.hrl").

Expand Down Expand Up @@ -169,7 +168,6 @@ resolve_auth_scope(TokenSpec) ->
).

resolve_auth_method(#{scope := {invoice, _}}) -> ?CTX_V1_AUTHMETHOD_INVOICEACCESSTOKEN;
resolve_auth_method(#{scope := {customer, _}}) -> ?CTX_V1_AUTHMETHOD_CUSTOMERACCESSTOKEN;
resolve_auth_method(#{scope := {invoice_template, _}}) -> ?CTX_V1_AUTHMETHOD_INVOICETEMPLATEACCESSTOKEN.

resolve_auth_expiration(TokenSpec) ->
Expand All @@ -187,13 +185,9 @@ get_token_lifetime(#{lifetime := LifeTime} = TokenSpec) when LifeTime =/= undefi
get_token_lifetime(#{scope := {invoice, _}}) ->
?DEFAULT_INVOICE_ACCESS_TOKEN_LIFETIME;
get_token_lifetime(#{scope := {invoice_template, _}}) ->
unlimited;
get_token_lifetime(#{scope := {customer, _}}) ->
?DEFAULT_CUSTOMER_ACCESS_TOKEN_LIFETIME.
unlimited.

%% Forbid creation of unlimited lifetime invoice and customer tokens
verify_token_lifetime(#{scope := {invoice, _}}, LifeTime) when LifeTime =/= unlimited -> ok;
verify_token_lifetime(#{scope := {customer, _}}, LifeTime) when LifeTime =/= unlimited -> ok;
verify_token_lifetime(#{scope := {invoice_template, _}}, _LifeTime) -> ok.

%%
Expand Down
2 changes: 1 addition & 1 deletion apps/capi/src/capi_bender.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-type id() :: binary().
-type idempotent_key_prefix() :: binary() | atom().
-type external_id() :: binary().
-type issuer_id() :: dmsl_domain_thrift:'PartyID'().
-type issuer_id() :: dmsl_base_thrift:'ID'().
-type idempotent_key() :: binary().
-type idempotent_key_params() :: {idempotent_key_prefix(), issuer_id(), external_id() | undefined}.

Expand Down
67 changes: 14 additions & 53 deletions apps/capi/src/capi_bouncer_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@
id => swag_server:operation_id(),
party => entity_id(),
shop => entity_id(),
contract => entity_id(),
invoice => entity_id(),
payment => entity_id(),
refund => entity_id(),
invoice_template => entity_id(),
customer => entity_id(),
binding => entity_id(),
file => entity_id(),
webhook => entity_id()
}.

-type prototype_payproc() :: #{
invoice => invoice_id() | invoice() | undefined,
invoice_template => invoice_template_id() | invoice_template() | undefined,
customer => customer_id() | customer() | undefined
invoice_template => invoice_template_id() | invoice_template() | undefined
}.

-type prototype_webhooks() :: #{
Expand All @@ -53,9 +48,6 @@
-type invoice_template_id() :: dmsl_domain_thrift:'InvoiceTemplateID'().
-type invoice_template() :: dmsl_domain_thrift:'InvoiceTemplate'().

-type customer_id() :: dmsl_payproc_thrift:'CustomerID'().
-type customer() :: dmsl_payproc_thrift:'Customer'().

-type webhook_id() :: dmsl_webhooker_thrift:'WebhookID'().
-type webhook() :: dmsl_webhooker_thrift:'Webhook'().

Expand Down Expand Up @@ -93,14 +85,10 @@ build(operation, #{id := OperationID} = Params, Acc, _WoodyCtx) ->
id = operation_id_to_binary(OperationID),
party = maybe_entity(party, Params),
shop = maybe_entity(shop, Params),
contract = maybe_entity(contract, Params),
invoice = maybe_entity(invoice, Params),
payment = maybe_entity(payment, Params),
refund = maybe_entity(refund, Params),
invoice_template = maybe_entity(invoice_template, Params),
customer = maybe_entity(customer, Params),
binding = maybe_entity(binding, Params),
file = maybe_entity(file, Params),
webhook = maybe_entity(webhook, Params)
}
}
Expand All @@ -117,11 +105,6 @@ build(payproc, #{} = Params, Acc, WoodyCtx) ->
invoice_template,
Params,
fun(V) -> build_invoice_template_ctx(V, WoodyCtx) end
),
customer = maybe_with(
customer,
Params,
fun(V) -> build_customer_ctx(V, WoodyCtx) end
)
}
};
Expand Down Expand Up @@ -152,8 +135,8 @@ build_invoice_ctx(Invoice, _WoodyCtx) ->
build_invoice_ctx(#payproc_Invoice{invoice = Invoice, payments = Payments}) ->
#ctx_v1_Invoice{
id = Invoice#domain_Invoice.id,
party = build_entity(Invoice#domain_Invoice.owner_id),
shop = build_entity(Invoice#domain_Invoice.shop_id),
party = build_entity(Invoice#domain_Invoice.party_ref#domain_PartyConfigRef.id),
shop = build_entity(Invoice#domain_Invoice.shop_ref#domain_ShopConfigRef.id),
payments = build_set(lists:map(fun build_payment_ctx/1, Payments))
}.

Expand All @@ -177,43 +160,27 @@ build_invoice_template_ctx(ID, WoodyCtx) when is_binary(ID) ->
build_invoice_template_ctx(InvoiceTemplate, _WoodyCtx) ->
build_invoice_template_ctx(InvoiceTemplate).

build_invoice_template_ctx(#domain_InvoiceTemplate{id = ID, owner_id = OwnerID, shop_id = ShopID}) ->
build_invoice_template_ctx(#domain_InvoiceTemplate{
id = ID, party_ref = #domain_PartyConfigRef{id = PartyID}, shop_ref = #domain_ShopConfigRef{id = ShopID}
}) ->
#ctx_v1_InvoiceTemplate{
id = ID,
party = build_entity(OwnerID),
party = build_entity(PartyID),
shop = build_entity(ShopID)
}.

build_customer_ctx(ID, WoodyCtx) when is_binary(ID) ->
maybe_with_woody_result(
customer_management,
'Get',
{ID, #payproc_EventRange{}},
WoodyCtx,
fun build_customer_ctx/1
);
build_customer_ctx(Customer, _WoodyCtx) ->
build_customer_ctx(Customer).

build_customer_ctx(#payproc_Customer{id = ID, owner_id = OwnerID, shop_id = ShopID, bindings = Bindings}) ->
#ctx_v1_Customer{
id = ID,
party = build_entity(OwnerID),
shop = build_entity(ShopID),
bindings = build_set(lists:map(fun build_binding_ctx/1, Bindings))
}.

build_binding_ctx(#payproc_CustomerBinding{id = ID}) ->
build_entity(ID).

%%

build_webhook_ctx(ID, WoodyCtx) when is_integer(ID) ->
maybe_with_woody_result(webhook_manager, 'Get', {ID}, WoodyCtx, fun build_webhook_ctx/1);
build_webhook_ctx(Webhook, _WoodyCtx) ->
build_webhook_ctx(Webhook).

build_webhook_ctx(#webhooker_Webhook{id = ID, party_id = PartyID, event_filter = Filter}) ->
build_webhook_ctx(#webhooker_Webhook{
id = ID,
party_ref = #domain_PartyConfigRef{id = PartyID},
event_filter = Filter
}) ->
#ctx_v1_Webhook{
id = integer_to_binary(ID),
party = build_entity(PartyID),
Expand All @@ -226,14 +193,8 @@ build_webhook_filter({Type, Filter}) ->
#ctx_v1_WebhookFilter{topic = erlang:atom_to_binary(Type, utf8)}
).

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)};
build_webhook_filter_details(#webhooker_CustomerEventFilter{shop_id = ShopID}, Ctx) ->
Ctx#ctx_v1_WebhookFilter{shop = 'maybe'(ShopID, fun build_entity/1)};
build_webhook_filter_details(#webhooker_WalletEventFilter{}, Ctx) ->
Ctx.
build_webhook_filter_details(#webhooker_InvoiceEventFilter{shop_ref = #domain_ShopConfigRef{id = ShopID}}, Ctx) ->
Ctx#ctx_v1_WebhookFilter{shop = 'maybe'(ShopID, fun build_entity/1)}.

%%

Expand Down
Loading
Loading