paystack_gateway_payment 1.1.2 copy "paystack_gateway_payment: ^1.1.2" to clipboard
paystack_gateway_payment: ^1.1.2 copied to clipboard

Flutter integration for Paystack: easily initialize, verify payments, and use a customizable payment button.

example/example.dart

import 'package:flutter/material.dart';
import 'package:paystack_gateway_payment/paystack_gateway_payment.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // Replace with your Paystack secret key
  final PaystackService paystackService =
      PaystackService(secretKey: 'YOUR_SECRET_KEY');

  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Paystack Example',
      home: Scaffold(
        appBar: AppBar(title: const Text('Paystack Payment Example')),
        body: PaymentScreen(paystackService: paystackService),
      ),
    );
  }
}

class PaymentScreen extends StatefulWidget {
  final PaystackService paystackService;

  const PaymentScreen({super.key, required this.paystackService});

  @override
  State<PaymentScreen> createState() => _PaymentScreenState();
}

class _PaymentScreenState extends State<PaymentScreen> {
  String? _verificationResult;

  // Method to verify a transaction by reference
  Future<void> _verifyTransaction(String reference) async {
    try {
      final response =
          await widget.paystackService.verifyTransaction(reference);
      setState(() {
        _verificationResult = response.status
            ? 'Transaction Verified: ${response.data['reference']}'
            : 'Verification Failed';
      });
    } catch (e) {
      setState(() {
        _verificationResult = 'Verification Error: ${e.toString()}';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          PaystackButton(
            paystackService: widget.paystackService,
            email: 'user@example.com',
            amount: 5000, // Amount in base currency units (e.g., kobo for NGN)
            callbackUrl: 'https://your.callback.url/',
            buttonText: const Text('Pay Now'),
            paymentScreenTitle: 'Pay with Paystack',
            buttonIcon: const Icon(Icons.payment),
          ),
          const SizedBox(height: 20),
          ElevatedButton(
            onPressed: () async {
              // Replace with a valid reference from a real transaction
              String reference = 'YOUR_TRANSACTION_REFERENCE';
              await _verifyTransaction(reference);
            },
            child: const Text('Verify Transaction'),
          ),
          if (_verificationResult != null) ...[
            const SizedBox(height: 20),
            Text(
              _verificationResult!,
              textAlign: TextAlign.center,
              style: const TextStyle(fontSize: 16, color: Colors.blue),
            ),
          ],
        ],
      ),
    );
  }
}
1
likes
0
points
322
downloads

Publisher

verified publisherhighvertical.com.ng

Weekly Downloads

Flutter integration for Paystack: easily initialize, verify payments, and use a customizable payment button.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http, webview_flutter

More

Packages that depend on paystack_gateway_payment