Skip to content

Commit b56b2db

Browse files
authored
Migrate to System.Text.Json (#8)
1 parent 5681e47 commit b56b2db

18 files changed

+1420
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,4 @@ $RECYCLE.BIN/
479479
##
480480
## Umbraco Commerce specific
481481
##
482+
/src/Umbraco.Commerce.PaymentProviders.Quickpay/packages.lock.json

Umbraco.Commerce.PaymentProviders.Quickpay.sln

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 16
3-
VisualStudioVersion = 16.0.31105.61
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34316.72
45
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Commerce.PaymentProviders.Quickpay", "src\Umbraco.Commerce.PaymentProviders.Quickpay\Umbraco.Commerce.PaymentProviders.Quickpay.csproj", "{F5698074-9952-4A9D-A406-268852BC49AF}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Umbraco.Commerce.PaymentProviders.Quickpay", "src\Umbraco.Commerce.PaymentProviders.Quickpay\Umbraco.Commerce.PaymentProviders.Quickpay.csproj", "{F5698074-9952-4A9D-A406-268852BC49AF}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Commerce.PaymentProviders.Quickpay.UnitTests", "tests\Umbraco.Commerce.PaymentProviders.Quickpay.UnitTests\Umbraco.Commerce.PaymentProviders.Quickpay.UnitTests.csproj", "{0CB214F8-4DCE-470B-8DC9-E4AA6E312835}"
69
EndProject
710
Global
811
GlobalSection(SolutionConfigurationPlatforms) = preSolution
912
Debug|Any CPU = Debug|Any CPU
1013
Release|Any CPU = Release|Any CPU
1114
EndGlobalSection
1215
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13-
{C5450C45-3A26-4DA7-B9C4-C6636706DBFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14-
{C5450C45-3A26-4DA7-B9C4-C6636706DBFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
1516
{F5698074-9952-4A9D-A406-268852BC49AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1617
{F5698074-9952-4A9D-A406-268852BC49AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
1718
{F5698074-9952-4A9D-A406-268852BC49AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
1819
{F5698074-9952-4A9D-A406-268852BC49AF}.Release|Any CPU.Build.0 = Release|Any CPU
19-
{95C0A77F-9D4E-46CE-930C-BE7044C8550F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{95C0A77F-9D4E-46CE-930C-BE7044C8550F}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{0CB214F8-4DCE-470B-8DC9-E4AA6E312835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{0CB214F8-4DCE-470B-8DC9-E4AA6E312835}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{0CB214F8-4DCE-470B-8DC9-E4AA6E312835}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{0CB214F8-4DCE-470B-8DC9-E4AA6E312835}.Release|Any CPU.Build.0 = Release|Any CPU
2124
EndGlobalSection
2225
GlobalSection(SolutionProperties) = preSolution
2326
HideSolutionNode = FALSE
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.IO;
2+
using System.Text.Json;
3+
using Flurl.Http.Configuration;
4+
5+
namespace Umbraco.Commerce.PaymentProviders.Quickpay.Api
6+
{
7+
internal class CustomFlurlJsonSerializer : ISerializer
8+
{
9+
private readonly JsonSerializerOptions _serializerOptions;
10+
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="CustomFlurlJsonSerializer"/> class.
13+
/// </summary>
14+
/// <param name="settings">Settings to control (de)serialization behavior.</param>
15+
public CustomFlurlJsonSerializer(JsonSerializerOptions settings = null)
16+
{
17+
_serializerOptions = settings;
18+
}
19+
20+
/// <summary>
21+
/// Serializes the specified object to a JSON string.
22+
/// </summary>
23+
/// <param name="obj">The object to serialize.</param>
24+
public string Serialize(object obj) => JsonSerializer.Serialize(obj, _serializerOptions);
25+
26+
/// <summary>
27+
/// Deserializes the specified JSON string to an object of type T.
28+
/// </summary>
29+
/// <param name="s">The JSON string to deserialize.</param>
30+
public T Deserialize<T>(string s) => JsonSerializer.Deserialize<T>(s, _serializerOptions);
31+
32+
/// <summary>
33+
/// Deserializes the specified stream to an object of type T.
34+
/// </summary>
35+
/// <param name="stream">The stream to deserialize.</param>
36+
public T Deserialize<T>(Stream stream)
37+
{
38+
return JsonSerializer.Deserialize<T>(stream, _serializerOptions);
39+
}
40+
}
41+
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Newtonsoft.Json;
21
using System.Collections.Generic;
2+
using System.Text.Json.Serialization;
33

44
namespace Umbraco.Commerce.PaymentProviders.Quickpay.Api.Models
55
{
@@ -8,133 +8,133 @@ public class MetaData
88
/// <summary>
99
/// Type (card, mobile, nin)
1010
/// </summary>
11-
[JsonProperty("type")]
11+
[JsonPropertyName("type")]
1212
public string Type { get; set; }
1313

1414
/// <summary>
1515
/// Origin of this transaction or card. If set, describes where it came from.
1616
/// </summary>
17-
[JsonProperty("origin")]
17+
[JsonPropertyName("origin")]
1818
public string Origin { get; set; }
1919

2020
/// <summary>
2121
/// Card type only: The card brand
2222
/// </summary>
23-
[JsonProperty("brand")]
23+
[JsonPropertyName("brand")]
2424
public string Brand { get; set; }
2525

2626
/// <summary>
2727
/// Card type only: Card BIN
2828
/// </summary>
29-
[JsonProperty("bin")]
29+
[JsonPropertyName("bin")]
3030
public string Bin { get; set; }
3131

3232
/// <summary>
3333
/// Card type only: Corporate status
3434
/// </summary>
35-
[JsonProperty("corporate")]
36-
public string Corporate { get; set; }
35+
[JsonPropertyName("corporate")]
36+
public bool? Corporate { get; set; }
3737

3838
/// <summary>
3939
/// Card type only: The last 4 digits of the card number
4040
/// </summary>
41-
[JsonProperty("last4")]
41+
[JsonPropertyName("last4")]
4242
public string Last4 { get; set; }
4343

4444
/// <summary>
4545
/// Card type only: The expiration month
4646
/// </summary>
47-
[JsonProperty("exp_month")]
47+
[JsonPropertyName("exp_month")]
4848
public int? ExpMonth { get; set; }
4949

5050
/// <summary>
5151
/// Card type only: The expiration year
5252
/// </summary>
53-
[JsonProperty("exp_year")]
53+
[JsonPropertyName("exp_year")]
5454
public int? ExpYear { get; set; }
5555

5656
/// <summary>
5757
/// Card type only: The card country in ISO 3166-1 alpha-3
5858
/// </summary>
59-
[JsonProperty("country")]
59+
[JsonPropertyName("country")]
6060
public string Country { get; set; }
6161

6262
/// <summary>
6363
/// Card type only: Verified via 3D-Secure
6464
/// </summary>
65-
[JsonProperty("is_3d_secure")]
65+
[JsonPropertyName("is_3d_secure")]
6666
public bool? Is3dSecure { get; set; }
6767

6868
/// <summary>
6969
/// Name of cardholder
7070
/// </summary>
71-
[JsonProperty("issued_to")]
71+
[JsonPropertyName("issued_to")]
7272
public string IssuedTo { get; set; }
7373

7474
/// <summary>
7575
/// Card type only: PCI safe hash of card number
7676
/// </summary>
77-
[JsonProperty("hash")]
77+
[JsonPropertyName("hash")]
7878
public string Hash { get; set; }
7979

8080
/// <summary>
8181
/// Mobile type only: The mobile number
8282
/// </summary>
83-
[JsonProperty("number")]
83+
[JsonPropertyName("number")]
8484
public object Number { get; set; }
8585

8686
/// <summary>
8787
/// Customer IP
8888
/// </summary>
89-
[JsonProperty("customer_ip")]
89+
[JsonPropertyName("customer_ip")]
9090
public string CustomerIp { get; set; }
9191

9292
/// <summary>
9393
/// Customer country based on IP geo-data, ISO 3166-1 alpha-2
9494
/// </summary>
95-
[JsonProperty("customer_country")]
95+
[JsonPropertyName("customer_country")]
9696
public string CustomerCountry { get; set; }
9797

9898
/// <summary>
9999
/// Suspected fraud
100100
/// </summary>
101-
[JsonProperty("fraud_suspected")]
101+
[JsonPropertyName("fraud_suspected")]
102102
public bool FraudSuspected { get; set; }
103103

104104
/// <summary>
105105
/// Fraud remarks
106106
/// </summary>
107-
[JsonProperty("fraud_remarks")]
107+
[JsonPropertyName("fraud_remarks")]
108108
public List<object> FraudRemarks { get; set; }
109109

110110
/// <summary>
111111
/// Reported as fraudulent
112112
/// </summary>
113-
[JsonProperty("fraud_reported")]
113+
[JsonPropertyName("fraud_reported")]
114114
public bool FraudReported { get; set; }
115115

116116
/// <summary>
117117
/// Fraud report date
118118
/// </summary>
119-
[JsonProperty("fraud_reported_at")]
119+
[JsonPropertyName("fraud_reported_at")]
120120
public string FraudReportedAt { get; set; }
121121

122122
/// <summary>
123123
/// NIN type only. NIN number
124124
/// </summary>
125-
[JsonProperty("nin_number")]
125+
[JsonPropertyName("nin_number")]
126126
public string NinNumber { get; set; }
127127

128128
/// <summary>
129129
/// NIN type only. NIN country code, ISO 3166-1 alpha-3
130130
/// </summary>
131-
[JsonProperty("nin_country_code")]
131+
[JsonPropertyName("nin_country_code")]
132132
public string NinCountryCode { get; set; }
133133

134134
/// <summary>
135135
/// NIN type only. NIN gender
136136
/// </summary>
137-
[JsonProperty("nin_gender")]
137+
[JsonPropertyName("nin_gender")]
138138
public string NinGender { get; set; }
139139
}
140140
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
22

33
namespace Umbraco.Commerce.PaymentProviders.Quickpay.Api.Models
44
{
@@ -7,49 +7,49 @@ public class Operation
77
/// <summary>
88
/// Operation ID
99
/// </summary>
10-
[JsonProperty("id")]
10+
[JsonPropertyName("id")]
1111
public int Id { get; set; }
1212

1313
/// <summary>
1414
/// Type of operation
1515
/// </summary>
16-
[JsonProperty("type")]
16+
[JsonPropertyName("type")]
1717
public string Type { get; set; }
1818

1919
/// <summary>
2020
/// Amount
2121
/// </summary>
22-
[JsonProperty("amount")]
23-
public int Amount { get; set; }
22+
[JsonPropertyName("amount")]
23+
public int? Amount { get; set; }
2424

2525
/// <summary>
2626
/// If the operation is pending
2727
/// </summary>
28-
[JsonProperty("pending")]
28+
[JsonPropertyName("pending")]
2929
public bool Pending { get; set; }
3030

3131
/// <summary>
3232
/// Quickpay status code
3333
/// </summary>
34-
[JsonProperty("qp_status_code")]
34+
[JsonPropertyName("qp_status_code")]
3535
public string QuickpayStatusCode { get; set; }
3636

3737
/// <summary>
3838
/// Quickpay status message
3939
/// </summary>
40-
[JsonProperty("qp_status_msg")]
40+
[JsonPropertyName("qp_status_msg")]
4141
public string QuickpayStatusMessage { get; set; }
4242

4343
/// <summary>
4444
/// Acquirer status code
4545
/// </summary>
46-
[JsonProperty("aq_status_code")]
46+
[JsonPropertyName("aq_status_code")]
4747
public string AcquirerStatusCode { get; set; }
4848

4949
/// <summary>
5050
/// Acquirer status message
5151
/// </summary>
52-
[JsonProperty("aq_status_msg")]
52+
[JsonPropertyName("aq_status_msg")]
5353
public string AcquirerStatusMessage { get; set; }
5454
}
5555
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
22

33
namespace Umbraco.Commerce.PaymentProviders.Quickpay.Api.Models
44
{
@@ -7,55 +7,55 @@ public class PaymentLink : PaymentLinkUrl
77
/// <summary>
88
/// Id of agreement that will be used in the payment window
99
/// </summary>
10-
[JsonProperty("agreement_id")]
10+
[JsonPropertyName("agreement_id")]
1111
public int AgreementId { get; set; }
1212

1313
/// <summary>
1414
/// Two letter language code that determines the language of the payment window
1515
/// </summary>
16-
[JsonProperty("language")]
16+
[JsonPropertyName("language")]
1717
public string Language { get; set; }
1818

1919
/// <summary>
2020
/// Amount to authorize
2121
/// </summary>
22-
[JsonProperty("amount")]
22+
[JsonPropertyName("amount")]
2323
public int Amount { get; set; }
2424

2525
/// <summary>
2626
/// Where cardholder is redirected after success
2727
/// </summary>
28-
[JsonProperty("continue_url")]
28+
[JsonPropertyName("continue_url")]
2929
public string ContinueUrl { get; set; }
3030

3131
/// <summary>
3232
/// Where cardholder is redirected after cancel
3333
/// </summary>
34-
[JsonProperty("cancel_url")]
34+
[JsonPropertyName("cancel_url")]
3535
public string CancelUrl { get; set; }
3636

3737
/// <summary>
3838
/// Endpoint for a POST callback
3939
/// </summary>
40-
[JsonProperty("callback_url")]
40+
[JsonPropertyName("callback_url")]
4141
public string CallbackUrl { get; set; }
4242

4343
/// <summary>
4444
/// Lock to these payment methods
4545
/// </summary>
46-
[JsonProperty("payment_methods")]
46+
[JsonPropertyName("payment_methods")]
4747
public string PaymentMethods { get; set; }
4848

4949
/// <summary>
5050
/// If true, will add acquirer fee to the amount
5151
/// </summary>
52-
[JsonProperty("auto_fee")]
52+
[JsonPropertyName("auto_fee")]
5353
public bool? AutoFee { get; set; }
5454

5555
/// <summary>
5656
/// If true, will capture the transaction after authorize succeeds
5757
/// </summary>
58-
[JsonProperty("auto_capture")]
58+
[JsonPropertyName("auto_capture")]
5959
public bool? AutoCapture { get; set; }
6060
}
6161
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
22

33
namespace Umbraco.Commerce.PaymentProviders.Quickpay.Api.Models
44
{
@@ -7,7 +7,7 @@ public class PaymentLinkUrl
77
/// <summary>
88
/// Url to payment window for this payment link
99
/// </summary>
10-
[JsonProperty("url")]
10+
[JsonPropertyName("url")]
1111
public string Url { get; set; }
1212
}
1313
}

0 commit comments

Comments
 (0)