private void PrintAccountTax(AccountTax settings) { Console.WriteLine("Tax settings for account {0}:", settings.AccountId); if (settings.Rules == null || settings.Rules.Count == 0) { Console.WriteLine("No tax rules."); } else { foreach (var rule in settings.Rules) { Console.Write("For location {0} in country {0}: ", rule.LocationId, rule.Country); if (rule.RatePercent != null) { Console.WriteLine("tax is {0}%.", rule.RatePercent); } if (rule.UseGlobalRate == true) { Console.WriteLine("using the global tax table rate."); } if (rule.ShippingTaxed == true) { Console.WriteLine(" Note: Shipping charges are also taxed."); } } } }
private void UpdateAccountTax(ulong merchantId, ulong accountId, AccountTax settings) { Console.WriteLine("================================================================="); Console.WriteLine("Updating Account Tax Settings for {0}", accountId); Console.WriteLine("================================================================="); service.Accounttax.Update(settings, merchantId, accountId).Execute(); Console.WriteLine(); }
/// <summary>Runs requests against the Content API for Shopping.</summary> internal void RunCalls(ulong merchantId) { AccountTax oldSettings = GetAccountTax(merchantId, merchantId); AccountTax newSettings = SampleTaxSettings(merchantId); UpdateAccountTax(merchantId, merchantId, newSettings); GetAccountTax(merchantId, merchantId); oldSettings.ETag = null; // Clear out the ETag first. UpdateAccountTax(merchantId, merchantId, oldSettings); GetAccountTax(merchantId, merchantId); }
/// <summary> /// Retrieves the tax settings for a particular account. /// </summary> /// <returns>The tax settings for the specified account.</returns> private AccountTax GetAccountTax(ulong merchantId, ulong accountId) { Console.WriteLine("================================================================="); Console.WriteLine("Getting Account Tax Settings for {0}", accountId); Console.WriteLine("================================================================="); AccountTax settings = service.Accounttax.Get(merchantId, accountId).Execute(); PrintAccountTax(settings); Console.WriteLine(); return(settings); }
private AccountTax SampleTaxSettings(ulong accountId) { AccountTaxTaxRule taxNY = new AccountTaxTaxRule(); taxNY.Country = "US"; taxNY.LocationId = 21167; taxNY.UseGlobalRate = true; AccountTax settings = new AccountTax(); settings.AccountId = accountId; settings.Rules = new List <AccountTaxTaxRule>(); settings.Rules.Add(taxNY); return(settings); }
/// <summary> /// Updates the tax settings of the account. This method can only be called for accounts to which the managing account has access: either the managing account itself for any Merchant Center account, or any sub-account when the managing account is a multi-client account. /// Documentation https://developers.google.com/shoppingcontent/v2/reference/accounttax/update /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Shoppingcontent service.</param> /// <param name="merchantId">The ID of the managing account.</param> /// <param name="accountId">The ID of the account for which to get/update account tax settings.</param> /// <param name="body">A valid Shoppingcontent v2 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>AccountTaxResponse</returns> public static AccountTax Update(ShoppingcontentService service, string merchantId, string accountId, AccountTax body, AccounttaxUpdateOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (merchantId == null) { throw new ArgumentNullException(merchantId); } if (accountId == null) { throw new ArgumentNullException(accountId); } // Building the initial request. var request = service.Accounttax.Update(body, merchantId, accountId); // Applying optional parameters to the request. request = (AccounttaxResource.UpdateRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Accounttax.Update failed.", ex); } }