Giter Club home page Giter Club logo

ufe-pr / flutterwave-flutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blackmann/flutterwave-flutter

0.0 0.0 0.0 1.76 MB

Flutterwave's Flutter library allows you to build a quick, simple, and excellent payment experience in your flutter applications. We provide a UI that can be used out-of-the-box to collect your users' payment details

Home Page: https://developer.flutterwave.com

License: Other

Dart 99.37% Kotlin 0.04% Ruby 0.44% Swift 0.13% Objective-C 0.01%

flutterwave-flutter's Introduction

Flutterwave Flutter SDK

Table of Contents

About

Flutterwave's Flutter SDK is Flutterwave's offical flutter sdk to integrate the Flutterwave payment into your flutter app. It comes with a readymade Drop In UI. The payment methods currently supported are Cards, USSD, Mpesa, GH Mobile Money, UG Mobile Money, ZM Mobile Money, Rwanda Mobile Money, Franc Mobile Money and Nigeria Bank Account.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. See references for links to dashboard and API documentation.

Prerequisite

  • Ensure you have your test (and live) API keys.
  • This Library runs and the V3 API, and so you need to be PCI-DSS certified to use this.
Flutter version >= 1.17.0
Flutterwave version 3 API keys

Installing

Add the dependency

In your pubspec.yaml file add:

  1. flutterwave: 0.0.3-dev.3
  2. run flutter pub get

Usage

1. Create a Flutterwave instance

Create a Flutterwave instance by calling the constructor Flutterwave.forUIPayment() The constructor accepts a mandatory instance of the following: the calling Context , publicKey, encryptionKey, amount, currency, email, fullName, txRef, isDebugMode and phoneNumber . It returns an instance of Flutterwave which we then call the async method .initializeForUiPayments() on.

 beginPayment async () { 
   try { 
	     Flutterwave flutterwave = Flutterwave.forUIPayment(
                     context: this.context,
                     encryptionKey: "Your_test_encryption_key_here",
                     publicKey: "Your_test_public_key_here",
                     currency: currency,
                     amount: amount,
                     email: "[email protected]",
                     fullName: "Valid Full Name",
                     txRef: txref,
                     isDebugMode: true,
                     phoneNumber: "0123456789",
                     acceptCardPayment: true,
                     acceptUSSDPayment: false,
                     acceptAccountPayment: false,
                     acceptFrancophoneMobileMoney: false,
                     acceptGhanaPayment: false,
                     acceptMpesaPayment: false,
                     acceptRwandaMoneyPayment: true,
                     acceptUgandaPayment: false,
                     acceptZambiaPayment: false)
                     
         final ChargeResponse response = await flutterwave.initializeForUiPayments();
                    
         } catch(error) {
	         handleError(error);
         }

2. Handle the response

Calling the .initialiazeForUiPayments() method returns a Future of ChargeResponse which we await for the actual response as seen above.

An example of how to make payment in a Widget would look like this:

   class PaymentWidget extends StatefulWidget {
     @override
     _PaymentWidgetState createState() => _PaymentWidgetState();
   }
   
   class _PaymentWidgetState extends State<PaymentWidget> {
     final String txref = "My_unique_transaction_reference_123";
     final String amount = "200";
     final String currency = FlutterwaveCurrency.RWF;
   
     @override
     Widget build(BuildContext context) {
       return Container();
     }
   
     beginPayment() async {
       final Flutterwave flutterwave = Flutterwave.forUIPayment(
           context: this.context,
           encryptionKey: "FLWPUBK_TEST-SANDBOXDEMOKEY-X",
           publicKey: "FLWPUBK_TEST-SANDBOXDEMOKEY-X",
           currency: this.currency,
           amount: this.amount,
           email: "[email protected]",
           fullName: "Valid Full Name",
           txRef: this.txref,
           isDebugMode: true,
           phoneNumber: "0123456789",
           acceptCardPayment: true,
           acceptUSSDPayment: false,
           acceptAccountPayment: false,
           acceptFrancophoneMobileMoney: false,
           acceptGhanaPayment: false,
           acceptMpesaPayment: false,
           acceptRwandaMoneyPayment: true,
           acceptUgandaPayment: false,
           acceptZambiaPayment: false);
   
       try {
         final ChargeResponse response = await flutterwave.initializeForUiPayments();
         if (response == null) {
           // user didn't complete the transaction.
         } else {
           final isSuccessful = checkPaymentIsSuccessful(response);
           if (isSuccessful) {
             // provide value to customer
           } else {
             // check message
             print(response.message);
   
             // check status
             print(response.status);
   
             // check processor error
             print(response.data.processorResponse);
           }
         }
       } catch (error, stacktrace) {
         // handleError(error);
       }
     }
   
     bool checkPaymentIsSuccessful(final ChargeResponse response) {
       return response.data.status == FlutterwaveConstants.SUCCESSFUL &&
           response.data.currency == this.currency &&
           response.data.amount == this.amount &&
           response.data.txRef == this.txref;
     }
   }

Please note that:

  • ChargeResponse can be null, depending on if the user cancels the transaction by pressing back.
  • You need to check the status of the transaction from the instance of ChargeResponse returned from calling .initializeForUiPayments(), the amount, currency and txRef are correct before providing value to the customer
  • To accept payment of different kinds, you need set the currency to the correspending payment type i.e, KES for Mpesa, RWF for Rwanda Mobile Money, NGN for USSD, Bank Accounts Payment and so on.

PLEASE NOTE

We advise you to do a further verification of transaction's details on your server to be sure everything checks out before providing service or goods as seen in the checkPaymentIsSuccessful() method above.

Deployment

  • Switch to Live Mode on the Dashboard settings page
  • Use the Live Public API key from the API tab, see here for more details.

Built Using

Flutterwave API References

Support

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.