0

I am working on integrating Stripe in our app. I want to add and accept cards through either a DialogFragment or an Activity with a custom layout instead of the Stripe-provided activities. I know I can use the provided views like CardInputWidget individually to build a UI, and I am successful in creating a DialogFragment that can take input for card information and perform validation accordingly.

But the problem is in setting up a flow to get results from the DialogFragment. Stripe uses onActivityResult to know whether the payment session was successful or not in adding a card. Is there a workaround to do this in my DialogFragment? If not, then how can I create an Activity with a custom layout to handle all this?

Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32
  • Abdul, you don't really need onActivityResult in this case; all you need is to 1. Create a payment method with `PaymentMethodCreateParams.Card` with the data you've collected in your custom form 2. confirm the paymentIntent call `confirmPayment` with client secret and the payment method created at 1. This could all be called in an event listener than the activityResult callback – wsw Feb 03 '20 at 06:29
  • how we could provide custome UI for strip – العبد Jul 11 '21 at 10:13

1 Answers1

1

You can use onActivityResult() in Fragments too (it also applies to DialogFragment).

class CardFragment : Fragment() {

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        
        if (requestCode == 12345) doSomething()
    }
}

Further info in this thread.

MateVojts
  • 66
  • 1
  • 5