public async Task <ActionResult> Update(int id, [FromBody] BillViewModel model) { // BeginPay 支付帳單 var existingBill = _billsService.GetById(id); if (existingBill == null) { return(NotFound()); } int paywayId = model.PayWayId; var payway = _paysService.GetPayWayById(paywayId); if (payway == null) { throw new EntityNotFoundException(new PayWay { Id = paywayId }); } if (existingBill.Payed) { ModelState.AddModelError("payed", "此訂單已經支付過了"); return(BadRequest(ModelState)); } if (existingBill.Expired) { ModelState.AddModelError("expired", "訂單已過繳款期限"); return(BadRequest(ModelState)); } var pay = Pay.Create(existingBill, payway, ThirdPartyPayment.EcPay); var amount = Convert.ToInt32(existingBill.NeedPayMoney); var ecPayTradeModel = _thirdPartyPayService.CreateEcPayTrade(pay, amount); if (!ecPayTradeModel.HasToken) { ModelState.AddModelError("", "開啟支付程序失敗,請稍候再試."); return(BadRequest(ModelState)); } await _paysService.CreateAsync(pay); if (existingBill.PayWayId != paywayId) { existingBill.PayWayId = paywayId; await _billsService.UpdateAsync(existingBill); } ecPayTradeModel.PaymentType = payway.Code; return(Ok(ecPayTradeModel)); }
private void AddData(int mID, int oID, decimal summ) { var tempPay = new Pay(_connectionSettings, mID, oID, summ); Pays.Add(tempPay.ToString(), tempPay); PayPanels.Add(tempPay.ToString(), tempPay.Create()); tempPay.Button.Click += (o, args) => { if (tempPay.Delete(Id)) { PayList.Items.Remove(PayPanels[tempPay.ToString()]); PayPanels.Remove(tempPay.ToString()); Pays.Remove(tempPay.ToString()); } }; tempPay.Button.Visibility = type == OpenType.View ? Visibility.Collapsed : Visibility.Visible; PayList.Items.Add(PayPanels[tempPay.ToString()]); SummField.Text = (Convert.ToDecimal( Extensions.PrepareStringToConvert(string.IsNullOrEmpty(SummField.Text) ? "0" : SummField.Text)) + summ).ToString(); }
public async Task <EcPayTradeModel> BeginPayAsync(int billId, BillViewModel model, string userId) { // BeginPay 支付帳單 var existingBill = _billsService.GetById(billId); if (existingBill == null) { return(null); } int paywayId = model.PayWayId; var payway = _paysService.GetPayWayById(paywayId); if (payway == null) { throw new EntityNotFoundException(new PayWay { Id = paywayId }); } if (existingBill.Payed) { throw new BadRequestException(new RequestErrorViewModel { Key = "payed", Message = "此訂單已經支付過了" }); } if (existingBill.Expired) { throw new BadRequestException(new RequestErrorViewModel { Key = "expired", Message = "訂單已過繳款期限" }); } var pay = Pay.Create(existingBill, payway, ThirdPartyPayment.EcPay); var amount = Convert.ToInt32(existingBill.NeedPayMoney); var ecPayTradeModel = _thirdPartyPayService.CreateEcPayTrade(pay, amount); if (!ecPayTradeModel.HasToken) { throw new BadRequestException(new RequestErrorViewModel { Key = "", Message = "開啟支付程序失敗,請稍候再試." }); } await _paysService.CreateAsync(pay); if (existingBill.PayWayId != paywayId) { existingBill.PayWayId = paywayId; await _billsService.UpdateAsync(existingBill); } ecPayTradeModel.PaymentType = payway.Code; return(ecPayTradeModel); }