Skip to content

Commit

Permalink
Merge pull request #60 from nb9960/master
Browse files Browse the repository at this point in the history
Integrated razorpay
  • Loading branch information
himanshusharma89 authored Mar 8, 2021
2 parents 05c3e6f + 754c62d commit 2d59aab
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 27 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.retro_shopping"
minSdkVersion 16
targetSdkVersion 28
minSdkVersion 23
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
98 changes: 75 additions & 23 deletions lib/widgets/payment/payment_window.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:retro_shopping/helpers/constants.dart';
import 'package:retro_shopping/widgets/payment/payment_successful.dart';
import 'package:retro_shopping/widgets/retro_button.dart';
import 'package:razorpay_flutter/razorpay_flutter.dart';
import 'package:fluttertoast/fluttertoast.dart';

class PaymentWindow extends StatefulWidget {
@override
Expand All @@ -9,12 +12,56 @@ class PaymentWindow extends StatefulWidget {

class _PaymentWindowState extends State<PaymentWindow> {
int cnt1, cnt2;

Razorpay _razorpay = Razorpay();
@override
void initState() {
super.initState();
cnt1 = 0;
cnt2 = 0;
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
}

@override
void dispose() {
_razorpay.clear();
super.dispose();
}

void _openCheckout() async {
var options = {
// Add valid key and other relevant options
'key': 'rzp_test_1DP5mmOlF5G5ag',
'external': {
'wallets': ['paytm', 'gpay', 'bhim']
}
};

try {
_razorpay.open(options);
} catch (e) {
debugPrint(e);
}
}

void refresh() {
setState(() {});
}

void _handlePaymentSuccess(PaymentSuccessResponse response) async {
Fluttertoast.showToast(msg: "SUCCESS: " + response.paymentId);
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => PaymentSuccessful()));
}

void _handlePaymentError(PaymentFailureResponse response) {
Fluttertoast.showToast(
msg: "ERROR: " + response.code.toString() + " - " + response.message);
}

void _handleExternalWallet(ExternalWalletResponse response) {
Fluttertoast.showToast(msg: "EXTERNAL_WALLET: " + response.walletName);
}

@override
Expand Down Expand Up @@ -239,31 +286,36 @@ class _PaymentWindowState extends State<PaymentWindow> {
height: height * 0.01,
),
Center(
child: RetroButton(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Payment & Address',
style: TextStyle(
fontFamily: 'pix M 8pt',
fontSize: 20,
fontWeight: FontWeight.bold,
color: RelicColors.primaryBlack,
child: InkWell(
onTap: () {
_openCheckout();
},
child: RetroButton(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Payment & Address',
style: TextStyle(
fontFamily: 'pix M 8pt',
fontSize: 20,
fontWeight: FontWeight.bold,
color: RelicColors.primaryBlack,
),
textAlign: TextAlign.left,
),
textAlign: TextAlign.left,
),
Icon(Icons.arrow_forward),
],
Icon(Icons.arrow_forward),
],
),
),
upperColor: Colors.white,
lowerColor: Colors.black,
height: height * 0.052,
width: width * 0.8,
borderColor: Colors.black,
),
upperColor: Colors.white,
lowerColor: Colors.black,
height: height * 0.052,
width: width * 0.8,
borderColor: Colors.black,
),
),
],
Expand Down
7 changes: 5 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
adobe_xd: ^0.1.4
adobe_xd: ^1.1.0+1
google_fonts: ^1.1.0

razorpay_flutter: 1.1.0
fluttertoast: ^7.1.8
dependency_overrides:
flutter_svg: 0.19.0
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 2d59aab

Please sign in to comment.