-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
7,441 additions
and
12,544 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/Plugins/Nop.Plugin.Shipping.UPS/API/NullToEmptyStringResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Nop.Plugin.Shipping.UPS.API; | ||
|
||
public class NullToEmptyStringResolver : DefaultContractResolver | ||
{ | ||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) | ||
{ | ||
return type.GetProperties() | ||
.Select(p => { | ||
var jp = base.CreateProperty(p, memberSerialization); | ||
jp.ValueProvider = new NullToEmptyStringValueProvider(p); | ||
return jp; | ||
}).ToList(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Plugins/Nop.Plugin.Shipping.UPS/API/NullToEmptyStringValueProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Nop.Plugin.Shipping.UPS.API | ||
{ | ||
public class NullToEmptyStringValueProvider : IValueProvider | ||
{ | ||
private readonly PropertyInfo _memberInfo; | ||
|
||
public NullToEmptyStringValueProvider(PropertyInfo memberInfo) | ||
{ | ||
_memberInfo = memberInfo; | ||
} | ||
|
||
public object GetValue(object target) | ||
{ | ||
var result = _memberInfo.GetValue(target); | ||
|
||
if (_memberInfo.PropertyType != typeof(string)) | ||
return result; | ||
|
||
var attributes = _memberInfo | ||
.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.RequiredAttribute)).FirstOrDefault() as System.ComponentModel.DataAnnotations.RequiredAttribute; | ||
|
||
if ((attributes?.AllowEmptyStrings ?? false) && result == null) | ||
result = ""; | ||
|
||
return result; | ||
} | ||
|
||
public void SetValue(object target, object value) | ||
{ | ||
_memberInfo.SetValue(target, value); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Plugins/Nop.Plugin.Shipping.UPS/API/OAuth/NopOAuthClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Nop.Plugin.Shipping.UPS.Services; | ||
|
||
namespace Nop.Plugin.Shipping.UPS.API.OAuth | ||
{ | ||
public partial class OAuthClient | ||
{ | ||
private UPSSettings _upsSettings; | ||
|
||
public OAuthClient(HttpClient httpClient, UPSSettings upsSettings) : this(httpClient) | ||
{ | ||
_upsSettings = upsSettings; | ||
|
||
if (!_upsSettings.UseSandbox) | ||
BaseUrl = UPSDefaults.ApiUrl.Replace("/api", ""); | ||
} | ||
|
||
partial void PrepareRequest(HttpClient client, HttpRequestMessage request, | ||
string url) | ||
{ | ||
client.PrepareRequest(request, _upsSettings); | ||
} | ||
|
||
public virtual Task<GenerateTokenSuccessResponse> GenerateTokenAsync() | ||
{ | ||
return GenerateTokenAsync(null, new Body(), CancellationToken.None); | ||
} | ||
|
||
partial void ProcessResponse(HttpClient client, HttpResponseMessage response) | ||
{ | ||
client.ProcessResponse(response, _upsSettings); | ||
} | ||
} | ||
} |
475 changes: 475 additions & 0 deletions
475
src/Plugins/Nop.Plugin.Shipping.UPS/API/OAuth/OAuthClient.cs
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
src/Plugins/Nop.Plugin.Shipping.UPS/API/Rates/NopRateClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Newtonsoft.Json; | ||
using Nop.Plugin.Shipping.UPS.Services; | ||
|
||
namespace Nop.Plugin.Shipping.UPS.API.Rates | ||
{ | ||
public partial class RateClient | ||
{ | ||
private UPSSettings _upsSettings; | ||
private string _accessToken; | ||
|
||
public RateClient(HttpClient httpClient, UPSSettings upsSettings, string accessToken) : this(httpClient) | ||
{ | ||
_upsSettings = upsSettings; | ||
_accessToken = accessToken; | ||
|
||
if (!_upsSettings.UseSandbox) | ||
BaseUrl = UPSDefaults.ApiUrl; | ||
} | ||
|
||
partial void PrepareRequest(HttpClient client, HttpRequestMessage request, | ||
string url) | ||
{ | ||
client.PrepareRequest(request, _upsSettings, _accessToken); | ||
} | ||
|
||
public async Task<RateResponse> ProcessRateAsync(RateRequest request) | ||
{ | ||
var response = await RateAsync(Guid.NewGuid().ToString(), | ||
_upsSettings.UseSandbox ? "testing" : UPSDefaults.SystemName, string.Empty, "v1", "Shop", new RATERequestWrapper | ||
{ | ||
RateRequest = request | ||
}); | ||
|
||
return response.RateResponse; | ||
} | ||
|
||
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings) | ||
{ | ||
settings.ContractResolver = new NullToEmptyStringResolver(); | ||
} | ||
} | ||
|
||
public partial class RateResponse_RatedShipment | ||
{ | ||
/// <summary> | ||
/// <remarks> | ||
/// For some reason, the description of this field in the API definition | ||
/// does not correspond to reality. More precisely, it does not always correspond to reality, | ||
/// sometimes the answer comes as a single object and sometimes as a collection of objects. | ||
/// since we do not use this data in our code, we decided to change type to object (It might be ICollection<RatedShipment_RatedPackage> or RatedShipment_RatedPackage). | ||
/// | ||
/// Do not delete this field unless you have made sure that the description of the API | ||
/// or the response from the server has changed</remarks> | ||
/// </summary> | ||
[JsonProperty("RatedPackage", Required = Required.Always)] | ||
[System.ComponentModel.DataAnnotations.Required] | ||
public object RatedPackage { get; set; } | ||
|
||
/// <summary> | ||
/// <remarks> | ||
/// For some reason, the description of this field in the API definition | ||
/// does not correspond to reality. More precisely, it does not always correspond to reality, | ||
/// sometimes the answer comes as a single object and sometimes as a collection of objects. | ||
/// since we do not use this data in our code, we decided to change type to object (It might be ICollection<RatedShipment_RatedShipmentAlert> or RatedShipment_RatedShipmentAlert). | ||
/// | ||
/// Do not delete this field unless you have made sure that the description of the API | ||
/// or the response from the server has changed</remarks> | ||
/// </summary> | ||
[JsonProperty("RatedShipmentAlert", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)] | ||
public object RatedShipmentAlert { get; set; } | ||
} | ||
} |
Oops, something went wrong.