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

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

  Future<void> pay() async {
    const upiId = '9000950877@ybl'; // supplier UPI
    const name = 'Sneha Supplier';
    const amount = '1.00';
    const note = 'Test Payment';

    final uri = Uri.parse(
      'upi://pay?pa=$upiId&pn=$name&am=$amount&cu=INR&tn=$note',
    );

    if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
      throw Exception('Could not launch UPI intent');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Pay with UPI')),
      body: Center(
        child: ElevatedButton(
          onPressed: pay,
          child: const Text('Pay ₹1.00'),
        ),
      ),
    );
  }
}
