public void Should_Return_An_Id_Upon_Success_With_No_Impersonation_Key()
        {
            var postTokenPageSessionRequestModel = new PostTokenPageSessionRequestModel
            {
                AttributeValues = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "parameter 1", "value 1" },
                    { "parameter 2", "value 2" }
                },
                SuccessUrl = "https://www.example.com"
            };

            var id = _tokenPageSessionsApi.TokenPageSessionsPost(postTokenPageSessionRequestModel, null);

            // Should return a valid Id.
            Assert.IsNotNull(id);
        }
        public void Should_Return_An_Id_Upon_Success_With_An_Impersonation_Key()
        {
            var postTokenPageSessionRequestModel = new PostTokenPageSessionRequestModel
            {
                AttributeValues = new System.Collections.Generic.Dictionary <string, string>
                {
                    { "param1", "parameter value 1" },
                    { "param2", "parameter value 2" }
                },
                AcceptedPaymentMethods = new System.Collections.Generic.List <AcceptedPaymentMethod> {
                    AcceptedPaymentMethod.CreditCard
                },
                SuccessUrl = "https://www.example.com"
            };

            var id = _tokenPageSessionsApi.TokenPageSessionsPost(postTokenPageSessionRequestModel, TestApiSettings.ImpersonationAccountKey);

            // Should return a valid Id.
            Assert.IsNotNull(id);
        }
Пример #3
0
        /// <summary>
        /// Creates a temporary "session" with parameters so that the user can be forwarded to the token page with this context.
        /// </summary>
        /// <param name="postTokenPageSessionRequestModel">Contains the parameters for the "session".</param>
        /// <param name="impersonationAccountKey">The key that allows impersonation of another account for which the token is being created. Only specify a value if the account being impersonated is different from the account that is submitting this request.</param>
        public string TokenPageSessionsPost(PostTokenPageSessionRequestModel postTokenPageSessionRequestModel, string impersonationAccountKey)
        {
            // verify the required parameter 'postTokenPageSessionRequestModel' is set
            if (postTokenPageSessionRequestModel == null)
            {
                throw new ApiException(400, "Missing required parameter 'postTokenPageSessionRequestModel' when calling TokenPageSessionsApi->TokenPageSessionsPost");
            }

            var    localVarPath         = "/api/v1/TokenPageSessions";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json", "text/json", "application/xml", "text/xml"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");

            if (impersonationAccountKey != null)
            {
                localVarHeaderParams.Add("impersonationAccountKey", Configuration.ApiClient.ParameterToString(impersonationAccountKey));                                  // header parameter
            }
            if (postTokenPageSessionRequestModel.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(postTokenPageSessionRequestModel); // http body (model) parameter
            }
            else
            {
                localVarPostBody = postTokenPageSessionRequestModel; // byte array
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (localVarStatusCode >= 400)
            {
                var errorResponseModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorResponseModel>(localVarResponse.Content);

                throw new ApiException(localVarStatusCode, errorResponseModel != null ? errorResponseModel.Message : null);
            }
            else if (localVarStatusCode == 0)
            {
                throw new ApiException(localVarStatusCode, localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);
            }

            var id = localVarResponse.Headers.First(x => x.Name == "Location").Value.ToString().Split('/').Last();

            return(id);
        }