-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMessageSenderController.cs
More file actions
70 lines (62 loc) · 3.56 KB
/
MessageSenderController.cs
File metadata and controls
70 lines (62 loc) · 3.56 KB
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
using OrderCloud.Catalyst;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Customer.OrderCloud.Common.Models;
using Customer.OrderCloud.Common.Commands;
namespace Customer.OrderCloud.Api.Controllers
{
// **************************************************************************************
// All routes are hit from special OrderCloud webhooks called "Message Senders".
// Create a Message sender config object in OrderCloud. https://ordercloud.io/api-reference/seller/message-senders/create
// Set MessageSender.SharedKey to match settings.OrderCloudSettings.WebhookHashKey in this project
// Set MessageSender.Url to "$baseUrl$/api/messagesender/{messagetype}" (include bracket literal characters) to match routes in this file
// Set MessageSender.MessageTypes to the types you want to use (routes below)
// Set MessageSender.xp to any json data you want included in the payload.ConfigData property for all routes
// See guide on message senders https://ordercloud.io/knowledge-base/message-senders
// **************************************************************************************
[Route("api/messagesender")]
public class MessageSenderController : CatalystController
{
private readonly ISendEmailCommand _command;
public MessageSenderController(ISendEmailCommand command)
{
_command = command;
}
// These message sender types share payloads and default template data fields. They should have unqiue templates. They can be split into separate actions as needed.
[HttpPost,
Route("NewUserInvitation"),
Route("ForgottenPassword")]
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task NewUserInvitation([FromBody] SetPasswordMessageSenderPayloadWithXp payload)
=> await _command.SendSetPasswordEmail(payload);
//These message sender types share payloads and default template data fields.They should have unqiue templates.They can be split into separate actions as needed.
[HttpPost,
Route("OrderSubmitted"),
Route("OrderSubmittedForApproval"),
Route("OrderApproved"),
Route("OrderDeclined"),
Route("OrderSubmittedForYourApproval"),
Route("OrderSubmittedForYourApprovalHasBeenApproved"),
Route("OrderSubmittedForYourApprovalHasBeenDeclined")]
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task OrderSubmitted([FromBody] OrderMessageSenderPayloadWithXp payload)
=> await _command.SendOrderEmail(payload);
[HttpPost, Route("ShipmentCreated")]
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task ShipmentCreated([FromBody] ShipmentCreatedMessageSenderPayloadWithXp payload)
=> await _command.SendShipmentCreatedEmail(payload);
//These message sender types share payloads and default template data fields.They should have unqiue templates.They can be split into separate actions as needed.
[HttpPost,
Route("OrderReturnSubmitted"),
Route("OrderReturnSubmittedForApproval"),
Route("OrderReturnApproved"),
Route("OrderReturnDeclined"),
Route("OrderReturnSubmittedForYourApproval"),
Route("OrderReturnSubmittedForYourApprovalHasBeenApproved"),
Route("OrderReturnSubmittedForYourApprovalHasBeenDeclined"),
Route("OrderReturnCompleted")]
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task OrderReturnSubmitted([FromBody] OrderReturnMessageSenderPayloadWithXp payload)
=> await _command.SendOrderReturnEmail(payload);
}
}