mirror of
https://github.com/valitydev/hellgate.git
synced 2024-11-06 02:45:20 +00:00
TD-225: Remove UserInfo auth logic (#22)
* Remove auth logic, update party client * hadolint please
This commit is contained in:
parent
b911b96246
commit
0bd0458340
@ -4,12 +4,10 @@ ARG OTP_VERSION
|
|||||||
FROM docker.io/library/erlang:${OTP_VERSION} AS builder
|
FROM docker.io/library/erlang:${OTP_VERSION} AS builder
|
||||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
|
||||||
ARG BUILDARCH
|
|
||||||
|
|
||||||
# Install thrift compiler
|
# Install thrift compiler
|
||||||
ARG THRIFT_VERSION
|
ARG THRIFT_VERSION
|
||||||
|
ARG TARGETARCH
|
||||||
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${BUILDARCH}.tar.gz" \
|
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \
|
||||||
| tar -xvz -C /usr/local/bin/
|
| tar -xvz -C /usr/local/bin/
|
||||||
|
|
||||||
# Copy sources
|
# Copy sources
|
||||||
@ -29,7 +27,6 @@ ARG SERVICE_NAME
|
|||||||
# Set env
|
# Set env
|
||||||
ENV CHARSET=UTF-8
|
ENV CHARSET=UTF-8
|
||||||
ENV LANG=C.UTF-8
|
ENV LANG=C.UTF-8
|
||||||
ENV SERVICE_NAME=${SERVICE_NAME}
|
|
||||||
|
|
||||||
# Set runtime
|
# Set runtime
|
||||||
WORKDIR /opt/${SERVICE_NAME}
|
WORKDIR /opt/${SERVICE_NAME}
|
||||||
|
@ -3,12 +3,10 @@ ARG OTP_VERSION
|
|||||||
FROM docker.io/library/erlang:${OTP_VERSION}
|
FROM docker.io/library/erlang:${OTP_VERSION}
|
||||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
|
||||||
ARG BUILDARCH
|
|
||||||
|
|
||||||
# Install thrift compiler
|
# Install thrift compiler
|
||||||
ARG THRIFT_VERSION
|
ARG THRIFT_VERSION
|
||||||
|
ARG TARGETARCH
|
||||||
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${BUILDARCH}.tar.gz" \
|
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \
|
||||||
| tar -xvz -C /usr/local/bin/
|
| tar -xvz -C /usr/local/bin/
|
||||||
|
|
||||||
# Set env
|
# Set env
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
gproc,
|
gproc,
|
||||||
dmt_client,
|
dmt_client,
|
||||||
party_client,
|
party_client,
|
||||||
woody_user_identity,
|
|
||||||
payproc_errors,
|
payproc_errors,
|
||||||
erl_health,
|
erl_health,
|
||||||
limiter_proto
|
limiter_proto
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
-module(hg_access_control).
|
|
||||||
|
|
||||||
%%% HG access controll
|
|
||||||
|
|
||||||
-export([check_user/2]).
|
|
||||||
|
|
||||||
-spec check_user(woody_user_identity:user_identity(), dmsl_domain_thrift:'PartyID'()) -> ok | invalid_user.
|
|
||||||
check_user(#{id := PartyID, realm := <<"external">>}, PartyID) ->
|
|
||||||
ok;
|
|
||||||
check_user(#{id := _AnyID, realm := <<"internal">>}, _PartyID) ->
|
|
||||||
ok;
|
|
||||||
%% @TODO must be deleted when we get rid of #payproc_ServiceUser
|
|
||||||
check_user(#{id := _AnyID, realm := <<"service">>}, _PartyID) ->
|
|
||||||
ok;
|
|
||||||
check_user(_, _) ->
|
|
||||||
invalid_user.
|
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
-export([get_woody_context/1]).
|
-export([get_woody_context/1]).
|
||||||
-export([set_woody_context/2]).
|
-export([set_woody_context/2]).
|
||||||
-export([get_user_identity/1]).
|
|
||||||
-export([set_user_identity/2]).
|
|
||||||
-export([get_party_client_context/1]).
|
-export([get_party_client_context/1]).
|
||||||
-export([set_party_client_context/2]).
|
-export([set_party_client_context/2]).
|
||||||
-export([get_party_client/1]).
|
-export([get_party_client/1]).
|
||||||
@ -18,13 +16,11 @@
|
|||||||
-opaque context() :: #{
|
-opaque context() :: #{
|
||||||
woody_context := woody_context(),
|
woody_context := woody_context(),
|
||||||
party_client_context := party_client_context(),
|
party_client_context := party_client_context(),
|
||||||
party_client => party_client(),
|
party_client => party_client()
|
||||||
user_identity => user_identity()
|
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type options() :: #{
|
-type options() :: #{
|
||||||
party_client => party_client(),
|
party_client => party_client(),
|
||||||
user_identity => user_identity(),
|
|
||||||
woody_context => woody_context(),
|
woody_context => woody_context(),
|
||||||
party_client_context => party_client_context()
|
party_client_context => party_client_context()
|
||||||
}.
|
}.
|
||||||
@ -34,7 +30,6 @@
|
|||||||
|
|
||||||
%% Internal types
|
%% Internal types
|
||||||
|
|
||||||
-type user_identity() :: woody_user_identity:user_identity().
|
|
||||||
-type woody_context() :: woody_context:ctx().
|
-type woody_context() :: woody_context:ctx().
|
||||||
-type party_client() :: party_client:client().
|
-type party_client() :: party_client:client().
|
||||||
-type party_client_context() :: party_client:context().
|
-type party_client_context() :: party_client:context().
|
||||||
@ -73,8 +68,7 @@ cleanup() ->
|
|||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec get_woody_context(context()) -> woody_context().
|
-spec get_woody_context(context()) -> woody_context().
|
||||||
get_woody_context(Context) ->
|
get_woody_context(#{woody_context := WoodyContext}) ->
|
||||||
#{woody_context := WoodyContext} = ensure_woody_user_info_set(Context),
|
|
||||||
WoodyContext.
|
WoodyContext.
|
||||||
|
|
||||||
-spec set_woody_context(woody_context(), context()) -> context().
|
-spec set_woody_context(woody_context(), context()) -> context().
|
||||||
@ -92,25 +86,13 @@ set_party_client(PartyClient, Context) ->
|
|||||||
Context#{party_client => PartyClient}.
|
Context#{party_client => PartyClient}.
|
||||||
|
|
||||||
-spec get_party_client_context(context()) -> party_client_context().
|
-spec get_party_client_context(context()) -> party_client_context().
|
||||||
get_party_client_context(Context) ->
|
get_party_client_context(#{party_client_context := PartyContext}) ->
|
||||||
#{party_client_context := PartyContext} = ensure_party_user_info_set(Context),
|
|
||||||
PartyContext.
|
PartyContext.
|
||||||
|
|
||||||
-spec set_party_client_context(party_client_context(), context()) -> context().
|
-spec set_party_client_context(party_client_context(), context()) -> context().
|
||||||
set_party_client_context(PartyContext, Context) ->
|
set_party_client_context(PartyContext, Context) ->
|
||||||
Context#{party_client_context := PartyContext}.
|
Context#{party_client_context := PartyContext}.
|
||||||
|
|
||||||
-spec get_user_identity(context()) -> user_identity() | no_return().
|
|
||||||
get_user_identity(#{user_identity := Identity}) ->
|
|
||||||
Identity;
|
|
||||||
get_user_identity(Context) ->
|
|
||||||
WoodyContext = get_woody_context(Context),
|
|
||||||
woody_user_identity:get(WoodyContext).
|
|
||||||
|
|
||||||
-spec set_user_identity(user_identity(), context()) -> context().
|
|
||||||
set_user_identity(Identity, Context) ->
|
|
||||||
Context#{user_identity => Identity}.
|
|
||||||
|
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|
||||||
-spec ensure_woody_context_exists(options()) -> options().
|
-spec ensure_woody_context_exists(options()) -> options().
|
||||||
@ -124,17 +106,3 @@ ensure_party_context_exists(#{party_client_context := _PartyContext} = Options)
|
|||||||
Options;
|
Options;
|
||||||
ensure_party_context_exists(#{woody_context := WoodyContext} = Options) ->
|
ensure_party_context_exists(#{woody_context := WoodyContext} = Options) ->
|
||||||
Options#{party_client_context => party_client:create_context(#{woody_context => WoodyContext})}.
|
Options#{party_client_context => party_client:create_context(#{woody_context => WoodyContext})}.
|
||||||
|
|
||||||
-spec ensure_woody_user_info_set(context()) -> context().
|
|
||||||
ensure_woody_user_info_set(#{user_identity := Identity, woody_context := WoodyContext} = Context) ->
|
|
||||||
NewWoodyContext = woody_user_identity:put(Identity, WoodyContext),
|
|
||||||
Context#{woody_context := NewWoodyContext};
|
|
||||||
ensure_woody_user_info_set(Context) ->
|
|
||||||
Context.
|
|
||||||
|
|
||||||
-spec ensure_party_user_info_set(context()) -> context().
|
|
||||||
ensure_party_user_info_set(#{user_identity := Identity, party_client_context := PartyContext} = Context) ->
|
|
||||||
NewPartyContext = party_client_context:set_user_info(Identity, PartyContext),
|
|
||||||
Context#{party_client_context := NewPartyContext};
|
|
||||||
ensure_party_user_info_set(Context) ->
|
|
||||||
Context.
|
|
||||||
|
@ -64,7 +64,6 @@ handle_function_('Create', {CustomerParams}, _Opts) ->
|
|||||||
ok = set_meta(CustomerID),
|
ok = set_meta(CustomerID),
|
||||||
PartyID = CustomerParams#payproc_CustomerParams.party_id,
|
PartyID = CustomerParams#payproc_CustomerParams.party_id,
|
||||||
ShopID = CustomerParams#payproc_CustomerParams.shop_id,
|
ShopID = CustomerParams#payproc_CustomerParams.shop_id,
|
||||||
ok = assert_party_accessible(PartyID),
|
|
||||||
Party = hg_party:get_party(PartyID),
|
Party = hg_party:get_party(PartyID),
|
||||||
Shop = ensure_shop_exists(hg_party:get_shop(ShopID, Party)),
|
Shop = ensure_shop_exists(hg_party:get_shop(ShopID, Party)),
|
||||||
ok = assert_party_shop_operable(Shop, Party),
|
ok = assert_party_shop_operable(Shop, Party),
|
||||||
@ -340,16 +339,6 @@ validate_paytool_params(PaytoolParams) ->
|
|||||||
try
|
try
|
||||||
ok = hg_recurrent_paytool:validate_paytool_params(PaytoolParams)
|
ok = hg_recurrent_paytool:validate_paytool_params(PaytoolParams)
|
||||||
catch
|
catch
|
||||||
throw:(Exception = #payproc_InvalidUser{}) ->
|
|
||||||
throw(Exception);
|
|
||||||
throw:(Exception = #payproc_InvalidPartyStatus{}) ->
|
|
||||||
throw(Exception);
|
|
||||||
throw:(Exception = #payproc_InvalidShopStatus{}) ->
|
|
||||||
throw(Exception);
|
|
||||||
throw:(Exception = #payproc_InvalidContractStatus{}) ->
|
|
||||||
throw(Exception);
|
|
||||||
throw:(Exception = #payproc_OperationNotPermitted{}) ->
|
|
||||||
throw(Exception);
|
|
||||||
throw:(#payproc_InvalidPaymentMethod{}) ->
|
throw:(#payproc_InvalidPaymentMethod{}) ->
|
||||||
throw(#payproc_OperationNotPermitted{})
|
throw(#payproc_OperationNotPermitted{})
|
||||||
end.
|
end.
|
||||||
@ -664,12 +653,8 @@ assert_customer_present(_) ->
|
|||||||
|
|
||||||
assert_customer_accessible(St = #st{}) ->
|
assert_customer_accessible(St = #st{}) ->
|
||||||
ok = assert_customer_present(St),
|
ok = assert_customer_present(St),
|
||||||
ok = assert_party_accessible(get_party_id(St)),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
assert_party_accessible(PartyID) ->
|
|
||||||
hg_invoice_utils:assert_party_accessible(PartyID).
|
|
||||||
|
|
||||||
assert_customer_operable(St = #st{}) ->
|
assert_customer_operable(St = #st{}) ->
|
||||||
ok = assert_customer_accessible(St),
|
ok = assert_customer_accessible(St),
|
||||||
Party = hg_party:get_party(get_party_id(St)),
|
Party = hg_party:get_party(get_party_id(St)),
|
||||||
|
@ -51,7 +51,6 @@
|
|||||||
-export([fail/1]).
|
-export([fail/1]).
|
||||||
|
|
||||||
-import(hg_invoice_utils, [
|
-import(hg_invoice_utils, [
|
||||||
assert_party_accessible/1,
|
|
||||||
assert_party_operable/1,
|
assert_party_operable/1,
|
||||||
assert_shop_operable/1,
|
assert_shop_operable/1,
|
||||||
assert_shop_exists/1
|
assert_shop_exists/1
|
||||||
@ -146,18 +145,26 @@ get_payment_opts(Revision, _, St = #st{invoice = Invoice}) ->
|
|||||||
handle_function(Func, Args, Opts) ->
|
handle_function(Func, Args, Opts) ->
|
||||||
scoper:scope(
|
scoper:scope(
|
||||||
invoicing,
|
invoicing,
|
||||||
fun() -> handle_function_(Func, Args, Opts) end
|
fun() ->
|
||||||
|
handle_function_(Func, remove_user_info_arg(Args), Opts)
|
||||||
|
end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
%% @TODO Delete after protocol migration
|
||||||
|
%% This is a migration measure to make sure we can accept both old and new (with no userinfo) protocol here
|
||||||
|
remove_user_info_arg(Args0) ->
|
||||||
|
erlang:delete_element(1, Args0).
|
||||||
|
|
||||||
|
add_user_info_arg(Args0) ->
|
||||||
|
erlang:insert_element(1, Args0, undefined).
|
||||||
|
|
||||||
-spec handle_function_(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) -> term() | no_return().
|
-spec handle_function_(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
handle_function_('Create', {UserInfo, InvoiceParams}, _Opts) ->
|
handle_function_('Create', {InvoiceParams}, _Opts) ->
|
||||||
DomainRevision = hg_domain:head(),
|
DomainRevision = hg_domain:head(),
|
||||||
InvoiceID = InvoiceParams#payproc_InvoiceParams.id,
|
InvoiceID = InvoiceParams#payproc_InvoiceParams.id,
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
PartyID = InvoiceParams#payproc_InvoiceParams.party_id,
|
PartyID = InvoiceParams#payproc_InvoiceParams.party_id,
|
||||||
ShopID = InvoiceParams#payproc_InvoiceParams.shop_id,
|
ShopID = InvoiceParams#payproc_InvoiceParams.shop_id,
|
||||||
_ = assert_party_accessible(PartyID),
|
|
||||||
Party = hg_party:get_party(PartyID),
|
Party = hg_party:get_party(PartyID),
|
||||||
Shop = assert_shop_exists(hg_party:get_shop(ShopID, Party)),
|
Shop = assert_shop_exists(hg_party:get_shop(ShopID, Party)),
|
||||||
_ = assert_party_shop_operable(Shop, Party),
|
_ = assert_party_shop_operable(Shop, Party),
|
||||||
@ -168,10 +175,9 @@ handle_function_('Create', {UserInfo, InvoiceParams}, _Opts) ->
|
|||||||
Allocation = maybe_allocation(AllocationPrototype, Cost, MerchantTerms, Party, Shop),
|
Allocation = maybe_allocation(AllocationPrototype, Cost, MerchantTerms, Party, Shop),
|
||||||
ok = ensure_started(InvoiceID, undefined, Party#domain_Party.revision, InvoiceParams, Allocation),
|
ok = ensure_started(InvoiceID, undefined, Party#domain_Party.revision, InvoiceParams, Allocation),
|
||||||
get_invoice_state(get_state(InvoiceID));
|
get_invoice_state(get_state(InvoiceID));
|
||||||
handle_function_('CreateWithTemplate', {UserInfo, Params}, _Opts) ->
|
handle_function_('CreateWithTemplate', {Params}, _Opts) ->
|
||||||
DomainRevision = hg_domain:head(),
|
DomainRevision = hg_domain:head(),
|
||||||
InvoiceID = Params#payproc_InvoiceWithTemplateParams.id,
|
InvoiceID = Params#payproc_InvoiceWithTemplateParams.id,
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
TplID = Params#payproc_InvoiceWithTemplateParams.template_id,
|
TplID = Params#payproc_InvoiceWithTemplateParams.template_id,
|
||||||
{Party, Shop, InvoiceParams} = make_invoice_params(Params),
|
{Party, Shop, InvoiceParams} = make_invoice_params(Params),
|
||||||
@ -184,60 +190,42 @@ handle_function_('CreateWithTemplate', {UserInfo, Params}, _Opts) ->
|
|||||||
get_invoice_state(get_state(InvoiceID));
|
get_invoice_state(get_state(InvoiceID));
|
||||||
handle_function_('CapturePaymentNew', Args, Opts) ->
|
handle_function_('CapturePaymentNew', Args, Opts) ->
|
||||||
handle_function_('CapturePayment', Args, Opts);
|
handle_function_('CapturePayment', Args, Opts);
|
||||||
handle_function_('Get', {UserInfo, InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}}, _Opts) ->
|
handle_function_('Get', {InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
St = get_state(InvoiceID, AfterID, Limit),
|
St = get_state(InvoiceID, AfterID, Limit),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
get_invoice_state(St);
|
get_invoice_state(St);
|
||||||
%% TODO Удалить после перехода на новый протокол
|
%% TODO Удалить после перехода на новый протокол
|
||||||
handle_function_('Get', {UserInfo, InvoiceID, undefined}, _Opts) ->
|
handle_function_('Get', {InvoiceID, undefined}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
get_invoice_state(St);
|
get_invoice_state(St);
|
||||||
handle_function_('GetEvents', {UserInfo, InvoiceID, Range}, _Opts) ->
|
handle_function_('GetEvents', {InvoiceID, Range}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
_ = assert_invoice(accessible, get_initial_state(InvoiceID)),
|
|
||||||
get_public_history(InvoiceID, Range);
|
get_public_history(InvoiceID, Range);
|
||||||
handle_function_('GetInvoiceAdjustment', {UserInfo, InvoiceID, ID}, _Opts) ->
|
handle_function_('GetInvoiceAdjustment', {InvoiceID, ID}, _Opts) ->
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
ok = set_invoicing_meta(InvoiceID),
|
ok = set_invoicing_meta(InvoiceID),
|
||||||
get_adjustment(ID, St);
|
get_adjustment(ID, St);
|
||||||
handle_function_('GetPayment', {UserInfo, InvoiceID, PaymentID}, _Opts) ->
|
handle_function_('GetPayment', {InvoiceID, PaymentID}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
get_payment_state(get_payment_session(PaymentID, St));
|
get_payment_state(get_payment_session(PaymentID, St));
|
||||||
handle_function_('GetPaymentRefund', {UserInfo, InvoiceID, PaymentID, ID}, _Opts) ->
|
handle_function_('GetPaymentRefund', {InvoiceID, PaymentID, ID}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
hg_invoice_payment:get_refund(ID, get_payment_session(PaymentID, St));
|
hg_invoice_payment:get_refund(ID, get_payment_session(PaymentID, St));
|
||||||
handle_function_('GetPaymentChargeback', {UserInfo, InvoiceID, PaymentID, ID}, _Opts) ->
|
handle_function_('GetPaymentChargeback', {InvoiceID, PaymentID, ID}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
CBSt = hg_invoice_payment:get_chargeback_state(ID, get_payment_session(PaymentID, St)),
|
CBSt = hg_invoice_payment:get_chargeback_state(ID, get_payment_session(PaymentID, St)),
|
||||||
hg_invoice_payment_chargeback:get(CBSt);
|
hg_invoice_payment_chargeback:get(CBSt);
|
||||||
handle_function_('GetPaymentAdjustment', {UserInfo, InvoiceID, PaymentID, ID}, _Opts) ->
|
handle_function_('GetPaymentAdjustment', {InvoiceID, PaymentID, ID}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
_ = set_invoicing_meta(InvoiceID, PaymentID),
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
hg_invoice_payment:get_adjustment(ID, get_payment_session(PaymentID, St));
|
hg_invoice_payment:get_adjustment(ID, get_payment_session(PaymentID, St));
|
||||||
handle_function_('ComputeTerms', {UserInfo, InvoiceID, PartyRevision0}, _Opts) ->
|
handle_function_('ComputeTerms', {InvoiceID, PartyRevision0}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
St = get_state(InvoiceID),
|
St = get_state(InvoiceID),
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
Timestamp = get_created_at(St),
|
Timestamp = get_created_at(St),
|
||||||
VS = hg_varset:prepare_shop_terms_varset(#{
|
VS = hg_varset:prepare_shop_terms_varset(#{
|
||||||
cost => get_cost(St)
|
cost => get_cost(St)
|
||||||
@ -269,20 +257,14 @@ handle_function_(Fun, Args, _Opts) when
|
|||||||
Fun =:= 'Fulfill' orelse
|
Fun =:= 'Fulfill' orelse
|
||||||
Fun =:= 'Rescind'
|
Fun =:= 'Rescind'
|
||||||
->
|
->
|
||||||
UserInfo = erlang:element(1, Args),
|
InvoiceID = erlang:element(1, Args),
|
||||||
InvoiceID = erlang:element(2, Args),
|
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
call(InvoiceID, Fun, Args);
|
call(InvoiceID, Fun, Args);
|
||||||
handle_function_('Repair', {UserInfo, InvoiceID, Changes, Action, Params}, _Opts) ->
|
handle_function_('Repair', {InvoiceID, Changes, Action, Params}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
_ = assert_invoice(accessible, get_initial_state(InvoiceID)),
|
|
||||||
repair(InvoiceID, {changes, Changes, Action, Params});
|
repair(InvoiceID, {changes, Changes, Action, Params});
|
||||||
handle_function_('RepairWithScenario', {UserInfo, InvoiceID, Scenario}, _Opts) ->
|
handle_function_('RepairWithScenario', {InvoiceID, Scenario}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_invoicing_meta(InvoiceID),
|
_ = set_invoicing_meta(InvoiceID),
|
||||||
_ = assert_invoice(accessible, get_initial_state(InvoiceID)),
|
|
||||||
repair(InvoiceID, {scenario, Scenario}).
|
repair(InvoiceID, {scenario, Scenario}).
|
||||||
|
|
||||||
maybe_allocation(undefined, _Cost, _MerchantTerms, _Party, _Shop) ->
|
maybe_allocation(undefined, _Cost, _MerchantTerms, _Party, _Shop) ->
|
||||||
@ -337,9 +319,6 @@ assert_invoice(operable, #st{party = Party} = St) when Party =/= undefined ->
|
|||||||
Party
|
Party
|
||||||
),
|
),
|
||||||
St;
|
St;
|
||||||
assert_invoice(accessible, #st{} = St) ->
|
|
||||||
assert_party_accessible(get_party_id(St)),
|
|
||||||
St;
|
|
||||||
assert_invoice({status, Status}, #st{invoice = #domain_Invoice{status = {Status, _}}} = St) ->
|
assert_invoice({status, Status}, #st{invoice = #domain_Invoice{status = {Status, _}}} = St) ->
|
||||||
St;
|
St;
|
||||||
assert_invoice({status, _Status}, #st{invoice = #domain_Invoice{status = Invalid}}) ->
|
assert_invoice({status, _Status}, #st{invoice = #domain_Invoice{status = Invalid}}) ->
|
||||||
@ -434,9 +413,6 @@ get_state(Ref) ->
|
|||||||
get_state(Ref, AfterID, Limit) ->
|
get_state(Ref, AfterID, Limit) ->
|
||||||
collapse_history(get_history(Ref, AfterID, Limit)).
|
collapse_history(get_history(Ref, AfterID, Limit)).
|
||||||
|
|
||||||
get_initial_state(Ref) ->
|
|
||||||
collapse_history(get_history(Ref, undefined, 1)).
|
|
||||||
|
|
||||||
get_public_history(InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}) ->
|
get_public_history(InvoiceID, #payproc_EventRange{'after' = AfterID, limit = Limit}) ->
|
||||||
[publish_invoice_event(InvoiceID, Ev) || Ev <- get_history(InvoiceID, AfterID, Limit)].
|
[publish_invoice_event(InvoiceID, Ev) || Ev <- get_history(InvoiceID, AfterID, Limit)].
|
||||||
|
|
||||||
@ -457,7 +433,7 @@ ensure_started(ID, TemplateID, PartyRevision, Params, Allocation) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
call(ID, Function, Args) ->
|
call(ID, Function, Args) ->
|
||||||
case hg_machine:thrift_call(?NS, ID, invoicing, {'Invoicing', Function}, Args) of
|
case hg_machine:thrift_call(?NS, ID, invoicing, {'Invoicing', Function}, add_user_info_arg(Args)) of
|
||||||
ok -> ok;
|
ok -> ok;
|
||||||
{ok, Reply} -> Reply;
|
{ok, Reply} -> Reply;
|
||||||
{exception, Exception} -> erlang:throw(Exception);
|
{exception, Exception} -> erlang:throw(Exception);
|
||||||
@ -607,21 +583,28 @@ handle_expiration(St) ->
|
|||||||
process_call(Call, #{history := History}) ->
|
process_call(Call, #{history := History}) ->
|
||||||
St = collapse_history(unmarshal_history(History)),
|
St = collapse_history(unmarshal_history(History)),
|
||||||
try
|
try
|
||||||
handle_result(handle_call(Call, St))
|
handle_result(handle_call(remove_user_info_from_call(Call), St))
|
||||||
catch
|
catch
|
||||||
throw:Exception ->
|
throw:Exception ->
|
||||||
{{exception, Exception}, #{}}
|
{{exception, Exception}, #{}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% @TODO Delete after protocol migration
|
||||||
|
%% This is a migration measure to make sure we can accept both old and new (with no userinfo) protocol here
|
||||||
|
remove_user_info_from_call({{'Invoicing', _} = Func, Args0}) ->
|
||||||
|
{Func, erlang:delete_element(1, Args0)};
|
||||||
|
remove_user_info_from_call(Call) ->
|
||||||
|
Call.
|
||||||
|
|
||||||
-spec handle_call(call(), st()) -> call_result().
|
-spec handle_call(call(), st()) -> call_result().
|
||||||
handle_call({{'Invoicing', 'StartPayment'}, {_UserInfo, _InvoiceID, PaymentParams}}, St0) ->
|
handle_call({{'Invoicing', 'StartPayment'}, {_InvoiceID, PaymentParams}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable], St),
|
_ = assert_invoice(operable, St),
|
||||||
_ = assert_all_adjustments_finalised(St),
|
_ = assert_all_adjustments_finalised(St),
|
||||||
start_payment(PaymentParams, St);
|
start_payment(PaymentParams, St);
|
||||||
handle_call({{'Invoicing', 'CapturePayment'}, {_UserInfo, _InvoiceID, PaymentID, Params}}, St0) ->
|
handle_call({{'Invoicing', 'CapturePayment'}, {_InvoiceID, PaymentID, Params}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable], St),
|
_ = assert_invoice(operable, St),
|
||||||
#payproc_InvoicePaymentCaptureParams{
|
#payproc_InvoicePaymentCaptureParams{
|
||||||
reason = Reason,
|
reason = Reason,
|
||||||
cash = Cash,
|
cash = Cash,
|
||||||
@ -637,9 +620,9 @@ handle_call({{'Invoicing', 'CapturePayment'}, {_UserInfo, _InvoiceID, PaymentID,
|
|||||||
action => Action,
|
action => Action,
|
||||||
state => St
|
state => St
|
||||||
};
|
};
|
||||||
handle_call({{'Invoicing', 'CancelPayment'}, {_UserInfo, _InvoiceID, PaymentID, Reason}}, St0) ->
|
handle_call({{'Invoicing', 'CancelPayment'}, {_InvoiceID, PaymentID, Reason}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable], St),
|
_ = assert_invoice(operable, St),
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
{ok, {Changes, Action}} = hg_invoice_payment:cancel(PaymentSession, Reason),
|
{ok, {Changes, Action}} = hg_invoice_payment:cancel(PaymentSession, Reason),
|
||||||
#{
|
#{
|
||||||
@ -648,17 +631,17 @@ handle_call({{'Invoicing', 'CancelPayment'}, {_UserInfo, _InvoiceID, PaymentID,
|
|||||||
action => Action,
|
action => Action,
|
||||||
state => St
|
state => St
|
||||||
};
|
};
|
||||||
handle_call({{'Invoicing', 'Fulfill'}, {_UserInfo, _InvoiceID, Reason}}, St0) ->
|
handle_call({{'Invoicing', 'Fulfill'}, {_InvoiceID, Reason}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable, {status, paid}], St),
|
_ = assert_invoice([operable, {status, paid}], St),
|
||||||
#{
|
#{
|
||||||
response => ok,
|
response => ok,
|
||||||
changes => [?invoice_status_changed(?invoice_fulfilled(hg_utils:format_reason(Reason)))],
|
changes => [?invoice_status_changed(?invoice_fulfilled(hg_utils:format_reason(Reason)))],
|
||||||
state => St
|
state => St
|
||||||
};
|
};
|
||||||
handle_call({{'Invoicing', 'Rescind'}, {_UserInfo, _InvoiceID, Reason}}, St0) ->
|
handle_call({{'Invoicing', 'Rescind'}, {_InvoiceID, Reason}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable, {status, unpaid}], St),
|
_ = assert_invoice([operable, {status, unpaid}], St),
|
||||||
_ = assert_no_pending_payment(St),
|
_ = assert_no_pending_payment(St),
|
||||||
#{
|
#{
|
||||||
response => ok,
|
response => ok,
|
||||||
@ -666,8 +649,7 @@ handle_call({{'Invoicing', 'Rescind'}, {_UserInfo, _InvoiceID, Reason}}, St0) ->
|
|||||||
action => hg_machine_action:unset_timer(),
|
action => hg_machine_action:unset_timer(),
|
||||||
state => St
|
state => St
|
||||||
};
|
};
|
||||||
handle_call({{'Invoicing', 'CreateInvoiceAdjustment'}, {_UserInfo, _InvoiceID, Params}}, St) ->
|
handle_call({{'Invoicing', 'CreateInvoiceAdjustment'}, {_InvoiceID, Params}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
ID = create_adjustment_id(St),
|
ID = create_adjustment_id(St),
|
||||||
TargetStatus = get_adjustment_params_target_status(Params),
|
TargetStatus = get_adjustment_params_target_status(Params),
|
||||||
InvoiceStatus = get_invoice_status(St),
|
InvoiceStatus = get_invoice_status(St),
|
||||||
@ -676,8 +658,7 @@ handle_call({{'Invoicing', 'CreateInvoiceAdjustment'}, {_UserInfo, _InvoiceID, P
|
|||||||
ok = assert_all_adjustments_finalised(St),
|
ok = assert_all_adjustments_finalised(St),
|
||||||
OccurredAt = hg_datetime:format_now(),
|
OccurredAt = hg_datetime:format_now(),
|
||||||
wrap_adjustment_impact(ID, hg_invoice_adjustment:create(ID, Params, OccurredAt), St, OccurredAt);
|
wrap_adjustment_impact(ID, hg_invoice_adjustment:create(ID, Params, OccurredAt), St, OccurredAt);
|
||||||
handle_call({{'Invoicing', 'CaptureAdjustment'}, {_UserInfo, _InvoiceID, ID}}, St) ->
|
handle_call({{'Invoicing', 'CaptureAdjustment'}, {_InvoiceID, ID}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
_ = assert_adjustment_processed(ID, St),
|
_ = assert_adjustment_processed(ID, St),
|
||||||
OccurredAt = hg_datetime:format_now(),
|
OccurredAt = hg_datetime:format_now(),
|
||||||
?adjustment_target_status(Status) = get_adjustment(ID, St),
|
?adjustment_target_status(Status) = get_adjustment(ID, St),
|
||||||
@ -688,8 +669,7 @@ handle_call({{'Invoicing', 'CaptureAdjustment'}, {_UserInfo, _InvoiceID, ID}}, S
|
|||||||
action => set_invoice_timer(Status, Action, St),
|
action => set_invoice_timer(Status, Action, St),
|
||||||
state => St
|
state => St
|
||||||
};
|
};
|
||||||
handle_call({{'Invoicing', 'CancelAdjustment'}, {_UserInfo, _InvoiceID, ID}}, St) ->
|
handle_call({{'Invoicing', 'CancelAdjustment'}, {_InvoiceID, ID}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
_ = assert_adjustment_processed(ID, St),
|
_ = assert_adjustment_processed(ID, St),
|
||||||
OccurredAt = hg_datetime:format_now(),
|
OccurredAt = hg_datetime:format_now(),
|
||||||
Status = get_invoice_status(St),
|
Status = get_invoice_status(St),
|
||||||
@ -700,47 +680,41 @@ handle_call({{'Invoicing', 'CancelAdjustment'}, {_UserInfo, _InvoiceID, ID}}, St
|
|||||||
action => set_invoice_timer(Status, Action, St),
|
action => set_invoice_timer(Status, Action, St),
|
||||||
state => St
|
state => St
|
||||||
};
|
};
|
||||||
handle_call({{'Invoicing', 'RefundPayment'}, {_UserInfo, _InvoiceID, PaymentID, Params}}, St0) ->
|
handle_call({{'Invoicing', 'RefundPayment'}, {_InvoiceID, PaymentID, Params}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable], St),
|
_ = assert_invoice(operable, St),
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
start_refund(refund, Params, PaymentID, PaymentSession, St);
|
start_refund(refund, Params, PaymentID, PaymentSession, St);
|
||||||
handle_call({{'Invoicing', 'CreateManualRefund'}, {_UserInfo, _InvoiceID, PaymentID, Params}}, St0) ->
|
handle_call({{'Invoicing', 'CreateManualRefund'}, {_InvoiceID, PaymentID, Params}}, St0) ->
|
||||||
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
St = St0#st{party = hg_party:get_party(get_party_id(St0))},
|
||||||
_ = assert_invoice([accessible, operable], St),
|
_ = assert_invoice(operable, St),
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
start_refund(manual_refund, Params, PaymentID, PaymentSession, St);
|
start_refund(manual_refund, Params, PaymentID, PaymentSession, St);
|
||||||
handle_call({{'Invoicing', 'CreateChargeback'}, {_UserInfo, _InvoiceID, PaymentID, Params}}, St) ->
|
handle_call({{'Invoicing', 'CreateChargeback'}, {_InvoiceID, PaymentID, Params}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
PaymentOpts = get_payment_opts(St),
|
PaymentOpts = get_payment_opts(St),
|
||||||
start_chargeback(Params, PaymentID, PaymentSession, PaymentOpts, St);
|
start_chargeback(Params, PaymentID, PaymentSession, PaymentOpts, St);
|
||||||
handle_call({{'Invoicing', 'CancelChargeback'}, {_UserInfo, _InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
handle_call({{'Invoicing', 'CancelChargeback'}, {_InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
||||||
#payproc_InvoicePaymentChargebackCancelParams{occurred_at = OccurredAt} = Params,
|
#payproc_InvoicePaymentChargebackCancelParams{occurred_at = OccurredAt} = Params,
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
CancelResult = hg_invoice_payment:cancel_chargeback(ChargebackID, PaymentSession, Params),
|
CancelResult = hg_invoice_payment:cancel_chargeback(ChargebackID, PaymentSession, Params),
|
||||||
wrap_payment_impact(PaymentID, CancelResult, St, OccurredAt);
|
wrap_payment_impact(PaymentID, CancelResult, St, OccurredAt);
|
||||||
handle_call({{'Invoicing', 'RejectChargeback'}, {_UserInfo, _InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
handle_call({{'Invoicing', 'RejectChargeback'}, {_InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
||||||
#payproc_InvoicePaymentChargebackRejectParams{occurred_at = OccurredAt} = Params,
|
#payproc_InvoicePaymentChargebackRejectParams{occurred_at = OccurredAt} = Params,
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
RejectResult = hg_invoice_payment:reject_chargeback(ChargebackID, PaymentSession, Params),
|
RejectResult = hg_invoice_payment:reject_chargeback(ChargebackID, PaymentSession, Params),
|
||||||
wrap_payment_impact(PaymentID, RejectResult, St, OccurredAt);
|
wrap_payment_impact(PaymentID, RejectResult, St, OccurredAt);
|
||||||
handle_call({{'Invoicing', 'AcceptChargeback'}, {_UserInfo, _InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
handle_call({{'Invoicing', 'AcceptChargeback'}, {_InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
||||||
#payproc_InvoicePaymentChargebackAcceptParams{occurred_at = OccurredAt} = Params,
|
#payproc_InvoicePaymentChargebackAcceptParams{occurred_at = OccurredAt} = Params,
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
AcceptResult = hg_invoice_payment:accept_chargeback(ChargebackID, PaymentSession, Params),
|
AcceptResult = hg_invoice_payment:accept_chargeback(ChargebackID, PaymentSession, Params),
|
||||||
wrap_payment_impact(PaymentID, AcceptResult, St, OccurredAt);
|
wrap_payment_impact(PaymentID, AcceptResult, St, OccurredAt);
|
||||||
handle_call({{'Invoicing', 'ReopenChargeback'}, {_UserInfo, _InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
handle_call({{'Invoicing', 'ReopenChargeback'}, {_InvoiceID, PaymentID, ChargebackID, Params}}, St) ->
|
||||||
#payproc_InvoicePaymentChargebackReopenParams{occurred_at = OccurredAt} = Params,
|
#payproc_InvoicePaymentChargebackReopenParams{occurred_at = OccurredAt} = Params,
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
ReopenResult = hg_invoice_payment:reopen_chargeback(ChargebackID, PaymentSession, Params),
|
ReopenResult = hg_invoice_payment:reopen_chargeback(ChargebackID, PaymentSession, Params),
|
||||||
wrap_payment_impact(PaymentID, ReopenResult, St, OccurredAt);
|
wrap_payment_impact(PaymentID, ReopenResult, St, OccurredAt);
|
||||||
handle_call({{'Invoicing', 'CreatePaymentAdjustment'}, {_UserInfo, _InvoiceID, PaymentID, Params}}, St) ->
|
handle_call({{'Invoicing', 'CreatePaymentAdjustment'}, {_InvoiceID, PaymentID, Params}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
Opts = #{timestamp := Timestamp} = get_payment_opts(St),
|
Opts = #{timestamp := Timestamp} = get_payment_opts(St),
|
||||||
wrap_payment_impact(
|
wrap_payment_impact(
|
||||||
@ -748,8 +722,7 @@ handle_call({{'Invoicing', 'CreatePaymentAdjustment'}, {_UserInfo, _InvoiceID, P
|
|||||||
hg_invoice_payment:create_adjustment(Timestamp, Params, PaymentSession, Opts),
|
hg_invoice_payment:create_adjustment(Timestamp, Params, PaymentSession, Opts),
|
||||||
St
|
St
|
||||||
);
|
);
|
||||||
handle_call({{'Invoicing', 'CapturePaymentAdjustment'}, {_UserInfo, _InvoiceID, PaymentID, ID}}, St) ->
|
handle_call({{'Invoicing', 'CapturePaymentAdjustment'}, {_InvoiceID, PaymentID, ID}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
Adjustment = hg_invoice_payment:get_adjustment(ID, PaymentSession),
|
Adjustment = hg_invoice_payment:get_adjustment(ID, PaymentSession),
|
||||||
PaymentOpts = get_payment_opts(
|
PaymentOpts = get_payment_opts(
|
||||||
@ -759,8 +732,7 @@ handle_call({{'Invoicing', 'CapturePaymentAdjustment'}, {_UserInfo, _InvoiceID,
|
|||||||
),
|
),
|
||||||
Impact = hg_invoice_payment:capture_adjustment(ID, PaymentSession, PaymentOpts),
|
Impact = hg_invoice_payment:capture_adjustment(ID, PaymentSession, PaymentOpts),
|
||||||
wrap_payment_impact(PaymentID, Impact, St);
|
wrap_payment_impact(PaymentID, Impact, St);
|
||||||
handle_call({{'Invoicing', 'CancelPaymentAdjustment'}, {_UserInfo, _InvoiceID, PaymentID, ID}}, St) ->
|
handle_call({{'Invoicing', 'CancelPaymentAdjustment'}, {_InvoiceID, PaymentID, ID}}, St) ->
|
||||||
_ = assert_invoice(accessible, St),
|
|
||||||
PaymentSession = get_payment_session(PaymentID, St),
|
PaymentSession = get_payment_session(PaymentID, St),
|
||||||
Adjustment = hg_invoice_payment:get_adjustment(ID, PaymentSession),
|
Adjustment = hg_invoice_payment:get_adjustment(ID, PaymentSession),
|
||||||
PaymentOpts = get_payment_opts(
|
PaymentOpts = get_payment_opts(
|
||||||
@ -1272,9 +1244,6 @@ create_adjustment_id(#st{adjustments = Adjustments}) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
assume_user_identity(UserInfo) ->
|
|
||||||
hg_woody_handler_utils:assume_user_identity(UserInfo).
|
|
||||||
|
|
||||||
make_invoice_params(Params) ->
|
make_invoice_params(Params) ->
|
||||||
#payproc_InvoiceWithTemplateParams{
|
#payproc_InvoiceWithTemplateParams{
|
||||||
id = InvoiceID,
|
id = InvoiceID,
|
||||||
@ -1294,7 +1263,6 @@ make_invoice_params(Params) ->
|
|||||||
} = hg_invoice_template:get(TplID),
|
} = hg_invoice_template:get(TplID),
|
||||||
Party = hg_party:get_party(PartyID),
|
Party = hg_party:get_party(PartyID),
|
||||||
Shop = assert_shop_exists(hg_party:get_shop(ShopID, Party)),
|
Shop = assert_shop_exists(hg_party:get_shop(ShopID, Party)),
|
||||||
_ = assert_party_accessible(PartyID),
|
|
||||||
_ = assert_party_shop_operable(Shop, Party),
|
_ = assert_party_shop_operable(Shop, Party),
|
||||||
Cart = make_invoice_cart(Cost, TplDetails, Shop),
|
Cart = make_invoice_cart(Cost, TplDetails, Shop),
|
||||||
InvoiceDetails = #domain_InvoiceDetails{
|
InvoiceDetails = #domain_InvoiceDetails{
|
||||||
|
@ -3928,8 +3928,6 @@ get_customer(CustomerID) ->
|
|||||||
Customer;
|
Customer;
|
||||||
{exception, #payproc_CustomerNotFound{}} ->
|
{exception, #payproc_CustomerNotFound{}} ->
|
||||||
throw_invalid_request(<<"Customer not found">>);
|
throw_invalid_request(<<"Customer not found">>);
|
||||||
{exception, #payproc_InvalidUser{}} ->
|
|
||||||
throw_invalid_request(<<"Invalid customer">>);
|
|
||||||
{exception, Error} ->
|
{exception, Error} ->
|
||||||
error({<<"Can't get customer">>, Error})
|
error({<<"Can't get customer">>, Error})
|
||||||
end.
|
end.
|
||||||
|
@ -49,42 +49,45 @@ get_invoice_template(ID) ->
|
|||||||
handle_function(Func, Args, Opts) ->
|
handle_function(Func, Args, Opts) ->
|
||||||
scoper:scope(
|
scoper:scope(
|
||||||
invoice_templating,
|
invoice_templating,
|
||||||
fun() -> handle_function_(Func, Args, Opts) end
|
fun() ->
|
||||||
|
handle_function_(Func, remove_user_info_arg(Args), Opts)
|
||||||
|
end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
%% @TODO Delete after protocol migration
|
||||||
|
%% This is a migration measure to make sure we can accept both old and new (with no userinfo) protocol here
|
||||||
|
remove_user_info_arg(Args0) ->
|
||||||
|
erlang:delete_element(1, Args0).
|
||||||
|
|
||||||
|
add_user_info_arg(Args0) ->
|
||||||
|
erlang:insert_element(1, Args0, undefined).
|
||||||
|
|
||||||
-spec handle_function_(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) -> term() | no_return().
|
-spec handle_function_(woody:func(), woody:args(), hg_woody_wrapper:handler_opts()) -> term() | no_return().
|
||||||
handle_function_('Create', {UserInfo, Params}, _Opts) ->
|
handle_function_('Create', {Params}, _Opts) ->
|
||||||
TplID = Params#payproc_InvoiceTemplateCreateParams.template_id,
|
TplID = Params#payproc_InvoiceTemplateCreateParams.template_id,
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_meta(TplID),
|
_ = set_meta(TplID),
|
||||||
Party = get_party(Params#payproc_InvoiceTemplateCreateParams.party_id),
|
Party = get_party(Params#payproc_InvoiceTemplateCreateParams.party_id),
|
||||||
Shop = get_shop(Params#payproc_InvoiceTemplateCreateParams.shop_id, Party),
|
Shop = get_shop(Params#payproc_InvoiceTemplateCreateParams.shop_id, Party),
|
||||||
ok = validate_create_params(Params, Shop),
|
ok = validate_create_params(Params, Shop),
|
||||||
ok = start(TplID, Params),
|
ok = start(TplID, Params),
|
||||||
get_invoice_template(TplID);
|
get_invoice_template(TplID);
|
||||||
handle_function_('Get', {UserInfo, TplID}, _Opts) ->
|
handle_function_('Get', {TplID}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_meta(TplID),
|
_ = set_meta(TplID),
|
||||||
Tpl = get_invoice_template(TplID),
|
get_invoice_template(TplID);
|
||||||
_ = hg_invoice_utils:assert_party_accessible(Tpl#domain_InvoiceTemplate.owner_id),
|
handle_function_('Update' = Fun, {TplID, Params} = Args, _Opts) ->
|
||||||
Tpl;
|
|
||||||
handle_function_('Update' = Fun, {UserInfo, TplID, Params} = Args, _Opts) ->
|
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_meta(TplID),
|
_ = set_meta(TplID),
|
||||||
Tpl = get_invoice_template(TplID),
|
Tpl = get_invoice_template(TplID),
|
||||||
Party = get_party(Tpl#domain_InvoiceTemplate.owner_id),
|
Party = get_party(Tpl#domain_InvoiceTemplate.owner_id),
|
||||||
Shop = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party),
|
Shop = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party),
|
||||||
ok = validate_update_params(Params, Shop),
|
ok = validate_update_params(Params, Shop),
|
||||||
call(TplID, Fun, Args);
|
call(TplID, Fun, Args);
|
||||||
handle_function_('Delete' = Fun, {UserInfo, TplID} = Args, _Opts) ->
|
handle_function_('Delete' = Fun, {TplID} = Args, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
Tpl = get_invoice_template(TplID),
|
Tpl = get_invoice_template(TplID),
|
||||||
Party = get_party(Tpl#domain_InvoiceTemplate.owner_id),
|
Party = get_party(Tpl#domain_InvoiceTemplate.owner_id),
|
||||||
_ = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party),
|
_ = get_shop(Tpl#domain_InvoiceTemplate.shop_id, Party),
|
||||||
_ = set_meta(TplID),
|
_ = set_meta(TplID),
|
||||||
call(TplID, Fun, Args);
|
call(TplID, Fun, Args);
|
||||||
handle_function_('ComputeTerms', {UserInfo, TplID, Timestamp, PartyRevision0}, _Opts) ->
|
handle_function_('ComputeTerms', {TplID, Timestamp, PartyRevision0}, _Opts) ->
|
||||||
ok = assume_user_identity(UserInfo),
|
|
||||||
_ = set_meta(TplID),
|
_ = set_meta(TplID),
|
||||||
Tpl = get_invoice_template(TplID),
|
Tpl = get_invoice_template(TplID),
|
||||||
Cost =
|
Cost =
|
||||||
@ -106,11 +109,7 @@ handle_function_('ComputeTerms', {UserInfo, TplID, Timestamp, PartyRevision0}, _
|
|||||||
VS
|
VS
|
||||||
).
|
).
|
||||||
|
|
||||||
assume_user_identity(UserInfo) ->
|
|
||||||
hg_woody_handler_utils:assume_user_identity(UserInfo).
|
|
||||||
|
|
||||||
get_party(PartyID) ->
|
get_party(PartyID) ->
|
||||||
_ = hg_invoice_utils:assert_party_accessible(PartyID),
|
|
||||||
Party = hg_party:get_party(PartyID),
|
Party = hg_party:get_party(PartyID),
|
||||||
_ = hg_invoice_utils:assert_party_operable(Party),
|
_ = hg_invoice_utils:assert_party_operable(Party),
|
||||||
Party.
|
Party.
|
||||||
@ -157,7 +156,9 @@ start(ID, Params) ->
|
|||||||
map_start_error(hg_machine:start(?NS, ID, EncodedParams)).
|
map_start_error(hg_machine:start(?NS, ID, EncodedParams)).
|
||||||
|
|
||||||
call(ID, Function, Args) ->
|
call(ID, Function, Args) ->
|
||||||
case hg_machine:thrift_call(?NS, ID, invoice_templating, {'InvoiceTemplating', Function}, Args) of
|
case
|
||||||
|
hg_machine:thrift_call(?NS, ID, invoice_templating, {'InvoiceTemplating', Function}, add_user_info_arg(Args))
|
||||||
|
of
|
||||||
ok ->
|
ok ->
|
||||||
ok;
|
ok;
|
||||||
{ok, Reply} ->
|
{ok, Reply} ->
|
||||||
@ -250,7 +251,7 @@ process_signal({repair, _}, _Machine) ->
|
|||||||
-spec process_call(call(), hg_machine:machine()) -> {hg_machine:response(), hg_machine:result()}.
|
-spec process_call(call(), hg_machine:machine()) -> {hg_machine:response(), hg_machine:result()}.
|
||||||
process_call(Call, #{history := History}) ->
|
process_call(Call, #{history := History}) ->
|
||||||
St = collapse_history(unmarshal_history(History)),
|
St = collapse_history(unmarshal_history(History)),
|
||||||
try handle_call(Call, St) of
|
try handle_call(remove_user_info_from_call(Call), St) of
|
||||||
{ok, Changes} ->
|
{ok, Changes} ->
|
||||||
{ok, #{events => [marshal_event_payload(Changes)]}};
|
{ok, #{events => [marshal_event_payload(Changes)]}};
|
||||||
{Reply, Changes} ->
|
{Reply, Changes} ->
|
||||||
@ -260,10 +261,15 @@ process_call(Call, #{history := History}) ->
|
|||||||
{{exception, Exception}, #{}}
|
{{exception, Exception}, #{}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle_call({{'InvoiceTemplating', 'Update'}, {_UserInfo, _TplID, Params}}, Tpl) ->
|
%% @TODO Delete after protocol migration
|
||||||
|
%% This is a migration measure to make sure we can accept both old and new (with no userinfo) protocol here
|
||||||
|
remove_user_info_from_call({{'InvoiceTemplating', _} = Func, Args0}) ->
|
||||||
|
{Func, erlang:delete_element(1, Args0)}.
|
||||||
|
|
||||||
|
handle_call({{'InvoiceTemplating', 'Update'}, {_TplID, Params}}, Tpl) ->
|
||||||
Changes = [?tpl_updated(Params)],
|
Changes = [?tpl_updated(Params)],
|
||||||
{merge_changes(Changes, Tpl), Changes};
|
{merge_changes(Changes, Tpl), Changes};
|
||||||
handle_call({{'InvoiceTemplating', 'Delete'}, {_UserInfo, _TplID}}, _Tpl) ->
|
handle_call({{'InvoiceTemplating', 'Delete'}, {_TplID}}, _Tpl) ->
|
||||||
{ok, [?tpl_deleted()]}.
|
{ok, [?tpl_deleted()]}.
|
||||||
|
|
||||||
collapse_history(History) ->
|
collapse_history(History) ->
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
-export([validate_cost/2]).
|
-export([validate_cost/2]).
|
||||||
-export([validate_currency/2]).
|
-export([validate_currency/2]).
|
||||||
-export([validate_cash_range/1]).
|
-export([validate_cash_range/1]).
|
||||||
-export([assert_party_accessible/1]).
|
|
||||||
-export([assert_party_operable/1]).
|
-export([assert_party_operable/1]).
|
||||||
-export([assert_shop_exists/1]).
|
-export([assert_shop_exists/1]).
|
||||||
-export([assert_shop_operable/1]).
|
-export([assert_shop_operable/1]).
|
||||||
@ -49,16 +48,6 @@ validate_amount(_) ->
|
|||||||
validate_currency(Currency, Shop = #domain_Shop{}) ->
|
validate_currency(Currency, Shop = #domain_Shop{}) ->
|
||||||
validate_currency_(Currency, get_shop_currency(Shop)).
|
validate_currency_(Currency, get_shop_currency(Shop)).
|
||||||
|
|
||||||
-spec assert_party_accessible(party_id()) -> ok.
|
|
||||||
assert_party_accessible(PartyID) ->
|
|
||||||
UserIdentity = hg_woody_handler_utils:get_user_identity(),
|
|
||||||
case hg_access_control:check_user(UserIdentity, PartyID) of
|
|
||||||
ok ->
|
|
||||||
ok;
|
|
||||||
invalid_user ->
|
|
||||||
throw(#payproc_InvalidUser{})
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec validate_cash_range(cash_range()) -> ok.
|
-spec validate_cash_range(cash_range()) -> ok.
|
||||||
validate_cash_range(#domain_CashRange{
|
validate_cash_range(#domain_CashRange{
|
||||||
lower = {LType, #domain_Cash{amount = LAmount, currency = Currency}},
|
lower = {LType, #domain_Cash{amount = LAmount, currency = Currency}},
|
||||||
|
@ -747,7 +747,6 @@ handle_result_action(#{}, Acc) ->
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
ensure_party_accessible(#payproc_RecurrentPaymentToolParams{party_id = PartyID, party_revision = Revision0}) ->
|
ensure_party_accessible(#payproc_RecurrentPaymentToolParams{party_id = PartyID, party_revision = Revision0}) ->
|
||||||
_ = hg_invoice_utils:assert_party_accessible(PartyID),
|
|
||||||
Revision = ensure_party_revision_defined(PartyID, Revision0),
|
Revision = ensure_party_revision_defined(PartyID, Revision0),
|
||||||
hg_party:checkout(PartyID, {revision, Revision}).
|
hg_party:checkout(PartyID, {revision, Revision}).
|
||||||
|
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
-module(hg_woody_handler_utils).
|
|
||||||
|
|
||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
|
||||||
|
|
||||||
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
|
|
||||||
-type user_identity() :: woody_user_identity:user_identity().
|
|
||||||
|
|
||||||
-export([get_user_identity/0]).
|
|
||||||
-export([collect_user_identity/1]).
|
|
||||||
-export([set_user_identity/1]).
|
|
||||||
-export([assume_user_identity/1]).
|
|
||||||
|
|
||||||
-spec get_user_identity() -> woody_user_identity:user_identity() | undefined.
|
|
||||||
get_user_identity() ->
|
|
||||||
try
|
|
||||||
Context = hg_context:load(),
|
|
||||||
woody_user_identity:get(hg_context:get_woody_context(Context))
|
|
||||||
catch
|
|
||||||
throw:{missing_required, _Key} ->
|
|
||||||
undefined
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec collect_user_identity(user_info()) -> user_identity().
|
|
||||||
collect_user_identity(UserInfo) ->
|
|
||||||
case get_user_identity() of
|
|
||||||
V when V /= undefined ->
|
|
||||||
V;
|
|
||||||
undefined ->
|
|
||||||
map_user_info(UserInfo)
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec set_user_identity(user_identity()) -> ok.
|
|
||||||
set_user_identity(UserIdentity) ->
|
|
||||||
hg_context:save(hg_context:set_user_identity(UserIdentity, hg_context:load())).
|
|
||||||
|
|
||||||
-spec assume_user_identity(user_info()) -> ok.
|
|
||||||
assume_user_identity(UserInfo) ->
|
|
||||||
case get_user_identity() of
|
|
||||||
V when V /= undefined ->
|
|
||||||
ok;
|
|
||||||
undefined ->
|
|
||||||
set_user_identity(map_user_info(UserInfo))
|
|
||||||
end.
|
|
||||||
|
|
||||||
map_user_info(#payproc_UserInfo{id = PartyID, type = Type}) ->
|
|
||||||
#{
|
|
||||||
id => PartyID,
|
|
||||||
realm => map_user_type(Type)
|
|
||||||
}.
|
|
||||||
|
|
||||||
map_user_type({external_user, #payproc_ExternalUser{}}) ->
|
|
||||||
<<"external">>;
|
|
||||||
map_user_type({internal_user, #payproc_InternalUser{}}) ->
|
|
||||||
<<"internal">>;
|
|
||||||
map_user_type({service_user, #payproc_ServiceUser{}}) ->
|
|
||||||
<<"service">>.
|
|
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
-export([cfg/2]).
|
-export([cfg/2]).
|
||||||
|
|
||||||
|
-export([create_client/1]).
|
||||||
-export([create_client/2]).
|
-export([create_client/2]).
|
||||||
-export([create_client/3]).
|
|
||||||
|
|
||||||
-export([create_party_and_shop/6]).
|
-export([create_party_and_shop/6]).
|
||||||
-export([create_party/2]).
|
-export([create_party/2]).
|
||||||
@ -296,19 +296,16 @@ cfg(Key, Config) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec create_client(woody:url(), woody_user_identity:id()) -> hg_client_api:t().
|
-spec create_client(woody:url()) -> hg_client_api:t().
|
||||||
create_client(RootUrl, UserID) ->
|
create_client(RootUrl) ->
|
||||||
create_client_w_context(RootUrl, UserID, woody_context:new()).
|
create_client_w_context(RootUrl, woody_context:new()).
|
||||||
|
|
||||||
-spec create_client(woody:url(), woody_user_identity:id(), woody:trace_id()) -> hg_client_api:t().
|
-spec create_client(woody:url(), woody:trace_id()) -> hg_client_api:t().
|
||||||
create_client(RootUrl, UserID, TraceID) ->
|
create_client(RootUrl, TraceID) ->
|
||||||
create_client_w_context(RootUrl, UserID, woody_context:new(TraceID)).
|
create_client_w_context(RootUrl, woody_context:new(TraceID)).
|
||||||
|
|
||||||
create_client_w_context(RootUrl, UserID, WoodyCtx) ->
|
create_client_w_context(RootUrl, WoodyCtx) ->
|
||||||
hg_client_api:new(RootUrl, woody_user_identity:put(make_user_identity(UserID), WoodyCtx)).
|
hg_client_api:new(RootUrl, WoodyCtx).
|
||||||
|
|
||||||
make_user_identity(UserID) ->
|
|
||||||
#{id => genlib:to_binary(UserID), realm => <<"external">>}.
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
-export([init_per_testcase/2]).
|
-export([init_per_testcase/2]).
|
||||||
-export([end_per_testcase/2]).
|
-export([end_per_testcase/2]).
|
||||||
|
|
||||||
-export([invalid_user/1]).
|
|
||||||
-export([invalid_party/1]).
|
-export([invalid_party/1]).
|
||||||
-export([invalid_shop/1]).
|
-export([invalid_shop/1]).
|
||||||
-export([invalid_party_status/1]).
|
-export([invalid_party_status/1]).
|
||||||
@ -81,7 +80,7 @@ init_per_suite(C) ->
|
|||||||
_ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())),
|
_ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())),
|
||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
PartyClient = {party_client:create_client(), party_client:create_context(user_info())},
|
PartyClient = {party_client:create_client(), party_client:create_context()},
|
||||||
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
||||||
_ = unlink(SupPid),
|
_ = unlink(SupPid),
|
||||||
@ -97,9 +96,6 @@ init_per_suite(C) ->
|
|||||||
ok = start_proxies([{hg_dummy_provider, 1, C1}, {hg_dummy_inspector, 2, C1}]),
|
ok = start_proxies([{hg_dummy_provider, 1, C1}, {hg_dummy_inspector, 2, C1}]),
|
||||||
C1.
|
C1.
|
||||||
|
|
||||||
user_info() ->
|
|
||||||
#{user_info => #{id => <<"test">>, realm => <<"service">>}}.
|
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> _.
|
-spec end_per_suite(config()) -> _.
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
_ = hg_domain:cleanup(),
|
_ = hg_domain:cleanup(),
|
||||||
@ -117,7 +113,6 @@ all() ->
|
|||||||
groups() ->
|
groups() ->
|
||||||
[
|
[
|
||||||
{invalid_customer_params, [sequence], [
|
{invalid_customer_params, [sequence], [
|
||||||
invalid_user,
|
|
||||||
invalid_party,
|
invalid_party,
|
||||||
invalid_shop,
|
invalid_shop,
|
||||||
invalid_party_status,
|
invalid_party_status,
|
||||||
@ -158,9 +153,8 @@ groups() ->
|
|||||||
-spec init_per_testcase(test_case_name(), config()) -> config().
|
-spec init_per_testcase(test_case_name(), config()) -> config().
|
||||||
init_per_testcase(Name, C) ->
|
init_per_testcase(Name, C) ->
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyID = cfg(party_id, C),
|
|
||||||
TraceID = hg_ct_helper:make_trace_id(Name),
|
TraceID = hg_ct_helper:make_trace_id(Name),
|
||||||
Client = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, PartyID, TraceID)),
|
Client = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, TraceID)),
|
||||||
[
|
[
|
||||||
{test_case_name, genlib:to_binary(Name)},
|
{test_case_name, genlib:to_binary(Name)},
|
||||||
{trace_id, TraceID},
|
{trace_id, TraceID},
|
||||||
@ -174,24 +168,16 @@ end_per_testcase(_Name, _C) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-spec invalid_user(config()) -> test_case_result().
|
|
||||||
-spec invalid_party(config()) -> test_case_result().
|
-spec invalid_party(config()) -> test_case_result().
|
||||||
-spec invalid_shop(config()) -> test_case_result().
|
-spec invalid_shop(config()) -> test_case_result().
|
||||||
-spec invalid_party_status(config()) -> test_case_result().
|
-spec invalid_party_status(config()) -> test_case_result().
|
||||||
-spec invalid_shop_status(config()) -> test_case_result().
|
-spec invalid_shop_status(config()) -> test_case_result().
|
||||||
|
|
||||||
invalid_user(C) ->
|
|
||||||
Client = cfg(client, C),
|
|
||||||
PartyID = hg_utils:unique_id(),
|
|
||||||
ShopID = hg_utils:unique_id(),
|
|
||||||
Params = hg_ct_helper:make_customer_params(PartyID, ShopID, cfg(test_case_name, C)),
|
|
||||||
{exception, #payproc_InvalidUser{}} = hg_client_customer:create(Params, Client).
|
|
||||||
|
|
||||||
invalid_party(C) ->
|
invalid_party(C) ->
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
ShopID = hg_utils:unique_id(),
|
ShopID = hg_utils:unique_id(),
|
||||||
Client = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, PartyID, cfg(trace_id, C))),
|
Client = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, cfg(trace_id, C))),
|
||||||
Params = hg_ct_helper:make_customer_params(PartyID, ShopID, cfg(test_case_name, C)),
|
Params = hg_ct_helper:make_customer_params(PartyID, ShopID, cfg(test_case_name, C)),
|
||||||
{exception, #payproc_PartyNotFound{}} = hg_client_customer:create(Params, Client).
|
{exception, #payproc_PartyNotFound{}} = hg_client_customer:create(Params, Client).
|
||||||
|
|
||||||
|
@ -126,8 +126,8 @@ init_per_suite(C) ->
|
|||||||
_ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())),
|
_ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())),
|
||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
PartyClient = {party_client:create_client(), party_client:create_context(user_info())},
|
PartyClient = {party_client:create_client(), party_client:create_context()},
|
||||||
CustomerClient = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, PartyID)),
|
CustomerClient = hg_client_customer:start(hg_ct_helper:create_client(RootUrl)),
|
||||||
_ = hg_ct_helper:create_party(PartyID, PartyClient),
|
_ = hg_ct_helper:create_party(PartyID, PartyClient),
|
||||||
Shop1ID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
Shop1ID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Shop2ID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
Shop2ID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
@ -146,9 +146,6 @@ init_per_suite(C) ->
|
|||||||
ok = start_proxies([{hg_dummy_provider, 1, C1}, {hg_dummy_inspector, 2, C1}]),
|
ok = start_proxies([{hg_dummy_provider, 1, C1}, {hg_dummy_inspector, 2, C1}]),
|
||||||
C1.
|
C1.
|
||||||
|
|
||||||
user_info() ->
|
|
||||||
#{user_info => #{id => <<"test">>, realm => <<"service">>}}.
|
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> config().
|
-spec end_per_suite(config()) -> config().
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
_ = hg_domain:cleanup(),
|
_ = hg_domain:cleanup(),
|
||||||
@ -165,7 +162,7 @@ end_per_group(_Name, _C) ->
|
|||||||
-spec init_per_testcase(test_case_name(), config()) -> config().
|
-spec init_per_testcase(test_case_name(), config()) -> config().
|
||||||
init_per_testcase(Name, C) ->
|
init_per_testcase(Name, C) ->
|
||||||
TraceID = hg_ct_helper:make_trace_id(Name),
|
TraceID = hg_ct_helper:make_trace_id(Name),
|
||||||
ApiClient = hg_ct_helper:create_client(cfg(root_url, C), cfg(party_id, C)),
|
ApiClient = hg_ct_helper:create_client(cfg(root_url, C)),
|
||||||
Client = hg_client_invoicing:start_link(ApiClient),
|
Client = hg_client_invoicing:start_link(ApiClient),
|
||||||
[
|
[
|
||||||
{test_case_name, genlib:to_binary(Name)},
|
{test_case_name, genlib:to_binary(Name)},
|
||||||
|
@ -94,7 +94,7 @@ init_per_suite(C) ->
|
|||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
|
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
PartyClient = {party_client:create_client(), party_client:create_context(user_info())},
|
PartyClient = {party_client:create_client(), party_client:create_context()},
|
||||||
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
|
|
||||||
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
||||||
@ -111,9 +111,6 @@ init_per_suite(C) ->
|
|||||||
ok = start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
|
ok = start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
|
||||||
NewC.
|
NewC.
|
||||||
|
|
||||||
user_info() ->
|
|
||||||
#{user_info => #{id => <<"test">>, realm => <<"service">>}}.
|
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> _.
|
-spec end_per_suite(config()) -> _.
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
_ = hg_domain:cleanup(),
|
_ = hg_domain:cleanup(),
|
||||||
@ -125,7 +122,7 @@ init_per_testcase(_Name, C) ->
|
|||||||
init_per_testcase(C).
|
init_per_testcase(C).
|
||||||
|
|
||||||
init_per_testcase(C) ->
|
init_per_testcase(C) ->
|
||||||
ApiClient = hg_ct_helper:create_client(cfg(root_url, C), cfg(party_id, C)),
|
ApiClient = hg_ct_helper:create_client(cfg(root_url, C)),
|
||||||
Client = hg_client_invoicing:start_link(ApiClient),
|
Client = hg_client_invoicing:start_link(ApiClient),
|
||||||
ClientTpl = hg_client_invoice_templating:start_link(ApiClient),
|
ClientTpl = hg_client_invoice_templating:start_link(ApiClient),
|
||||||
ok = hg_context:save(hg_context:create()),
|
ok = hg_context:save(hg_context:create()),
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
-export([init_per_testcase/2]).
|
-export([init_per_testcase/2]).
|
||||||
-export([end_per_testcase/2]).
|
-export([end_per_testcase/2]).
|
||||||
|
|
||||||
-export([create_invalid_party/1]).
|
|
||||||
-export([create_invalid_shop/1]).
|
-export([create_invalid_shop/1]).
|
||||||
-export([create_invalid_party_status/1]).
|
-export([create_invalid_party_status/1]).
|
||||||
-export([create_invalid_shop_status/1]).
|
-export([create_invalid_shop_status/1]).
|
||||||
@ -53,7 +52,6 @@
|
|||||||
-spec all() -> [test_case_name()].
|
-spec all() -> [test_case_name()].
|
||||||
all() ->
|
all() ->
|
||||||
[
|
[
|
||||||
create_invalid_party,
|
|
||||||
create_invalid_shop,
|
create_invalid_shop,
|
||||||
create_invalid_party_status,
|
create_invalid_party_status,
|
||||||
create_invalid_shop_status,
|
create_invalid_shop_status,
|
||||||
@ -88,7 +86,7 @@ init_per_suite(C) ->
|
|||||||
_ = hg_domain:insert(construct_domain_fixture()),
|
_ = hg_domain:insert(construct_domain_fixture()),
|
||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
Client = {party_client:create_client(), party_client:create_context(user_info())},
|
Client = {party_client:create_client(), party_client:create_context()},
|
||||||
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), Client),
|
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), Client),
|
||||||
[
|
[
|
||||||
{party_id, PartyID},
|
{party_id, PartyID},
|
||||||
@ -99,9 +97,6 @@ init_per_suite(C) ->
|
|||||||
| C
|
| C
|
||||||
].
|
].
|
||||||
|
|
||||||
user_info() ->
|
|
||||||
#{user_info => #{id => <<"test">>, realm => <<"service">>}}.
|
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> _.
|
-spec end_per_suite(config()) -> _.
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
_ = hg_domain:cleanup(),
|
_ = hg_domain:cleanup(),
|
||||||
@ -112,22 +107,13 @@ end_per_suite(C) ->
|
|||||||
-spec init_per_testcase(test_case_name(), config()) -> config().
|
-spec init_per_testcase(test_case_name(), config()) -> config().
|
||||||
init_per_testcase(_Name, C) ->
|
init_per_testcase(_Name, C) ->
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyID = cfg(party_id, C),
|
Client = hg_client_invoice_templating:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
Client = hg_client_invoice_templating:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
|
||||||
[{client, Client} | C].
|
[{client, Client} | C].
|
||||||
|
|
||||||
-spec end_per_testcase(test_case_name(), config()) -> _.
|
-spec end_per_testcase(test_case_name(), config()) -> _.
|
||||||
end_per_testcase(_Name, _C) ->
|
end_per_testcase(_Name, _C) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec create_invalid_party(config()) -> _.
|
|
||||||
create_invalid_party(C) ->
|
|
||||||
Client = cfg(client, C),
|
|
||||||
ShopID = cfg(shop_id, C),
|
|
||||||
PartyID = ?MISSING_PARTY_ID,
|
|
||||||
Params = make_invoice_tpl_create_params(PartyID, ShopID),
|
|
||||||
{exception, #payproc_InvalidUser{}} = hg_client_invoice_templating:create(Params, Client).
|
|
||||||
|
|
||||||
-spec create_invalid_shop(config()) -> _.
|
-spec create_invalid_shop(config()) -> _.
|
||||||
create_invalid_shop(C) ->
|
create_invalid_shop(C) ->
|
||||||
Client = cfg(client, C),
|
Client = cfg(client, C),
|
||||||
|
@ -713,12 +713,12 @@ init_per_suite(C) ->
|
|||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
|
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
PartyClient = {party_client:create_client(), party_client:create_context(user_info())},
|
PartyClient = {party_client:create_client(), party_client:create_context()},
|
||||||
CustomerClient = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, PartyID)),
|
CustomerClient = hg_client_customer:start(hg_ct_helper:create_client(RootUrl)),
|
||||||
|
|
||||||
Party2ID = hg_utils:unique_id(),
|
Party2ID = hg_utils:unique_id(),
|
||||||
PartyClient2 = {party_client:create_client(), party_client:create_context(user_info())},
|
PartyClient2 = {party_client:create_client(), party_client:create_context()},
|
||||||
CustomerClient2 = hg_client_customer:start(hg_ct_helper:create_client(RootUrl, Party2ID)),
|
CustomerClient2 = hg_client_customer:start(hg_ct_helper:create_client(RootUrl)),
|
||||||
|
|
||||||
Party3ID = <<"bIg merch">>,
|
Party3ID = <<"bIg merch">>,
|
||||||
_ = hg_ct_helper:create_party(Party3ID, PartyClient),
|
_ = hg_ct_helper:create_party(Party3ID, PartyClient),
|
||||||
@ -748,9 +748,6 @@ init_per_suite(C) ->
|
|||||||
ok = start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
|
ok = start_proxies([{hg_dummy_provider, 1, NewC}, {hg_dummy_inspector, 2, NewC}]),
|
||||||
NewC.
|
NewC.
|
||||||
|
|
||||||
user_info() ->
|
|
||||||
#{user_info => #{id => <<"test">>, realm => <<"service">>}}.
|
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> _.
|
-spec end_per_suite(config()) -> _.
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
_ = hg_domain:cleanup(),
|
_ = hg_domain:cleanup(),
|
||||||
@ -926,7 +923,7 @@ override_domain_fixture(Fixture, C) ->
|
|||||||
[{original_domain_revision, Revision} | init_per_testcase(C)].
|
[{original_domain_revision, Revision} | init_per_testcase(C)].
|
||||||
|
|
||||||
init_per_testcase(C) ->
|
init_per_testcase(C) ->
|
||||||
ApiClient = hg_ct_helper:create_client(cfg(root_url, C), cfg(party_id, C)),
|
ApiClient = hg_ct_helper:create_client(cfg(root_url, C)),
|
||||||
Client = hg_client_invoicing:start_link(ApiClient),
|
Client = hg_client_invoicing:start_link(ApiClient),
|
||||||
ClientTpl = hg_client_invoice_templating:start_link(ApiClient),
|
ClientTpl = hg_client_invoice_templating:start_link(ApiClient),
|
||||||
ok = hg_context:save(hg_context:create()),
|
ok = hg_context:save(hg_context:create()),
|
||||||
@ -1362,7 +1359,7 @@ payment_limit_success(C, PmtSys) ->
|
|||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
#{party_id := PartyID} = cfg(limits, C),
|
#{party_id := PartyID} = cfg(limits, C),
|
||||||
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
|
|
||||||
?invoice_state(
|
?invoice_state(
|
||||||
?invoice_w_status(?invoice_paid()),
|
?invoice_w_status(?invoice_paid()),
|
||||||
@ -1383,7 +1380,7 @@ payment_limit_other_shop_success(C, PmtSys) ->
|
|||||||
#{party_id := PartyID} = cfg(limits, C),
|
#{party_id := PartyID} = cfg(limits, C),
|
||||||
ShopID1 = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID1 = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
ShopID2 = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID2 = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1,
|
PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1,
|
||||||
|
|
||||||
?invoice_state(
|
?invoice_state(
|
||||||
@ -1409,7 +1406,7 @@ payment_limit_overflow(C, PmtSys) ->
|
|||||||
#{party_id := PartyID} = cfg(limits, C),
|
#{party_id := PartyID} = cfg(limits, C),
|
||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1,
|
PaymentAmount = ?LIMIT_UPPER_BOUNDARY - 1,
|
||||||
?invoice_state(
|
?invoice_state(
|
||||||
?invoice_w_status(?invoice_paid()) = Invoice,
|
?invoice_w_status(?invoice_paid()) = Invoice,
|
||||||
@ -1441,7 +1438,7 @@ switch_provider_after_limit_overflow(C, PmtSys, ProviderID) ->
|
|||||||
#{party_id_w_several_limits := PartyID} = cfg(limits, C),
|
#{party_id_w_several_limits := PartyID} = cfg(limits, C),
|
||||||
PaymentAmount = 49999,
|
PaymentAmount = 49999,
|
||||||
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
|
|
||||||
?invoice_state(
|
?invoice_state(
|
||||||
?invoice_w_status(?invoice_paid()) = Invoice,
|
?invoice_w_status(?invoice_paid()) = Invoice,
|
||||||
@ -1479,7 +1476,7 @@ refund_limit_success(C, PmtSys) ->
|
|||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
#{party_id := PartyID} = cfg(limits, C),
|
#{party_id := PartyID} = cfg(limits, C),
|
||||||
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
|
|
||||||
?invoice_state(
|
?invoice_state(
|
||||||
?invoice_w_status(?invoice_paid()),
|
?invoice_w_status(?invoice_paid()),
|
||||||
@ -1530,7 +1527,7 @@ payment_partial_capture_limit_success(C, PmtSys) ->
|
|||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
#{party_id := PartyID} = cfg(limits, C),
|
#{party_id := PartyID} = cfg(limits, C),
|
||||||
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(8), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
|
|
||||||
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(100), make_cash(InitialCost)),
|
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(100), make_cash(InitialCost)),
|
||||||
InvoiceID = create_invoice(InvoiceParams, Client),
|
InvoiceID = create_invoice(InvoiceParams, Client),
|
||||||
@ -1621,7 +1618,7 @@ payment_success_ruleset(C, PmtSys) ->
|
|||||||
PartyID = cfg(party_id_big_merch, C),
|
PartyID = cfg(party_id_big_merch, C),
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)),
|
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)),
|
||||||
InvoiceID = create_invoice(InvoiceParams, Client),
|
InvoiceID = create_invoice(InvoiceParams, Client),
|
||||||
@ -2510,7 +2507,7 @@ party_revision_check_new(C) ->
|
|||||||
party_revision_check(C, PartyID, PmtSys) ->
|
party_revision_check(C, PartyID, PmtSys) ->
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
Client = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
{InvoiceRev, InvoiceID} = invoice_create_and_get_revision(PartyID, Client, ShopID),
|
{InvoiceRev, InvoiceID} = invoice_create_and_get_revision(PartyID, Client, ShopID),
|
||||||
|
|
||||||
@ -3067,7 +3064,7 @@ invalid_payment_w_deprived_party_new(C) ->
|
|||||||
invalid_payment_w_deprived_party(C, PartyID, PmtSys) ->
|
invalid_payment_w_deprived_party(C, PartyID, PmtSys) ->
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)),
|
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubberduck">>, make_due_date(10), make_cash(42000)),
|
||||||
InvoiceID = create_invoice(InvoiceParams, InvoicingClient),
|
InvoiceID = create_invoice(InvoiceParams, InvoicingClient),
|
||||||
@ -3089,7 +3086,7 @@ external_account_posting(C, PmtSys) ->
|
|||||||
PartyID = ?PARTYID_EXTERNAL,
|
PartyID = ?PARTYID_EXTERNAL,
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?tmpl(2), ?pinst(2), PartyClient),
|
ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(2), <<"RUB">>, ?tmpl(2), ?pinst(2), PartyClient),
|
||||||
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubbermoss">>, make_due_date(10), make_cash(42000)),
|
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubbermoss">>, make_due_date(10), make_cash(42000)),
|
||||||
InvoiceID = create_invoice(InvoiceParams, InvoicingClient),
|
InvoiceID = create_invoice(InvoiceParams, InvoicingClient),
|
||||||
@ -3135,7 +3132,7 @@ terminal_cashflow_overrides_provider(C, PmtSys) ->
|
|||||||
PartyID = ?PARTYID_EXTERNAL,
|
PartyID = ?PARTYID_EXTERNAL,
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyClient = cfg(party_client, C),
|
PartyClient = cfg(party_client, C),
|
||||||
InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl, PartyID)),
|
InvoicingClient = hg_client_invoicing:start_link(hg_ct_helper:create_client(RootUrl)),
|
||||||
ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(4), <<"RUB">>, ?tmpl(2), ?pinst(2), PartyClient),
|
ShopID = hg_ct_helper:create_battle_ready_shop(PartyID, ?cat(4), <<"RUB">>, ?tmpl(2), ?pinst(2), PartyClient),
|
||||||
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubbermoss">>, make_due_date(10), make_cash(42000)),
|
InvoiceParams = make_invoice_params(PartyID, ShopID, <<"rubbermoss">>, make_due_date(10), make_cash(42000)),
|
||||||
InvoiceID = create_invoice(InvoiceParams, InvoicingClient),
|
InvoiceID = create_invoice(InvoiceParams, InvoicingClient),
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
-export([init_per_testcase/2]).
|
-export([init_per_testcase/2]).
|
||||||
-export([end_per_testcase/2]).
|
-export([end_per_testcase/2]).
|
||||||
|
|
||||||
-export([invalid_user/1]).
|
|
||||||
-export([invalid_user_new/1]).
|
|
||||||
-export([invalid_party/1]).
|
-export([invalid_party/1]).
|
||||||
-export([invalid_party_new/1]).
|
-export([invalid_party_new/1]).
|
||||||
-export([invalid_shop/1]).
|
-export([invalid_shop/1]).
|
||||||
@ -87,7 +85,7 @@ init_per_suite(C) ->
|
|||||||
_ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())),
|
_ = hg_domain:insert(construct_domain_fixture(construct_term_set_w_recurrent_paytools())),
|
||||||
RootUrl = maps:get(hellgate_root_url, Ret),
|
RootUrl = maps:get(hellgate_root_url, Ret),
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
PartyClient = {party_client:create_client(), party_client:create_context(user_info())},
|
PartyClient = {party_client:create_client(), party_client:create_context()},
|
||||||
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
ShopID = hg_ct_helper:create_party_and_shop(PartyID, ?cat(1), <<"RUB">>, ?tmpl(1), ?pinst(1), PartyClient),
|
||||||
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
{ok, SupPid} = supervisor:start_link(?MODULE, []),
|
||||||
_ = unlink(SupPid),
|
_ = unlink(SupPid),
|
||||||
@ -103,9 +101,6 @@ init_per_suite(C) ->
|
|||||||
ok = start_proxies([{hg_dummy_provider, 1, C1}, {hg_dummy_inspector, 2, C1}]),
|
ok = start_proxies([{hg_dummy_provider, 1, C1}, {hg_dummy_inspector, 2, C1}]),
|
||||||
C1.
|
C1.
|
||||||
|
|
||||||
user_info() ->
|
|
||||||
#{user_info => #{id => <<"test">>, realm => <<"service">>}}.
|
|
||||||
|
|
||||||
-spec end_per_suite(config()) -> _.
|
-spec end_per_suite(config()) -> _.
|
||||||
end_per_suite(C) ->
|
end_per_suite(C) ->
|
||||||
_ = hg_domain:cleanup(),
|
_ = hg_domain:cleanup(),
|
||||||
@ -139,8 +134,6 @@ all() ->
|
|||||||
groups() ->
|
groups() ->
|
||||||
[
|
[
|
||||||
{invalid_recurrent_paytool_params, [sequence], [
|
{invalid_recurrent_paytool_params, [sequence], [
|
||||||
invalid_user,
|
|
||||||
invalid_user_new,
|
|
||||||
invalid_party,
|
invalid_party,
|
||||||
invalid_party_new,
|
invalid_party_new,
|
||||||
invalid_shop,
|
invalid_shop,
|
||||||
@ -159,9 +152,8 @@ groups() ->
|
|||||||
-spec init_per_testcase(test_case_name(), config()) -> config().
|
-spec init_per_testcase(test_case_name(), config()) -> config().
|
||||||
init_per_testcase(Name, C) ->
|
init_per_testcase(Name, C) ->
|
||||||
RootUrl = cfg(root_url, C),
|
RootUrl = cfg(root_url, C),
|
||||||
PartyID = cfg(party_id, C),
|
|
||||||
TraceID = hg_ct_helper:make_trace_id(Name),
|
TraceID = hg_ct_helper:make_trace_id(Name),
|
||||||
Client = hg_client_recurrent_paytool:start(hg_ct_helper:create_client(RootUrl, PartyID, TraceID)),
|
Client = hg_client_recurrent_paytool:start(hg_ct_helper:create_client(RootUrl, TraceID)),
|
||||||
[
|
[
|
||||||
{test_case_name, genlib:to_binary(Name)},
|
{test_case_name, genlib:to_binary(Name)},
|
||||||
{trace_id, TraceID},
|
{trace_id, TraceID},
|
||||||
@ -179,8 +171,6 @@ end_per_testcase(_Name, _C) ->
|
|||||||
|
|
||||||
%% invalid_recurrent_paytool_params group
|
%% invalid_recurrent_paytool_params group
|
||||||
|
|
||||||
-spec invalid_user(config()) -> test_case_result().
|
|
||||||
-spec invalid_user_new(config()) -> test_case_result().
|
|
||||||
-spec invalid_party(config()) -> test_case_result().
|
-spec invalid_party(config()) -> test_case_result().
|
||||||
-spec invalid_party_new(config()) -> test_case_result().
|
-spec invalid_party_new(config()) -> test_case_result().
|
||||||
-spec invalid_shop(config()) -> test_case_result().
|
-spec invalid_shop(config()) -> test_case_result().
|
||||||
@ -192,20 +182,6 @@ end_per_testcase(_Name, _C) ->
|
|||||||
-spec invalid_payment_method(config()) -> test_case_result().
|
-spec invalid_payment_method(config()) -> test_case_result().
|
||||||
-spec invalid_payment_method_new(config()) -> test_case_result().
|
-spec invalid_payment_method_new(config()) -> test_case_result().
|
||||||
|
|
||||||
invalid_user(C) ->
|
|
||||||
invalid_user(C, visa).
|
|
||||||
|
|
||||||
invalid_user_new(C) ->
|
|
||||||
invalid_user(C, ?pmt_sys(<<"visa-ref">>)).
|
|
||||||
|
|
||||||
invalid_user(C, PmtSys) ->
|
|
||||||
PaytoolID = hg_utils:unique_id(),
|
|
||||||
Client = cfg(client, C),
|
|
||||||
PartyID = hg_utils:unique_id(),
|
|
||||||
ShopID = hg_utils:unique_id(),
|
|
||||||
Params = make_recurrent_paytool_params(PaytoolID, PartyID, ShopID, PmtSys),
|
|
||||||
{exception, #payproc_InvalidUser{}} = hg_client_recurrent_paytool:create(Params, Client).
|
|
||||||
|
|
||||||
invalid_party(C) ->
|
invalid_party(C) ->
|
||||||
invalid_party(C, visa).
|
invalid_party(C, visa).
|
||||||
|
|
||||||
@ -217,7 +193,7 @@ invalid_party(C, PmtSys) ->
|
|||||||
PaytoolID = hg_utils:unique_id(),
|
PaytoolID = hg_utils:unique_id(),
|
||||||
PartyID = hg_utils:unique_id(),
|
PartyID = hg_utils:unique_id(),
|
||||||
ShopID = hg_utils:unique_id(),
|
ShopID = hg_utils:unique_id(),
|
||||||
Client = hg_client_recurrent_paytool:start(hg_ct_helper:create_client(RootUrl, PartyID, cfg(trace_id, C))),
|
Client = hg_client_recurrent_paytool:start(hg_ct_helper:create_client(RootUrl, cfg(trace_id, C))),
|
||||||
Params = make_recurrent_paytool_params(PaytoolID, PartyID, ShopID, PmtSys),
|
Params = make_recurrent_paytool_params(PaytoolID, PartyID, ShopID, PmtSys),
|
||||||
{exception, #payproc_PartyNotFound{}} = hg_client_recurrent_paytool:create(Params, Client).
|
{exception, #payproc_PartyNotFound{}} = hg_client_recurrent_paytool:create(Params, Client).
|
||||||
|
|
||||||
|
@ -152,15 +152,8 @@ end_per_group(_GroupName, C) ->
|
|||||||
-spec init_per_testcase(test_case_name(), config()) -> config().
|
-spec init_per_testcase(test_case_name(), config()) -> config().
|
||||||
init_per_testcase(_, C) ->
|
init_per_testcase(_, C) ->
|
||||||
Ctx0 = hg_context:set_party_client(cfg(party_client, C), hg_context:create()),
|
Ctx0 = hg_context:set_party_client(cfg(party_client, C), hg_context:create()),
|
||||||
Ctx1 = hg_context:set_user_identity(
|
|
||||||
#{
|
|
||||||
id => cfg(party_id, C),
|
|
||||||
realm => <<"internal">>
|
|
||||||
},
|
|
||||||
Ctx0
|
|
||||||
),
|
|
||||||
PartyClientContext = party_client_context:create(#{}),
|
PartyClientContext = party_client_context:create(#{}),
|
||||||
Ctx2 = hg_context:set_party_client_context(PartyClientContext, Ctx1),
|
Ctx2 = hg_context:set_party_client_context(PartyClientContext, Ctx0),
|
||||||
ok = hg_context:save(Ctx2),
|
ok = hg_context:save(Ctx2),
|
||||||
C.
|
C.
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([start/1]).
|
-export([start/1]).
|
||||||
-export([start/2]).
|
|
||||||
-export([start_link/1]).
|
-export([start_link/1]).
|
||||||
-export([stop/1]).
|
-export([stop/1]).
|
||||||
|
|
||||||
@ -27,7 +26,6 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
|
|
||||||
-type id() :: dmsl_domain_thrift:'InvoiceTemplateID'().
|
-type id() :: dmsl_domain_thrift:'InvoiceTemplateID'().
|
||||||
-type create_params() :: dmsl_payment_processing_thrift:'InvoiceTemplateCreateParams'().
|
-type create_params() :: dmsl_payment_processing_thrift:'InvoiceTemplateCreateParams'().
|
||||||
-type update_params() :: dmsl_payment_processing_thrift:'InvoiceTemplateUpdateParams'().
|
-type update_params() :: dmsl_payment_processing_thrift:'InvoiceTemplateUpdateParams'().
|
||||||
@ -38,18 +36,14 @@
|
|||||||
|
|
||||||
-spec start(hg_client_api:t()) -> pid().
|
-spec start(hg_client_api:t()) -> pid().
|
||||||
start(ApiClient) ->
|
start(ApiClient) ->
|
||||||
start(start, undefined, ApiClient).
|
start(start, ApiClient).
|
||||||
|
|
||||||
-spec start(user_info(), hg_client_api:t()) -> pid().
|
|
||||||
start(UserInfo, ApiClient) ->
|
|
||||||
start(start, UserInfo, ApiClient).
|
|
||||||
|
|
||||||
-spec start_link(hg_client_api:t()) -> pid().
|
-spec start_link(hg_client_api:t()) -> pid().
|
||||||
start_link(ApiClient) ->
|
start_link(ApiClient) ->
|
||||||
start(start_link, undefined, ApiClient).
|
start(start_link, ApiClient).
|
||||||
|
|
||||||
start(Mode, UserInfo, ApiClient) ->
|
start(Mode, ApiClient) ->
|
||||||
{ok, Pid} = gen_server:Mode(?MODULE, {UserInfo, ApiClient}, []),
|
{ok, Pid} = gen_server:Mode(?MODULE, ApiClient, []),
|
||||||
Pid.
|
Pid.
|
||||||
|
|
||||||
-spec stop(pid()) -> ok.
|
-spec stop(pid()) -> ok.
|
||||||
@ -91,7 +85,6 @@ map_result_error({error, Error}) ->
|
|||||||
-type event() :: dmsl_payment_processing_thrift:'Event'().
|
-type event() :: dmsl_payment_processing_thrift:'Event'().
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
user_info :: user_info(),
|
|
||||||
pollers :: #{id() => hg_client_event_poller:st(event())},
|
pollers :: #{id() => hg_client_event_poller:st(event())},
|
||||||
client :: hg_client_api:t()
|
client :: hg_client_api:t()
|
||||||
}).
|
}).
|
||||||
@ -99,13 +92,13 @@ map_result_error({error, Error}) ->
|
|||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
-type callref() :: {pid(), Tag :: reference()}.
|
-type callref() :: {pid(), Tag :: reference()}.
|
||||||
|
|
||||||
-spec init({user_info(), hg_client_api:t()}) -> {ok, state()}.
|
-spec init(hg_client_api:t()) -> {ok, state()}.
|
||||||
init({UserInfo, ApiClient}) ->
|
init(ApiClient) ->
|
||||||
{ok, #state{user_info = UserInfo, pollers = #{}, client = ApiClient}}.
|
{ok, #state{pollers = #{}, client = ApiClient}}.
|
||||||
|
|
||||||
-spec handle_call(term(), callref(), state()) -> {reply, term(), state()} | {noreply, state()}.
|
-spec handle_call(term(), callref(), state()) -> {reply, term(), state()} | {noreply, state()}.
|
||||||
handle_call({call, Function, Args}, _From, St = #state{user_info = UserInfo, client = Client}) ->
|
handle_call({call, Function, Args}, _From, St = #state{client = Client}) ->
|
||||||
{Result, ClientNext} = hg_client_api:call(invoice_templating, Function, [UserInfo | Args], Client),
|
{Result, ClientNext} = hg_client_api:call(invoice_templating, Function, with_user_info(Args), Client),
|
||||||
{reply, Result, St#state{client = ClientNext}};
|
{reply, Result, St#state{client = ClientNext}};
|
||||||
handle_call({pull_event, InvoiceID, Timeout}, _From, St = #state{client = Client}) ->
|
handle_call({pull_event, InvoiceID, Timeout}, _From, St = #state{client = Client}) ->
|
||||||
Poller = get_poller(InvoiceID, St),
|
Poller = get_poller(InvoiceID, St),
|
||||||
@ -143,14 +136,17 @@ code_change(_OldVsn, _State, _Extra) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
get_poller(ID, #state{user_info = UserInfo, pollers = Pollers}) ->
|
get_poller(ID, #state{pollers = Pollers}) ->
|
||||||
maps:get(ID, Pollers, construct_poller(UserInfo, ID)).
|
maps:get(ID, Pollers, construct_poller(ID)).
|
||||||
|
|
||||||
set_poller(ID, Poller, St = #state{pollers = Pollers}) ->
|
set_poller(ID, Poller, St = #state{pollers = Pollers}) ->
|
||||||
St#state{pollers = maps:put(ID, Poller, Pollers)}.
|
St#state{pollers = maps:put(ID, Poller, Pollers)}.
|
||||||
|
|
||||||
construct_poller(UserInfo, ID) ->
|
construct_poller(ID) ->
|
||||||
hg_client_event_poller:new(
|
hg_client_event_poller:new(
|
||||||
{invoice_templating, 'GetEvents', [UserInfo, ID]},
|
{invoice_templating, 'GetEvents', with_user_info([ID])},
|
||||||
fun(Event) -> Event#payproc_Event.id end
|
fun(Event) -> Event#payproc_Event.id end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
with_user_info(Args) ->
|
||||||
|
[undefined | Args].
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
|
||||||
|
|
||||||
-export([start/1]).
|
-export([start/1]).
|
||||||
-export([start/2]).
|
|
||||||
-export([start_link/1]).
|
-export([start_link/1]).
|
||||||
-export([stop/1]).
|
-export([stop/1]).
|
||||||
|
|
||||||
@ -63,7 +62,6 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
-type user_info() :: dmsl_payment_processing_thrift:'UserInfo'().
|
|
||||||
-type invoice_id() :: dmsl_domain_thrift:'InvoiceID'().
|
-type invoice_id() :: dmsl_domain_thrift:'InvoiceID'().
|
||||||
-type invoice_state() :: dmsl_payment_processing_thrift:'Invoice'().
|
-type invoice_state() :: dmsl_payment_processing_thrift:'Invoice'().
|
||||||
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
|
-type payment() :: dmsl_domain_thrift:'InvoicePayment'().
|
||||||
@ -102,18 +100,14 @@
|
|||||||
|
|
||||||
-spec start(hg_client_api:t()) -> pid().
|
-spec start(hg_client_api:t()) -> pid().
|
||||||
start(ApiClient) ->
|
start(ApiClient) ->
|
||||||
start(start, undefined, ApiClient).
|
start(start, ApiClient).
|
||||||
|
|
||||||
-spec start(user_info(), hg_client_api:t()) -> pid().
|
|
||||||
start(UserInfo, ApiClient) ->
|
|
||||||
start(start, UserInfo, ApiClient).
|
|
||||||
|
|
||||||
-spec start_link(hg_client_api:t()) -> pid().
|
-spec start_link(hg_client_api:t()) -> pid().
|
||||||
start_link(ApiClient) ->
|
start_link(ApiClient) ->
|
||||||
start(start_link, undefined, ApiClient).
|
start(start_link, ApiClient).
|
||||||
|
|
||||||
start(Mode, UserInfo, ApiClient) ->
|
start(Mode, ApiClient) ->
|
||||||
{ok, Pid} = gen_server:Mode(?MODULE, {UserInfo, ApiClient}, []),
|
{ok, Pid} = gen_server:Mode(?MODULE, ApiClient, []),
|
||||||
Pid.
|
Pid.
|
||||||
|
|
||||||
-spec stop(pid()) -> ok.
|
-spec stop(pid()) -> ok.
|
||||||
@ -317,7 +311,6 @@ map_result_error({error, Error}) ->
|
|||||||
-type event() :: dmsl_payment_processing_thrift:'Event'().
|
-type event() :: dmsl_payment_processing_thrift:'Event'().
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
user_info :: user_info(),
|
|
||||||
pollers :: #{invoice_id() => hg_client_event_poller:st(event())},
|
pollers :: #{invoice_id() => hg_client_event_poller:st(event())},
|
||||||
client :: hg_client_api:t()
|
client :: hg_client_api:t()
|
||||||
}).
|
}).
|
||||||
@ -325,13 +318,13 @@ map_result_error({error, Error}) ->
|
|||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
-type callref() :: {pid(), Tag :: reference()}.
|
-type callref() :: {pid(), Tag :: reference()}.
|
||||||
|
|
||||||
-spec init({user_info(), hg_client_api:t()}) -> {ok, state()}.
|
-spec init(hg_client_api:t()) -> {ok, state()}.
|
||||||
init({UserInfo, ApiClient}) ->
|
init(ApiClient) ->
|
||||||
{ok, #state{user_info = UserInfo, pollers = #{}, client = ApiClient}}.
|
{ok, #state{pollers = #{}, client = ApiClient}}.
|
||||||
|
|
||||||
-spec handle_call(term(), callref(), state()) -> {reply, term(), state()} | {noreply, state()}.
|
-spec handle_call(term(), callref(), state()) -> {reply, term(), state()} | {noreply, state()}.
|
||||||
handle_call({call, Function, Args}, _From, St = #state{user_info = UserInfo, client = Client}) ->
|
handle_call({call, Function, Args}, _From, St = #state{client = Client}) ->
|
||||||
{Result, ClientNext} = hg_client_api:call(invoicing, Function, [UserInfo | Args], Client),
|
{Result, ClientNext} = hg_client_api:call(invoicing, Function, with_user_info(Args), Client),
|
||||||
{reply, Result, St#state{client = ClientNext}};
|
{reply, Result, St#state{client = ClientNext}};
|
||||||
handle_call({pull_event, InvoiceID, Timeout}, _From, St = #state{client = Client}) ->
|
handle_call({pull_event, InvoiceID, Timeout}, _From, St = #state{client = Client}) ->
|
||||||
Poller = get_poller(InvoiceID, St),
|
Poller = get_poller(InvoiceID, St),
|
||||||
@ -369,14 +362,17 @@ code_change(_OldVsn, _State, _Extra) ->
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
get_poller(InvoiceID, #state{user_info = UserInfo, pollers = Pollers}) ->
|
get_poller(InvoiceID, #state{pollers = Pollers}) ->
|
||||||
maps:get(InvoiceID, Pollers, construct_poller(UserInfo, InvoiceID)).
|
maps:get(InvoiceID, Pollers, construct_poller(InvoiceID)).
|
||||||
|
|
||||||
set_poller(InvoiceID, Poller, St = #state{pollers = Pollers}) ->
|
set_poller(InvoiceID, Poller, St = #state{pollers = Pollers}) ->
|
||||||
St#state{pollers = maps:put(InvoiceID, Poller, Pollers)}.
|
St#state{pollers = maps:put(InvoiceID, Poller, Pollers)}.
|
||||||
|
|
||||||
construct_poller(UserInfo, InvoiceID) ->
|
construct_poller(InvoiceID) ->
|
||||||
hg_client_event_poller:new(
|
hg_client_event_poller:new(
|
||||||
{invoicing, 'GetEvents', [UserInfo, InvoiceID]},
|
{invoicing, 'GetEvents', with_user_info([InvoiceID])},
|
||||||
fun(Event) -> Event#payproc_Event.id end
|
fun(Event) -> Event#payproc_Event.id end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
with_user_info(Args) ->
|
||||||
|
[undefined | Args].
|
||||||
|
@ -12,8 +12,7 @@
|
|||||||
-type handler_opts() :: #{
|
-type handler_opts() :: #{
|
||||||
handler := module(),
|
handler := module(),
|
||||||
party_client => party_client:client(),
|
party_client => party_client:client(),
|
||||||
default_handling_timeout => timeout(),
|
default_handling_timeout => timeout()
|
||||||
user_identity => undefined | woody_user_identity:user_identity()
|
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type client_opts() :: #{
|
-type client_opts() :: #{
|
||||||
@ -115,23 +114,10 @@ create_context(WoodyContext, Opts) ->
|
|||||||
configure_party_client(Context, Opts).
|
configure_party_client(Context, Opts).
|
||||||
|
|
||||||
configure_party_client(Context0, #{party_client := PartyClient}) ->
|
configure_party_client(Context0, #{party_client := PartyClient}) ->
|
||||||
DefaultUserInfo = #{id => <<"hellgate">>, realm => <<"service">>},
|
hg_context:set_party_client(PartyClient, Context0);
|
||||||
Context1 = set_default_party_user_identity(DefaultUserInfo, Context0),
|
|
||||||
hg_context:set_party_client(PartyClient, Context1);
|
|
||||||
configure_party_client(Context, _Opts) ->
|
configure_party_client(Context, _Opts) ->
|
||||||
Context.
|
Context.
|
||||||
|
|
||||||
set_default_party_user_identity(UserInfo, Context) ->
|
|
||||||
PartyClientContext0 = hg_context:get_party_client_context(Context),
|
|
||||||
PartyClientContext1 =
|
|
||||||
case party_client_context:get_user_info(PartyClientContext0) of
|
|
||||||
undefined ->
|
|
||||||
party_client_context:set_user_info(UserInfo, PartyClientContext0);
|
|
||||||
_UserInfo ->
|
|
||||||
PartyClientContext0
|
|
||||||
end,
|
|
||||||
hg_context:set_party_client_context(PartyClientContext1, Context).
|
|
||||||
|
|
||||||
-spec ensure_woody_deadline_set(woody_context:ctx(), handler_opts()) -> woody_context:ctx().
|
-spec ensure_woody_deadline_set(woody_context:ctx(), handler_opts()) -> woody_context:ctx().
|
||||||
ensure_woody_deadline_set(WoodyContext, Opts) ->
|
ensure_woody_deadline_set(WoodyContext, Opts) ->
|
||||||
case woody_context:get_deadline(WoodyContext) of
|
case woody_context:get_deadline(WoodyContext) of
|
||||||
|
@ -38,13 +38,13 @@ services:
|
|||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
machinegun:
|
machinegun:
|
||||||
image: docker.io/rbkmoney/machinegun:c05a8c18cd4f7966d70b6ad84cac9429cdfe37ae
|
image: ghcr.io/valitydev/machinegun:sha-7f0a21a
|
||||||
command: /opt/machinegun/bin/machinegun foreground
|
command: /opt/machinegun/bin/machinegun foreground
|
||||||
volumes:
|
volumes:
|
||||||
- ./test/machinegun/config.yaml:/opt/machinegun/etc/config.yaml
|
- ./test/machinegun/config.yaml:/opt/machinegun/etc/config.yaml
|
||||||
- ./test/machinegun/cookie:/opt/machinegun/etc/cookie
|
- ./test/machinegun/cookie:/opt/machinegun/etc/cookie
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: "curl http://localhost:8022/"
|
test: "/opt/machinegun/bin/machinegun ping"
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 1s
|
timeout: 1s
|
||||||
retries: 20
|
retries: 20
|
||||||
@ -82,10 +82,10 @@ services:
|
|||||||
test: "curl http://localhost:8023/actuator/health"
|
test: "curl http://localhost:8023/actuator/health"
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 1s
|
timeout: 1s
|
||||||
retries: 20
|
retries: 40
|
||||||
|
|
||||||
party-management:
|
party-management:
|
||||||
image: ghcr.io/valitydev/party-management:sha-f757b79
|
image: ghcr.io/valitydev/party-management:sha-76058e0
|
||||||
command: /opt/party-management/bin/party-management foreground
|
command: /opt/party-management/bin/party-management foreground
|
||||||
depends_on:
|
depends_on:
|
||||||
machinegun:
|
machinegun:
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
{gproc, "0.9.0"},
|
{gproc, "0.9.0"},
|
||||||
{genlib, {git, "https://github.com/valitydev/genlib.git", {branch, "master"}}},
|
{genlib, {git, "https://github.com/valitydev/genlib.git", {branch, "master"}}},
|
||||||
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
|
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
|
||||||
{woody_user_identity, {git, "https://github.com/valitydev/woody_erlang_user_identity.git", {branch, "master"}}},
|
|
||||||
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
|
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
|
||||||
{payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}},
|
{payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}},
|
||||||
{mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}},
|
{mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}},
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
|
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
|
||||||
{<<"party_client">>,
|
{<<"party_client">>,
|
||||||
{git,"https://github.com/valitydev/party-client-erlang.git",
|
{git,"https://github.com/valitydev/party-client-erlang.git",
|
||||||
{ref,"602d4dc87b54d2bf899ae36462853f7d7eb014ae"}},
|
{ref,"31850a63f6c00da7e10897b23298ad38f9bf448d"}},
|
||||||
0},
|
0},
|
||||||
{<<"payproc_errors">>,
|
{<<"payproc_errors">>,
|
||||||
{git,"https://github.com/valitydev/payproc-errors-erlang.git",
|
{git,"https://github.com/valitydev/payproc-errors-erlang.git",
|
||||||
@ -72,10 +72,6 @@
|
|||||||
{<<"woody">>,
|
{<<"woody">>,
|
||||||
{git,"https://github.com/valitydev/woody_erlang.git",
|
{git,"https://github.com/valitydev/woody_erlang.git",
|
||||||
{ref,"6f818c57e3b19f96260b1f968115c9bc5bcad4d2"}},
|
{ref,"6f818c57e3b19f96260b1f968115c9bc5bcad4d2"}},
|
||||||
0},
|
|
||||||
{<<"woody_user_identity">>,
|
|
||||||
{git,"https://github.com/valitydev/woody_erlang_user_identity.git",
|
|
||||||
{ref,"a480762fea8d7c08f105fb39ca809482b6cb042e"}},
|
|
||||||
0}]}.
|
0}]}.
|
||||||
[
|
[
|
||||||
{pkg_hash,[
|
{pkg_hash,[
|
||||||
|
Loading…
Reference in New Issue
Block a user