jio_payment_sdk 0.0.9 copy "jio_payment_sdk: ^0.0.9" to clipboard
jio_payment_sdk: ^0.0.9 copied to clipboard

A Flutter package to integrate Jio Payment Gateway.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:math';
import 'package:jio_payment_sdk/jio_payment_sdk.dart';

void main() => runApp(const MyApp());

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

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

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

  @override
  State<Homepage> createState() => _HomepageState();
}

class _HomepageState extends State<Homepage> implements PaymentCallback {
  List<OrderItem> orderDetailList = [
    OrderItem(name: "Testing - Object1", image: 'asset/image.png', price: 250.00, description: "Desc", quantity: 1, isAssetImage: true),
    OrderItem(name: "Testing - Object2", image: 'asset/image.png', price: 250.00, description: "Description", quantity: 100, isAssetImage: true),
  ];
  TextEditingController inputPrice = TextEditingController();
  String response = '';

  String merchantTxnNo() {
    final random = Random.secure();
    String txnNo = '';
    for (int i = 0; i < 16; i++) {
      txnNo += random.nextInt(10).toString();
    }
    return "TEST$txnNo";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(response),
              SizedBox(height: 100),
              SizedBox(
                width: 200,
                child: TextField(controller: inputPrice, keyboardType: TextInputType.number),
              ),
              SizedBox(height: 100),
              ElevatedButton(
                onPressed: () {
                  double? am;
                  if (inputPrice.text.isEmpty) {
                    return;
                  }
                  am = double.tryParse(inputPrice.text);
                  if (am == null) {
                    return;
                  }
                  setState(() {
                    response = '';
                  });

                  JioPaymentSdk.initializeJioPayments(
                    /// Required Params.............................
                    context,
                    callback: this,
                    amount: am,
                    env: JioPaymentEnv.prod,
                    merchantId: 'Enter your merchantId',
                    aggId: "Enter your aggregator id", //in uat "",
                    secretKey: "Enter your secret key",
                    email: 'test@gmail.in',
                    userName: 'Test User',
                    merchantName: 'Reliance',
                    merchantImage: "asset/Ajio logo.png",
                    merchantTrId:  merchantTxnNo(), 
                    isAssetMerchantImage: true,
                    /// Optional Params.............................
                    addlParam1: "",
                    addlParam2: "",
                    // orderSummary: OrderSummary(title: "Order Summary", items: orderDetailList),
                    // theme: CustomTheme(primaryColor: const Color.fromRGBO(227, 155, 43, 1), secondaryColor: Colors.black87),
                    // allowedPaymentTypes: ["NB","UPI_QR", "UPI_INTENT", "UPI_VPA","CARD"],
                    // timeOut: 10000000,
                  );
                },
                child: SizedBox(
                  width: double.infinity,
                  child: Center(child: const Text("Pay")),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  @override
  void onPaymentCompletedResponse(PaymentResult result) {
    setState(() {
      response = result.jsonData.toString();
    });
    // showTransactionStatusBottomSheet(context, result);
  }

  Future<void> showTransactionStatusBottomSheet(BuildContext context, PaymentResult result) async {
    Future.delayed(Duration(milliseconds: 10), () {
      showModalBottomSheet(
        // ignore: use_build_context_synchronously
        context: context,
        isScrollControlled: true,
        shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
        builder: (context) {
          return SizedBox(
            width: double.infinity,
            child: Padding(
              padding: const EdgeInsets.all(24.0),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(result.success ? Icons.check_circle : Icons.cancel, color: result.success ? Colors.green : Colors.red, size: 64),
                  const SizedBox(height: 16),
                  Text(
                    result.success ? 'Transaction Successful' : 'Transaction Failed',
                    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: result.success ? Colors.green : Colors.red),
                  ),
                  const SizedBox(height: 8),
                  if (result.transactionId != null && result.success) Text('Txn ID: ${result.transactionId}'),
                  const SizedBox(height: 24),
                  Flexible(child: Text(result.jsonData.toString())),
                  const SizedBox(height: 8),
                  ElevatedButton(onPressed: () => Navigator.pop(context), child: const Text("OK")),
                ],
              ),
            ),
          );
        },
      );
    });
  }
}
2
likes
130
points
116
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to integrate Jio Payment Gateway.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

convert, crypto, cupertino_icons, dio, flutter, flutter_inappwebview, flutter_pretty_dio_logger, flutter_upi_india, intl, pretty_qr_code, url_launcher

More

Packages that depend on jio_payment_sdk