-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathPaymentRequestDefaultConverter.cs
More file actions
48 lines (39 loc) · 1.55 KB
/
PaymentRequestDefaultConverter.cs
File metadata and controls
48 lines (39 loc) · 1.55 KB
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
using Newtonsoft.Json;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.OrdersModule.Data.Model;
using VirtoCommerce.PaymentModule.Model.Requests;
using VirtoCommerce.Platform.Core.Common;
namespace VirtoCommerce.OrdersModule.Data.Services;
public class PaymentRequestDefaultConverter : IPaymentRequestConverter
{
public virtual PaymentParameters GetPaymentParameters(PaymentCallbackParameters request)
{
var result = AbstractTypeFactory<PaymentParameters>.TryCreateInstance();
foreach (var parameter in request?.Parameters ?? [])
{
result.Parameters.Add(parameter.Key, parameter.Value);
}
result.OrderId = result.Parameters.Get("orderid");
result.PaymentMethodCode = result.Parameters.Get("code");
return result;
}
public virtual PaymentParameters GetPaymentParameters(string requestBody, string requestQuery)
{
var paymentCallbackParameters = JsonConvert.DeserializeObject<PaymentCallbackParameters>(requestBody);
return GetPaymentParameters(paymentCallbackParameters);
}
public virtual (object, bool) GetResponse(PostProcessPaymentRequestResult result)
{
if (result is PostProcessPaymentRequestNotValidResult notValidResult)
{
var response = new
{
Message = notValidResult.ErrorMessage,
Errors = notValidResult.Errors,
};
return (response, false);
}
return (result, true);
}
}