/// <summary> /// 获取支付时使用的Html /// 交易不存在等错误发生时返回错误信息 /// </summary> public virtual HtmlString GetPaymentHtml(long transactionId) { // 获取交易和支付接口 PaymentTransaction transaction = null; PaymentApi api = null; UnitOfWork.ReadData <PaymentTransaction>(r => { transaction = r.GetById(transactionId); api = transaction == null ? null : transaction.Api; var _ = api == null ? null : api.Type; // 在数据库连接关闭前抓取类型 }); // 检查交易和接口是否存在 if (transaction == null) { return(BuildErrorHtml(new T("Payment transaction not found"))); } else if (api == null) { return(BuildErrorHtml(new T("Payment api not exist"))); } // 检查当前登录用户是否可以支付 var result = transaction.Check(c => c.IsPayerLoggedIn); if (!result.First) { return(BuildErrorHtml(result.Second)); } result = transaction.Check(c => c.IsPayable); if (!result.First) { return(BuildErrorHtml(result.Second)); } // 调用接口处理器生成支付html var html = new HtmlString("No Result"); var handlers = api.GetHandlers(); handlers.ForEach(h => h.GetPaymentHtml(transaction, ref html)); return(html); }