Skip to content

Commit

Permalink
Publish offer method added.
Browse files Browse the repository at this point in the history
  • Loading branch information
shafaqat-ali-cms365 committed Jan 28, 2024
1 parent 60b05df commit 28ccb71
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 48 deletions.
16 changes: 14 additions & 2 deletions EbaySharp/Controllers/EbayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public async Task<InventoryItem> GetInventoryItem(string SKU)
{
return await new InventoryController(accessToken).GetInventoryItem(SKU);
}
public async Task CreateInventoryItem(string SKU, InventoryItem inventoryItem)
public async Task CreateOrReplaceInventoryItem(string SKU, InventoryItem inventoryItem)
{
await new InventoryController(accessToken).CreateInventoryItem(SKU, inventoryItem);
await new InventoryController(accessToken).CreateOrReplaceInventoryItem(SKU, inventoryItem);
}
public async Task<Offers> GetOffers(string SKU)
{
Expand All @@ -68,6 +68,18 @@ public async Task<Offer> GetOffer(string offerID)
{
return await new InventoryController(accessToken).GetOffer(offerID);
}
public async Task<OfferCreated>CreateOffer(Offer offer, string locale)
{
return await new InventoryController(accessToken).CreateOffer(offer, locale);
}
public async Task UpdateOffer(string offerId, Offer offer, string locale)
{
await new InventoryController(accessToken).UpdateOffer(offerId, offer, locale);
}
public async Task<OfferPublished> PublishOffer(string offerId, string locale)
{
return await new InventoryController(accessToken).PublishOffer(offerId, locale);
}
public async Task DeleteInventoryItem(string SKU)
{
await new InventoryController(accessToken).DeleteInventoryItem(SKU);
Expand Down
31 changes: 28 additions & 3 deletions EbaySharp/Controllers/InventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using EbaySharp.Entities.Sell.Inventory.Location;
using EbaySharp.Entities.Sell.Inventory.Offer;
using EbaySharp.Source;
using System.Text.Json;

namespace EbaySharp.Controllers
{
Expand Down Expand Up @@ -36,11 +35,14 @@ public async Task DeleteInventoryItem(string SKU)
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.INVENTORY_ITEM, SKU)}";
await new RequestExecuter().ExecuteDeleteRequest(requestUrl, $"Bearer {accessToken}");
}
public async Task CreateInventoryItem(string SKU, InventoryItem inventoryItem)
public async Task CreateOrReplaceInventoryItem(string SKU, InventoryItem inventoryItem)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.INVENTORY_ITEM, SKU)}";
await new RequestExecuter().ExecutePutRequest(requestUrl, $"Bearer {accessToken}", inventoryItem.SerializeToJson(), inventoryItem.Locale);
}

#region OFFER

public async Task<Offers> GetOffers(string SKU)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.OFFERS, SKU)}";
Expand All @@ -51,6 +53,27 @@ public async Task<Offer> GetOffer(string offerID)
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.OFFER, offerID)}";
return await new RequestExecuter().ExecuteGetRequest<Offer>(requestUrl, $"Bearer {accessToken}");
}
public async Task<OfferCreated> CreateOffer(Offer offer, string locale)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{Constants.SELL.INVENTORY.METHODS.CREATE_OFFER}";
return await new RequestExecuter().ExecutePostRequest<OfferCreated>(requestUrl, $"Bearer {accessToken}", offer.SerializeToJson(), locale);
}
public async Task UpdateOffer(string offerID, Offer offer, string locale)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.OFFER, offerID)}";
await new RequestExecuter().ExecutePutRequest(requestUrl, $"Bearer {accessToken}", offer.SerializeToJson(), locale);
}
public async Task<OfferPublished> PublishOffer(string offerID, string locale)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.OFFER, offerID)}/publish";
return await new RequestExecuter().ExecutePostRequest<OfferPublished>(requestUrl, $"Bearer {accessToken}", null, locale);
}

#endregion


#region INVENTORY_LOCATION

