示例#1
0
        /// <summary>
        /// Calculate taxes on a bridge conference transaction
        /// </summary>
        /// <remarks>This method will take a Billing address, Bridge Address, Host Address (optional) and list of participants.
        /// The system will determine which taxes apply for each participant and return the summarized taxes for the bridge
        /// conference transaction. The individual participant results are returned if ReturnParticipantResults is true.</remarks>
        /// <param name="transaction">Bridge conference transaction details including list of participants.</param>
        /// <returns>BridgeConferenceResults object containing an array of BridgeConferenceParticipantResult objects for each
        /// participant transaction processed and TaxData array containing the summarized taxes for the bridge conference calculation.</returns>
        public async Task <BridgeConferenceResults> CalculateBridgeConferenceTaxes(BridgeConferenceTransaction transaction)
        {
            HttpResponseMessage response = await httpClient.PostAsJsonAsync($"api/v1/BridgeConference/Taxes", transaction);

            if (!response.IsSuccessStatusCode)
            {
                string error = response.Headers.Contains(ErrorHeader) ?
                               response.Headers.GetValues(ErrorHeader).FirstOrDefault() :
                               null;

                throw new AfcRestException(response.StatusCode, error);
            }

            string content = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <BridgeConferenceResults>(content));
        }
示例#2
0
        /// <summary>
        /// Example showing how to calculate taxes for a bridge conference transaction.
        /// </summary>
        private static void CalculateBridgeConferenceTaxes()
        {
            PrintSeparator();
            Console.WriteLine($"API: POST {BaseAddress}/api/v1/BridgeConference/Taxes");
            Console.WriteLine();

            using (var client = new AfcRestClient(BaseAddress, UserName, Password, ClientId, ClientProfileId))
            {
                try
                {
                    // Create a BridgeConferenceTransaction object to specify the input data for the tax calculation
                    var transaction = new BridgeConferenceTransaction
                    {
                        BillingAddress = new ZipAddress
                        {
                            CountryIso = "USA",
                            State      = "WA",
                            County     = "King",
                            Locality   = "Seattle",
                            ZipCode    = "98101"
                        },
                        BridgeAddress = new ZipAddress
                        {
                            CountryIso = "USA",
                            State      = "KS",
                            County     = "Johnson",
                            Locality   = "Overland Park",
                            ZipCode    = "66212"
                        },
                        BusinessClass     = 0,      // ILEC
                        Charge            = 25.95,
                        CompanyIdentifier = "TST",
                        CustomerType      = 0,      // Residential
                        Date            = DateTime.Today,
                        FacilitiesBased = true,
                        Franchise       = true,
                        HostAddress     = new ZipAddress
                        {
                            CountryIso = "USA",
                            State      = "KS",
                            County     = "Johnson",
                            Locality   = "Overland Park",
                            ZipCode    = "66212"
                        },
                        Incorporated = true,
                        Lifeline     = false,
                        Lines        = 1,
                        Locations    = 0,
                        Minutes      = 0,
                        Participants = new []
                        {
                            new BridgeConferenceParticipant
                            {
                                ParticipantAddress = new ZipAddress
                                {
                                    CountryIso = "USA",
                                    State      = "WA",
                                    County     = "King",
                                    Locality   = "Seattle",
                                    ZipCode    = "98101"
                                },
                                ParticipantRef = "1"
                            },
                            new BridgeConferenceParticipant
                            {
                                ParticipantAddress = new ZipAddress
                                {
                                    CountryIso = "USA",
                                    State      = "CO",
                                    County     = "Denver",
                                    Locality   = "Denver",
                                    ZipCode    = "80014"
                                },
                                ParticipantRef = "2"
                            }
                        }.ToList(),
                        ProcessInvalidParticipant = true, // Don't fail transaction if a participant fails to be processed
                        Regulated = false,
                        ReturnParticipantTaxes = true,    // Return each individual participant's taxes in the response
                        Sale         = true,
                        ServiceClass = 1                  // Primary long distance
                    };

                    Console.WriteLine($"REQUEST BODY:");
                    Console.WriteLine(transaction.ToJson());
                    Console.WriteLine();

                    // Invoke REST API to calculate taxes on the bridge conference transaction
                    BridgeConferenceResults results = client.CalculateBridgeConferenceTaxes(transaction).Result;

                    Console.WriteLine($"RESPONSE:");
                    Console.WriteLine(results.ToJson());
                    Console.WriteLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"ERROR: {ex.Message}");
                }
            }
        }