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
10 changes: 7 additions & 3 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, binary()},
scope := {invoice | invoice_template | customer, binary()},
shop => binary(),
lifetime => pos_integer() | unlimited,
metadata => token_keeper_client:metadata()
Expand Down Expand Up @@ -168,7 +168,8 @@ resolve_auth_scope(TokenSpec) ->
).

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

resolve_auth_expiration(TokenSpec) ->
case get_token_lifetime(TokenSpec) of
Expand All @@ -185,10 +186,13 @@ 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, _}}) ->
unlimited.

verify_token_lifetime(#{scope := {invoice, _}}, LifeTime) when LifeTime =/= unlimited -> ok;
verify_token_lifetime(#{scope := {invoice_template, _}}, _LifeTime) -> ok.
verify_token_lifetime(#{scope := {invoice_template, _}}, _LifeTime) -> ok;
verify_token_lifetime(#{scope := {customer, _}}, _LifeTime) -> ok.

%%

Expand Down
3 changes: 2 additions & 1 deletion apps/capi/src/capi_bouncer_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
payment => entity_id(),
refund => entity_id(),
invoice_template => entity_id(),
webhook => entity_id()
webhook => entity_id(),
customer => entity_id()
}.

-type prototype_payproc() :: #{
Expand Down
24 changes: 24 additions & 0 deletions apps/capi/src/capi_feature_schemas.erl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@
-define(postal_code, 71).
-define(date_of_birth, 72).
-define(document_id, 73).
-define(metadata, 74).

-export([payment/0]).
-export([invoice/0]).
-export([invoice_template/0]).
-export([refund/0]).
-export([customer/0]).

-spec payment() -> schema().
payment() ->
Expand Down Expand Up @@ -166,6 +168,28 @@ refund() ->
?allocation => {<<"allocation">>, {set, allocation_transaction()}}
}.

-spec customer() -> schema().
customer() ->
#{
?contact_info => {<<"contactInfo">>, contact_info_schema()},
?metadata => <<"metadata">>
}.

contact_info_schema() ->
#{
?email => <<"email">>,
?phone_number => <<"phoneNumber">>,
?first_name => <<"firstName">>,
?last_name => <<"lastName">>,
?country => <<"country">>,
?state => <<"state">>,
?city => <<"city">>,
?address => <<"address">>,
?postal_code => <<"postalCode">>,
?date_of_birth => <<"dateOfBirth">>,
?document_id => <<"documentId">>
}.

-spec payment_tool_schema() -> schema().
payment_tool_schema() ->
{union, <<"type">>, #{
Expand Down
2 changes: 2 additions & 0 deletions apps/capi/src/capi_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ get_handlers() ->
[
capi_handler_categories,
capi_handler_countries,
capi_handler_customers,
capi_handler_invoice_templates,
capi_handler_invoices,
capi_handler_parties,
Expand Down Expand Up @@ -308,6 +309,7 @@ set_context_meta(Context) ->
-spec set_request_meta(operation_id(), request_data()) -> ok.
set_request_meta(OperationID, Req) ->
InterestParams = [
'customerID',
'invoiceID',
'invoiceTemplateID',
'webhookID',
Expand Down
Loading
Loading