/// <summary> /// Refunds a captured charge. /// </summary> public HttpResponse <Refund> RefundCharge(string chargeId, ChargeRefund requestModel) { if (!chargeId.StartsWith("charge_")) { chargeId = "charge_" + chargeId; } var request = new RestRequest(Endpoints.RefundCharge, Method.POST); request.AddUrlSegment("chargeId", chargeId); request.RequestFormat = DataFormat.Json; request.AddBody(requestModel); return(Execute <Refund>(request)); }
public bool refundPayment(string chargeId) { // productDetails is optional. either we just pass ChargeRefund alias .Only chargeId required. var productDetails = new ChargeRefund() { Value = "1", Products = new List <Product>() { new Product { Name = "ipad 3", Price = 1, Quantity = 1, ShippingCost = 10.5M, Description = "Gold edition", Image = "http://goofle.com/?id=12345", Sku = "TR12345", TrackingUrl = "http://tracket.com?id=123456" } } }; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Add("Authorization", "sk_test_b2ce2577-0c3e-44f3-91e9-f14ea499cfce"); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var response = client.PostAsJsonAsync("https://sandbox.checkout.com/api2/v2/charges/" + chargeId + "/refund", productDetails).Result; string res = ""; if (response.IsSuccessStatusCode) { using (HttpContent content = response.Content) { // ... Read the string. Task <string> result = content.ReadAsStringAsync(); res = result.Result; var voidResponce = JsonConvert.DeserializeObject <CheckoutJSImplementation.Models.Refund>(res); } } else { Task <string> result = response.Content.ReadAsStringAsync(); res = result.Result; } return(response.IsSuccessStatusCode); }
protected void but_refundCharge_Click(object sender, EventArgs e) { // Create payload var refundChargeRequestModel = new ChargeRefund() { Description = "void charge", TrackId = "TRK12345", Value = "100" }; try { // Create APIClient instance with your secret key ckoAPIClient = new APIClient(); // Submit your request and receive an apiResponse HttpResponse <Refund> apiResponse = ckoAPIClient.ChargeService.RefundCharge(label_chargeId.Text, refundChargeRequestModel); if (!apiResponse.HasError) { // Access the response object retrieved from the api var refundinfo = apiResponse.Model; tb_refundChargeRsp.Text = String.Format("Status: {0}! \nCharge ID: {1} \nResponse Code: {2} \nResponse Message: {3} \nRefund Value: {4}", refundinfo.Status, refundinfo.Id, refundinfo.ResponseCode, refundinfo.ResponseMessage, refundinfo.Value); } else { // Api has returned an error object. You can access the details in the error property of the apiResponse. // apiResponse.error tb_refundChargeRsp.Text = string.Format("Message:/n{0} Error Code:/n{1} ", apiResponse.Error.Message, apiResponse.Error.ErrorCode); } } catch (Exception exc) { //... Handle exception } }
/// <summary> /// Refunds a captured charge. /// </summary> public HttpResponse <Refund> RefundCharge(string chargeId, ChargeRefund requestModel) { var chargeRefundsApiUri = string.Format(ApiUrls.RefundCharge, chargeId); return(new ApiHttpClient().PostRequest <Refund>(chargeRefundsApiUri, AppSettings.SecretKey, requestModel)); }
public Task <HttpResponse <Refund> > RefundChargeAsync(string chargeId, ChargeRefund requestModel) { var chargeRefundsApiUri = string.Format(_configuration.ApiUrls.RefundCharge, chargeId); return(_apiHttpClient.PostRequest <Refund>(chargeRefundsApiUri, _configuration.SecretKey, requestModel)); }
public HttpResponse <Refund> RefundCharge(string chargeId, ChargeRefund requestModel) { return(_chargeServiceAsync.RefundChargeAsync(chargeId, requestModel).Result); }