始终在条带上获取状态 "Incomplete"
Getting status "Incomplete" on stripe always
我总是在 onCompletePayment
得到 incomplete
,我也检查了 stripe 示例应用程序,但它也不适合我。我有支票,但我无法解决这个问题。
那么我这边的错误是什么?
来源:
PaymentConfiguration.init(BuildConfig.STRIPE_PUBLISHABLE_KEY)
/* Initialized customer*/
private fun setupPaymentSession() {
mPaymentSession = PaymentSession(mvpView?.baseActivity!!)
val paymentSessionInitialized = mPaymentSession!!.init(object : PaymentSession.PaymentSessionListener {
override fun onCommunicatingStateChanged(isCommunicating: Boolean) {
if (isCommunicating) {
} else {
}
}
override fun onError(errorCode: Int, errorMessage: String?) {
}
override fun onPaymentSessionDataChanged(data: PaymentSessionData) {
mPaymentSessionData = data
checkForCustomerUpdates()
}
}, PaymentSessionConfig.Builder()
/* .setPrepopulatedShippingInfo(getExampleShippingInfo())
.setHiddenShippingInfoFields(ShippingInfoWidget.PHONE_FIELD, ShippingInfoWidget.CITY_FIELD)*/
.setShippingInfoRequired(false)
.build())
if (paymentSessionInitialized) {
mPaymentSession?.setCartTotal(20L)
}
}
override fun handlePaymentData(requestCode: Int, resultCode: Int, data: Intent?) {
if (data != null) {
mPaymentSession?.handlePaymentData(requestCode, resultCode, data)
mPaymentSession?.completePayment(PaymentCompletionProvider { paymentData, listener ->
Toast.makeText(mvpView?.baseActivity!!, "success" + paymentData.paymentResult, Toast.LENGTH_SHORT).show()
listener.onPaymentResult(paymentData.paymentResult)
})
}
}
不熟悉 Kotlin,但在您提供的代码片段中,我建议不要覆盖 handlePaymentData
。
而是像文档 here or as shown in the example here 中建议的那样在主机 onActivityResult
中调用 mPaymentSession.handlePaymentData
,以便对 PaymentSessionData
进行任何更新在初始化 PaymentSession
时(即使用 mPaymentSession!!.init
)向您的 PaymentSessionListener
报告。
此外,通常,根据您的应用结帐流程,您可能希望在用户点击 "Pay" 按钮时调用 mPaymentSession.completePayment(...)
。
您将传递给 completePayment(...)
调用一个 PaymentCompletionProvider
,它将:
- 向您的后端发送 HTTP 请求,以便您可以使用 Stripe 的 API
创建费用
- 使用
listener.onPaymentResult(...)
标记支付结果通过PaymentResultListener.SUCCESS
,例如支付成功。
我认为示例应用程序没有这样的示例,但在 Java 中,您可以在 "Pay" 按钮设置上设置一个点击监听器,如下所示:
Button payButton = findViewById(R.id.pay_bttn);
payButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPaymentSessionData.isPaymentReadyToCharge() && mPaymentSessionData.getPaymentResult() == PaymentResultListener.SUCCESS) {
// Use the data to complete your charge - see below.
mPaymentSession.completePayment(new PaymentCompletionProvider() {
@Override
public void completePayment(@NonNull PaymentSessionData data, @NonNull PaymentResultListener listener) {
Log.v(TAG, "Completing payment with data: " + data.toString());
// This is where you want to call your backend...
// In this case mark the payment as Successful
listener.onPaymentResult(PaymentResultListener.SUCCESS);
}
});
}
}
});
希望对您有所帮助。
我总是在 onCompletePayment
得到 incomplete
,我也检查了 stripe 示例应用程序,但它也不适合我。我有支票,但我无法解决这个问题。
那么我这边的错误是什么?
来源:
PaymentConfiguration.init(BuildConfig.STRIPE_PUBLISHABLE_KEY)
/* Initialized customer*/
private fun setupPaymentSession() {
mPaymentSession = PaymentSession(mvpView?.baseActivity!!)
val paymentSessionInitialized = mPaymentSession!!.init(object : PaymentSession.PaymentSessionListener {
override fun onCommunicatingStateChanged(isCommunicating: Boolean) {
if (isCommunicating) {
} else {
}
}
override fun onError(errorCode: Int, errorMessage: String?) {
}
override fun onPaymentSessionDataChanged(data: PaymentSessionData) {
mPaymentSessionData = data
checkForCustomerUpdates()
}
}, PaymentSessionConfig.Builder()
/* .setPrepopulatedShippingInfo(getExampleShippingInfo())
.setHiddenShippingInfoFields(ShippingInfoWidget.PHONE_FIELD, ShippingInfoWidget.CITY_FIELD)*/
.setShippingInfoRequired(false)
.build())
if (paymentSessionInitialized) {
mPaymentSession?.setCartTotal(20L)
}
}
override fun handlePaymentData(requestCode: Int, resultCode: Int, data: Intent?) {
if (data != null) {
mPaymentSession?.handlePaymentData(requestCode, resultCode, data)
mPaymentSession?.completePayment(PaymentCompletionProvider { paymentData, listener ->
Toast.makeText(mvpView?.baseActivity!!, "success" + paymentData.paymentResult, Toast.LENGTH_SHORT).show()
listener.onPaymentResult(paymentData.paymentResult)
})
}
}
不熟悉 Kotlin,但在您提供的代码片段中,我建议不要覆盖 handlePaymentData
。
而是像文档 here or as shown in the example here 中建议的那样在主机 onActivityResult
中调用 mPaymentSession.handlePaymentData
,以便对 PaymentSessionData
进行任何更新在初始化 PaymentSession
时(即使用 mPaymentSession!!.init
)向您的 PaymentSessionListener
报告。
此外,通常,根据您的应用结帐流程,您可能希望在用户点击 "Pay" 按钮时调用 mPaymentSession.completePayment(...)
。
您将传递给 completePayment(...)
调用一个 PaymentCompletionProvider
,它将:
- 向您的后端发送 HTTP 请求,以便您可以使用 Stripe 的 API 创建费用
- 使用
listener.onPaymentResult(...)
标记支付结果通过PaymentResultListener.SUCCESS
,例如支付成功。
我认为示例应用程序没有这样的示例,但在 Java 中,您可以在 "Pay" 按钮设置上设置一个点击监听器,如下所示:
Button payButton = findViewById(R.id.pay_bttn);
payButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPaymentSessionData.isPaymentReadyToCharge() && mPaymentSessionData.getPaymentResult() == PaymentResultListener.SUCCESS) {
// Use the data to complete your charge - see below.
mPaymentSession.completePayment(new PaymentCompletionProvider() {
@Override
public void completePayment(@NonNull PaymentSessionData data, @NonNull PaymentResultListener listener) {
Log.v(TAG, "Completing payment with data: " + data.toString());
// This is where you want to call your backend...
// In this case mark the payment as Successful
listener.onPaymentResult(PaymentResultListener.SUCCESS);
}
});
}
}
});
希望对您有所帮助。