Android 当前应用程序中的 Braintree SDK 集成 activity

Android Braintree SDK Integration in current application's activity

我想将 Braintree API 集成到我的 android application.I 参考 Braintree 页面中,我知道了如何将其集成到应用程序中。但是当我想在当前显示 activity 的布局下方显示 Drop-In UI 时,我遇到了问题。但在演示中它将开始新的 activity BraintreePaymentActivity.java.

我不想打开新的 activity 我只想在我的 activity 中显示相同的操作。为此,我参考 Card-form demo 并在购买按钮上添加了我的 Purchase.And 自定义按钮,单击我调用下面的代码。但是这里我不明白从哪里可以得到Nonce值?

Braintree.setup ( this, CLIENT_TOKEN_FROM_SERVER, new Braintree.BraintreeSetupFinishedListener () {
 @Override
 public void onBraintreeSetupFinished ( boolean setupSuccessful, Braintree braintree, String errorMessage, Exception exception ) {
    if ( setupSuccessful ) {
        // braintree is now setup and available for use
    } else {
        // Braintree could not be initialized, check errors and try again
        // This is usually a result of a network connectivity error
    }
 }} );

如果有人对此有任何想法,请在此处提出建议。

我受困于 Braintree API

提前致谢。

你说得对,你的用例不适合 Drop-in UI。

要添加 PaymentMethodNonce 侦听器,设置 Braintree 后,只需调用 Braintree.addListener 并提供 Braintree.PaymentMethodNonceListener 实现即可。我在下面包含了一个示例。您还可以参考 Braintree 文档中信用卡指南中的 client side integration 部分。

Braintree.setup (this, CLIENT_TOKEN_FROM_SERVER, new Braintree.BraintreeSetupFinishedListener () {
    @Override
    public void onBraintreeSetupFinished ( boolean setupSuccessful, Braintree braintree, String errorMessage, Exception exception) {
        if (setupSuccessful) {
            // braintree is now setup and available for use
            braintree.addListener(new Braintree.PaymentMethodNonceListener() {
                public void onPaymentMethodNonce(String paymentMethodNonce) {
                    // Communicate the nonce to your server
                }
            });
        } else {
            // Braintree could not be initialized, check errors and try again
            // This is usually a result of a network connectivity error
        }
    }
});