コード例 #1
0
    def post(self):
        payload = request.get_data()
        sig_header = request.headers.get("STRIPE_SIGNATURE")
        event = None

        try:
            event = stripe.Webhook.construct_event(
                payload, sig_header, app.config["STRIPE_WEBHOOK_SECRET"])
        except ValueError as e:
            return responses.error(error_message="Invalid payload",
                                   error_code=None,
                                   status_code=400)
        except stripe.error.SignatureVerificationError as e:
            return responses.error(error_message="Invalid signature",
                                   error_code=None,
                                   status_code=400)

        event_dict = event.to_dict()
        if event_dict["type"] == "checkout.session.completed":
            session = event_dict["data"]["object"]
            if session["payment_status"] == "paid":
                checkout_order = robin_manager.create_checkout_order(
                    session_id=session["id"],
                    customer_id=session["customer"],
                    amount=session["amount_total"],
                    currency=session["currency"],
                    metadata=session["metadata"],
                )
                if checkout_order:
                    robin_manager.commit_changes()
                    return responses.success("OK")
        return responses.error("Not found", status_code=404, error_code=None)
コード例 #2
0
    def post(self, args: Dict[str, Any]):
        new_user = auth_manager.signup_user(
            args["email"],
            login_provider=args["login_provider"],
            login_provider_uid=args["email"],
            login_provider_data=FlokLoginData(password=args["password"]),
            first_name=args.get("first_name"),
            last_name=args.get("last_name"),
        )
        user_login_id = auth_manager.user_login_id(new_user)

        ### Auto creating company and retreat v1 upon signup for now.
        company_name = None
        if args.get("first_name"):
            company_name = f"{args.get('first_name')}'s company"

        new_company = company_manager.create_company(name=company_name,
                                                     admins=[new_user])
        retreat_manager.create_retreat(new_company, )
        auth_manager.commit_changes()
        ###

        return responses.success(
            {"user": UserApiSchema.dump(obj=new_user)},
            extra_headers=web.login_cookie_header(jwt, user_login_id.login_id),
        )
コード例 #3
0
 def post(self, post_args: Dict[str, any]):
     flok_fee = 12500  # $125
     flok_line_item = "Flok fee (per employee)"
     retreat = retreat_manager.get_retreat(post_args["retreat_id"], g.user)
     if retreat:
         matches: List[RetreatProposal] = list(
             filter(lambda p: p.id == post_args["proposal_id"],
                    retreat.proposals))
         if matches:
             proposal = matches[0]
             stripe_customer = robin_manager.get_stripe_customer(g.user)
             if not stripe_customer:
                 stripe_customer = robin_manager.create_stripe_customer(
                     g.user)
             stripe_checkout_session = robin_manager.create_stripe_checkout_session(
                 customer=stripe_customer,
                 image=proposal.image_url,
                 name=flok_line_item,
                 price=flok_fee,
                 quantity=retreat.num_employees,
                 success_url=post_args["redirect_url"],
                 cancel_url=post_args["redirect_url"],
                 metadata={
                     "retreat_id": retreat.id,
                     "proposal_id": proposal.id,
                 },
             )
             robin_manager.commit_changes()
             return responses.success(
                 {"session_id": stripe_checkout_session.id})
コード例 #4
0
ファイル: message.py プロジェクト: Summ-Technologies/pigeon
 def post(self, post_args: dict, conversation_id: str):
     if slack_client.send_text_message(conversation_id=conversation_id,
                                       message=post_args["message"]):
         return responses.success("Success", 204)
     return responses.error("Something went wrong",
                            status_code=500,
                            error_code=None)
コード例 #5
0
ファイル: message.py プロジェクト: Summ-Technologies/pigeon
 def get(self, conversation_id: str):
     conversation = pigeon_manager.get_conversation(conversation_id)
     if conversation:
         messages = pigeon_manager.get_messages(conversation=conversation)
         return responses.success(
             {"messages": list(map(MessageModel.to_json, messages))}, 200)
     else:
         return responses.error("Conversation not found", None, 404)
コード例 #6
0
 def delete(self):
     return responses.success(
         {"message": "Successfully logged out"},
         extra_headers={
             "Set-Cookie":
             f"{jwt.jwt_cookie_name}=logged; Path=/; Expires=Mon, 01, Jan 2000, 00:00:00 GMT; HttpOnly"
         },
     )
コード例 #7
0
 def put(self, put_args: Dict[str, int], retreat_id: int):
     retreat = retreat_manager.get_retreat(retreat_id, g.user)
     if retreat:
         retreat_manager.update_retreat_filter_details(
             retreat, put_args["num_employees"], put_args.get("num_nights"))
         retreat_manager.commit_changes()
         return responses.success(
             {"retreat": RetreatApiSchema.dump(obj=retreat)})
     return responses.error("Can't find retreat",
                            status_code=404,
                            error_code=None)
コード例 #8
0
 def delete(self, retreat_id: int):
     """Unselect prefered retreat proposal"""
     retreat = retreat_manager.get_retreat(retreat_id, g.user)
     if retreat:
         retreat_manager.unselect_retreat_proposal(retreat)
         retreat_manager.commit_changes()
         return responses.success(
             {"retreat": RetreatApiSchema.dump(obj=retreat)})
     else:
         return responses.error("Can't find retreat",
                                status_code=404,
                                error_code=None)
