paystack_flutter_sdk 0.0.1-alpha.2

SDKflutter
Platformandroidios

Paystack Flutter SDK with support for multiple channels to accept payments from your customers in supported regions.

Paystack Flutter SDK

A Paystack plugin for accepting payments in your Flutter application.

Support

AndroidiOSMacOSWebLinuxWindows

Requirements

Paystack Flutter SDK builds upon the recent patterns in the Android and iOS, thus your app should target:

  • Flutter >= 3.3.0
  • iOS >= 13
  • Android
    • Minimum SDK: 23
    • Compile SDK: 34

[!IMPORTANT]

Flutter (3.3.0 below, at the moment) extends the FlutterActivity as the base class for Android. The FlutterActivity doesn't have the ComponentActivity, a compulsory necessity for loading the payment views with the SDK, in its ancestral tree. To fix this, change the FlutterActivity to FlutterFragmentActivity in the MainActivity in the android folder of your project.

Getting Started

  • Install the dependency in your project
flutter pub get paystack_flutter_sdk
  • Import the paystack_flutter into your .dart file
import 'package:paystack_flutter_sdk/paystack_flutter_sdk.dart';
  • Use the plugin
final _publicKey = "pk_domain_xxxxxx";
final _accessCode = "67joTry7t1jz2o";
final _paystack = Paystack();

 initialize(String publicKey) async {
    try {
      final response = await _paystack.initialize(publicKey, true);
      if (response) {
        log("Sucessfully initialised the SDK");
      } else {
        log("Unable to initialise the SDK");
      }
    } on PlatformException catch (e) {
      log(e.message!);
    }
  }

  launch() async {
    String reference = "";
    try {
      final response = await _paystack.launch(_accessCode);
      if (response.status) {
        reference = response.reference;
        log(reference);
      } else {
        log(response.message);
      }
    } on PlatformException catch (e) {
      log(e.message!);
    }

    setState(() {
      _reference = reference;
    });
  }

Handling responses

The SDK returns two categories of responses:

  • Transaction: This returned when you've successfully intergated the SDK and able to get the payment UI. This response is tied to the transaction lifecylce and has the following model:

    ParameterTypeDescription
    statusStringIndicates the state of the transaction. Possible values are: success, cancelled, failed
    messageStringThis is a short detail about the status of the transaction
    referenceStringThis is a unique identifier used to manage post-payment processes. It is only returned when the status is success
  • Exception: Exceptions are thrown during your integration process. There are mostly issues surronding the development process. Exceptions make use of the platform-specific FlutterError model which has the following parameters: following model:

    ParameterTypeDescription
    codeStringThis indicates the category of error
    messageStringThis is a short description of the error
    detailsStringThis current returns nil. In a future update, we can use it to provide details about fixing the error

The following are the error codes that can be returned when an exception occurs:

Error CodeDescription
INVALID_ARGUMENTThis occurs when you aren't passing the required paramter(s) (public key) to set up the SDK
INITIALIZATION_ERRORThis occurs when the SDK cannot be initialized with the parameters passed
UNSUPPORTED_VERSIONThis occurs when your projects doesn't conform to the SDK requirements
MISSING_VIEWThis occur when the SDK cannot find a view controller (iOS) or Activity (Android) to attach to
LAUNCH_ERRORThis occurs when the payment UI cannot be loaded