Advertisement
narimetisaigopi

flutter razorpay integration code

Dec 14th, 2020
1,389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. # add this package "razorpay_flutter: ^1.2.2" in the pubspec.yaml file
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:razorpay_flutter/razorpay_flutter.dart';
  5.  
  6. class PaymentScreen extends StatefulWidget {
  7. @override
  8. _PaymentScreenState createState() => _PaymentScreenState();
  9. }
  10.  
  11. class _PaymentScreenState extends State<PaymentScreen> {
  12. var _razorpay = Razorpay();
  13.  
  14. var options;
  15.  
  16. @override
  17. void initState() {
  18. _razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
  19. _razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
  20. _razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
  21.  
  22. options = {
  23. 'key': '<Generate and Add Your Key here https://dashboard.razorpay.com/app/keys>',
  24. 'amount': 100 * 100,
  25. 'name': 'Sai Gopi YT',
  26. 'description': 'Course Free',
  27. 'prefill': {'contact': '7981686394', 'email': 'test@razorpay.com'}
  28. };
  29.  
  30. super.initState();
  31. }
  32.  
  33. void _handlePaymentSuccess(PaymentSuccessResponse response) {
  34. // Do something when payment succeeds
  35.  
  36. print("_handlePaymentSuccess payment is success " + response.paymentId);
  37. }
  38.  
  39. void _handlePaymentError(PaymentFailureResponse response) {
  40. // Do something when payment fails
  41. print("_handlePaymentError payment is failed " + response.message);
  42. }
  43.  
  44. void _handleExternalWallet(ExternalWalletResponse response) {
  45. // Do something when an external wallet was selected
  46. }
  47.  
  48. @override
  49. Widget build(BuildContext context) {
  50. return Scaffold(
  51. appBar: AppBar(
  52. title: Text("Payment Gateway"),
  53. ),
  54. body: Center(
  55. child: RaisedButton(
  56. onPressed: () {
  57. _razorpay.open(options);
  58. },
  59. child: Text("Start payment")),
  60. ),
  61. );
  62. }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement