From 5565c4e1010a90c7aa8bfb40b8fcfeb5dc504ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Wed, 1 Jul 2026 16:12:22 +0300 Subject: [PATCH 1/2] added to party --- apps/capi/src/capi_handler_utils.erl | 31 ++++++++++++++++++++-------- apps/capi/test/capi_dummy_data.hrl | 2 +- rebar.config | 2 +- rebar.lock | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/apps/capi/src/capi_handler_utils.erl b/apps/capi/src/capi_handler_utils.erl index e9f9788..447b0fd 100644 --- a/apps/capi/src/capi_handler_utils.erl +++ b/apps/capi/src/capi_handler_utils.erl @@ -190,17 +190,30 @@ get_base_url( #{default_base_url := Default}, ProcessingContext ) -> - case capi_party:get_shop(PartyID, ShopID, ProcessingContext) of - {ok, #domain_ShopConfig{ - checkout_location = #domain_ShopCheckoutLocation{ - locations = [#domain_CheckoutLocation{base_url = V} | _] - } - }} -> - V; - _ -> - Default + ShopUrl = + case capi_party:get_shop(PartyID, ShopID, ProcessingContext) of + {ok, #domain_ShopConfig{checkout_locations = ShopLocations}} -> + checkout_base_url(ShopLocations); + _ -> + undefined + end, + case ShopUrl of + undefined -> + case capi_party:get_party(PartyID, ProcessingContext) of + {ok, #domain_PartyConfig{checkout_locations = PartyLocations}} -> + checkout_base_url(PartyLocations); + _ -> + Default + end; + ShopBaseUrl -> + ShopBaseUrl end. +checkout_base_url(#domain_CheckoutLocations{locations = [#domain_CheckoutLocation{base_url = BaseUrl} | _]}) -> + BaseUrl; +checkout_base_url(_) -> + undefined. + -spec issue_access_token(token_source(), processing_context()) -> map(). issue_access_token(#domain_Invoice{} = Invoice, ProcessingContext) -> TokenSpec = #{ diff --git a/apps/capi/test/capi_dummy_data.hrl b/apps/capi/test/capi_dummy_data.hrl index a5dad45..66c1c53 100644 --- a/apps/capi/test/capi_dummy_data.hrl +++ b/apps/capi/test/capi_dummy_data.hrl @@ -458,7 +458,7 @@ party_ref = #domain_PartyConfigRef{id = ?STRING}, location = ?SHOP_LOCATION, category = #domain_CategoryRef{id = ?INTEGER}, - checkout_location = #domain_ShopCheckoutLocation{ + checkout_locations = #domain_CheckoutLocations{ locations = [#domain_CheckoutLocation{base_url = ?CHECKOUT_URL}] } }). diff --git a/rebar.config b/rebar.config index 214b4a8..96325de 100644 --- a/rebar.config +++ b/rebar.config @@ -36,7 +36,7 @@ {cowboy_draining_server, {git, "https://github.com/valitydev/cowboy_draining_server.git", {branch, "master"}}}, {woody, {git, "https://github.com/valitydev/woody_erlang.git", {tag, "v1.1.0"}}}, {woody_user_identity, {git, "https://github.com/valitydev/woody_erlang_user_identity.git", {tag, "v1.1.0"}}}, - {damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.37"}}}, + {damsel, {git, "https://github.com/valitydev/damsel.git", {tag, "v2.2.39"}}}, {bender_proto, {git, "https://github.com/valitydev/bender-proto.git", {branch, "master"}}}, {bender_client, {git, "https://github.com/valitydev/bender-client-erlang.git", {tag, "v1.1.0"}}}, {dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {tag, "v2.0.3"}}}, diff --git a/rebar.lock b/rebar.lock index 561f8bd..653552e 100644 --- a/rebar.lock +++ b/rebar.lock @@ -41,7 +41,7 @@ {<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2}, {<<"damsel">>, {git,"https://github.com/valitydev/damsel.git", - {ref,"dcd668277f5a2a144dd823bb0e6c9ba7b94428cc"}}, + {ref,"25e75a53bbdc2cdbda7da266d05ae626fa3fa69b"}}, 0}, {<<"dmt_client">>, {git,"https://github.com/valitydev/dmt_client.git", From 32d7a8a431a06877f12f509028fac47c2d883066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Wed, 1 Jul 2026 16:48:15 +0300 Subject: [PATCH 2/2] refactored --- apps/capi/src/capi_handler_utils.erl | 30 ++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/capi/src/capi_handler_utils.erl b/apps/capi/src/capi_handler_utils.erl index 447b0fd..a770470 100644 --- a/apps/capi/src/capi_handler_utils.erl +++ b/apps/capi/src/capi_handler_utils.erl @@ -185,35 +185,27 @@ create_checkout_url(Invoice, AccessToken, Params0, ProcessingContext) -> #{<<"url">> => <>} end. +-define(CHECKOUT_BASE_URL(BaseUrl), #domain_CheckoutLocations{ + locations = [#domain_CheckoutLocation{base_url = BaseUrl} | _] +}). + get_base_url( #domain_Invoice{party_ref = #domain_PartyConfigRef{id = PartyID}, shop_ref = #domain_ShopConfigRef{id = ShopID}}, #{default_base_url := Default}, ProcessingContext ) -> - ShopUrl = - case capi_party:get_shop(PartyID, ShopID, ProcessingContext) of - {ok, #domain_ShopConfig{checkout_locations = ShopLocations}} -> - checkout_base_url(ShopLocations); - _ -> - undefined - end, - case ShopUrl of - undefined -> + case capi_party:get_shop(PartyID, ShopID, ProcessingContext) of + {ok, #domain_ShopConfig{checkout_locations = ?CHECKOUT_BASE_URL(V)}} -> + V; + _ -> case capi_party:get_party(PartyID, ProcessingContext) of - {ok, #domain_PartyConfig{checkout_locations = PartyLocations}} -> - checkout_base_url(PartyLocations); + {ok, #domain_PartyConfig{checkout_locations = ?CHECKOUT_BASE_URL(V)}} -> + V; _ -> Default - end; - ShopBaseUrl -> - ShopBaseUrl + end end. -checkout_base_url(#domain_CheckoutLocations{locations = [#domain_CheckoutLocation{base_url = BaseUrl} | _]}) -> - BaseUrl; -checkout_base_url(_) -> - undefined. - -spec issue_access_token(token_source(), processing_context()) -> map(). issue_access_token(#domain_Invoice{} = Invoice, ProcessingContext) -> TokenSpec = #{