public ActionResult Invoice_chk(InvoiceOrderViewModel orderForm) { InvoicePurchaseModel invoiceCheck = new InvoicePurchaseModel(); invoiceCheck.mainProdName = orderForm.mainProdName; invoiceCheck.shopname = orderForm.shopname; invoiceCheck.addr = orderForm.addr; invoiceCheck.contactname = orderForm.contactname; invoiceCheck.contacttel = orderForm.contacttel; invoiceCheck.orderDetail = new List <OrderDetailModel>(); for (int i = 0; i < orderForm.prodType.Length; i++) { if ((orderForm.qty[i] ?? 0) > 0) { OrderDetailModel orderDetail = new OrderDetailModel(); orderDetail.prodType = orderForm.prodType[i]; orderDetail.prodName = orderForm.prodName[i]; orderDetail.prodPrice = orderForm.prodPrice[i] ?? 0; orderDetail.qty = orderForm.qty[i] ?? 0; orderDetail.freightRate = 0; if (orderDetail.prodType == "熱感紙" && orderForm.Islands == "Y") { orderDetail.freightRate = 200 * orderDetail.qty; } orderDetail.subtotal += orderDetail.prodPrice * orderDetail.qty + orderDetail.freightRate; invoiceCheck.total += orderDetail.subtotal; invoiceCheck.orderDetail.Add(orderDetail); } } return(View(invoiceCheck)); }
public async Task <IHttpActionResult> UpdatePaymentGate(InvoiceOrderViewModel data) { try { if (data.PaymentType == null) { return(BadRequest(this.General_Err)); } var order = await _uow.Invoice.GetForPayment(data.Code, this.CurrentUserId); if (order == null) { return(BadRequest(this.General_Err)); } if (data.PaymentType == (int)PaymentType.ATM || data.PaymentType == (int)PaymentType.CreditCard) { order.IsCreditCard = (data.PaymentType == (int)PaymentType.CreditCard); var res = PaymentWithZaloPay(order); return(Ok(res)); } else if (data.PaymentType == (int)PaymentType.QRCode) { var res = PaymentWithZaloPayQR(order); return(Ok(res)); } return(BadRequest(this.General_Err)); } catch (BusinessException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { _log.Error(ex); return(BadRequest(this.General_Err)); } }
private string PaymentWithZaloPay(InvoiceOrderViewModel order) { try { string clientIP = this.ClientIP; string desc = "Gói " + order.ServiceName + " - Số tiền: " + ((long)order.Amount).ToString(); string appTransId = $"{DateTime.Now.ToString("yyMMddHHmmss")}-{order.Code}"; string bankCode = order.IsCreditCard ? "CC" : ""; string phone = ""; var resp = new ZalopayPaygateService().CreateOrderURL(order.UserId, (long)order.Amount, appTransId, bankCode, desc, phone); if (resp != null) { _uow.ZaloPayTransaction.IU(new Core.Entities.Model.ZaloPayTransaction { InvoiceId = order.Id, UserId = order.UserId, InvoiceCode = order.Code, Amount = order.Amount, AppTransId = appTransId, TransDesc = desc, BankCode = bankCode, PayGateTransId = string.Empty, PayGateChannel = 0, IsCreditCard = order.IsCreditCard, ClientIP = clientIP }); } return(resp); }catch (Exception ex) { _log.Error(ex); return(null); } }
private Dictionary <string, object> PaymentWithZaloPayQR(InvoiceOrderViewModel order) { try { string clientIP = this.ClientIP; string desc = string.Format("Mua dịch vụ {0} - Số tiền {1}", order.ServiceName, order.Amount); string appTransId = $"{DateTime.Now.ToString("yyMMddHHmmss")}-{order.Code}"; string bankCode = "QRCode"; var res = new ZalopayPaygateService().CreateOrderQR("", (long)order.Amount, appTransId, "{}", order.ServiceName, desc); if (res != null) { _uow.ZaloPayTransaction.IU(new Core.Entities.Model.ZaloPayTransaction { InvoiceId = order.Id, UserId = order.UserId, InvoiceCode = order.Code, Amount = order.Amount, AppTransId = appTransId, TransDesc = desc, BankCode = bankCode, PayGateTransId = string.Empty, PayGateChannel = 0, IsCreditCard = false, ClientIP = clientIP }); } res.Add("appTransId", appTransId); return(res); }catch (Exception ex) { _log.Error(ex); return(null); } }