remita_flutter_inline 1.0.2 copy "remita_flutter_inline: ^1.0.2" to clipboard
remita_flutter_inline: ^1.0.2 copied to clipboard

PlatformAndroidiOS
outdated

A Remita package that helps you accept payment in your flutter application.

example/example.dart

import 'dart:async';
import 'dart:developer';

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

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Example App',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Example Home'),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late GlobalKey<FormState> _formKey;
  late TextEditingController _controller;
  final _globalKey = GlobalKey<ScaffoldMessengerState>();

  @override
  void initState() {
    super.initState();
    _formKey = GlobalKey<FormState>();
    _controller = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Example App')),
      body: Form(
        key: _formKey,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              margin: EdgeInsets.symmetric(horizontal: MediaQuery.of(context).size.width * 0.1, vertical: 10),
              child: TextFormField(
                decoration: const InputDecoration(labelText: 'Enter RRR'),
                controller: _controller,
                validator: (_) => _controller.text.isEmpty ? 'RRR is required' : null,
              ),
            ),
            ElevatedButton(
              onPressed: () {
                final FormState? form = _formKey.currentState;
                if (form!.validate()) {
                  _initializePayment(context, _controller.text);
                }
              },
              child: const Text('Pay Now'),
            ),
          ],
        ),
      ),
    );
  }

  _initializePayment(BuildContext context, String rrr) async {
    PaymentRequest request = PaymentRequest(
      environment: RemittaEnvironment.demo,
      rrr: rrr,
      key: 'enter your key here',
    );

    RemitaPayment remita = RemitaInlinePayment(
      buildContext: context,
      paymentRequest: request,
      customizer: Customizer(),
    );

    PaymentResponse response = await remita.initiatePayment();
    if (response.code != null && response.code == '00') {
      // transaction successful
      // verify transaction status before providing value
    } else {
      // transaction not successful.
    }
    log(response.toString());
  }
}
1
likes
130
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

A Remita package that helps you accept payment in your flutter application.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_inappwebview

More

Packages that depend on remita_flutter_inline