.Net SDK for Voucherify - coupons, vouchers, promo codes http://www.voucherify.io
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
images
lib Added Price to Product #18 (#19) Aug 1, 2018
src
.gitignore
license
readme-Unity.md
readme-Xamarin.md
readme.md

readme.md

Official Voucherify SDK for .NET Framework

Frameworks supported | Dependencies | Setup | Callback or Async? | Unity | Xamarin | Contributing | Changelog

API: Vouchers | Campaigns | Distributions | Validations | Redemptions | Customers | Products | Products | Products | Promotions | Segments | Validation Rules


Frameworks supported

  • .NET 2.0 (Server, Client)
  • .NET 3.5 (Server, Client)
  • .NET 3.5 Unity (Client)
  • .NET 4.0 (Server, Client)
  • .NET 4.5 (Server, Client)
  • PCL (portable45-net45+win8+wp8+wpa81) (Server, Client)

Dependencies

The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:

Install-Package Newtonsoft.Json

PCL (portable45-net45+win8+wp8+wpa81) (Server, Client)

There could be a need to install additional packages in case the assemblies are not available in your framework. Those references has been removed from original package to support using Voucherify directly in Xamarin.Droid and Xamarin.iOS environments where both: HttpClient and async/await operations are supported without additional libraries.

Install-Package Microsoft.Net.Http
Install-Package Microsoft.Bcl
Install-Package Microsoft.Bcl.Build

Setup

Server Side Library

Install-Package Voucherify

Or simple use libraries from lib/{target-framework} folder:

  • Voucherify.dll - Server Side Library

Log-in to Voucherify web interface and obtain your Server Side Keys from Configuration:

var api = new Voucherify.Api(
            "<app_id>",
            "<token>")            
            .WithSSL();

You can also specify the API verison if needed:

var api = new Voucherify.Api(
            "<app_id>",
            "<token>")            
            .WithSSL()
            .WithVersion(Voucherify.Core.ApiVerions.v2017_04_20);

Client Side Library

Install-Package Voucherify.Client

Or simple use libraries from lib/{target-framework} folder:

  • Voucherify.Client.dll - Client Side Library

Log-in to Voucherify web interface and obtain your Client Side Keys from Configuration:

var api = new Voucherify.Client.Api(
    "<client_app_id>",
    "<client_token>",
    "<origin>")
    .WithSSL();

Callback or Async?

Callbacks Usage (.NET 2.0 - .NET 4.0)

api.Vouchers.Get("<your-voucher-code>", (response) =>
            {
                if (response.Exception != null)
                {
                    Console.WriteLine("Exception: {0}", response.Exception);
                }
                else
                {
                    Console.WriteLine("Voucher: {0}", response.Result);
                }
            });

Async Usage (.NET 4.5 standard + PCL (portable-net45+netcore45+wpa81+wp8))

        try
        {
            Voucher newVoucher = new Voucher()
            {
                Discount = Discount.WithAmountOff(10),
                Type = VoucherType.DiscountVoucher
            };

            Voucher voucher = await api.Vouchers.CreateVoucher(newVoucher);
            Console.WriteLine("Voucher: {0}", voucher);
        }
        catch (VoucherifyClientException exception)
        {
            Console.WriteLine("Exception: {0}", exception);
        }

Unity

Unity README

Xamarin

Xamarin README

API

This SDK is fully consistent with restufl API Voucherify provides. Detalied description and example responses you will find at official docs. Method headers point to more detalied params description you can use.

Vouchers API

Methods are provided within Api.Vouchers.* namespace.

Create Voucher

public async Task<DataModel.Voucher> Create(DataModel.Contexts.VoucherCreate voucher)
public async Task<DataModel.Voucher> Create(string code, DataModel.Contexts.VoucherCreate voucher)

public void Create(DataModel.Contexts.VoucherCreate voucher, Action<ApiResponse<DataModel.Voucher>> callback)
public void Create(string code, DataModel.Contexts.VoucherCreate voucher, Action<ApiResponse<DataModel.Voucher>> callback)

Check voucher object.

Get Voucher

public async Task<DataModel.Voucher> Get(string code)

public void Get(string code, Action<ApiResponse<DataModel.Voucher>> callback)

Update Voucher

public async Task<DataModel.Voucher> Update(string code, DataModel.Contexts.VoucherUpdate voucher)

public void Update(string code, DataModel.Contexts.VoucherUpdate voucher, Action<ApiResponse<DataModel.Voucher>> callback)

