Skip to content

Commit

Permalink
[android][ios] Upgrade stripe-react-native to 0.19.0 (#19432)
Browse files Browse the repository at this point in the history
# Why

close ENG-6537

# How

- `et uvm -m @stripe/stripe-react-native -c 'v0.19.0'`
- backport native stripe version to old sdks' podspec and build.gradle
- [android] transform manually
  - remove `GooglePayButtonManager.kt`, `GooglePayButtonView.kt`
  - remove `GooglePayButtonManager()` in `StripeSdkPackage.kt`
  - revert `import host.exp.expoview.R` change in `CardFormView.kt`
- backport versioned code for stripe-android 20.12 breaking changes

## [Notable change] bump `compileSdkVersion` to 33 on android expo go

this is a hard requirement for stripe 0.19.0

- [notifications] fix related build error when `RemoteInput.getResultsFromIntent` returns null
- [webview] backport for build error: react-native-webview/react-native-webview@7f78f20
- [gesture-handler] backport for build error: software-mansion/react-native-gesture-handler@8d70e87

# 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.70.2`, `react@18.1.0` and other unsynced packages
  - `expo start`
3. test android/ios unversioned expo go with the local stripe example app.
4. there're many different test cases. i just did smoke test from the accepting payments by credit cards.

stripe test api keys: https://stripe.com/docs/keys
stripe test credit card: https://stripe.com/docs/testing
  • Loading branch information
Kudo committed Oct 10, 2022
1 parent e9bd9a9 commit afdb83b
Show file tree
Hide file tree
Showing 47 changed files with 1,441 additions and 542 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,7 @@ Package-specific changes not released in any SDK will be added here just before
### 📚 3rd party library updates

- Updated `react-native-safe-area-context` from `4.3.1` to `4.4.1`. ([#19055](https://github.com/expo/expo/pull/19401) by [@brentvatne](https://github.com/brentvatne))
- Updated `@stripe/stripe-react-native` from `0.13.1` to `0.18.1` on iOS. ([#19055](https://github.com/expo/expo/pull/19055) by [@tsapeta](https://github.com/tsapeta))
- Updated `@stripe/stripe-react-native` from `0.13.1` to `0.19.0`. ([#19055](https://github.com/expo/expo/pull/19055) by [@tsapeta](https://github.com/tsapeta), [#19432](https://github.com/expo/expo/pull/19432) by [@kudo](https://github.com/kudo))
- Updated `@shopify/flash-list` from `1.1.0` to `1.3.0`. ([#19317](https://github.com/expo/expo/pull/19317) by [@kudo](https://github.com/kudo))
- Updated `react-native-view-shot` from `3.3.0` to `3.4.0`. ([#19405](https://github.com/expo/expo/pull/19405) by [@douglowder](https://github.com/douglowder))
- Updated `react-native-webview` from `11.23.0` to `11.23.1`. ([#19375](https://github.com/expo/expo/pull/19375) by [@aleqsio](https://github.com/aleqsio))
Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion safeExtGet("compileSdkVersion", 31)
compileSdkVersion safeExtGet("compileSdkVersion", 33)

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Expand Up @@ -4,7 +4,7 @@ buildscript {
ext {
minSdkVersion = 21
targetSdkVersion = 31
compileSdkVersion = 31
compileSdkVersion = 33

dbFlowVersion = '4.2.4'
buildToolsVersion = '31.0.0'
Expand Down
9 changes: 5 additions & 4 deletions android/expoview/build.gradle
Expand Up @@ -110,7 +110,7 @@ repositories {
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 31)
compileSdkVersion safeExtGet("compileSdkVersion", 33)

// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
Expand Down Expand Up @@ -422,9 +422,10 @@ dependencies {
api 'com.github.troZee:ViewPager2:v1.0.6'

// stripe-react-native
implementation('com.stripe:stripe-android:20.5.+')
implementation('com.stripe:financial-connections:20.5.+')
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation('com.stripe:stripe-android:20.12.+')
implementation('com.stripe:financial-connections:20.12.+')
compileOnly 'com.stripe:stripe-android-issuing-push-provisioning:1.1.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
implementation 'com.google.android.material:material:1.3.0'

Expand Down
Expand Up @@ -10,6 +10,8 @@ import com.facebook.react.uimanager.events.EventDispatcher
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.getIntOrNull
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.getValOr
import com.stripe.android.databinding.BecsDebitWidgetBinding
import com.stripe.android.model.PaymentMethodCreateParams
import com.stripe.android.view.BecsDebitWidget
Expand Down
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Color
import android.graphics.Typeface
import android.os.Build
import android.text.Editable
import android.text.InputFilter
import android.text.TextWatcher
import android.util.Log
import android.widget.FrameLayout
Expand All @@ -16,6 +17,8 @@ import com.facebook.react.uimanager.events.EventDispatcher
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.*
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.mapCardBrand
import com.stripe.android.core.model.CountryCode
import com.stripe.android.core.model.CountryUtils
import com.stripe.android.databinding.CardInputWidgetBinding
Expand All @@ -25,7 +28,6 @@ import com.stripe.android.view.CardInputListener
import com.stripe.android.view.CardInputWidget
import com.stripe.android.view.CardValidCallback
import com.stripe.android.view.StripeEditText
import java.lang.Exception

class CardFieldView(context: ThemedReactContext) : FrameLayout(context) {
private var mCardWidget: CardInputWidget = CardInputWidget(context)
Expand Down Expand Up @@ -205,12 +207,11 @@ class CardFieldView(context: ThemedReactContext) : FrameLayout(context) {
* We can reliable assume that setPostalCodeEnabled is called before
* setCountryCode because of the order of the props in CardField.tsx
*/
fun setCountryCode(countryCode: String?) {
fun setCountryCode(countryString: String?) {
if (mCardWidget.postalCodeEnabled) {
val doesCountryUsePostalCode = CountryUtils.doesCountryUsePostalCode(
CountryCode.create(value = countryCode ?: LocaleListCompat.getAdjustedDefault()[0].country)
)
mCardWidget.postalCodeRequired = doesCountryUsePostalCode
val countryCode = CountryCode.create(value = countryString ?: LocaleListCompat.getAdjustedDefault()[0]?.country ?: "US")
mCardWidget.postalCodeRequired = CountryUtils.doesCountryUsePostalCode(countryCode)
setPostalCodeFilter(countryCode)
}
}

Expand Down Expand Up @@ -275,6 +276,7 @@ class CardFieldView(context: ThemedReactContext) : FrameLayout(context) {
cardDetails["validNumber"] = getCardValidationState(CardValidCallback.Fields.Number, cardInputWidgetBinding.cardNumberEditText)
cardDetails["validCVC"] = getCardValidationState(CardValidCallback.Fields.Cvc, cardInputWidgetBinding.cvcEditText)
cardDetails["validExpiryDate"] = getCardValidationState(CardValidCallback.Fields.Expiry, cardInputWidgetBinding.expiryDateEditText)
cardDetails["brand"] = mapCardBrand(cardInputWidgetBinding.cardNumberEditText.cardBrand)

if (isValid) {
onValidCardChange()
Expand Down Expand Up @@ -335,6 +337,26 @@ class CardFieldView(context: ThemedReactContext) : FrameLayout(context) {
})
}

private fun setPostalCodeFilter(countryCode: CountryCode) {
cardInputWidgetBinding.postalCodeEditText.filters = arrayOf(
*cardInputWidgetBinding.postalCodeEditText.filters,
createPostalCodeInputFilter(countryCode)
)
}

private fun createPostalCodeInputFilter(countryCode: CountryCode): InputFilter {
return InputFilter { charSequence, start, end, _, _, _ ->
for (i in start until end) {
val isValidCharacter = (countryCode == CountryCode.US && PostalCodeUtilities.isValidUsPostalCodeCharacter(charSequence[i])) ||
(countryCode != CountryCode.US && PostalCodeUtilities.isValidGlobalPostalCodeCharacter(charSequence[i]))
if (!isValidCharacter) {
return@InputFilter ""
}
}
return@InputFilter null
}
}

override fun requestLayout() {
super.requestLayout()
post(mLayoutRunnable)
Expand Down
Expand Up @@ -4,6 +4,7 @@ import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.Typeface
import android.os.Build
import android.text.InputFilter
import android.view.View
import android.view.View.OnFocusChangeListener
import android.widget.FrameLayout
Expand All @@ -14,6 +15,8 @@ import com.facebook.react.uimanager.events.EventDispatcher
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.*
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.mapCardBrand
import com.stripe.android.core.model.CountryCode
import com.stripe.android.databinding.CardMultilineWidgetBinding
import com.stripe.android.databinding.StripeCardFormViewBinding
Expand Down Expand Up @@ -51,10 +54,15 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
}

fun setDefaultValues(defaults: ReadableMap) {
defaults.getString("countryCode")?.let {
cardFormViewBinding.countryLayout.setSelectedCountryCode(CountryCode(it))
cardFormViewBinding.countryLayout.updateUiForCountryEntered(CountryCode(it))
setCountry(defaults.getString("countryCode"))
}

private fun setCountry(countryString: String?) {
if (countryString != null) {
cardFormViewBinding.countryLayout.setSelectedCountryCode(CountryCode(countryString))
cardFormViewBinding.countryLayout.updateUiForCountryEntered(CountryCode(countryString))
}
setPostalCodeFilter()
}

fun setPlaceHolders(value: ReadableMap) {
Expand Down Expand Up @@ -255,6 +263,29 @@ class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
}
}

private fun setPostalCodeFilter() {
cardFormViewBinding.postalCode.filters = arrayOf(
*cardFormViewBinding.postalCode.filters,
createPostalCodeInputFilter()
)
}

private fun createPostalCodeInputFilter(): InputFilter {
return InputFilter { charSequence, start, end, _, _, _ ->
if (cardFormViewBinding.countryLayout.getSelectedCountryCode() == CountryCode.US) {
// Rely on CardFormView's built-in US postal code filter
return@InputFilter null
}

for (i in start until end) {
if (!PostalCodeUtilities.isValidGlobalPostalCodeCharacter(charSequence[i])) {
return@InputFilter ""
}
}
return@InputFilter null
}
}

override fun requestLayout() {
super.requestLayout()
post(mLayoutRunnable)
Expand Down
Expand Up @@ -9,6 +9,11 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.*
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.createError
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.createResult
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.mapFromPaymentIntentResult
import versioned.host.exp.exponent.modules.api.components.reactnativestripesdk.utils.mapFromSetupIntentResult
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.SetupIntent
import com.stripe.android.model.StripeIntent
Expand All @@ -19,6 +24,7 @@ import com.stripe.android.payments.bankaccount.navigation.CollectBankAccountResu
class CollectBankAccountLauncherFragment(
private val context: ReactApplicationContext,
private val publishableKey: String,
private val stripeAccountId: String?,
private val clientSecret: String,
private val isPaymentIntent: Boolean,
private val collectParams: CollectBankAccountConfiguration.USBankAccount,
Expand All @@ -43,12 +49,14 @@ class CollectBankAccountLauncherFragment(
if (isPaymentIntent) {
collectBankAccountLauncher.presentWithPaymentIntent(
publishableKey,
stripeAccountId,
clientSecret,
collectParams
)
} else {
collectBankAccountLauncher.presentWithSetupIntent(
publishableKey,
stripeAccountId,
clientSecret,
collectParams
)
Expand Down Expand Up @@ -78,7 +86,11 @@ class CollectBankAccountLauncherFragment(
promise.resolve(createError(ErrorType.Failed.toString(), result.error))
}
}
(context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
removeFragment(context)
}
}

companion object {
const val TAG = "collect_bank_account_launcher_fragment"
}
}

0 comments on commit afdb83b

Please sign in to comment.