stripe / stripe-android

Stripe Android SDK
https://stripe.com/docs/mobile/android
MIT License
1.26k stars 640 forks source link

Adding a card / payment method in Android Compose #4226

Closed ilazakis closed 3 months ago

ilazakis commented 2 years ago

Hi, I'm looking for the currently proposed way to add / update payment methods (cards) when using @Composables.

I am effectively looking for the equivalent of STPAddCardViewController in iOS for Compose based apps, a built-in UI that captures all info within the Stripe SDK / UI and only returns a payment method id.

I think I'm looking for the Compose equivalent of CardInputWidget?

Context: I need to capture payment info for later use, not an on-demand payment.

Something like:

@Composable
fun MyAddCardUI() {
    SomeStripeAddCardComposeUI(onCardAdded = {...})
}
michelleb-stripe commented 2 years ago

@ilazakis We do not yet have a compose only version of our Card widgets, but have it in our backlog.

We recommend using CardFormView which can be used from compose as describe here. CardInputWidget is in maintenance mode and is not receiving new features, only major bug fixes.

Let us know if we can help any further.

ilazakis commented 2 years ago

Thank you @michelleb-stripe!

With regards to compose compatibility, I already had a view wrapped up like this, was just wondering about a compose equivalent; I will keep an eye on the release schedule to update it when the time comes.

With regards to the actual Stripe UI used, CardFormView seems to only be validating cards, not creating a PaymentMethod using that card. I would like the latter, the Android equivalent of STPAddCardViewController, which has a payment method added callback, not just a is this card a valid one callback. Does that make sense?

Thanks!

aliriaz-stripe commented 2 years ago

CardFormView seems to only be validating cards, not creating a PaymentMethod using that card

@ilazakis CardFormView does allow you to create a PaymentMethod, you have to manually call the createPaymentMethod() function but CardFormView collects the payment method parameters for you to pass to that function.

ilazakis commented 2 years ago

Thanks @aliriaz-stripe!

We recommend using CardFormView which can be used from compose as describe here.

@michelleb-stripe I used CardFormView per your recommendation above, but it looks like that component only gives one access to CardParams, not PaymentMethodCreateParams, which is what createPaymentMethod() requires, per @aliriaz-stripe's comment above.

I'd be more than happy to use CardParams to construct the required PaymentMethodCreateParams manually, but:

  1. At that point, customer / card PII is escaping Stripe's code, potentially breaking PCI compliance assumptions?
  2. The PaymentMethodCreateParams constructor is marked as internal i.e. inaccessible to code not belonging to Stripe

CardInputWidget is in maintenance mode and is not receiving new features, only major bug fixes.

CardInputWidget does provide direct access to PaymentMethodCreateParams, so not sure how to proceed without ignoring your recommendation to not use it. Hopefully, I've just missed something 😃

EDIT: It looks like what I was missing was the publicly available factory methods of PaymentMethodCreateParams, specifically createCard.

That said, CardFormView still lacks a lot of functionality until it catches up with CardInputWidget e.g. setting up a Locale manually and ignoring country selection / postcode inputs.

Thanks both for your help! 👍

michelleb-stripe commented 2 years ago

@ilazakis Glad you were able to get that working.

I added your request for setting up the locale manually and ignoring country selection / postcode inputs to our backlog. We will provide updates as we work on it.

ilazakis commented 2 years ago

Thank you @michelleb-stripe! I will be monitoring this issue for updates 👍

ColtonIdle commented 2 years ago

Just want to say that I'm also looking for better out of the box support for stripe + compose. As of right now I have a bug in my project (due to downstream dependencies) that prevents us from using a composable AndroidView. We're considering just building a library that will end up wrapping it, but as of right now I am just trying to build a form by myself to collect CC info. Which isn't actually too terrible, I just don't know how to take the info from here

Screen Shot 2021-11-12 at 12 48 20 AM

and convert it into a PaymentMethod

Edit: Looks like the simplest way I could figure out how to do this was like this

val paymentMethod = stripe?.createPaymentMethod(
                                PaymentMethodCreateParams.createCard(
                                    CardParams(
                                        "4242424242424242",
                                        1,
                                        2024,
                                        "211",
                                        "Name",
                                        null,
                                        null,
                                        null
                                    )
                                )
                            )
                            CustomerSession.getInstance().attachPaymentMethod(paymentMethod?.id.toString(), object : CustomerSession.PaymentMethodRetrievalListener 
samhorne commented 1 year ago

Hi @michelleb-stripe @michelleb-stripe can we get an update on where this is in the backlog?

ColtonIdle commented 1 year ago

I could have sworn that they did release some compose stuff for stripe. in my case, i just built everything by hand.

martymiller commented 1 year ago

This was opened in 2021 and we still don't have a Compose version of CardInputWidget?

jameswoo-stripe commented 1 year ago

@ColtonIdle Thank you for sharing some information about your integration. I see in the image you posted that you are building your own payment method collection form. Have you considered using PaymentSheet? If not, could you describe why you haven't?

Unfortunately, we don't have any future plans to migrate CardInputWidget or similar to compose at the moment.

ColtonIdle commented 1 year ago

@jameswoo-stripe I honestly didn't know that was an option. I felt like when I integrated stripe into my app over a year ago I found it tough to figure out what options were available to me. Our two contraints were: 1. we wanted it to be contained in our own activity (we took a signle activity architecture approach) 2. use jetpack compose

ill take a look at payment sheet

jaynewstrom-stripe commented 3 months ago

We don't have plans to add compose support for CardInputWidget. We do have first class support for compose with PaymentSheet.

ColtonIdle commented 2 months ago

Thanks! Hopefully one day I have to use stripe again and I'll have this as a starting off point 😅