Order Nce products¶
Use sample below to order a Nce product.
using Crayon.Api.Sdk;
using Crayon.Api.Sdk.Domain.Csp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ClientSdkSample
{
internal class Program
{
static async Task Main(string[] args)
{
var clientId = "XXXXXX";
var clientSecret = "XXXXXX";
var userName = "XXXX@XXXX.XXX EMAIL";
var password = "XXXXXX";
var apiUrl = "https://api.crayon.com/";
var client = new CrayonApiClient(apiUrl);
var token = client.Tokens.GetUserToken(clientId, clientSecret, userName, password).GetData().AccessToken;
var order = new AssetOrder();
order.ResellerCustomerId = XXXX; //customerTenantId // Cloud Account ID
order.OrderLines = new List<AssetOrderLine>();
var orderLine = new AssetOrderLine();
orderLine.BillingCycle = BillingCycleType.Monthly;
orderLine.ProductId = "CFQ7TTC0LF8R";
orderLine.ProductVariantId = 2622144;
orderLine.Quantity = 1;
orderLine.SkuId = "0010";
orderLine.TermDuration = "P1M";
orderLine.Type = AssetType.Subscription;
order.OrderLines.Add(orderLine);
var verifyResult = await client.Assets.VerifyAsync(token, order);
if (verifyResult.IsSuccessStatusCode)
{
if (verifyResult.Data.OrderLines.Any(x => x.Errors.Any()))
{
//order lines with error
foreach (var errRow in verifyResult.Data.OrderLines.Where(x => x.Errors.Any()))
{
foreach (var errItem in errRow.Errors)
{
Console.WriteLine($"Error: {errItem.Description}");
}
}
}
else
{
var checkoutResult = await client.Assets.CheckoutAsync(token, verifyResult.Data);
if (checkoutResult.IsSuccessStatusCode)
{
//successful
Console.WriteLine("Purchase request successfully added to the queue.");
}
else
{
//connection problem
Console.WriteLine("Checkout failed.");
}
}
}
else
{
//connection problem
Console.WriteLine("Verify failed.");
}
}
}
}