paystack_africa 2.0.0 copy "paystack_africa: ^2.0.0" to clipboard
paystack_africa: ^2.0.0 copied to clipboard

Flutter helper to create Paystack payment sessions, open an in-app WebView checkout, and return success/failure results with typed responses.

example/main.dart

import 'package:flutter/material.dart';
import 'package:paystack_africa/lib/src/core/payment_result.dart';
import 'package:paystack_africa/lib/src/gateways/paystack/paystack_gateway.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Paystack Example',
      theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  static const publicKey = String.fromEnvironment(
    'PAYSTACK_PUBLIC_KEY',
    defaultValue: 'pk_test_example_for_dev_only',
  );

  @override
  Widget build(BuildContext context) {
    final gateway = PaystackGateway(publicKey: publicKey);

    return Scaffold(
      appBar: AppBar(title: const Text('Paystack (WebView) Example')),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            final res = await gateway.pay(
              context: context,
              amountSmallestUnit: 150000, // ₦1,500
              email: 'customer@example.com',
            );
            final msg = res.isSuccess
                ? 'SUCCESS: ${(res as PaymentSuccess).data}'
                : 'FAIL: ${(res as PaymentFailure).message}';
            if (context.mounted) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text(msg)),
              );
            }
          },
          child: const Text('Pay ₦1,500'),
        ),
      ),
    );
  }
}
1
likes
160
points
42
downloads

Publisher

verified publishergoutam.info

Weekly Downloads

Flutter helper to create Paystack payment sessions, open an in-app WebView checkout, and return success/failure results with typed responses.

Repository (GitHub)
View/report issues

Topics

#payments #checkout #paystack #nigeria

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, webview_flutter

More

Packages that depend on paystack_africa