Esempio n. 1
0
 /// <summary>
 ///     Constructor for use if the keys and SIN are managed by this library.
 /// </summary>
 /// <param name="environment">Target environment. Options: Env.Test / Env.Prod</param>
 /// <param name="privateKeyPath">Private Key file path.</param>
 /// <param name="tokens">Env.Tokens containing the available tokens.</param>
 public BitPay(string environment, string privateKeyPath, Env.Tokens tokens)
 {
     _env = environment;
     BuildConfig(privateKeyPath, tokens);
     InitKeys().Wait();
     Init().Wait();
 }
Esempio n. 2
0
        /// <summary>
        ///     Builds the configuration object
        /// </summary>
        /// <returns></returns>
        private void BuildConfig(string privateKeyPath, Env.Tokens tokens)
        {
            try
            {
                if (!File.Exists(privateKeyPath))
                {
                    throw new Exception("Private Key file not found");
                }
                var config = new Dictionary <string, string>
                {
                    { "BitPayConfiguration:Environment", _env },
                    { "BitPayConfiguration:EnvConfig:" + _env + ":PrivateKeyPath", privateKeyPath },
                    { "BitPayConfiguration:EnvConfig:" + _env + ":ApiTokens:pos", tokens.POS },
                    { "BitPayConfiguration:EnvConfig:" + _env + ":ApiTokens:merchant", tokens.Merchant },
                    { "BitPayConfiguration:EnvConfig:" + _env + ":ApiTokens:payroll", tokens.Payout }
                };

                var builder = new ConfigurationBuilder().AddInMemoryCollection(config);
                _configuration = builder.Build();
            }
            catch (Exception ex)
            {
                throw new ConfigNotFoundException(ex);
            }
        }