示例#1
0
def index():
    if request.method == 'POST':
        _logger.info(f'USSD API POST vals: {request.form}')
        own_phone = request.form['own_phone']
        other_phone = request.form.get('other_phone')
        amount = request.form.get('amount')
        timestamp = datetime.now().timestamp()

        if not own_phone or not amount:
            return "Not sure what are you trying to achieve"

        if not other_phone:
            other_phone = own_phone

        other_phone = f"+254{other_phone[1:]}"

        try:
            data = {'recipient_number': other_phone,
                    'sender_number': f"+254{own_phone[1:]}",
                    'amount': amount,
                    'timestamp': str(timestamp)}

            post_rabbitmq(data)
            res = redirect('/')
            res.set_cookie('own_phone', own_phone)
            return res
        except Exception as ex:
            return f"Contact Admin if issues persists Error: {str(ex)}: [email protected]"

    else:
        own_phone = request.cookies.get('own_phone', '')
        return render_template('create.html', own_phone=own_phone)
示例#2
0
def get_key_path(i, ktype):
    try:
        KEY_NAME = ktype + str(i) + ASYMM_FILE_FORMATS[ktype]
        _logger.info("KPATH - FETCH - %s -- %s" % (ktype, KEY_NAME))
        return os.path.join(KD, KEY_NAME)
    except Exception as E:
        quit(E)
示例#3
0
def validate_keypair(i, s, v):
    msg = "message" + str(i)
    sig = s.sign(msg)
    ver = v.verify(sig, msg)
    if not ver:
        _logger.error("Error while reading keypair: " % i)
        return False
    _logger.info("Round succeeded for keypair: " % i)
    return True
示例#4
0
    def on_response_connected(self):
        _logger.info("connecting to a broker")
        connection = pika.BlockingConnection(self.parameters)
        channel = connection.channel()
        _logger.info("declaring queue {}".format(self.queue))
        channel.queue_declare(queue=self.queue, durable=True)

        # We need to bind this channel to an exchange, that will be used to transfer
        # messages from our delay queue.
        channel.queue_bind(exchange='amq.direct', queue=self.queue)

        # Create our delay channel.
        delay_channel = connection.channel()
        # delay_channel.confirm_delivery()

        # This is where we declare the delay, and routing for our delay channel.
        delay_channel.queue_declare(
            queue='delay_queue',
            durable=True,
            arguments={
                'x-message-ttl':
                5000,  # Delay until the message is transferred in milliseconds.
                'x-dead-letter-exchange':
                'amq.direct',  # Exchange used to transfer the message from A to B.
                'x-dead-letter-routing-key': self.
                queue  # Name of the queue we want the message transferred to.
            })

        _logger.info("Publishing Message to ...({})".format(self.queue))
        delay_channel.basic_publish(
            exchange='',
            routing_key='delay_queue',
            body=str(self.request),
            properties=pika.BasicProperties(delivery_mode=2))

        _logger.info("Published Message...({})".format(self.request))
        connection.close()
        _logger.info("Connection closed...({})".format(self.queue))
示例#5
0
def post_rabbitmq(data, queue_name="mpesa-queue"):
    msg = "post_rabbitmq", "queue: {}  data: {}".format(queue_name, data)
    _logger.info(f'airtime_web API post_rabbitmq: {msg}')
    push = QueuePublisherClient(queue_name, json.dumps(data))  # json.dumps(res).__str__())
    _logger.info(f'airtime_web API post_rabbitmq: {data}')
    push.on_response_connected()