Delete Voucher

public async Task Delete(string code, DataModel.Queries.VoucherDelete query)

public void Delete(string code, DataModel.Queries.VoucherDelete query, Action<ApiResponse> callback)

List Vouchers

public async Task<IList<DataModel.Voucher>> List(DataModel.Queries.VouchersFilter filter)

public void List(DataModel.Queries.VouchersFilter filter, Action<ApiResponse<IList<DataModel.Voucher>>> callback)

Enable Voucher

public async Task<DataModel.Voucher> Enable(string code)

public void Enable(string code, Action<ApiResponse<DataModel.Voucher>> callback)

Disable Voucher

public async Task<DataModel.Voucher> Disable(string code)

public void Disable(string code, Action<ApiResponse<DataModel.Voucher>> callback)

Import Vouchers

public async Task<Core.DataModel.Empty> Import(List<DataModel.Contexts.VoucherImport> vouchers)

public void Import(List<DataModel.Contexts.VoucherImport> vouchers, Action<ApiResponse<Core.DataModel.Empty>> callback)

[Add Gift Balance]

public async Task<DataModel.Balance> AddGiftBalance(string code, DataModel.Contexts.VoucherAddGiftBalance balance)
        
public void AddGiftBalance(string code, DataModel.Contexts.VoucherAddGiftBalance balance, Action<ApiResponse<DataModel.Balance>> callback)

Campaigns API

Methods are provided within Api.Campaigns.* namespace.

Create Campaign

public async Task<DataModel.Campaign> Create(DataModel.Contexts.CampaignCreate campaign)

public void Create(DataModel.Contexts.CampaignCreate campaign, Action<ApiResponse<DataModel.Campaign>> callback)

Get Campaign

public async Task<DataModel.Campaign> Get(string name)

public void Get(string name, Action<ApiResponse<DataModel.Campaign>> callback)

[Update Campaign]

public async Task<DataModel.Campaign> Update(string name, DataModel.Contexts.CampaignUpdate campaign)

public void Update(string name, DataModel.Contexts.CampaignUpdate campaign, Action<ApiResponse<DataModel.Campaign>> callback)

[Delete Campaigns]

public async Task Delete(string name, DataModel.Queries.CampaignDelete query)
        
public void Delete(string name, DataModel.Queries.CampaignDelete query, Action<ApiResponse> callback)

[List Campaigns]

public async Task<DataModel.CampaignList> List(DataModel.Queries.CampaignFilter filter)
 
public void List(DataModel.Queries.CampaignFilter filter, Action<ApiResponse<DataModel.CampaignList>> callback)    

Add Voucher to Campaign

public async Task<DataModel.Voucher> AddVoucher(string name, DataModel.Contexts.CampaignAddVoucher addVoucherContext)

public void AddVoucher(string name, DataModel.Contexts.CampaignAddVoucher addVoucherContext, Action<ApiResponse<DataModel.Voucher>> callback)

Import Vouchers to Campaign

public async Task<Core.DataModel.Empty> ImportVouchers(string name, List<DataModel.Contexts.CampaignVoucherImport> addVoucherContext)

public void ImportVouchers(string name, List<DataModel.Contexts.CampaignVoucherImport> addVoucherContext, Action<ApiResponse<Core.DataModel.Empty>> callback)

Distributions API

Methods are provided within Api.Distributions.* namespace.

Publish Voucher

public async Task<DataModel.Publication> Publish(DataModel.Contexts.VoucherPublish context)

public void Publish(DataModel.Contexts.VoucherPublish context, Action<ApiResponse<DataModel.Publication>> callback)

Validations API

Methods are provided within Api.Validations.* namespace.

Validate Voucher

public async Task<DataModel.Validation> ValidateVoucher(string code, DataModel.Contexts.Validation context)

public void ValidateVoucher(string code, DataModel.Contexts.Validation context, Action<ApiResponse<DataModel.Validation>> callback)

[Validate Promotions]

public async Task<DataModel.Validation> ValidatePromotion(DataModel.Contexts.Validation context)

public void ValidatePromotion(DataModel.Contexts.Validation context, Action<ApiResponse<DataModel.Validation>> callback)

[Validate]

public async Task<DataModel.Validation> Validate(string code, DataModel.Contexts.Validation context)

public void Validate(string code, DataModel.Contexts.Validation context, Action<ApiResponse<DataModel.Validation>> callback)

Redemptions API

