Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

CheckOutController.cs 2.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  1. namespace ContosoFlowers.Controllers
  2. {
  3. using System;
  4. using System.Threading.Tasks;
  5. using System.Web.Mvc;
  6. using Microsoft.Bot.Builder.Dialogs;
  7. using Services;
  8. using Services.Models;
  9. [RoutePrefix("CheckOut")]
  10. [RequireHttps]
  11. public class CheckOutController : Controller
  12. {
  13. private readonly IOrdersService ordersService;
  14. public CheckOutController(IOrdersService ordersService)
  15. {
  16. this.ordersService = ordersService;
  17. }
  18. [Route("")]
  19. [HttpGet]
  20. public ActionResult Index(string state, string orderId)
  21. {
  22. var order = this.ordersService.RetrieveOrder(orderId);
  23. // Check order exists
  24. if (order == null)
  25. {
  26. throw new ArgumentException("Order Id not found", "orderId");
  27. }
  28. // Check order if order is already processed
  29. if (order.Payed)
  30. {
  31. return this.RedirectToAction("Completed", new { orderId = orderId });
  32. }
  33. // Payment form
  34. this.ViewBag.State = state;
  35. return this.View(order);
  36. }
  37. [Route("")]
  38. [HttpPost]
  39. public async Task<ActionResult> Index(string state, string orderId, PaymentDetails paymentDetails)
  40. {
  41. this.ordersService.ConfirmOrder(orderId, paymentDetails);
  42. // Send Receipt
  43. var resumptionCookie = ResumptionCookie.GZipDeserialize(state);
  44. var message = resumptionCookie.GetMessage();
  45. message.Text = orderId;
  46. await Conversation.ResumeAsync(resumptionCookie, message);
  47. return this.RedirectToAction("Completed", new { orderId = orderId });
  48. }
  49. [Route("completed")]
  50. public ActionResult Completed(string orderId)
  51. {
  52. var order = this.ordersService.RetrieveOrder(orderId);
  53. if (order == null)
  54. {
  55. throw new ArgumentException("Order Id not found", "orderId");
  56. }
  57. return this.View("Completed", order);
  58. }
  59. }
  60. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...