Got a client request to return some third party API data to a customer's order and display it on the payment successful page but I'm running into deadlock issues whilst trying to save said data.
A breakdown of the setup:
User goes through checkout
User gets sent to the third party payment provider
The payment callback URL is triggered and the order is updated accordingly. However, if the payment is successful the customer is also sent to the payment successful page where the further updates to the order are made.
Example of the method called during the ProcessCallback method:
private static CallbackResult ProcessPaymentProviderCallback(OrderReadOnly order)
{
var client = new VivaWalletClient();
var vivaWalletOrder = client.RetrieveOrder(int.Parse(order.Properties["vivaWalletOrderCode"]));
var paymentState = (VivaWalletState) vivaWalletOrder.StateId;
switch (paymentState)
{
case VivaWalletState.Pending:
case VivaWalletState.Expired:
case VivaWalletState.Cancelled:
return CallbackResult.Ok();
case VivaWalletState.Paid:
return new CallbackResult
{
TransactionInfo = new TransactionInfo
{
AmountAuthorized = order.TransactionAmount.Value,
TransactionFee = 0,
TransactionId = order.Properties["vivaWalletTransactionId"],
PaymentStatus = PaymentStatus.Captured
}
};
default:
throw new ArgumentOutOfRangeException();
}
}
Example of the method called in the PaymentSuccessfulPageController, this is the one that gets sacrificed to the deadlock gods:
private void ProcessEcologi(OrderReadOnly order)
{
try
{
if (order.Properties.ContainsKey(OrderConstants.TreesPlanted) &&
!order.Properties[OrderConstants.TreesPlanted].Value.IsNullOrEmpty())
{
return;
}
var client = new EcologiClient();
var purchaseTreesResponse =
client.PurchaseTrees($"{order.CustomerInfo.FirstName} {order.CustomerInfo.LastName}", 2); // TODO
using (var unitOfWork = _vendrApi.Uow.Create())
{
var writableOrder = order.AsWritable(unitOfWork)
.SetProperties(new Dictionary<string, string>
{
{OrderConstants.TreesPlanted, 2.ToString()}, // TODO
{OrderConstants.TreesUrl, purchaseTreesResponse.TreeUrl},
{OrderConstants.ContributionUrl, ""} // TODO
});
_vendrApi.SaveOrder(writableOrder);
unitOfWork.Complete();
}
}
catch (Exception e)
{
_logger.Error<PaymentSuccessfulPageController>(e);
}
}
From face value, I'd imagine because of the callback response finalizing the order and doing it's magic that trying to manipulate the order further at this stage isn't the best idea.
Unfortunately, I can't move the logic from the PaymentSuccessfulPageController to the Callback action as I need the data as soon as the page has loaded. Any ideas?
Deadlock issue when making order updates
Got a client request to return some third party API data to a customer's order and display it on the payment successful page but I'm running into deadlock issues whilst trying to save said data.
A breakdown of the setup:
Example of the method called during the ProcessCallback method:
Example of the method called in the PaymentSuccessfulPageController, this is the one that gets sacrificed to the deadlock gods:
From face value, I'd imagine because of the callback response finalizing the order and doing it's magic that trying to manipulate the order further at this stage isn't the best idea.
Unfortunately, I can't move the logic from the PaymentSuccessfulPageController to the Callback action as I need the data as soon as the page has loaded. Any ideas?
Hi Ryan,
Are you able to identify what statements are deadlocking? And any deadlock debugging information so we can try and work out why it would deadlock?
There are some good debugging tips if you google for them but any detailed info you can provide the more we have to look into / try and replicate.
is working on a reply...