Methods are provided within Api.Redemptions.* namespace.

Redeem Voucher

public async Task<DataModel.Redemption> RedeemVoucher(string code, DataModel.Queries.RedemptionRedeem query, DataModel.Contexts.RedemptionRedeem context)
        
public void RedeemVoucher(string code, DataModel.Queries.RedemptionRedeem query, DataModel.Contexts.RedemptionRedeem context, Action<ApiResponse<DataModel.Redemption>> callback)        

[Redeem Promotion]

public async Task<DataModel.Redemption> RedeemPromotion(string promotionId, DataModel.Contexts.RedemptionRedeem context)

public void RedeemPromotion(string promotionId, DataModel.Contexts.RedemptionRedeem context, Action<ApiResponse<DataModel.Redemption>> callback)        

[Redeem]

public async Task<DataModel.Redemption> Redeem(string code, DataModel.Contexts.RedemptionRedeem context)

public void Redeem(string code, DataModel.Queries.RedemptionRedeem query, DataModel.Contexts.RedemptionRedeem context, Action<ApiResponse<DataModel.Results.RedemptionRedeem>> callback)

[Get Redemption]

public async Task<DataModel.Redemption> Get(string redemptionId)

public void Get(string redemptionId, Action<ApiResponse<DataModel.Redemption>> callback)

List Redemptions

public async Task<DataModel.RedemptionList> List(DataModel.Queries.RedemptionsFilter filter)

public void List(DataModel.Queries.RedemptionsFilter filter, Action<ApiResponse<DataModel.RedemptionList>> callback)

Get Voucher's Redemptions

public async Task<DataModel.VoucherRedemption> GetForVoucher(string code)

public void GetForVoucher(string code, Action<ApiResponse<DataModel.VoucherRedemption>> callback)

Rollback Redemption

public async Task<DataModel.Results.RedemptionRollback> Rollback(string redemptionId, DataModel.Queries.RedemptionRollback query, DataModel.Contexts.RedemptionRollback context)

public void Rollback(string redemptionId, DataModel.Queries.RedemptionRollback query, DataModel.Contexts.RedemptionRollback context, Action<ApiResponse<DataModel.Results.RedemptionRollback>> callback)

Check redemption rollback object.


Customers API

Methods are provided within Api.Customers.* namespace.

Create Customer

public async Task<DataModel.Customer> Create(DataModel.Contexts.CustomerCreate customer)

public void Create(DataModel.Contexts.CustomerCreate customer, Action<ApiResponse<DataModel.Customer>> callback)

Check customer object.

Get Customer

public async Task<DataModel.Customer> Get(string customerId)

public void Get(string customerId, Action<ApiResponse<DataModel.Customer>> callback)

Update Customer

public async Task<DataModel.Customer> Update(string customerId, DataModel.Contexts.CustomerUpdate customer)

public void Update(string customerId, DataModel.Contexts.CustomerUpdate customer, Action<ApiResponse<DataModel.Customer>> callback)

Delete Customer

public async Task Delete(string customerId)

public void Delete(string customerId, Action<ApiResponse> callback)

[List Customers]

public async Task<DataModel.CustomerList> List(DataModel.Queries.CustomerFilter filter)

public void List(DataModel.Queries.CustomerFilter filter, Action<ApiResponse<DataModel.CustomerList>> callback)

Products API

Methods are provided within Api.Products.* namespace.

Create Product

public async Task<DataModel.Product> Create(DataModel.Contexts.ProductCreate product)

public void Create(DataModel.Contexts.ProductCreate product, Action<ApiResponse<DataModel.Product>> callback)

Check product object.

Get Product

public async Task<DataModel.Product> Get(string productId)

public void Get(string productId, Action<ApiResponse<DataModel.Product>> callback)

Update Product

public async Task<DataModel.Product> Update(string productId, DataModel.Contexts.ProductUpdate product)

public void Update(string productId, DataModel.Contexts.ProductUpdate product, Action<ApiResponse<DataModel.Product>> callback)

Delete Product

public async Task Delete(string productId)

public void Delete(string productId, Action<ApiResponse> callback)

List Products

public async Task<DataModel.ProductList> List()

public void List(Action<ApiResponse<DataModel.ProductList>> callback)

Create SKU

public async Task<DataModel.Sku> CreateSku(string productId, DataModel.Contexts.SkuCreate sku)

public void CreateSku(string productId, DataModel.Contexts.SkuCreate sku, Action<ApiResponse<DataModel.Sku>> callback)

