Skip to content

Repository files navigation

Interswitch Payment Gateway SDK for Flutter

Interswitch

The Interswitch Payment Gateway (IPG) SDK for Flutter provides a seamless way to integrate secure payment processing into your mobile applications. Built on top of the robust Interswitch Web Checkout, this SDK simplifies the integration process using a WebView-based redirect flow.

Official Documentation


Features

  • Official Integration: Follows Interswitch Web Redirect standards.
  • Cross-Platform: Full support for both iOS and Android.
  • Pure Dart: No native dependencies - simple integration without platform-specific setup.
  • Multiple Payment Methods: Card, Bank Transfer, USSD, QR Code, OPay, and Wallets.
  • Built-in Error Handling: Custom WebpayException for network and WebView errors.

Installation

Add the package to your pubspec.yaml:

dependencies:
interswitch_payment_gateway: ^0.0.1

OR

Run this command

flutter pub add interswitch_payment_gateway

Then run:

flutter pub get

Note: This package requires webview_flutter which is included as a dependency. No additional setup needed.


Quick Start

The following example demonstrates a basic payment implementation.

import'package:flutter/material.dart';
import'package:interswitch_payment_gateway/interswitch_payment_gateway.dart';
classPaymentScreenextendsStatelessWidget {
// Replace with your actual Interswitch credentials// These are test credentials for demonstrationfinal webpay =WebpayClient(
merchantCode:'<merchant-code>', // Test merchant code
payItemId:'<pay-item-id>', // Test pay item ID
redirectUrl:'<redirect-url>',
mode:EnvironmentMode.test,
);
Future<void> makePayment(BuildContext context) async {
try {
final result =await webpay.checkout(
context: context,
amount:100000, // Amount in Kobo (e.g., 100000 = ₦1,000.00)
txnRef:'<transaction-reference>',
custEmail:'<customer-email>',
);
if (result ==null) {
// User cancelled the paymentreturn;
}
if (result['resp'] =='00') {
// Payment successful - verify on your backendprint('Success! Ref: ${result['txnref']}');
} else {
// Payment failedprint('Failed: ${result['desc']}');
}
} onWebpayExceptioncatch (e) {
// Technical error (network, WebView, etc.)print('Error: ${e.message}');
}
}
@overrideWidgetbuild(BuildContext context) {
returnElevatedButton(
onPressed: () =>makePayment(context),
child:constText('Pay Now'),
);
}
}

Advanced Usage

With Customer Information

Pre-fill customer details to streamline the checkout experience.

final webpay =WebpayClient(
merchantCode:'YOUR_MERCHANT_CODE',
payItemId:'YOUR_PAY_ITEM_ID',
redirectUrl:'https://your-domain.com/callback',
mode:EnvironmentMode.live,
// Default customer info (can be overridden per transaction)
custName:'John Doe',
custEmail:'john@example.com',
custId:'CUST_12345',
payItemName:'Premium Subscription',
);

API Reference: WebpayClient Constructor

ParameterTypeRequiredDefaultDescription
merchantCodeStringYes-Your Interswitch Merchant Code.
payItemIdStringYes-Your Interswitch Pay Item ID.
redirectUrlStringYes-URL for capturing payment response.
modeEnvironmentModeYestestEnvironment (test or live).
custNameString?No-Default customer name.
custEmailString?No-Default customer email.
custIdString?No-Default customer ID in your system.
custMobileNoString?No-Default customer mobile number.
payItemNameString?No-Default name of the item being purchased.

API Reference: checkout() Method

ParameterTypeRequiredDefaultDescription
contextBuildContextYes-Flutter build context for navigation.
amountintYes-Transaction amount in Kobo (e.g., 100000 = ₦1000).
txnRefStringYes-Unique transaction reference for the session.
currencyintNo566ISO 4217 currency code (Default: 566 for NGN).
custNameString?No-Customer name (overrides default).
custEmailString?No-Customer email (overrides default).
custIdString?No-Customer ID (overrides default).
custMobileNoString?No-Customer mobile number (overrides default).
payItemNameString?No-Item name (overrides default).

Response Handling

Payment Response Fields

FieldTypeDescription
respStringResponse code ("00" = success).
descStringHuman-readable response description.
txnrefStringYour transaction reference.
amountStringTransaction amount in Kobo.

Result Scenarios

ScenarioHow to DetectAction
Payment successfulresult['resp'] == '00'Verify on backend, fulfill order.
Payment failedresult['resp'] != '00'Show result['desc'] to user.
User cancelledresult == nullReturn to previous screen.
Technical errorThrows WebpayExceptionShow error message, allow retry.

Common Response Codes

CodeDescription
00Approved / Successful
Z1Transaction not found
Z5Transaction pending
Z6Transaction processing

For a complete list, see Response Codes.


Transaction Verification

Important: Always verify transactions on your backend server using Interswitch's Transaction Status API. The client-side response should not be solely relied upon for confirming payment status.


Test Cards

For testing in sandbox mode, use test cards from Interswitch: Test Cards Documentation


Example

See the example directory for a complete working implementation.


Contributing

We welcome contributions! Please submit pull requests or open issues on the GitHub repository.

License

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


Built for the Flutter community

About

Interswitch Payment Gateway SDK for Flutter

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages