ccavenue_india_sdk_flutter 1.0.1 copy "ccavenue_india_sdk_flutter: ^1.0.1" to clipboard
ccavenue_india_sdk_flutter: ^1.0.1 copied to clipboard

A Flutter plugin for integrating CCAvenue Payment Gateway in Android and iOS applications. Supports environments and customization.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:ccavenue_india_sdk_flutter/ccavenue_india_sdk_flutter.dart'; // Your package
import 'package:ccavenue_india_sdk_flutter/ccavenue_order_model.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'CCAvenue Payment Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primaryColor: const Color(0xFF164880),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final _amountController = TextEditingController(text: "170.00");
  final _sdk = CcavenueIndiaSdk(); // Initialize your SDK
  String errorText = "";
  bool _loading = false;

  Future<void> _initiatePayment() async {
    setState(() {
      _loading = true;
      errorText = "";
    });

    try {
      final order = CCAvenueOrderModel(
        accessCode: "AVZC42NB40AS14CZSA",
        amount: _amountController.text,
        currency: "INR",
        trackingId: "2130000002080911",
        requestHash: "72dbbe423daed0af6f2d782f845f7a7baa52e17ab57b320a0e163c2c9367f40b02033bbb486ba2a703a33943e52bc18229b927b0e19c3339fbb3c286750df9b2",
        // Customization
        paymentType: "all",
        environment: 'qa',
        // New Fields as per request
        displayDialog: "yes", 
        displayPromo: "yes",
        ignorePaymentType: [], // Example: ["CREDIT_CARD", "DEBIT_CARD"]
        customerId: "123456",
        promoCode: "",
        promoSkuCode: "",
      );

      // 2. Call the SDK - this triggers the native bridge
      final String? response = await _sdk.initiatePayment(order);

      if (!mounted) return;

      setState(() {
        _loading = false;
      });

      // 3. Show the raw response returned from Native (Kotlin/Swift)
      _showResponseDialog(response ?? "No response received");

    } catch (e) {
      setState(() {
        _loading = false;
        errorText = "Error: $e";
      });
    }
  }

  void _showResponseDialog(String response) {
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: const Text('CCAvenue SDK Response'),
        content: SingleChildScrollView(
          child: Text(
            response,
            style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
          ),
        ),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context),
            child: const Text('OK'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('CCAvenue India SDK'),
        centerTitle: true,
        backgroundColor: const Color(0xFF164880),
        foregroundColor: Colors.white,
      ),
      body: _loading
          ? const Center(child: CircularProgressIndicator())
          : Padding(
              padding: const EdgeInsets.all(20.0),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Icon(Icons.account_balance_wallet, size: 80, color: Color(0xFF164880)),
                  const SizedBox(height: 40),
                  TextField(
                    controller: _amountController,
                    keyboardType: const TextInputType.numberWithOptions(decimal: true),
                    decoration: InputDecoration(
                      labelText: "Payment Amount",
                      prefixIcon: const Icon(Icons.currency_rupee),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(12),
                      ),
                      errorText: errorText.isEmpty ? null : errorText,
                    ),
                  ),
                  const SizedBox(height: 24),
                  SizedBox(
                    width: double.infinity,
                    height: 55,
                    child: ElevatedButton(
                      onPressed: _initiatePayment,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: const Color(0xFF164880),
                        foregroundColor: Colors.white,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(12),
                        ),
                      ),
                      child: const Text(
                        "PROCEED TO PAY",
                        style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
                      ),
                    ),
                  ),
                ],
              ),
            ),
    );
  }

  @override
  void dispose() {
    _amountController.dispose();
    super.dispose();
  }
}
1
likes
140
points
0
downloads

Publisher

verified publisherccavenue.com

Weekly Downloads

A Flutter plugin for integrating CCAvenue Payment Gateway in Android and iOS applications. Supports environments and customization.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ccavenue_india_sdk_flutter

Packages that implement ccavenue_india_sdk_flutter