Check SKU object.

Get SKU

public async Task<DataModel.Sku> GetSku(string productId, string skuId)

public void GetSku(string productId, string skuId, Action<ApiResponse<DataModel.Sku>> callback)

Update SKU

public async Task<DataModel.Sku> UpdateSku(string productId, string skuId, DataModel.Contexts.SkuUpdate sku)

public void UpdateSku(string productId, string skuId, DataModel.Contexts.SkuUpdate sku, Action<ApiResponse<DataModel.Sku>> callback)

Delete SKU

public async Task DeleteSku(string productId, string skuId)

public void DeleteSku(string productId, string skuId, Action<ApiResponse> callback)

List all product SKUs

public async Task<DataModel.ProductSkus> ListSkus(string productId)

public void ListSkus(string productId, Action<ApiResponse<DataModel.ProductSkus>> callback)

Events API

Methods are provided within Api.Events.* namespace.

[Create Event]

public async Task<DataModel.Event> Create(DataModel.Contexts.EventCreate eventObject)

public void Create(DataModel.Contexts.EventCreate eventObject, Action<ApiResponse<DataModel.Event>> callback)

Orders API

Methods are provided within Api.Orders.* namespace.

[Create Order]

public async Task<DataModel.Order> Create(DataModel.Contexts.OrderCreate order)

public void Create(DataModel.Contexts.OrderCreate order, Action<ApiResponse<DataModel.Order>> callback)

[Get Order]

public async Task<DataModel.Order> Get(string orderId)

public void Get(string orderId, Action<ApiResponse<DataModel.Order>> callback)

[Update Order]

public async Task<DataModel.Order> Update(string orderId, DataModel.Contexts.OrderUpdate order)

public void Update(string orderId, DataModel.Contexts.OrderUpdate order, Action<ApiResponse<DataModel.Order>> callback)

[List Orders]

public async Task<DataModel.OrderList> List(DataModel.Queries.OrderFilter filter)

public void List(DataModel.Queries.OrderFilter filter, Action<ApiResponse<DataModel.OrderList>> callback)

Promotions API

Methods are provided within Api.Promotions.* namespace.

[Get Promotion Tier]

 public async Task<DataModel.PromotionTier> Get(string promotionTierId)

public void Get(string promotionTierId, Action<ApiResponse<DataModel.PromotionTier>> callback)

[List For Campaign]

public async Task<DataModel.PromotionTierList> ListForCampaign(string campaign)

public void ListForCampaign(string campaign, Action<ApiResponse<DataModel.PromotionTierList>> callback)

[Create Campaing]

public async Task<DataModel.Campaign> CreateCampaign(DataModel.Contexts.CampaignPromotionCreate promotionCampaign)

public void CreateCampaign(DataModel.Contexts.CampaignPromotionCreate promotionCampaign, Action<ApiResponse<DataModel.Campaign>> callback)

[Add Tier To Campaign]

public async Task<DataModel.PromotionTier> AddTierToCampaign(string campaignId, DataModel.Contexts.PromotionTierCreate promotionTier)

public void AddTierToCampaign(string campaignId, DataModel.Contexts.PromotionTierCreate promotionTier, Action<ApiResponse<DataModel.PromotionTier>> callback)

[Update Promotion Tier]

public async Task<DataModel.PromotionTier> Update(string promotionTierId, DataModel.Contexts.PromotionTierUpdate promotionTier)

public void Update(string promotionTierId, DataModel.Contexts.PromotionTierUpdate promotionTier, Action<ApiResponse<DataModel.PromotionTier>> callback)

[Delete Promotion Tier]

public async Task Delete(string promotionTierId)

public void Delete(string promotionTierId, Action<ApiResponse> callback)

Segments API

Methods are provided within Api.Segments.* namespace.

[Get Segment]

public async Task<DataModel.Segment> Get(string segmentId)

public void Get(string segmentId, Action<ApiResponse<DataModel.Segment>> callback)

[Create Segment]

 public async Task<DataModel.Segment> Create(DataModel.Contexts.SegmentCreate voucher)

public void Create(DataModel.Contexts.SegmentCreate voucher, Action<ApiResponse<DataModel.Segment>> callback)

[Delete Segment]

public async Task Delete(string segmentId)

public void Delete(string segmentId, Action<ApiResponse> callback)

Validation Rules API

Methods are provided within Api.ValidationRules.* namespace.

[Create Validation Rule]

