A client requested that we send a google event when a customer hits the thank you page after payment is successful.
They want to send the email and other orderdata to the datalayer.|
We are using Molly as a payment provider.
I searched the documentation but I can’t find how I can get the orderdata on the page.
Any pointers?
1 Like
Do you have control over how the thank you page url is constructed? If you do, you could add a query string parameter with the order ID in it, then you could refetch the order again.
Something very rough and ready
public class ThankYouPageController : RenderController
{
private readonly ILogger<ThankYouPageController> _logger;
private readonly IOrderService _orderService;
private readonly IPublishedValueFallback _publishedValueFallback;
private readonly IUmbracoMapper _mapper;
private readonly IMemberManager _memberManager;
public ThankYouPageController(
ILogger<ThankYouPageController> logger,
IPublishedValueFallback publishedValueFallback,
IOrderService orderService,
IUmbracoMapper umbracoMapper,
IMemberManager memberManager,
ICompositeViewEngine compositeViewEngine,
IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine, umbracoContextAccessor)
{
_logger = logger;
_orderService = orderService;
_mapper = umbracoMapper;
_memberManager = memberManager;
_publishedValueFallback = publishedValueFallback;
}
public override IActionResult Index()
{
var vm = new ThankYouPageViewModel(CurrentPage, _publishedValueFallback);
try
{
HttpContext.Request.Query.TryGetValue("id", out StringValues orderReference);
if (string.IsNullOrEmpty(orderReference))
{
return Redirect(CurrentPage.Parent.Url());
}
var store = CurrentPage.GetStore();
var order = _orderService.GetOrder(store.Id, orderReference);
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
}
return CurrentTemplate(vm);
}
}
You can call umbracoCommerceApi.GetCurrentFinalizedOrder(storeId)
to get the order that was just finalized.
Checkout the getting started tutorial example here (this is using v15’s async API’s however) Creating a Custom Checkout Flow | Umbraco Commerce