コード例 #9
0
 def post(self, args: Dict[str, Any]):
     logged_in_user = auth_manager.signin_user(
         login_provider=args["login_provider"],
         login_provider_uid=args["email"],
         login_provider_data=FlokLoginData(password=args["password"]),
     )
     user_login_id = auth_manager.user_login_id(logged_in_user)
     auth_manager.commit_changes()
     return responses.success(
         {"user": UserApiSchema.dump(obj=logged_in_user)},
         extra_headers=web.login_cookie_header(jwt, user_login_id.login_id),
     )
コード例 #10
0
 def post(self, args: Dict[str, Any]):
     user = auth_manager.signin_user_and_reset_password(
         user_login_token=args["login_token"],
         login_provider_data=FlokLoginData(password=args["password"]),
         login_provider=UserLoginProviderType.FLOK,
     )
     user_login_id = auth_manager.user_login_id(user)
     auth_manager.commit_changes()
     return responses.success(
         {"user": UserApiSchema.dump(obj=user)},
         extra_headers=web.login_cookie_header(jwt, user_login_id.login_id),
     )
コード例 #11
0
    def get(self):
        response = {"user": UserApiSchema.dump(obj=g.user)}

        companies = company_manager.get_companies(g.user, is_admin=True)

        if companies:
            company = companies[0]
            response.update({"company": CompanyApiSchema.dump(obj=company)})

            retreats = retreat_manager.get_retreats(company)
            if retreats:
                retreat = retreats[0]
                response.update(
                    {"retreat": RetreatApiSchema.dump(obj=retreat)})

        return responses.success(response)
コード例 #12
0
 def post(self, post_args: Dict[str, int], retreat_id: int):
     """Select prefered retreat proposal"""
     retreat = retreat_manager.get_retreat(retreat_id, g.user)
     if retreat:
         if retreat_manager.select_retreat_proposal(
                 retreat, post_args["proposal_id"]):
             retreat_manager.commit_changes()
             return responses.success(
                 {"retreat": RetreatApiSchema.dump(obj=retreat)})
         else:
             return responses.error("Can't find proposal",
                                    status_code=404,
                                    error_code=None)
     else:
         return responses.error("Can't find retreat",
                                status_code=404,
                                error_code=None)
コード例 #13
0
    def post(self, post_args: Dict[str, any], retreat_id: int):
        companies = company_manager.get_companies(g.user, is_admin=True)
        if companies:
            company = companies[0]
            retreats = list(
                filter(
                    lambda _retreat: _retreat.id == retreat_id,
                    retreat_manager.get_retreats(company),
                ))
            if retreats:
                retreat = retreats[0]
                retreat_manager.add_employee_location_submission(
                    retreat, post_args["submission"])
                retreat_manager.commit_changes()
                return responses.success({
                    "retreat":
                    RetreatApiSchema.dump(obj=retreat),
                })

        return responses.error("Can't find retreat.",
                               status_code=404,
                               error_code=None)
コード例 #14
0
ファイル: webhook.py プロジェクト: Summ-Technologies/pigeon
    def post(self):
        if not signature_verifier.is_valid(
            body=request.get_data(),
            timestamp=request.headers.get("X-Slack-Request-Timestamp"),
            signature=request.headers.get("X-Slack-Signature"),
        ):
            return responses.error("Invalid request", status_code=403, error_code=None)

        wrapped_event = request.get_json()
        logger.error(wrapped_event)

        challenge = wrapped_event.get("challenge")
        if challenge:
            return responses.success({"challenge": challenge})

        wrapped_event_type = wrapped_event.get("type")
        event = wrapped_event.get("event", {})
        if (
            wrapped_event_type == "event_callback"
            and event.get("type") == "message"
            and event.get("channel_type") == "im"
        ):
            message_subtype = event.get("subtype")
            if message_subtype == None:
                conversation_id = event["channel"]
                user_id = event["user"]
                text = event["text"]
                ts = event["ts"]
                conversation = pigeon_manager.get_conversation(conversation_id)
                user = pigeon_manager.get_user(user_id)
                if not user:
                    user = pigeon_manager.create_user(user_id)
                if not conversation:
                    conversation = pigeon_manager.create_conversation(
                        conversation_id, user_id
                    )
                pigeon_manager.upsert_message(ts, conversation, user_id, text)
                pigeon_manager.commit_changes()
                return responses.success("Ok")
            elif message_subtype == "message_deleted":
                return responses.error(
                    "Can't handle subtype: message_deleted",
                    status_code=422,
                    error_code=None,
                )
            elif message_subtype == "message_changed":
                conversation_id = event["channel"]
                event_message = event["message"]
                user_id = event_message["user"]
                text = event_message["text"]
                ts = event_message["ts"]
                conversation = pigeon_manager.get_conversation(conversation_id)
                user = pigeon_manager.get_user(user_id)
                if not user:
                    user = pigeon_manager.create_user(user_id)
                if not conversation:
                    conversation = pigeon_manager.create_conversation(
                        conversation_id, user_id
                    )
                pigeon_manager.upsert_message(ts, conversation, user_id, text)
                pigeon_manager.commit_changes()
                return responses.success("Ok")
            else:
                return responses.error(
                    "Can't handle subtype", status_code=422, error_code=None
                )
        else:
            return responses.error(
                "Invalid request, unknown code", status_code=422, error_code=None
            )
コード例 #15
0
 def get(self, args: Dict[str, any]):
     user = auth_manager.get_user_by_login_token(
         login_token=args["login_token"])
     if user:
         return responses.success({"user": UserApiSchema.dump(obj=user)})
     raise HawkAuthException(1005)