Getting Started
A convenience library has been provided in C# to facilitate use of the Margot Okapi API. Sample code is provided here. Note that a MargotOkapiException may be raised that will propagate any API exceptions.
You can find the margot client from the nuget package:
dotnet add package Margot.Client
Initialize Client
Provider your Margot Okapi api key. For security, we recommend not hard coding the api key in your code. Instead, load it via a configuration setting.
var moClient = new MargotOkapiClient(moApiKey);
Find Products
List<Product> products = await moClient.GetProducts(new ProductSearchCriteria() {
Name = "Premium"
});
Create Products
var newProduct = await moClient.CreateProduct(new Product() {
DurationCount = 1,
DurationType = "Months",
Name = "100 Labels " + Guid.NewGuid(),
Price = 5495,
ProductType = "FeatureSupplement",
SupplementalFeatureQty = 100,
});
Delete Product
await moClient.DeleteProduct(foundProduct.ProductId);
Create Stripe Customer
var newTenantStripeCustomer = await moClient.CreateTenantStripeCustomer(new StripeCustomerCreationData() {
Name = "Developer",
Email = "you@sightsource.net",
PaymentMethodId = "pm_card_discover" // special test value for Stripe's API
});
Preview Purchase
var purchaseDetails = await moClient.PreviewPurchase(new ProductPurchaseCriteria() {
ProductId = sampleProduct.ProductId,
PreferredPaymentDayOfMonth = 15
});
Execute a Purchase
purchaseDetails = await moClient.Purchase(new ProductPurchaseProcessingCriteria() {
ProductId = sampleProduct.ProductId,
PreferredPaymentDayOfMonth = 15,
Autorenew = true,
StripeCustomerId = newTenantStripeCustomer.StripeCustomerId,
TenantId = new Random().Next(5000, 10001)
});
This is an example, shell implementation of the GetTenantUsers callback that must be implemented and secured as described above. This would be a publicly accessible route since the validation occurs within the action definition.
Get Tenant Users Callback
/*
This is an example, shell implementation of the GetTenantUsers callback that must be implemented and secured as described above.
This would be a publicly accessible route since the validation occurs within the action definition.
*/
[HttpPost("[action]")]
public async Task<IActionResult> GetTenantUsers () {
string providedHash = ControllerContext.HttpContext.Request.Headers.ContainsKey(AppConstants.API_WEBOOK_HEADER_KEY)
? ControllerContext.HttpContext.Request.Headers[AppConstants.API_WEBOOK_HEADER_KEY].FirstOrDefault()
: null;
if (String.IsNullOrEmpty(providedHash)) {
throw new ApplicationException("Missing authentication hash header");
}
var validHash = _cipherService.ComputeSHA256Hash(_appSettings.TestSystemTenantApiKey, _appSettings.TestSystemTenantApiKey);
if (validHash != providedHash) {
throw new ApplicationException("Invalid authentication hash");
}
return Ok(new Tenant() {
TenantId = 1,
TenantName = "Test",
StripeCustomerId = "some-customer-id",
StripePaymentMethodId = "some-payment-method-id",
UsersToNotify = new List<Person>() {
new Person() {
PersonId = 300,
Email = "your_email@email.com",
FirstName = "AdminFirstName",
LastName = "AdminLastName",
MobilePhone = "AdminMobilePhone",
NotificationPreference = "EmailAndSMS"
},
new Person() {
PersonId = 500,
Email = "admin@email.com",
FirstName = "PersonFirstName",
LastName = "PersonLastName",
NotificationPreference = "Email"
}
}});
}