Ejemplo n.º 1
0
        /// <summary>
        /// Criar Preferência de Notificação para App - Create Notification Preference for App
        /// </summary>
        /// <param name="body"></param>
        /// <param name="app_id">Código identificador do App. Exemplo: APP-3984HG73HE92</param>
        /// <returns></returns>
        public async Task <NotificationResponse> CreateApp(NotificationRequest body, string app_id)
        {
            Regex regex = new Regex(@"^APP-[a-zA-Z0-9]{12}$");
            Match match = regex.Match(app_id);

            if (!match.Success)
            {
                throw new ArgumentException("app_id invalid");
            }
            StringContent       stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync($"v2/preferences/{app_id}/notifications", stringContent);

            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 <NotificationResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Criar Assinante - Create Subscriber
        /// </summary>
        /// <param name="body"></param>
        /// <param name="new_vault">Se new_vault=true, o envio do node credit_card é obrigatório. Utilize isso para criar um assinante com dados de cartão e gerar um cofre para guardar os dados de pagamento com segurança no Moip.</param>
        /// <returns></returns>
        public async Task <SubscriberResponse> CreateSubscriber(SubscriberRequest body, bool new_vault)
        {
            string json;

            try
            {
                json = JsonConvert.SerializeObject(body);
                JObject jObject = JObject.Parse(json);
                jObject["address"]["streetNumber"].Rename("number");
                jObject["address"]["zipCode"].Rename("zipcode");
                json = jObject.ToString();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            StringContent       stringContent = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync($"assinaturas/v1/customers?new_vault={new_vault}", stringContent);

            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 <SubscriberResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Criar Preferência de Notificação - Create Notification Preference
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public async Task <HttpStatusCode> CreateNotificationPreference(NotificationRequest body)
        {
            StringContent       stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync("assinaturas/v1/users/preferences", stringContent);

            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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retentativa pagamento de fatura - Retentive invoice payment
        /// </summary>
        /// <param name="id">ID da fatura</param>
        /// <returns></returns>
        public async Task <HttpStatusCode> RetentiveInvoicePayment(string id)
        {
            StringContent       stringContent = new StringContent(null, Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync($"assinaturas/v1/invoices/{id}/retry", stringContent);

            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>
 /// Capturar Multi Pagamento Pré-Autorizado - Capture Multi-Payment Pre-authorized
 /// </summary>
 /// <param name="multipayment_id">Id identificador do multipagamento.</param>
 /// <returns></returns>
 public async Task<MultiPaymentResponse> CaptureAuthorized(string multipayment_id)
 {
     HttpResponseMessage response = await ClientInstance.PostAsync($"v2/multipayments/{multipayment_id}/capture", null);
     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;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Associar Cupom para Nova Assinatura - Associate Coupon For New Signature
        /// </summary>
        /// <param name="body"></param>
        /// <param name="true_or_false">Caso queira criar um novo Assinante o valor desse ser "true", caso contrário "false".</param>
        /// <returns></returns>
        public async Task <CouponResponse> AssociateCouponForNewSignature(CouponRequest body, string true_or_false)
        {
            string json;

            try
            {
                json = JsonConvert.SerializeObject(body);
                JObject jObject = JObject.Parse(json);
                if (jObject["customer"]["address"] != null)
                {
                    if (jObject["customer"]["address"]["streetNumber"] != null)
                    {
                        jObject["customer"]["address"]["streetNumber"].Rename("number");
                    }
                    if (jObject["customer"]["address"]["zipCode"] != null)
                    {
                        jObject["customer"]["address"]["zipCode"].Rename("zipcode");
                    }
                }
                json = jObject.ToString();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            StringContent       stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync($"assinaturas/v1/subscriptions?new_customer={true_or_false}", stringContent);

            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 <CouponResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// Criar Multi Pagamento - Create multi payment
 /// </summary>
 /// <param name="body"></param>
 /// <param name="multiorder_id">Código identificador do multipedido. Exemplo: MOR-XXXXXXXX</param>
 /// <returns></returns>
 public async Task<MultiPaymentResponse> Create(MultiPaymentRequest body, string multiorder_id)
 {
     StringContent stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
     HttpResponseMessage response = await ClientInstance.PostAsync($"v2/multiorders/{multiorder_id}/multipayments", stringContent);
     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>
        /// Liberação de Custódia - Release of Custody
        /// </summary>
        /// <param name="escrow_id">Código identificador da custódia. Exemplo ECW-9OS6FAPR3FD5</param>
        /// <returns></returns>
        public async Task <PaymentResponse> ReleaseCustody(string escrow_id)
        {
            HttpResponseMessage response = await ClientInstance.PostAsync($"escrows/{escrow_id}/release", null);

            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 <PaymentResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw new ArgumentException("Error message: " + ex.Message);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Criar Preferência de Notificação para Conta Wirecard - Create Notification Preference for Wirecard Account
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public async Task <NotificationResponse> CreatAccountWirecard(NotificationRequest body)
        {
            StringContent       stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync("v2/preferences/notifications", stringContent);

            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 <NotificationResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Criar novo boleto de fatura - Create New Invoice Boleto
        /// </summary>
        /// <param name="body"></param>
        /// <param name="id">ID da fatura</param>
        /// <returns></returns>
        public async Task <RetentativeResponse> CreateNewInvoiceBoleto(RetentativeRequest body, string id)
        {
            StringContent       stringContent = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
            HttpResponseMessage response      = await ClientInstance.PostAsync($"assinaturas/v1/invoices/{id}/boletos", stringContent);

            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 <RetentativeResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }