【问题标题】:Using Hangfire for automatic payment processing使用 Hangfire 进行自动支付处理
【发布时间】:2016-04-30 22:05:51
【问题描述】:
我刚刚发现了hangfire。我已经成功安装了mysql存储版本。我想在以下场景中使用它:
每天凌晨 12:01,它应该触发一个带有 OWIN 和 EF 应用程序控制器操作的 ASP.NET MVC5,该操作检查数据库并选择要在相关日期处理的付款参考。此操作通过向支付处理提供商提供一个 api url 结束。我的问题是如果我的操作被称为“ProcessPayments”我如何设置hangfire 每天重复这个过程。感谢您的帮助。
【问题讨论】:
标签:
mysql
asp.net-mvc
entity-framework
owin
hangfire
【解决方案1】:
以防万一有人在我问这个问题时需要像我这样的启动推动。使用 Hangfire Mysql Storage、Identity 2、ASP.NET、MVC5、EF、C#,您可以在控制器中创建一个操作,如下所示,为该流程添加一个循环作业。
public ActionResult PDPayment(int id)
{
string cronExp = "1 12 * * *";
using (ApplicationDbContext db = new ApplicationDbContext())
{
var a = db.DDs.SingleOrDefault(a => a.DDId==id);
RecurringJob.AddOrUpdate(a.id+"-"+a.DDId+"_job", () => ProcessPayments(id), cronExp);
return new EmptyResult();
}
}
然后您创建付款方式或逻辑。
public static void ProcessPayments(int id)
{
eg fetch records with id
create invoice
process invoice- payment
update records of payment
send email
redirect to success or failed page
}