1) list_profile:
class DetailPage extends StatefulWidget {
final DocumentSnapshot post;
DetailPage({this.post});
@override
_DetailPageState createState() => _DetailPageState();
}
class _DetailPageState extends State<DetailPage> {
bool pressed = false;
String taskname,tasksector,taskpocket,tasklandmark;
int _myTaskType = 0;
String taskVal;
StateModel appState;
bool _loadingVisible = false;
@override
Widget build(BuildContext context) {
// final CounterBloc _counterBloc = BlocProvider.of<CounterBloc>(context);
DateTime now = DateTime.now();
String formattedDate = DateFormat('EEE d MMM y').format(now);
// firebase location to be set
confirm() { // for driver
appState = StateWidget.of(context).state;
//final userId = appState?.firebaseUserAuth?.uid ?? '';
final w_fl = appState?.user?.w_fl ?? '';
final firstName = appState?.user?.firstName ?? '';
final number = appState?.user?.number ?? '';
DocumentReference ds = Firestore.instance
.collection("customer2")
.document("${widget.post.data["driverNumber"]}")
.collection("1")
.document(formattedDate);
Map<String, dynamic> data = {
//"Status": firstName + " $lastName",
"customerName":firstName,
"customerNumber":number,
"time":taskVal,
"status": "Waiting...",
"address":taskname,
"sector":tasksector,
"pocket":taskpocket,
"landmark":tasklandmark,
"payment":"X"
};
ds.setData(data).whenComplete(() {
print('Task created');
});
}
confirm2() { // to fetched only on customer side i.e yourBookings
appState = StateWidget.of(context).state;
//final userId = appState?.firebaseUserAuth?.uid ?? '';
final w_fl = appState?.user?.w_fl ?? '';
final firstName = appState?.user?.firstName ?? '';
final lastName = appState?.user?.lastName ?? '';
final number = appState?.user?.number ?? '';
DocumentReference ds = Firestore.instance
.collection("confirmed_c_rides2")
.document(number)
.collection('1')
.document(formattedDate);
Map<String, dynamic> data = {
//"Status": firstName + " $lastName",
"carImage": "${widget.post.data["carImage"]}",
"driverImage": "${widget.post.data["driverImage"]}",
"experience": "${widget.post.data["experience"]}",
"firstName": "${widget.post.data["driverName"]}",
"gender": "${widget.post.data["gender"]}",
"time": taskVal,
"driverNumber": "${widget.post.data["driverNumber"]}",
//"status": "Waiting..."
"payment":"Complete your payment to confirm"
};
ds.setData(data).whenComplete(() {
print('Task created');
});
}
return Scaffold()
2) check.dart
class CheckRazor extends StatefulWidget {
@override
_CheckRazorState createState() => _CheckRazorState();
}
class _CheckRazorState extends State<CheckRazor> {
Razorpay _razorpay = Razorpay();
var options;
Future payData() async {
try {
_razorpay.open(options);
} catch (e) {
print("errror occured here is ......................./:$e");
}
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
}
void _handlePaymentSuccess(PaymentSuccessResponse response) async {
print("payment has succedded");
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (BuildContext context) => SuccessPage(
response: response,
),
),
(Route<dynamic> route) => false,
);
_razorpay.clear();
// Do something when payment succeeds
}
void _handlePaymentError(PaymentFailureResponse response) {..............}
@override
void initState() {
// TODO: implement initState
super.initState();
options = {.......}
@override
Widget build(BuildContext context) {
return Scaffold(
RaisedButton(onPressed(){
confirm();
confirm2();}
);
}
Я хочу создать данные в базе данных только при успешной оплате , В вышеприведенных кодах ... я только что соединил два разных кода: создание данных (для базы данных) и оплата.
1) Подтверждение () и подтверждение2 () отвечают за создание данных для базы данных. 2) _handlePaymentSuccess () отвечает за успешную оплату. Пожалуйста, помогите !!!