razorpay / razorpay-flutter

Razorpay Flutter Plugin
MIT License
106 stars 149 forks source link

type 'String' is not a subtype of type 'Map<dynamic, dynamic>?' in type cast #289

Open msai0109 opened 1 year ago

msai0109 commented 1 year ago

Description

Facing issue when I am trying to launch the razorpay checkout activity using "razorpay.open(options)".its showing razorpay loading screen and closing razorpay screen immediately.

Flutter Version :

Flutter 3.0.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision ee4e09cce0 (7 months ago) • 2022-05-09 16:45:18 -0700 Engine • revision d1b9a6938a Tools • Dart 2.17.0 • DevTools 2.12.2

Xcode Version :

14.1 (14B47b)

LOG:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'String' is not a subtype of type 'Map<dynamic, dynamic>?' in type cast

0 PaymentFailureResponse.fromMap (package:razorpay_flutter/razorpay_flutter.dart:150:44)

1 Razorpay._handleResult (package:razorpay_flutter/razorpay_flutter.dart:72:42)

2 Razorpay.open (package:razorpay_flutter/razorpay_flutter.dart:54:5)

E/ActivityThread( 2973): Activity com.razorpay.CheckoutActivity has leaked IntentReceiver com.razorpay.E$_q$@3d138fb that was originally registered here. Are you missing a call to unregisterReceiver()? E/ActivityThread( 2973): android.app.IntentReceiverLeaked: Activity com.razorpay.CheckoutActivity has leaked IntentReceiver com.razorpay.E$_q$@3d138fb that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1717) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1494) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1757) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1723) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:736) at com.razorpay.O$_M$.onFinish(CheckoutPresenterImpl.java:889) at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:142) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) ## Options : var options = { 'key': 'xxxxxxxxxxxx', 'amount': 9900, 'name': 'RazorPay Flutter', 'prefill': {'contact': '1234567890', 'email': 'test@example.com'}, 'retry': {'enabled': true, 'max_count': 1}, 'send_sms_hash': true, 'subscription_id': 'sub_id', 'external': { 'wallets': ['paytm'] } };
aj-stimveda commented 1 year ago

It's because you are probably testing this in your emulator. This plugin only works in real devices.

swarajkumarsingh commented 1 year ago

Greeting msai0109

Problem: The problem here is the orderID that you are using to get the orderID, paymentId, and signature. the orderID Is already exhausted and used in the previous Razopay Instance Call. In simple words, you are using the same orderID again and again in Razorpay SDK.

Solution: the best solution is to wrap your Razorpay instance with a try-catch block and use a different orderID each and every time you call Razorpay SDK.

        var options = {
                        'key': myKeyId,
                        'amount': 100,
                        'name': 'Acme Corp.',
                        'description': 'Fine T-Shirt',
                        'retry': {'enabled': true, 'max_count': 1},
                        'order_id': myOrderId, // Different OrderID
                        'send_sms_hash': true,
                        'prefill': {
                          'contact': '8888888888',
                          'email': 'test@razorpay.com'
                        },
                        'external': {
                          'wallets': ['paytm']
                        }
          };

WHY ? Razorpay SDK is not throwing the appropriate error, maybe they will fix this error by logging on to later versions.

msai0109 commented 1 year ago

Greeting msai0109

Problem: The problem here is the orderID that you are using to get the orderID, paymentId, and signature. the orderID Is already exhausted and used in the previous Razopay Instance Call. In simple words, you are using the same orderID again and again in Razorpay SDK.

Solution: the best solution is to wrap your Razorpay instance with a try-catch block and use a different orderID each and every time you call Razorpay SDK.

       var options = {
                       'key': myKeyId,
                       'amount': 100,
                       'name': 'Acme Corp.',
                       'description': 'Fine T-Shirt',
                       'retry': {'enabled': true, 'max_count': 1},
                       'order_id': myOrderId, // Different OrderID
                       'send_sms_hash': true,
                       'prefill': {
                         'contact': '8888888888',
                         'email': 'test@razorpay.com'
                       },
                       'external': {
                         'wallets': ['paytm']
                       }
         };

WHY ? Razorpay SDK is not throwing the appropriate error, maybe they will fix this error by logging on to later versions.

here, i am trying to create subscription.

HarshitSingh1509 commented 1 year ago

Description

