public async Task <UserContract> PostAsync(StringWrapper receipt) { _telemetryClient.TrackEvent("IapController PostAsync invoked"); if (receipt == null) { throw ServiceExceptions.IapValidationException("IapController: Receipt is null"); } var registrationReference = await ValidateAndReturnCurrentUserId(); UserContract returnUser; try { int goldValue; var xmlReceipt = new XmlDocument(); xmlReceipt.LoadXml(receipt.Data); var iapReceipt = _iapValidator.ValidateXmlSignature(xmlReceipt); var user = await _repository.GetUser(null, registrationReference); iapReceipt.UserId = user.UserId; var productKey = "Iap"; if (!string.IsNullOrEmpty(iapReceipt.ProductId)) { productKey = "Iap" + iapReceipt.ProductId.Trim(); int.TryParse(WebConfigurationManager.AppSettings[productKey], out goldValue); } else { throw ServiceExceptions.IapValidationException( $"IapController: Product not found in configuration: {productKey}"); } iapReceipt.GoldIncrement = goldValue; returnUser = await _repository.InsertIapPurchase(iapReceipt); } catch (DataLayerException ex) { _telemetryClient.TrackException(ex); if (ex.Error == DataLayerError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.DataLayerException(ex.Message); } catch (IapValidationException ex) { _telemetryClient.TrackException(ex); if (ex.Error == IapValidationError.Unknown) { throw ServiceExceptions.UnknownInternalFailureException(ServiceExceptions.Source); } throw ServiceExceptions.IapValidationException(ex.Message); } return(returnUser); }