pagarme / pagarme-net

Pagar.me .NET library
MIT License
42 stars 49 forks source link

Exception of type 'PagarMe.PagarMeException' was thrown (v4 2019-09-01) #145

Open ghost opened 3 years ago

ghost commented 3 years ago

Estou sempre recebendo esse erro : PagarMe.PagarMeException: 'Exception of type 'PagarMe.PagarMeException' was thrown.' no transaction.Save();

Não sei onde está o erro, pois testei exatamente com os parâmetros da DOC (v4 2019-09-01) https://docs.pagar.me/docs/realizando-uma-transacao-de-cartao-de-credito


        PagarMeService.DefaultApiKey = $"{myAPIKey}";
            PagarMeService.DefaultEncryptionKey = $"{myCryptKey}";

            Transaction transaction = new Transaction();

            transaction.Amount = 100;
            transaction.Card = new Card
            {
                CardHash = $"{cardHash}"
            };

            transaction.Customer = new Customer
            {
                ExternalId = $"{externalId}",
                Name = $"{name}",
                Type = CustomerType.Individual,
                Country = "br",
                Email = $"email",
                Documents = new[]
                {
                new Document{
                Type = DocumentType.Cpf,
                Number = $"{cpf}"
                            }
                },
                PhoneNumbers = new string[]
                {
                    $"{phoneNumber}"
                },
                Birthday = new DateTime(1993, 07, 05).ToString("yyyy-MM-dd")
            };

            transaction.Billing = new Billing
            {
                Name = $"{name}",
                Address = new Address()
                {
                    Country = "br",
                    State = "sp",
                    City = $"{city}",
                    Neighborhood = $"{neighborhood}",
                    Street = $"{street}",
                    StreetNumber = $"{streetNumber}",
                    Zipcode = $"{zipCode}"
                }
            };

            transaction.Item = new[]
            {
                new Item()
                {
                    Id = $"{itemId}",
                    Title = $"{itemTitle}",
                    Quantity = 1,
                    Tangible = false,
                    UnitPrice = 100
                }
            };

            transaction.Save();
bonattogabriel commented 3 years ago

Não sei se conseguiu resolver já mas fiz aqui também e para funcionar eu não utilizei transaction.Card = new Card... Tive que passar somente o transaction.CardHash o cardhash e ele funcionou. Teste aí caso não tenha conseguido

vitor-tenorio commented 3 years ago

Tbm não sei se já foi resolvido, mas utilizei um

try 
    transaction.save() 

catch ex as PagarMeException

dentro de ex estava o erro

thiaraujo commented 3 years ago

Ao invés de CardHash, utilize: transaction.Card = new Card { Id = cardHash};