Skip to content

Commit

Permalink
Fix crash when no bank is selected in AddPaymentMethodActivity (#4579)
Browse files Browse the repository at this point in the history
  • Loading branch information
brnunes-stripe authored Feb 11, 2022
1 parent 4a29c26 commit ec1768e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [CHANGED] [4546](https://github.com/stripe/stripe-android/pull/4546) Update to kotlin 1.6
* [FIXED] [4560](https://github.com/stripe/stripe-android/pull/4560) Fix `cardValidCallback` being added multiple times in `CardInputWidget`.
* [FIXED] [4574](https://github.com/stripe/stripe-android/pull/4574) Take `postalCode` into account in `CardMultilineWidget` validation.
* [FIXED] [4579](https://github.com/stripe/stripe-android/pull/4579) Fix crash when no bank is selected in `AddPaymentMethodActivity`.
### PaymentSheet
* [FIXED] [4466](https://github.com/stripe/stripe-android/pull/4466) Fix issues when activities are lost on low resource phones.
* [FIXED] [4557](https://github.com/stripe/stripe-android/pull/4557) Add missing app info to some Stripe API requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ class AddFpxPaymentMethodTest {

@Test
fun launchFpxAndSelectBank() {
launchBankSelector()

// click on first bank in the list
onView(withId(R.id.bank_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())
)
}

@Test
fun launchFpxAndConfirmWithoutSelectingBank() {
launchBankSelector()

// confirm selection without selecting a bank
onView(withId(R.id.action_save)).perform(click())

// Nothing should happen as no bank was selected
}

private fun launchBankSelector() {
// launch FPX selection activity
onView(withId(R.id.examples)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(11, click())
Expand All @@ -46,10 +65,5 @@ class AddFpxPaymentMethodTest {
// click select payment method button
onView(withId(R.id.select_payment_method_button))
.perform(click())

// click on first bank in the list
onView(withId(R.id.bank_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ class AddNetbankingPaymentMethodTest {

@Test
fun launchNetbankingAndSelectBank() {
launchBankSelector()

// click on first bank in the list
onView(withId(R.id.bank_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())
)
}

@Test
fun launchNetbankingAndConfirmWithoutSelectingBank() {
launchBankSelector()

// confirm selection without selecting a bank
onView(withId(R.id.action_save)).perform(click())

// Nothing should happen as no bank was selected
}

private fun launchBankSelector() {
// launch Netbanking selection activity
onView(withId(R.id.examples)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(10, click())
Expand All @@ -52,10 +71,5 @@ class AddNetbankingPaymentMethodTest {
// click select payment method button
onView(withId(R.id.select_payment_method_button))
.perform(click())

// click on first bank in the list
onView(withId(R.id.bank_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.stripe.android.R
import com.stripe.android.databinding.BankListPaymentMethodBinding
import com.stripe.android.model.BankStatuses
Expand Down Expand Up @@ -36,11 +37,12 @@ internal class AddPaymentMethodFpxView @JvmOverloads internal constructor(

override val createParams: PaymentMethodCreateParams?
get() {
val fpxBank = FpxBank.values()[fpxAdapter.selectedPosition]

return PaymentMethodCreateParams.create(
PaymentMethodCreateParams.Fpx(bank = fpxBank.code)
)
return fpxAdapter.selectedPosition.takeIf { it != RecyclerView.NO_POSITION }?.let {
val fpxBank = FpxBank.values()[it]
PaymentMethodCreateParams.create(
PaymentMethodCreateParams.Fpx(bank = fpxBank.code)
)
}
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.AttributeSet
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.stripe.android.R
import com.stripe.android.databinding.BankListPaymentMethodBinding
import com.stripe.android.model.PaymentMethodCreateParams
Expand All @@ -25,11 +26,14 @@ internal class AddPaymentMethodNetbankingView @JvmOverloads internal constructor

override val createParams: PaymentMethodCreateParams?
get() {
val netbankingBank = NetbankingBank.values()[netbankingAdapter.selectedPosition]
return netbankingAdapter.selectedPosition.takeIf { it != RecyclerView.NO_POSITION }
?.let {
val netbankingBank = NetbankingBank.values()[netbankingAdapter.selectedPosition]

return PaymentMethodCreateParams.create(
PaymentMethodCreateParams.Netbanking(bank = netbankingBank.code)
)
return PaymentMethodCreateParams.create(
PaymentMethodCreateParams.Netbanking(bank = netbankingBank.code)
)
}
}

init {
Expand Down

0 comments on commit ec1768e

Please sign in to comment.