public async Task<InventoryLocations> GetInventoryLocations(int limit, int offset)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.LOCATIONS, limit, offset)}";
Expand All @@ -64,12 +87,14 @@ public async Task<InventoryLocation> GetInventoryLocation(string merchantLocatio
public async Task CreateInventoryLocation(InventoryLocation inventoryLocation)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.LOCATION, inventoryLocation.MerchantLocationKey)}";
await new RequestExecuter().ExecutePostRequest(requestUrl, $"Bearer {accessToken}", inventoryLocation.SerializeToJson());
await new RequestExecuter().ExecutePostRequest(requestUrl, $"Bearer {accessToken}", inventoryLocation.SerializeToJson(), null);
}
public async Task DeleteInventoryLocation(string merchantLocationKey)
{
string requestUrl = $"{Constants.SERVER_URL}{Constants.SELL.INVENTORY.ENDPOINT_URL}{string.Format(Constants.SELL.INVENTORY.METHODS.LOCATION, merchantLocationKey)}";
await new RequestExecuter().ExecuteDeleteRequest(requestUrl, $"Bearer {accessToken}");
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class InventoryItem
{
public Availability Availability { get; set; }
public ConditionEnum Condition { get; set; }
public ConditionEnum? Condition { get; set; }
public string ConditionDescription { get; set; }
public List<ConditionDescriptor> ConditionDescriptors { get; set; }
public string[] GroupIDs { get; set; }
Expand Down
6 changes: 2 additions & 4 deletions EbaySharp/Entities/Sell/Inventory/InventoryItem/Product.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Nodes;

namespace EbaySharp.Entities.Sell.Inventory.InventoryItem
namespace EbaySharp.Entities.Sell.Inventory.InventoryItem
{
public class Product
{
Expand All @@ -15,6 +13,6 @@ public class Product
public string Subtitle { get; set; }
public string Title { get; set; }
public string[] UPC { get; set; }
public string[] VIDeoIDs { get; set; }
public string[] VideoIds { get; set; }
}
}
2 changes: 1 addition & 1 deletion EbaySharp/Entities/Sell/Inventory/Location/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Address
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public CountryCodeEnum Country { get; set; }
public CountryCodeEnum? Country { get; set; }
public string County { get; set; }
public string PostalCode { get; set; }
public string StateOrProvince { get; set; }
Expand Down
4 changes: 1 addition & 3 deletions EbaySharp/Entities/Sell/Inventory/Location/Location.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Net;

namespace EbaySharp.Entities.Sell.Inventory.Location
namespace EbaySharp.Entities.Sell.Inventory.Location
{
public class Location
{
Expand Down
12 changes: 6 additions & 6 deletions EbaySharp/Entities/Sell/Inventory/Offer/ListingPolicies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
public class ListingPolicies
{
public BestOfferTerms BestOfferTerms { get; set; }
public bool EBayPlusIfEligible { get; set; }
public string FulfillmentPolicyID { get; set; }
public string PaymentPolicyID { get; set; }
public string[] ProductCompliancePolicyIDs { get; set; }
public bool? EBayPlusIfEligible { get; set; }
public string FulfillmentPolicyId { get; set; }
public string PaymentPolicyId { get; set; }
public string[] ProductCompliancePolicyIds { get; set; }
public RegionalProductCompliancePolicies RegionalProductCompliancePolicies { get; set; }
public RegionalTakeBackPolicies RegionalTakeBackPolicies { get; set; }
public string ReturnPolicyID { get; set; }
public string ReturnPolicyId { get; set; }
public List<ShippingCostOverride> ShippingCostOverrides { get; set; }
public string TakeBackPolicyID { get; set; }
public string TakeBackPolicyId { get; set; }
}
}
25 changes: 12 additions & 13 deletions EbaySharp/Entities/Sell/Inventory/Offer/Offer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ namespace EbaySharp.Entities.Sell.Inventory.Offer
{
public class Offer
{
public int AvailableQuantity { get; set; }
public string CategoryID { get; set; }
public string CategoryId { get; set; }
public Charity Charity { get; set; }
public ExtendedProducerResponsibility ExtendedProducerResponsibility { get; set; }
public FormatTypeEnum Format { get; set; }
public bool HIDeBuyerDetails { get; set; }
public bool IncludeCatalogProductDetails { get; set; }
public FormatTypeEnum? Format { get; set; }
public bool? HideBuyerDetails { get; set; }
public bool? IncludeCatalogProductDetails { get; set; }
public Listing Listing { get; set; }
public string ListingDescription { get; set; }
public ListingDurationEnum ListingDuration { get; set; }
public ListingDurationEnum? ListingDuration { get; set; }
public ListingPolicies ListingPolicies { get; set; }
public string ListingStartDate { get; set; }
public int LotSize { get; set; }
public MarketplaceEnum MarketplaceID { get; set; }
public int? LotSize { get; set; }
public MarketplaceEnum? MarketplaceId { get; set; }
public string MerchantLocationKey { get; set; }
public string OfferID { get; set; }
public string OfferId { get; set; }
public PricingSummary PricingSummary { get; set; }
public int QuantityLimitPerBuyer { get; set; }
public int? QuantityLimitPerBuyer { get; set; }
public Regulatory Regulatory { get; set; }
public string SecondaryCategoryID { get; set; }
public string SKU { get; set; }
public OfferStatusEnum Status { get; set; }
public string SecondaryCategoryId { get; set; }
public string Sku { get; set; }
public OfferStatusEnum? Status { get; set; }
public string[] StoreCategoryNames { get; set; }
public Tax Tax { get; set; }
}
Expand Down
7 changes: 7 additions & 0 deletions EbaySharp/Entities/Sell/Inventory/Offer/OfferCreated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EbaySharp.Entities.Sell.Inventory.Offer
{
public class OfferCreated
{
public string OfferId { get; set; }
}
}
7 changes: 7 additions & 0 deletions EbaySharp/Entities/Sell/Inventory/Offer/OfferPublished.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EbaySharp.Entities.Sell.Inventory.Offer
{
public class OfferPublished
{
public string ListingId { get; set; }
}
}
8 changes: 3 additions & 5 deletions EbaySharp/Entities/Sell/Inventory/Offer/PricingSummary.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System.Diagnostics;

namespace EbaySharp.Entities.Sell.Inventory.Offer
namespace EbaySharp.Entities.Sell.Inventory.Offer
{
public class PricingSummary
{
public Amount AuctionReservePrice { get; set; }
public Amount AuctionStartPrice { get; set; }
public Amount MinimumAdvertisedPrice { get; set; }
public SoldOnEnum OriginallySoldForRetailPriceOn { get; set; }
public SoldOnEnum? OriginallySoldForRetailPriceOn { get; set; }
public Amount OriginalRetailPrice { get; set; }
public Amount Price { get; set; }
public MinimumAdvertisedPriceHandlingEnum PricingVisibility { get; set; }
public MinimumAdvertisedPriceHandlingEnum? PricingVisibility { get; set; }
}
}
2 changes: 1 addition & 1 deletion EbaySharp/Entities/Sell/Inventory/Offer/Tax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class Tax
{
public bool ApplyTax { get; set; }
public string ThirdPartyTaxCategory { get; set; }
public int VatPercentage { get; set; }
public float VatPercentage { get; set; }
}
}
1 change: 1 addition & 0 deletions EbaySharp/Source/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal struct METHODS
internal const string INVENTORY_ITEM = "/inventory_item/{0}";
internal const string OFFERS = "/offer?sku={0}";
internal const string OFFER = "/offer/{0}";
internal const string CREATE_OFFER = "/offer";
internal const string LOCATIONS = "/location?limit={0}&offset={1}";
internal const string LOCATION = "/location/{0}";
}
Expand Down
29 changes: 21 additions & 8 deletions EbaySharp/Source/RequestExecuter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,26 @@ public async Task ExecuteDeleteRequest(string requestUrl, string authHeaderValue
throw new Exception(responseContent);
}
}
private async Task<T> executePostRequest<T>(string requestUrl, string authHeaderValue, List<KeyValuePair<string, string>>? keyValuePayload, string? JSONPayload)
private async Task<T> executePostRequest<T>(string requestUrl, string authHeaderValue, List<KeyValuePair<string, string>>? keyValuePayload, string? JSONPayload, string? contentLanguage)
{
HttpResponseMessage response = await executeRequest(HttpMethod.Post, requestUrl, authHeaderValue, null, keyValuePayload, JSONPayload);
HttpResponseMessage response = await executeRequest(HttpMethod.Post, requestUrl, authHeaderValue, contentLanguage, keyValuePayload, JSONPayload);
string responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return responseContent.DeserializeToObject<T>();
}
throw new Exception(responseContent);
}
public async Task ExecutePutRequest(string requestUrl, string authHeaderValue, string JSONPayload, string contentLanguage)
//private async Task executePostRequest(string requestUrl, string authHeaderValue, List<KeyValuePair<string, string>>? keyValuePayload, string? JSONPayload, string? contentLanguage)
//{
// HttpResponseMessage response = await executeRequest(HttpMethod.Post, requestUrl, authHeaderValue, contentLanguage, keyValuePayload, JSONPayload);
// string responseContent = await response.Content.ReadAsStringAsync();
// if (response.IsSuccessStatusCode==false)
// {
// throw new Exception(responseContent);
// }
//}
public async Task ExecutePutRequest(string requestUrl, string authHeaderValue, string? JSONPayload, string? contentLanguage)
{
HttpResponseMessage response = await executeRequest(HttpMethod.Put, requestUrl, authHeaderValue, contentLanguage, null, JSONPayload);
string responseContent = await response.Content.ReadAsStringAsync();
Expand All @@ -68,13 +77,17 @@ public async Task ExecutePutRequest(string requestUrl, string authHeaderValue, s
throw new Exception(responseContent);
}
}
public async Task<T> ExecutePostRequest<T>(string requestUrl, string authHeaderValue, List<KeyValuePair<string, string>> keyValuePayload)
public async Task<T> ExecutePostRequest<T>(string requestUrl, string authHeaderValue, List<KeyValuePair<string, string>>? keyValuePayload)
{
return await executePostRequest<T>(requestUrl, authHeaderValue, keyValuePayload, null);
return await executePostRequest<T>(requestUrl, authHeaderValue, keyValuePayload, null, null);
}
public async Task ExecutePostRequest(string requestUrl, string authHeaderValue, string JSONPayload)
public async Task<T> ExecutePostRequest<T>(string requestUrl, string authHeaderValue, string? JSONPayload, string? contentLanguage)
{
HttpResponseMessage response = await executeRequest(HttpMethod.Post, requestUrl, authHeaderValue, null, null, JSONPayload);
return await executePostRequest<T>(requestUrl, authHeaderValue, null, JSONPayload, contentLanguage);
}
public async Task ExecutePostRequest(string requestUrl, string authHeaderValue, string JSONPayload, string? contentLanguage)
{
HttpResponseMessage response = await executeRequest(HttpMethod.Post, requestUrl, authHeaderValue, contentLanguage, null, JSONPayload);
string responseContent = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode==false)
{
Expand All @@ -83,7 +96,7 @@ public async Task ExecutePostRequest(string requestUrl, string authHeaderValue,
}
public async Task<T> ExecutePostRequest<T>(string requestUrl, string authHeaderValue, string? JSONPayload)
{
return await executePostRequest<T>(requestUrl, authHeaderValue, null, JSONPayload);
return await executePostRequest<T>(requestUrl, authHeaderValue, null, JSONPayload, null);
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Dictionary<string, string[]> aspects = new Dictionary<string, string[]>
{ "Type", new[] { "Helmet/Action" } }
};

await ebayController.CreateInventoryItem("test-sku-api", new InventoryItem()
await ebayController.CreateOrReplaceInventoryItem("test-sku-api", new InventoryItem()
{
Availability = new Availability() { ShipToLocationAvailability = new ShipToLocationAvailability() { Quantity = 3 } },
Condition = ConditionEnum.NEW,
Expand Down

0 comments on commit 28ccb71

Please sign in to comment.