Files
Neo_wallet/neowallet_mobile/lib/Pay/PayThaiQr.dart
nutchayut a02c6b91a8 bug fixed
2024-12-27 16:45:29 +07:00

374 lines
15 KiB
Dart

import 'dart:convert';
import 'package:cathaypay_mobile/GetPaid/GetPaid.dart';
import 'package:cathaypay_mobile/Home/HomePage.dart';
import 'package:cathaypay_mobile/Pay/PayQrDialog.dart';
import 'package:cathaypay_mobile/PinCodeVadidate.dart';
import 'package:cathaypay_mobile/main.dart';
import 'package:cathaypay_mobile/utils/utils.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import '../api/api.dart';
import '../utils/color_custom.dart';
import 'PayQrDialogV2.dart';
class PayThaiQr extends StatefulWidget {
const PayThaiQr({Key? key, required this.code}) : super(key: key);
final String code;
@override
State<PayThaiQr> createState() => _PayQrPageState();
}
class _PayQrPageState extends State<PayThaiQr> {
@override
void initState() {
super.initState();
}
String removeTextPrice() {
return price.text.replaceAll(",", "").replaceAll("฿", "").trim();
}
initC2B() {
Utils.loadingProgress(context);
// var param = jsonEncode(<dynamic, dynamic>{"MobileDeviceNo": payPhone ?? "", "Note": "", "TransactionID": transactionID});
var param = jsonEncode(
<dynamic, dynamic>{"requestTransactionID": Utils.getDateInitPromptPay() + (profile?.phoneNumber?.lastChars(4)), "qrTextRequest": widget.code,
"amount": "${removeTextPrice()}00"});
Api.post(context, Api.payThaiInitial, param).then((value) => {
if (value != null) {confirmPayQrC2BAmount(value["requestTransactionID"], value["responseTransactionID"])} else {}
});
}
confirmPayQrC2BAmount(String req, String res) {
// var param = jsonEncode(<dynamic, dynamic>{"MobileDeviceNo": payPhone ?? "", "Note": "", "TransactionID": transactionID});
var param = jsonEncode(<dynamic, dynamic>{"requestTransactionID": req, "responseTransactionID": res, "confirmPayment": "Y", "note": ""});
Api.post(context, Api.payThaiConfirm, param).then((value) => {
if (value != null)
{
Navigator.pop(context),
showDialog(
context: context,
builder: (BuildContext context) {
return PayQrDialogV2(
price: value["slipAmount"]??"",
bill: value["requestTransactionID"]??"",
phone: value["promptpayID"]??"",
name: value["slipTitleTH"]??"",
name_en: value["slipTitleEN"]??"",
bankName: value["bankName"]??"",
referenceNo:value["referenceNo"]??"",
slipDateTime: value["slipDateTime"]??"",
transactionId: "",
);
/* return PayQrDialog(
phone: "",
price: removeTextPrice(),
name: "",
transactionId: req,
);*/
})
}
else
{}
});
}
// CurrencyTextInputFormatter decimalFormat = CurrencyTextInputFormatter.currency(symbol: "", decimalDigits: 2,);
TextEditingController price = new TextEditingController();
String priceTemp = "";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
actions: [
CupertinoButton(
onPressed: () {
Navigator.pop(context);
},
child: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: const Icon(
Icons.clear,
color: Colors.grey,
),
),
)
],
elevation: 0,
title: Text(
"Pay".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Colors.black,
fontSize: 20,
),
),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"จำนวนเงินที่โอน / จ่าย".tr(),
style: TextStyle(
color: Color(0xff65676b),
fontSize: 16,
fontWeight: FontWeight.w300,
),
),
SizedBox(
height: 10,
),
Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xfff2f2f2),
),
child: TextField(
textAlign: TextAlign.end,
keyboardType: TextInputType.numberWithOptions(decimal: true),
// inputFormatters: [FilteringTextInputFormatter.allow(RegExp("[0-9.]"))],
inputFormatters: [
TextInputFormatter.withFunction((TextEditingValue oldValue, TextEditingValue newValue) {
print("newValue " + newValue.text);
if (".".allMatches(newValue.text).length > 1) {
print("case1 " + newValue.text);
return oldValue;
} else if (newValue.text.contains(".") && newValue.text.split(".")[1].length == 1) {
return newValue;
} else {
if (oldValue.text.contains(".") && oldValue.text.split(".")[1].length == 2) {
print("case2 " + newValue.text);
return oldValue;
} else {
// If a decimal point was just added to the end of the value, keep it.
if (newValue.text.endsWith('.') && '.'.allMatches(newValue.text).length == 1) {
return newValue;
}
}
}
print("out case");
var formatter = NumberFormat('฿ #,###,###.##', 'en_US');
var value = formatter.parse(newValue.text) ?? 0;
// Otherwise, format the value correctly.
return TextEditingValue(
text: formatter.format(value),
);
})
],
// onTap: (){
// Utils.popupNum(context, price);
// },
controller: price,
style: TextStyle(fontSize: 24),
decoration: InputDecoration(
hintText: "จำนวนเงินที่โอน / จ่าย".tr(),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(horizontal: 16),
),
),
),
SizedBox(
height: 10,
),
Text(
"ใช้แต้ม NEO PAY แทนเงินสด".tr(),
style: TextStyle(
color: Color(0xff65676b),
fontSize: 16,
fontWeight: FontWeight.w300,
),
),
Text(
"${"คะแนนของคุณ".tr()} : ${Utils.moneyFormat(profile?.maxCardMembers.first.pointBalance)} ${"แต้ม".tr()}",
style: TextStyle(
color: Color(0xff9d001b),
fontSize: 14,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xfff2f2f2),
),
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 6,
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"10 ${"แต้ม".tr()}",
textAlign: TextAlign.right,
style: TextStyle(
color: Color(0xff65676b),
),
),
],
),
),
),
Text(
"=",
textAlign: TextAlign.right,
style: TextStyle(
color: Color(0xff65676b),
fontSize: 24,
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
color: Color(0xff9d001b),
),
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 6,
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"100 ${"Baht".tr()}",
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white,
),
),
],
),
))
],
),
Center(
child: Text(
"1 แต้ม = 10 สตางค์".tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xff65676b),
fontSize: 14,
fontWeight: FontWeight.w300,
),
),
),
Container(
height: 136,
color: Colors.transparent,
child: Column(
children: [
SizedBox(
height: 20,
),
Row(
children: [
Text(
"ยอดเงินทั้งหมด".tr(),
style: TextStyle(
color: Color(0xff65676b),
fontSize: 16,
),
),
Spacer(),
Text(
price.text,
textAlign: TextAlign.right,
style: TextStyle(
color: Color(0xff9d001b),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
Text(
" ${"Baht".tr()}",
textAlign: TextAlign.right,
style: TextStyle(
color: Color(0xff65676b),
fontSize: 16,
),
)
],
),
SizedBox(
height: 20,
),
InkWell(
onTap: () async {
FocusScope.of(context).requestFocus(FocusNode());
final result = await Navigator.push(
context,
MaterialPageRoute(builder: (context) => PinCodeValidatePage()),
);
if (result == true) {
initC2B();
}
},
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
),
child: Container(
padding: EdgeInsets.all(10),
child: Text(
"Confirm".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: ColorCustom.greyBorder,
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
),
),
),
SizedBox(
height: 10,
),
],
),
),
SizedBox(
height: 10,
),
],
),
),
),
));
}
}