Skip to content

Commit

Permalink
Fixed callback-related data (adyen webhooks handling).
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavSmetaninSSM committed Jul 3, 2024
1 parent d5d7540 commit 5383358
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/AdyenCheckoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,13 @@ public override OutputResult HandleRequest(Order order)
{
try
{
string jsonData;
using (var inputStream = new StreamReader(Context.Current.Request.InputStream))
string jsonData = (string)Context.Current.Items["AdyenCallback"];
if (string.IsNullOrEmpty(jsonData))
{
jsonData = inputStream.ReadToEnd();
using (var inputStream = new StreamReader(Context.Current.Request.InputStream))
{
jsonData = inputStream.ReadToEndAsync().GetAwaiter().GetResult();
}
}

Callback(order, jsonData);
Expand Down Expand Up @@ -675,6 +678,8 @@ private void Callback(Order order, string jsonData)
private void HandleNotificationItem(Order order, NotificationRequestItem notificationItem)
{
NotificationEventCode? eventCode = notificationItem.GetNotificationEventCode();
bool isSuccess = Converter.ToBoolean(notificationItem.Success);

switch (eventCode)
{
case NotificationEventCode.Authorisation:
Expand Down Expand Up @@ -702,7 +707,7 @@ private void HandleNotificationItem(Order order, NotificationRequestItem notific

void Authorisation()
{
if (notificationItem.Success)
if (isSuccess)
{
if (!order.Complete)
{
Expand All @@ -729,7 +734,7 @@ void Authorisation()

void Capture()
{
if (eventCode is NotificationEventCode.Capture && notificationItem.Success)
if (eventCode is NotificationEventCode.Capture && isSuccess)
{
UpdateTransactionNumber(order, notificationItem.PspReference);
order.TransactionAmount = notificationItem.Amount.Value.Value / 100d;
Expand All @@ -754,7 +759,7 @@ void Capture()
void Cancellation()
{
order.TransactionAmount = 0;
if (notificationItem.Success)
if (isSuccess)
{
Services.Taxes.CancelTaxes(order);
order.CaptureInfo = new OrderCaptureInfo(OrderCaptureInfo.OrderCaptureState.Cancel, string.Empty);
Expand Down Expand Up @@ -795,8 +800,8 @@ void Refund()

double refundAmount = notificationItem.Amount.Value.Value / 100d;
IEnumerable<OrderReturnInfo> existingOperations = order.ReturnOperations ?? new List<OrderReturnInfo>();
bool isFailedNotification = (notificationItem.Success && eventCode is NotificationEventCode.RefundFailed) || // literally: refund failed successfully
(!notificationItem.Success && eventCode is NotificationEventCode.Refund); // refund was not succeed
bool isFailedNotification = (isSuccess && eventCode is NotificationEventCode.RefundFailed) || // literally: refund failed successfully
(!isSuccess && eventCode is NotificationEventCode.Refund); // refund was not succeed

if (notificationItem.MerchantReference.Contains(RefundIdDelimeter)) // operation was created on DW side
{
Expand Down
2 changes: 1 addition & 1 deletion src/Dynamicweb.Ecommerce.CheckoutHandlers.Adyen.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>10.2.0</VersionPrefix>
<VersionPrefix>10.2.1</VersionPrefix>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Adyen</Title>
<Description>Adyen Checkout Handler</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static string GetDataToSign(NotificationRequestItem notificationRequestI
Converter.ToString(amount.Value),
amount.Currency,
notificationRequestItem.EventCode,
notificationRequestItem.Success.ToString().ToLower()
notificationRequestItem.Success.ToLower()
};

return string.Join(":", signedDataList);
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Notification/NotificationRequestItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class NotificationRequestItem
public string Reason { get; set; }

[DataMember(Name = "success")]
public bool Success { get; set; }
public string Success { get; set; }

public NotificationEventCode? GetNotificationEventCode()
{
Expand Down

0 comments on commit 5383358

Please sign in to comment.