370 lines
15 KiB
Dart
370 lines
15 KiB
Dart
import 'dart:convert';
|
|
|
|
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: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';
|
|
|
|
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 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(
|
|
"จ่ายเงิน",
|
|
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(
|
|
"จำนวนเงินที่โอน / จ่าย",
|
|
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: 'จำนวนเงินที่โอน',
|
|
border: InputBorder.none,
|
|
contentPadding: EdgeInsets.symmetric(horizontal: 16),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
Text(
|
|
"ใช้แต้ม Cathay Pay แทนเงินสด",
|
|
style: TextStyle(
|
|
color: Color(0xff65676b),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w300,
|
|
),
|
|
),
|
|
Text(
|
|
"คะแนนของคุณ : 12,000 แต้ม",
|
|
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(
|
|
"0 แต้ม",
|
|
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(
|
|
"0 บาท",
|
|
textAlign: TextAlign.right,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
))
|
|
],
|
|
),
|
|
Center(
|
|
child: Text(
|
|
"1 แต้ม = 10 สตางค์",
|
|
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(
|
|
"ยอดเงินทั้งหมด",
|
|
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(
|
|
" บาท",
|
|
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: Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: 51,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(40),
|
|
color: Color(0xff9d001b),
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 10,
|
|
vertical: 12,
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(
|
|
width: 106,
|
|
height: 32,
|
|
child: Text(
|
|
"ยืนยัน",
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.kanit(
|
|
color: Colors.white,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 10,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
));
|
|
}
|
|
}
|