diff --git a/SquareSpaceSharp/Entities/Profile.cs b/SquareSpaceSharp/Entities/Profile.cs new file mode 100644 index 0000000..ab29aec --- /dev/null +++ b/SquareSpaceSharp/Entities/Profile.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace SquareSpaceSharp.Entities +{ + public class Profile + { + /// + /// The profile's system identifier + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Profile first name. + /// + [JsonProperty("firstName")] + public string FirstName { get; set; } + + /// + /// Profile last name. + /// + [JsonProperty("lastName")] + public string LastName { get; set; } + + /// + /// Profile email address. + /// + [JsonProperty("email")] + public string Email { get; set; } + + /// + /// Indicates whether the profile has an account with the website. + /// + [JsonProperty("hasAccount")] + public bool HasAccount { get; set; } + + /// + /// Indicates whether the profile has any commerce orders or donations with the website. + /// + [JsonProperty("isCustomer")] + public bool CustomerEmail { get; set; } + + /// + /// ISO 8601 UTC date and time string; represents when the profile was created. + /// + [JsonProperty("createdOn")] + public string CreatedOn { get; set; } + + /// + /// Profile’s address. + /// An approximate address for the user based on existing data; + /// it should not be used for shipping or billing purposes. + /// Field is `null` if an approximate address can't be determined. + /// + [JsonProperty("address")] + public Address Address { get; set; } + + /// + /// Indicates whether the profile opted to receive marketing. + /// + [JsonProperty("acceptsMarketing")] + public bool AcceptsMarketing { get; set; } + + /// + /// Summary of profile’s commerce transactions. + /// If a profile has no commerce transactions, the object is still returned with `null` or `0` values. + /// This information is calculated asynchronously; there may be a slight delay between + /// when an order is created, and when it's reflected in the object. + /// + [JsonProperty("transactionsSummary")] + public TransactionsSummary TransactionSummary { get; set; } + + } +} \ No newline at end of file diff --git a/SquareSpaceSharp/Entities/ProfileCollection.cs b/SquareSpaceSharp/Entities/ProfileCollection.cs new file mode 100644 index 0000000..158fb5f --- /dev/null +++ b/SquareSpaceSharp/Entities/ProfileCollection.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace SquareSpaceSharp.Entities +{ + public class ProfileCollection + { + /// + /// An array of order resource objects, which will be empty if the store doesn't have any orders yet. + /// + [JsonProperty("Profiles")] + public IEnumerable Profiles { get; set; } + + /// + /// An object containing the following fields: + /// + [JsonProperty("pagination")] + public Pagination Pagination { get; set; } + } +} diff --git a/SquareSpaceSharp/Entities/ProfileQueryParameters.cs b/SquareSpaceSharp/Entities/ProfileQueryParameters.cs new file mode 100644 index 0000000..dc1485c --- /dev/null +++ b/SquareSpaceSharp/Entities/ProfileQueryParameters.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using SquareSpaceSharp.Infrastructure; +using System.Net; +using System.Text; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace SquareSpaceSharp.Entities +{ + public class ProfileQueryParameters : Parameterizable + { + /// + /// Type: A string token, returned from the pagination.nextPageCursor of a previous response.Identifies where the next page of results should begin.If this parameter is not present or empty, the first page of order data will be returned. + /// + [JsonProperty("cursor")] + public string Cursor { get; set; } + + /// + /// optional, values include "isCustomer" and/or "hasAccount", or "Email". + /// The "email" filter cannot be used with "isCUstomer" or "hasAccount" + /// Semicolon separated list used to filter profile results: + /// isCustomer: Value must be true; false currently not supported + /// hasAccount: Value must be true; false currently not supported + /// email: Valid email address with URL-encoded characters; case insensitive + /// filter=isCustomer,true;hasAccount,true + /// + [JsonProperty("filter")] + public string Filter { get; set; } + + /// + /// optional, values include: asc or dsc + /// Identifies the sort direction of the result list; asc for ascending or dsc for descending. + /// If parameter is not specified, the returned list is in descending order by sortField or by profile id if sortField is not specified. + /// + [JsonProperty("sortDirection")] + public string SortDirection { get; set; } + + /// + /// optional; values include: createdOn, id, email, or lastName + /// Identifies the sort field of the result list: + /// id: Unique id of a Profile + /// lastName: Last name of a profile + /// createdOn: ISO 8601 UTC date and time when a profile was created + /// email: Email address of a profile + /// + [JsonProperty("sortField")] + public string FulfillmentStatus { get; set; } + } +} \ No newline at end of file diff --git a/SquareSpaceSharp/Entities/TransactionsSummary.cs b/SquareSpaceSharp/Entities/TransactionsSummary.cs new file mode 100644 index 0000000..71647bd --- /dev/null +++ b/SquareSpaceSharp/Entities/TransactionsSummary.cs @@ -0,0 +1,66 @@ +using Newtonsoft.Json; + +namespace SquareSpaceSharp.Entities +{ + public class TransactionsSummary + { + /// + /// ISO 8601 UTC date and time string; represents when the profile’s first order was submitted. + /// + [JsonProperty("firstOrderSubmittedOn")] + public string FirstOrderSubmittedOn { get; set; } + + /// + /// ISO 8601 UTC date and time string; represents when the profile’s last order was submitted. + /// + [JsonProperty("lastOrderSubmittedOn")] + public string LastOrderSubmittedOn { get; set; } + + + /// + /// Count of orders submitted. + /// + [JsonProperty("orderCount")] + public int OrderCount { get; set; } + + /// + /// Monetary amount with 1,000,000 limit and no markers for the dollar amount. + // Conforms to the selected ISO currency's precision. + // (E.g., JPY uses 123, but USD uses 123.00 or 123.) + /// + [JsonProperty("totalOrderAmount")] + public CurrencyValue TotalOrderAmount { get; set; } + + /// + /// Total of all order refunds. + /// + [JsonProperty("totalRefundAmount")] + public CurrencyValue TotalRefundAmount { get; set; } + + + /// + /// ISO 8601 UTC date and time string; represents when the profile’s first donation was submitted. + /// + [JsonProperty("firstDonationSubmittedOn")] + public string FirstDonationSubmittedOn { get; set; } + + /// + /// ISO 8601 UTC date and time string; represents when the profile’s latest donation was submitted. + /// + [JsonProperty("lastDonationSubmittedOn")] + public string LastDonationSubmittedOn { get; set; } + + + /// + /// Count of donations submitted. + /// + [JsonProperty("donationCount")] + public int DonationCount { get; set; } + + /// + /// Total of all order refunds. + /// + [JsonProperty("totalDonationAmount")] + public CurrencyValue TotalDonationAmount { get; set; } + } +} \ No newline at end of file diff --git a/SquareSpaceSharp/Services/Profile/ProfileService.cs b/SquareSpaceSharp/Services/Profile/ProfileService.cs new file mode 100644 index 0000000..3284050 --- /dev/null +++ b/SquareSpaceSharp/Services/Profile/ProfileService.cs @@ -0,0 +1,47 @@ +using System.Net.Http; +using System.Threading.Tasks; +using SquareSpaceSharp.Entities; +using SquareSpaceSharp.Extensions; +using SquareSpaceSharp.Infrastructure; + +namespace SquareSpaceSharp.Services.Profile +{ + public class ProfileService : SquareSpaceService + { + /// + /// Creates a new instance of . + /// + /// App Secret Api Key + public ProfileService(string secretApiKey) : base(secretApiKey) + { + } + + /// + /// Returns collection of profiles + /// + /// Order query parameters + public virtual async Task GetProfilesAsync(OrderQueryParameters queryParameters = null) + { + var req = PrepareRequest("profiles",isCommerce:false); + + if (queryParameters != null) + { + req.QueryParams.AddRange(queryParameters.ToParameters()); + } + + return await ExecuteRequestAsync(req, HttpMethod.Get); + } + + /// + /// Returns a profiles that match ID. + /// + /// Requested profile ID + /// The . + public virtual async Task GetProfilesByIdAsync(string profileId) + { + var req = PrepareRequest($"profiles/{profileId}",isCommerce:false); + + return await ExecuteRequestAsync(req, HttpMethod.Get); + } + } +} \ No newline at end of file diff --git a/SquareSpaceSharp/Services/SquareSpaceService.cs b/SquareSpaceSharp/Services/SquareSpaceService.cs index 741e86a..9dfc41c 100644 --- a/SquareSpaceSharp/Services/SquareSpaceService.cs +++ b/SquareSpaceSharp/Services/SquareSpaceService.cs @@ -59,6 +59,19 @@ protected RequestUri PrepareRequest(string apiVersion, string path) return new RequestUri(new Uri($"https://api.squarespace.com/{apiVersion}/commerce/{path}")); } + protected RequestUri PrepareRequest(string path,bool isCommerce) + { + if (isCommerce) { + return new RequestUri(new Uri($"https://api.squarespace.com/1.0/commerce/{path}")); + + } + else + { + return new RequestUri(new Uri($"https://api.squarespace.com/1.0/{path}")); + + } + } + /// /// Prepares a request to the path and appends the shop's access token header if applicable. /// diff --git a/SquareSpaceSharp/SquareSpaceSharp.csproj b/SquareSpaceSharp/SquareSpaceSharp.csproj index a4fd53b..ec3543e 100644 --- a/SquareSpaceSharp/SquareSpaceSharp.csproj +++ b/SquareSpaceSharp/SquareSpaceSharp.csproj @@ -1,6 +1,6 @@  - netcoreapp2.1; + net7.0 SquareSpaceSharp SquareSpaceSharp 1.0.1