CAPI-366: Offset refund ids (#414)

This commit is contained in:
Alexey 2019-08-27 14:01:54 +03:00 committed by GitHub
parent be66e0eae7
commit d9cafafef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -6,6 +6,7 @@
-type woody_context() :: woody_context:ctx().
-type context_data() :: #{binary() => term()}.
-type bender_context() :: #{binary() => term()}.
-type sequence_params() :: #{minimum => integer()}.
-export_type([
bender_context/0,
context_data/0
@ -15,6 +16,7 @@
-export([gen_by_snowflake/3]).
-export([gen_by_sequence/4]).
-export([gen_by_sequence/5]).
-export([gen_by_sequence/6]).
-export([gen_by_constant/4]).
-export([gen_by_constant/5]).
-export([get_idempotent_key/3]).
@ -49,8 +51,17 @@ gen_by_sequence(IdempotentKey, SequenceID, Hash, WoodyContext) ->
{error, {external_id_conflict, binary()}}.
gen_by_sequence(IdempotentKey, SequenceID, Hash, WoodyContext, CtxData) ->
gen_by_sequence(IdempotentKey, SequenceID, Hash, WoodyContext, CtxData, #{}).
-spec gen_by_sequence(binary(), binary(), integer(), woody_context(), context_data(), sequence_params()) ->
{ok, binary()} |
{error, {external_id_conflict, binary()}}.
gen_by_sequence(IdempotentKey, SequenceID, Hash, WoodyContext, CtxData, Params) ->
Minimum = maps:get(minimum, Params, undefined),
Sequence = {sequence, #bender_SequenceSchema{
sequence_id = SequenceID
sequence_id = SequenceID,
minimum = Minimum
}},
generate_id(IdempotentKey, Sequence, Hash, WoodyContext, CtxData).

View File

@ -441,7 +441,7 @@ create_refund(InvoiceID, PaymentID, RefundParams, #{woody_context := WoodyCtx} =
SequenceID = create_sequence_id([InvoiceID, PaymentID], BenderPrefix),
CtxData = #{<<"invoice_id">> => InvoiceID, <<"payment_id">> => PaymentID},
Hash = erlang:phash2(RefundParams),
case capi_bender:gen_by_sequence(IdempotentKey, SequenceID, Hash, WoodyCtx, CtxData) of
case capi_bender:gen_by_sequence(IdempotentKey, SequenceID, Hash, WoodyCtx, CtxData, #{minimum => 100}) of
{ok, ID} ->
Params = #payproc_InvoicePaymentRefundParams{
id = ID,