我总是在onCompletePayment
得到incomplete
,我也检查了条纹样本应用程序,但它对我来说也不起作用。我有很多检查,但我无法纠正这个问题。
那么,我这边会有什么错误呢?
来源:
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
。
相反,按照此处文档中的建议或此处示例中所示,调用主机Activity
的onActivityResult
中的mPaymentSession.handlePaymentData
,以便在初始化PaymentSession
时(即使用mPaymentSession!!.init
(将对PaymentSessionData
的任何更新报告给您附加的PaymentSessionListener
。
此外,通常情况下,根据您的应用程序Checkout流程,您会希望在用户单击(例如("支付"按钮时调用mPaymentSession.completePayment(...)
。
您将传递给completePayment(...)
调用PaymentCompletionProvider
,该调用将:
- 向后端发送HTTP请求,以便您可以使用Stripe的API创建收费
- 在例如支付成功的情况下使用CCD_ 14通过CCD_
我不认为示例应用程序有这样的例子,但在Java中,你可以在你的"支付"按钮设置上有一个点击监听器,如下所示:
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);
}
});
}
}
});
我希望这能有所帮助。