Foloosi
  • INTRODUCTION
  • FEATURES
  • Get Started
    • Create Api Credentials
    • Checkout Page Customization
  • Payment Methods
    • Popup Payment Method
    • Hosting Payment Method
    • Saved Card Payment Method
  • CLIENT SIDE INTEGRATIONS
    • Javascript Integration
      • Create Payment Token
      • Payment Widget Initialization
      • Payment Response Handling
      • Additional Setup
      • Sample Integrations
    • PHP Integration
      • Create Payment Token
      • Payment Widget Initialization
      • Payment Response Handling
      • Additional Setup
      • Sample integrations
    • React JS Integration
      • Create payment Token
      • Payment Widget Initialization
      • Payment Response Handling
      • Additional Setup
    • Angular JS Integration
      • Create payment Token
      • Payment Widget Initialization
      • Payment Response Handling
      • Additional Setup
  • ECOMMERCE INTEGRATIONS
    • WooCommerce
    • CS Cart
    • Ecwid
    • Opencart
    • Magento
    • Prestashop
  • MOBILE SDK INTEGRATIONS
    • Android SDK
      • Initiate Payment
      • Payment Response Handling
    • iOS SDK
      • Initiate Payment
      • Payment Response Handling
    • React Native SDK
      • Make Payment
    • Flutter SDK
      • Installation
      • Make Payment
      • Sample Dart Program
  • SUBSCRIPTIONS
    • Foloosi Subscription for WooCommerce
    • Api Subscription
      • Sample Integration
    • Subscription
  • WEBHOOKS
  • PARTNER PAYOUT
  • CARD DETAILS
    • Test Cards
Powered by GitBook
On this page

Was this helpful?

  1. MOBILE SDK INTEGRATIONS
  2. Flutter SDK

Sample Dart Program

import 'dart:async';
import 'dart:convert';

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  TextEditingController amountTextField = TextEditingController();
  final GlobalKey<ScaffoldState> key = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: key,
        appBar: AppBar(
          backgroundColor: Colors.blue,
          title: const Text('Foloosi Example',
              style: TextStyle(color: Colors.white)),
        ),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                margin: const EdgeInsets.all(20),
                child: TextField(
                  controller: amountTextField,
                  keyboardType: TextInputType.text,
                  decoration:
                      const InputDecoration(hintText: "Enter the amount"),
                ),
              ),
              GestureDetector(
                onTap: () {
                  initPlatformState();
                },
                child: Container(
                  margin: const EdgeInsets.all(20),
                  height: 50,
                  color: Colors.blue,
                  child: const Center(
                    child: Text(
                      "Proceed Payment",
                      style: TextStyle(color: Colors.white, fontSize: 18),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  /// Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    if (amountTextField.text.trim().isNotEmpty) {
      try {
        var initData = {
          "merchantKey": "Your Merchant Key",
          "customColor": "#1E8449",
        };
        await FoloosiPlugins.init(json.encode(initData));

        FoloosiPlugins.setLogVisible(true);
        var res = {
          "orderId": "ORD1234",
          "orderDescription": "Your Order Description",
          "orderAmount": double.parse(amountTextField.text),
          "state": "",
          "postalCode": "",
          "country": "ARE",
          "currencyCode": "AED",
          "customerUniqueReference": "",
          "customer": {
            "name": "Foloosi Test",
            "email": "[email protected]",
            "mobile": "501234567",
            "code": "",
            "address": "",
            "city": "",
          },
        };
        var result = await FoloosiPlugins.makePayment(json.encode(res));
        // var referenceToken = "";
        // var result = await FoloosiPlugins.makePaymentWithReferenceToken(referenceToken);
        debugPrint("Payment Response: $result");
      } on Exception catch (exception) {
        exception.runtimeType;
      }
    } else {
      debugPrint("Error: Please enter amount");
    }
  }
}
PreviousMake PaymentNextFoloosi Subscription for WooCommerce

Last updated 1 month ago

Was this helpful?