Skip to content

Commit 754c62d

Browse files
author
“nb9960”
committed
feat: razorpay
1 parent 05c3e6f commit 754c62d

File tree

3 files changed

+82
-27
lines changed

3 files changed

+82
-27
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ android {
3939
defaultConfig {
4040
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
4141
applicationId "com.example.retro_shopping"
42-
minSdkVersion 16
43-
targetSdkVersion 28
42+
minSdkVersion 23
43+
targetSdkVersion 29
4444
versionCode flutterVersionCode.toInteger()
4545
versionName flutterVersionName
4646
}

lib/widgets/payment/payment_window.dart

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:retro_shopping/helpers/constants.dart';
3+
import 'package:retro_shopping/widgets/payment/payment_successful.dart';
34
import 'package:retro_shopping/widgets/retro_button.dart';
5+
import 'package:razorpay_flutter/razorpay_flutter.dart';
6+
import 'package:fluttertoast/fluttertoast.dart';
47

58
class PaymentWindow extends StatefulWidget {
69
@override
@@ -9,12 +12,56 @@ class PaymentWindow extends StatefulWidget {
912

1013
class _PaymentWindowState extends State<PaymentWindow> {
1114
int cnt1, cnt2;
12-
15+
Razorpay _razorpay = Razorpay();
1316
@override
1417
void initState() {
1518
super.initState();
1619
cnt1 = 0;
1720
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);
1865
}
1966

2067
@override
@@ -239,31 +286,36 @@ class _PaymentWindowState extends State<PaymentWindow> {
239286
height: height * 0.01,
240287
),
241288
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,
255308
),
256-
textAlign: TextAlign.left,
257-
),
258-
Icon(Icons.arrow_forward),
259-
],
309+
Icon(Icons.arrow_forward),
310+
],
311+
),
260312
),
313+
upperColor: Colors.white,
314+
lowerColor: Colors.black,
315+
height: height * 0.052,
316+
width: width * 0.8,
317+
borderColor: Colors.black,
261318
),
262-
upperColor: Colors.white,
263-
lowerColor: Colors.black,
264-
height: height * 0.052,
265-
width: width * 0.8,
266-
borderColor: Colors.black,
267319
),
268320
),
269321
],

pubspec.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ dependencies:
2727
# The following adds the Cupertino Icons font to your application.
2828
# Use with the CupertinoIcons class for iOS style icons.
2929
cupertino_icons: ^0.1.3
30-
adobe_xd: ^0.1.4
30+
adobe_xd: ^1.1.0+1
3131
google_fonts: ^1.1.0
32-
32+
razorpay_flutter: 1.1.0
33+
fluttertoast: ^7.1.8
34+
dependency_overrides:
35+
flutter_svg: 0.19.0
3336
dev_dependencies:
3437
flutter_test:
3538
sdk: flutter

0 commit comments

Comments
 (0)