Code Monkey home page Code Monkey logo

flutter_paystack's Introduction

Paystack Flutter Plugin

A Paystack Plugin for flutter developers for receiving payments online(Android currently supported, still working on the ios).

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Screenshots

Usage

To use this package :

  dependencies:
    flutter:
      sdk: flutter
    paystack_flutter:

## Connecting to Paystack
First, you should create define your paystack variables `PAYSTACK_PUBLIC_KEY`  and `BACKEND_URL` like this :
   
   
```dart
 static const paystack_pub_key = "Your_Paystack_Public_Key";
 static const paystack_backend_url = "https://infinite-peak-60063.herokuapp.com";

After the variables have been defined create a new function or method connectPaystack which is used to initialize flutter channel :

 connectPaystack() async {
     String result;
     try {
       result = await PaystackFlutter.connectToPaystack({
         "NAME": "Your Name",
         "EMAIL": "[email protected]",
         "AMOUNT": 100,
         "CURRENCY": "NGN",
         "PAYMENT_FOR": "Testing API",
         "PAYSTACK_PUBLIC_KEY":paystack_pub_key,
         "BACKEND_URL": paystack_backend_url,
       });
     } on PlatformException catch (e) {
       result = e.message;
       print(e.message);
     }
 
     
     if (!mounted) return;
 
     setState(() {
       transcation = result;
     });
 }

Paystack Channel Response codes

Listen for response via the result, with the response you can do as use please

 } on PlatformException catch (e) {
        result = e.message;
        print(e.message);
}

For Successful transaction result is SUCCESSFULL For Failed transaction result is UNSUCCESSFULL

Complete Code Setup example

 
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:paystack_flutter/paystack_flutter.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String transcation = 'No transcation Yet';
  Map<String, dynamic> _data = {};

  static const platform = const MethodChannel('maugost.com/paystack_flutter');
  static const paystack_pub_key = "Your_Paystack_Public_Key";
  static const paystack_backend_url =
      "https://infinite-peak-60063.herokuapp.com";

  @override
  initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Flutter Paystack '),
        ),
        body: new Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Text(transcation),
              new Padding(
                padding: const EdgeInsets.all(10.0),
                child: new RaisedButton(
                  child: new Text("Pay with Paystack N100"),
                  onPressed: connectPaystack,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  connectPaystack() async {
    String result;
    try {
      result = await PaystackFlutter.connectToPaystack({
        "NAME": "Your Name",
        "EMAIL": "[email protected]",
        "AMOUNT": 100,
        "CURRENCY": "NGN",
        "PAYMENT_FOR": "Testing API",
        "PAYSTACK_PUBLIC_KEY": paystack_pub_key,
        "BACKEND_URL": paystack_backend_url,
      });
    } on PlatformException catch (e) {
      result = e.message;
      print(e.message);
    }

    if (!mounted) return;

    setState(() {
      transcation = result;
    });
  }
}

flutter_paystack's People

Contributors

mtellect avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flutter_paystack's Issues

Suggestions?

For the sake of sanity later in the future, it would have made more sense if we maintain just one project per integration. I noticed this might cause of a bit of conflict later on. See repo below. https://github.com/lakexyde/flutter_paystack. Since both would be doing the same thing, why not just contribute there?

Subscription

Hey!

Does this plugin support recurring subscription yet?

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.