/// <summary>
        /// Sets the public key on the view model or any errors that occurred.
        /// </summary>
        private async Task SetPublicKey(CheckoutViewModel model)
        {
            var response = await PaymentsApiClient.GetPublicKey();

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

            // Check that the request to get the public key was successful.
            if (!response.IsSuccessStatusCode)
            {
                var errorMessage = TryGetErrorMessage(content);

                if (string.IsNullOrWhiteSpace(errorMessage))
                {
                    errorMessage = "The attempt to retrieve the public key from Payments API did not succeed and has produced an unexpected error.";
                }

                model.ErrorsViewModel.Errors.Add(new ErrorViewModel
                {
                    Error       = "Public key request error",
                    Description = errorMessage
                });

                return;
            }

            var publicKeyData = JsonConvert.DeserializeObject <Models.PaymentsApi.PublicKeyData>(content);

            model.PublicKey = publicKeyData.Value;
        }
示例#2
0
        /// <summary>
        /// Validate that the authenticated organization user can make a request to Payments API.
        /// </summary>
        private async Task <ErrorViewModel> TestPaymentsApiAuthorization()
        {
            var response = await PaymentsApiClient.GetPublicKey();

            if (response.IsSuccessStatusCode)
            {
                return(null);
            }

            return(new ErrorViewModel
            {
                Error = "Public key request error",
                Description = "The attempt to test Payments API did not succeed and has produced an unexpected error."
            });
        }