func Parse(u *url.URL, h http.Header, req *models.Mail) (int, http.Header, interface{}, error) { if err := req.Validate(); err != nil { runner.MustGetLogger().Error("mail parse validate err : %S", err.Error()) // faily silently, we dont want mail parser service to retry on // the failed validation return response.NewDefaultOK() } if err := req.Persist(); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
func PublishEvent(u *url.URL, h http.Header, req *emailsender.Mail) (int, http.Header, interface{}, error) { if err := emailsender.Send(req); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
// HasCreditCard returns the existance status of group's credit card func HasCreditCard(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if !context.IsLoggedIn() { return response.NewBadRequest(models.ErrNotLoggedIn) } group, err := modelhelper.GetGroup(context.GroupName) if err != nil { return response.NewBadRequest(err) } if group.Payment.Customer.ID == "" { return response.NewNotFound() } err = payment.CheckCustomerHasSource(group.Payment.Customer.ID) if err == payment.ErrCustomerSourceNotExists { return response.NewNotFound() } if err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
// Webhook handles events from stripe func Webhook(u *url.URL, h http.Header, req *stripe.Event) (int, http.Header, interface{}, error) { // if we dont support the handler, just return success so they dont try again. handler, err := payment.GetHandler(req.Type) if err != nil { return response.NewDefaultOK() } // get the event from stripe api again since they dont provide a way to // authenticate incoming requests event, err := event.Get(req.ID, nil) if err != nil { return response.NewBadRequest(err) } if err := handler(event.Data.Raw); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
// DeleteCreditCard deletes the credit card of a group func DeleteCreditCard(u *url.URL, h http.Header, _ interface{}, context *models.Context) (int, http.Header, interface{}, error) { if err := context.IsGroupAdmin(); err != nil { return response.NewBadRequest(err) } if err := payment.DeleteCreditCardForGroup(context.GroupName); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
// HandleEvent handles events with given data func HandleEvent(u *url.URL, h http.Header, req map[string]interface{}) (int, http.Header, interface{}, error) { eventName := u.Query().Get("eventName") if eventName == "" { return response.NewBadRequest(errors.New("eventName can not be empty")) } if err := bongo.B.Emit(eventName, req); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
// handlePing handles the pings coming from anywhere func handlePing(u *url.URL, h http.Header, req *presence.Ping) (int, http.Header, interface{}, error) { if req == nil { return response.NewBadRequest(errors.New("req should be set")) } if req.GroupName == "" { return response.NewBadRequest(errors.New("groupName should be set")) } if req.AccountID == 0 { return response.NewBadRequest(errors.New("accountId should be set")) } req.CreatedAt = time.Now().UTC() // send the ping request to the related worker if err := bongo.B.PublishEvent(presence.EventName, req); err != nil { return response.NewBadRequest(err) } return response.NewDefaultOK() }
func RejectInvite(u *url.URL, h http.Header, participant *models.ChannelParticipant, ctx *models.Context) (int, http.Header, interface{}, error) { query := ctx.OverrideQuery(request.GetQuery(u)) participant.StatusConstant = models.ChannelParticipant_STATUS_LEFT cp, err := updateStatus(participant, query, ctx) if err != nil { return response.NewBadRequest(err) } if err := addLeaveActivity(query.Id, ctx.Client.Account.Id, cp); err != nil { return response.NewBadRequest(err) } ch := models.NewChannel() if err := ch.ById(query.Id); err != nil { return response.NewBadRequest(err) } go notifyParticipants(ch, models.ChannelParticipant_Removed_From_Channel_Event, []*models.ChannelParticipant{cp}) return response.NewDefaultOK() }
func AcceptInvite(u *url.URL, h http.Header, participant *models.ChannelParticipant, ctx *models.Context) (int, http.Header, interface{}, error) { query := ctx.OverrideQuery(request.GetQuery(u)) participant.StatusConstant = models.ChannelParticipant_STATUS_ACTIVE cp, err := updateStatus(participant, query, ctx) if err != nil { return response.NewBadRequest(err) } if err := addJoinActivity(query.Id, cp, 0); err != nil { return response.NewBadRequest(err) } ch := models.NewChannel() if err := ch.ById(query.Id); err != nil { return response.NewBadRequest(err) } go notifyParticipants(ch, models.ChannelParticipant_Added_To_Channel_Event, []*models.ChannelParticipant{cp}) return response.NewDefaultOK() }