This repository provides an implementation of Stripe Payment using Kotlin Multiplatform Mobile (KMM). It supports multiple payment methods, including iDEAL, Card, UPI, and CashApp.
- Initialize Stripe SDK with a publishable key
- Create Payment Methods for different payment options
- Confirm Payment and handle next actions
- Support for multiple payment methods (Card, iDEAL, UPI, CashApp)
-
Add Dependencies
Add the Stripe KMM dependency in yourshared
module'sbuild.gradle.kts
undercommonMain
:kotlin { sourceSets { commonMain { dependencies { implementation("io.github.qburst.stripekmm:<version>") } } } }
-
Add Shared Dependency
- Ensure the shared module dependency is properly set up in your iOS project
- The shared module containing the Stripe KMM implementation will be automatically available
-
Add Swift Package
- Open your iOS project in Xcode
- Go to File → Add Package Dependencies
- Add
SwiftKMMStripeKit
- Click on "Add Package"
Before making any payments, initialize the Stripe SDK with your publishable key:
val stripe = ProvideStripeSdk()
val initialiseParams = InitialiseParams(
publishableKey = "<your_publishable_key>",
appInfo = AppInfo(
name = "<your_app_name>",
version = "<your_app_version>",
partnerId = "<your_partner_id>",
url = "<your_app_url>",
)
)
// Initialize Stripe
CoroutineScope(Dispatchers.Default).launch {
stripe.initialise(initialiseParams)
}
Before proceeding with payment, collect user billing details:
val billingDetails = BillingDetails(
name = "<customer_name>",
email = "<customer_email>",
phone = "<customer_phone>"
)
The app provides different payment methods. The user selects one from:
- iDEAL
- Card
- UPI
- CashApp
var selectedMethod by remember { mutableStateOf("") }
Once the user provides the necessary details, create the payment method:
CoroutineScope(Dispatchers.Default).launch {
stripe.createPaymentMethod(
params = when(selectedMethod) {
"Ideal" -> {
CreateParams.IdealParams(
paymentMethodData = CreateParams.PaymentMethodDataIdeal(
bankName = "<ideal_bank_name>",
billingDetails = billingDetails
)
)
}
"Card" -> {
CreateParams.CardParamsWithToken(
paymentMethodData = CreateParams.PaymentMethodDataWithToken(
token = "<card_token>",
billingDetails = billingDetails
)
)
}
"Upi" -> {
CreateParams.UpiParams(
paymentMethodData = CreateParams.PaymentMethodDataUpi(
vpa = "<upi_vpa>",
billingDetails = billingDetails
)
)
}
"CashApp" -> {
CreateParams.CashAppParams(
paymentMethodData = CreateParams.PaymentMethodDataCashApp(
billingDetails = billingDetails
)
)
}
else -> throw IllegalStateException("Invalid payment method selected")
},
options = CreateOptions(FutureUsage.OFF_SESSION),
onSuccess = { result ->
println("Payment Method Created: $result")
},
onError = { error ->
println("Error: $error")
}
)
}
Once a payment method is created, confirm the payment:
CoroutineScope(Dispatchers.Default).launch {
stripe.confirmPayment(
paymentIntentClientSecret = "<payment_intent_client_secret>",
params = ConfirmParams.CardParamsWithToken(
paymentMethodData = ConfirmParams.PaymentMethodDataWithToken(
token = "<card_token>",
billingDetails = billingDetails
)
),
options = CreateOptions(FutureUsage.OFF_SESSION),
onSuccess = { result ->
println("Payment Confirmed: $result")
},
onError = { error ->
println("Error: $error")
}
)
}
Sometimes, additional steps are required for authentication (e.g., 3D Secure). In such cases, handle next actions:
CoroutineScope(Dispatchers.Default).launch {
stripe.handleNextAction(
paymentIntentClientSecret = "<payment_intent_client_secret>",
returnURL = "<your_return_url>",
onSuccess = { result ->
println("Next Action Handled: $result")
},
onError = { error ->
println("Error: $error")
}
)
}
You can customize the following parameters:
- Billing Details (
BillingDetails(name, email, phone)
) - Payment Options (
CreateOptions(FutureUsage.OFF_SESSION)
) - Return URL (
<your_return_url>
) - Publishable Key (
<your_publishable_key>
)
- Ensure you replace placeholders (
<your_publishable_key>
,<payment_intent_client_secret>
,<your_return_url>
) with your actual credentials - Test using Stripe Test Cards from Stripe Docs
- You must handle 3D Secure authentication (if required)
This project is licensed under the MIT License.
For issues and support, open an issue on the repository or check Stripe Documentation: