fatoorah_pay 1.0.0 copy "fatoorah_pay: ^1.0.0" to clipboard
fatoorah_pay: ^1.0.0 copied to clipboard

A comprehensive Flutter SDK for integrating MyFatoorah payment gateway with support for payments, subscriptions, transactions, and account management.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:fatoorah_pay/fatoorah_pay.dart';
import 'package:url_launcher/url_launcher.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Fatoorah Pay Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const ExamplePage(),
    );
  }
}

class ExamplePage extends StatefulWidget {
  const ExamplePage({super.key});

  @override
  State<ExamplePage> createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  late final FatoorahPay sdk;
  bool _isLoading = false;

  @override
  void initState() {
    sdk = FatoorahPay(
      baseUrl: 'https://pay.fatoorah.ai',
      apiKey: 'YOUR_API_KEY',
      debugMode: true,
    );

    super.initState();
  }

  //FULL EXAMPLE REPO FOR ALL SECTIONS
  //USE THIS REPO PLEASE FOR SPECIFIC AND EASY INTEGERATION PROCESS

  Future<void> _openExamplesRepo() async {
    await launchUrl(
      Uri.parse(
        'https://github.com/fatoorahsa/fatoorah_pay_flutter_example/tree/main/examples',
      ),
      mode: LaunchMode.inAppBrowserView,
    );
  }

  Future<void> _createPaymentLink() async {
    try {
      setState(() => _isLoading = true);

      final result = await sdk.createPaymentLink(
        PaymentLinkRequest(
          isLive: false,
          amountCents: 10000,
          fullName: 'name',
          email: '[email protected]',
          phoneNumber: '+966555123456',
          description: 'Invoice #INV-2025-001',
          expiresAt: DateTime.now().toUtc().add(Duration(hours: 24)),
        ),
      );
      result.when(
        onSuccess: (link) {
          print('Payment Link Created!');
          // HERE YOU HAVE YOUR PAYMENT LINK DATA
          print('URL: ${link.paymentUrl}');
          _showSuccessDialog(link);
        },
        onFailure: (error) {
          print('Error: ${error.message}');
          _showErrorDialog(error.message);
        },
      );
    } catch (e) {
      print('Error: $e');
      _showErrorDialog('Error: $e');
    } finally {
      setState(() => _isLoading = false);
    }
  }

  void _showSuccessDialog(PaymentLink link) {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: const Text('Payment Link Created!'),
        content: Text('URL: ${link.paymentUrl}'),
        actions: [
          TextButton(
            onPressed: () => Navigator.of(context).pop(),
            child: const Text('OK'),
          ),
        ],
      ),
    );
  }

  void _showErrorDialog(String message) {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: const Text('Error'),
        content: Text(message),
        actions: [
          TextButton(
            onPressed: () => Navigator.of(context).pop(),
            child: const Text('OK'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Fatoorah Pay Example'),
        actions: [
          IconButton(
            onPressed: _openExamplesRepo,
            icon: const Icon(Icons.code),
            tooltip: 'View More Examples',
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Container(
              padding: const EdgeInsets.all(16),
              decoration: BoxDecoration(
                color: Colors.blue.shade50,
                borderRadius: BorderRadius.circular(8),
                border: Border.all(color: Colors.blue.shade200),
              ),
              child: Column(
                children: [
                  const Icon(Icons.code, size: 48, color: Colors.blue),
                  const SizedBox(height: 8),
                  const Text(
                    'Need More Examples?',
                    style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
                  ),
                  const SizedBox(height: 8),
                  ElevatedButton.icon(
                    onPressed: _openExamplesRepo,
                    icon: const Icon(Icons.launch),
                    label: const Text('View Complete Examples on GitHub'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colors.blue,
                      foregroundColor: Colors.white,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 24),
            const Text(
              'Create Payment Link',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: _isLoading ? null : _createPaymentLink,
              child: _isLoading
                  ? const SizedBox(
                      width: 20,
                      height: 20,
                      child: CircularProgressIndicator(strokeWidth: 2),
                    )
                  : const Text('Create Payment Link'),
            ),
          ],
        ),
      ),
    );
  }
}
4
likes
150
points
75
downloads

Publisher

unverified uploader

Weekly Downloads

A comprehensive Flutter SDK for integrating MyFatoorah payment gateway with support for payments, subscriptions, transactions, and account management.

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter

More

Packages that depend on fatoorah_pay