/// <summary> /// Fulfills gold on the service. /// </summary> /// <param name="productReceipt">The product receipt.</param> /// <returns>The user with an updated gold balance.</returns> public async Task<User> FulfillGold(string productReceipt) { try { var productReceiptWrapper = new StringWrapper { Data = productReceipt }; var userContract = await _mobileServiceClient.InvokeApiAsync<StringWrapper, UserContract>("iap", productReceiptWrapper, HttpMethod.Post, null); return userContract.ToDataModel(); } catch (Exception e) { throw new ServiceException("FulfillGold error", e); } }
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; }