Android Braintree SDK 集成在当前应用程序的活动中



我想将Braintree API集成到我的android应用程序中。我参考了Braintree页面,我想到了如何将其集成到应用程序中。但我有一个问题,当我想显示Drop-In UI下面我目前显示活动的布局。但在演示中,它将启动新的活动BraintreePaymentActivity.java

我不想打开新的活动,我只想在我的活动中显示相同的操作。为此,我参考了卡片表单演示并添加了购买的自定义按钮。在购买按钮上点击我呼叫下面的代码。但在这里我不明白从哪里我可以得到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文档中的信用卡指南中的客户端集成部分。

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
        }
    }
});

最新更新