Beispiel #1
0
        public async Task <HttpResponseMessage> PostRequestQrCodeAsClient(QrTransactionModel.RequestQrCodeViewModel requestQrCodeViewModel, [FromUri] string client_id)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse((HttpStatusCode)422, ModelState));
            }

            if (!db.Actors.Any(u => u.Id == client_id))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, client_id));
            }
            if (requestQrCodeViewModel.available_until > 1209600)
            {
                return(Request.CreateResponse((HttpStatusCode)468, "Availability is too long. Maximum is 14 days."));
            }
            if (requestQrCodeViewModel.available_until < 60)
            {
                return(Request.CreateResponse((HttpStatusCode)469, "Availability is too short. Minimum is 60 seconds."));
            }
            if (requestQrCodeViewModel.reference.Length > 140)
            {
                return(Request.CreateResponse((HttpStatusCode)464, "Reference code is too long. Max length is 140 chars."));
            }

            Transaction transaction = new Transaction();

            transaction.Amount         = requestQrCodeViewModel.amount;
            transaction.Currency       = requestQrCodeViewModel.currency;
            transaction.Reference      = requestQrCodeViewModel.reference;
            transaction.AvailableUntil = DateTime.Now.AddSeconds(requestQrCodeViewModel.available_until);
            transaction.AdjustibleUp   = requestQrCodeViewModel.adjustible_up;
            transaction.AdjustibleDown = requestQrCodeViewModel.adjustible_down;
            transaction.Status         = "Open";
            transaction.RecipientId    = client_id;
            string transactionId = "Priv_Trans_" + HelperMethods.GetUniqueKey(10);

            transaction.Id            = transactionId;
            transaction.DateOfPayment = DateTime.Now;

            db.Transactions.Add(transaction);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            String transactionUrl = "ubgpay://trans/" + transactionId;

            CodeGenerator qrGenerator = new CodeGenerator();
            string        img         = qrGenerator.RenderQRWithPicture(transactionUrl);


            QrTransactionModel.QrLinKRefViewModel qrLinKRefViewModel = new QrTransactionModel.QrLinKRefViewModel();
            qrLinKRefViewModel.link            = transactionUrl;
            qrLinKRefViewModel.img             = img;
            qrLinKRefViewModel.refId           = transactionId;
            qrLinKRefViewModel.available_until = transaction.AvailableUntil;

            //TODO Test if QR should be included

            return(Request.CreateResponse(HttpStatusCode.Created, qrLinKRefViewModel));
        }
Beispiel #2
0
        public async Task <HttpResponseMessage> PostRequestQrCodeAsVendor(QrTransactionModel.RequestQrCodeViewModel requestQrCodeViewModel)
        {
            if (!ModelState.IsValid)
            {
                var response2 = Request.CreateResponse((HttpStatusCode)422, ModelState);
                return(response2);
            }

            if (!db.Actors.Any(u => u.UserName == requestQrCodeViewModel.user_name))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, requestQrCodeViewModel.user_name));
            }
            if (!(db.Actors.FirstOrDefault(u => u.UserName == requestQrCodeViewModel.user_name).AuthToken == requestQrCodeViewModel.auth_token))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "AuthToken is not valid!"));
            }
            if (db.Actors.FirstOrDefault(u => u.UserName == requestQrCodeViewModel.user_name).Expiration_AuthToken < DateTime.Now)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "AuthToken is expired!"));
            }
            if (requestQrCodeViewModel.available_until > 259200)
            {
                return(Request.CreateResponse((HttpStatusCode)468, "Availability is too long. Maximum is 72 hours."));
            }
            if (requestQrCodeViewModel.available_until < 60)
            {
                return(Request.CreateResponse((HttpStatusCode)469, "Availability is too short. Minimum is 60 seconds."));
            }
            if (requestQrCodeViewModel.reference.Length > 140)
            {
                return(Request.CreateResponse((HttpStatusCode)464, "Reference code is too long. Max length is 140 chars."));
            }

            Transaction transaction = new Transaction();

            transaction.Amount         = requestQrCodeViewModel.amount;
            transaction.Currency       = requestQrCodeViewModel.currency;
            transaction.Reference      = requestQrCodeViewModel.reference;
            transaction.AvailableUntil = DateTime.Now.AddSeconds(requestQrCodeViewModel.available_until);
            transaction.AdjustibleUp   = requestQrCodeViewModel.adjustible_up;
            transaction.AdjustibleDown = requestQrCodeViewModel.adjustible_down;
            transaction.Status         = "Open";
            transaction.RecipientId    = db.Actors.FirstOrDefault(u => u.UserName == requestQrCodeViewModel.user_name).Id;
            string transactionId = "Ref_" + HelperMethods.GetUniqueKey(10);

            transaction.Id            = transactionId;
            transaction.DateOfPayment = DateTime.Now;

            db.Transactions.Add(transaction);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw;
            }

            String transactionUrl = "ubgpay://trans/" + transactionId;

            CodeGenerator qrGenerator = new CodeGenerator();
            string        img         = qrGenerator.RenderQRWithPicture(transactionUrl);


            QrTransactionModel.QrLinKRefViewModel qrLinKRefViewModel = new QrTransactionModel.QrLinKRefViewModel();
            qrLinKRefViewModel.link  = transactionUrl;
            qrLinKRefViewModel.img   = img;
            qrLinKRefViewModel.refId = transactionId;

            return(Request.CreateResponse(HttpStatusCode.Created, qrLinKRefViewModel));
        }