public Reimbursement(CrashEvent e, string cart) { cart_id = cart; hsmv_report_number = e.hsmv_report_number; timely = true; reimbursement_amount = 500; // reimbursement amount in us cents reporting_agency = e.reporting_agency; }
///<Note> // receives order info // formats purchase and reimbursements // issues download tokens for successful purchase ///</Note> public Task HandleTransaction(PurchaseRequest order) { Purchase po = FormatNewPurchase(order); // creates a purchase object var charge = _stripe.CreateCharge(order); // create Stripe charge po.stripe_charge_token = charge.Id; // add charge token to purchase po.charge_token_result = charge.Status; // add charge outcome to purchase if (charge.Status == "succeeded") { List <string> purchased = new List <string>(); // empty list will hold download tokens for purchase var cart = _cart.GetContent(order.cart_id); // pull the item-list from order foreach (var c in cart) { string hsmv_token = String.Empty; // holds the formated download token CrashEvent hsmv_report = _crash.FindByHsmvReportNumber(c.hsmv_report_number); // pull report // if(hsmv_report.timely) // TODO if report is timely // { // Reimbursement funds = FormatReimbursement(hsmv_report, po.cart_id); // create Stripe transfer // } string token = new DownloadToken( po.cart_id, hsmv_report.hsmv_report_number.ToString(), po.stripe_charge_token).Mint(); hsmv_token += hsmv_report.hsmv_report_number.ToString() + "." + token; // concatenate report number to the token purchased.Add(hsmv_token); } if (!LogTransaction(po)) // saves our purchase object { var error = "error writing purchase details"; throw new Exception(nameof(error)); } ; return(Task.FromResult(purchased)); // return download tokens } else // path is hit if the Stripe charge fails (ie insufficient funds) { if (!LogTransaction(po)) // save the attempted purchase { var fail = "error writing purchase details"; throw new Exception(nameof(fail)); } var failure = new StandardResponse() // return the failure message to the client { message = charge.FailureMessage }; return(Task.FromResult(failure)); } }
///<Note> TODO // create a stripe transfer to reimburse the reporting agency // create a reimbursement object (holding transfer token) to save for s4 records ///</Note> private Reimbursement FormatReimbursement(CrashEvent crash_report, string cart_id) { var funds = new Reimbursement(crash_report, cart_id); // review order contents var accident = new { occured = crash_report.crash_date_and_time, reported = crash_report.hsmv_entry_date }; if (isWithinDateRange(accident.occured, accident.reported, 10)) { // adjsut fund allocation funds.reimbursement_amount += 5; funds.timely = true; } if (!LogReimbursement(funds)) { var error = "error writing reimbursement details"; throw new Exception(nameof(error)); } ; return(funds); }