nravepay 1.0.1+2 copy "nravepay: ^1.0.1+2" to clipboard
nravepay: ^1.0.1+2 copied to clipboard

outdated

Accepting payment using Flutterwave in flutter.

example/lib/main.dart

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

import 'keys.dart';

void main() {
  NRavePayRepository.setup(
      publicKey: PaymentKeys.publicKey,
      encryptionKey: PaymentKeys.encryptionKey,
      secKey: PaymentKeys.secretKey,
      staging: true);
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      home: MyHomePage(title: 'NRavePay Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<void> _startPayment() async {
    var initializer = PayInitializer(
        amount: 450,
        email: 'email@email.com',
        txRef: 'reference${DateTime.now().microsecondsSinceEpoch}',
        narration: 'New payment',
        country: 'Nigeria',
        currency: 'NGN',
        firstname: 'Nelson',
        lastname: 'Eze',
        useCard: true,
        phoneNumber: '09092343432',
        onComplete: (result) {
          if (result.status == HttpStatus.success) {
            if (result.card != null) {
              print(result.card.toMap());
              //  saveCard(card);
            }
          }
          print(result.message);
        });
    return PayManager().prompt(context: context, initializer: initializer);
  }

  List<BankCard> cards = [
    BankCard.fromMap({
      "id": '1234567',
      "token": "flw-t1nf-5eab9b1fbfbab5806f676a88ef9630c2-m03k",
      "last_4digits": "4246",
      "expiry": "09/32",
      "first_6digits": "418742",
      "issuer": "Visa",
      "type": "VISA"
    }),
    BankCard.fromMap({
      "id": "1622103329220332_2643",
      "token": "flw-t1nf-2c09dac5ab2da4c472c75da603da2e42-m03k",
      "last_4digits": "2643",
      "expiry": "09/32",
      "country": "UNITED KINGDOM GB",
      "first_6digits": "455605",
      "issuer": "CREDIT",
      "type": "VISA"
    })
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Accept payments in Flutter using Flutterwave',
            ),
            Container(
              margin: const EdgeInsets.all(18.0),
              width: 200,
              child: ElevatedButton(
                child: Text('Pay #450'),
                onPressed: _startPayment,
              ),
            ),
            Container(
              margin: const EdgeInsets.all(18.0),
              width: 200,
              child: ElevatedButton(
                child: Text('Pay With Saved Card #450'),
                onPressed: () {
                  NRavePayRepository.instance
                      .updateCards(cards, "1622103329220332_2643");
                  return _startPayment();
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}