代码之家  ›  专栏  ›  技术社区  ›  Rajasekaran M

始终在条带上获取状态“不完整”

  •  1
  • Rajasekaran M  · 技术社区  · 8 年前

    我总是 incomplete 在 onCompletePayment 我也检查了条纹样本应用程序,但它也不适合我。我已经检查了很多,但我不能纠正这个问题。

    那么我这边会有什么错误呢?

    资料来源:

    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)
            })
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   psmvac    8 年前

    不熟悉kotlin,但在您提供的代码片段中,我建议不要重写 handlePaymentData 是的。

    而是打电话 mPaymentSession.handlePaymentData 在 onActivityResult 你的主人 Activity 就像医生建议的那样 here 或如图所示 in the example here 以便对 PaymentSessionData 向您的 PaymentSessionListener 初始化时附加的 PaymentSession (即 mPaymentSession!!.init )中。

    通常,根据你的应用程序结帐流程,你会想打电话给 mPaymentSession.completePayment(...) 例如,用户点击“支付”按钮。

    你可以通过 completePayment(...) 打电话给 PaymentCompletionProvider 这将:

    1. 向后端发送http请求,以便可以使用stripe的api创建费用
    2. 使用标记付款结果 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);
                    }
                });
            }
        }
    });
    

    我希望这能有帮助。