voucherifyio / voucherify-dotNET-sdk

.Net SDK for Voucherify - coupons, vouchers, promo codes http://www.voucherify.io
http://www.voucherify.io
MIT License
12 stars 16 forks source link
dotnet sdk voucher

Official Voucherify SDK for .NET Framework

Build Status Build Status Build Status


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

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


Build

Run with dotnet cli

Build & Pack: sh ./run-build.sh Tests: sh ./run-tests.sh

Run with nuget

Prerequisites

Tests

nuget restore ./src/Tests/Voucherify.Tests.csproj
msbuild /p:"Configuration=Release" ./src/Tests/Voucherify.Tests.csproj
mono ./testrunner/xunit.runner.console.2.2.0/tools/xunit.console.exe ./src/Tests/bin/Release/netcoreapp2.0/Voucherify.Tests.dll

Server

nuget restore ./src/Voucherify/Voucherify.csproj
msbuild /p:"Configuration=Release" ./src/Voucherify/Voucherify.csproj
nuget pack ./src/Voucherify/Voucherify.nuspec

Client

nuget restore ./src/Voucherify/Voucherify.Client.csproj
msbuild /p:"Configuration=Release" ./src/Voucherify/Voucherify.Client.csproj
nuget pack ./src/Voucherify/Voucherify.Client.nuspec

Running Examples

msbuild /p:"Configuration=Release" ./src/Examples/Examples.Voucherify.net45/Examples.Voucherify.net45.csproj
mono ./src/Examples/Examples.Voucherify.net45/bin/Release/Examples.Voucherify.net45.exe <api_key> <api_token> <voucher_code>

Frameworks supported

TLS support

Due to security resons old versions of TLS (1.0 and 1.1) will be deprecated soon and our api will not accept any calls using those layers. Thus, we decided to switch .NET SDK to use TLS 1.2 already. The following articles will help you setup your environemnt:

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

Setup

Server Side Library

Install-Package Voucherify

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

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.v2018_08_01);

API Endpoint

Optionally, you can specify API Endpoint if you want to use Voucherify running in a specific region.

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

Client Side Library

Install-Package Voucherify.Client

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

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();

API Endpoint

Optionally, you can specify API Endpoint if you want to use Voucherify running in a specific region.

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

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, .NET 6.0 .NET Standard 2.0)

        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);
        }

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)
public async Task Delete(string code, Core.DataModel.ForcedOperation query query)

public void Delete(string code, Action<ApiResponse> callback)
public void Delete(string code, Core.DataModel.ForcedOperation query 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)
public async Task Delete(string name, Core.DataModel.ForcedOperation query query)

public void Delete(string name, Action<ApiResponse> callback)
public void Delete(string name, Core.DataModel.ForcedOperation query 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.PublicationSingle> Publish(DataModel.Contexts.VoucherPublishSingle context)

public void Publish(DataModel.Contexts.VoucherPublishSingle context, Action<ApiResponse<DataModel.PublicatioSingle>> callback)

Create Publication

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

public void CreatePublication(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 Promotion]

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)

[Validate Stackable]

public async Task<DataModel.StackableValidation> Validate(DataModel.Contexts.StackableValidation context)

public void Validate(DataModel.Contexts.StackableValidation context, Action<ApiResponse<DataModel.StackableValidation>> 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.

[Redeem Stackable]

public async Task<DataModel.StackableRedemption> Redeem(DataModel.Contexts.StackableRedemptionRedeem context)

public void Redeem(DataModel.Contexts.StackableRedemptionRedeem context, Action<ApiResponse<DataModel.StackableRedemption>> callback)

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)

[Update Consents]

public async Task<Core.DataModel.Empty> UpdateConsents(string customerId, DataModel.Contexts.CustomerConsentUpdate update)

public void UpdateConsents(string customerId, DataModel.Contexts.CustomerConsentUpdate update, Action<ApiResponse<Core.DataModel.Empty>> callback)

Consents API

Methods are provided within Api.Consents.* namespace.

[List Consents]

public async Task<DataModel.ConsentAndGroupList> List()

public void List(Action<ApiResponse<DataModel.ConsentAndGroupList>> 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 async Task Delete(string productId, Core.DataModel.ForcedOperation query)

public void Delete(string productId, Action<ApiResponse> callback)
public void Delete(string productId, Core.DataModel.ForcedOperation query, 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 async Task DeleteSku(string productId, string skuId, Core.DataModel.ForcedOperation query)

public void DeleteSku(string productId, string skuId, Action<ApiResponse> callback)
public void DeleteSku(string productId, string skuId, Core.DataModel.ForcedOperation query, 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.BusinessValidationRule> Create(DataModel.Contexts.BusinessValidationRuleCreate validationRule)

public void Create(DataModel.Contexts.BusinessValidationRuleCreate validationRule, Action<ApiResponse<DataModel.BusinessValidationRule>> callback)

[Get Validation Rule]

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

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

[Update Validation Rule]

public async Task<DataModel.BusinessValidationRule> Update(string validationRuleId, DataModel.Contexts.BusinessValidationRuleUpdate validationRule)

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

[Delete Validation Rule]

public async Task Delete(string validationRuleId)

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

[Create Validation Rule Assignment]

public async Task<DataModel.BusinessValidationRuleAssignment> CreateAssignment(string validationRuleId, DataModel.Contexts.BusinessValidationRuleAssignmentCreate validationRule)

public void CreateAssignment(string validationRuleId, DataModel.Contexts.BusinessValidationRuleAssignmentCreate validationRule, Action<ApiResponse<DataModel.BusinessValidationRuleAssignment>> callback)

[Delete Validation Rule Assignment]

public async Task DeleteAssignment(string validationRuleId, string assignmentId)

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

[List Validation Rules]

public async Task<DataModel.BusinessValidationRuleList> List(DataModel.Queries.BusinessValidationRuleFilter filter)

public void List(DataModel.Queries.BusinessValidationRuleFilter filter, Action<ApiResponse<DataModel.BusinessValidationRuleList>> callback)

[List Validation Rule Assignments]

public async Task<DataModel.BusinessValidationRuleAssignmentList> ListAssignments(string validationRuleId, DataModel.Queries.BusinessValidationRuleAssignmentFilter filter)

public void ListAssignments(string validationRuleId, DataModel.Queries.BusinessValidationRuleAssignmentFilter filter, Action<ApiResponse<DataModel.BusinessValidationRuleAssignmentList>> callback)

Contributing

Bug reports and pull requests are welcome through GitHub Issues.

Changelog