Configuration
PaystackConfig
centralizes environment, keys, logging, retry behavior, and defaults used by the SDK.
Basics
final config = PaystackConfig(
publicKey: 'pk_test_xxx',
secretKey: 'sk_test_xxx',
environment: Environment.test, // test | staging | production
logLevel: LogLevel.info, // debug | info | warning | error
retryPolicy: const RetryPolicy(),
// currency: 'NGN',
// locale: 'en',
// timeout: Duration(seconds: 30),
);
await MindPaystack.init(config);
Keys and environments
- Use
pk_test_...
/sk_test_...
keys in non‑production; production requirespk_live_...
/sk_live_...
. - The SDK prevents test keys in
Environment.production
.
config.environment = Environment.production; // validates keys
Logging
config.logLevel = LogLevel.debug; // verbose logs via internal logger
Retry policy
RetryPolicy
handles exponential backoff with jitter for retryable status codes.
final retry = const RetryPolicy(
maxAttempts: 3,
initialDelayMs: 1000,
maxDelayMs: 30000,
backoffFactor: 2.0,
jitterFactor: 0.2,
retryNonIdempotentRequests: false,
retryableStatusCodes: {408,429,500,502,503,504},
);
final config = PaystackConfig(
publicKey: 'pk_test_xxx',
secretKey: 'sk_test_xxx',
retryPolicy: retry,
);
Timeouts and headers
All requests use timeout
from PaystackConfig
. The client adds:
Authorization: Bearer <key>
x-request-id
,idempotency-key
,x-sdk-name
,x-sdk-version
,x-environment
Environment base URLs
The HTTP client targets https://api.paystack.co
. You can still set Environment
for meta headers and validations.
Creating from environment variables
final config = PaystackConfig.fromEnvironment();
Reads PAYSTACK_PUBLIC_KEY
, PAYSTACK_SECRET_KEY
, PAYSTACK_ENVIRONMENT
, PAYSTACK_LOG_LEVEL
from compile‑time environment.
Last updated on