/// <summary> /// Get Remittance client /// </summary> /// <returns></returns> public static IRemittanceClient GetRemittanceClient() { var services = new ServiceCollection(); /** * Change keys if running tests locally */ var config = new RemittanceConfig { ApiKey = "c16cb022f6ee4c82acaa635b3eea2ebd", SubscriptionKey = "cf4f7a46c6804d69b7d605a3e304ffe2", UserId = "7706a623-7c1c-4d25-9cea-06cf06fbda51", Environment = "sandbox", Sandbox = true }; services.AddHttpClient(Common.Constants.MtnClient, c => { c.BaseAddress = new Uri(Common.Constants.Sandbox); c.DefaultRequestHeaders.Add(Common.Constants.EnvHeader, "sandbox"); }); services.AddScoped <IBaseClient, BaseClient>() .AddScoped <ITokenClient, TokenClient>() .AddSingleton(config) .AddScoped <IRemittanceClient, RemittanceClient>() .AddScoped <IAccountBalanceClient, AccountBalanceClient>() .AddScoped <ITransferClient, TransferClient>() .AddScoped <IAccountHolderClient, AccountHolderClient>(); var serviceProvider = services.BuildServiceProvider(); var client = serviceProvider.GetService <IRemittanceClient>(); return(client); }
public RemittanceClient( RemittanceConfig remittanceConfig, ITokenClient tokenClient, IAccountBalanceClient accountBalanceClient, IAccountHolderClient accountHolderClient, ITransferClient transferClient) { this.remittanceConfig = remittanceConfig; this.tokenClient = tokenClient; this.accountBalanceClient = accountBalanceClient; this.accountHolderClient = accountHolderClient; this.transferClient = transferClient; }
/// <summary> /// Mtn Remittance Client /// </summary> /// <param name="services"></param> /// <param name="config"></param> /// <returns></returns> public static IServiceCollection AddMtnRemittanceClient(this IServiceCollection services, RemittanceConfig config) { services.AddHttpClient(Constants.MtnClient, c => { c.BaseAddress = config.Sandbox ? new Uri(Constants.Sandbox) : new Uri(config.BaseUrl); c.DefaultRequestHeaders.Add(Constants.EnvHeader, "sandbox"); }); return(services.AddScoped <IBaseClient, BaseClient>() .AddScoped <ITokenClient, TokenClient>() .AddSingleton(config) .AddScoped <IRemittanceClient, RemittanceClient>() .AddScoped <IAccountBalanceClient, AccountBalanceClient>() .AddScoped <ITransferClient, TransferClient>() .AddScoped <IAccountHolderClient, AccountHolderClient>()); }