OPS-272: Adds 'ForParty' operations implementation (#29)

* Adds `getInvoiceByExternalIDForParty` implementations with tests
* Adds `getPaymentInstitutionPayoutMethodsForParty` and `getPaymentInstitutionPayoutSchedulesForParty`
* Adds `getPaymentByExternalIDForParty` and `getRefundByExternalIDForParty`
* Bumps `swag_client` and `swag_server`
This commit is contained in:
Aleksey Kashapov 2023-03-07 13:20:32 +03:00 committed by GitHub
parent 031d6effbb
commit dbb2039c30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 300 additions and 35 deletions

View File

@ -106,10 +106,12 @@ prepare('GetInvoiceByID' = OperationID, Req, Context) ->
{ok, {200, #{}, capi_handler_decoder_invoicing:decode_invoice(Invoice)}} {ok, {200, #{}, capi_handler_decoder_invoicing:decode_invoice(Invoice)}}
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare('GetInvoiceByExternalID' = OperationID, Req, Context) -> prepare(OperationID, #{'partyID' := PartyID, 'externalID' := ExternalID}, Context) when
ExternalID = maps:get('externalID', Req), OperationID =:= 'GetInvoiceByExternalIDForParty';
OperationID =:= 'GetInvoiceByExternalID'
->
{InvoiceID, ResultInvoice} = {InvoiceID, ResultInvoice} =
case get_invoice_by_external_id(ExternalID, Context) of case get_invoice_by_external_id(PartyID, ExternalID, Context) of
{ok, Result} -> {ok, Result} ->
Result; Result;
{error, internal_id_not_found} -> {error, internal_id_not_found} ->
@ -131,6 +133,10 @@ prepare('GetInvoiceByExternalID' = OperationID, Req, Context) ->
{ok, {200, #{}, capi_handler_decoder_invoicing:decode_invoice(Invoice)}} {ok, {200, #{}, capi_handler_decoder_invoicing:decode_invoice(Invoice)}}
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare('GetInvoiceByExternalID' = OperationID, Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
Req1 = maps:put('partyID', PartyID, Req),
prepare(OperationID, Req1, Context);
prepare('FulfillInvoice' = OperationID, Req, Context) -> prepare('FulfillInvoice' = OperationID, Req, Context) ->
InvoiceID = maps:get('invoiceID', Req), InvoiceID = maps:get('invoiceID', Req),
Authorize = fun() -> Authorize = fun() ->
@ -454,8 +460,7 @@ decode_refund_for_event(#domain_InvoicePaymentRefund{cash = undefined} = Refund,
capi_handler_utils:get_payment_by_id(InvoiceID, PaymentID, Context), capi_handler_utils:get_payment_by_id(InvoiceID, PaymentID, Context),
capi_handler_decoder_invoicing:decode_refund(Refund#domain_InvoicePaymentRefund{cash = Cash}). capi_handler_decoder_invoicing:decode_refund(Refund#domain_InvoicePaymentRefund{cash = Cash}).
get_invoice_by_external_id(ExternalID, #{woody_context := WoodyContext} = Context) -> get_invoice_by_external_id(PartyID, ExternalID, #{woody_context := WoodyContext} = Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
InvoiceKey = {'CreateInvoice', PartyID, ExternalID}, InvoiceKey = {'CreateInvoice', PartyID, ExternalID},
case capi_bender:get_internal_id(InvoiceKey, WoodyContext) of case capi_bender:get_internal_id(InvoiceKey, WoodyContext) of
{ok, InvoiceID, _CtxData} -> {ok, InvoiceID, _CtxData} ->

View File

@ -56,7 +56,10 @@ prepare(OperationID = 'GetPaymentInstitutionPaymentTerms', Req, Context) ->
end end
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPaymentInstitutionPayoutMethods', Req, Context) -> prepare(OperationID, Req, Context) when
OperationID =:= 'GetPaymentInstitutionPayoutMethods';
OperationID =:= 'GetPaymentInstitutionPayoutMethodsForParty'
->
Authorize = mk_authorize_operation(OperationID, Context), Authorize = mk_authorize_operation(OperationID, Context),
Process = fun() -> Process = fun() ->
PaymentInstitutionID = genlib:to_int(maps:get('paymentInstitutionID', Req)), PaymentInstitutionID = genlib:to_int(maps:get('paymentInstitutionID', Req)),
@ -70,7 +73,10 @@ prepare(OperationID = 'GetPaymentInstitutionPayoutMethods', Req, Context) ->
end end
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPaymentInstitutionPayoutSchedules', Req, Context) -> prepare(OperationID, Req, Context) when
OperationID =:= 'GetPaymentInstitutionPayoutSchedules';
OperationID =:= 'GetPaymentInstitutionPayoutSchedulesForParty'
->
Authorize = mk_authorize_operation(OperationID, Context), Authorize = mk_authorize_operation(OperationID, Context),
Process = fun() -> Process = fun() ->
PaymentInstitutionID = genlib:to_int(maps:get('paymentInstitutionID', Req)), PaymentInstitutionID = genlib:to_int(maps:get('paymentInstitutionID', Req)),
@ -145,12 +151,16 @@ compute_payment_institution_terms(PaymentInstitutionID, VS, Context) ->
Ref = ?PAYMENT_INSTITUTION_REF(PaymentInstitutionID), Ref = ?PAYMENT_INSTITUTION_REF(PaymentInstitutionID),
capi_party:compute_payment_institution_terms(Ref, VS, Context). capi_party:compute_payment_institution_terms(Ref, VS, Context).
prepare_request_varset(Req, Context) -> prepare_request_varset(#{'partyID' := PartyID} = Req, _Context) ->
#payproc_Varset{ #payproc_Varset{
currency = encode_optional_currency(genlib_map:get('currency', Req)), currency = encode_optional_currency(genlib_map:get('currency', Req)),
payout_method = encode_optional_payout_method(genlib_map:get('payoutMethod', Req)), payout_method = encode_optional_payout_method(genlib_map:get('payoutMethod', Req)),
party_id = capi_handler_utils:get_party_id(Context) party_id = PartyID
}. };
prepare_request_varset(Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
Req1 = maps:put('partyID', PartyID, Req),
prepare_request_varset(Req1, Context).
% %

View File

@ -101,9 +101,11 @@ prepare(OperationID = 'GetPaymentByID', Req, Context) ->
end end
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPaymentByExternalID', Req, Context) -> prepare(OperationID, #{'partyID' := PartyID, 'externalID' := ExternalID}, Context) when
ExternalID = maps:get('externalID', Req), OperationID =:= 'GetPaymentByExternalID';
InternalID = get_payment_by_external_id(ExternalID, Context), OperationID =:= 'GetPaymentByExternalIDForParty'
->
InternalID = get_payment_by_external_id(PartyID, ExternalID, Context),
Invoice = maybe( Invoice = maybe(
InternalID, InternalID,
fun({InvoiceID, _}) -> get_invoice_by_id(InvoiceID, Context) end fun({InvoiceID, _}) -> get_invoice_by_id(InvoiceID, Context) end
@ -135,6 +137,10 @@ prepare(OperationID = 'GetPaymentByExternalID', Req, Context) ->
end end
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetPaymentByExternalID', Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
Req1 = maps:put('partyID', PartyID, Req),
prepare(OperationID, Req1, Context);
prepare(OperationID = 'CapturePayment', Req, Context) -> prepare(OperationID = 'CapturePayment', Req, Context) ->
InvoiceID = maps:get('invoiceID', Req), InvoiceID = maps:get('invoiceID', Req),
PaymentID = maps:get('paymentID', Req), PaymentID = maps:get('paymentID', Req),
@ -361,9 +367,11 @@ prepare(OperationID = 'GetRefundByID', Req, Context) ->
end end
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetRefundByExternalID', Req, Context) -> prepare(OperationID, #{'partyID' := PartyID, 'externalID' := ExternalID}, Context) when
ExternalID = maps:get('externalID', Req), OperationID =:= 'GetRefundByExternalID';
InternalID = get_refund_by_external_id(ExternalID, Context), OperationID =:= 'GetRefundByExternalIDForParty'
->
InternalID = get_refund_by_external_id(PartyID, ExternalID, Context),
Invoice = maybe( Invoice = maybe(
InternalID, InternalID,
fun({InvoiceID, _PaymentID, _RefundID}) -> get_invoice_by_id(InvoiceID, Context) end fun({InvoiceID, _PaymentID, _RefundID}) -> get_invoice_by_id(InvoiceID, Context) end
@ -397,6 +405,10 @@ prepare(OperationID = 'GetRefundByExternalID', Req, Context) ->
end end
end, end,
{ok, #{authorize => Authorize, process => Process}}; {ok, #{authorize => Authorize, process => Process}};
prepare(OperationID = 'GetRefundByExternalID', Req, Context) ->
PartyID = capi_handler_utils:get_party_id(Context),
Req1 = maps:put('partyID', PartyID, Req),
prepare(OperationID, Req1, Context);
prepare(OperationID = 'GetChargebacks', Req, Context) -> prepare(OperationID = 'GetChargebacks', Req, Context) ->
InvoiceID = maps:get('invoiceID', Req), InvoiceID = maps:get('invoiceID', Req),
PaymentID = maps:get('paymentID', Req), PaymentID = maps:get('paymentID', Req),
@ -496,7 +508,7 @@ create_payment_id(Invoice, PaymentParams0, Context, OperationID, PaymentToolThri
Identity = capi_bender:make_identity(capi_feature_schemas:payment(), PaymentParams), Identity = capi_bender:make_identity(capi_feature_schemas:payment(), PaymentParams),
SequenceParams = #{}, SequenceParams = #{},
#{woody_context := WoodyCtx} = Context, #{woody_context := WoodyCtx} = Context,
%% We put `invoice_id` in a context here because `get_payment_by_external_id()` needs it to work %% We put `invoice_id` in a context here because `get_payment_by_external_id/3` needs it to work
CtxData = #{<<"invoice_id">> => InvoiceID}, CtxData = #{<<"invoice_id">> => InvoiceID},
capi_bender:gen_sequence(IdempotentKey, Identity, SequenceID, SequenceParams, WoodyCtx, CtxData). capi_bender:gen_sequence(IdempotentKey, Identity, SequenceID, SequenceParams, WoodyCtx, CtxData).
@ -654,8 +666,7 @@ decode_payment_token(_Other) ->
decode_invoice_payment(InvoiceID, InvoicePayment, Context) -> decode_invoice_payment(InvoiceID, InvoicePayment, Context) ->
capi_handler_decoder_invoicing:decode_invoice_payment(InvoiceID, InvoicePayment, Context). capi_handler_decoder_invoicing:decode_invoice_payment(InvoiceID, InvoicePayment, Context).
get_refund_by_external_id(ExternalID, #{woody_context := WoodyContext} = Context) -> get_refund_by_external_id(PartyID, ExternalID, #{woody_context := WoodyContext}) ->
PartyID = capi_handler_utils:get_party_id(Context),
IdempotentKey = {'CreateRefund', PartyID, ExternalID}, IdempotentKey = {'CreateRefund', PartyID, ExternalID},
case capi_bender:get_internal_id(IdempotentKey, WoodyContext) of case capi_bender:get_internal_id(IdempotentKey, WoodyContext) of
{ok, RefundID, CtxData} -> {ok, RefundID, CtxData} ->
@ -666,9 +677,9 @@ get_refund_by_external_id(ExternalID, #{woody_context := WoodyContext} = Context
undefined undefined
end. end.
-spec get_payment_by_external_id(binary(), capi_handler:processing_context()) -> {binary(), binary()} | undefined. -spec get_payment_by_external_id(binary(), binary(), capi_handler:processing_context()) ->
get_payment_by_external_id(ExternalID, #{woody_context := WoodyContext} = Context) -> {binary(), binary()} | undefined.
PartyID = capi_handler_utils:get_party_id(Context), get_payment_by_external_id(PartyID, ExternalID, #{woody_context := WoodyContext}) ->
IdempotentKey = {'CreatePayment', PartyID, ExternalID}, IdempotentKey = {'CreatePayment', PartyID, ExternalID},
case capi_bender:get_internal_id(IdempotentKey, WoodyContext) of case capi_bender:get_internal_id(IdempotentKey, WoodyContext) of
{ok, PaymentID, CtxData} -> {ok, PaymentID, CtxData} ->
@ -701,7 +712,7 @@ create_refund(InvoiceID, PaymentID, RefundParams0, Context, BenderPrefix) ->
SequenceID = create_sequence_id([InvoiceID, PaymentID], BenderPrefix), SequenceID = create_sequence_id([InvoiceID, PaymentID], BenderPrefix),
SequenceParams = #{minimum => 100}, SequenceParams = #{minimum => 100},
#{woody_context := WoodyCtx} = Context, #{woody_context := WoodyCtx} = Context,
%% We put `invoice_id` and `payment_id` in a context here because `get_refund_by_external_id/2` needs it to work %% We put `invoice_id` and `payment_id` in a context here because `get_refund_by_external_id/3` needs it to work
CtxData = #{<<"invoice_id">> => InvoiceID, <<"payment_id">> => PaymentID}, CtxData = #{<<"invoice_id">> => InvoiceID, <<"payment_id">> => PaymentID},
RefundID = capi_bender:gen_sequence(IdempotentKey, Identity, SequenceID, SequenceParams, WoodyCtx, CtxData), RefundID = capi_bender:gen_sequence(IdempotentKey, Identity, SequenceID, SequenceParams, WoodyCtx, CtxData),
refund_payment(RefundID, InvoiceID, PaymentID, RefundParams, Context). refund_payment(RefundID, InvoiceID, PaymentID, RefundParams, Context).

View File

@ -27,6 +27,7 @@
create_invoice_ok_test/1, create_invoice_ok_test/1,
create_invoice_autorization_error_test/1, create_invoice_autorization_error_test/1,
get_invoice_by_external_id/1, get_invoice_by_external_id/1,
get_invoice_by_external_id_for_party/1,
get_invoice_by_external_id_not_impl_error/1, get_invoice_by_external_id_not_impl_error/1,
create_invoice_access_token_ok_test/1, create_invoice_access_token_ok_test/1,
create_invoice_template_ok_test/1, create_invoice_template_ok_test/1,
@ -109,12 +110,17 @@
get_payment_institution_by_ref/1, get_payment_institution_by_ref/1,
get_payment_institution_payment_terms/1, get_payment_institution_payment_terms/1,
get_payment_institution_payout_terms/1, get_payment_institution_payout_terms/1,
get_payment_institution_payout_terms_for_party/1,
get_payment_institution_payout_schedules/1, get_payment_institution_payout_schedules/1,
get_payment_institution_payout_schedules_for_party/1,
get_service_provider_by_id/1, get_service_provider_by_id/1,
check_no_payment_by_external_id_test/1, check_no_payment_by_external_id_test/1,
check_no_internal_id_for_external_id_test/1, check_no_internal_id_for_external_id_test/1,
retrieve_payment_by_external_id_test/1, retrieve_payment_by_external_id_test/1,
retrieve_payment_by_external_id_for_party_test/1,
check_no_invoice_by_external_id_test/1, check_no_invoice_by_external_id_test/1,
retrieve_refund_by_external_id_test/1,
retrieve_refund_by_external_id_for_party_test/1,
get_country_by_id_test/1, get_country_by_id_test/1,
get_country_by_id_not_found_test/1, get_country_by_id_not_found_test/1,
get_countries_test/1, get_countries_test/1,
@ -160,6 +166,7 @@ groups() ->
create_invoice_ok_test, create_invoice_ok_test,
create_invoice_autorization_error_test, create_invoice_autorization_error_test,
get_invoice_by_external_id, get_invoice_by_external_id,
get_invoice_by_external_id_for_party,
get_invoice_by_external_id_not_impl_error, get_invoice_by_external_id_not_impl_error,
check_no_invoice_by_external_id_test, check_no_invoice_by_external_id_test,
create_invoice_access_token_ok_test, create_invoice_access_token_ok_test,
@ -205,7 +212,10 @@ groups() ->
create_payment_ok_test, create_payment_ok_test,
retrieve_payment_by_external_id_test, retrieve_payment_by_external_id_test,
retrieve_payment_by_external_id_for_party_test,
check_no_payment_by_external_id_test, check_no_payment_by_external_id_test,
retrieve_refund_by_external_id_test,
retrieve_refund_by_external_id_for_party_test,
create_refund, create_refund,
create_refund_blocked_error, create_refund_blocked_error,
create_refund_expired_error, create_refund_expired_error,
@ -229,7 +239,9 @@ groups() ->
get_payment_institution_by_ref, get_payment_institution_by_ref,
get_payment_institution_payment_terms, get_payment_institution_payment_terms,
get_payment_institution_payout_terms, get_payment_institution_payout_terms,
get_payment_institution_payout_terms_for_party,
get_payment_institution_payout_schedules, get_payment_institution_payout_schedules,
get_payment_institution_payout_schedules_for_party,
get_service_provider_by_id, get_service_provider_by_id,
get_category_by_ref_ok_test, get_category_by_ref_ok_test,
@ -360,6 +372,31 @@ get_invoice_by_external_id(Config) ->
{ok, _} = capi_client_invoices:get_invoice_by_external_id(?config(context, Config), ExternalID). {ok, _} = capi_client_invoices:get_invoice_by_external_id(?config(context, Config), ExternalID).
-spec get_invoice_by_external_id_for_party(config()) -> _.
get_invoice_by_external_id_for_party(Config) ->
PartyID = capi_utils:get_unique_id(),
ExternalID = <<"merch_id">>,
BenderContext = capi_msgp_marshalling:marshal(#{<<"context_data">> => #{}}),
InvoiceID = capi_utils:get_unique_id(),
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Get', _) -> {ok, ?PAYPROC_INVOICE_WITH_ID(InvoiceID, ExternalID, PartyID)} end},
{bender, fun('GetInternalID', _) ->
{ok, capi_ct_helper_bender:get_internal_id_result(InvoiceID, BenderContext)}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_invoice_op_ctx(
<<"GetInvoiceByExternalIDForParty">>,
InvoiceID,
PartyID,
?STRING,
Config
),
{ok, _} = capi_client_invoices:get_invoice_by_external_id_for_party(?config(context, Config), PartyID, ExternalID).
-spec get_invoice_by_external_id_not_impl_error(config()) -> _. -spec get_invoice_by_external_id_not_impl_error(config()) -> _.
get_invoice_by_external_id_not_impl_error(Config) -> get_invoice_by_external_id_not_impl_error(Config) ->
ExternalID = <<"merch_id">>, ExternalID = <<"merch_id">>,
@ -1879,6 +1916,100 @@ retrieve_payment_by_external_id_test(Config) ->
}} = }} =
capi_client_payments:get_payment_by_external_id(?config(context, Config), ExternalID). capi_client_payments:get_payment_by_external_id(?config(context, Config), ExternalID).
-spec retrieve_payment_by_external_id_for_party_test(config()) -> _.
retrieve_payment_by_external_id_for_party_test(Config) ->
PartyID = capi_utils:get_unique_id(),
PaymentID = capi_utils:get_unique_id(),
ExternalID = capi_utils:get_unique_id(),
BenderContext = capi_msgp_marshalling:marshal(#{<<"context_data">> => #{<<"invoice_id">> => ?STRING}}),
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Get', _) ->
Payment = ?PAYPROC_PAYMENT(?PAYMENT_W_EXTERNAL_ID(PaymentID, ExternalID)),
{ok, ?PAYPROC_INVOICE(?INVOICE(?STRING, undefined, PartyID), [Payment])}
end},
{bender, fun('GetInternalID', _) ->
{ok, capi_ct_helper_bender:get_internal_id_result(PaymentID, BenderContext)}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_payment_op_ctx(
<<"GetPaymentByExternalIDForParty">>,
?STRING,
PaymentID,
PartyID,
?STRING,
Config
),
{ok, #{<<"externalID">> := ExternalID}} =
capi_client_payments:get_payment_by_external_id_for_party(?config(context, Config), PartyID, ExternalID).
-spec retrieve_refund_by_external_id_test(config()) -> _.
retrieve_refund_by_external_id_test(Config) ->
RefundID = capi_utils:get_unique_id(),
PaymentID = capi_utils:get_unique_id(),
ExternalID = capi_utils:get_unique_id(),
BenderContext = capi_msgp_marshalling:marshal(#{
<<"context_data">> => #{<<"payment_id">> => PaymentID, <<"invoice_id">> => ?STRING}
}),
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Get', _) ->
P = ?PAYPROC_PAYMENT(?PAYMENT_W_EXTERNAL_ID(PaymentID, ?STRING)),
Payment = P#payproc_InvoicePayment{refunds = [?PAYPROC_REFUND(RefundID, ExternalID)]},
{ok, ?PAYPROC_INVOICE([Payment])}
end},
{bender, fun('GetInternalID', _) ->
{ok, capi_ct_helper_bender:get_internal_id_result(RefundID, BenderContext)}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_payment_op_ctx(
<<"GetRefundByExternalID">>,
?STRING,
PaymentID,
?STRING,
?STRING,
Config
),
{ok, #{<<"externalID">> := ExternalID}} =
capi_client_payments:get_refund_by_external_id(?config(context, Config), ExternalID).
-spec retrieve_refund_by_external_id_for_party_test(config()) -> _.
retrieve_refund_by_external_id_for_party_test(Config) ->
PartyID = capi_utils:get_unique_id(),
RefundID = capi_utils:get_unique_id(),
PaymentID = capi_utils:get_unique_id(),
ExternalID = capi_utils:get_unique_id(),
BenderContext = capi_msgp_marshalling:marshal(#{
<<"context_data">> => #{<<"payment_id">> => PaymentID, <<"invoice_id">> => ?STRING}
}),
_ = capi_ct_helper:mock_services(
[
{invoicing, fun('Get', _) ->
P = ?PAYPROC_PAYMENT(?PAYMENT_W_EXTERNAL_ID(PaymentID, ?STRING)),
Payment = P#payproc_InvoicePayment{refunds = [?PAYPROC_REFUND(RefundID, ExternalID)]},
{ok, ?PAYPROC_INVOICE(?INVOICE(?STRING, undefined, PartyID), [Payment])}
end},
{bender, fun('GetInternalID', _) ->
{ok, capi_ct_helper_bender:get_internal_id_result(RefundID, BenderContext)}
end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_payment_op_ctx(
<<"GetRefundByExternalIDForParty">>,
?STRING,
PaymentID,
PartyID,
?STRING,
Config
),
{ok, #{<<"externalID">> := ExternalID}} =
capi_client_payments:get_refund_by_external_id_for_party(?config(context, Config), PartyID, ExternalID).
-spec get_payment_institutions(config()) -> _. -spec get_payment_institutions(config()) -> _.
get_payment_institutions(Config) -> get_payment_institutions(Config) ->
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutions">>, Config), _ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutions">>, Config),
@ -1920,6 +2051,23 @@ get_payment_institution_payout_terms(Config) ->
<<"RUB">> <<"RUB">>
). ).
-spec get_payment_institution_payout_terms_for_party(config()) -> _.
get_payment_institution_payout_terms_for_party(Config) ->
PartyID = capi_utils:get_unique_id(),
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ComputePaymentInstitutionTerms', _) -> {ok, ?TERM_SET} end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutionPayoutMethodsForParty">>, Config),
{ok, _} = capi_client_payment_institutions:get_payment_institution_payout_methods_for_party(
?config(context, Config),
PartyID,
?INTEGER,
<<"RUB">>
).
-spec get_payment_institution_payout_schedules(config()) -> _. -spec get_payment_institution_payout_schedules(config()) -> _.
get_payment_institution_payout_schedules(Config) -> get_payment_institution_payout_schedules(Config) ->
_ = capi_ct_helper:mock_services( _ = capi_ct_helper:mock_services(
@ -1937,6 +2085,25 @@ get_payment_institution_payout_schedules(Config) ->
<<"BankAccount">> <<"BankAccount">>
). ).
-spec get_payment_institution_payout_schedules_for_party(config()) -> _.
get_payment_institution_payout_schedules_for_party(Config) ->
PartyID = capi_utils:get_unique_id(),
_ = capi_ct_helper:mock_services(
[
{party_management, fun('ComputePaymentInstitutionTerms', _) -> {ok, ?TERM_SET} end}
],
Config
),
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetPaymentInstitutionPayoutSchedulesForParty">>, Config),
{ok, _} = capi_client_payment_institutions:get_payment_institution_payout_schedules_for_party(
?config(context, Config),
PartyID,
?INTEGER,
<<"USD">>,
<<"BankAccount">>
).
-spec get_service_provider_by_id(config()) -> _. -spec get_service_provider_by_id(config()) -> _.
get_service_provider_by_id(Config) -> get_service_provider_by_id(Config) ->
_ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetServiceProviderByID">>, Config), _ = capi_ct_helper_bouncer:mock_assert_op_ctx(<<"GetServiceProviderByID">>, Config),

View File

@ -77,7 +77,9 @@
-define(INVOICE, ?INVOICE(?STRING, undefined)). -define(INVOICE, ?INVOICE(?STRING, undefined)).
-define(INVOICE(ID, EID), #domain_Invoice{ -define(INVOICE(ID, EID), ?INVOICE(ID, EID, ?STRING)).
-define(INVOICE(ID, EID, OwnerID), #domain_Invoice{
id = ID, id = ID,
created_at = ?TIMESTAMP, created_at = ?TIMESTAMP,
status = ?INVOICE_STATUS(unpaid), status = ?INVOICE_STATUS(unpaid),
@ -86,7 +88,7 @@
cost = ?CASH, cost = ?CASH,
context = ?CONTENT, context = ?CONTENT,
shop_id = ?STRING, shop_id = ?STRING,
owner_id = ?STRING, owner_id = OwnerID,
template_id = ?STRING, template_id = ?STRING,
external_id = EID external_id = EID
}). }).
@ -110,20 +112,21 @@
}} }}
). ).
-define(PAYPROC_INVOICE(Payments), #payproc_Invoice{ -define(PAYPROC_INVOICE(Payments), ?PAYPROC_INVOICE(?INVOICE, Payments)).
invoice = ?INVOICE,
-define(PAYPROC_INVOICE(Invoice, Payments), #payproc_Invoice{
invoice = Invoice,
payments = Payments payments = Payments
}). }).
-define(PAYPROC_INVOICE, ?PAYPROC_INVOICE([])). -define(PAYPROC_INVOICE, ?PAYPROC_INVOICE([])).
-define(PAYPROC_INVOICE_WITH_ID(ID), #payproc_Invoice{ -define(PAYPROC_INVOICE_WITH_ID(ID), ?PAYPROC_INVOICE_WITH_ID(ID, undefined, ?STRING)).
invoice = ?INVOICE(ID, undefined),
payments = []
}).
-define(PAYPROC_INVOICE_WITH_ID(ID, EID), #payproc_Invoice{ -define(PAYPROC_INVOICE_WITH_ID(ID, EID), ?PAYPROC_INVOICE_WITH_ID(ID, EID, ?STRING)).
invoice = ?INVOICE(ID, EID),
-define(PAYPROC_INVOICE_WITH_ID(ID, EID, OwnerID), #payproc_Invoice{
invoice = ?INVOICE(ID, EID, OwnerID),
payments = [] payments = []
}). }).

View File

@ -6,6 +6,7 @@
-export([get_invoice_events/4]). -export([get_invoice_events/4]).
-export([get_invoice_by_id/2]). -export([get_invoice_by_id/2]).
-export([get_invoice_by_external_id/2]). -export([get_invoice_by_external_id/2]).
-export([get_invoice_by_external_id_for_party/3]).
-export([fulfill_invoice/3]). -export([fulfill_invoice/3]).
-export([rescind_invoice/3]). -export([rescind_invoice/3]).
-export([get_invoice_payment_methods/2]). -export([get_invoice_payment_methods/2]).
@ -64,6 +65,13 @@ get_invoice_by_external_id(Context, ExternalID) ->
Response = swag_client_invoices_api:get_invoice_by_external_id(Url, PreparedParams, Opts), Response = swag_client_invoices_api:get_invoice_by_external_id(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response). capi_client_lib:handle_response(Response).
-spec get_invoice_by_external_id_for_party(context(), binary(), binary()) -> {ok, term()} | {error, term()}.
get_invoice_by_external_id_for_party(Context, PartyID, ExternalID) ->
Params = #{binding => #{<<"partyID">> => PartyID}, qs_val => #{<<"externalID">> => ExternalID}},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_invoices_api:get_invoice_by_external_id_for_party(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec fulfill_invoice(context(), binary(), binary()) -> ok | {error, term()}. -spec fulfill_invoice(context(), binary(), binary()) -> ok | {error, term()}.
fulfill_invoice(Context, InvoiceID, Reason) -> fulfill_invoice(Context, InvoiceID, Reason) ->
Params = #{ Params = #{

View File

@ -6,8 +6,10 @@
-export([get_payment_institution_payment_terms/2]). -export([get_payment_institution_payment_terms/2]).
-export([get_payment_institution_payout_methods/2]). -export([get_payment_institution_payout_methods/2]).
-export([get_payment_institution_payout_methods/3]). -export([get_payment_institution_payout_methods/3]).
-export([get_payment_institution_payout_methods_for_party/4]).
-export([get_payment_institution_payout_schedules/2]). -export([get_payment_institution_payout_schedules/2]).
-export([get_payment_institution_payout_schedules/4]). -export([get_payment_institution_payout_schedules/4]).
-export([get_payment_institution_payout_schedules_for_party/5]).
-export([get_service_provider_by_id/2]). -export([get_service_provider_by_id/2]).
-type context() :: capi_client_lib:context(). -type context() :: capi_client_lib:context().
@ -70,6 +72,24 @@ get_payment_institution_payout_methods(Context, PaymentInstitutionID, Currency)
Response = swag_client_payment_institutions_api:get_payment_institution_payout_methods(Url, PreparedParams, Opts), Response = swag_client_payment_institutions_api:get_payment_institution_payout_methods(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response). capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_methods_for_party(context(), binary(), term(), term()) ->
{ok, term()} | {error, term()}.
get_payment_institution_payout_methods_for_party(Context, PartyID, PaymentInstitutionID, Currency) ->
Params = #{
binding => #{
<<"partyID">> => PartyID,
<<"paymentInstitutionID">> => genlib:to_list(PaymentInstitutionID)
},
qs_val => genlib_map:compact(#{
currency => Currency
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payment_institutions_api:get_payment_institution_payout_methods_for_party(
Url, PreparedParams, Opts
),
capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_schedules(context(), term()) -> {ok, term()} | {error, term()}. -spec get_payment_institution_payout_schedules(context(), term()) -> {ok, term()} | {error, term()}.
get_payment_institution_payout_schedules(Context, PaymentInstitutionID) -> get_payment_institution_payout_schedules(Context, PaymentInstitutionID) ->
get_payment_institution_payout_schedules(Context, PaymentInstitutionID, undefined, undefined). get_payment_institution_payout_schedules(Context, PaymentInstitutionID, undefined, undefined).
@ -89,6 +109,25 @@ get_payment_institution_payout_schedules(Context, PaymentInstitutionID, Currency
Response = swag_client_payment_institutions_api:get_payment_institution_payout_schedules(Url, PreparedParams, Opts), Response = swag_client_payment_institutions_api:get_payment_institution_payout_schedules(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response). capi_client_lib:handle_response(Response).
-spec get_payment_institution_payout_schedules_for_party(context(), binary(), term(), term(), term()) ->
{ok, term()} | {error, term()}.
get_payment_institution_payout_schedules_for_party(Context, PartyID, PaymentInstitutionID, Currency, Method) ->
Params = #{
binding => #{
<<"partyID">> => PartyID,
<<"paymentInstitutionID">> => genlib:to_list(PaymentInstitutionID)
},
qs_val => genlib_map:compact(#{
'currency' => Currency,
'payoutMethod' => Method
})
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payment_institutions_api:get_payment_institution_payout_schedules_for_party(
Url, PreparedParams, Opts
),
capi_client_lib:handle_response(Response).
-spec get_service_provider_by_id(context(), binary()) -> {ok, term()} | {error, term()}. -spec get_service_provider_by_id(context(), binary()) -> {ok, term()} | {error, term()}.
get_service_provider_by_id(Context, ServiceProviderID) -> get_service_provider_by_id(Context, ServiceProviderID) ->
Params = #{ Params = #{

View File

@ -2,6 +2,7 @@
-export([get_payment_by_id/3]). -export([get_payment_by_id/3]).
-export([get_payment_by_external_id/2]). -export([get_payment_by_external_id/2]).
-export([get_payment_by_external_id_for_party/3]).
-export([get_payments/2]). -export([get_payments/2]).
-export([create_payment/3]). -export([create_payment/3]).
-export([cancel_payment/4]). -export([cancel_payment/4]).
@ -9,6 +10,7 @@
-export([get_refunds/3]). -export([get_refunds/3]).
-export([get_refund_by_id/4]). -export([get_refund_by_id/4]).
-export([get_refund_by_external_id/2]). -export([get_refund_by_external_id/2]).
-export([get_refund_by_external_id_for_party/3]).
-export([get_chargebacks/3]). -export([get_chargebacks/3]).
-export([get_chargeback_by_id/4]). -export([get_chargeback_by_id/4]).
-export([create_refund/4]). -export([create_refund/4]).
@ -49,6 +51,16 @@ get_payment_by_external_id(Context, ExternalID) ->
Response = swag_client_payments_api:get_payment_by_external_id(Url, PreparedParams, Opts), Response = swag_client_payments_api:get_payment_by_external_id(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response). capi_client_lib:handle_response(Response).
-spec get_payment_by_external_id_for_party(context(), binary(), binary()) -> {ok, term()} | {error, term()}.
get_payment_by_external_id_for_party(Context, PartyID, ExternalID) ->
Params = #{
binding => #{<<"partyID">> => PartyID},
qs_val => #{<<"externalID">> => ExternalID}
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payments_api:get_payment_by_external_id_for_party(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec create_payment(context(), map(), binary()) -> {ok, term()} | {error, term()}. -spec create_payment(context(), map(), binary()) -> {ok, term()} | {error, term()}.
create_payment(Context, Request, InvoiceID) -> create_payment(Context, Request, InvoiceID) ->
Params = #{ Params = #{
@ -129,6 +141,16 @@ get_refund_by_external_id(Context, ExternalID) ->
Response = swag_client_payments_api:get_refund_by_external_id(Url, PreparedParams, Opts), Response = swag_client_payments_api:get_refund_by_external_id(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response). capi_client_lib:handle_response(Response).
-spec get_refund_by_external_id_for_party(context(), binary(), binary()) -> {ok, term()} | {error, term()}.
get_refund_by_external_id_for_party(Context, PartyID, ExternalID) ->
Params = #{
binding => #{<<"partyID">> => PartyID},
qs_val => #{<<"externalID">> => ExternalID}
},
{Url, PreparedParams, Opts} = capi_client_lib:make_request(Context, Params),
Response = swag_client_payments_api:get_refund_by_external_id_for_party(Url, PreparedParams, Opts),
capi_client_lib:handle_response(Response).
-spec create_refund(context(), map(), binary(), binary()) -> {ok, term()} | {error, term()}. -spec create_refund(context(), map(), binary(), binary()) -> {ok, term()} | {error, term()}.
create_refund(Context, Request, InvoiceID, PaymentID) -> create_refund(Context, Request, InvoiceID, PaymentID) ->
Params = #{ Params = #{

View File

@ -119,11 +119,11 @@
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},2}, {<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.6">>},2},
{<<"swag_client">>, {<<"swag_client">>,
{git,"https://github.com/valitydev/swag-payments", {git,"https://github.com/valitydev/swag-payments",
{ref,"a6529bb729abfff1fe265dde5971866bed0669b4"}}, {ref,"ba5219fab460373881178c98b85addb16829d383"}},
0}, 0},
{<<"swag_server">>, {<<"swag_server">>,
{git,"https://github.com/valitydev/swag-payments", {git,"https://github.com/valitydev/swag-payments",
{ref,"aaa932d06ccafb7c25f80f433557836e80d6d2ac"}}, {ref,"5d8696a4e68cf54b45e750905e30d5a003d80e61"}},
0}, 0},
{<<"thrift">>, {<<"thrift">>,
{git,"https://github.com/valitydev/thrift_erlang.git", {git,"https://github.com/valitydev/thrift_erlang.git",