How to build a simple payment app using Flutter and Flutterwave

How to build a simple payment app using Flutter and Flutterwave

In this article, you are going to learn how to build a simple payment app using Flutter and Flutterwave.

Originally published by Promise Nzubechi Amadi at https://medium.com

It’s always a privilege to help you upgrade your skillset through my write-ups and tutelage.

In this article, you are going to learn how to build a simple payment app using Flutter and Flutterwave.

By the end of this article, you will learn the following:

  • How to set up a Flutterwave account.
  • How to integrate your Flutterwave API into your Flutter app.

So, let's jump in.

Flutterwave is a start-up dedicated to improving digital payments in Africa. It has a product called Rave.

Rave is a service offered by Flutterwave which that enables merchants accept global payments from card, bank accounts, and Unstructured Supplementary Service Data (USSD) code.

Step 1: To create a new rave account, go to https://ravepay.co/

At the top right corner of the site, click on the “SIGN UP” button (this is if you don’t have an account)

But if you have a Flutterwave account, then click “Log in” button.

Enter your E-mail Address and Password to login to your account.

Your Flutterwave dashboard will look like this image below.

Click on “Setting”, select “API” in other to view your API keys.

Note: Your Live API Keys should be kept private.

Congrats you have completed the first step, the second step will be to create our app using flutter.

Let’s continue.

Step 2: You can create your payment app using Visual Studio, IntelliJ or Android studio.

If you have IntelliJ installed on your computer, click on File>>New>>Project, Select Flutter and click on “Next

Enter the project name and click on “Finish

Open “pubspec.yaml”, install flutter_rave package.

dependencies:
  flutter_rave: ^0.0.5

Add this code to your main.dart

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

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

class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( color: Colors.orangeAccent, theme: ThemeData(primaryColor: Colors.orangeAccent), title: 'Flutterwave', debugShowCheckedModeBanner: false, home: MyHomePage(title: 'Flutterwave'), ); } }

class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState(); }

class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), centerTitle: true, ), body: Center( child: Builder( builder: (context) => SingleChildScrollView( child: Padding( padding: const EdgeInsets.only(left: 10.0, right: 10), child: InkWell( onTap: () => _pay(context), child: Card( color: Colors.orangeAccent, elevation: 15, child: Container( height: 250, width: MediaQuery.of(context).size.width, child: Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( "Card Payment", style: TextStyle( color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold), ), SizedBox( width: 10, ), Icon( Icons.payment, color: Colors.black, size: 30, ) ], ), ), ), ), ), ), ), ), ), ); }

_pay(BuildContext context) { final snackBar_onFailure = SnackBar(content: Text('Transaction failed')); final snackBar_onClosed = SnackBar(content: Text('Transaction closed')); final _rave = RaveCardPayment( isDemo: true, encKey: "c53e399709de57d42e2e36ca", publicKey: "FLWPUBK-d97d92534644f21f8c50802f0ff44e02-X", transactionRef: "hvHPvKYaRuJLlJWSPWGGKUyaAfWeZKnm", amount: 100, email: "[email protected]", onSuccess: (response) { print("$response"); print("Transaction Successful"); if (mounted) { Scaffold.of(context).showSnackBar( SnackBar( content: Text("Transaction Sucessful!"), backgroundColor: Colors.green, duration: Duration( seconds: 5, ), ), ); } }, onFailure: (err) { print("$err"); print("Transaction failed"); Scaffold.of(context).showSnackBar(snackBar_onFailure); }, onClosed: () { print("Transaction closed"); Scaffold.of(context).showSnackBar(snackBar_onClosed); }, context: context, ); _rave.process(); } }

Run your app on your smartphone or emulator.

Congratulations!! you have built a payment app using Flutter and Flutterwave.

P.S: Here is the source code for the project you just worked on.

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading

Learn Flutter & Dart to Build iOS & Android Apps

Flutter & Dart - The Complete Flutter App Development Course

Dart and Flutter: The Complete Developer’s Guide

Flutter - Advanced Course

Flutter Tutorial - Flight List UI Example In Flutter

Flutter Tutorial for Beginners - Full Tutorial

Using Go Library in Flutter

A Beginners Guide to the Flutter Bottom Sheet

Flutter Course - Full Tutorial for Beginners (Build iOS and Android Apps)

Flutter Tutorial For Beginners - Build Your First Flutter App

.

flutter mobile-apps dart ios

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

How To Succeed In Mobile App Wireframe Design?

This article covers everything about mobile app wireframe design: what to do and what not, tools used in designing a mobile or web app wireframe, and more.

How long does it take to develop/build an app?

This article covers A-Z about the mobile and web app development process and answers your question on how long does it take to develop/build an app.

Top 25 Flutter Mobile App Templates in 2020

Flutter has been booming worldwide from the past few years. While there are many popular mobile app development technologies out there, Flutter has managed to leave its mark in the mobile application development world. In this article, we’ve curated the best Flutter app templates available on the market as of July 2020.

Best Mobile App Development Company | Android and iOS Apps

iPrism Tech is a one of the best and offshore mobile app development company in India, Saudi Arabia and USA. We are a major providers of android, iphone and ipad mobile app development services at economical prices.