Skip to content

Commit

Permalink
Reset status when payment completed
Browse files Browse the repository at this point in the history
  • Loading branch information
brnunes-stripe committed Sep 14, 2022
1 parent 7b0f200 commit 484f344
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,27 @@ class AlipayPaymentActivity : StripeIntentActivity() {
callback = object : ApiResultCallback<PaymentIntentResult> {
override fun onSuccess(result: PaymentIntentResult) {
val paymentIntent = result.intent
val status = paymentIntent.status
when (status) {
when (paymentIntent.status) {
StripeIntent.Status.Succeeded ->
viewModel.status.value += "\n\nPayment succeeded"
updateStatus("\n\nPayment succeeded")
StripeIntent.Status.RequiresAction ->
stripe.handleNextActionForPayment(this@AlipayPaymentActivity, secret)
else -> viewModel.status.value += "\n\nPayment failed or canceled"
else -> updateStatus("\n\nPayment failed or canceled")
}
}

override fun onError(e: Exception) {
viewModel.status.value += "\n\nError: ${e.message}"
updateStatus("\n\nError: ${e.message}")
}
}
)
}

private fun updateStatus(appendMessage: String) {
viewModel.status.value += appendMessage
viewModel.inProgress.postValue(false)
}

private fun enableUi(enable: Boolean) {
viewBinding.progressBar.visibility = if (enable) View.INVISIBLE else View.VISIBLE
viewBinding.confirmWithPaymentButton.isEnabled = enable
Expand Down

0 comments on commit 484f344

Please sign in to comment.