Skip to content
Advertisement

Stripe Saving Card from android/kotlin equivalent to react strpe.CreatePaymentMethod

We have implemented using react to get save card and getting payment method id successfully like this:

   const paymentMethodReq = await stripe.createPaymentMethod({
      type: "card",
      card: elements.getElement(CardNumberElement),
      billing_details: formData
    })

Above code is being used in reactjs, that’s working fine, but we are going through a trouble to implement same feature on android, we have not found anything for kotlin. we will attach customer and other thing later, we only want to get the payment method id to save the card, that is exactly what we have done on reactjs but not getting how to implement in kotlin.

Can anyone help me what you are using in kotlin for the same feature?

Advertisement

Answer

This is how you can create payment method in kotlin.

       val billingDetails: PaymentMethod.BillingDetails =
        PaymentMethod.BillingDetails.Builder().build()

       val metaData = HashMap<String, String>()
       metaData["createdVia"] = "android"
    
       val card: PaymentMethodCreateParams.Card = 
       binding.cardMultiWidget.paymentMethodCard!!

       val paymentMethodParams: PaymentMethodCreateParams =
       PaymentMethodCreateParams.create(card, billingDetails,
       metaData)

cardMultiWidget is the widget that stripe provides for android.

You can find out more about in the Stripe-Samples

and here is the official stripe-android documentation about the methods. You can find mostly under payments-core.

Advertisement