我想将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
困住了。
提前致谢。
答案 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
}
}
});