payfast_flutter 0.0.1 copy "payfast_flutter: ^0.0.1" to clipboard
payfast_flutter: ^0.0.1 copied to clipboard

Flutter SDK for PayFast payment gateway integration with WebView support.

PayFast Flutter #

A Flutter package for integrating the PayFast payment gateway using WebView.

Features #

  • Easy integration with PayFast payment gateway
  • Secure token-based authentication
  • WebView-based payment flow
  • Support for PKR currency
  • Simple API for initiating payments

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  payfast_flutter:
    path: ../  # For local development

Or if published to pub.dev:

dependencies:
  payfast_flutter: ^0.0.1

Then run:

flutter pub get

Usage #

Basic Implementation #

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: PaymentPage(),
    );
  }
}

class PaymentPage extends StatelessWidget {
  const PaymentPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("PayFast Demo")),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            PayFastService.startPayment(
              context: context,
              merchantId: "241665",
              securedKey: "YOUR_SECURED_KEY",
              amount: "100",
            );
          },
          child: const Text("Pay 100 PKR"),
        ),
      ),
    );
  }
}

API Reference #

PayFastService

The main service class for handling payments.

Methods

startPayment()

Initiates the payment flow.

Parameters:

  • context (BuildContext, required): The build context for navigation
  • merchantId (String, required): Your PayFast merchant ID
  • securedKey (String, required): Your PayFast secured key
  • amount (String, required): The payment amount
await PayFastService.startPayment(
  context: context,
  merchantId: "241665",
  securedKey: "YOUR_SECURED_KEY",
  amount: "100",
);

getToken()

Gets an access token from PayFast API.

Parameters:

  • merchantId (String, required): Your PayFast merchant ID
  • securedKey (String, required): Your PayFast secured key
  • basketId (String, required): Unique basket/order ID
  • amount (String, required): The payment amount

Returns: Future<String?> - The access token or null if failed

final token = await PayFastService.getToken(
  merchantId: "241665",
  securedKey: "YOUR_SECURED_KEY",
  basketId: "ORD-12345",
  amount: "100",
);

How It Works #

  1. Generate Basket ID: A unique basket ID is generated using timestamp
  2. Get Token: The service calls PayFast API to get an access token
  3. Navigate to WebView: If token is valid, user is navigated to payment page
  4. Auto-Submit Form: The WebView loads an HTML form that auto-submits to PayFast
  5. Process Payment: PayFast processes the payment and returns the result

API Endpoints #

The package uses the following PayFast endpoints:

  • Token Generation: https://ipg1.apps.net.pk/Ecommerce/api/Transaction/GetAccessToken
  • Payment Processing: https://ipg1.apps.net.pk/Ecommerce/api/Transaction/PostTransaction

Example #

A complete example app is available in the example folder. To run it:

cd example
flutter run

Dependencies #

  • http: ^1.2.0 - For API calls
  • webview_flutter: ^4.7.0 - For displaying payment interface

Requirements #

  • Flutter SDK: >=3.0.0 <4.0.0
  • Dart SDK: >=3.10.8

Notes #

  • Currency is fixed to PKR (Pakistani Rupee)
  • PROCCODE is set to "00" by default
  • Make sure to replace YOUR_SECURED_KEY with your actual PayFast secured key
  • The basket ID is auto-generated using timestamp format: ORD-{timestamp}

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Support #

For issues and questions, please file them in the issue tracker.

6
likes
0
points
148
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter SDK for PayFast payment gateway integration with WebView support.

Repository (GitHub)
View/report issues

Topics

#payfast #payment #flutter-payment #pakistan-payment

License

unknown (license)

Dependencies

crypto, flutter, http, webview_flutter

More

Packages that depend on payfast_flutter