Skip to content

Commit

Permalink
Update stripe-react-native to 0.18.1 to fix compilation errors in Xco…
Browse files Browse the repository at this point in the history
…de 14
  • Loading branch information
tsapeta committed Sep 9, 2022
1 parent 819418b commit 4376ff6
Show file tree
Hide file tree
Showing 44 changed files with 2,418 additions and 607 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ Package-specific changes not released in any SDK will be added here just before

### 📚 3rd party library updates

- Updated `@stripe/stripe-react-native` from `0.13.1` to `0.18.1`.

### 🛠 Breaking changes

### 🎉 New features
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,14 +15,15 @@ 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
import com.stripe.android.model.Address
import com.stripe.android.model.PaymentMethodCreateParams
import com.stripe.android.view.CardFormView
import com.stripe.android.view.CardInputListener
import host.exp.expoview.R

class CardFormView(context: ThemedReactContext) : FrameLayout(context) {
private var cardForm: CardFormView = CardFormView(context, null, R.style.StripeCardFormView_Borderless)
Expand Down Expand Up @@ -51,10 +53,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 +262,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 4376ff6

Please sign in to comment.