forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckOutController.cs
82 lines (68 loc) · 2.36 KB
/
CheckOutController.cs
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
72
73
74
75
76
77
78
79
80
81
82
namespace ContosoFlowers.Controllers
{
using System;
using System.Threading.Tasks;
using System.Web.Mvc;
using Microsoft.Bot.Builder.ConnectorEx;
using Microsoft.Bot.Builder.Dialogs;
using Services;
using Services.Models;
[RoutePrefix("CheckOut")]
[RequireHttps]
public class CheckOutController : Controller
{
private readonly IOrdersService ordersService;
public CheckOutController(IOrdersService ordersService)
{
this.ordersService = ordersService;
}
[Route("")]
[HttpGet]
public ActionResult Index(string state, string orderId)
{
var order = this.ordersService.RetrieveOrder(orderId);
// Check order exists
if (order == null)
{
throw new ArgumentException("Order Id not found", "orderId");
}
// Check order if order is already processed
if (order.Payed)
{
return this.RedirectToAction("Completed", new { orderId = orderId });
}
// Payment form
this.ViewBag.State = state;
return this.View(order);
}
[Route("")]
[HttpPost]
public async Task<ActionResult> Index(
string botId,
string channelId,
string conversationId,
string serviceUrl,
string userId,
string orderId,
PaymentDetails paymentDetails)
{
this.ordersService.ConfirmOrder(orderId, paymentDetails);
var address = new Address(botId, channelId, userId, conversationId, serviceUrl);
var conversationReference = address.ToConversationReference();
var message = conversationReference.GetPostToBotMessage();
message.Text = orderId;
await Conversation.ResumeAsync(conversationReference, message);
return this.RedirectToAction("Completed", new { orderId = orderId });
}
[Route("completed")]
public ActionResult Completed(string orderId)
{
var order = this.ordersService.RetrieveOrder(orderId);
if (order == null)
{
throw new ArgumentException("Order Id not found", "orderId");
}
return this.View("Completed", order);
}
}
}