fix: persist specialist_id on event create; 402 commercial without active sub. Fixes EventHub/EventHubBack#61
This commit is contained in:
@@ -409,9 +409,26 @@ register_and_login(Email, Password) ->
|
||||
|
||||
-spec create_calendar(binary(), map()) -> binary().
|
||||
create_calendar(Token, Params) ->
|
||||
Type = maps:get(type, Params, maps:get(<<"type">>, Params, <<"personal">>)),
|
||||
case Type of
|
||||
<<"commercial">> -> ensure_commercial_subscription(Token);
|
||||
commercial -> ensure_commercial_subscription(Token);
|
||||
_ -> ok
|
||||
end,
|
||||
#{<<"id">> := CalId} = client_post(<<"/v1/calendars">>, Token, Params),
|
||||
CalId.
|
||||
|
||||
-spec ensure_commercial_subscription(binary()) -> ok.
|
||||
ensure_commercial_subscription(Token) ->
|
||||
case client_request(post, <<"/v1/subscription">>, Token,
|
||||
jsx:encode(#{action => <<"start_trial">>})) of
|
||||
{ok, 201, _, _} -> ok;
|
||||
{ok, 200, _, _} -> ok;
|
||||
{ok, 409, _, _} -> ok; %% already has subscription / trial used with active
|
||||
{ok, 400, _, _} -> ok; %% trial_already_used — may still have active paid
|
||||
_ -> ok
|
||||
end.
|
||||
|
||||
-spec create_event(binary(), binary(), map()) -> binary().
|
||||
create_event(Token, CalId, Params) ->
|
||||
Path = <<"/v1/calendars/", CalId/binary, "/events">>,
|
||||
|
||||
Reference in New Issue
Block a user