anypay_razorpay 0.0.2 copy "anypay_razorpay: ^0.0.2" to clipboard
anypay_razorpay: ^0.0.2 copied to clipboard

Razorpay adapter for AnyPay, enabling Razorpay payments in Flutter.

example/lib/main.dart

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

void main() {
  // Initialize bindings BEFORE using any platform channel
  WidgetsFlutterBinding.ensureInitialized();

  // Create Razorpay config
  final razorpayConfig = RazorpayConfig(
    key: 'YOUR_RAZOR_PAY_KEY',
    name: 'Test Shop',
    description: 'Test Payment',
    prefill: {'contact': '9999999999', 'email': 'test@example.com'},
  );

  // Register Razorpay adapter
  AnyPay.registerAdapter('razorpay', RazorpayAdapter(razorpayConfig));

  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: RazorpayExamplePage());
  }
}

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

  @override
  State<RazorpayExamplePage> createState() => _RazorpayExamplePageState();
}

class _RazorpayExamplePageState extends State<RazorpayExamplePage> {
  bool _isProcessing = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('AnyPay Razorpay Example')),
      body: Center(
        child: ElevatedButton(
          onPressed: _isProcessing ? null : _payWithRazorpay,
          child: const Text('Pay 500 INR with Razorpay'),
        ),
      ),
    );
  }

  Future<void> _payWithRazorpay() async {
    setState(() => _isProcessing = true);

    try {
      final result = await AnyPay.chargeWithName(
        providerName: 'razorpay',
        options: PaymentOptions(
          amount: 50000, // 500 INR in paise
          currency: 'INR',
          metadata: {'orderId': 'ORD001'},
        ),
      );

      if (!mounted) return;

      // Optional overlay feedback
      PaymentStatusOverlay.show(
        context,
        status: result.status,
        message: result.message ?? '',
      );

      // Developer-defined UI
      _showDialog(result.status.name, result.message ?? '');
    } catch (e) {
      if (mounted) _showDialog('Error', e.toString());
    } finally {
      if (mounted) setState(() => _isProcessing = false);
    }
  }

  void _showDialog(String title, String message) {
    showDialog(
      context: context,
      builder: (_) => AlertDialog(
        title: Text(title),
        content: Text(message),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context),
            child: const Text('OK'),
          ),
        ],
      ),
    );
  }
}
1
likes
160
points
134
downloads

Publisher

unverified uploader

Weekly Downloads

Razorpay adapter for AnyPay, enabling Razorpay payments in Flutter.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

anypay, flutter, razorpay_flutter

More

Packages that depend on anypay_razorpay