Facing issue when I am trying to launch the razorpay checkout activity using "razorpay.open(options)".its showing razorpay loading screen and closing razorpay screen immediately.

  • Razorpay Package version : 1.3.4
  • Android Emulator version : Pixel_3a_API_31
  • Mode : Debug

Flutter Version :

Flutter 3.0.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision ee4e09cce0 (7 months ago) • 2022-05-09 16:45:18 -0700 Engine • revision d1b9a6938a Tools • Dart 2.17.0 • DevTools 2.12.2

Xcode Version :

14.1 (14B47b)

LOG:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'String' is not a subtype of type 'Map<dynamic, dynamic>?' in type cast #0 PaymentFailureResponse.fromMap (package:razorpay_flutter/razorpay_flutter.dart:150:44) #1 Razorpay._handleResult (package:razorpay_flutter/razorpay_flutter.dart:72:42) #2 Razorpay.open (package:razorpay_flutter/razorpay_flutter.dart:54:5)

E/ActivityThread( 2973): Activity com.razorpay.CheckoutActivity has leaked IntentReceiver com.razorpay.E$_q$@3d138fb that was originally registered here. Are you missing a call to unregisterReceiver()? E/ActivityThread( 2973): android.app.IntentReceiverLeaked: Activity com.razorpay.CheckoutActivity has leaked IntentReceiver com.razorpay.E$_q$@3d138fb that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1717) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1494) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1757) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1723) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:736) at com.razorpay.O$_M$.onFinish(CheckoutPresenterImpl.java:889) at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:142) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Options :

var options = { 'key': 'xxxxxxxxxxxx', 'amount': 9900, 'name': 'RazorPay Flutter', 'prefill': {'contact': '1234567890', 'email': 'test@example.com'}, 'retry': {'enabled': true, 'max_count': 1}, 'send_sms_hash': true, 'subscription_id': 'sub_id', 'external': { 'wallets': ['paytm'] } };

I am still facing this issue, Unhandled Exception: type 'String' is not a subtype of type 'Map<dynamic, dynamic>?' in type cast #0 PaymentFailureResponse.fromMap What does razorpay suggest in this case? Should I downgrade the version or any changes in plugin's original code?

swarajkumarsingh commented 1 year ago

Greeting HarshitSingh1509

Problem: The problem here in the orderID that you are using to get the orderID, paymentId, and signature. the orderID Is already exhausted and used in the previous Razopay Instance Call. In simple words, you are using the same orderID again and again in Razorpay SDK.

Solution: the best solution is to wrap your Razorpay instance with a try-catch block and use a different orderID each and every time you call Razorpay SDK. Also do not forget to check whether your keyID and orderID are in correct place.

   var options = {
                   'key': myKeyId,
                   'amount': 100,
                   'name': 'Acme Corp.',
                   'description': 'Fine T-Shirt',
                   'retry': {'enabled': true, 'max_count': 1},
                   'order_id': myOrderId, // Different OrderID
                   'send_sms_hash': true,
                   'prefill': {
                     'contact': '8888888888',
                     'email': 'test@razorpay.com'
                   },
                   'external': {
                     'wallets': ['paytm']
                   }
     };
swarajkumarsingh commented 1 year ago

Ok, so just take the orderID, paymentId, and signature, then verify it in the RazorpayPay Payment SDK in onSuccessResponse, and then send the credentials returned by the razorpay SDK to backend, and then work accordingly

Akshiiitsaxena commented 1 year ago

@HarshitSingh1509 were you able to get any workaround for this problem?

swarajkumarsingh commented 1 year ago

@HarshitSingh1509 Please provide more of your code, to get over the problem. @HarshitSingh1509 are also facing the same problem ?

HarshitSingh1509 commented 1 year ago

@Akshiiitsaxena I have downgraded the version of razorpay and everything went well!! @swarajkumarsingh I have just used the latest version and tried to implement the code, there only I got the error

swarajkumarsingh commented 1 year ago

@Akshiiitsaxena I have downgraded the version of Razorpay and everything went well!! @swarajkumarsingh I have just used the latest version and tried to implement the code, there only I got the error

@HarshitSingh1509 Yes the version can also solve the problem, but the point to note is that in the above code, orderId is not used in the Razorpay SDK, if this is continued then we won't get orderID, paymentId, and signature, and then we cant verify whether the order is valid or not, so the point is orderId should be present.