def authenticate_wc():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    params = request.args
    redirect_url = mod_woocommerce.handleAuthenicate(params)
    return redirect(redirect_url, 305)
def authenticate_wc_callback():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    params = request.form
    if request.is_json:
        params = request.json
    if mod_woocommerce.handleAuthenicateCallback(params):
        return make_response("")
def paymentCancel():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    m_pg = mod_payment.Paygate()
    payment_rec = m_pg.handleCancel(request)
    m_mwp = mod_makewebpage.Mwp()
    return m_mwp.doOrderCancelled(request, payment_rec["user_id"],
                                  payment_rec["fb_page_id"],
                                  payment_rec["order_id"])
def ping():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    if request.args.get("q") == "chatbotcms-wcbot":
        resp = make_response("pong", 200)
        resp.headers["Access-Control-Allow-Origin"] = "*"
        resp.headers["Access-Control-Allow-Headers"] = "X-Requested-With"
        return resp
    else:
        time.sleep(3)
        return make_response("Invalid request!\n", 500)
def test_db():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    if request.args.get("q") == "chatbotcms-wcbot":
        try:
            m_mdb = mod_database.Mdb()
            count = m_mdb.getClientsCount()
            resp = make_response("Database connection okay.\n", 200)
            resp.headers["Access-Control-Allow-Origin"] = "*"
            resp.headers["Access-Control-Allow-Headers"] = "X-Requested-With"
            return resp
        except Exception as ex:
            return make_response("Exp: " + str(ex), 200)
    else:
        time.sleep(3)
        return make_response("Invalid request! Missing query string.\n", 500)
def paymentReturn():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    m_pg = mod_payment.Paygate()
    result = m_pg.handleReturn(request)
    if result == None:  # Prevent double entry
        return make_response("ok")
    else:
        m_mwp = mod_makewebpage.Mwp()
        paymenttxn = result["paymenttxn"]
        m_wcbot = mod_wcbot.WcBot()
        m_wcbot.doOrderReceived(paymenttxn["user_id"],
                                paymenttxn["fb_page_id"],
                                paymenttxn["order_id"])
        return m_mwp.renderOrderReceivedHtml(request, paymenttxn,
                                             result["shopcart"],
                                             result["wcorder"])
def webhookfb():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    mMgr = mod_messenger.Messenger()
    if request.method == "GET":
        result = mMgr.webhookGet(request.args)
        if result is not None:
            return make_response(result)
        else:
            return make_response("Unkown verify token!", 500)
    elif request.method == "POST":
        try:
            result = mMgr.webhookPost(request)
            return make_response(result)
        except:
            logger.error(traceback.format_exc())
            return make_response("")
def test_wc():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    if request.args.get("subscribe_vk") is None:
        time.sleep(3)
        return make_response("Invalid request! Missing query string.\n", 500)
    client_id = request.args.get("subscribe_vk")
    m_mdb = mod_database.Mdb()
    client_rec = m_mdb.findClientByVerifyToken(client_id)
    if client_rec is None:
        return make_response("Invalid request! Invalid id", 500)
    wc_rec = client_rec["woocommerce"]
    wc_url = wc_rec["url"]
    m_wc = mod_woocommerce.Wc(wc_url, wc_rec["consumer_key"],
                              wc_rec["consumer_secret"])
    m_wc.getGeneralSetting()
    m_wc.getProductsList(1, 1)
    resp = make_response(
        "WooCommerce connection with '{0}' okay.\n".format(wc_url), 200)
    resp.headers["Access-Control-Allow-Origin"] = "*"
    resp.headers["Access-Control-Allow-Headers"] = "X-Requested-With"
    return resp
def index():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    time.sleep(1)
    return make_response("WcBot is running\n", 200)
def webServices(name):
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request, remove_path="/ws")
    cart_ws = mod_webservices.Shopcart()
    return cart_ws.handleService(name, request)
def makeWebPage():
    logger.debug(
        str(currentframe().f_lineno) + ":" + inspect.stack()[0][3] + "()")
    mod_global.server_entry(request)
    m_mwp = mod_makewebpage.Mwp()
    return m_mwp.mapHandler(request)