You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter集成Paytm UPI支付故障:交易无法正常发起求助

集成Paytm支付到Flutter应用时的问题排查与解决方案

问题描述

我正在开发一款需集成Paytm支付的Flutter应用,目前遇到两个核心问题:

  • 使用flutter_upi_india包发起UPI支付时,Paytm、PhonePe等所有支付应用均持续返回交易失败。
  • 使用url_launcher通过paytm:// URL scheme直接唤起Paytm发起支付,同样失败。

相关代码如下:

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

class PaymentScreen extends StatelessWidget {
  final String paytmQrCode = "paytmqr2810050501011uduvuiplds0@paytm&pn=Paytm%20Merchant&paytmqr=2810050501011UDUVUIPLDS0"; // Replace with actual Paytm QR code
  final String transactionRefId = "txn123456789"; // Replace with a unique transaction reference ID
  final String transactionNote = "Payment for Order"; // Replace with transaction note
  final String amount = "100.00"; // Replace with the transaction amount in string format
  final String currency = "INR"; // Replace with the currency code

  void initiatePayment() async {
    // Constructing the Paytm QR URI
    Uri uri = Uri.parse(
        "paytm://wallet/pay?mId=paytm&pa=$paytmQrCode&tid=$transactionRefId&tn=$transactionNote&am=$amount&cu=$currency");

    if (await canLaunch(uri.toString())) {
      await launch(uri.toString());
    } else {
      throw 'Could not launch $uri';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Pay via Paytm'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            initiatePayment();
          },
          child: Text('Pay with Paytm'),
        ),
      ),
    );
  }
}

预期结果:应用能正确唤起Paytm或其他支付应用,用户可顺畅完成支付。


问题排查与解决方案

1. 修复URL Scheme参数错误

当前URI构造存在核心参数错误:

  • pa参数要求是纯UPI虚拟支付地址(VPA),比如merchant@paytm,而你传入的是包含&pn=...等额外参数的完整QR码字符串,导致Paytm无法解析。
  • mId参数需替换为Paytm分配的真实商户ID,而非默认的paytm。

修改后的URI构造示例:

// 替换为实际的商家VPA和商户ID
final String merchantVpa = "your_merchant_id@paytm";
final String merchantId = "YOUR_PAYTM_MERCHANT_ID";

Uri uri = Uri.parse(
    "paytm://wallet/pay?mId=$merchantId&pa=$merchantVpa&tid=$transactionRefId&tn=$transactionNote&am=$amount&cu=$currency");

2. 第三方UPI包适配问题

flutter_upi_india包失败的常见原因:

  • 包未适配Paytm的专属支付校验逻辑,部分参数(如商户令牌)无法被Paytm识别。
  • 设备上的UPI应用版本过低,建议更新到最新版后重试。

推荐方案:直接使用Paytm官方Flutter SDK,而非第三方UPI通用包。官方SDK会处理Paytm专属的交易令牌生成、参数校验逻辑,确保支付流程合规。

3. URL Launcher平台配置补全

  • Android端:在AndroidManifest.xml中添加Paytm应用查询权限,确保能正常唤起:
<queries>
  <package android:name="net.one97.paytm" />
</queries>
  • iOS端:在Info.plist中添加Paytm scheme白名单:
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>paytm</string>
</array>

4. 测试环境与参数校验

  • 使用Paytm沙箱环境测试,避免生产环境参数错误导致交易失败。
  • 确保tid(交易参考ID)全局唯一,重复ID会被Paytm拒绝。
  • 检查金额格式是否符合要求,需保留两位小数(如100.00而非100)。

内容的提问来源于stack exchange,提问作者Zaid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 16:22:39