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

时间:2015-05-27 12:50:00

标签: android braintree

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

我不想打开新活动,我只想在我的活动中显示相同的操作。为此,我引用了Card-form demo并添加了我的自定义按钮进行购买。在购买按钮上单击我调用下面的代码。但在这里,我不明白从哪里可以获得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困住了。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您的用例不适合Drop-in用户界面,这是正确的。

为了添加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
        }
    }
});