-
Notifications
You must be signed in to change notification settings - Fork 14
/
IntegrationEventController.cs
111 lines (94 loc) · 6.82 KB
/
IntegrationEventController.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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 "Integration Events".
// Create an IntegrationEvent config object in OrderCloud for each event type (AddToCart, OrderCheckout, OrderReturn, OpenIdConnect) you wish to use.
// See https://ordercloud.io/api-reference/seller/integration-events/create
// For all config objects, set IntegrationEvent.HashKey to match match settings.OrderCloudSettings.WebhookHashKey.
// **************************************************************************************
[Route("api/integrationevent")]
public class IntegrationEventController : CatalystController
{
private readonly IAddToCartEventCommand _addToCartCommand;
private readonly IOpenIdConnectCommand _openIdConnectCommand;
private readonly IOrderReturnCommand _orderReturnCommand;
private readonly ICheckoutCommand _checkoutCommand;
public IntegrationEventController(
IAddToCartEventCommand addToCartCommand,
IOpenIdConnectCommand openIdConnectCommand,
IOrderReturnCommand orderReturnCommand,
ICheckoutCommand checkoutCommand
)
{
_addToCartCommand = addToCartCommand;
_openIdConnectCommand = openIdConnectCommand;
_orderReturnCommand = orderReturnCommand;
_checkoutCommand = checkoutCommand;
}
// **************************************************************************************
// * EventType - "AddToCard"
// * CustomImplementationUrl - "{baseUrl}/api/integrationevent/addtocart"
// * For integrating an external product catalog with ordercloud cart and fulfillment.
// * See https://ordercloud.io/knowledge-base/ad-hoc-products
// **************************************************************************************
[HttpPost, Route("addtocart")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<AddToCartResponseWithXp> GetProductWithUnitPriceAsync([FromBody] AddToCartIEPayloadWithXp payload) =>
await _addToCartCommand.GetProductWithUnitPriceAsync(payload);
// **************************************************************************************
// * EventType - "OpenIDConnect"
// * CustomImplementationUrl - "{baseUrl}/api/integrationevent/openidconnect"
// * For single sign on integrations where users need to be synced into OrderCloud from an identity provider
// * See https://ordercloud.io/knowledge-base/sso-via-openid-connect
// **************************************************************************************
[HttpPost, Route("openidconnect/createuser")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OpenIdConnectCreateUserResponse> CreateUserFromSSOAsync([FromBody] OpenIDConnectIEPayloadWithXp payload) =>
await _openIdConnectCommand.CreateUserFromSSOAsync(payload);
[HttpPost, Route("openidconnect/syncuser")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OpenIdConnectSyncUserResponse> UpdateUserFromSSOAsync([FromBody] OpenIDConnectIEPayloadWithXp payload) =>
await _openIdConnectCommand.UpdateUserFromSSOAsync(payload);
// **************************************************************************************
// * EventType - "OrderReturn"
// * CustomImplementationUrl - "{baseUrl}/api/integrationevent/orderreturn"
// * For custom calculation of refund amounts on order returns
// * See https://ordercloud.io/knowledge-base/order-returns
// **************************************************************************************
[HttpPost, Route("orderreturn/calculateorderreturn")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OrderReturnResponse> CalculateOrderReturnRefundAsync([FromBody] OrderReturnIEPayloadWithXp payload) =>
await _orderReturnCommand.CalculateOrderReturnRefundAsync(payload);
// **************************************************************************************
// * EventType - "OrderCheckout"
// * CustomImplementationUrl - "{baseUrl}/api/integrationevent/ordercheckout"
// * For all checkout integrations like shipping, tax, payment, email confirmation, order forwarding
// * See https://ordercloud.io/knowledge-base/order-checkout-integration
// **************************************************************************************
[HttpPost, Route("ordercheckout/shippingrates")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<ShipEstimateResponseWithXp> EstimateShippingCostsAsync([FromBody] OrderCheckoutIEPayloadWithXp payload) =>
await _checkoutCommand.EstimateShippingCostsAsync(payload);
[HttpPost, Route("ordercheckout/ordercalculate")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OrderCalculateResponseWithXp> RecalculatePricesAndTaxAsync([FromBody] OrderCheckoutIEPayloadWithXp payload) =>
await _checkoutCommand.RecalculatePricesAndTaxAsync(payload);
[HttpPost, Route("ordercheckout/ordersubmit")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OrderSubmitResponseWithXp> PostSubmitProcessingAsync([FromBody] OrderCheckoutIEPayloadWithXp payload) =>
await _checkoutCommand.ProcessOrderPostSubmitAsync(payload);
[HttpPost, Route("ordercheckout/orderapproved")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OrderApprovedResponseWithXp> PostApprovalProcessingAsync([FromBody] OrderCheckoutIEPayloadWithXp payload) =>
await _checkoutCommand.ProcessOrderPostApprovalAsync(payload);
[HttpPost, Route("ordercheckout/ordersubmitforapproval")] // route and method specified by OrderCloud platform
[OrderCloudWebhookAuth] // Security feature to verifiy request came from Ordercloud.
public async Task<OrderSubmitForApprovalResponseWithXp> PostSubmitForApprovalProcessingAsync([FromBody] OrderCheckoutIEPayloadWithXp payload) =>
await _checkoutCommand.ProcessOrderPostSubmitForApprovalAsync(payload);
}
}