From 5ae19ef9607467e4298276778e065958f2878f78 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Thu, 22 Jun 2023 22:54:37 +0800 Subject: [PATCH] [go] update stripe-react-native to 0.28.0 (#23035) # Why update vendoring modules for sdk 49 # How - `et uvm -m @stripe/stripe-react-native -c 'v0.28.0'` - backport native stripe version to old sdks' podspec and build.gradle - transform manually - [android] remove `GooglePayButtonManager.kt`, `GooglePayButtonView.kt` - [android] remove `GooglePayButtonManager()` and `AddToWalletButtonManager()` in `StripeSdkPackage.kt` - [android] revert `import host.exp.expoview.R` change in `CardFormView.kt` - [ios] remove `stripe-react-native/ios/Tests/**/*` test files # Test Plan 1. clone and setup [stripe example app](https://github.com/stripe/stripe-react-native#run-the-example-app) 2. in `example/` - `yarn add file:/path/to/expo/packages/expo` - yarn add for `react-native@0.72.0`, `react@18.2.0` and other unsynced packages - and other necessary changes. i'd shared my patch file here: https://gist.github.com/Kudo/1d976feb403c325828b61b301bea3276 3. install unversioned expo go to simulator/emulator 4. modify the stripe cloned repo's maestro e2e test cases - cd `e2e-tests` - modify the ***.yml** file you want to test and replace `- launchApp` to ```yml - stopApp - openLink: exp://127.0.0.1:8081 ``` - replace the 127.0.0.1:8081 to the local dev-server address 5. run maestro test, e.g. `maestro --device {device_id} test -e APP_ID=host.exp.Exponent cardfield-basic.yml` 6. i only went through these test cases - cardfield-basic.yml - paymentsheet-basic.yml - paymentsheet-customFlow.yml --- .../reactnativestripesdk/CardFieldView.kt | 4 ++ .../CardFieldViewManager.kt | 5 +++ .../reactnativestripesdk/CardFormView.kt | 4 ++ .../CardFormViewManager.kt | 5 +++ .../FinancialConnectionsSheetFragment.kt | 40 +++++++++++++++---- ios/Podfile.lock | 4 +- .../ios/CardFieldManager.m | 1 + .../ios/CardFieldView.swift | 6 +++ .../stripe-react-native/ios/CardFormManager.m | 4 +- .../ios/CardFormView.swift | 18 ++++----- .../stripe-react-native/ios/StripeSdk.swift | 11 +++-- .../stripe-react-native.podspec.json | 4 +- packages/expo/bundledNativeModules.json | 2 +- 13 files changed, 79 insertions(+), 29 deletions(-) diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldView.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldView.kt index 62917c281a169..f37405447ea96 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldView.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldView.kt @@ -209,6 +209,10 @@ class CardFieldView(context: ThemedReactContext) : FrameLayout(context) { } } + fun setDisabled(isDisabled: Boolean) { + mCardWidget.isEnabled = !isDisabled + } + /** * We can reliable assume that setPostalCodeEnabled is called before * setCountryCode because of the order of the props in CardField.tsx diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldViewManager.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldViewManager.kt index a94cfaa1b1eba..f878026664275 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldViewManager.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFieldViewManager.kt @@ -56,6 +56,11 @@ class CardFieldViewManager : SimpleViewManager() { view.setPlaceHolders(placeholders) } + @ReactProp(name = "disabled") + fun setDisabled(view: CardFieldView, isDisabled: Boolean) { + view.setDisabled(isDisabled) + } + override fun createViewInstance(reactContext: ThemedReactContext): CardFieldView { val stripeSdkModule: StripeSdkModule? = reactContext.getNativeModule(StripeSdkModule::class.java) val view = CardFieldView(reactContext) diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormView.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormView.kt index 76daa2bdaaab9..5af251c78bab7 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormView.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormView.kt @@ -59,6 +59,10 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) { setCountry(defaults.getString("countryCode")) } + fun setDisabled(isDisabled: Boolean) { + cardForm.isEnabled = !isDisabled + } + private fun setCountry(countryString: String?) { if (countryString != null) { cardFormViewBinding.countryLayout.setSelectedCountryCode(CountryCode(countryString)) diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormViewManager.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormViewManager.kt index fe05125912ff5..1fb13f8796c8f 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormViewManager.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/CardFormViewManager.kt @@ -56,6 +56,11 @@ class CardFormViewManager : SimpleViewManager() { view.setDefaultValues(defaults) } + @ReactProp(name = "disabled") + fun setDisabled(view: CardFormView, isDisabled: Boolean) { + view.setDisabled(isDisabled) + } + override fun createViewInstance(reactContext: ThemedReactContext): CardFormView { val stripeSdkModule: StripeSdkModule? = reactContext.getNativeModule(StripeSdkModule::class.java) val view = CardFormView(reactContext) diff --git a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/FinancialConnectionsSheetFragment.kt b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/FinancialConnectionsSheetFragment.kt index bef07d65a3199..0a7601b1c5012 100644 --- a/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +++ b/android/expoview/src/main/java/versioned/host/exp/exponent/modules/api/components/reactnativestripesdk/FinancialConnectionsSheetFragment.kt @@ -180,18 +180,44 @@ class FinancialConnectionsSheetFragment : Fragment() { val map = WritableNativeMap() map.putDouble("asOf", balance.asOf * 1000.0) map.putString("type", mapFromBalanceType(balance.type)) - map.putMap("current", balance.current as ReadableMap) WritableNativeMap().also { - it.putMap("available", balance.cash?.available as ReadableMap) - map.putMap("cash", it) - } - WritableNativeMap().also { - it.putMap("used", balance.credit?.used as ReadableMap) - map.putMap("credit", it) + for (entry in balance.current.entries) { + it.putInt(entry.key, entry.value) + } + map.putMap("current", it) } + map.putMap("cash", mapFromCashAvailable(balance)) + map.putMap("credit", mapFromCreditUsed(balance)) + return map } + private fun mapFromCashAvailable(balance: Balance): WritableNativeMap { + return WritableNativeMap().also { cashMap -> + WritableNativeMap().also { availableMap -> + balance.cash?.available?.entries?.let { entries -> + for (entry in entries) { + availableMap.putInt(entry.key, entry.value) + } + } + cashMap.putMap("available", availableMap) + } + } + } + + private fun mapFromCreditUsed(balance: Balance): WritableNativeMap { + return WritableNativeMap().also { creditMap -> + WritableNativeMap().also { usedMap -> + balance.credit?.used?.entries?.let { entries -> + for (entry in entries) { + usedMap.putInt(entry.key, entry.value) + } + } + creditMap.putMap("used", usedMap) + } + } + } + private fun mapFromAccountBalanceRefresh(balanceRefresh: BalanceRefresh?): WritableMap? { if (balanceRefresh == null) { return null diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 484ad29fa7f91..995ef03019f9e 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2272,7 +2272,7 @@ PODS: - StripePayments (= 23.8.0) - StripePaymentsUI (= 23.8.0) - StripeUICore (= 23.8.0) - - stripe-react-native (0.27.2): + - stripe-react-native (0.28.0): - React-Core - Stripe (~> 23.8.0) - StripeApplePay (~> 23.8.0) @@ -3795,7 +3795,7 @@ SPEC CHECKSUMS: SDWebImageWebPCoder: 295a6573c512f54ad2dd58098e64e17dcf008499 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 Stripe: 5432fbab660595a3bee937235dd71a99028ac68c - stripe-react-native: 3c3ce2b0dbc0b4a85d8eaa72e96b78ef679b87d6 + stripe-react-native: 096d83ad94da350f08f5cd48275e7f9645dde297 StripeApplePay: 5e686f50ee07c439b79b907dffeb144135e601c9 StripeCore: 91164d69b8593f44df9ee93e56a00355592068b6 StripeFinancialConnections: b30a494579271f33f38d9a934288c2ad617bfc26 diff --git a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldManager.m b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldManager.m index 6ea66092b4f37..f57af87215033 100644 --- a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldManager.m +++ b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldManager.m @@ -10,6 +10,7 @@ @interface RCT_EXTERN_MODULE(CardFieldManager, RCTViewManager) RCT_EXPORT_VIEW_PROPERTY(cardStyle, NSDictionary) RCT_EXPORT_VIEW_PROPERTY(placeholders, NSDictionary) RCT_EXPORT_VIEW_PROPERTY(autofocus, BOOL) +RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(dangerouslyGetFullCardDetails, BOOL) RCT_EXTERN_METHOD(focus:(nonnull NSNumber*) reactTag) RCT_EXTERN_METHOD(blur:(nonnull NSNumber*) reactTag) diff --git a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldView.swift b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldView.swift index 95397cb0460f0..b1ccead2c1796 100644 --- a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldView.swift +++ b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFieldView.swift @@ -12,6 +12,12 @@ class CardFieldView: UIView, STPPaymentCardTextFieldDelegate { public var cardParams: STPPaymentMethodParams? = nil public var cardPostalCode: String? = nil + @objc var disabled: Bool = false { + didSet { + cardField.isUserInteractionEnabled = !disabled + } + } + @objc var postalCodeEnabled: Bool = true { didSet { cardField.postalCodeEntryEnabled = postalCodeEnabled diff --git a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormManager.m b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormManager.m index 22ad6b356c66b..6eadf6be3f74c 100644 --- a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormManager.m +++ b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormManager.m @@ -6,8 +6,8 @@ @interface RCT_EXTERN_MODULE(CardFormManager, RCTViewManager) RCT_EXPORT_VIEW_PROPERTY(onFormComplete, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(dangerouslyGetFullCardDetails, BOOL) RCT_EXPORT_VIEW_PROPERTY(autofocus, BOOL) -RCT_EXPORT_VIEW_PROPERTY(isUserInteractionEnabledValue, BOOL) +RCT_EXPORT_VIEW_PROPERTY(cardStyle, NSDictionary) +RCT_EXPORT_VIEW_PROPERTY(disabled, BOOL) RCT_EXTERN_METHOD(focus:(nonnull NSNumber*) reactTag) RCT_EXTERN_METHOD(blur:(nonnull NSNumber*) reactTag) -RCT_EXPORT_VIEW_PROPERTY(cardStyle, NSDictionary) @end diff --git a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormView.swift b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormView.swift index f0bc39b2ad3b2..5d68322fbbd16 100644 --- a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormView.swift +++ b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/CardFormView.swift @@ -10,7 +10,7 @@ class CardFormView: UIView, STPCardFormViewDelegate { @objc var dangerouslyGetFullCardDetails: Bool = false @objc var onFormComplete: RCTDirectEventBlock? @objc var autofocus: Bool = false - @objc var isUserInteractionEnabledValue: Bool = true + @objc var disabled: Bool = false override func didSetProps(_ changedProps: [String]!) { if let cardForm = self.cardForm { @@ -20,7 +20,7 @@ class CardFormView: UIView, STPCardFormViewDelegate { let style = self.cardStyle["type"] as? String == "borderless" ? STPCardFormViewStyle.borderless : STPCardFormViewStyle.standard let _cardForm = STPCardFormView(style: style) _cardForm.delegate = self - // _cardForm.isUserInteractionEnabled = isUserInteractionEnabledValue + _cardForm.isUserInteractionEnabled = !disabled if autofocus == true { let _ = _cardForm.becomeFirstResponder() @@ -33,10 +33,10 @@ class CardFormView: UIView, STPCardFormViewDelegate { @objc var cardStyle: NSDictionary = NSDictionary() { didSet { - setStyles() + setStyles() } } - + func cardFormView(_ form: STPCardFormView, didChangeToStateComplete complete: Bool) { if onFormComplete != nil { let brand = STPCardValidator.brand(forNumber: cardForm?.cardParams?.card?.number ?? "") @@ -49,7 +49,7 @@ class CardFormView: UIView, STPCardFormViewDelegate { "postalCode": cardForm?.cardParams?.billingDetails?.address?.postalCode ?? "", "country": cardForm?.cardParams?.billingDetails?.address?.country ] - + if (dangerouslyGetFullCardDetails) { cardData["number"] = cardForm?.cardParams?.card?.number ?? "" cardData["cvc"] = cardForm?.cardParams?.card?.cvc ?? "" @@ -76,13 +76,13 @@ class CardFormView: UIView, STPCardFormViewDelegate { cardForm?.backgroundColor = UIColor(hexString: backgroundColor) } /** - The following reveals a bug in STPCardFormView where there's a extra space in the layer, - and thus must remain commented out for now. + The following reveals a bug in STPCardFormView where there's a extra space in the layer, + and thus must remain commented out for now. if let borderWidth = cardStyle["borderWidth"] as? Int { - cardForm?.layer.borderWidth = CGFloat(borderWidth) + cardForm?.layer.borderWidth = CGFloat(borderWidth) } else { - cardForm?.layer.borderWidth = CGFloat(0) + cardForm?.layer.borderWidth = CGFloat(0) } */ diff --git a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/StripeSdk.swift b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/StripeSdk.swift index 90cd5c130662e..047ae6be0790a 100644 --- a/ios/vendored/unversioned/@stripe/stripe-react-native/ios/StripeSdk.swift +++ b/ios/vendored/unversioned/@stripe/stripe-react-native/ios/StripeSdk.swift @@ -145,9 +145,8 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap case .canceled: resolve(Errors.createError(ErrorType.Canceled, "The payment flow has been canceled")) case .failed(let error): - resolve(Errors.createError(ErrorType.Failed, error.localizedDescription)) + resolve(Errors.createError(ErrorType.Failed, error)) } - } } else { resolve(Errors.createError(ErrorType.Failed, "No payment sheet has been initialized yet")) @@ -221,7 +220,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap STPAPIClient.shared.createToken(forCVCUpdate: cvc) { (token, error) in if error != nil || token == nil { - resolve(Errors.createError(ErrorType.Failed, error?.localizedDescription ?? "")) + resolve(Errors.createError(ErrorType.Failed, error as? NSError)) } else { let tokenId = token?.tokenId resolve(["tokenId": tokenId]) @@ -558,7 +557,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap if let paymentMethodParams = paymentMethodParams { STPAPIClient.shared.createPaymentMethod(with: paymentMethodParams) { paymentMethod, error in if let createError = error { - resolve(Errors.createError(ErrorType.Failed, createError.localizedDescription)) + resolve(Errors.createError(ErrorType.Failed, createError as NSError)) } else { resolve( Mappers.createResult("paymentMethod", Mappers.mapFromPaymentMethod(paymentMethod)) @@ -908,7 +907,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap if let lastPaymentError = paymentIntent?.lastPaymentError { resolve(Errors.createError(ErrorType.Unknown, lastPaymentError)) } else { - resolve(Errors.createError(ErrorType.Unknown, error?.localizedDescription)) + resolve(Errors.createError(ErrorType.Unknown, error as? NSError)) } return } @@ -932,7 +931,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap if let lastSetupError = setupIntent?.lastSetupError { resolve(Errors.createError(ErrorType.Unknown, lastSetupError)) } else { - resolve(Errors.createError(ErrorType.Unknown, error?.localizedDescription)) + resolve(Errors.createError(ErrorType.Unknown, error as? NSError)) } return } diff --git a/ios/vendored/unversioned/@stripe/stripe-react-native/stripe-react-native.podspec.json b/ios/vendored/unversioned/@stripe/stripe-react-native/stripe-react-native.podspec.json index 45823922dedfe..6ad8e44117ed2 100644 --- a/ios/vendored/unversioned/@stripe/stripe-react-native/stripe-react-native.podspec.json +++ b/ios/vendored/unversioned/@stripe/stripe-react-native/stripe-react-native.podspec.json @@ -1,6 +1,6 @@ { "name": "stripe-react-native", - "version": "0.27.2", + "version": "0.28.0", "summary": "Stripe SDK for React Native", "homepage": "https://github.com/stripe/stripe-react-native/#readme", "license": "MIT", @@ -10,7 +10,7 @@ }, "source": { "git": "https://github.com/stripe/stripe-react-native.git", - "tag": "0.27.2" + "tag": "0.28.0" }, "source_files": "ios/**/*.{h,m,mm,swift}", "exclude_files": "ios/Tests/", diff --git a/packages/expo/bundledNativeModules.json b/packages/expo/bundledNativeModules.json index 93a21dee5fc5b..44ae47739124d 100644 --- a/packages/expo/bundledNativeModules.json +++ b/packages/expo/bundledNativeModules.json @@ -8,7 +8,7 @@ "@react-native-community/viewpager": "5.0.11", "@react-native-picker/picker": "2.4.10", "@react-native-segmented-control/segmented-control": "2.4.1", - "@stripe/stripe-react-native": "0.27.2", + "@stripe/stripe-react-native": "0.28.0", "expo-analytics-amplitude": "~11.3.0", "expo-app-auth": "~11.1.0", "expo-app-loader-provider": "~8.0.0",