Skip to Content
DocumentationGetting Started

Getting Started

Get up and running with MindPaystack in 3 simple steps. This Dart-first SDK works seamlessly across pure Dart projects, Flutter apps, and server-side applications.

Choose Your Setup: Pure Dart backend, Flutter mobile app, or full-stack Dart application


Installation Guide

For Pure Dart Projects (CLI, Server, Backend)

Perfect for Dart VM applications, server-side integrations, or CLI tools:

# Core SDK only - lightweight and framework-agnostic dart pub add mind_paystack

For Flutter Applications

Get the core SDK for Flutter apps (UI components coming soon):

# Core SDK for Flutter dart pub add mind_paystack # Note: mind_paystack_flutter coming soon!

Package Overview

PackageUse CaseStatusFeatures
mind_paystackCore SDK for any Dart projectAvailableTransaction APIs, type-safe models
mind_paystack_flutterFlutter-specific featuresComing SoonUI widgets, platform integration

Quick Start: 3 Steps to Payment

Step 1: Initialize the SDK

Pure Dart Setup:

import 'package:mind_paystack/mind_paystack.dart'; Future<void> main() async { // Initialize once at application startup await MindPaystack.initialize( PaystackConfig( publicKey: 'pk_test_your_public_key', secretKey: 'sk_test_your_secret_key', environment: Environment.test, ), ); // Your application logic here print('MindPaystack initialized successfully!'); }

Flutter Setup:

import 'package:flutter/material.dart'; import 'package:mind_paystack/mind_paystack.dart'; Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); // Initialize before runApp() await MindPaystack.initialize( PaystackConfig( publicKey: 'pk_test_your_public_key', secretKey: 'sk_test_your_secret_key', environment: Environment.test, logLevel: LogLevel.debug, // Helpful during development ), ); runApp(MyApp()); }

Environment Variables Setup (Recommended):

// Create .env file in your project root // PAYSTACK_PUBLIC_KEY=pk_test_your_key // PAYSTACK_SECRET_KEY=sk_test_your_key // PAYSTACK_ENVIRONMENT=test Future<void> main() async { // Automatically reads from environment variables final sdk = await MindPaystack.fromEnvironment(); print('SDK initialized from environment'); }

Step 2: Initialize a Transaction

Type-Safe Transaction Creation:

import 'package:mind_paystack/mind_paystack.dart'; Future<void> createPayment() async { final sdk = MindPaystack.instance; try { final transaction = await sdk.transaction.initialize( InitializeTransactionOptions( email: 'customer@example.com', amount: Money.fromCents(50000, Currency.ngn), // ₦500.00 reference: 'order_${DateTime.now().millisecondsSinceEpoch}', callbackUrl: 'https://yourapp.com/payment/callback', metadata: { 'order_id': '12345', 'customer_name': 'John Doe', }, ), ); // Transaction created successfully print('Payment URL: ${transaction.data.authorizationUrl}'); print('Reference: ${transaction.data.reference}'); // Open authorization URL in browser/webview // await launchUrl(Uri.parse(transaction.data.authorizationUrl)); } on MindException catch (e) { // Handle Paystack-specific errors print('Payment initialization failed: ${e.message}'); print('Error code: ${e.code}'); } }

Step 3: Verify the Payment

Secure Payment Verification:

Future<bool> verifyPayment(String reference) async { final sdk = MindPaystack.instance; try { final verification = await sdk.transaction.verify( VerifyTransactionOptions(reference: reference), ); if (verification.data.status == 'success') { print('Payment successful! ₦${verification.data.amount / 100}'); print('Gateway response: ${verification.data.gatewayResponse}'); return true; } else { print('Payment failed or pending: ${verification.data.status}'); return false; } } on MindException catch (e) { print('Verification failed: ${e.message}'); return false; } }

Complete Example: Payment Flow

Here’s a complete working example that demonstrates the full payment lifecycle:

import 'package:mind_paystack/mind_paystack.dart'; class PaymentService { static Future<void> initialize() async { await MindPaystack.initialize( PaystackConfig( publicKey: 'pk_test_your_key', secretKey: 'sk_test_your_key', environment: Environment.test, ), ); } static Future<String?> createPayment({ required String customerEmail, required int amountInCents, Map<String, dynamic>? metadata, }) async { final sdk = MindPaystack.instance; try { final result = await sdk.transaction.initialize( InitializeTransactionOptions( email: customerEmail, amount: Money.fromCents(amountInCents, Currency.ngn), metadata: metadata, ), ); return result.data.authorizationUrl; } on MindException catch (e) { print('Payment creation failed: ${e.message}'); return null; } } static Future<bool> verifyPayment(String reference) async { final sdk = MindPaystack.instance; try { final result = await sdk.transaction.verify( VerifyTransactionOptions(reference: reference), ); return result.data.status == 'success'; } on MindException catch (e) { print('Verification failed: ${e.message}'); return false; } } } // Usage example Future<void> main() async { // Step 1: Initialize await PaymentService.initialize(); // Step 2: Create payment final paymentUrl = await PaymentService.createPayment( customerEmail: 'customer@example.com', amountInCents: 50000, // ₦500.00 metadata: {'product': 'Premium Subscription'}, ); if (paymentUrl != null) { print('Direct customer to: $paymentUrl'); // Step 3: Verify payment (after customer completes payment) // This would typically happen in a webhook or callback // final isSuccessful = await PaymentService.verifyPayment(reference); } }

Development vs Production

Test Environment (Development)

PaystackConfig( publicKey: 'pk_test_...', // Test public key secretKey: 'sk_test_...', // Test secret key environment: Environment.test, logLevel: LogLevel.debug, // Verbose logging )

Live Environment (Production)

PaystackConfig( publicKey: 'pk_live_...', // Live public key secretKey: 'sk_live_...', // Live secret key environment: Environment.live, logLevel: LogLevel.warning, // Minimal logging )

🚀 Ready to go deeper? Explore our comprehensive guides for specific use cases and advanced features.

Last updated on