新增订单待支付与支付确认后端流程
This commit is contained in:
@@ -152,6 +152,23 @@ func (h *Handler) Cancel(c *gin.Context) {
|
||||
response.OK(c, gin.H{"cancelled": true})
|
||||
}
|
||||
|
||||
func (h *Handler) Pay(c *gin.Context) {
|
||||
userID, ok := currentUserID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少用户上下文")
|
||||
return
|
||||
}
|
||||
id, ok := parseID(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if err := h.service.Pay(userID, id); err != nil {
|
||||
writeOrderError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"paid": true})
|
||||
}
|
||||
|
||||
func (h *Handler) SubmitHandoff(c *gin.Context) {
|
||||
userID, ok := currentUserID(c)
|
||||
if !ok {
|
||||
@@ -287,6 +304,10 @@ func writeOrderError(c *gin.Context, err error) {
|
||||
response.Error(c, http.StatusConflict, "listing_unavailable", "该账号暂不可租")
|
||||
case errors.Is(err, ErrCannotRentOwnListing):
|
||||
response.BadRequest(c, "不能租用自己发布的账号")
|
||||
case errors.Is(err, ErrInsufficientBalance):
|
||||
response.Error(c, http.StatusConflict, "insufficient_balance", "钱包余额不足,请先充值")
|
||||
case errors.Is(err, ErrOrderCannotPay):
|
||||
response.Error(c, http.StatusConflict, "order_cannot_pay", "当前订单不能支付")
|
||||
case errors.Is(err, ErrOrderCannotCancel):
|
||||
response.Error(c, http.StatusConflict, "order_cannot_cancel", "当前订单不能取消")
|
||||
case errors.Is(err, ErrOrderCannotHandoff):
|
||||
|
||||
Reference in New Issue
Block a user