braintree / braintree_dotnet

Braintree .NET library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
136 stars 73 forks source link

BraintreeGateway Does not Work With Variables #120

Closed MSIH closed 2 years ago

MSIH commented 2 years ago

General information

Issue description

@using Microsoft.Extensions.Configuration
@inject IConfiguration AppConfiguration

    Environment = AppConfiguration["Braintree:Sandbox:BraintreeEnvironment"];
    MerchantId = AppConfiguration["Braintree:Sandbox:BraintreeMerchantId"];
    PublicKey = AppConfiguration["Braintree:Sandbox:BraintreePublicKey"];
    PrivateKey = AppConfiguration["Braintree:Sandbox:BraintreePrivateKey"];

This works: gateway = new BraintreeGateway(Environment, MerchantId, PublicKey, PrivateKey);

This gives the error "cannot convert string to Braintree Environment"

        gateway = new BraintreeGateway(Environment, MerchantId, PublicKey, PrivateKey);
        {
            Environment = Environment,
            MerchantId = MerchantId,
           PublicKey = PublicKey,
           PrivateKey = PrivateKey
       }
    }
smendoza88 commented 2 years ago

I had that problem too, I ended up doing

 BraintreeGateway Gateway = new BraintreeGateway
{
      Environment = Braintree.Environment.ParseEnvironment(Configuration["BT:Environment"]),
      MerchantId = Configuration["BT:MerchantId"],
      PublicKey = Configuration["BT:PublicKey"],
      PrivateKey = Configuration["BT:PrivateKey"]
};
hollabaq86 commented 2 years ago

👋 thanks for reaching out, @smendoza88's is correct, you need to parse the Braintree.Environment.