Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deleting saved payment methods #4108

Merged
merged 21 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4982,8 +4982,9 @@ public abstract interface class com/stripe/android/paymentsheet/PaymentOptionCal
}

public final class com/stripe/android/paymentsheet/PaymentOptionsViewModel_Factory_MembersInjector : dagger/MembersInjector {
public fun <init> (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Ldagger/MembersInjector;
public fun <init> (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)V
public static fun create (Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;Ljavax/inject/Provider;)Ldagger/MembersInjector;
public static fun injectCustomerRepository (Lcom/stripe/android/paymentsheet/PaymentOptionsViewModel$Factory;Lcom/stripe/android/paymentsheet/repositories/CustomerRepository;)V
public static fun injectEventReporter (Lcom/stripe/android/paymentsheet/PaymentOptionsViewModel$Factory;Lcom/stripe/android/paymentsheet/analytics/EventReporter;)V
public fun injectMembers (Lcom/stripe/android/paymentsheet/PaymentOptionsViewModel$Factory;)V
public synthetic fun injectMembers (Ljava/lang/Object;)V
Expand Down
10 changes: 10 additions & 0 deletions payments-core/res/drawable/stripe_ic_delete_symbol.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="20dp"
android:viewportHeight="22"
android:viewportWidth="22"
android:width="20dp">
<path
android:fillColor="#FF453A"
android:fillType="evenOdd"
android:pathData="M10.8076,21.6152C4.8892,21.6152 0,16.7261 0,10.8076C0,4.8892 4.8809,0 10.7993,0C16.7178,0 21.6152,4.8892 21.6152,10.8076C21.6152,16.7261 16.7261,21.6152 10.8076,21.6152ZM6.1011,11.6128H15.4976C16.0288,11.6128 16.394,11.3306 16.394,10.8242C16.394,10.3013 16.0537,10.0024 15.4976,10.0024H6.1011C5.5532,10.0024 5.1963,10.3013 5.1963,10.8242C5.1963,11.3306 5.5781,11.6128 6.1011,11.6128Z" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:width="14dp">
<path
android:pathData="M3.0728,5.6L7.1364,1.5364C7.4879,1.1849 7.4879,0.6151 7.1364,0.2636C6.7849,-0.0879 6.2151,-0.0879 5.8636,0.2636L0.2636,5.8636C-0.0879,6.2151 -0.0879,6.7849 0.2636,7.1364L5.8636,12.7364C6.2151,13.0879 6.7849,13.0879 7.1364,12.7364C7.4879,12.3849 7.4879,11.8151 7.1364,11.4636L3.0728,7.4H13.1C13.5971,7.4 14,6.9971 14,6.5C14,6.0029 13.5971,5.6 13.1,5.6H3.0728Z"
android:fillColor="@color/stripe_paymentsheet_toolbar_button_color"
android:fillColor="@color/stripe_paymentsheet_toolbar_items_color"
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
android:fillAlpha="0.4"
android:fillType="evenOdd" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:width="14dp">
<path
android:pathData="M3.0728,5.6L7.1364,1.5364C7.4879,1.1849 7.4879,0.6151 7.1364,0.2636C6.7849,-0.0879 6.2151,-0.0879 5.8636,0.2636L0.2636,5.8636C-0.0879,6.2151 -0.0879,6.7849 0.2636,7.1364L5.8636,12.7364C6.2151,13.0879 6.7849,13.0879 7.1364,12.7364C7.4879,12.3849 7.4879,11.8151 7.1364,11.4636L3.0728,7.4H13.1C13.5971,7.4 14,6.9971 14,6.5C14,6.0029 13.5971,5.6 13.1,5.6H3.0728Z"
android:fillColor="@color/stripe_paymentsheet_toolbar_button_color"
android:fillColor="@color/stripe_paymentsheet_toolbar_items_color"
android:fillAlpha="0.6"
android:fillType="evenOdd" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:viewportHeight="12">
<path
android:pathData="M7.4142,6L11.7071,10.2929C12.0976,10.6834 12.0976,11.3166 11.7071,11.7071C11.3166,12.0976 10.6834,12.0976 10.2929,11.7071L6,7.4142L1.7071,11.7071C1.3166,12.0976 0.6834,12.0976 0.2929,11.7071C-0.0976,11.3166 -0.0976,10.6834 0.2929,10.2929L4.5858,6L0.2929,1.7071C-0.0976,1.3166 -0.0976,0.6834 0.2929,0.2929C0.6834,-0.0976 1.3166,-0.0976 1.7071,0.2929L6,4.5858L10.2929,0.2929C10.6834,-0.0976 11.3166,-0.0976 11.7071,0.2929C12.0976,0.6834 12.0976,1.3166 11.7071,1.7071L7.4142,6Z"
android:fillColor="@color/stripe_paymentsheet_toolbar_button_color"
android:fillColor="@color/stripe_paymentsheet_toolbar_items_color"
android:fillAlpha="0.4"
android:fillType="evenOdd" />
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:viewportHeight="12">
<path
android:pathData="M7.4142,6L11.7071,10.2929C12.0976,10.6834 12.0976,11.3166 11.7071,11.7071C11.3166,12.0976 10.6834,12.0976 10.2929,11.7071L6,7.4142L1.7071,11.7071C1.3166,12.0976 0.6834,12.0976 0.2929,11.7071C-0.0976,11.3166 -0.0976,10.6834 0.2929,10.2929L4.5858,6L0.2929,1.7071C-0.0976,1.3166 -0.0976,0.6834 0.2929,0.2929C0.6834,-0.0976 1.3166,-0.0976 1.7071,0.2929L6,4.5858L10.2929,0.2929C10.6834,-0.0976 11.3166,-0.0976 11.7071,0.2929C12.0976,0.6834 12.0976,1.3166 11.7071,1.7071L7.4142,6Z"
android:fillColor="@color/stripe_paymentsheet_toolbar_button_color"
android:fillColor="@color/stripe_paymentsheet_toolbar_items_color"
android:fillAlpha="0.6"
android:fillType="evenOdd" />
</vector>
1 change: 0 additions & 1 deletion payments-core/res/layout/activity_payment_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

<ImageView
android:id="@+id/check_icon"
style="@style/StripePaymentOptionItemCardCheck"
style="@style/StripePaymentOptionItemCheckIcon"
android:duplicateParentState="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@

<ImageView
android:id="@+id/check_icon"
style="@style/StripePaymentOptionItemCardCheck"
style="@style/StripePaymentOptionItemCheckIcon"
android:duplicateParentState="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/delete_icon"
style="@style/StripePaymentOptionItemDeleteIcon"
android:duplicateParentState="true"
android:layout_width="@dimen/stripe_paymentsheet_minimum_tap_size"
android:layout_height="@dimen/stripe_paymentsheet_minimum_tap_size"
android:contentDescription="@null"
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/edit"
android:title="@string/edit"
app:showAsAction="always" />
</menu>
2 changes: 1 addition & 1 deletion payments-core/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<color name="stripe_paymentsheet_elements_background_default">#474747</color>
<color name="stripe_paymentsheet_elements_background_disabled">#474747</color>
<color name="stripe_paymentsheet_form_border">#3Dffffff</color>
<color name="stripe_paymentsheet_toolbar_button_color">#FFFFFF</color>
<color name="stripe_paymentsheet_toolbar_items_color">#FFFFFF</color>
<color name="stripe_paymentsheet_add_payment_method_form_stroke">#3Dffffff</color>
<color name="stripe_paymentsheet_add_pm_card_unselected_stroke">#1FFFFFFF</color>
<color name="stripe_paymentsheet_add_pm_card_selected_stroke">#DEFFFFFF</color>
Expand Down
2 changes: 1 addition & 1 deletion payments-core/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<color name="stripe_paymentsheet_elements_background_disabled">#F8F8F8</color>
<color name="stripe_paymentsheet_textinputlayout_hint">#661A1A1A</color>
<color name="stripe_paymentsheet_textinput_color">#E61A1A1A</color>
<color name="stripe_paymentsheet_toolbar_button_color">#000000</color>
<color name="stripe_paymentsheet_toolbar_items_color">#000000</color>
<color name="stripe_paymentsheet_add_payment_method_form_stroke">@android:color/transparent
</color>
<color name="stripe_paymentsheet_add_pm_card_unselected_stroke">#E7E7E7</color>
Expand Down
1 change: 1 addition & 0 deletions payments-core/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<dimen name="stripe_card_widget_progress_size">12dp</dimen>

<!-- PaymentSheet -->
<dimen name="stripe_paymentsheet_minimum_tap_size">48dp</dimen>
<dimen name="stripe_paymentsheet_paymentmethod_icon_height">64dp</dimen>
<dimen name="stripe_paymentsheet_paymentmethod_icon_width">100dp</dimen>
<dimen name="stripe_paymentsheet_paymentmethod_icon_radius">6dp</dimen>
Expand Down
23 changes: 12 additions & 11 deletions payments-core/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

<style name="Stripe.CardInputWidget.EditText" parent="Stripe.Base.CardInputWidget.EditText" />

<style name="Stripe.Base.CardInputWidget.TextInputLayout" parent="Widget.Design.TextInputLayout"></style>
<style name="Stripe.Base.CardInputWidget.TextInputLayout" parent="Widget.Design.TextInputLayout" />

<style name="Stripe.CardInputWidget.TextInputLayout" parent="Stripe.Base.CardInputWidget.TextInputLayout" />

<style name="Stripe.Base.CardMultilineWidget.TextInputLayout" parent="Widget.Design.TextInputLayout"></style>
<style name="Stripe.Base.CardMultilineWidget.TextInputLayout" parent="Widget.Design.TextInputLayout" />

<style name="Stripe.CardMultilineWidget.TextInputLayout" parent="Stripe.Base.CardMultilineWidget.TextInputLayout" />

Expand Down Expand Up @@ -81,15 +81,23 @@
<item name="android:layout_gravity">center</item>
</style>

<style name="StripePaymentOptionItemCardCheck">
<style name="StripePaymentOptionItemCheckIcon">
<item name="android:visibility">gone</item>
<item name="android:src">@drawable/stripe_ic_check_circle</item>

<!-- modify the bottom and end layout to correctly position the check -->
<item name="android:layout_marginBottom">11dp</item>
<item name="android:paddingEnd">-2dp</item>
</style>

<style name="StripePaymentOptionItemDeleteIcon">
<item name="android:visibility">gone</item>
<item name="android:src">@drawable/stripe_ic_delete_symbol</item>
<!-- modify the bottom and end layout to correctly position the icon -->
<item name="android:paddingBottom">24dp</item>
<item name="android:paddingEnd">-24dp</item>
<item name="android:scaleType">center</item>
</style>

<style name="StripeAddPaymentMethodItemCard">
<item name="android:layout_width">@dimen/stripe_paymentsheet_add_pm_card_width</item>
<item name="android:layout_height">@dimen/stripe_paymentsheet_add_pm_card_height</item>
Expand Down Expand Up @@ -213,13 +221,6 @@
</item>
</style>

<style name="StripePaymentSheetToolbar">
<item name="android:paddingTop">16dp</item>
<item name="android:paddingStart">@dimen/stripe_paymentsheet_outer_spacing_horizontal</item>
<item name="android:paddingEnd">@dimen/stripe_paymentsheet_outer_spacing_horizontal</item>
<item name="android:layout_marginBottom">12dp</item>
</style>

<style name="StripeCardFormView">
<item name="cardFormStyle">standard</item>
</style>
Expand Down
1 change: 1 addition & 0 deletions payments-core/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<item name="windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="colorSurface">@color/stripe_paymentsheet_background</item>
<item name="actionMenuTextColor">@color/stripe_paymentsheet_toolbar_items_color</item>
</style>

<style name="StripePaymentSheetDefaultTheme" parent="StripePaymentSheetBaseTheme" />
Expand Down
11 changes: 11 additions & 0 deletions payments-core/res/values/totranslate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="edit">Edit</string>
<string name="done">Done</string>
<string name="remove">Remove</string>
<string name="cancel">Cancel</string>
<!-- Title for a dialog confirming the user's intent to delete a saved payment method. -->
<string name="stripe_paymentsheet_remove_pm">Remove %s</string>
<!-- Details of a saved bank account. E.g. 'Bank account ending in 4242' -->
<string name="bank_account_ending_in">Bank account ending in %s</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.stripe.android.paymentsheet

import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.stripe.android.R
import com.stripe.android.databinding.FragmentPaymentsheetPaymentMethodsListBinding
import com.stripe.android.model.PaymentMethod
import com.stripe.android.paymentsheet.analytics.EventReporter
import com.stripe.android.paymentsheet.model.FragmentConfig
import com.stripe.android.paymentsheet.model.PaymentSelection
import com.stripe.android.paymentsheet.model.SupportedPaymentMethod
import com.stripe.android.paymentsheet.ui.BaseSheetActivity
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel

Expand All @@ -21,27 +29,54 @@ internal abstract class BasePaymentMethodsListFragment(
abstract val sheetViewModel: BaseSheetViewModel<*>

protected lateinit var config: FragmentConfig
private lateinit var adapter: PaymentOptionsAdapter

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

override fun onCreateView(
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val nullableConfig = arguments?.getParcelable<FragmentConfig>(
BaseSheetActivity.EXTRA_FRAGMENT_CONFIG
)
if (nullableConfig == null) {
sheetViewModel.onFatal(
IllegalArgumentException("Failed to start existing payment options fragment.")
)
return
return null
}

this.config = nullableConfig

setHasOptionsMenu(config.paymentMethods.isNotEmpty())

return super.onCreateView(inflater, container, savedInstanceState)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setupRecyclerView(FragmentPaymentsheetPaymentMethodsListBinding.bind(view))

eventReporter.onShowExistingPaymentOptions()
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
inflater.inflate(R.menu.paymentsheet_payment_methods_list, menu)
super.onCreateOptionsMenu(menu, inflater)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.edit -> {
adapter.toggleEditing()
item.setTitle(if (adapter.isEditing) R.string.done else R.string.edit)
sheetViewModel.setEditing(adapter.isEditing)
true
}
else -> super.onOptionsItemSelected(item)
}
}

private fun setupRecyclerView(viewBinding: FragmentPaymentsheetPaymentMethodsListBinding) {
val layoutManager = object : LinearLayoutManager(
activity,
Expand All @@ -57,9 +92,10 @@ internal abstract class BasePaymentMethodsListFragment(
viewBinding.recycler.layoutManager = it
}

val adapter = PaymentOptionsAdapter(
adapter = PaymentOptionsAdapter(
canClickSelectedItem,
paymentOptionSelectedListener = ::onPaymentOptionSelected,
paymentMethodDeleteListener = ::deletePaymentMethod,
addCardClickListener = {
transitionToAddPaymentMethod()
}
Expand All @@ -83,4 +119,44 @@ internal abstract class BasePaymentMethodsListFragment(
) {
sheetViewModel.updateSelection(paymentSelection)
}

private fun deletePaymentMethod(item: PaymentOptionsAdapter.Item.SavedPaymentMethod) =
activity?.let {
brnunes-stripe marked this conversation as resolved.
Show resolved Hide resolved
AlertDialog.Builder(it)
.setTitle(
resources.getString(
R.string.stripe_paymentsheet_remove_pm,
SupportedPaymentMethod.fromCode(item.paymentMethod.type?.code)
?.run {
resources.getString(
displayNameResource
)
}
)
)
.setMessage(item.paymentMethod.getDescription())
.setCancelable(true)
.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog.dismiss()
}
.setPositiveButton(R.string.remove) { _, _ ->
adapter.removeItem(item)
sheetViewModel.removePaymentMethod(item.paymentMethod)
}
.create()
.show()
}

fun PaymentMethod.getDescription() = when (type) {
PaymentMethod.Type.Card -> resources.getString(
R.string.card_ending_in,
card?.brand,
card?.last4
)
PaymentMethod.Type.SepaDebit -> resources.getString(
R.string.bank_account_ending_in,
sepaDebit?.last4
)
else -> ""
}
}
Loading