Esempio n. 1
0
        def __init__(self, kwargs):

            if util.check_param(kwargs,'billing_address'):
                billing_address = Orders.Order.Address("billing", kwargs)
            else:
                billing_address = None
            if util.check_param(kwargs,'shipping_address'):
                shipping_address = Orders.Order.Address("shipping", kwargs)
            else:
                shipping_address = None
            if util.get_arg(kwargs, 'card') is not None:
                card = Cards.Card(util.get_arg(kwargs, 'card'))
            else:
                card = None
            if util.get_arg(kwargs, 'payment_gateway_response') is not None:
                gateway_response = Orders.Order.GatewayResponse(util.get_arg(kwargs, 'payment_gateway_response'))
            else:
                gateway_response = None
            if 'refunds' in kwargs:
                refunds = []
                for refund in kwargs['refunds']:
                    refund_obj = Orders.Order.Refund(refund)
                    refunds.append(refund_obj)
            else:
                refunds = None
            self.merchant_id = util.get_arg(kwargs, 'merchant_id')
            self.order_id = util.get_arg(kwargs, 'order_id')
            self.status = util.get_arg(kwargs, 'status')
            self.status_id = util.get_arg(kwargs, 'status_id')
            self.amount = util.get_arg(kwargs, 'amount')
            self.currency = util.get_arg(kwargs, 'currency')
            self.customer_id = util.get_arg(kwargs, 'customer_id')
            self.customer_email = util.get_arg(kwargs, 'customer_email')
            self.customer_phone = util.get_arg(kwargs, 'customer_phone')
            self.product_id = util.get_arg(kwargs, 'product_id')
            self.return_url = util.get_arg(kwargs, 'return_url')
            self.description = util.get_arg(kwargs, 'description')
            self.billing_address = billing_address
            self.shipping_address = shipping_address
            self.udf1 = util.get_arg(kwargs, 'udf1')
            self.udf2 = util.get_arg(kwargs, 'udf2')
            self.udf3 = util.get_arg(kwargs, 'udf3')
            self.udf4 = util.get_arg(kwargs, 'udf4')
            self.udf5 = util.get_arg(kwargs, 'udf5')
            self.udf6 = util.get_arg(kwargs, 'udf6')
            self.udf7 = util.get_arg(kwargs, 'udf7')
            self.udf8 = util.get_arg(kwargs, 'udf8')
            self.udf9 = util.get_arg(kwargs, 'udf9')
            self.udf10 = util.get_arg(kwargs, 'udf10')
            self.txn_id = util.get_arg(kwargs, 'txn_id')
            self.gateway_id = util.get_arg(kwargs, 'gateway_id')
            self.bank_error_code = util.get_arg(kwargs, 'bank_error_code')
            self.bank_error_message = util.get_arg(kwargs, 'bank_error_message')
            self.refunded = util.get_arg(kwargs, 'refunded')
            self.amount_refunded = util.get_arg(kwargs, 'amount_refunded')
            self.card = card
            self.gateway_response = gateway_response
            self.refunds = refunds
Esempio n. 2
0
File: awc.py Progetto: rzymek01/MiSS
    def __init__(self, j, k, m, initial):
        self.j = check_param(j, lambda x: x > 0, "J has to be bigger than 0")
        self.k = check_param(k, lambda x: x > j, "K has to be bigger than J")
        self.m = m
        self.initial = check_param(initial, lambda x: len(x) == k, "Have to receive K initial values")

        self.values = deque(self.initial)

        self.carry = 0

        self.current = 0
Esempio n. 3
0
    def __init__(self, j, k, m, initial):
        self.j = check_param(j, lambda x: x > 0, "J has to be bigger than 0")
        self.k = check_param(k, lambda x: x > j, "K has to be bigger than J")
        self.m = m
        self.initial = check_param(initial, lambda x: len(x) == k,
                                   "Have to receive K initial values")

        self.values = deque(self.initial)

        self.carry = 0

        self.current = 0
Esempio n. 4
0
def delete():
    try:
        data = json.loads(flask.request.data)
    except json.decoder.JSONDecodeError:
        logger.error("delete subway line ERROR: JSON decode failed.\n %s" %
                     traceback.format_exc())
        logger.debug("DELETE /line/v1/delete - %s" % http_code.NotAcceptable)
        message = {
            "error": "invalid DELETE request: JSON decode failed.",
            "code": http_code.NotAcceptable,
            "tips": util.get_tips_dict(10004)
        }
        message = json.dumps(message)
        return message, http_code.NotAcceptable

    token = flask.request.headers.get("token", None)
    if (token not in util.session) or \
            (not conductor.user.is_admin_user(util.session[token])):
        message = {
            "error": "limited authority",
            "code": http_code.Unauthorized,
            "tips": util.get_tips_dict(10006)
        }
        message = json.dumps(message)
        logger.warn("delete subway line WARNING: limited authority.")
        logger.debug("DELETE /line/v1/delete - %s" % http_code.Unauthorized)
        return message, http_code.Unauthorized

    uuid = data.get("uuid", None)
    logger.info("Begin to delete subway line %s." % uuid)
    try:
        kwargs = {"uuid": uuid}
        util.check_param(**kwargs)
        conductor.line.delete_subway_line(uuid)
    except STPHTTPException as e:
        message = {"error": e.error_message, "code": e.httpcode, "tips": e.tip}
        message = json.dumps(message)
        logger.error("delete subway line %s ERROR:\n%s" %
                     (uuid, traceback.format_exc()))
        logger.debug("DELETE /line/v1/delete - %s" % e.httpcode)
        return message, e.httpcode

    message = {
        "success": "delete subway line %s success." % uuid,
        "code": http_code.OK
    }
    message = json.dumps(message)
    return message, http_code.OK