public async Task<DataModel.ValidationRule> Create(DataModel.Contexts.ValidationRuleCreate validationRule)

public void Create(DataModel.Contexts.ValidationRuleCreate validationRule, Action<ApiResponse<DataModel.ValidationRule>> callback)

[Get Validation Rule]

public async Task<DataModel.ValidationRule> Get(string validationRuleId)

public void Get(string validationRuleId, Action<ApiResponse<DataModel.ValidationRule>> callback)

[Update Validation Rule]

public async Task<DataModel.ValidationRule> Update(string validationRuleId, DataModel.Contexts.ValidationRuleUpdate validationRule)

public void Update(string validationRuleId, DataModel.Contexts.ValidationRuleUpdate validationRule, Action<ApiResponse<DataModel.ValidationRule>> callback)

[Delete Validation Rule]

public async Task Delete(string validationRuleId)

public void Delete(string validationRuleId, Action<ApiResponse> callback)

Contributing

Bug reports and pull requests are welcome through GitHub Issues.

Changelog

  • 2018-08-01 - 4.3.2 - Added Price to Product
  • 2018-02-05 - 4.3.1 - Fixed Segments API endpoints. Fixed Library versioning.
  • 2018-02-04 - 4.3.0 - Added support for Api Versions. Added support for Orders, Events, Promotions, Segments and Validation Rules.
  • 2017-11-22 - 4.2.0 - Added 'ApplicableTo' property to Voucher.
  • 2017-10-24 - 4.1.2 - Added 'key' property to VoucherifyClientException. Removed private setters for Order and Customer entities.
  • 2017-08-30 - 4.1.1 - Added .ConfigureAwait(false) to all awaitable calls to prevent deadlocks when using the ASP.NET.
  • 2016-12-19 - 4.1.0 - Added missing methods. Created two additional namespaces: Validations and Distributions. Support for gift.balance (for Gift Vouchers).
  • 2016-11-17 - 4.0.2 - Fixed issue with InnerException serialization
  • 2016-11-17 - 4.0.1 - Remove dependencies for Portable library to allow use it in Xamarin Applications.
  • 2016-11-16 - 4.0.0 - Define separated libraries: Voucherify (server side methods) and Voucherify.Client (client side methods). Define Voucherify.Core. Define Voucherify.DataModel. Client Supported Apis: Vouchers, Redemptions. Server Supported Apis: Vouchers, Redemptions, Campaigns, Customers, Products.

  • 2016-11-02 - 3.1.0 - Added Validate method for Vouchers. Fixed issue with DiscountType mapping.
  • 2016-09-13 - 3.0.0 - Removed dependencies to RSP.Promise and RestSharp, stick to base libraries only.

  • 2016-09-06 - 2.2.0 - Added Portable Class Library (portable45-net45+win8+wp8+wpa81). Added Order Items. Improved Error Handling.
  • 2016-08-17 - 2.1.0 - Fixed Request Header for .Net 3.5+ and empty metadata issue.
  • 2016-07-21 - 2.0.0 - Fixed Data Conversion Problems. Added Update method for Vouchers, Added Code Pattern for Voucher creation.

  • 2016-07-11 - 1.1.3 - Fixed DLLs
  • 2016-07-11 - 1.1.2 - Fixed package dependencies for .Net Framework 3.5+.
  • 2016-07-11 - 1.1.1 - Fixed package dependencies.
  • 2016-07-11 - 1.1.0 - Added support for .Net Framework 2.0 with classic callback approach. Get rid of DataContract attribute.

  • 2016-07-03 - 1.0.0 - Replace async/await with RSG.Promise library. Use RestSharp instead of HttpClient.
  • 2016-07-03 - 0.2.0 - Introduced support for .Net Framework 3.5.
  • 2016-06-26 - 0.1.0 - Initial version of SDK that supports Vouchers, Redemption and Customer endpoints.
  • 2016-07-11 - 1.1.1 - Fixed package dependencies.
  • 2016-07-11 - 1.1.0 - Added support for .Net Framework 2.0 with classic callback approach. Get rid of DataContract attribute.
  • 2016-07-03 - 1.0.0 - Replace async/await with RSG.Promise library. Use RestSharp instead of HttpClient.
  • 2016-07-03 - 0.2.0 - Introduced support for .Net Framework 3.5.
  • 2016-06-26 - 0.1.0 - Initial version of SDK that supports Vouchers, Redemption and Customer endpoints.