У меня проблема с Stripe API на Android. Я пытаюсь добавить карту, и до сих пор, если вы делаете успешную карту, все работает отлично. Если вы добавляете карточку (которая должна дать сбой), это приводит к полному приложению cra sh.
. Я следовал полосовым инструкциям, как это сделать. Но я не могу поймать, как только это произойдет.
private fun createCardContent() {
try{
creditcardViewModel.requestStatusLiveData.postValue(NetworkState.LOADING)
val cardMy = com.stripe.android.model.Card.create(
cardModel.cardNumber,
cardModel.expMonth,
cardModel.expYear,
cardModel.cCV
)
if(cardMy.validateCard()){
val owner = cardModel.cardOwner
val billingDetails = PaymentMethod.BillingDetails(null, null, owner, null)
creditcardViewModel.stripeSetupIntent.value?.let {
val paymentMethodParams = PaymentMethodCreateParams.create(cardMy.toPaymentMethodParamsCard(),billingDetails,null)
val confirmParams = ConfirmSetupIntentParams.create(paymentMethodParams, it.client_secret)
try {
stripe.confirmSetupIntent(this, confirmParams)
// it gets till here, and then crashes
}catch(api: APIException){
showDialogError(getString(R.string.card_error_general))
}
}
}else{
creditcardViewModel.requestStatusLiveData.postValue(NetworkState.SUCCESSFUL)
showDialogError(getString(R.string.card_error_general))
}
}catch(e:IOException){
showDialogError(getString(R.string.card_error_general))
}
}
Я должен получить onError
catch (в этой функции, но ничего)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
stripe.onSetupResult(requestCode, data, object : ApiResultCallback<SetupIntentResult> {
override fun onError(e: Exception) {
showDialogError(getString(R.string.card_error_general))
creditcardViewModel.requestStatusLiveData.postValue(NetworkState.FAILED)
}
override fun onSuccess(result: SetupIntentResult) {
val setupIntent = result.intent
val status = setupIntent.status
if (status == StripeIntent.Status.Succeeded) {
creditcardViewModel.requestStatusLiveData.postValue(NetworkState.SUCCESSFUL)
notificationViewModel.insertNotification(
NotificationModel(
GlobalConstants.NotificationCases.CARD_ADDED,
Date()
)
)
val accountFragment = parentFragment as AccountFragment
accountFragment.returnChildFragment()
} else if (status == StripeIntent.Status.RequiresPaymentMethod) {
showDialogError(getString(R.string.card_error_general))
creditcardViewModel.requestStatusLiveData.postValue(NetworkState.FAILED)
logd("StripeIntent", "setup-failed")
}
}
})
Это ошибка, которую я получаю при вставке полосы в данной тестовой версии 4000 0000 0000 9995
2020-03-12 13:09:13.096 11288-11406/com.example.testableE/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-6
Process: com.example.testableE, PID: 11288
java.lang.RuntimeException: Request-id: req_Qdd21qBCr0ds33199v
com.stripe.android.exception.APIException: Your card has insufficient funds.
at android.os.Parcel.writeException(Parcel.java:1779)
at com.stripe.android.PaymentController$Result.writeToParcel(Unknown Source:24)
at android.os.Parcel.writeParcelable(Parcel.java:1683)
at android.os.Parcel.writeValue(Parcel.java:1589)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:875)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
at android.os.Bundle.writeToParcel(Bundle.java:1233)
at android.os.Parcel.writeBundle(Parcel.java:915)
at android.content.Intent.writeToParcel(Intent.java:9973)
at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3730)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1671)
at android.app.Activity.startActivityForResult(Activity.java:4586)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at androidx.fragment.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:796)
at androidx.fragment.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:933)
at androidx.fragment.app.Fragment.startActivityForResult(Fragment.java:1206)
at androidx.fragment.app.Fragment.startActivityForResult(Fragment.java:1194)
at com.stripe.android.view.AuthActivityStarter$Host.startActivityForResult$stripe_release(AuthActivityStarter.kt:30)
at com.stripe.android.PaymentRelayStarter$Companion$create$1.start(PaymentRelayStarter.kt:28)
at com.stripe.android.PaymentRelayStarter$Companion$create$1.start(PaymentRelayStarter.kt:21)
at com.stripe.android.StripePaymentController$Companion.handleError(StripePaymentController.kt:899)
at com.stripe.android.StripePaymentController$Companion.access$handleError(StripePaymentController.kt:838)
at com.stripe.android.StripePaymentController$ConfirmStripeIntentCallback.onError(StripePaymentController.kt:542)
at com.stripe.android.ApiOperation.dispatchResult(ApiOperation.kt:40)
at com.stripe.android.ApiOperation.access$dispatchResult(ApiOperation.kt:13)
at com.stripe.android.ApiOperation$execute$1$1.invokeSuspend(ApiOperation.kt:32)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6746)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)