/// <summary> /// Creates a fake <see cref="ReceiptClient" /> and instruments it to make use of the Azure Core /// Test Framework functionalities. /// </summary> /// <returns>The instrumented <see cref="ReceiptClient" />.</returns> private ReceiptClient CreateInstrumentedClient() { var fakeEndpoint = new Uri("http://localhost"); var fakeCredential = new AzureKeyCredential("fakeKey"); var client = new ReceiptClient(fakeEndpoint, fakeCredential); return(InstrumentClient(client)); }
/// <summary> /// Creates a <see cref="ReceiptClient" /> with the endpoint and API key provided via environment /// variables and instruments it to make use of the Azure Core Test Framework functionalities. /// </summary> /// <returns>The instrumented <see cref="ReceiptClient" />.</returns> private ReceiptClient CreateInstrumentedClient() { var endpointEnvironmentVariable = Environment.GetEnvironmentVariable(TestEnvironment.EndpointEnvironmentVariableName); var keyEnvironmentVariable = Environment.GetEnvironmentVariable(TestEnvironment.ApiKeyEnvironmentVariableName); Assert.NotNull(endpointEnvironmentVariable); Assert.NotNull(keyEnvironmentVariable); var endpoint = new Uri(endpointEnvironmentVariable); var credential = new AzureKeyCredential(keyEnvironmentVariable); var client = new ReceiptClient(endpoint, credential); return(InstrumentClient(client)); }
public async Task <VerifyPurchaseResult> VerifyPurchase(SKPaymentTransaction transaction) { bool success; string error; try { Logger.Log("VerifyPurchase ..."); var encodedReceipt = EncodeBase64(transaction.TransactionReceipt.ToString()); var response = await ReceiptClient.Add(encodedReceipt); if (response != null) { if (response.Success) { Logger.Log("Verification successful"); error = null; success = true; } else { Logger.Log("Verification failed: " + response.ErrorCode + ": " + response.ErrorMessageClean); error = response.ErrorMessageClean; success = false; } } else { Logger.Log("Verification failed: response is null"); error = string.Empty; success = false; } } catch (Exception e) { Logger.Log("Verification Exception: " + e.ToString()); error = e.ToString(); success = false; } return(new VerifyPurchaseResult() { Success = success, Error = error }); }
public async void PostReceipt() { ReceiptClient client = this.CreateClient(); Receipt receipt = new Receipt(); receipt.Date = DateTime.Now; receipt.UserId = 1; ReceiptEntry entry = new ReceiptEntry(); entry.Amount = 30m; receipt.Entries = new List <ReceiptEntry> { entry }; Receipt saved = await client.Save(receipt); }
static async Task AnalyzeReceipt(ReceiptClient client) { var filePath = "/Users/chstone/Downloads/contoso-allinone.jpg"; using var stream = File.OpenRead(filePath); var resp = await client.ExtractReceiptAsync(stream, FormContentType.Jpeg, true); var result = resp.Value; Console.WriteLine($"Receipt:"); Console.WriteLine($" Start: {result.PageRange.StartPageNumber}"); Console.WriteLine($" End: {result.PageRange.EndPageNumber}"); Console.WriteLine($" Type: {result.ReceiptType}"); Console.WriteLine($" MerchantName: {result.MerchantName}"); Console.WriteLine($" MerchantAddress: {result.MerchantAddress}"); Console.WriteLine($" MerchantPhoneNumber: {result.MerchantPhoneNumber}"); Console.WriteLine($" TransactionDate: {result.TransactionDate}"); Console.WriteLine($" TransactionTime: {result.TransactionTime}"); Console.WriteLine($" TransactionDate2: {result.ExtractedFields["TransactionDate"].Text}"); Console.WriteLine($" Subtotal: {result.Subtotal}"); Console.WriteLine($" Tax: {result.Tax}"); Console.WriteLine($" Tip: {result.Tip}"); Console.WriteLine($" Total: {result.Total}"); Console.WriteLine($" Items:"); foreach (var item in result.Items) { Console.WriteLine($" - Name: {item.Name}"); Console.WriteLine($" - Quantity: {item.Quantity}"); // Console.WriteLine($" - Price: {item.Price}"); Console.WriteLine($" - TotalPrice: {item.TotalPrice}"); } Console.WriteLine($" Page:"); Console.WriteLine($" Number: {result.RawExtractedPage.Page}"); Console.WriteLine($" Width: {result.RawExtractedPage.Width} {result.RawExtractedPage.Unit}"); Console.WriteLine($" Height: {result.RawExtractedPage.Height} {result.RawExtractedPage.Unit}"); Console.WriteLine($" Angle: {result.RawExtractedPage.Angle}"); Console.WriteLine($" Language: {result.RawExtractedPage.Language}"); Console.WriteLine($" LineCount: {result.RawExtractedPage.Lines.Count}"); }
static async Task Main(string[] args) { var endpoint = Environment.GetEnvironmentVariable(EnvEndpoint) ?? throw new ArgumentNullException(EnvEndpoint); var key = Environment.GetEnvironmentVariable(EnvApiKey) ?? throw new ArgumentNullException(EnvApiKey); var frEndpoint = new Uri(endpoint); var frKey = new FormRecognizerApiKeyCredential(key); var frOptions = new FormRecognizerClientOptions(ServiceVersion.V2_0_Preview); var custom = new CustomFormClient(frEndpoint, frKey, frOptions); var receipts = new ReceiptClient(frEndpoint, frKey, frOptions); var layout = new FormLayoutClient(frEndpoint, frKey, frOptions); // await TrainCustomModelWithLabels(custom); // await AnalyzeWithCustomModelWithLabels(custom); // await AnalyzeLayout(layout); // await AnalyzeReceipt(receipts); // await GetModelSummary(custom); // await DeleteModel(custom); await Task.CompletedTask; }
public async void GetReceiptByDateRange() { ReceiptClient client = this.CreateClient(); IEnumerable <Receipt> result = await client.GetReceiptsByDates(1, null, DateTime.Now); }
public async void GetReceipts() { ReceiptClient client = this.CreateClient(); IEnumerable <Receipt> result = await client.GetReceipts(1); }
public async void GetReceipt() { ReceiptClient client = this.CreateClient(); Receipt result = await client.GetReceipt(1, 2); }