-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support offline mode #564
support offline mode #564
Conversation
@@ -961,4 +997,33 @@ class StripeTerminalReactNative: RCTEventEmitter, DiscoveryDelegate, BluetoothRe | |||
let result = Mappers.mapFromReaderDisplayMessage(displayMessage) | |||
sendEvent(withName: ReactNativeConstants.REQUEST_READER_DISPLAY_MESSAGE.rawValue, body: ["result": result]) | |||
} | |||
|
|||
func terminal(_ terminal: Terminal, didChange offlineStatus: OfflineStatus) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func terminal(_ terminal: Terminal, didChange offlineStatus: OfflineStatus) { | |
func terminal(_ terminal: Terminal, didChangeOfflineStatus offlineStatus: OfflineStatus) { |
android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good. I left a few comments, some are echoing @nazli-stripe's comments as well. Thanks for the big lift here!
android/src/main/java/com/stripeterminalreactnative/ReactNativeConstants.kt
Outdated
Show resolved
Hide resolved
android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt
Show resolved
Hide resolved
android/src/main/java/com/stripeterminalreactnative/StripeTerminalReactNativeModule.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I left a handful of small comments.
"prefer_online" -> OfflineBehavior.PREFER_ONLINE | ||
"require_online" -> OfflineBehavior.REQUIRE_ONLINE | ||
"force_offline" -> OfflineBehavior.FORCE_OFFLINE | ||
else -> OfflineBehavior.PREFER_ONLINE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize we are following the same pattern we do elsewhere, but I think we should consider more strictly validating the input string parameters, rather than assuming a default value whenever the string doesn't match an expected value. Specifically, I think we should raise an exception here rather than defaulting to PREFER_ONLINE
.
No change requested for this PR, but please consider making this change broadly throughout the RN code base in the future.
@@ -138,6 +139,7 @@ export interface StripeTerminalSdkType { | |||
setSimulatedCard(cardNumber: string): Promise<{ | |||
error?: StripeError; | |||
}>; | |||
getOfflineStatus(): Promise<OfflinePaymentStatus>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooc, is there a reason this returns a Promise
instead of just an OfflinePaymentStatus
? The values should be immediately available from the native SDKs, so I don't think we need to make this async.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank a lot for your comments~. we have also considered using the synchronous method before. Later, during the debugging process, we saw the RN document mentioning the suggestion that we use the asynchronous method to avoid possible performance problems. Please kindly correct us if we understand something wrong.https://reactnative.dev/docs/native-modules-android?android-language=kotlin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it. I'm fine with leaving this as async and returning a promise. 👍
android/src/main/java/com/stripeterminalreactnative/listener/RNOfflineListener.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes look good. I left one small comment re: the error message.
android/src/main/java/com/stripeterminalreactnative/listener/RNOfflineListener.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Latest changes look good to me. Thanks!
2852529
to
43eaa36
Compare
Summary
Support offline mode
Motivation
To support users to create and process PaymentIntents while offline.
Testing
Documentation
Select one: