@@ -6,6 +6,40 @@ import 'package:mind_paystack/src/ui/theme.dart';
66import 'package:mind_paystack/src/utils/logger.dart' ;
77
88class MindPaystackConfig {
9+
10+ MindPaystackConfig ({
11+ required this .publicKey,
12+ Environment environment = Environment .test,
13+ LogLevel logLevel = LogLevel .info,
14+ this .retryPolicy = const RetryPolicy (),
15+ String currency = 'NGN' ,
16+ String locale = 'en' ,
17+ MPTheme ? theme,
18+ Duration ? timeout,
19+ }) : _environment = environment,
20+ _logLevel = logLevel,
21+ _currency = currency,
22+ _locale = locale,
23+ _theme = theme,
24+ timeout = timeout ?? const Duration (seconds: 30 ) {
25+ _validateConfig ();
26+ _initializeLogger ();
27+ }
28+
29+ /// Create config from environment variables
30+ factory MindPaystackConfig .fromEnvironment () {
31+ const publicKey = String .fromEnvironment ('PAYSTACK_PUBLIC_KEY' );
32+ const environment =
33+ String .fromEnvironment ('PAYSTACK_ENVIRONMENT' , defaultValue: 'test' );
34+ const logLevel =
35+ String .fromEnvironment ('PAYSTACK_LOG_LEVEL' , defaultValue: 'info' );
36+
37+ return MindPaystackConfig (
38+ publicKey: publicKey,
39+ environment: Environment .fromString (environment),
40+ logLevel: LogLevel .fromString (logLevel),
41+ );
42+ }
943 /// API public key from Paystack dashboard
1044 final String publicKey;
1145
@@ -33,25 +67,6 @@ class MindPaystackConfig {
3367 /// Timeout duration for API requests
3468 final Duration timeout;
3569
36- MindPaystackConfig ({
37- required this .publicKey,
38- Environment environment = Environment .test,
39- LogLevel logLevel = LogLevel .info,
40- this .retryPolicy = const RetryPolicy (),
41- String currency = 'NGN' ,
42- String locale = 'en' ,
43- MPTheme ? theme,
44- Duration ? timeout,
45- }) : _environment = environment,
46- _logLevel = logLevel,
47- _currency = currency,
48- _locale = locale,
49- _theme = theme,
50- timeout = timeout ?? const Duration (seconds: 30 ) {
51- _validateConfig ();
52- _initializeLogger ();
53- }
54-
5570 /// Environment getter
5671 Environment get environment => _environment;
5772
@@ -114,21 +129,6 @@ class MindPaystackConfig {
114129 MPLogger .info ('Custom logger set' );
115130 }
116131
117- /// Create config from environment variables
118- factory MindPaystackConfig .fromEnvironment () {
119- const publicKey = String .fromEnvironment ('PAYSTACK_PUBLIC_KEY' );
120- const environment =
121- String .fromEnvironment ('PAYSTACK_ENVIRONMENT' , defaultValue: 'test' );
122- const logLevel =
123- String .fromEnvironment ('PAYSTACK_LOG_LEVEL' , defaultValue: 'info' );
124-
125- return MindPaystackConfig (
126- publicKey: publicKey,
127- environment: Environment .fromString (environment),
128- logLevel: LogLevel .fromString (logLevel),
129- );
130- }
131-
132132 /// Validate configuration
133133 void _validateConfig () {
134134 if (publicKey.isEmpty) {
@@ -193,7 +193,7 @@ class MindPaystackConfig {
193193 retryPolicy: retryPolicy ?? this .retryPolicy,
194194 currency: currency ?? this .currency,
195195 locale: locale ?? this .locale,
196- theme: theme ?? this . _theme,
196+ theme: theme ?? _theme,
197197 timeout: timeout ?? this .timeout,
198198 );
199199 }
0 commit comments