Skip to content

Commit

Permalink
[go] update stripe-react-native to 0.28.0 (expo#23035)
Browse files Browse the repository at this point in the history
# 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 `[email protected]`, `[email protected]` 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
  • Loading branch information
Kudo authored Jun 22, 2023
1 parent aedc98a commit 5ae19ef
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class CardFieldViewManager : SimpleViewManager<CardFieldView>() {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class CardFormViewManager : SimpleViewManager<CardFormView>() {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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 ?? "")
Expand All @@ -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 ?? ""
Expand All @@ -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)
}

*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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/",
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/bundledNativeModules.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5ae19ef

Please sign in to comment.