Diin Diin - 1 year ago 107
SQL Question

Using Hangfire for automatic payment processing

I have just discovered hangfire. I have successfully installed the mysql storage version. I want to use this in the following scenario:
Everyday at 12:01 am it should trigger an ASP.NET MVC5 with OWIN and EF application controller action that checks database and select payment references due to be processed on the date in question. This action ends by presenting an api url to the payment processing provider. My Question is if my action is called "ProcessPayments" How do I set hangfire to repeat this process everyday. Thanks for any help.

Answer Source

Just in case someone needs a start up push like myself when I asked this question. Using Hangfire Mysql Storage,Identity 2, ASP.NET, MVC5, EF, C# you could create an action in your controller like below to add a recurrent job for the process.

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();

Then you create your method or logic for the payment.

 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     

Hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download