Beispiel #1
0
        public MundipaggResponse <string> CreateAccessToken()
        {
            string accessTokenEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers/{this.CustomerId}/access-tokens";

            NameValueCollection createAccessTokenHeader = new NameValueCollection {
                { "Authorization", this.Authorization }
            };

            WebResponse <string> createAccessTokenResult = RestClient.SendHttpWebRequest <string>(null, HttpVerb.Post, HttpContentType.Json, accessTokenEndpoint, createAccessTokenHeader, true);

            bool createAccessTokenSuccess = createAccessTokenResult.IsSuccessStatusCode;

            MundipaggResponse <string> response = new MundipaggResponse <string> {
                Success = createAccessTokenSuccess
            };

            dynamic deserializedResult = Serializer.DynamicDeserialize(createAccessTokenResult.RawData);

            if (createAccessTokenSuccess)
            {
                response.ResponseData = (string)deserializedResult.code;
            }
            else
            {
                response.Error = deserializedResult.message;
            }

            return(response);
        }
        public static MundipaggResponse <bool> Delete(string creditCardKey)
        {
            string creditCardEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers/{CustomerId}/cards/{creditCardKey}";

            NameValueCollection header = new NameValueCollection {
                { "Authorization", Authorization }
            };

            WebResponse <string> result = RestClient.SendHttpWebRequest <string>(null, HttpVerb.Delete, HttpContentType.Json, creditCardEndpoint, header, true);

            MundipaggResponse <bool> response = new MundipaggResponse <bool> {
                Success = result.IsSuccessStatusCode
            };

            if (result.IsSuccessStatusCode)
            {
                MundipaggCreditCardData creditCardData = Serializer.NewtonsoftDeserialize <MundipaggCreditCardData>(result.ResponseData);
                response.ResponseData = string.IsNullOrWhiteSpace(creditCardData.Status) == false && "delete".Equals(creditCardData.Status, StringComparison.OrdinalIgnoreCase) == true;
            }
            else
            {
                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    return new MundipaggResponse <bool> {
                               Success = true, ResponseData = true
                    }
                }
                ;

                dynamic deserializedResult = Serializer.DynamicDeserialize(result.RawData);
                response.Error = deserializedResult.message;
            }

            return(response);
        }
        public static MundipaggResponse <IEnumerable <MundipaggCreditCardData> > GetAll()
        {
            string creditCardEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers/{CustomerId}/cards";

            NameValueCollection header = new NameValueCollection {
                { "Authorization", Authorization }
            };

            WebResponse <string> result = RestClient.SendHttpWebRequest <string>(null, HttpVerb.Get, HttpContentType.Json, creditCardEndpoint, header, true);

            MundipaggResponse <IEnumerable <MundipaggCreditCardData> > response = new MundipaggResponse <IEnumerable <MundipaggCreditCardData> > {
                Success = result.IsSuccessStatusCode
            };

            dynamic deserializedResult = Serializer.DynamicDeserialize(result.ResponseData);

            if (result.IsSuccessStatusCode)
            {
                response.ResponseData = Serializer.NewtonsoftDeserialize <IEnumerable <MundipaggCreditCardData> >(Convert.ToString(deserializedResult.data));
            }
            else
            {
                response.Error = deserializedResult.message;
            }

            return(response);
        }
        public static MundipaggResponse <string> Create(MundipaggCreditCardData creditCardInfo)
        {
            string creditCardEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers/{CustomerId}/cards";

            NameValueCollection header = new NameValueCollection {
                { "Authorization", Authorization }
            };

            WebResponse <string> result = RestClient.SendHttpWebRequest <string>(creditCardInfo, HttpVerb.Post, HttpContentType.Json, creditCardEndpoint, header, true);

            MundipaggResponse <string> response = new MundipaggResponse <string> {
                Success = result.IsSuccessStatusCode
            };

            if (result.IsSuccessStatusCode)
            {
                MundipaggCreditCardData creditCardData = Serializer.NewtonsoftDeserialize <MundipaggCreditCardData>(result.ResponseData);
                response.ResponseData = creditCardData.Token;
            }
            else
            {
                dynamic deserializedResult = Serializer.DynamicDeserialize(result.ResponseData);
                response.Error = deserializedResult.message;
            }

            return(response);
        }
