Nets-mobile-acceptance / Netaxept-Android-SDK

PiA Netaxept Android SDK is a library that provides the native In-App interaction to perform Netaxept payments directly from an app on Android devices while minimizing PCI DSS requirements for you.
31 stars 15 forks source link

React Native sample error handling #13

Closed igor-bv closed 4 years ago

igor-bv commented 4 years ago

@Miss-PiA, hi! Could you please explain/clarify error handling case on register api request error(on android example at least). As far as I see error handler will call buildTransactionInfo with null values as arguments. https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/App.js#L117

But as far as getTransactionInfo will run the while loop when transactionInfo == null - this loop seems like became an infinite loop. https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L444

So the questions are:

  1. Am I correct in the above statements? If yes - how to figure out from closing Nets dialog with appropriate error?
  2. How can I cancel Nets dialog activity from the JS code? For example for the case when some api request in JS code will fail?

Thanks in advance!

Miss-PiA commented 4 years ago

Hello,

Thank you for reaching out to us.

https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L444 Yes you are absolutely right about the above code in the current implementation, the loop gets into a never ending state, we will look into the issue and do the required changes.

For handling the error case on register api request you must break the loop in below code by making this condition false when the result is returned back to buildTransactionInfo with null values as arguments. https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L444

You can use any logic for identifying that the response for register api has been received with a null value which should break the while loop and let the code return null value to PiASDK via this line https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L449

PiASDK will do the check for null and complete the payment flow by finishing the activity and sending back the result in onActivityResult of SDKModule https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L81

Further you can handle the result from onActivityResult and show an appropriate error to the users.

As of the current implementation, you will have result.isSuccess() as false https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L87

But the result.getError() will contain null so you will have to handle the error with an appropriate message https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L93

We will take this point as well into consideration and make sure sdk returns an appropriate error code.

Thank you for pointing out the issue.

Please let us know if you have further questions!

igor-bv commented 4 years ago

Hello,

Thank you for reaching out to us.

https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L444

Yes you are absolutely right about the above code in the current implementation, the loop gets into a never ending state, we will look into the issue and do the required changes. For handling the error case on register api request you must break the loop in below code by making this condition false when the result is returned back to buildTransactionInfo with null values as arguments. https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L444

You can use any logic for identifying that the response for register api has been received with a null value which should break the while loop and let the code return null value to PiASDK via this line https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L449

PiASDK will do the check for null and complete the payment flow by finishing the activity and sending back the result in onActivityResult of SDKModule https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L81

Further you can handle the result from onActivityResult and show an appropriate error to the users.

As of the current implementation, you will have result.isSuccess() as false https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L87

But the result.getError() will contain null so you will have to handle the error with an appropriate message https://github.com/Nets-mobile-acceptance/Netaxept-Android-SDK/blob/d01e89b5a5dc638d35eecb072e806f740c97d886/ReactNative/PiaSampleReactNative/android/app/src/main/java/com/piasample/SDKModule.java#L93

We will take this point as well into consideration and make sure sdk returns an appropriate error code.

Thank you for pointing out the issue.

Please let us know if you have further questions!

Hi, thanks for the feedback. I'll add some logic as you suggested.