public async Task Should_Refund_With_Reason_And_Description() { CreateRefundRequest request = new CreateRefundRequest { ConversationId = "123456789", Locale = Locale.TR.ToString(), PaymentTransactionId = "1", Price = "0.5", Ip = "85.34.78.112", Currency = Currency.TRY.ToString(), Reason = RefundReason.OTHER.ToString(), Description = "customer requested for default sample" }; Refund refund = await Refund.CreateAsync(request, Options); PrintResponse(refund); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.ToString(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.IsNotNull(refund.SystemTime); Assert.IsNull(refund.ErrorCode); Assert.IsNull(refund.ErrorMessage); Assert.IsNull(refund.ErrorGroup); }
/// <summary> /// Creates the Refund. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public async Task <APIResponse> CreateRefund(CreateRefundRequest request) { try { var client = httpClientFactory.CreateClient(WalletServiceOperation.serviceName); var param = JsonConvert.SerializeObject(request); HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json"); var response = await client.PostAsync(servicesConfig.Wallet + WalletServiceOperation.CreateRefund(), contentPost); if (response.IsSuccessStatusCode) { var refund = JsonConvert.DeserializeObject <RefundResponse>(await response.Content.ReadAsStringAsync()); return(new APIResponse(refund, HttpStatusCode.Created)); } return(new APIResponse(response.StatusCode)); } catch (Exception ex) { logger.Error(ex, "Exception in method 'CreateRefund()'"); var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message; return(new APIResponse(exMessage, HttpStatusCode.InternalServerError)); } }
public void Should_Refund_Fraudulent_Payment() { CreatePaymentRequest paymentRequest = CreatePaymentRequestBuilder.Create() .StandardListingPayment() .Build(); Payment payment = Payment.Create(paymentRequest, Options); CreateRefundRequest request = new CreateRefundRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; request.PaymentTransactionId = payment.PaymentItems[0].PaymentTransactionId; request.Price = "0.2"; request.Currency = Currency.TRY.ToString(); request.Ip = "85.34.78.112"; request.Reason = RefundReason.FRAUD.ToString(); request.Description = "stolen card request with 11000 try payment for default sample"; Refund refund = Refund.Create(request, Options); PrintResponse(refund); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.ToString(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.AreEqual(payment.PaymentId, refund.PaymentId); Assert.AreEqual(payment.PaymentItems[0].PaymentTransactionId, refund.PaymentTransactionId); Assert.AreEqual("0.2", refund.Price.RemoveTrailingZeros()); Assert.NotNull(refund.SystemTime); Assert.Null(refund.ErrorCode); Assert.Null(refund.ErrorMessage); Assert.Null(refund.ErrorGroup); }
public async Task Should_Refund_Payment() { CreatePaymentRequest paymentRequest = CreatePaymentRequestBuilder.Create() .StandardListingPayment() .Build(); Payment payment = await Payment.CreateAsync(paymentRequest, Options); CreateRefundRequest request = new CreateRefundRequest { Locale = Locale.TR.ToString(), ConversationId = "123456789", PaymentTransactionId = payment.PaymentItems[0].PaymentTransactionId, Price = "0.2", Currency = Currency.TRY.ToString(), Ip = "85.34.78.112" }; Refund refund = await Refund.CreateAsync(request, Options); PrintResponse(refund); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.ToString(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.AreEqual(payment.PaymentId, refund.PaymentId); Assert.AreEqual(payment.PaymentItems[0].PaymentTransactionId, refund.PaymentTransactionId); Assert.AreEqual("0.2", refund.Price); Assert.AreEqual(0.2, refund.Price.ParseDouble()); AssertDecimal.AreEqual(0.2M, refund.Price.ParseDecimal()); Assert.NotNull(refund.SystemTime); Assert.Null(refund.ErrorCode); Assert.Null(refund.ErrorMessage); Assert.Null(refund.ErrorGroup); }
public void Should_Refund_With_Reason_And_Description() { CreateRefundRequest request = new CreateRefundRequest(); request.ConversationId = "123456789"; request.Locale = Locale.TR.ToString(); request.PaymentTransactionId = "1"; request.Price = "0.5"; request.Ip = "85.34.78.112"; request.Currency = Currency.TRY.ToString(); request.Reason = RefundReason.OTHER.ToString(); request.Description = "customer requested for default sample"; Refund refund = Refund.Create(request, options); PrintResponse <Refund>(refund); Assert.AreEqual(Status.SUCCESS.ToString(), refund.Status); Assert.AreEqual(Locale.TR.ToString(), refund.Locale); Assert.AreEqual("123456789", refund.ConversationId); Assert.IsNotNull(refund.SystemTime); Assert.IsNull(refund.ErrorCode); Assert.IsNull(refund.ErrorMessage); Assert.IsNull(refund.ErrorGroup); }
public async Task <IActionResult> CreateRefund([FromBody] CreateRefundRequest request) { var createRefundCommand = new CreateRefundCommand(request); var result = await mediator.Send(createRefundCommand); return(StatusCode((int)result.Code, result.Value)); }
/// <summary> /// Refunds the given amount for the given charge. /// </summary> /// <param name="refundRequest"></param> /// <param name="headers"></param> /// <returns>AmazonPayResponse response</returns> public RefundResponse Refund(CreateRefundRequest refundRequest, Dictionary <string, string> headers = null) { var refundUri = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.InStore, Constants.Resources.InStore.Refund); var apiRequest = new ApiRequest(refundUri, HttpMethod.POST, refundRequest, headers); var result = CallAPI <RefundResponse>(apiRequest); return(result); }
public Task <ApiResponse <CreateRefundPayload> > CreateRefundAsync(CreateRefundRequest request) { if (request is null) { throw new ArgumentNullException(nameof(request)); } return(PostAsync <ApiResponse <CreateRefundPayload> >(Defaults.Api.Endpoints.RefundPath, request)); }
/// <summary> /// Create a refund of the transaction /// </summary> /// <param name="transactionId">Transaction ID</param> /// <param name="refundRequest">Request parameters to create refund</param> /// <returns>Refund and/or errors if exist</returns> public PaymentResponse <Refund> CreateRefund(string transactionId, CreateRefundRequest refundRequest) { try { //try to get the selected location var selectedLocation = GetActiveLocations().FirstOrDefault(location => location.Id.Equals(_squarePaymentSettings.LocationId)); if (selectedLocation == null) { throw new NopException("Location is a required parameter for payment requests"); } //create transaction API var configuration = CreateApiConfiguration(); var transactionsApi = new TransactionsApi(configuration); //create refund var createRefundResponse = transactionsApi.CreateRefund(selectedLocation.Id, transactionId, refundRequest); if (createRefundResponse == null) { throw new NopException("No service response"); } //check whether there are errors in the service response if (createRefundResponse.Errors?.Any() ?? false) { var errorsMessage = string.Join(";", createRefundResponse.Errors.Select(error => error.ToString())); throw new NopException($"There are errors in the service response. {errorsMessage}"); } return(new PaymentResponse <Refund> { ResponseValue = createRefundResponse.Refund }); } catch (Exception exception) { //log full error var errorMessage = exception.Message; _logger.Error($"Square payment error: {errorMessage}.", exception, _workContext.CurrentCustomer); if (exception is ApiException apiException) { //try to get error details var response = JsonConvert.DeserializeObject <CreateRefundResponse>(apiException.ErrorContent) as CreateRefundResponse; if (response?.Errors?.Any() ?? false) { errorMessage = string.Join(";", response.Errors.Select(error => error.Detail)); } } return(new PaymentResponse <Refund> { Error = errorMessage }); } }
public async Task RefundsCreateCreate() { var request = new CreateRefundRequest { Amount = 100000, // THB 1,000.00 }; var refund = await Client.Refunds .ByCharge("chrg_test_52ye6ksqi1dacbw8wkx") .Create(request); Assert.AreEqual(100000, refund.Amount); }
public void CanConvertToJsonMinimal() { // arrange var chargeId = "S02-7331650-8246451"; var request = new CreateRefundRequest(chargeId, 12.99M, Currency.EUR); // act string json = request.ToJson(); string json2 = request.ToJson(); // assert Assert.AreEqual(json, json2); Assert.AreEqual("{\"chargeId\":\"S02-7331650-8246451\",\"refundAmount\":{\"amount\":12.99,\"currencyCode\":\"EUR\"}}", json); }
public virtual Task <OpenPayEntity> CreateRefundAsync(string orderId, CreateRefundRequest request) { if (orderId is null) { throw new ArgumentNullException(nameof(orderId)); } if (request is null) { throw new ArgumentNullException(nameof(request)); } return(PostAsync <OpenPayEntity>($"/v1/merchant/orders/{orderId}/refund", request)); }
public void CreateRefundRequestIsNullThrows() { // given var subject = new RefundsClient(_clientConfiguration); CreateRefundRequest request = null; // when AsyncTestDelegate test = () => subject.CreateAsync(request); // then var ex = Assert.ThrowsAsync <ArgumentNullException>(test); Assert.That(ex.ParamName, Is.EqualTo(nameof(request))); }
/// <summary> /// Refunds a payment /// </summary> /// <param name="refundPaymentRequest">Request</param> /// <returns>Result</returns> public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { if (refundPaymentRequest == null) { throw new ArgumentNullException(nameof(refundPaymentRequest)); } var refundRequest = new CreateRefundRequest { PaymentId = Guid.Parse(refundPaymentRequest.Order.CaptureTransactionId), Amount = (int)(refundPaymentRequest.AmountToRefund * 100) }; try { var refundResponse = _refundApi.CreateRefundAsync(refundRequest).GetAwaiter().GetResult(); if (refundResponse == null) { return new RefundPaymentResult { Errors = new[] { "No refund response" } } } ; var refundIds = _genericAttributeService.GetAttribute <List <string> >(refundPaymentRequest.Order, Defaults.RefundIdAttributeName) ?? new List <string>(); var refundId = refundResponse.Id.ToString(); if (!refundIds.Contains(refundId)) { refundIds.Add(refundId); } _genericAttributeService.SaveAttribute(refundPaymentRequest.Order, Defaults.RefundIdAttributeName, refundIds); return(new RefundPaymentResult { NewPaymentStatus = refundPaymentRequest.IsPartialRefund ? Core.Domain.Payments.PaymentStatus.PartiallyRefunded : Core.Domain.Payments.PaymentStatus.Refunded }); } catch (ApiException exception) { _logger.Error($"{Defaults.SystemName}: {exception.Message}", exception); return(new RefundPaymentResult { Errors = new[] { exception.Message } }); } }
/// <summary> /// Returns the value indicating whether to refund was created successfully; otherwise returns the errors as <see cref="IList{string}"/> /// </summary> /// <param name="order">The order</param> /// <param name="order">The amount to refund.</param> /// <returns>The <see cref="Task"/> containing the value indicating whether to refund was created successfully; otherwise returns the errors as <see cref="IList{string}"/></returns> public virtual async Task <(bool IsSuccess, IList <string> Errors)> RefundOrderAsync(Order order, decimal?amountToRefund = null) { if (order is null) { throw new ArgumentNullException(nameof(order)); } var validationResult = await ValidateAsync(); if (!validationResult.IsValid) { return(false, validationResult.Errors); } var errors = new List <string>(); if (string.IsNullOrEmpty(order.CaptureTransactionId)) { errors.Add($"Cannot refund the OpenPay order. The captured transaction id is null."); return(false, errors); } try { var createRefundRequest = new CreateRefundRequest { FullRefund = !amountToRefund.HasValue, ReducePriceBy = amountToRefund.HasValue ? (int)(amountToRefund.Value * 100) : 0 }; var createRefundResponse = await _openPayApi.CreateRefundAsync(order.CaptureTransactionId, createRefundRequest); if (createRefundResponse == null) { errors.Add($"Cannot refund the OpenPay order. Cannot create the OpenPay refund by captured order id '{order.CaptureTransactionId}'."); return(false, errors); } return(true, errors); } catch (ApiException ex) { errors.Add(ex.Message); } return(false, errors); }
public void CanConstructWithAllPropertiesInitializedAsExpected() { // arrange var chargeId = "S02-7331650-8246451"; // act var request = new CreateRefundRequest(chargeId, 12.99M, Currency.EUR); // assert Assert.IsNotNull(request); Assert.IsNotNull(request.ChargeId); Assert.IsNotNull(request.RefundAmount); Assert.AreEqual(12.99, request.RefundAmount.Amount); Assert.AreEqual(Currency.EUR, request.RefundAmount.CurrencyCode); Assert.IsNull(request.SoftDescriptor); }
private async Task Refund(string omiseChargeId, double amount) { try { var request = new CreateRefundRequest { Amount = (long)(amount * 100) }; await client.Charge(omiseChargeId).Refunds.Create(request); } catch (Exception) { throw; } }
public async Task CallsCreateRefundEndpoint() { // given var subject = new RefundsClient(_clientConfiguration); var request = new CreateRefundRequest { IdempotencyKey = Guid.NewGuid().ToString() }; // when await subject.CreateAsync(request); // then _httpTest .ShouldHaveCalled("https://api.gocardless.com/refunds") .WithHeader("Idempotency-Key") .WithVerb(HttpMethod.Post); }
public void Should_Refund_Charged_From_Merchant() { CreateRefundRequest request = new CreateRefundRequest(); request.ConversationId = "123456789"; request.Locale = Locale.TR.GetName(); request.PaymentTransactionId = "41"; request.Price = "0.1"; request.Ip = "127.0.0.1"; RefundChargedFromMerchant refundChargedFromMerchant = RefundChargedFromMerchant.Create(request, options); PrintResponse <RefundChargedFromMerchant>(refundChargedFromMerchant); Assert.IsNotNull(refundChargedFromMerchant.SystemTime); Assert.AreEqual(Status.SUCCESS.ToString(), refundChargedFromMerchant.Status); Assert.AreEqual(Locale.TR.GetName(), refundChargedFromMerchant.Locale); Assert.AreEqual("123456789", refundChargedFromMerchant.ConversationId); }
public void Should_Refund_Payment() { CreateRefundRequest request = new CreateRefundRequest(); request.Locale = Locale.TR.GetName(); request.ConversationId = "123456789"; request.PaymentTransactionId = "29"; request.Price = "1.0"; request.Ip = "127.0.0.1"; ConnectRefund connectRefund = ConnectRefund.Create(request, options); PrintResponse <ConnectRefund>(connectRefund); Assert.IsNotNull(connectRefund.SystemTime); Assert.AreEqual(Status.SUCCESS.ToString(), connectRefund.Status); Assert.AreEqual(Locale.TR.GetName(), connectRefund.Locale); Assert.AreEqual("123456789", connectRefund.ConversationId); }
public void OrderRefundPayment() { // TODO uncomment below to test the method and replace null with proper value string id = null; var authorization = authorizationApi.AuthorizationCreateToken("https://auth-dev.partpay.co.nz"); var createOrderRequest = CreateRequest(CreateOrderRequest.PaymentFlowEnum.Payment); var createOrderResponse = instance.OrderCreate(authorization, "IK006", createOrderRequest); id = createOrderResponse.OrderId; System.Threading.Thread.Sleep(2000); // Give the system time to complete the creation of the order var order = instance.OrderGet(authorization, id); var refund = new CreateRefundRequest(50, "Refund test"); var response = instance.OrderRefund(authorization, id, "IK007", refund); Assert.IsInstanceOf <RefundOrder>(response, "response is Refund"); }
/// <summary> /// Ödeme Talebi İadesi /// </summary> /// <param name="refundPaymentRequest">Request</param> /// <returns>Result</returns> public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest) { var refundResult = new RefundPaymentResult(); if (!refundPaymentRequest.IsPartialRefund) { CreateCancelRequest request = new CreateCancelRequest(); request.ConversationId = refundPaymentRequest.Order.CustomOrderNumber; request.Locale = Locale.TR.ToString(); request.PaymentId = refundPaymentRequest.Order.AuthorizationTransactionId; request.Ip = refundPaymentRequest.Order.CustomerIp; Cancel cancel = Cancel.Create(request, HelperApiOptions.GetApiContext(_iyzicoPayPaymentSettings)); if (cancel.Status == "success") { refundResult.NewPaymentStatus = PaymentStatus.Refunded; } else { refundResult.AddError(cancel.ErrorGroup); } } else { string[] list = refundPaymentRequest.Order.AuthorizationTransactionResult.Split('-'); CreateRefundRequest request = new CreateRefundRequest(); request.ConversationId = refundPaymentRequest.Order.CustomOrderNumber; request.Locale = Locale.TR.ToString(); request.PaymentTransactionId = list[0]; request.Price = refundPaymentRequest.AmountToRefund.ToString("##.###").Replace(',', '.'); request.Ip = refundPaymentRequest.Order.CustomerIp; request.Currency = Currency.TRY.ToString(); Iyzico.Models.Refund refund = Iyzico.Models.Refund.Create(request, HelperApiOptions.GetApiContext(_iyzicoPayPaymentSettings)); if (refund.Status == "success") { refundResult.NewPaymentStatus = PaymentStatus.PartiallyRefunded; } } return(refundResult); }
public async Task CreatesRefund() { // given var payment = await _resourceFactory.CreatePaymentFor(_mandate); var request = new CreateRefundRequest { Amount = 100, Links = new CreateRefundLinks { Payment = payment.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, Reference = "RF123456", TotalAmountConfirmation = 100 }; var subject = new RefundsClient(_clientConfiguration); // when var result = await subject.CreateAsync(request); var actual = result.Item; // then Assert.That(actual, Is.Not.Null); Assert.That(actual.Id, Is.Not.Null); Assert.That(actual.Amount, Is.EqualTo(request.Amount)); Assert.That(actual.CreatedAt, Is.Not.Null.And.Not.EqualTo(default(DateTimeOffset))); Assert.That(actual.Currency, Is.EqualTo(payment.Currency)); Assert.That(actual.Links, Is.Not.Null); Assert.That(actual.Links.Payment, Is.EqualTo(request.Links.Payment)); Assert.That(actual.Metadata, Is.EqualTo(request.Metadata)); Assert.That(actual.Reference, Is.EqualTo(request.Reference)); }
/// <summary> /// Create a refund of the transaction /// </summary> /// <param name="transactionId">Transaction ID</param> /// <param name="refundRequest">Request parameters to create refund</param> /// <returns>Refund</returns> public Refund CreateRefund(string transactionId, CreateRefundRequest refundRequest) { try { //try to get the selected location var selectedLocation = GetActiveLocations().FirstOrDefault(location => location.Id.Equals(_squarePaymentSettings.LocationId)); if (selectedLocation == null) throw new NopException("Location is a required parameter for payment requests"); //create transaction API var configuration = CreateApiConfiguration(); var transactionsApi = new TransactionsApi(configuration); //create refund var createRefundResponse = transactionsApi.CreateRefund(selectedLocation.Id, transactionId, refundRequest); if (createRefundResponse == null) throw new NopException("No service response"); //check whether there are errors in the service response if (createRefundResponse.Errors?.Any() ?? false) { var errorsMessage = string.Join(";", createRefundResponse.Errors.Select(error => error.ToString())); throw new NopException($"There are errors in the service response. {errorsMessage}"); } return createRefundResponse.Refund; } catch (Exception exception) { var errorMessage = $"Square payment error: {exception.Message}."; if (exception is ApiException apiException) errorMessage = $"{errorMessage} Details: {apiException.ErrorCode} - {apiException.ErrorContent}"; //log errors _logger.Error(errorMessage, exception, _workContext.CurrentCustomer); return null; } }
public async Task CreateRefundRequestIsInvalidThrows() { // given var payment = await _resourceFactory.CreatePaymentFor(_mandate); var request = new CreateRefundRequest { Amount = 100, IdempotencyKey = Guid.NewGuid().ToString(), Links = new CreateRefundLinks { Payment = payment.Id }, Metadata = new Dictionary <string, string> { ["Key1"] = "Value1", ["Key2"] = "Value2", ["Key3"] = "Value3", }, TotalAmountConfirmation = 100 }; var subject = new RefundsClient(_clientConfiguration); // when AsyncTestDelegate test = () => subject.CreateAsync(request); // then var ex = Assert.ThrowsAsync <ValidationFailedException>(test); Assert.That(ex.Code, Is.EqualTo((int)HttpStatusCode.UnprocessableEntity)); Assert.That(ex.DocumentationUrl, Is.Not.Null); Assert.That(ex.Errors?.Any(), Is.True); Assert.That(ex.Message, Is.Not.Null.And.Not.Empty); Assert.That(ex.RawResponse, Is.Not.Null.And.Not.Empty); Assert.That(ex.RequestId, Is.Not.Null.And.Not.Empty); }
public static Refund Create(CreateRefundRequest request, Options options) { return(RestHttpClient.Create().Post <Refund>(options.BaseUrl + "/payment/refund", GetHttpHeaders(request, options), request)); }
public static async Task <RefundChargedFromMerchant> CreateAsync(CreateRefundRequest request, Options options) { return(await RestHttpClient.Instance.PostAsync <RefundChargedFromMerchant>(options.BaseUrl + RefundChargedFromMerchantUrl, GetHttpHeaders(request, options), request)); }
public static RefundChargedFromMerchant Create(CreateRefundRequest request, Options options) { return(RestHttpClient.Instance.Post <RefundChargedFromMerchant>(options.BaseUrl + RefundChargedFromMerchantUrl, GetHttpHeaders(request, options), request)); }
/// <summary> /// CreateRefund Initiates a refund for a previously charged tender. /// </summary> /// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception> /// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param> /// <param name="locationId">The ID of the original transaction's associated location.</param> /// <param name="transactionId"></param> /// <param name="body">An object containing the fields to POST for the request.\n\nSee the corresponding object definition for field details.</param> /// <returns>Task of ApiResponse (CreateRefundResponse)</returns> public async System.Threading.Tasks.Task <ApiResponse <CreateRefundResponse> > CreateRefundAsyncWithHttpInfo(string authorization, string locationId, string transactionId, CreateRefundRequest body) { // verify the required parameter 'authorization' is set if (authorization == null) { throw new ApiV2Exception(400, "Missing required parameter 'authorization' when calling CreateRefund"); } // verify the required parameter 'locationId' is set if (locationId == null) { throw new ApiV2Exception(400, "Missing required parameter 'locationId' when calling CreateRefund"); } // verify the required parameter 'transactionId' is set if (transactionId == null) { throw new ApiV2Exception(400, "Missing required parameter 'transactionId' when calling CreateRefund"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiV2Exception(400, "Missing required parameter 'body' when calling CreateRefund"); } var localVarPath = "/v2/locations/{location_id}/transactions/{transaction_id}/refund"; 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" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; 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 (locationId != null) { localVarPathParams.Add("location_id", Configuration.ApiClient.ParameterToString(locationId)); // path parameter } if (transactionId != null) { localVarPathParams.Add("transaction_id", Configuration.ApiClient.ParameterToString(transactionId)); // path parameter } if (authorization != null) { localVarHeaderParams.Add("Authorization", Configuration.ApiClient.ParameterToString(authorization)); // header parameter } if (body.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (localVarStatusCode >= 400) { throw new ApiV2Exception(localVarStatusCode, "Error calling CreateRefund: " + localVarResponse.Content, localVarResponse.Content); } else if (localVarStatusCode == 0) { throw new ApiV2Exception(localVarStatusCode, "Error calling CreateRefund: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); } return(new ApiResponse <CreateRefundResponse>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (CreateRefundResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(CreateRefundResponse)))); }
/// <summary> /// CreateRefund Initiates a refund for a previously charged tender. /// </summary> /// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception> /// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param> /// <param name="locationId">The ID of the original transaction's associated location.</param> /// <param name="transactionId"></param> /// <param name="body">An object containing the fields to POST for the request.\n\nSee the corresponding object definition for field details.</param> /// <returns>Task of CreateRefundResponse</returns> public async System.Threading.Tasks.Task <CreateRefundResponse> CreateRefundAsync(string authorization, string locationId, string transactionId, CreateRefundRequest body) { ApiResponse <CreateRefundResponse> localVarResponse = await CreateRefundAsyncWithHttpInfo(authorization, locationId, transactionId, body); return(localVarResponse.Data); }