public async Task TestCapture() { string orderId = "1038111762115"; string chargeId = "FXIW-UJX5"; decimal value = 433.99M; AffirmCaptureRequest captureRequest = new AffirmCaptureRequest { order_id = orderId, amount = (int)(value * 100) }; var jsonSerializedRequest = JsonConvert.SerializeObject(captureRequest); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri($"{BASE_URL}/{AffirmConstants.Transactions}/{chargeId}/{AffirmConstants.Capture}"), //Content = new StringContent(jsonSerializedRequest, Encoding.UTF8, APPLICATION_JSON) }; request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{publicKey}:{privateKey}"))); HttpClient client = new HttpClient(); var response = await client.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseContent); }
/// <summary> /// Capture the funds of an authorized charge, similar to capturing a credit card transaction. After capturing a loan: /// The customer receives a notice that the charge is captured /// The customer's first payment is due in 30 days /// Affirm pays the merchants within 2-3 business days /// Full or partial refunds can be processed within 120 days /// </summary> /// <returns></returns> public async Task <JObject> CaptureAsync(string publicApiKey, string privateApiKey, string chargeId, string orderId, decimal amount, string transactionId) { int amountInPennies = (int)(amount * 100); AffirmCaptureRequest captureRequest = new AffirmCaptureRequest { order_id = orderId, amount = amountInPennies }; var jsonSerializedRequest = JsonConvert.SerializeObject(captureRequest); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri($"{affirmBaseUrl}/{AffirmConstants.Transactions}/{chargeId}/{AffirmConstants.Capture}"), Content = new StringContent(jsonSerializedRequest, Encoding.UTF8, APPLICATION_JSON) }; request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{publicApiKey}:{privateApiKey}"))); request.Headers.Add("X-Vtex-Use-Https", "true"); request.Headers.Add("Proxy-Authorization", _httpContextAccessor.HttpContext.Request.Headers[HEADER_VTEX_CREDENTIAL].ToString()); request.Headers.Add("Idempotency-Key", transactionId); _context.Vtex.Logger.Info("CaptureAsync", null, $"Capture {amount} for {orderId} [{chargeId}]"); var response = await _httpClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); return(ParseAffirmResponse(response, responseContent)); }