public void Should_Create_Get_And_Delete_With_Impersonation() { // setup var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(TestApiSettings.Key + ":" + TestApiSettings.Secret); var autoPayApi = new AutoPayApi(TestApiSettings.Uri); var tokensApi = new TokensApi(TestApiSettings.Uri); var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = DateTime.Now.Year + 1, PostalCode = "54321" } }; autoPayApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); tokensApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); //Create Token var tokenId = tokensApi.TokensPost(postTokenRequestModel, TestApiSettings.InvoicesImpersonationAccountKey); var id = Guid.NewGuid(); var autopayRequestModel = new PostAutoPayRequestModel { EmailAddress = "*****@*****.**", AttributeValues = new Dictionary <string, string>() { ["accountCode"] = "123", ["postalCode"] = "78701", ["uniqueId"] = id.ToString() }, PublicTokenId = tokenId }; // Create and get autopay var createdId = autoPayApi.AutoPayPost(autopayRequestModel, TestApiSettings.InvoicesImpersonationAccountKey); var gotten = autoPayApi.AutoPayGet(createdId.Value, TestApiSettings.InvoicesImpersonationAccountKey); autoPayApi.AutoPayCancel(createdId.Value, TestApiSettings.InvoicesImpersonationAccountKey); Assert.IsNotNull(gotten); Assert.AreEqual(tokenId, gotten.TokenId); }
public void Should_Create_And_Delete() { // Setup var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(TestApiSettings.InvoiceKey + ":" + TestApiSettings.InvoiceSecret); var autoPayApi = new AutoPayApi(TestApiSettings.Uri); var tokensApi = new TokensApi(TestApiSettings.Uri); var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = DateTime.Now.Year + 1, PostalCode = "54321" } }; autoPayApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); tokensApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); // Create Token var tokenId = tokensApi.TokensPost(postTokenRequestModel); var autopayRequestModel = new PostAutoPayRequestModel { EmailAddress = "*****@*****.**", AttributeValues = new Dictionary <string, string>() { ["accountCode"] = "123", ["postalCode"] = "78702" }, PublicTokenId = tokenId }; var createdId = autoPayApi.AutoPayPost(autopayRequestModel); var result = autoPayApi.AutoPayCancel(createdId.Value); Assert.IsTrue(result); }
/// <summary> /// Creates an auto pay specified Invoice. /// </summary> /// <exception cref="epay3.Web.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="postAutoPayRequestModel">Contains the parameters for the auto pay.</param> /// <param name="impersonationAccountKey">The key that allows impersonation of another account for which the transaction(s) will be processed. Only specify a value if the account being impersonated is different from the account that is submitting this request. (optional, default to )</param> /// <returns></returns> public long?AutoPayPost(PostAutoPayRequestModel postAutoPayRequestModel, string impersonationAccountKey = null) { if (postAutoPayRequestModel == null) { throw new ApiException(400, "Missing required parameter 'postAutoPayRequestModel' when calling AutoPay Api->AutoPayPost"); } var localVarPath = "/api/v1/autoPay"; 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 (postAutoPayRequestModel.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(postAutoPayRequestModel); // http body (model) parameter } else { localVarPostBody = postAutoPayRequestModel; // 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 >= 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(long.Parse(id)); }