Esempio n. 5
0
def add():
    try:
        data = json.loads(flask.request.data)
    except json.decoder.JSONDecodeError:
        logger.error("add subway line ERROR: JSON decode failed.\n %s" %
                     traceback.format_exc())
        logger.debug("POST /line/v1/add - 406")
        message = {
            "error": "invalid POST request: JSON decode failed.",
            "code": http_code.NotAcceptable,
            "tips": util.get_tips_dict(10004)
        }
        message = json.dumps(message)
        return message, http_code.NotAcceptable

    token = flask.request.headers.get("token", None)
    if (token not in util.session) or \
            (not conductor.user.is_admin_user(util.session[token])):
        message = {
            "error": "limited authority",
            "code": http_code.Unauthorized,
            "tips": util.get_tips_dict(10006)
        }
        message = json.dumps(message)
        logger.warn("add subway line WARNING: limited authority.")
        logger.debug("POST /line/v1/add - 401")
        return message, http_code.Unauthorized

    name = data.get("name", None)
    try:
        logger.info("Begin to add subway line %s." % name)
        util.check_param(name=name)
        conductor.line.add_subway_line(name)
    except STPHTTPException as e:
        message = {"error": e.error_message, "code": e.httpcode, "tips": e.tip}
        message = json.dumps(message)
        logger.error("add subway line %s ERROR:\n%s" %
                     (name, traceback.format_exc()))
        logger.debug("POST /line/v1/add - %s" % e.httpcode)
        return message, e.httpcode

    message = {
        "success": "add subway line %s success." % name,
        "code": http_code.OK
    }
    message = json.dumps(message)
    return message, http_code.OK
Esempio n. 6
0
def send_code_email():
    try:
        data = json.loads(flask.request.data)

        params = {
            "receiver": data.get("receiver", None),
            "header": data.get("header", None),
            "operate": data.get("operate", None)
        }
        util.check_param(**params)
        verify_code = util.general_verify_code(6)
        kwargs = {
            "header": params["header"],
            "type": "send_code",
            "receiver": params["receiver"],
            "operate": params["operate"],
            "code": verify_code
        }
        from main import send_mail
        send_mail(**kwargs)

        conductor.user.push_verify_code(kwargs["receiver"], verify_code,
                                        kwargs["operate"])

        message = {
            "success": "send to %s success." % kwargs["receiver"],
            "code": http_code.OK
        }
        message = json.dumps(message)
    except STPHTTPException as e:
        logger.debug("POST /email/v1/code - %s" % e.httpcode)
        logger.error("send code email ERROR:\n%s" % traceback.format_exc())
        message = {"error": "send mail failed.", "code": e.httpcode}
        message = json.dumps(message)
        return message, e.httpcode
    except json.decoder.JSONDecodeError:
        logger.error("register user ERROR: JSON decode failed.\n %s" %
                     traceback.format_exc())
        logger.debug("POST /user/v1/register - 406")
        message = {
            "error": "invalid POST request: JSON decode failed.",
            "code": http_code.NotAcceptable
        }
        message = json.dumps(message)
        return message, http_code.NotAcceptable

    return message, http_code.OK
Esempio n. 7
0
def update(context):
    try:
        data = json.loads(flask.request.data)
    except json.decoder.JSONDecodeError:
        logger.error("modify subway line ERROR: JSON decode failed.\n %s" %
                     traceback.format_exc())
        logger.debug("PUT /line/v1/modify/%s - 406" % context)
        message = {
            "error": "invalid PUT request: JSON decode failed.",
            "code": http_code.NotAcceptable,
            "tips": util.get_tips_dict(10004)
        }
        message = json.dumps(message)
        return message, http_code.NotAcceptable

    token = flask.request.headers.get("token", None)
    if (token not in util.session) or \
            (not conductor.user.is_admin_user(util.session[token])):
        message = {
            "error": "limited authority",
            "code": http_code.Unauthorized,
            "tips": util.get_tips_dict(10006)
        }
        message = json.dumps(message)
        logger.warn("update subway line WARNING: limited authority.")
        logger.debug("PUT /line/v1/modify/%s - 401" % context)
        return message, http_code.Unauthorized

    if context == "name":
        uuid = data.get("uuid", None)
        new_name = data.get("name", None)
        try:
            param = {"uuid": uuid, "name": new_name}
            util.check_param(**param)
            conductor.line.update_line(**param)
        except STPHTTPException as e:
            message = {
                "error": e.error_message,
                "code": e.httpcode,
                "tips": e.tip
            }
            message = json.dumps(message)
            logger.error("update subway line %s name ERROR:\n%s" %
                         (uuid, traceback.format_exc()))
            logger.debug("PUT /line/v1/modify/name - %s" % e.httpcode)
            return message, e.httpcode

        message = {
            "success": "update subway line %s success." % uuid,
            "code": http_code.OK
        }
        message = json.dumps(message)
        return message, http_code.OK
    else:
        message = {
            "error": "unknown modify request - '%s'" % context,
            "code": http_code.NotFound,
            "tips": util.get_tips_dict(10007)
        }
        message = json.dumps(message)
        return message, http_code.NotFound