flutter_payment_plugin 1.0.0 copy "flutter_payment_plugin: ^1.0.0" to clipboard
flutter_payment_plugin: ^1.0.0 copied to clipboard

Flutter Payment Plugin: simple payment initiation with WebView and return URL handling.

Flutter Payment Plugin — Step‑by‑Step Integration #

This guide explains how to add and use flutter_payment_plugin in any Flutter app.

1) Add the Package #

  • Run: flutter pub add flutter_payment_plugin
  • Import: import 'package:flutter_payment_plugin/flutter_payment_plugin.dart';

2) Android Setup #

  • No additional Android changes are required.

3) iOS Setup #

  • To make the deep links to open payment apps, add these URL schemes to ios/<YourAppName>/Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
  <!-- Add the schemes you plan to support -->
  <string>upi</string>
  <string>gpay</string>
  <string>phonepe</string>
  <string>paytm</string>
  <!-- etc. -->
</array>

4) Prepare Your Inputs #

  • url: your payment gateway base domain (e.g., https://your-gateway.example)
  • params must include at least: api_key, order_id, salt, hash, mode, amount, name, phone, email, return_url
  • Optional fields as required by your gateway: description, currency, country, city, state, address_line_1, address_line_2, zip_code, enable_auto_refund, udf1udf5
  • Generate hash according to your gateway’s spec (recommended on backend).

5) Trigger the Payment #

Future<void> startPayment() async {
  final params = <String, String>{
    'api_key': 'YOUR_API_KEY',
    'order_id': 'YOUR_ORDER_ID',
    'salt': 'YOUR_SALT',
    'hash': 'YOUR_GENERATED_HASH',
    'mode': 'LIVE',
    'amount': '100',
    'name': 'Buyer Name',
    'phone': '9999999999',
    'email': 'buyer@example.com',
    'return_url': 'https://your.domain/return',
    // optional fields...
  };

  final result = await FlutterPaymentPlugin.openPayment(
    url: 'https://your-gateway.example',
    params: params,
    title: 'Payment',
    javaScript: true,
  );

  if (result.cancelled) {
    // Handle cancellation
  } else if (result.success) {
    // Handle success, check result.data if provided
  } else {
    // Handle failure, inspect result.data
  }
}

6) Integration Tips #

  • Ensure all required fields are set and trimmed.
  • Use a reachable return_url provided by your gateway.
  • Prefer generating hash securely on your backend.
  • Payment initiation endpoint is fixed: BASE_URL + /v2/paymentrequest. Provide only the base url.

7) Common Issues #

  • Wrong endpoint: ensure your base url is correct; the request path is always /v2/paymentrequest.
  • Network errors: check device connectivity and the base url.
  • iOS deep links: add URL schemes for the apps your flow targets.
0
likes
150
points
265
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter Payment Plugin: simple payment initiation with WebView and return URL handling.

Repository
View/report issues

Topics

#payments #webview #gateway #android #ios

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on flutter_payment_plugin

Packages that implement flutter_payment_plugin