/// <summary> /// Consultar Assinante - Consult Subscriber /// </summary> /// <param name="code"> Código do Assinante </param> /// <returns></returns> public async Task <SubscriberResponse> ConsultSubscriber(string code) { HttpResponseMessage response = await ClientInstance.GetAsync($"assinaturas/v1/customers/{code}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { string json = await response.Content.ReadAsStringAsync(); JObject jObject = JObject.Parse(json); jObject["address"]["number"].Rename("streetNumber"); jObject["address"]["zipcode"].Rename("ZipCode"); json = jObject.ToString(); return(JsonConvert.DeserializeObject <SubscriberResponse>(json)); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Listar Todos os Clientes - List All Customers /// </summary> /// <returns></returns> public async Task <List <CustomerResponse> > List() { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/customers/"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { string json = await response.Content.ReadAsStringAsync(); //remove: {'customers': json = json.Remove(0, 13); //remove: } json = json.Remove(json.Length - 1); return(JsonConvert.DeserializeObject <List <CustomerResponse> >(json)); } catch (System.Exception ex) { throw ex; } }
public async Task <byte[]> Download(string path, IDictionary <string, string> headers = null, IDictionary <string, string> cookies = null) { this.InitizeClient(headers, cookies); var httpResponse = await ClientInstance.GetAsync(path); httpResponse.EnsureSuccessStatusCode();//用来抛异常的 return(await httpResponse.Content.ReadAsByteArrayAsync()); }
public async Task <T> Get <T>(string path, IDictionary <string, string> headers = null, IDictionary <string, string> cookies = null) { this.InitizeClient(headers, cookies); var httpResponse = await ClientInstance.GetAsync(path); httpResponse.EnsureSuccessStatusCode();//用来抛异常的 string responseBody = await httpResponse.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <T>(responseBody)); }
/// <summary> /// Simular pagamentos - Simulate Payments /// </summary> /// <param name="payment_id">Código identificador do pagamento que deseja autorizar. Exemplo: PAY-0UBH5IAJ8KHX</param> /// <param name="valor">Valor a ser autorizado no pagamento. O formato deve incluir centavos e não deve incluir vírgula. Exemplo: Para autorizar pagamento no valor de R$265 você deve setar o valor 26500</param> /// <returns></returns> public async Task <HttpStatusCode> Simulate(string payment_id, int valor) { HttpResponseMessage response = await ClientInstance.GetAsync($"simulador/authorize?payment_id={payment_id}&amount={valor}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } return(response.StatusCode); }
/// <summary> /// Obter Arquivo Financeiro - Get Financial File /// </summary> /// <param name="eventsCreatedAt">Data referente à liquidação dos lançamentos financeiros. Formato: YYYY-MM-DD</param> /// <returns></returns> public async Task <string> GetFinancialFile(string eventsCreatedAt) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/reconciliations/financials?eventsCreatedAt={eventsCreatedAt}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } return(await response.Content.ReadAsStringAsync()); }
/// <summary> /// Consultar Multi Pagamento - Consult /// </summary> /// <param name="multiorder_id">Id do multipagamento. string(16).</param> /// <returns></returns> public async Task<MultiPaymentResponse> Consult(string multiorder_id) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/multipayments/{multiorder_id}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return JsonConvert.DeserializeObject<MultiPaymentResponse>(await response.Content.ReadAsStringAsync()); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Obtem a chave pública - Get public key /// </summary> /// <returns></returns> public async Task <PublicKeyAccountWirecardResponse> GetPublickey() { HttpResponseMessage response = await ClientInstance.GetAsync("v2/keys"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <PublicKeyAccountWirecardResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw new ArgumentException("Error message: " + ex.Message); } }
/// <summary> /// Listar Todos os Webhooks Enviados - List All Sent Webhooks /// </summary> /// <returns></returns> public async Task <WebhooksResponse> ListWebhooks() { HttpResponseMessage response = await ClientInstance.GetAsync("v2/webhooks"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <WebhooksResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Consultar Plano - Consult Plan /// </summary> /// <param name="code"> Código do plano </param> /// <returns></returns> public async Task <PlanResponse> ConsultPlan(string code) { HttpResponseMessage response = await ClientInstance.GetAsync($"assinaturas/v1/plans/{code}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <PlanResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Listar Reembolsos do Pedido - List Order Reimbursements /// </summary> /// <param name="orders_id">Id do pedido em formato de hash. string(16).</param> /// <returns></returns> public async Task <List <RefundResponse> > ListOrders(string orders_id) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/orders/{orders_id}/refunds"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <List <RefundResponse> >(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Obter Arquivo de Vendas - Get Sales File /// </summary> /// <param name="date">Data no formato YYYYMMDD</param> /// <returns></returns> public async Task <SalesFileResponse> GetSalesFile(string date) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/reconciliations/sales/{date}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <SalesFileResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Listar Extrato Futuro - List Future Extract /// </summary> /// <param name="begin">Data de início de exibição no formato YYYY-MM-DD.</param> /// <param name="end">Data de fim de exibição no formato YYYY-MM-DD.</param> /// <returns></returns> public async Task <ExtractResponse> ListFuture(string begin, string end) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/futurestatements?begin={begin}&end={end}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <ExtractResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Detalhes do Extrato - Extract Details /// </summary> /// <param name="type">Tipo do extrato</param> /// <param name="date">Data para visualizar os detalhes no formato YYYY-MM-DD.</param> /// <returns></returns> public async Task <ExtractResponse> Detail(string type, string date) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/statements/details?type={type}&date={date}"); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); WirecardException.WirecardError wirecardException = WirecardException.DeserializeObject(content); throw new WirecardException(wirecardException, "HTTP Response Not Success", content, (int)response.StatusCode); } try { return(JsonConvert.DeserializeObject <ExtractResponse>(await response.Content.ReadAsStringAsync())); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// Conta Existe - Account Exist /// </summary> /// <param name="email_document">email ou documento (cpf/cnpj)</param> /// <returns></returns> public async Task <HttpStatusCode> AccountExist(string email_document) { HttpResponseMessage response = await ClientInstance.GetAsync($"v2/accounts/exists?{(email_document.Contains("@") ? "email" : "tax_document")}={email_document}"); return(response.StatusCode); }