Flutter Paytm Integration
How to Integrate Paytm Payment Gateway in Flutter? Flutter Paytm Integration with Example.

Search for a command to run...
How to Integrate Paytm Payment Gateway in Flutter? Flutter Paytm Integration with Example.

I have Integrated all steps and txn token generate by python code and pass to the start transaction method. but paytm app appear for 1 or 2 seconds and it's closed. It showed platform exception(Your session has expired). I don't understand why this is happened. Please help me and reply ASAP.
I'm getting this error after creating start transaction
Something went wrong. The transaction request sent by you is incorrect.
please reply ASAP :)
I already recommended in the blog, that you should create your own server and deploy it rather than using my deployed link. So I suggest you to simply fork the server repo and deploy it on your own server. It's not very complicated. You can follow the steps I've shown above.
hi , i need help in paytm integration. i followed above steps. but i getting error.
if u see my message please reply. i am waiting for ur help.
Sure, please drop a message on discord will try to help. Here is my id:
Dhruv Nakum#3467
Dhruv Nakum Bro. i do same steps above afterthen when i click to button. its open paytm but shown error
Error is - Something went wrong. The transaction request sent by you is incorrect.
Lessons from Code, Content, and Consistency

Reliability basics: Outbox pattern + why it matters

Introducing Kafka/Redpanda + move to event-driven workflow

Connect Orders ↔ Inventory (first working service-to-service flow)

Inventory service + gRPC + proto contracts



http in Flutter and it will return you the Txn Token.Pre-requisites before we begin with the integration part.
AllInOneSdk in Flutterpaytm_allinonesdk package.dependencies:
paytm_allinonesdk: ^1.1.4
PaytmConfig classCreate PaytmConfig class and define the required variables.
class PaytmConfig {
final String _mid = "...";
final String _mKey = "...";
final String _website = "DEFAULT"; // or "WEBSTAGING" in Testing
final String _url =
'https://flutter-paytm-backend.herokuapp.com/generateTxnToken'; // Add your own backend URL
String get mid => _mid;
String get mKey => _mKey;
String get website => _website;
String get url => _url;
}

getMap which will return a JSON encoded string. This string contains all the information required to generate txn Token.String getMap(double amount, String callbackUrl, String orderId) {
return json.encode({
"mid": mid,
"key_secret": mKey,
"website": website,
"orderId": orderId,
"amount": amount.toString(),
"callbackUrl": callbackUrl,
"custId": "122", // Pass users Customer ID here
});
}
Now, let's create a function called generateTxnToken which is used to make a POST request to the backend.
Future<void> generateTxnToken(double amount, String orderId) async {
final callBackUrl =
'https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=$orderId';
final body = getMap(amount, callBackUrl, orderId);
try {
final response = await http.post(
Uri.parse(url),
body: body,
headers: {'Content-type': "application/json"},
);
String txnToken = response.body;
await initiateTransaction(orderId, amount, txnToken, callBackUrl);
} catch (e) {
print(e);
}
}
Future<void> initiateTransaction(String orderId, double amount,
String txnToken, String callBackUrl) async {
String result = '';
try {
var response = AllInOneSdk.startTransaction(
mid,
orderId,
amount.toString(),
txnToken,
callBackUrl,
false, // isStaging
false, // restrictAppInvoke
);
response.then((value) {
// Transaction successfull
print(value);
}).catchError((onError) {
if (onError is PlatformException) {
result = onError.message! + " \n " + onError.details.toString();
print(result);
} else {
result = onError.toString();
print(result);
}
});
} catch (err) {
// Transaction failed
result = err.toString();
print(result);
}
}
generateTxnToken function from our UI.FloatingActionButton(
onPressed: () async {
await paytmConfig.generateTxnToken(amount, orderId);
},
child: const Icon(Icons.payment),
),

