Skip to content
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

Merged
merged 21 commits into from
Nov 27, 2023
Merged

support offline mode #564

merged 21 commits into from
Nov 27, 2023

Conversation

ianlin-bbpos
Copy link
Collaborator

Summary

Support offline mode

Motivation

To support users to create and process PaymentIntents while offline.

Testing

  • I tested this manually
  • I added automated tests

Documentation

Select one:

  • I have added relevant documentation for my changes.
  • This PR does not result in any developer-facing changes.

ios/Mappers.swift Outdated Show resolved Hide resolved
@@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func terminal(_ terminal: Terminal, didChange offlineStatus: OfflineStatus) {
func terminal(_ terminal: Terminal, didChangeOfflineStatus offlineStatus: OfflineStatus) {

Copy link
Collaborator

@billfinn-stripe billfinn-stripe left a 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!

Copy link
Collaborator

@billfinn-stripe billfinn-stripe left a 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
Copy link
Collaborator

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>;
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

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. 👍

dev-app/src/screens/CollectCardPaymentScreen.tsx Outdated Show resolved Hide resolved
dev-app/src/screens/CollectCardPaymentScreen.tsx Outdated Show resolved Hide resolved
dev-app/src/screens/CollectCardPaymentScreen.tsx Outdated Show resolved Hide resolved
dev-app/src/screens/DatabaseScreen.tsx Outdated Show resolved Hide resolved
dev-app/src/screens/HomeScreen.tsx Outdated Show resolved Hide resolved
ios/StripeTerminalReactNative.swift Show resolved Hide resolved
src/components/StripeTerminalProvider.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@billfinn-stripe billfinn-stripe left a 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.

Copy link
Collaborator

@billfinn-stripe billfinn-stripe left a 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!

@nazli-stripe nazli-stripe merged commit ffb7cae into main Nov 27, 2023
1 check passed
@nazli-stripe nazli-stripe deleted the bbpos/support-offline-mode branch September 7, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants