Home > Mobile >  Exception of type 'Braintree.Exceptions.AuthenticationException' was thrown, even thought
Exception of type 'Braintree.Exceptions.AuthenticationException' was thrown, even thought

Time:07-14

I'm trying to use the Sandbox Environment, but I can't seem to authenticate for some reason,

Here the method:

public Customer CreateCustomer(
        User user)
    {
        var request = new CustomerRequest
        {
            FirstName = user.Firstname,
            LastName = user.Lastname,
            Email = user.Email
        };

        try{
            var gateway = new BraintreeGateway
              {
               Environment = Braintree.Environment.SANDBOX,
               MerchantId  = "rmzzy8txvc2w35pg",
               PublicKey   = "wqgg52tmkhsfmn9t",
               PrivateKey  = "86ab47514a195d393db6d1b12350facf"
              };

            Braintree.Result<Customer> result = gateway.Customer.Create(request);

            return result.Target;

        }catch(Exception ex){
            Console.WriteLine(ex.Message);

            return null!;
        }
    }

This API key is valid, as shown In the image below taken from my sandbox account:

Click to see Image

In the try & catch block, this is the exception that I catch:

Exception of type 'Braintree.Exceptions.AuthenticationException' was thrown.

However when I Use(Image used for lack of better way of showing the error)

ClientId Error

What should I Do to fix this?

CodePudding user response:

I checked your second pic, and I found the error message is:

missing clientid when constructing braintreegateway

Then I check the source code about BraintreeGateway. I found IBraintreeGateway interface include Configuration.

So the problem is the literal meaning of the error message, please check.

  • Related