尝试添加错误的卡时 Stripe 崩溃
Stripe crashes when trying to add wrong card
我在 Android 上遇到 Stripe API 的问题。我正在尝试添加一张卡片,到目前为止,如果您制作一张成功的卡片,一切正常。如果您添加一张卡(这意味着失败),它会导致整个应用程序崩溃。
我已按照条纹说明进行操作。但是一旦发生,我就无法赶上。
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.start(PaymentRelayStarter.kt:28)
at com.stripe.android.PaymentRelayStarter$Companion$create.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.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)
问题已通过 stripe 新版本解决(适用于最新的 14.1.1
)
如果有人对 graddle 和编译有疑问。我还更新了最新版本的所有依赖项。
我想可能是
com.google.gms:google-services:4.3.2
那不允许我编译 stripe 新版本。
切换到新的 com.google.gms:google-services:4.3.3(可能)解决了这个问题。
我在 Android 上遇到 Stripe API 的问题。我正在尝试添加一张卡片,到目前为止,如果您制作一张成功的卡片,一切正常。如果您添加一张卡(这意味着失败),它会导致整个应用程序崩溃。
我已按照条纹说明进行操作。但是一旦发生,我就无法赶上。
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.start(PaymentRelayStarter.kt:28)
at com.stripe.android.PaymentRelayStarter$Companion$create.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.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)
问题已通过 stripe 新版本解决(适用于最新的 14.1.1
)
如果有人对 graddle 和编译有疑问。我还更新了最新版本的所有依赖项。
我想可能是
com.google.gms:google-services:4.3.2
那不允许我编译 stripe 新版本。 切换到新的 com.google.gms:google-services:4.3.3(可能)解决了这个问题。