/// <summary> /// Gets the purchased packages. /// </summary> /// <param name="errorResponse">The error response.</param> /// <returns></returns> public List <Package> GetPurchasedPackages(out string errorResponse) { errorResponse = string.Empty; string storeKey = StoreService.GetOrganizationKey();; // setup REST call var client = new RestClient(_rockStoreUrl); client.Timeout = _clientTimeout; var request = new RestRequest(); request.Method = Method.GET; request.Resource = string.Format("api/Packages/GetPurchasedPackages/{0}", storeKey); var response = client.Execute(request); if (response.ResponseStatus == ResponseStatus.Completed) { List <Package> packages = JsonConvert.DeserializeObject <List <Package> >(response.Content); return(packages); } else { errorResponse = response.ErrorMessage; return(new List <Package>()); } }
protected void btnInstall_Click( object sender, EventArgs e ) { StoreService storeService = new StoreService(); string errorResponse = string.Empty; var installResponse = storeService.Purchase( txtUsername.Text, txtPassword.Text, packageId, out errorResponse ); if ( installResponse != null ) { switch ( installResponse.PurchaseResult ) { case PurchaseResult.AuthenticationFailed: lMessages.Text = string.Format( "<div class='alert alert-warning margin-t-md'><strong>Could Not Authenticate</strong> {0}</div>", installResponse.Message ); break; case PurchaseResult.Error: lMessages.Text = string.Format( "<div class='alert alert-warning margin-t-md'><strong>An Error Occurred</strong> {0}</div>", installResponse.Message ); break; case PurchaseResult.NoCardOnFile: lMessages.Text = string.Format( "<div class='alert alert-warning margin-t-md'><strong>No Card On File</strong> No credit card is on file for your organization. Please add a card from your <a href='{0}'>Account Page</a>.</div>", ResolveRockUrl( "~/RockShop/Account" ) ); break; case PurchaseResult.NotAuthorized: lMessages.Text = string.Format( "<div class='alert alert-warning margin-t-md'><strong>Unauthorized</strong> You are not currently authorized to make purchases for this organization. Please see your organization's primary contact to enable your account for purchases.</div>" ); break; case PurchaseResult.PaymentFailed: lMessages.Text = string.Format( "<div class='alert alert-warning margin-t-md'><strong>Payment Error</strong> An error occurred while processing the credit card on file for your organization. The error was: {0}. Please update your card's information from your <a href='{1}'>Account Page</a>.</div>", installResponse.Message, ResolveRockUrl( "~/RockShop/Account" ) ); break; case PurchaseResult.Success: ProcessInstall( installResponse ); break; } } else { lMessages.Text = string.Format( "<div class='alert alert-danger margin-t-md'><strong>Install Error</strong> An error occurred while attempting to authenticate your install of this package. The error was: {0}.</div>", ( string.IsNullOrWhiteSpace( errorResponse ) ? "Unknown" : errorResponse ) ); } }
/// <summary> /// Gets the package. /// </summary> /// <param name="packageId">The package identifier.</param> /// <param name="errorResponse">The error response.</param> /// <returns></returns> public Package GetPackage(int packageId, out string errorResponse) { errorResponse = string.Empty; string storeKey = StoreService.GetOrganizationKey(); // setup REST call var client = new RestClient(_rockStoreUrl); client.Timeout = _clientTimeout; var request = new RestRequest(); request.Method = Method.GET; request.Resource = string.Format("api/Packages/GetPackageDetails/{0}/{1}", packageId.ToString(), storeKey); //request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; }; var response = client.Execute <Package>(request); if (response.ResponseStatus == ResponseStatus.Completed) { return(response.Data); } else { errorResponse = response.ErrorMessage; return(new Package()); } }
/// <summary> /// Returns true if the Organization has a StoreOrganizationKey /// </summary> /// <returns></returns> public static bool OrganizationIsConfigured() { var storeKey = StoreService.GetOrganizationKey(); if (string.IsNullOrWhiteSpace(storeKey)) { return(false); } else { return(true); } }
/// <summary> /// Gets all packages. /// </summary> /// <param name="categoryId">The category identifier.</param> /// <param name="errorResponse">The error response.</param> /// <returns></returns> public IEnumerable <Package> GetAllPackages(int?categoryId, out string errorResponse) { errorResponse = string.Empty; var encodedOrganizationKey = StoreService.GetEncodedOrganizationKey(); var resourcePath = string.Empty; Dictionary <string, List <string> > queryParameters = null; if (categoryId.HasValue) { resourcePath = $"Api/Packages/GetSummariesByCategory/{categoryId.Value}/{encodedOrganizationKey}"; } else { resourcePath = "Api/Promos"; queryParameters = new Dictionary <string, List <string> > { { "$expand", new List <string> { "PrimaryCategory,SecondaryCategory,PackageTypeValue,Vendor,PackageIconBinaryFile" } } }; } // deserialize to list of packages var response = ExecuteRestGetRequest <List <Package> >(resourcePath, queryParameters); var packageList = new List <Package>(); if (response.ResponseStatus == ResponseStatus.Completed && response.Data != null) { packageList = response.Data; // If the key is null null out the price so it can't be installed. if (encodedOrganizationKey.IsNullOrWhiteSpace()) { foreach (var package in packageList) { if (!package.IsFree) { package.Price = null; } } } } else { errorResponse = response.ErrorMessage; } return(packageList); }
/// <summary> /// Gets the purchased packages. /// </summary> /// <param name="errorResponse">The error response.</param> /// <returns></returns> public List <Package> GetPurchasedPackages(out string errorResponse) { errorResponse = string.Empty; string storeKey = StoreService.GetOrganizationKey();; if (string.IsNullOrEmpty(storeKey)) { errorResponse = "The 'Store Key' is not configured yet. Please check the Account and ensure it is configured for your organization."; return(new List <Package>()); } // setup REST call var client = new RestClient(_rockStoreUrl); client.Timeout = _clientTimeout; var request = new RestRequest(); request.Method = Method.GET; request.Resource = string.Format("api/Packages/GetPurchasedPackages/{0}", storeKey); var response = client.Execute(request); try { if (response.ResponseStatus == ResponseStatus.Completed) { List <Package> packages = JsonConvert.DeserializeObject <List <Package> >(response.Content); return(packages); } else { errorResponse = response.ErrorMessage; return(new List <Package>()); } } catch (JsonReaderException) { errorResponse = "Something went wrong while retrieving the purchased packages. It's possible your 'Store Key' is bad (could not be decrypted) and needs to be revoked."; return(new List <Package>()); } }
/// <summary> /// Gets the purchased packages. /// </summary> /// <param name="errorResponse">The error response.</param> /// <returns></returns> public List <Package> GetPurchasedPackages(out string errorResponse) { errorResponse = string.Empty; string storeKey = StoreService.GetOrganizationKey(); if (string.IsNullOrEmpty(storeKey)) { errorResponse = "The 'Store Key' is not configured yet. Please check the Account and ensure it is configured for your organization."; return(new List <Package>()); } var response = ExecuteRestGetRequest <List <Package> >($"api/Packages/GetPurchasedPackages/{storeKey}/true"); if (response.ResponseStatus == ResponseStatus.Completed) { return(response.Data); } else { errorResponse = response.ErrorMessage; return(new List <Package>()); } }
/// <summary> /// Gets the encoded organization key. /// </summary> /// <returns></returns> public static string GetEncodedOrganizationKey() { var organizationKey = StoreService.GetOrganizationKey(); return(HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(organizationKey)))); }
private void ProcessNoResults() { string errorMessage = string.Empty; // first check that the username/password they provided are correct bool canAuthicate = new StoreService().AuthenicateUser( txtUsername.Text, txtPassword.Text); if ( canAuthicate ) { lMessages.Text = @"<div class='alert alert-warning margin-t-md'>It appears that no organizations have been configured for this account. You can set up an organization on the Rock RMS website. Simply login and then select 'My Account' from the dropdown in the top right corner.</div>"; } else { lMessages.Text = @"<div class='alert alert-warning margin-t-md'>The username/password provided did not match a user on the Rock RMS website. Be sure you provide a valid account from this site. If you would like to create an account or retrieve your password please <a href='https://www.rockrms.com/Rock/Login'> vistit the Rock RMS website</a>.</div>"; } }