Reputation: 4281
I'm trying to accept payment but getting this error in callback of sdk.
Code:
val params = cardInputWidget.paymentMethodCreateParams
if (params != null) {
val confirmParams =
ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams(params, clientSecret)
stripe = Stripe(
applicationContext,
PaymentConfiguration.getInstance(applicationContext).publishableKey)
stripe.confirmPayment(this, confirmParams)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
stripe.onPaymentResult(requestCode, data, object : ApiResultCallback<PaymentIntentResult> {
override fun onSuccess(result: PaymentIntentResult) {
val paymentIntent = result.intent
val status = paymentIntent.status
if (status == StripeIntent.Status.Succeeded) {
val gson = GsonBuilder().setPrettyPrinting().create()
showToast("Payment succeeded " + gson.toJson(paymentIntent))
} else {
showToast("Payment Error: "+paymentIntent.lastPaymentError?.message ?: "")
}
}
override fun onError(e: Exception) {
showToast("Payment failed "+e.message)
}
})
}
onError is getting always called!
This is internal code of sdk:
Upvotes: 4
Views: 3395
Reputation: 476
You are using confirmPayment
method instead of confirmSetupIntent
method. One is used for confirming payment intents with client secret, and the other one is used for confirming setup intents with client secret. Checkout the stripe documentation for saving and reusing payment methods: https://stripe.com/docs/payments/save-and-reuse
Upvotes: 6