Exemplo n.º 1
0
        public ActionResult <MidTransTransactionResponseModel> Charge([FromBody] MidTransChargeInputModel data)
        {
            MidTransBL bl = new MidTransBL(DbContext, AppSettings);

            var dat = bl.TransactionMidTrans(data);

            MidTransTransactionResponseModel res = new MidTransTransactionResponseModel();

            res = dat;
            return(res);
        }
Exemplo n.º 2
0
        public ActionResult ProceedPayment(string bookID, double hargaAmt, double discAmt, double totalAmt, double payAmt)
        {
            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                MidTransTransactionResponseModel OutPutData = null;
                MidTransChargeInputModel         filter     = new MidTransChargeInputModel();
                PurchaseOutputModel OutPutPurch             = null;
                PurchaseInputModel  inputPurch = new PurchaseInputModel();
                inputPurch.SubTotal   = hargaAmt;
                inputPurch.Diskon     = discAmt;
                inputPurch.GrandTotal = totalAmt;
                inputPurch.UangMuka   = payAmt;
                inputPurch.UserID     = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                inputPurch.BookID     = new string[1];
                inputPurch.BookID[0]  = bookID;
                using (var clientPurch = new HttpClient())
                {
                    clientPurch.BaseAddress = new Uri(BaseAPI + "MediaBuyer/");
                    var responseTaskPurch = clientPurch.PostAsJsonAsync <PurchaseInputModel>("ProcessToPurchase", inputPurch);
                    responseTaskPurch.Wait();

                    var resultPurch = responseTaskPurch.Result;
                    if (resultPurch.IsSuccessStatusCode)
                    {
                        var contentPurch = resultPurch.Content.ReadAsStringAsync();
                        PurchaseResponseModel resutlPurch = Newtonsoft.Json.JsonConvert.DeserializeObject <PurchaseResponseModel>(contentPurch.Result);
                        OutPutPurch = resutlPurch.data;
                        if (OutPutPurch != null)
                        {
                            filter.customer_details = new CustomerDetails();
                            filter.customer_details.billing_address  = new BillingAddress();
                            filter.customer_details.shipping_address = new ShippingAddress();
                            filter.transaction_details              = new TransactionDetails();
                            filter.transaction_details.currency     = "IDR";
                            filter.transaction_details.order_id     = OutPutPurch.InvoiceNo;
                            filter.transaction_details.gross_amount = payAmt;
                            filter.user_id = HttpContext.Session.GetString(SessionKeyID);
                            using (var client = new HttpClient())
                            {
                                client.BaseAddress = new Uri(BaseAPI.Replace("api/", ""));
                                var responseTask = client.PostAsJsonAsync <MidTransChargeInputModel>("charge", filter);
                                responseTask.Wait();

                                var result = responseTask.Result;
                                if (result.IsSuccessStatusCode)
                                {
                                    var content = result.Content.ReadAsStringAsync();
                                    MidTransTransactionResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <MidTransTransactionResponseModel>(content.Result);
                                    OutPutData = resutl;
                                }
                                else                                 //web api sent error response
                                {
                                    //log response status here..
                                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                                }
                            }
                        }
                    }
                    else                     //web api sent error response
                    {
                        //log response status here..
                        ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                    }
                }

                return(Json(OutPutData));
            }
            else
            {
                TempData["CustomError"] = "Please login before using the web.";
                if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV")
                {
                    return(RedirectToAction("AdminLogon", "Login"));
                }
                else if (HttpContext.Session.GetString(Loginfrom) == "MDO")
                {
                    return(RedirectToAction("OwnerLogon", "Login"));
                }
                else
                {
                    return(RedirectToAction("BuyerLogon", "Login"));
                }
                //return RedirectToAction("Logon", "Login");
            }
        }