Beispiel #5
0
        public MundipaggResponse <string> CreateCustomer(string name, string email)
        {
            string customersEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers";

            NameValueCollection createCustomerHeader = new NameValueCollection {
                { "Authorization", this.Authorization }
            };

            WebResponse <string> createCustomerResult = RestClient.SendHttpWebRequest <string>(new { name, email }, HttpVerb.Post, HttpContentType.Json, customersEndpoint, createCustomerHeader, true);

            bool createdCustomerSuccess = createCustomerResult.IsSuccessStatusCode;

            MundipaggResponse <string> response = new MundipaggResponse <string> {
                Success = createdCustomerSuccess
            };

            dynamic deserializedResult = Serializer.DynamicDeserialize(createCustomerResult.RawData);

            if (createdCustomerSuccess)
            {
                response.ResponseData = (string)deserializedResult.id;
            }
            else
            {
                response.Error = deserializedResult.message;
            }

            return(response);
        }
Beispiel #6
0
        public MundipaggResponse <string> CreateCheckoutToken(MundipaggPaymentData orderData, MundipaggAddressData addressData = null)
        {
            #region Dynamic Token Parameters

            object addressParameter = null;

            if (addressData != null)
            {
                var address = new {
                    editable     = false,
                    street       = addressData.Street,
                    number       = addressData.Number,
                    complement   = addressData.Complement,
                    zip_code     = addressData.ZipCode.GetDigits(),
                    neighborhood = addressData.District,
                    city         = addressData.City,
                    state        = addressData.State,
                    country      = addressData.CountryIsoCode
                };

                addressParameter = address;
            }

            var orderParameter = new {
                items = orderData.OrderDataCollection.Select(itemData => new { amount = itemData.AmountInCents, description = itemData.Description, quantity = itemData.Quantity }).Cast <object>().ToList()
            };

            List <object> installmentCollection = new List <object> {
                new {
                    installments = orderData.Installments,
                    total_amount = orderData.TotalAmountInCents
                }
            };

            var cardParameters = new {
                capture = "true",
                statement_descriptor = orderData.StatementDescriptor,
                installments         = installmentCollection
            };

            var paymentSettingsParameters = new {
                default_payment_method   = "credit_card",
                accepted_payment_methods = new[] { "credit_card" },
                card = cardParameters
            };

            var data = new {
                expires_in        = 30,
                type              = "order",
                order             = orderParameter,
                customer_id       = this.CustomerId,
                customer_editable = false,
                shippable         = false,
                currency          = "BRL",
                success_url       = orderData.SuccessUrl,
                billing_address   = addressParameter,
                payment_settings  = paymentSettingsParameters
            };

            #endregion

            string createTokenEndpoint = $"{MUNDIPAGG_COMMERCE_HOST_ADDRESS}/tokens";

            NameValueCollection createTokenHeader = new NameValueCollection {
                { "Authorization", this.Authorization }
            };

            WebResponse <string> createTokenResult = RestClient.SendHttpWebRequest <string>(data, HttpVerb.Post, HttpContentType.Json, createTokenEndpoint, createTokenHeader, true);

            bool createTokenSuccess = createTokenResult.IsSuccessStatusCode;

            MundipaggResponse <string> response = new MundipaggResponse <string> {
                Success = createTokenSuccess
            };

            dynamic deserializedResult = Serializer.DynamicDeserialize(createTokenResult.RawData);

            if (createTokenSuccess)
            {
                response.ResponseData = (string)deserializedResult.id;
            }
            else
            {
                response.Error = deserializedResult.Message;
            }

            return(response);
        }