def sendRequest(self, params):
     try:
         log_debug('Message Sent: %s' % params)
         url = self.getApiHost()
         r = requests.get(url, params=params)
         log_debug('Message Response: %s' % r.text)
         return json.loads(r.text)
     except Exception as e:
         log_error()
         return {"status": "failed", "response": "Error Message: %s" % e}
Esempio n. 2
0
    def post(self, request, *args, **kwargs):
        initial = {'request': self.request}
        form = SupplyOrderForm(request.POST, request=request)
        data = dict()
        error = dict()
        log_debug('GGGG')
        try:
            if form.is_valid():
                with transaction.atomic():
                    x = datetime.datetime.now()
                    order_count = SupplyOrder.objects.all().count()
                    cnt = "%04d" % order_count
                    y = x.strftime("%y")
                    m = x.strftime("%m")
                    order_number = "%s/%s%s" % (cnt, m, y)
                    order = form.save(commit=False)
                    order.created_by = request.user
                    order.order_reference = genetate_uuid4()
                    order.order_number = order_number
                    if not request.user.is_superuser:
                        if request.user.profile.access_level.name == "SUPPLIER":
                            order.supplier = request.user.supplier_user.supplier
                    order.save()

                    data = request.POST
                    item_id = data.getlist('item_id')
                    unit_price = data.getlist('unit_price')
                    quantity = data.getlist('item_quantity')
                    total_price = data.getlist('total_price')

                    for i in range(len(item_id)):

                        OrderItem.objects.create(order=order,
                                                 item=get_object_or_404(
                                                     Item, pk=item_id[i]),
                                                 quantity=quantity[i],
                                                 unit_price=unit_price[i],
                                                 price=total_price[i],
                                                 created_by=request.user)
                    return redirect('order:list')

        except Exception as e:
            log_error()
            error['errors'] = "Error %s" % e

        data = {
            'form': form,
            'item_form': OrderItemForm,
            'active': ['_order', '__order']
        }
        data.update(error)
        return render(request, self.template_name, data)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        form = CustomerOrderForm(request.POST)
        data = dict()
        error = dict()
        log_debug('GGGG')
        try:
            if form.is_valid():
                with transaction.atomic():
                    x = datetime.datetime.now()
                    order_count = CustomerOrder.objects.all().count()
                    cnt = "%04d" % order_count
                    y = x.strftime("%y")
                    m = x.strftime("%m")
                    order_number = "%s/%s%s" % (cnt, m, y)
                    order = form.save(commit=False)
                    order.created_by = request.user
                    order.order_reference = genetate_uuid4()
                    order.order_number = order_number
                    order.order_date = x
                    order.save()

                    data = request.POST
                    item_id = data.getlist('item_id')
                    unit_price = data.getlist('unit_price')
                    quantity = data.getlist('item_quantity')
                    total_price = data.getlist('total_price')

                    for i in range(len(item_id)):

                        CustomerOrderItem.objects.create(
                            order=order,
                            item=get_object_or_404(AgroDealerItem,
                                                   pk=item_id[i]),
                            quantity=quantity[i],
                            unit_price=unit_price[i],
                            price=total_price[i],
                            created_by=request.user,
                            order_date=x)
                    return redirect('order:order_list')

        except Exception as e:
            log_error()
            error['errors'] = "Error %s" % e

        data = {
            'form': form,
            'item_form': OrderItemForm,
            'active': ['_order', '_agrodealer_order']
        }
        data.update(error)
        return render(request, self.template_name, data)
Esempio n. 4
0
def depr__sendSMS(msisdn, message, **kwargs):
    try:
        res = None
        account = kwargs.get('account', '')
        outgoing = OutgoingMessages()
        outgoing.msisdn = msisdn
        outgoing.message = message
        outgoing.account = account if account else None
        try:
            sm = MessagingTransaction('BkKda32wkdqUeMWUBYPY')
            res = sm.sendOneSMS(msisdn, message)
            log_debug("Sent Message... %s" % res)
        except Exception:
            log_debug("Sending Failed... %s" % traceback.format_exc())
            outgoing.status = 'FAILED'
        outgoing.response = res
        outgoing.save()
    except Exception as e:
        #Die silently
        log_error()
Esempio n. 5
0
def payment_transction(msisdn, amount, reference):
    # if True:
    #     return {"status": "FAILED", "statusMessage": "Test Complete"}
    msisdn = msisdn
    timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
    password = '******'
    accountid = 'andrew'
    token = base64.urlsafe_b64encode(accountid + password + timestamp)
    http_auth = base64.urlsafe_b64encode('andrew:hamwe')
    url = 'https://payments.hamwepay.com/endpoint/service/transaction/'

    try:
        data = {
            "reference": reference,
            "method": "COLLECTION",
            "amount": "%s" % amount,
            "timestamp": timestamp,
            "token": token,
            "phonenumber": msisdn,
            "accountid": accountid
        }

        log_debug("Sending Airtime: %s" % data)
        headers = {
            'content-type': 'application/json',
            'Authorization': 'Basic %s' % http_auth
        }

        req = requests.post(url, data=json.dumps(data), headers=headers)
        jr = json.loads(req.text)
        if 'transactionStatus' in jr:
            if jr['transactionStatus'] == 'SUCCESSFUL':
                log_debug(jr)
        log_debug("Response From Server %s" % req.text)
        return jr
    except Exception as err:
        log_error()
        return {"status": "ERROR", "statusMessage": "Server Error"}