Stripe Integration in Android (React Native/Kotlin/Java) — Updated

A complete guide for integrating Stripe, mainly cards, with updated payment method in android with React Native, Kotlin and Java.

Story behind -

React Native example

Stripe card dialog after integrating in React Native code base
"dependencies": {
...
"tipsi-stripe":"^9.0.0"
}
import stripe from 'tipsi-stripe'
stripe.setOptions({
publishableKey: 'pk_test_publishableUniqueKey'
})
const stripeCardDialog = () => { return stripe.paymentRequestWithCardForm()
.then((stripeTokenInfo) => {
console.log("[SUCCESS] Stripe Token ID: ", stripeTokenInfo.id)
}).catch((error) => {
console.log("[ERROR] User Cancelled the action")
})
}

Kotlin example

dependencies {
...

def stripeVersion = "16.1.1"
implementation "com.stripe:stripe-android:$stripeVersion"
}
android {
...
buildTypes.each {
...
it.resValue 'string', 'stripe_pk', 'pk_test_publishableUniqueKey'
}
}
<com.stripe.android.view.CardInputWidget
android:id="@+id/widget_add_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/dimen_4"
android:padding="@dimen/dimen_4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
private var stripe: Stripe? = null
private fun initStripe() {
val stripeKey: String = getString(R.string.stripe_pk)
stripe = Stripe(requireContext(), stripeKey)
}

Java example

private void initStripe() {
String stripeKey = getString(R.string.stripepk);
stripe = new Stripe(context, stripeKey);
}

Keep these in mind -

Software Engineer | Ex-DSC Lead | Reader & Writer | Researcher | LinkedIn/Github/GitLab/FB/IG: thenishchalraj

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store