From 91f569c542102cc526aa33b958ae3fdb350add7d Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Sat, 8 Jul 2023 10:15:06 +0200 Subject: [PATCH 1/3] sync Android + iOS with 0.28.0 --- .../AuBECSDebitFormView.kt | 4 +- .../com/reactnativestripesdk/CardFieldView.kt | 6 ++- .../CardFieldViewManager.kt | 5 +++ .../com/reactnativestripesdk/CardFormView.kt | 8 +++- .../CardFormViewManager.kt | 5 +++ .../FinancialConnectionsSheetFragment.kt | 40 +++++++++++++++---- .../pushprovisioning/AddToWalletButtonView.kt | 2 +- .../Classes/Stripe Sdk/CardFieldView.swift | 6 +++ .../ios/Classes/Stripe Sdk/CardFormView.swift | 18 ++++----- .../ios/Classes/Stripe Sdk/StripeSdk.swift | 11 +++-- 10 files changed, 77 insertions(+), 28 deletions(-) diff --git a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/AuBECSDebitFormView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/AuBECSDebitFormView.kt index f158db3c4..c95177847 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/AuBECSDebitFormView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/AuBECSDebitFormView.kt @@ -12,7 +12,7 @@ import com.google.android.material.shape.MaterialShapeDrawable import com.google.android.material.shape.ShapeAppearanceModel import com.reactnativestripesdk.utils.getIntOrNull import com.reactnativestripesdk.utils.getValOr -import com.stripe.android.databinding.BecsDebitWidgetBinding +import com.stripe.android.databinding.StripeBecsDebitWidgetBinding import com.stripe.android.model.PaymentMethodCreateParams import com.stripe.android.view.BecsDebitWidget import com.stripe.android.view.StripeEditText @@ -35,7 +35,7 @@ class AuBECSDebitFormView(private val context: ThemedReactContext) : FrameLayout if (!this::becsDebitWidget.isInitialized || value == null) { return } - val binding = BecsDebitWidgetBinding.bind(becsDebitWidget) + val binding = StripeBecsDebitWidgetBinding.bind(becsDebitWidget) val textColor = getValOr(value, "textColor", null) val textErrorColor = getValOr(value, "textErrorColor", null) val placeholderColor = getValOr(value, "placeholderColor", null) diff --git a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt index 27f1b1dfb..f032b13bb 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt @@ -22,7 +22,7 @@ import com.reactnativestripesdk.utils.* import com.reactnativestripesdk.utils.mapCardBrand import com.stripe.android.core.model.CountryCode import com.stripe.android.core.model.CountryUtils -import com.stripe.android.databinding.CardInputWidgetBinding +import com.stripe.android.databinding.StripeCardInputWidgetBinding import com.stripe.android.model.Address import com.stripe.android.model.PaymentMethodCreateParams import com.stripe.android.view.CardInputListener @@ -210,6 +210,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/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldViewManager.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldViewManager.kt index a87bca3b6..dcc2e911a 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldViewManager.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldViewManager.kt @@ -59,6 +59,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/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt index 0e2d2c0ff..88200926d 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormView.kt @@ -20,7 +20,7 @@ import com.google.android.material.shape.ShapeAppearanceModel import com.reactnativestripesdk.utils.* import com.reactnativestripesdk.utils.mapCardBrand import com.stripe.android.core.model.CountryCode -import com.stripe.android.databinding.CardMultilineWidgetBinding +import com.stripe.android.databinding.StripeCardMultilineWidgetBinding import com.stripe.android.databinding.StripeCardFormViewBinding import com.stripe.android.model.Address import com.stripe.android.model.PaymentMethodCreateParams @@ -37,7 +37,7 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) { var cardParams: PaymentMethodCreateParams.Card? = null var cardAddress: Address? = null private val cardFormViewBinding = StripeCardFormViewBinding.bind(cardForm) - private val multilineWidgetBinding = CardMultilineWidgetBinding.bind(cardFormViewBinding.cardMultilineWidget) + private val multilineWidgetBinding = StripeCardMultilineWidgetBinding.bind(cardFormViewBinding.cardMultilineWidget) init { cardFormViewBinding.cardMultilineWidgetContainer.isFocusable = true @@ -60,6 +60,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/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormViewManager.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormViewManager.kt index 473db495a..45000acc9 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFormViewManager.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/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/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt index dd202a824..bb41e4363 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/FinancialConnectionsSheetFragment.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/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/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt index e9c8f6f84..653c29f3a 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt @@ -95,7 +95,7 @@ class AddToWalletButtonView(private val context: ThemedReactContext, private val } }) .centerCrop() - .override((widthOverride * scale.toFloat()).toInt(), (heightOverride * scale.toFloat()).toInt()) + .override((widthOverride * scale).toInt(), (heightOverride * scale).toInt()) .into(this) } } diff --git a/packages/stripe_ios/ios/Classes/Stripe Sdk/CardFieldView.swift b/packages/stripe_ios/ios/Classes/Stripe Sdk/CardFieldView.swift index 65b8b7cac..742c754e5 100644 --- a/packages/stripe_ios/ios/Classes/Stripe Sdk/CardFieldView.swift +++ b/packages/stripe_ios/ios/Classes/Stripe Sdk/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/packages/stripe_ios/ios/Classes/Stripe Sdk/CardFormView.swift b/packages/stripe_ios/ios/Classes/Stripe Sdk/CardFormView.swift index f0bc39b2a..5d68322fb 100644 --- a/packages/stripe_ios/ios/Classes/Stripe Sdk/CardFormView.swift +++ b/packages/stripe_ios/ios/Classes/Stripe Sdk/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/packages/stripe_ios/ios/Classes/Stripe Sdk/StripeSdk.swift b/packages/stripe_ios/ios/Classes/Stripe Sdk/StripeSdk.swift index 90cd5c130..047ae6be0 100644 --- a/packages/stripe_ios/ios/Classes/Stripe Sdk/StripeSdk.swift +++ b/packages/stripe_ios/ios/Classes/Stripe Sdk/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 } From 288b76b46520866ee4f2ee43208670f1bd44007c Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Sat, 8 Jul 2023 10:34:41 +0200 Subject: [PATCH 2/3] add missing method callers + update Stripe iOS version --- .../com/flutter/stripe/StripeSdkCardFormPlatformView.kt | 8 ++++++++ .../com/flutter/stripe/StripeSdkCardPlatformView.kt | 8 ++++++++ packages/stripe_ios/ios/Classes/CardFieldFactory.swift | 7 ++++++- packages/stripe_ios/ios/Classes/CardFormFactory.swift | 7 ++++--- packages/stripe_ios/ios/stripe_ios.podspec | 2 +- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt index b472608b9..8416e5deb 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt @@ -48,6 +48,9 @@ class StripeSdkCardFormPlatformView( if (creationParams?.containsKey("autofocus") == true) { cardFormViewManager.setAutofocus(cardView, creationParams["autofocus"] as Boolean) } + if (creationParams?.containsKey("disabled") == true) { + cardFormViewManager.setDisabled(cardView, creationParams["disabled"] as Boolean) + } if (creationParams?.containsKey("cardDetails") == true) { val value = ReadableMap(creationParams["cardDetails"] as Map) @@ -101,6 +104,11 @@ class StripeSdkCardFormPlatformView( cardFormViewManager.setAutofocus(cardView, arguments.getBoolean("autofocus")) result.success(null) } + "disabled" -> { + val arguments = ReadableMap(call.arguments as Map) + cardFormViewManager.setDisabled(cardView, arguments.getBoolean("disabled")) + result.success(null) + } "requestFocus" -> { val binding = CardMultilineWidgetBinding.bind(cardView.cardForm) binding.etCardNumber.requestFocus() diff --git a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt index 9b7cf7c5f..1facb6fc1 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt @@ -43,6 +43,9 @@ class StripeSdkCardPlatformView( if (creationParams?.containsKey("placeholder") == true) { stripeSdkCardViewManager.setPlaceHolders(cardView, ReadableMap(creationParams["placeholder"] as Map)) } + if (creationParams?.containsKey("disabled") == true) { + stripeSdkCardViewManager.setDisabled(cardView, creationParams["disabled"] as Boolean) + } if (creationParams?.containsKey("dangerouslyGetFullCardDetails") == true) { stripeSdkCardViewManager.setDangerouslyGetFullCardDetails(cardView, creationParams["dangerouslyGetFullCardDetails"] as Boolean) } @@ -118,6 +121,11 @@ class StripeSdkCardPlatformView( stripeSdkCardViewManager.setAutofocus(cardView, arguments.getBoolean("autofocus")) result.success(null) } + "disabled" -> { + val arguments = ReadableMap(call.arguments as Map) + stripeSdkCardViewManager.setDisabled(cardView, arguments.getBoolean("disabled")) + result.success(null) + } "requestFocus" -> { val binding = CardInputWidgetBinding.bind(cardView.mCardWidget) binding.cardNumberEditText.requestFocus() diff --git a/packages/stripe_ios/ios/Classes/CardFieldFactory.swift b/packages/stripe_ios/ios/Classes/CardFieldFactory.swift index 1515562e0..c0864c950 100644 --- a/packages/stripe_ios/ios/Classes/CardFieldFactory.swift +++ b/packages/stripe_ios/ios/Classes/CardFieldFactory.swift @@ -75,7 +75,8 @@ class CardFieldPlatformView: NSObject, FlutterPlatformView, STPPaymentCardTextFi "onCountryCodeChangedEvent", "onPlaceholderChanged", "dangerouslyGetFullCardDetails", - "autofocus": + "autofocus", + "disabled": updateProps(call.arguments as? [String : Any]) result(nil) case "focus": @@ -132,6 +133,10 @@ class CardFieldPlatformView: NSObject, FlutterPlatformView, STPPaymentCardTextFi cardField.postalCodeEnabled = postalCodeEnabled } + if let disabled = arguments["disabled"] as? Bool{ + cardField.disabled = disabled + } + if let cardDetails = arguments["cardDetails"] as? NSDictionary { cardField.dangerouslyUpdateCardDetails(params: cardDetails) } diff --git a/packages/stripe_ios/ios/Classes/CardFormFactory.swift b/packages/stripe_ios/ios/Classes/CardFormFactory.swift index e62a28c02..9cc50b829 100644 --- a/packages/stripe_ios/ios/Classes/CardFormFactory.swift +++ b/packages/stripe_ios/ios/Classes/CardFormFactory.swift @@ -75,7 +75,8 @@ class CardFormPlatformView : NSObject, FlutterPlatformView { "onPostalCodeEnabledChanged", "dangerouslyGetFullCardDetails", "isUserInteractionEnabledValue", - "autofocus": + "autofocus", + "disabled": updateProps(call.arguments) result(nil) case "focus": @@ -104,8 +105,8 @@ class CardFormPlatformView : NSObject, FlutterPlatformView { cardForm.dangerouslyGetFullCardDetails = dangerouslyGetFullCardDetails } - if let isUserInteractionEnabledValue = arguments["isUserInteractionEnabledValue"] as? Bool{ - cardForm.isUserInteractionEnabledValue = isUserInteractionEnabledValue + if let disabled = arguments["disabled"] as? Bool{ + cardForm.disabled = disabled } if let autofocus = arguments["autofocus"] as? Bool{ cardForm.autofocus = autofocus diff --git a/packages/stripe_ios/ios/stripe_ios.podspec b/packages/stripe_ios/ios/stripe_ios.podspec index d40dd97b5..62cfa3aab 100644 --- a/packages/stripe_ios/ios/stripe_ios.podspec +++ b/packages/stripe_ios/ios/stripe_ios.podspec @@ -2,7 +2,7 @@ # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. # Run `pod lib lint stripe_ios.podspec' to validate before publishing. # -stripe_version = '~> 23.7.0' +stripe_version = '~> 23.8.0' Pod::Spec.new do |s| s.name = 'stripe_ios' s.version = '0.0.1' From 5791de5fc89d24e754de9f582730a6e12f009098 Mon Sep 17 00:00:00 2001 From: Remon <> Date: Sat, 8 Jul 2023 20:30:05 +0200 Subject: [PATCH 3/3] sync dart side with version 0.28 --- example/ios/Runner.xcodeproj/project.pbxproj | 1 + packages/stripe/lib/src/stripe.dart | 2 +- .../stripe/lib/src/widgets/card_field.dart | 10 ++++++ .../lib/src/widgets/card_form_field.dart | 34 ++++++++++++------- packages/stripe_android/android/build.gradle | 2 +- .../stripe/StripeSdkCardFormPlatformView.kt | 4 +-- .../stripe/StripeSdkCardPlatformView.kt | 6 ++-- .../com/reactnativestripesdk/CardFieldView.kt | 2 +- .../pushprovisioning/AddToWalletButtonView.kt | 2 +- 9 files changed, 42 insertions(+), 21 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 729c8c8e8..d402467cc 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -299,6 +299,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( diff --git a/packages/stripe/lib/src/stripe.dart b/packages/stripe/lib/src/stripe.dart index 65ade184f..bb2ca9cdc 100644 --- a/packages/stripe/lib/src/stripe.dart +++ b/packages/stripe/lib/src/stripe.dart @@ -506,7 +506,7 @@ class Stripe { /// Call this method when the user logs out from your app. /// - /// This will ensur ethat any persisted authentication state in the + /// This will ensure that any persisted authentication state in the /// paymentsheet, such as authentication cookies are cleared during logout. Future resetPaymentSheetCustomer() async { await _awaitForSettings(); diff --git a/packages/stripe/lib/src/widgets/card_field.dart b/packages/stripe/lib/src/widgets/card_field.dart index b0419c5a4..82e9d7562 100644 --- a/packages/stripe/lib/src/widgets/card_field.dart +++ b/packages/stripe/lib/src/widgets/card_field.dart @@ -21,6 +21,7 @@ class CardField extends StatefulWidget { this.countryCode, this.style, this.autofocus = false, + this.disabled = false, this.dangerouslyGetFullCardDetails = false, this.dangerouslyUpdateFullCardDetails = false, this.cursorColor, @@ -77,6 +78,11 @@ class CardField extends StatefulWidget { /// Default is `false`. final bool autofocus; + /// When true it applies a state that does not allow the user to interact with + /// the card form field. + /// Default is `false`. + final bool disabled; + /// Controller that can be use to execute several operations on the cardfield /// e.g (clear). final CardEditController? controller; @@ -178,6 +184,7 @@ class _CardFieldState extends State { delegate: const _NegativeMarginLayout(margin: platformMargin), child: _MethodChannelCardField( controller: controller, + disabled: widget.disabled, height: platformCardHeight, androidPlatformViewRenderType: widget.androidPlatformViewRenderType, @@ -274,6 +281,7 @@ class _MethodChannelCardField extends StatefulWidget { this.style, this.placeholder, this.enablePostalCode = false, + this.disabled = false, this.countryCode, double? width, double? height = kCardFieldDefaultHeight, @@ -298,6 +306,7 @@ class _MethodChannelCardField extends StatefulWidget { final String? countryCode; final FocusNode focusNode; final bool autofocus; + final bool disabled; final CardEditController controller; final bool dangerouslyGetFullCardDetails; final bool dangerouslyUpdateFullCardDetails; @@ -395,6 +404,7 @@ class _MethodChannelCardFieldState extends State<_MethodChannelCardField> controller.initalDetails != null) 'cardDetails': controller.initalDetails?.toJson(), 'autofocus': widget.autofocus, + 'disabled': widget.disabled, }; Widget platform; diff --git a/packages/stripe/lib/src/widgets/card_form_field.dart b/packages/stripe/lib/src/widgets/card_form_field.dart index 4797e0642..7ab7de580 100644 --- a/packages/stripe/lib/src/widgets/card_form_field.dart +++ b/packages/stripe/lib/src/widgets/card_form_field.dart @@ -18,18 +18,19 @@ import 'keep_visible_on_focus.dart'; /// ![Sripe Card Form] /// (https://github.com/flutter-stripe/flutter_stripe/tree/main/docs/assets/card_form.png) class CardFormField extends StatefulWidget { - const CardFormField( - {this.onCardChanged, - Key? key, - this.onFocus, - this.enablePostalCode = true, - this.countryCode, - this.style, - this.autofocus = false, - this.dangerouslyGetFullCardDetails = false, - this.dangerouslyUpdateFullCardDetails = false, - this.controller}) - : super(key: key); + const CardFormField({ + this.onCardChanged, + Key? key, + this.onFocus, + this.enablePostalCode = true, + this.countryCode, + this.style, + this.autofocus = false, + this.dangerouslyGetFullCardDetails = false, + this.dangerouslyUpdateFullCardDetails = false, + this.disabled = false, + this.controller, + }) : super(key: key); /// Callback that will be executed when a specific field gets focus. final CardFocusCallback? onFocus; @@ -80,6 +81,11 @@ class CardFormField extends StatefulWidget { /// Default is `false`. final bool dangerouslyUpdateFullCardDetails; + /// When true it applies a state that does not allow the user to interact with + /// the card form field. + /// Default is `false`. + final bool disabled; + @override // ignore: library_private_types_in_public_api _CardFormFieldState createState() => _CardFormFieldState(); @@ -187,6 +193,7 @@ class _CardFormFieldState extends State { enablePostalCode: widget.enablePostalCode, onCardChanged: widget.onCardChanged, autofocus: widget.autofocus, + disabled: widget.disabled, onFocus: widget.onFocus, countryCode: widget.countryCode, ); @@ -212,6 +219,7 @@ class _MethodChannelCardFormField extends StatefulWidget { this.dangerouslyGetFullCardDetails = false, this.dangerouslyUpdateFullCardDetails = false, this.autofocus = false, + this.disabled = false, this.countryCode, }) : assert(constraints == null || constraints.debugAssertIsValid()), constraints = (width != null || height != null) @@ -227,6 +235,7 @@ class _MethodChannelCardFormField extends StatefulWidget { final bool enablePostalCode; final FocusNode focusNode; final bool autofocus; + final bool disabled; final CardFormEditController controller; final bool dangerouslyGetFullCardDetails; final bool dangerouslyUpdateFullCardDetails; @@ -299,6 +308,7 @@ class _MethodChannelCardFormFieldState controller._initalDetails != null) 'cardDetails': controller._initalDetails?.toJson(), 'autofocus': widget.autofocus, + 'disabled': widget.disabled, 'defaultValues': { 'countryCode': widget.countryCode, } diff --git a/packages/stripe_android/android/build.gradle b/packages/stripe_android/android/build.gradle index a1221b8ab..c7e2e2ff1 100644 --- a/packages/stripe_android/android/build.gradle +++ b/packages/stripe_android/android/build.gradle @@ -3,7 +3,7 @@ version '1.0-SNAPSHOT' buildscript { ext.kotlin_version = '1.8.0' - ext.stripe_version = '20.23.+' + ext.stripe_version = '20.25.+' repositories { google() diff --git a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt index 8416e5deb..c7a16a116 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardFormPlatformView.kt @@ -11,7 +11,7 @@ import com.facebook.react.uimanager.ThemedReactContext import com.reactnativestripesdk.* import com.reactnativestripesdk.utils.getIntOrNull import com.reactnativestripesdk.utils.getValOr -import com.stripe.android.databinding.CardMultilineWidgetBinding +import com.stripe.android.databinding.StripeCardMultilineWidgetBinding import com.stripe.android.databinding.StripeCardFormViewBinding import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel @@ -110,7 +110,7 @@ class StripeSdkCardFormPlatformView( result.success(null) } "requestFocus" -> { - val binding = CardMultilineWidgetBinding.bind(cardView.cardForm) + val binding = StripeCardMultilineWidgetBinding.bind(cardView.cardForm) binding.etCardNumber.requestFocus() val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); diff --git a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt index 1facb6fc1..ba4e9adad 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeSdkCardPlatformView.kt @@ -9,7 +9,7 @@ import com.facebook.react.uimanager.ThemedReactContext import com.reactnativestripesdk.* import com.reactnativestripesdk.utils.getIntOrNull import com.reactnativestripesdk.utils.getValOr -import com.stripe.android.databinding.CardInputWidgetBinding +import com.stripe.android.databinding.StripeCardInputWidgetBinding import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.platform.PlatformView @@ -56,7 +56,7 @@ class StripeSdkCardPlatformView( val value = ReadableMap(creationParams["cardDetails"] as Map) stripeSdkCardViewManager.setCardDetails(value, themedContext) - val binding = CardInputWidgetBinding.bind(cardView.mCardWidget) + val binding = StripeCardInputWidgetBinding.bind(cardView.mCardWidget) val number = getValOr(value, "number", null) val expirationYear = getIntOrNull(value, "expiryYear") val expirationMonth = getIntOrNull(value, "expiryMonth") @@ -127,7 +127,7 @@ class StripeSdkCardPlatformView( result.success(null) } "requestFocus" -> { - val binding = CardInputWidgetBinding.bind(cardView.mCardWidget) + val binding = StripeCardInputWidgetBinding.bind(cardView.mCardWidget) binding.cardNumberEditText.requestFocus() val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); diff --git a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt index f032b13bb..4475bd170 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/CardFieldView.kt @@ -33,7 +33,7 @@ import java.lang.Exception class CardFieldView(context: ThemedReactContext) : FrameLayout(context) { internal var mCardWidget: CardInputWidget = CardInputWidget(context) - private val cardInputWidgetBinding = CardInputWidgetBinding.bind(mCardWidget) + private val cardInputWidgetBinding = StripeCardInputWidgetBinding.bind(mCardWidget) val cardDetails: MutableMap = mutableMapOf("brand" to "", "last4" to "", "expiryMonth" to null, "expiryYear" to null, "postalCode" to "", "validNumber" to "Unknown", "validCVC" to "Unknown", "validExpiryDate" to "Unknown") var cardParams: PaymentMethodCreateParams.Card? = null var cardAddress: Address? = null diff --git a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt index 653c29f3a..6a69c2e30 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/pushprovisioning/AddToWalletButtonView.kt @@ -95,7 +95,7 @@ class AddToWalletButtonView(private val context: ThemedReactContext, private val } }) .centerCrop() - .override((widthOverride * scale).toInt(), (heightOverride * scale).toInt()) + .override((widthOverride * scale.toInt()), (heightOverride * scale.toInt())) .into(this) } }