private static JArray ToDto(UpdatePaymentParameter parameter) { if (parameter == null) { throw new ArgumentNullException(); } var arr = new JArray(); if (parameter.JsonPatches != null) { foreach (var patch in parameter.JsonPatches) { arr.Add(ToDto(patch)); } } return(arr); }
public async Task <CreatePaymentResponse> UpdatePayment(string paymentId, UpdatePaymentParameter parameter) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } var jObj = ToDto(parameter); var client = _httpClientFactory.GetHttpClient(); var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, new Uri($"{BaseConstants.RESTSandboxEndpoint}v1/payments/payment/{paymentId}")) { Content = new StringContent(jObj.ToString(), Encoding.UTF8, "application/json") }; request.Headers.Add("Authorization", $"Bearer {parameter.AccessToken}"); var response = await client.SendAsync(request).ConfigureAwait(false); var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var obj = JObject.Parse(content); try { response.EnsureSuccessStatusCode(); } catch (Exception) { return(new CreatePaymentResponse { IsValid = false, ErrorResponse = ToErrorResponseModel(obj) }); } return(ToCreatePaymentModel(obj)); }