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

            var id = _paymentPageSessionsApi.PaymentPageSessionsPost(postPaymentPageSessionRequestModel, null);

            // Should return a valid Id.
            Assert.IsNotNull(id);
        }
        public void Should_Return_An_Id_Upon_Success_With_An_Impersonation_Key()
        {
            var postPaymentPageSessionRequestModel = new PostPaymentPageSessionRequestModel
            {
                Amount = 100,
                InitiatingPartyCreditCardFee = 20,
                InitiatingPartyAchFee        = 2,
                AcceptedPaymentMethods       = new System.Collections.Generic.List <AcceptedPaymentMethod> {
                    AcceptedPaymentMethod.Ach
                },
                SuccessUrl = "https://www.example.com",
                PayerFee   = 5
            };

            var id = _paymentPageSessionsApi.PaymentPageSessionsPost(postPaymentPageSessionRequestModel, TestApiSettings.ImpersonationAccountKey);

            // Should return a valid Id.
            Assert.IsNotNull(id);
        }
        public void Should_Validate_Against_A_High_Initiator_Credit_Card_Fee()
        {
            var postPaymentPageSessionRequestModel = new PostPaymentPageSessionRequestModel
            {
                Amount = 100,
                InitiatingPartyCreditCardFee = 101,
                InitiatingPartyAchFee        = 2
            };

            try
            {
                var id = _paymentPageSessionsApi.PaymentPageSessionsPost(postPaymentPageSessionRequestModel, TestApiSettings.ImpersonationAccountKey);

                Assert.Fail();
            }
            catch (ApiException exception)
            {
                Assert.AreEqual(400, exception.ErrorCode);
            }
        }
        public void Should_Fail_With_An_Invalid_Processing_Account_Id()
        {
            var postPaymentPageSessionRequestModel = new PostPaymentPageSessionRequestModel
            {
                Amount = 100,
                InitiatingPartyCreditCardFee = 20,
                InitiatingPartyAchFee        = 2
            };

            try
            {
                var id = _paymentPageSessionsApi.PaymentPageSessionsPost(postPaymentPageSessionRequestModel, "INVALID KEY");

                Assert.Fail();
            }
            catch (ApiException exception)
            {
                Assert.AreEqual(401, exception.ErrorCode);
            }
        }
        public void Should_Require_Processing_AccountId_If_Initiator_Fee_Is_Not_Null()
        {
            var postPaymentPageSessionRequestModel = new PostPaymentPageSessionRequestModel
            {
                Amount = 100,
                InitiatingPartyCreditCardFee = 20,
                InitiatingPartyAchFee        = 2
            };

            try
            {
                var id = _paymentPageSessionsApi.PaymentPageSessionsPost(postPaymentPageSessionRequestModel, null);

                Assert.Fail();
            }
            catch (ApiException exception)
            {
                Assert.AreEqual(400, exception.ErrorCode);
            }
        }
        /// <summary>
        /// Creates a temporary "session" with parameters so that the user can be forwarded to the payment page with this context.
        /// </summary>
        /// <param name="postPaymentPageSessionRequestModel">Contains the parameters for the "session".</param>
        /// <param name="impersonationAccountKey">The key that allows impersonation of another account for which the transaction is being processed. Only specify a value if the account being impersonated is different from the account that is submitting this request.</param>
        public string PaymentPageSessionsPost(PostPaymentPageSessionRequestModel postPaymentPageSessionRequestModel, string impersonationAccountKey)
        {
            // verify the required parameter 'postPaymentPageSessionRequestModel' is set
            if (postPaymentPageSessionRequestModel == null)
            {
                throw new ApiException(400, "Missing required parameter 'postPaymentPageSessionRequestModel' when calling PaymentPageSessionsApi->PaymentPageSessionsPost");
            }

            var    localVarPath         = "/api/v1/PaymentPageSessions";
            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 (postPaymentPageSessionRequestModel.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(postPaymentPageSessionRequestModel); // http body (model) parameter
            }
            else
            {
                localVarPostBody = postPaymentPageSessionRequestModel; // 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);
        }