DEV Community

Cover image for A simple way to integrate/implement Payment Gateway in Flutter app - (Paystack).
Samuel Adekunle
Samuel Adekunle

Posted on

A simple way to integrate/implement Payment Gateway in Flutter app - (Paystack).

Hello everyone and welcome to a brand new tutorial series on Flutter. Today, we’re going to learn how to integrate or implement a payment gateway into our flutter application using the paystack platform.

If you want to know more about some cogent flutter Tricks and Tips and How to achieve tasks easily in Flutter, consider following me and sign up for the newsletter so you don’t miss any updates and subscribe to my YouTube Channel as well. Thanks

Let's get started

For a full explanation on this topic, kindly watch the video tutorial

The first thing you need to do is to create an account with paystack if you haven't done so before, just go to this address and create an account.

After creating a free account on your dashboard you will see two keys located at the button of the page, Secret and Public key we're going to be making use of the secret key.

Note: the keys are still on Test Mode, so if you want to Activate it to live just click on Activate Business on your dashboard and submit your information and you're good to go but this tutorial we're only going to use the test key and the code is still the same as when you activate your business you only just have to change the key and that's all.

Screenshot 2021-02-26 144944.png

Create a new flutter project or you can use any existing flutter projects, we're going to use a package called Paystack Manager, so head over to your pubspec.yaml file and install the dependency

  paystack_manager: ^1.0.4
Enter fullscreen mode Exit fullscreen mode

Create a new dart file e.g payment.dart, we're only going to display a button and the function for payment on this page

On the button pressed, we're going to call the _processPayment function.

   onPressed: _processPayment, // this function will be declear later
    child: Text(
      "Pay N1,000",
Enter fullscreen mode Exit fullscreen mode

Process payment function 👇

void _processPayment() {
    try {
      PaystackPayManager(context: context)
// Your company Image
          image: NetworkImage(
        ..setAmount(100000) // you need to add two zeros at the end e.g 100000 = N1,000.00
// you can set your own unique transaction reference, here am using timestamp
        ..setCurrency("NGN") // Set currency, the platform only has three currencies, when registering the
list of countries listed is the currency that is available for you to use
        ..setEmail("") // user email address and information
            "custom_fields": [
                "value": "TechWithSam", // set this your company name
                "display_name": "Payment_to",
                "variable_name": "Payment_to"
    } catch (error) {
      print('Payment Error ==> $error');

  void _onPaymentSuccessful(Transaction transaction) {
    print('Transaction succesful');
        "Transaction message ==> ${transaction.message}, Ref ${transaction.refrenceNumber}");

  void _onPaymentPending(Transaction transaction) {
    print('Transaction Pending');
    print("Transaction Ref ${transaction.refrenceNumber}");

  void _onPaymentFailed(Transaction transaction) {
    print('Transaction Failed');
    print("Transaction message ==> ${transaction.message}");

  void _onCancel(Transaction transaction) {
    print('Transaction Cancelled');
Enter fullscreen mode Exit fullscreen mode


Frame 1.png

Let's now test our payment app, after clicking on pay you will get the layout of the payment page where you can select either Pay with Card or Pay with Bank. Since our key is still on test mode we can only test our payment app with a test credit card 💳 and paystack already provides that, to get a list of test credit cards you can use just click this URL ==> Test Cards.

Process: Click pay ==> Pay with Card ==> Input a test card ==>Submit ==> 4-digit pin ==> OTP ==> Payment Response.

Frame 1 (1).png

If you check your email, you're going to receive an email saying you just received a test payment and some other info.

And that's all the major stuff you need to know 👌, You should check out the video for the full explanation.

Full Source Code 👇 - Show some ❤️ by starring ⭐ the repo and do follow me 😄!

GitHub logo techwithsam / payment_integration_flutter

Integration in flutter using paystack

I hope you have learned one thing or the other, kindly give this article much appreciation you want if you enjoy it, feel free to ask a question and leave a comment if you feel like it 🤭. Thanks for reading and see you in the next series.

🔗 Let's Connect Online 🔗 ==> Github | Twitter | Youtube | WhatsApp | LinkedIn | Patreon | Facebook.

Join the Flutter Dev Community 👨‍💻👨‍💻 ==> Facebook | Telegram | WhatsApp | Signal.

Subscribe to my Telegram channel | Youtube channel. Thanks

Happy Fluttering 🥰👨‍💻

Top comments (3)

karfagen profile image
Sofiia Shevchuk • Edited

Good job, thanks! I hope this fills in my gaps. By the way, Cleveroad also has a good post about mobile app payment gateway. I advise!

hiehq profile image
Hie HQ

This has clearly solved many doubts. Hie HQ appreciates the way you've explained everything. On the contrary, we also provide information in similar Tech space.