1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:retro_shopping/helpers/constants.dart' ;
3
+ import 'package:retro_shopping/widgets/payment/payment_successful.dart' ;
3
4
import 'package:retro_shopping/widgets/retro_button.dart' ;
5
+ import 'package:razorpay_flutter/razorpay_flutter.dart' ;
6
+ import 'package:fluttertoast/fluttertoast.dart' ;
4
7
5
8
class PaymentWindow extends StatefulWidget {
6
9
@override
@@ -9,12 +12,56 @@ class PaymentWindow extends StatefulWidget {
9
12
10
13
class _PaymentWindowState extends State <PaymentWindow > {
11
14
int cnt1, cnt2;
12
-
15
+ Razorpay _razorpay = Razorpay ();
13
16
@override
14
17
void initState () {
15
18
super .initState ();
16
19
cnt1 = 0 ;
17
20
cnt2 = 0 ;
21
+ _razorpay.on (Razorpay .EVENT_PAYMENT_SUCCESS , _handlePaymentSuccess);
22
+ _razorpay.on (Razorpay .EVENT_PAYMENT_ERROR , _handlePaymentError);
23
+ _razorpay.on (Razorpay .EVENT_EXTERNAL_WALLET , _handleExternalWallet);
24
+ }
25
+
26
+ @override
27
+ void dispose () {
28
+ _razorpay.clear ();
29
+ super .dispose ();
30
+ }
31
+
32
+ void _openCheckout () async {
33
+ var options = {
34
+ // Add valid key and other relevant options
35
+ 'key' : 'rzp_test_1DP5mmOlF5G5ag' ,
36
+ 'external' : {
37
+ 'wallets' : ['paytm' , 'gpay' , 'bhim' ]
38
+ }
39
+ };
40
+
41
+ try {
42
+ _razorpay.open (options);
43
+ } catch (e) {
44
+ debugPrint (e);
45
+ }
46
+ }
47
+
48
+ void refresh () {
49
+ setState (() {});
50
+ }
51
+
52
+ void _handlePaymentSuccess (PaymentSuccessResponse response) async {
53
+ Fluttertoast .showToast (msg: "SUCCESS: " + response.paymentId);
54
+ Navigator .of (context).push (MaterialPageRoute (
55
+ builder: (BuildContext context) => PaymentSuccessful ()));
56
+ }
57
+
58
+ void _handlePaymentError (PaymentFailureResponse response) {
59
+ Fluttertoast .showToast (
60
+ msg: "ERROR: " + response.code.toString () + " - " + response.message);
61
+ }
62
+
63
+ void _handleExternalWallet (ExternalWalletResponse response) {
64
+ Fluttertoast .showToast (msg: "EXTERNAL_WALLET: " + response.walletName);
18
65
}
19
66
20
67
@override
@@ -239,31 +286,36 @@ class _PaymentWindowState extends State<PaymentWindow> {
239
286
height: height * 0.01 ,
240
287
),
241
288
Center (
242
- child: RetroButton (
243
- child: Padding (
244
- padding: const EdgeInsets .symmetric (horizontal: 12 ),
245
- child: Row (
246
- mainAxisAlignment: MainAxisAlignment .center,
247
- children: [
248
- Text (
249
- 'Payment & Address' ,
250
- style: TextStyle (
251
- fontFamily: 'pix M 8pt' ,
252
- fontSize: 20 ,
253
- fontWeight: FontWeight .bold,
254
- color: RelicColors .primaryBlack,
289
+ child: InkWell (
290
+ onTap: () {
291
+ _openCheckout ();
292
+ },
293
+ child: RetroButton (
294
+ child: Padding (
295
+ padding: const EdgeInsets .symmetric (horizontal: 12 ),
296
+ child: Row (
297
+ mainAxisAlignment: MainAxisAlignment .center,
298
+ children: [
299
+ Text (
300
+ 'Payment & Address' ,
301
+ style: TextStyle (
302
+ fontFamily: 'pix M 8pt' ,
303
+ fontSize: 20 ,
304
+ fontWeight: FontWeight .bold,
305
+ color: RelicColors .primaryBlack,
306
+ ),
307
+ textAlign: TextAlign .left,
255
308
),
256
- textAlign: TextAlign .left,
257
- ),
258
- Icon (Icons .arrow_forward),
259
- ],
309
+ Icon (Icons .arrow_forward),
310
+ ],
311
+ ),
260
312
),
313
+ upperColor: Colors .white,
314
+ lowerColor: Colors .black,
315
+ height: height * 0.052 ,
316
+ width: width * 0.8 ,
317
+ borderColor: Colors .black,
261
318
),
262
- upperColor: Colors .white,
263
- lowerColor: Colors .black,
264
- height: height * 0.052 ,
265
- width: width * 0.8 ,
266
- borderColor: Colors .black,
267
319
),
268
320
),
269
321
],
0 commit comments