Beispiel #1
0
        public BankResponseModel Edit(EditBankInputModel data)
        {
            Bank temp = new Bank();

            temp.ID                 = data.BankID;
            temp.Kode               = data.Kode;
            temp.BankName           = data.Nama;
            temp.IsActive           = data.IsActive;
            temp.LastUpdateDate     = DateTime.Now;
            temp.LastUpdateByUserID = data.LastUpdateByUserID;

            BankRepository bankRepo = new BankRepository(DbContext);

            var res = bankRepo.Update(temp);

            BankResponseModel result = new BankResponseModel();

            result.Message  = res.Message;
            result.Response = res.Result;

            BankOutputModel output = new BankOutputModel();

            output.Kode = data.Kode;
            output.Nama = data.Nama;

            result.data = output;

            return(result);
        }
            public async void UpdatedBankIsReturned()
            {
                var expectedBank = new BankResponseModel
                {
                    AccountNumber         = "5e12967707909e62b2bb2036c209085a784fabbc3deccefee70052b6181c8ed8",
                    IpAddress             = "83.168.1.232",
                    NodeIdentifier        = "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1",
                    Port                  = 80,
                    Protocol              = "http",
                    Version               = "v1.0",
                    DefaultTransactionFee = 1,
                    Trust                 = "53.22"
                };

                var service = BuildUpdateBankAsyncConnectedBanksServiceMock(expectedBank);

                var bank = await service.UpdateBankAsync(
                    "d5356888dc9303e44ce52b1e06c3165a7759b9df1e6a6dfbd33ee1c3df1ab4d1",
                    new RequestModel());

                var expectedBankStr = JsonConvert.SerializeObject(expectedBank);
                var actualBankStr   = JsonConvert.SerializeObject(bank);

                Assert.Equal(expectedBankStr, actualBankStr);
            }
        // POST: api/Bank
        public HttpResponseMessage Post([FromBody] string value)
        {
            try
            {
                //Simluate an error for testing
                //Random objRandom = new Random();
                //int num = objRandom.Next(1, 3);
                //if (num == 2)
                //   throw new Exception("Simulated error");

                BankResponseModel objBankResponse = new BankResponseModel()
                {
                    Identifier = Guid.NewGuid().ToString(),
                    Status     = "OK",
                    Message    = "Payment Process Successfully"
                };

                return(Request.CreateResponse(HttpStatusCode.OK, objBankResponse));
            }
            catch (Exception ex)
            {
                BankResponseModel objBankErrorResponse = new BankResponseModel()
                {
                    Status = "ERROR", Message = ex.Message
                };
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, objBankErrorResponse));
            }
        }
Beispiel #4
0
        public ActionResult <BankResponseModel> EditMasterBank([FromBody] EditBankInputModel data)
        {
            BankResponseModel response = new BankResponseModel();

            try
            {
                BankBL posBL = new BankBL(DbContext);
                return(posBL.Edit(data));
            }
            catch (Exception ex)
            {
                response.Message  = ex.Message;
                response.Response = false;
                return(response);
            }
        }
Beispiel #5
0
        public async Task <BankResponseModel> MakeBankPayment(PaymentBindingModels Payment)
        {
            //build final url
            String url = baseUrl + "api/Bank";

            using (HttpResponseMessage response = await Api.ApiConnector.PostAsJsonAsync(url, Payment))
            {
                BankResponseModel objBankResponse = await response.Content.ReadAsAsync <BankResponseModel>();

                using (var scope = DI.DI.Container.BeginLifetimeScope())
                {
                    var obj = scope.Resolve <ILoggerInterface>();
                    //Logs API call response status
                    string msg = String.Format("STATUS: {0} | URL: {1} | MSG: {2}", objBankResponse.Status, url, objBankResponse.Message);
                    obj.LogMessage("BankApi.MakeBankPayment", msg);
                }

                return(objBankResponse);
            }
        }
        // POST: Make a payment
        public async Task <HttpResponseMessage> Post([FromBody] PaymentBindingModels Payment)
        {
            try
            {
                //In case POST send with no data
                if (Payment == null)
                {
                    throw new Exception("No data provided");
                }

                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }


                using (ApplicationDbContext entities = new ApplicationDbContext())
                {
                    //Retrieve Authenticated User
                    var AuthenticatedUser = entities.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

                    if (AuthenticatedUser == null)
                    {
                        throw new Exception("Unable to retrieve authenticated user");
                    }


                    //Request Bank Payment
                    BankApi           objBank     = new BankApi();
                    BankResponseModel objresponse = await objBank.MakeBankPayment(Payment);


                    PaymentModel PayModel = new PaymentModel()
                    {
                        CardHolderName = Payment.CardHolderName,
                        CardNumber     = Payment.GetMaskCardNumber(),
                        Amount         = Payment.Amount,
                        Currency       = Payment.Currency.ToUpper(),
                        AuthUser       = AuthenticatedUser,
                        CardExpDate    = Payment.CardExpDate,
                        Cvv            = Payment.Cvv,
                        RequestDate    = DateTime.Now,
                        BankIdentifer  = objresponse.Identifier,
                        BankStatus     = objresponse.Status
                    };

                    //Save Payment
                    entities.Payments.Add(PayModel);
                    entities.SaveChanges();

                    if (objresponse.Status != "OK")
                    {
                        throw new Exception("Error processing payment with bank");
                    }

                    var objPayResponse = new
                    {
                        status = "OK",
                        PaymentBankIdentifer = PayModel.BankIdentifer,
                        GetPayment           = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/api/Payment/" + PayModel.Id
                    };

                    var messsage = Request.CreateResponse(HttpStatusCode.Created, objPayResponse);

                    return(messsage);
                }
            }
            catch (Exception ex)
            {
                using (var scope = DI.DI.Container.BeginLifetimeScope())
                {
                    var obj = scope.Resolve <ILoggerInterface>();
                    //Logger error Message
                    obj.LogMessage("PaymentsController.Post", ex.Message);
                }

                ErrorResponseModel objResponse = new ErrorResponseModel()
                {
                    Status = "ERROR", Message = ex.Message
                };
                return(Request.CreateResponse(HttpStatusCode.BadRequest, objResponse));
            }
        }
        public static IConnectedBanksService BuildUpdateBankAsyncConnectedBanksServiceMock(BankResponseModel expectedBank)
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(JsonConvert.SerializeObject(expectedBank), Encoding.UTF8, "application/json");

            var requestSenderMock          = new Mock <IHttpRequestSender>();
            IConnectedBanksService service = new ConnectedBanksService(requestSenderMock.Object);

            requestSenderMock
            .Setup(x => x.PatchAsync(It.IsAny <string>(), It.IsAny <StringContent>()))
            .ReturnsAsync(response);

            return(service);
        }