所以我试图通过匹配params["state"]
回调来更新模式,在我的控制器中,我正在做这样的事情。
def create(conn, params) do
viewer = GiftActions.get_gift_user!(params["user_id"])
case params["state"] do
"captured" ->
GiftActions.validate_gift_order(viewer, params)
Logger.info("Request is validated sending code to #{inspect(viewer.email)}")
{:ok, id} ->
put_status(conn, 200)
|> json(%{data: id})
_ -> put_status(conn, 404) |> json(%{data: ""})
end
end
params["state"]
如果是,我的函数将处理更新captured
,就像这样
def validate_gift_order(viewer, attrs) do
{:ok, gift_order} = __MODULE__.get_gift_by_payment_id(viewer, attrs["id"])
gift_order
|> GiftOrders.changeset(%{state: attrs["state"]})
|> Repo.update()
end
一切正常,但最后我没有回来Plug.Conn
。错误是说
[error] #PID<0.5693.0> running VWeb.Endpoint (connection #PID<0.5692.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /api/v1/gift-callback?user_id=#######
** (exit) an exception was raised:
** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection, got: :ok
(viavolo 0.1.0) lib/v_web/controllers/gif_callback_controller.ex:1: VWeb.GiftCallbackController.phoenix_controller_pipeline/2
(phoenix 1.5.9) lib/phoenix/router.ex:352: Phoenix.Router.__call__/2
(viavolo 0.1.0) lib/viavolo_web/endpoint.ex:1: ViavoloWeb.Endpoint.plug_builder_call/2
(viavolo 0.1.0) lib/viavolo_web/endpoint.ex:1: VWeb.Endpoint."call (overridable 3)"/2
(viavolo 0.1.0) lib/plug/debugger.ex:136: VWeb.Endpoint."call (overridable 4)"/2
(viavolo 0.1.0) lib/v_web/endpoint.ex:1: VWeb.Endpoint.call/2
我不完全确定为什么?我应该回到这里做什么?