Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions CustomConverters/ShippingZoneMethodSettingsConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using WooCommerceNET.WooCommerce.FlexibleShipping;

namespace WooCommerceNET.CustomConverters
{
public class ShippingZoneMethodSettingsConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JToken token = JToken.Load(reader);
if (token.Type == JTokenType.Array)
{
return token.ToObject<List<ShippingZoneMethodRule>>();
}
return token.ToString();
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
}
23 changes: 21 additions & 2 deletions RestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WooCommerceNET.Base;

Expand Down Expand Up @@ -172,9 +173,16 @@ public virtual async Task<string> SendHttpClientRequest<T>(string endpoint, Requ
if (JWTRequestFilter != null)
JWTRequestFilter.Invoke(request);

var buffer = Encoding.UTF8.GetBytes($"username={wc_key}&password={wc_secret}");
var convKey = ConvertAmpersandsToUTF8Hex(wc_key);
var convSecret = ConvertAmpersandsToUTF8Hex(wc_secret);

var buffer = Encoding.UTF8.GetBytes($"username={convKey}&password={convSecret}");
Stream dataStream = await request.GetRequestStreamAsync().ConfigureAwait(false);
dataStream.Write(buffer, 0, buffer.Length);
dataStream.Close();

request.ContentLength = buffer.Length;

WebResponse response = await request.GetResponseAsync().ConfigureAwait(false);
Stream resStream = response.GetResponseStream();
string result = await GetStreamContent(resStream, "UTF-8").ConfigureAwait(false);
Expand Down Expand Up @@ -244,7 +252,12 @@ public virtual async Task<string> SendHttpClientRequest<T>(string endpoint, Requ
httpWebRequest.ContentType = "application/x-www-form-urlencoded";

Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false);
FileStream fileStream = new FileStream(parms["path"], FileMode.Open, FileAccess.Read);

// If the given path is a physical path, open file. If not, read from URL.
var fileStream = parms["source"] == "local" ?
new FileStream(parms["path"], FileMode.Open, FileAccess.Read) :
(new WebClient()).OpenRead(parms["path"]);

byte[] buffer = new byte[4096];
int bytesRead = 0;

Expand Down Expand Up @@ -462,6 +475,12 @@ public string DateTimeFormat
return IsLegacy ? "yyyy-MM-ddTHH:mm:ssZ" : "yyyy-MM-ddTHH:mm:ssK";
}
}

private string ConvertAmpersandsToUTF8Hex(string original)
{
var pattern = new Regex("[&]");
return pattern.Replace(original, "%26");
}
}

public class WP_JWT_Object
Expand Down
6 changes: 5 additions & 1 deletion WooCommerce.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Changes Doc: https://github.com/XiaoFaye/WooCommerce.NET/blob/master/Changes.md
11. Add UpdateRangeRaw to ignore deserialize return json. #523</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>0.8.3.0</AssemblyVersion>
<SignAssembly>true</SignAssembly>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>sn.key.snk</AssemblyOriginatorKeyFile>
<PackageLicenseFile>License.md</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand All @@ -44,4 +44,8 @@ Changes Doc: https://github.com/XiaoFaye/WooCommerce.NET/blob/master/Changes.md
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions WooCommerce/FlexibleShipping/ShippingZoneMethodRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace WooCommerceNET.WooCommerce.FlexibleShipping
{
public class ShippingZoneMethodRule
{
public ICollection<ShippingZoneMethodRuleCondition> conditions { get; set; }
public string cost_per_order { get; set; }
}

public class ShippingZoneMethodRuleCondition
{
public string condition_id { get; set; }
public string min { get; set; }
public string max { get; set; }
}
}
7 changes: 5 additions & 2 deletions WooCommerce/v2/ShippingZone.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Runtime.Serialization;
using WooCommerceNET.CustomConverters;

namespace WooCommerceNET.WooCommerce.v2
{
Expand Down Expand Up @@ -165,7 +167,8 @@ public class ShippingZoneMethodSetting
/// Setting value.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string value { get; set; }
[JsonConverter(typeof(ShippingZoneMethodSettingsConverter))]
public object value { get; set; }

/// <summary>
/// Default value for the setting.
Expand Down
Binary file added bin/Debug/WooCommerceNET.0.8.3.nupkg
Binary file not shown.
63 changes: 63 additions & 0 deletions bin/Debug/netstandard2.0/WooCommerce.NET.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"WooCommerce.NET/0.8.3": {
"dependencies": {
"NETStandard.Library": "2.0.3",
"Newtonsoft.Json": "13.0.1"
},
"runtime": {
"WooCommerce.NET.dll": {}
}
},
"Microsoft.NETCore.Platforms/1.1.0": {},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"Newtonsoft.Json/13.0.1": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "13.0.0.0",
"fileVersion": "13.0.1.25517"
}
}
}
}
},
"libraries": {
"WooCommerce.NET/0.8.3": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
},
"Newtonsoft.Json/13.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==",
"path": "newtonsoft.json/13.0.1",
"hashPath": "newtonsoft.json.13.0.1.nupkg.sha512"
}
}
}
Binary file added bin/Debug/netstandard2.0/WooCommerce.NET.dll
Binary file not shown.
Binary file added bin/Debug/netstandard2.0/WooCommerce.NET.pdb
Binary file not shown.
41 changes: 41 additions & 0 deletions obj/Debug/WooCommerceNET.0.8.3.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>WooCommerceNET</id>
<version>0.8.3</version>
<authors>JamesYang@NZ</authors>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<license type="file">License.md</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<projectUrl>https://github.com/XiaoFaye/WooCommerce.NET</projectUrl>
<description>A .NET Wrapper for WooCommerce/WordPress REST API</description>
<releaseNotes>WooCommerce.NET is a .NET library for calling WooCommerce/WordPress REST API in .NET applications.

