Skip to content

Commit 08049cb

Browse files
committed
Amazon payments: Order wasn't found if the capturing\refunding took place at Amazon Seller Central and the notification came through IPN
1 parent a337f3c commit 08049cb

6 files changed

Lines changed: 53 additions & 4 deletions

File tree

src/Plugins/SmartStore.AmazonPay/Description.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FriendlyName: Pay with Amazon
22
SystemName: SmartStore.AmazonPay
3-
Version: 1.17
3+
Version: 1.18
44
Group: Payment
55
MinAppVersion: 2.1.0
66
Author: SmartStore AG

src/Plugins/SmartStore.AmazonPay/Extensions/AmazonPayApiExtensions.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
2+
using System.Linq;
23
using System.Text;
34
using OffAmazonPaymentsService;
45
using OffAmazonPaymentsService.Model;
6+
using SmartStore.AmazonPay.Extensions;
7+
using SmartStore.AmazonPay.Services;
8+
using SmartStore.Core.Data;
9+
using SmartStore.Core.Domain.Orders;
510
using SmartStore.Services.Directory;
611
using SmartStore.Services.Localization;
7-
using SmartStore.AmazonPay.Extensions;
812

913
namespace SmartStore.AmazonPay.Api
1014
{
@@ -193,5 +197,27 @@ public static void ToAddress(this OrderReferenceDetails details, SmartStore.Core
193197
details.Destination.PhysicalDestination.ToAddress(address, countryService, stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);
194198
}
195199
}
200+
201+
public static Order GetOrderByAmazonId(this IRepository<Order> orderRepository, string amazonId)
202+
{
203+
// S02-9777218-8608106 OrderReferenceId
204+
// S02-9777218-8608106-A088344 Auth ID
205+
// S02-9777218-8608106-C088344 Capture ID
206+
207+
if (amazonId.HasValue())
208+
{
209+
string amazonOrderReferenceId = amazonId.Substring(0, amazonId.LastIndexOf('-'));
210+
if (amazonOrderReferenceId.HasValue())
211+
{
212+
var orders = orderRepository.Table
213+
.Where(x => x.PaymentMethodSystemName == AmazonPayCore.SystemName && x.AuthorizationTransactionId.StartsWith(amazonOrderReferenceId))
214+
.ToList();
215+
216+
if (orders.Count() == 1)
217+
return orders.FirstOrDefault();
218+
}
219+
}
220+
return null;
221+
}
196222
}
197223
}

src/Plugins/SmartStore.AmazonPay/Extensions/MiscExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System.Web;
1+
using System.Collections.Generic;
22
using System.Linq;
3-
using System.Collections.Generic;
3+
using System.Web;
44
using SmartStore.AmazonPay.Services;
55
using SmartStore.Core.Domain.Common;
66
using SmartStore.Services.Common;

src/Plugins/SmartStore.AmazonPay/Services/AmazonPayCore.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ public class AmazonPayApiData
8787
public bool? CaptureNow { get; set; }
8888
public DateTime Creation { get; set; }
8989
public DateTime? Expiration { get; set; }
90+
91+
public string AnyAmazonId
92+
{
93+
get
94+
{
95+
if (CaptureId.HasValue())
96+
return CaptureId;
97+
if (AuthorizationId.HasValue())
98+
return AuthorizationId;
99+
return RefundId;
100+
}
101+
}
90102
}
91103

92104

src/Plugins/SmartStore.AmazonPay/Services/AmazonPayService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,9 @@ private Order FindOrder(AmazonPayApiData data)
815815
else if (data.MessageType.IsCaseInsensitiveEqual("CaptureNotification"))
816816
{
817817
if ((order = _orderService.GetOrderByPaymentCapture(AmazonPayCore.SystemName, data.CaptureId)) == null)
818+
order = _orderRepository.GetOrderByAmazonId(data.AnyAmazonId);
819+
820+
if (order == null)
818821
errorId = "CaptureId {0}".FormatWith(data.CaptureId);
819822
}
820823
else if (data.MessageType.IsCaseInsensitiveEqual("RefundNotification"))
@@ -824,6 +827,9 @@ private Order FindOrder(AmazonPayApiData data)
824827
.FirstOrDefault();
825828

826829
if (attribute == null || (order = _orderService.GetOrderById(attribute.EntityId)) == null)
830+
order = _orderRepository.GetOrderByAmazonId(data.AnyAmazonId);
831+
832+
if (order == null)
827833
errorId = "RefundId {0}".FormatWith(data.RefundId);
828834
}
829835

src/Plugins/SmartStore.AmazonPay/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#Release Notes#
22

3+
##Pay with Amazon 1.18##
4+
###Bugfixes###
5+
* Order wasn't found if the capturing\refunding took place at Amazon Seller Central and the notification came through IPN
6+
37
##Pay with Amazon 1.17##
8+
###Improvements###
49
* Amazon payments review
510

611
##Pay with Amazon 1.16##

0 commit comments

Comments
 (0)