using System; using System.Collections.Generic; using System.Text.Json; using System.Threading.Tasks; using Complyance.SDK; using Complyance.SDK.Exceptions; using Complyance.SDK.Models; using Xunit; using Environment = Complyance.SDK.Models.Environment; namespace Complyance.SDK.TestProject { public class UAETaxInvoiceTest { private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions { WriteIndented = true }; private const string DefaultApiKey = "ak_dfc7321146db8cfcf9cb35c539fa"; private const string SourceName = "A"; private const string SourceVersion = "1"; private static readonly Environment SdkEnvironment = Environment.Sandbox; private static readonly Country TestCountry = Country.AE; static UAETaxInvoiceTest() { var sources = new List { new Source(SourceName, SourceVersion, SourceType.FirstParty) }; var apiKey = System.Environment.GetEnvironmentVariable("COMPLYANCE_API_KEY"); if (string.IsNullOrWhiteSpace(apiKey)) { apiKey = DefaultApiKey; } var config = new SDKConfig(apiKey, SdkEnvironment, sources); GETSUnifySDK.Configure(config); } [Fact] public async Task TestUAETaxInvoiceFlow() { var payload = CreateUAETestPayload(); var documentType = GetsDocumentType.NewBuilder() .Base(BASE.TAX_INVOICE) .Build(); Console.WriteLine("=== UAE Tax Invoice Flow ==="); Console.WriteLine($"URL: {SdkEnvironment.GetBaseUrl()}"); Console.WriteLine("REQUEST:"); Console.WriteLine(JsonSerializer.Serialize(payload, JsonOptions)); UnifyResponse response; try { response = await GETSUnifySDK.PushToUnifyAsync( SourceName, SourceVersion, documentType, TestCountry, Operation.Single, Mode.Documents, Purpose.Invoicing, payload); } catch (SDKException e) { var message = FirstNonEmpty(e.Message, e.ErrorDetail?.Message, "UAE flow failed"); Console.Error.WriteLine($"❌ UAE Tax Invoice Flow failed: {message}"); if (e.ErrorDetail != null) { Console.Error.WriteLine($" Error Code: {e.ErrorDetail.Code}"); Console.Error.WriteLine($" Message: {FirstNonEmpty(e.ErrorDetail.Message, message)}"); if (!string.IsNullOrWhiteSpace(e.ErrorDetail.Suggestion)) { Console.Error.WriteLine($" Suggestion: {e.ErrorDetail.Suggestion}"); } } throw; } Assert.NotNull(response); Assert.NotNull(response.Status); Console.WriteLine("RESPONSE:"); Console.WriteLine(JsonSerializer.Serialize(response, JsonOptions)); if ("error".Equals(response.Status, StringComparison.OrdinalIgnoreCase)) { var errorCode = response.Error?.Code.ToString() ?? "UNKNOWN"; var message = FirstNonEmpty(response.Error?.Message, response.Message, "UAE flow failed"); var suggestion = response.Error?.Suggestion; Console.Error.WriteLine($"❌ UAE Tax Invoice Flow failed: {message}"); Console.Error.WriteLine($" Status: {FirstNonEmpty(response.Status, "unknown")}"); Console.Error.WriteLine($" Error Code: {errorCode}"); Console.Error.WriteLine($" Message: {message}"); Console.Error.WriteLine($" Response Message: {FirstNonEmpty(response.Message, "(empty)")}"); if (!string.IsNullOrWhiteSpace(suggestion)) { Console.Error.WriteLine($" Suggestion: {suggestion}"); } throw new SDKException(message); } Console.WriteLine($"✅ Status: {response.Status}"); } private static string FirstNonEmpty(params string?[] values) { foreach (var value in values) { if (!string.IsNullOrWhiteSpace(value)) { return value; } } return string.Empty; } private static Dictionary CreateUAETestPayload() { var documentId = "b1c2d3e4-f567-8901-2345-67890abcdef1"; var payload = new Dictionary(); var invoiceData = new Dictionary { ["document_number"] = "shubham-36", ["reference_id"] = "20260202104801557", ["document_id"] = documentId, ["document_type"] = "tax_invoice", ["invoice_date"] = "2026-03-26", ["invoice_time"] = "00:00:00Z", ["currency_code"] = "AED", ["tax_currency_code"] = "AED", ["due_date"] = "2026-04-26", ["period_start_date"] = "2026-02-25", ["period_end_date"] = "2026-03-27", ["period_frequency"] = "MONTHLY", ["exchange_rate"] = 1.0, ["line_extension_amount"] = 5000, ["tax_exclusive_amount"] = 5000, ["total_tax_amount"] = 0, ["total_amount"] = 5000, ["total_allowances"] = 0, ["total_charges"] = 0, ["prepaid_amount"] = 0, ["amount_due"] = 5000, ["rounding_amount"] = 0, ["original_reference_id"] = "UAE-INV-ORIG-001", ["credit_note_reason"] = "VD" }; payload["invoice_data"] = invoiceData; var sellerInfo = new Dictionary { ["seller_name"] = "ABC Trading LLC", ["seller_trade_name"] = "ABC Trading", ["seller_party_id"] = "SELLER-UAE-001", ["vat_number_type"] = "TRN", ["vat_number"] = "100819867100003", ["tax_scheme"] = "VAT", ["registration_number"] = "CN-1234567", ["registration_type"] = "TL", ["registration_scheme"] = "AE:TL", ["authority_name"] = "Dubai Department of Economic Development", ["peppol_id"] = "0235:1101560970", ["seller_email"] = "contact@abctrading.ae", ["seller_phone"] = "+971-4-1234567", ["seller_contact_name"] = "Ahmed Al Maktoum", ["street_name"] = "Sheikh Zayed Road", ["additional_address"] = "Building 123", ["building_number"] = "123", ["city_name"] = "Dubai", ["state_province"] = "DUBAI", ["postal_code"] = "00000", ["country_code"] = "AE" }; payload["seller_info"] = sellerInfo; var buyerInfo = new Dictionary { ["buyer_name"] = "XYZ Corporation LLC", ["buyer_trade_name"] = "XYZ Corp", ["buyer_party_id"] = "BUYER-UAE-001", ["buyer_vat_type"] = "TRN", ["buyer_vat_number"] = "100889867100003", ["buyer_tax_scheme"] = "VAT", ["buyer_registration_number"] = "CN-9876543", ["buyer_registration_type"] = "TL", ["buyer_registration_scheme"] = "TL", ["buyer_authority_name"] = "Abu Dhabi Department of Economic Development", ["buyer_peppol_id"] = "0235:1101560970", ["buyer_email"] = "purchasing@xyzcorp.ae", ["buyer_phone"] = "+971-2-9876543", ["buyer_contact_name"] = "Fatima Al Mansouri", ["buyer_street_name"] = "Al Wasl Road", ["buyer_additional_address"] = "Tower 2", ["buyer_building_number"] = "456", ["buyer_city"] = "Dubai", ["buyer_state_province"] = "DUBAI", ["buyer_postal_code"] = "00000", ["buyer_country"] = "AE" }; payload["buyer_info"] = buyerInfo; var lineItems = new List> { new Dictionary { ["line_id"] = "1", ["item_name"] = "Office Equipment", ["item_description"] = "Professional office equipment package", ["quantity"] = 10, ["unit_code"] = "EA", ["unit_price"] = 500, ["net_price"] = 500, ["gross_price"] = 500, ["line_taxable_value"] = 5000, ["tax_category"] = "Z", ["tax_rate"] = 0, ["tax_amount"] = 0, ["line_total"] = 5000, ["item_type"] = "GOODS", ["country_of_origin"] = "AE", ["classification_code"] = "8471", ["classification_scheme"] = "HS", ["seller_item_code"] = "SKU-001", ["buyer_item_code"] = "BUYER-SKU-001", ["batch_number"] = "BATCH-2024-001" } }; payload["line_items"] = lineItems; var taxTotals = new List> { new Dictionary { ["tax_amount"] = 0, ["taxable_amount"] = 5000, ["tax_category_code"] = "Z", ["tax_rate"] = 5 } }; payload["tax_totals"] = taxTotals; var deliveryInfo = new Dictionary { ["deliver_to_address_line1"] = "Sheikh Zayed Road", ["deliver_to_city"] = "Dubai", ["deliver_to_country_subdivision"] = "DUBAI", ["deliver_to_country_code"] = "AE" }; payload["delivery_info"] = deliveryInfo; var uaeExtensions = new Dictionary { ["unique_identifier"] = documentId, ["invoiced_object_id"] = "OBJECT-2024-001", ["taxpoint_date"] = "2026-03-27", ["total_amount_including_tax_in_aed"] = 5000, ["authority_name"] = "Dubai Department of Economic Development", ["buyer_authority_name"] = "Abu Dhabi Department of Economic Development", ["business_process_type"] = "urn:peppol:bis:billing", ["specification_identifier"] = "urn:peppol:pint:ae:invoice:v1", ["beneficiary_id"] = "100889867100003", ["principal_id"] = "PRINCIPAL-001" }; payload["uae_extensions"] = uaeExtensions; var paymentInfo = new Dictionary { ["payment_id"] = "PAY-001", ["payment_means_code"] = "IN_CASH", ["payment_means_text"] = "Bank Transfer", ["remittance_info"] = "Payment for Invoice UAE-DBT-20260327123000000", ["account_id"] = "AE123456789012345678901", ["account_name"] = "ABC Trading LLC", ["bank_id"] = "AEBN0001" }; payload["payment_info"] = paymentInfo; var paymentTerms = new List> { new Dictionary { ["instructions_id"] = "TERMS-001", ["note"] = "Net 30 days", ["amount"] = 5000, ["due_date"] = "2026-04-26" } }; payload["payment_terms"] = paymentTerms; var supportingDocuments = new List> { new Dictionary { ["custom_reference_number"] = "1234565432" } }; payload["supporting_documents"] = supportingDocuments; return payload; } } }