Skip to content

Instantly share code, notes, and snippets.

@red-star25
Created February 7, 2022 08:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save red-star25/65562b056a444025f058e489c336c28a to your computer and use it in GitHub Desktop.
Save red-star25/65562b056a444025f058e489c336c28a to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:paytm_allinonesdk/paytm_allinonesdk.dart';
class PaytmConfig {
final String _mid = "...";
final String _mKey = "...";
final String _website = "DEFAULT";
final String _url =
'https://flutter-paytm-backend.herokuapp.com/generateTxnToken';
String get mid => _mid;
String get mKey => _mKey;
String get website => _website;
String get url => _url;
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",
});
}
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,
false,
);
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);
}
}
}
@thakaredipali
Copy link

thakaredipali commented Jul 23, 2022

@red-star25 I have generated txn token by python code and passed to the start transaction method I got "Your session has expired " platform exception. Please help me.

@red-star25
Copy link
Author

@thakaredipali
Copy link

thakaredipali commented Jul 23, 2022

@red-star25 Yes, I already seen this. But this is not same. Please help me why this happened.

@VikasAgrawal-04
Copy link

Sir can you help me out! I have added you to the discord recently!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment