예제 #1
0
        public HttpResponseMessage CreateOrder([FromBody]MerchantRequestModel model)
        {
            try
            {
                BankEntities context = new BankEntities();
                ACCOUNT account = context.ACCOUNTs.FirstOrDefault(x => x.MERCHANT_ID == model.MerchantID);
                if (ModelState.IsValid)
                {
                    if (account == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "There is no merchant with sent ID value!");
                    }
                    else if (!account.MERCHANT_PASSWORD.Equals(model.MerchantPassword))
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "Incorect password for merchant!");
                    }

                    long last = context.TRANSACTIONs.Count() > 0 ? context.TRANSACTIONs.OrderByDescending(x => x.TRANSACTIONTIMESTAMP).FirstOrDefault().PAYMENT_ID : 0;
                    long paymentID = GenerateNumber.GenerateTenDigitNumber(last);

                    TRANSACTION transaction = new TRANSACTION
                    {
                        AMOUNT = model.Amount,
                        TRANSACTIONORDERID = model.MerchantOrderID,
                        TRANSACTIONTIMESTAMP = model.MerchantTimestamp,
                        PAYMENT_ID = paymentID
                    };

                    context.TRANSACTIONs.Add(transaction);
                    context.SaveChanges();

                    string bankWebAppURL = System.Configuration.ConfigurationManager.AppSettings["BankWebApp"];

                    MerchantResponseModel responseModel = new MerchantResponseModel();
                    responseModel.PaymentID = paymentID.ToString();
                    responseModel.PaymentURL = string.Format("{0}{1}", bankWebAppURL, paymentID);

                    return Request.CreateResponse(HttpStatusCode.OK, responseModel);
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "Bad model!");
                }
            }
            catch
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError);
            }
        }
예제 #2
0
        public HttpResponseMessage CheckOrder([FromBody]PccRequestModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    BankEntities context = new BankEntities();

                    CREDITCARD creditCard = context.CREDITCARDs.FirstOrDefault(x => x.PAN == model.CardPAN && x.SECURITYCODE == model.CardSecurityCode);
                    if (creditCard == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "Bad PAN!");
                    }

                    if (creditCard.ACCOUNT == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid card parameters!");
                    }

                    ACCOUNT account = creditCard.ACCOUNT;

                    if (account.AMMOUNT < model.Amount)
                    {
                        return Request.CreateResponse(HttpStatusCode.BadRequest, "There is not enough money in the account!");
                    }

                    long last = context.TRANSACTIONs.Count() > 0 ? context.TRANSACTIONs.OrderByDescending(x => x.TRANSACTIONTIMESTAMP).FirstOrDefault().PAYMENT_ID : 0;
                    long paymentID = GenerateNumber.GenerateTenDigitNumber(last);

                    TRANSACTION transaction = new TRANSACTION
                    {

                        AMOUNT = model.Amount,
                        TRANSACTIONORDERID = model.AcquirerID,
                        TRANSACTIONTIMESTAMP = model.AcquirerTimestamp,
                        PAYMENT_ID = paymentID
                    };

                    long lastOrderID = context.BANKORDERs.Count() > 0 ? context.BANKORDERs.OrderByDescending(x => x.BANKORDERTIMESTAMP).FirstOrDefault().BANKORDER_ID : 0;
                    long OrderID = GenerateNumber.GenerateTenDigitNumber(last);

                    BANKORDER order = new BANKORDER
                    {
                        BANKORDER_ID = OrderID,
                        BANKORDERTIMESTAMP = DateTime.Now,
                        CREDITCARD = creditCard,
                        IS_ISSUER = true,
                        TRANSACTION = transaction
                    };

                    account.AMMOUNT -= model.Amount;
                    context.BANKORDERs.Add(order);
                    context.SaveChanges();

                    IssuerResponseModel issuerModel = new IssuerResponseModel
                    {
                        AcquirerID = model.AcquirerID,
                        AcquirerTimestamp = model.AcquirerTimestamp,
                        IssuerID = order.BANKORDER_ID,
                        IssuerTimestamp = order.BANKORDERTIMESTAMP
                    };

                    return Request.CreateResponse(HttpStatusCode.OK, issuerModel);
                }
                catch
                {
                    return Request.CreateResponse(HttpStatusCode.InternalServerError);
                }
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid model");
        }