-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathPaymentRequestDefaultConverter.cs
More file actions
55 lines (46 loc) · 1.86 KB
/
PaymentRequestDefaultConverter.cs
File metadata and controls
55 lines (46 loc) · 1.86 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
49
50
51
52
53
54
55
using System;
using System.Collections.Specialized;
using Newtonsoft.Json;
using VirtoCommerce.OrdersModule.Core.Model;
using VirtoCommerce.OrdersModule.Core.Services;
using VirtoCommerce.OrdersModule.Data.Model;
using VirtoCommerce.PaymentModule.Model.Requests;
namespace VirtoCommerce.OrdersModule.Data.Services
{
public class PaymentRequestDefaultConverter : IPaymentRequestConverter
{
public virtual PaymentParameters GetPaymentParameters(PaymentCallbackParameters request)
{
var result = new PaymentParameters();
result.Parameters = new NameValueCollection();
foreach (var parameter in request?.Parameters ?? Array.Empty<KeyValuePair>())
{
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 bool IsFailure(PostProcessPaymentRequestResult result)
{
return result is PostProcessPaymentRequestNotValidResult;
}
public virtual object GetResponse(PostProcessPaymentRequestResult result)
{
if (IsFailure(result))
{
return new
{
Message = (result as PostProcessPaymentRequestNotValidResult)?.ErrorMessage,
Errors = (result as PostProcessPaymentRequestNotValidResult)?.Errors
};
}
return result;
}
}
}