GitHub: https://github.com/XiaoFaye/WooCommerce.NET
Changes Doc: https://github.com/XiaoFaye/WooCommerce.NET/blob/master/Changes.md

* v0.8.3 update
1. Fix error while creating a refund. #476
2. Allow authenticate Woocommerce API with JWT (set WCAuthWithJWT to true). #478
3. Fix error on retrieving refund. #484
4. Fix error on deserialize BatchObject. #523
5. Fix error on date format. #524
6. Add user-friendly attribute names and values to Metadata. #558
7. Change all id field to unsigned 32bit integer to prevent overflow. #560
8. Change functions in BaseObject to virtual to support Unit Test. #568
9. Add function to delete tax class by slug. #576
10. Allow WC Plugins to use WCObject.
11. Add UpdateRangeRaw to ignore deserialize return json. #523</releaseNotes>
<copyright>Copyright © 2015 - 2021 James Yang@NZ</copyright>
<tags>WooCommerce Wordpress Restful API</tags>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
<files>
<file src="C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\bin\Debug\netstandard2.0\WooCommerce.NET.dll" target="lib\netstandard2.0\WooCommerce.NET.dll" />
<file src="C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\License.md" target="License.md" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
25 changes: 25 additions & 0 deletions obj/Debug/netstandard2.0/WooCommerce.NET.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("JamesYang@NZ")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright © 2015 - 2021 James Yang@NZ")]
[assembly: System.Reflection.AssemblyDescriptionAttribute("A .NET Wrapper for WooCommerce/WordPress REST API")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("0.8.3.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("0.8.3")]
[assembly: System.Reflection.AssemblyProductAttribute("WooCommerce.NET")]
[assembly: System.Reflection.AssemblyTitleAttribute("WooCommerce.NET")]
[assembly: System.Reflection.AssemblyVersionAttribute("0.8.3.0")]

// Generated by the MSBuild WriteCodeFragment class.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d55f61249a76f3092a08994b10cc7071dc1bdac6
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
is_global = true
build_property.RootNamespace = WooCommerce.NET
build_property.ProjectDir = C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3db8ec6cc22cb1364631cfc725ce11ea608aa07f
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.csproj.AssemblyReference.cache
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.AssemblyInfoInputs.cache
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.AssemblyInfo.cs
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.csproj.CoreCompileInputs.cache
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\bin\Debug\netstandard2.0\WooCommerce.NET.deps.json
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\bin\Debug\netstandard2.0\WooCommerce.NET.dll
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\bin\Debug\netstandard2.0\WooCommerce.NET.pdb
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.dll
C:\Users\kamorim\source\repos\L4B\l4b-shop-api\WooCommerce.NET\obj\Debug\netstandard2.0\WooCommerce.NET.pdb
Binary file added obj/Debug/netstandard2.0/WooCommerce.NET.dll
Binary file not shown.
Binary file added obj/Debug/netstandard2.0/WooCommerce.NET.pdb
Binary file not shown.
73 changes: 73 additions & 0 deletions obj/WooCommerce.NET.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"format": 1,
"restore": {
"C:\\Users\\kamorim\\source\\repos\\L4B\\l4b-shop-api\\WooCommerce.NET\\WooCommerce.NET.csproj": {}
},
"projects": {
"C:\\Users\\kamorim\\source\\repos\\L4B\\l4b-shop-api\\WooCommerce.NET\\WooCommerce.NET.csproj": {
"version": "0.8.3",
"restore": {
"projectUniqueName": "C:\\Users\\kamorim\\source\\repos\\L4B\\l4b-shop-api\\WooCommerce.NET\\WooCommerce.NET.csproj",
"projectName": "WooCommerceNET",
"projectPath": "C:\\Users\\kamorim\\source\\repos\\L4B\\l4b-shop-api\\WooCommerce.NET\\WooCommerce.NET.csproj",
"packagesPath": "C:\\Users\\kamorim\\.nuget\\packages\\",
"outputPath": "C:\\Users\\kamorim\\source\\repos\\L4B\\l4b-shop-api\\WooCommerce.NET\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet\\"
],
"configFilePaths": [
"C:\\Users\\kamorim\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
],
"originalTargetFrameworks": [
"netstandard2.0"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netstandard2.0": {
"targetAlias": "netstandard2.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netstandard2.0": {
"targetAlias": "netstandard2.0",
"dependencies": {
"NETStandard.Library": {
"suppressParent": "All",
"target": "Package",
"version": "[2.0.3, )",
"autoReferenced": true
},
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.1, )"
}
},
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.402\\RuntimeIdentifierGraph.json"
}
}
}
}
}
19 changes: 19 additions & 0 deletions obj/WooCommerce.NET.csproj.nuget.g.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\kamorim\.nuget\packages\;C:\Program Files (x86)\Microsoft\Xamarin\NuGet\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\kamorim\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft\Xamarin\NuGet\" />
</ItemGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
Loading