braintree集成导致Android问题

前端之家收集整理的这篇文章主要介绍了braintree集成导致Android问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从服务器获取客户端令牌,但是当调用设置BraintreeFramgent时,它会说Tokenization Key或客户端令牌无效.

之后如果我点击按钮然后OnActivityResult考虑RESULT_CANCELED并显示对话框.

下面的代码

compile 'com.braintreepayments.api:braintree:2.+'

compile 'com.braintreepayments.api:drop-in:2.+'

java文件

String clientToken;
private BraintreeFragment mBraintreeFragment;
private String mNonce;

在OnCreate

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Warning,signature verification is disabled for this demo only,you should never
        // do this as it opens a security hole
        PayPalSignatureVerification.disableAppSwitchSignatureVerification();


        clienttoken();
    }

clienttoken()

public void clienttoken() {
        AsyncHttpClient client = new AsyncHttpClient();
        client.get("http://......&action=clientToken",new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode,Header[] headers,String responseString,Throwable throwable) {
            }

            @Override
            public void onSuccess(int statusCode,String responseString) {
                clientToken = responseString;
                setup();
                //Toast.makeText(MainActivity.this,clientToken,Toast.LENGTH_LONG).show();
            }
        });
    }

建立()

private void setup() {
        try {

            mBraintreeFragment = BraintreeFragment.newInstance(this,clientToken);

        } catch (InvalidArgumentException e) {
            showDialog(e.getMessage());
        }
    }

按钮单击

public void launchDropIn(View v) {
        startActivityForResult(onBraintreeSubmit().getIntent(this),DROP_IN_REQUEST);
    }

onBraintreeSubmit()

public PaymentRequest onBraintreeSubmit() {
        PaymentRequest paymentRequest = new PaymentRequest()
                .clientToken(clientToken)
                .primaryDescription(getString(R.string.cart))
                .secondaryDescription("1 Item")
                .amount("$1.00")
                .submitButtonText(getString(R.string.buy));

        return paymentRequest;
    }

onActivityResult

@Override
    public void onActivityResult(int requestCode,int resultCode,Intent data) {
        super.onActivityResult(requestCode,resultCode,data);



        if (resultCode == Activity.RESULT_OK) {
            PaymentMethodNonce paymentMethodNonce =
                    data.getParcelableExtra(BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE);

            if (Settings.isThreeDSecureEnabled(this)) {
                mLoading = ProgressDialog.show(this,getString(R.string.loading),true,false);
                ThreeDSecure.performVerification(mBraintreeFragment,mNonce,"1");
            } else {
                mCreateTransactionButton.setEnabled(true);
            }
        } else if (resultCode != RESULT_CANCELED) {
            safelyCloseLoadingView();
            showDialog(data.getStringExtra(BraintreePaymentActivity.EXTRA_ERROR_MESSAGE));
        }
    }

我对Android中的Braintree集成是全新的.
问题是什么我哪里错了?或者还有什么建议.

解决方法

完全披露:我在Braintree工作.

您收到的警告表明您生成的客户端令牌可能不正确.使用here给出的示例有效客户端令牌测试您的集成.如果可行,请检查以确保您正在使用的Braintree网关(沙箱或生产)的API密钥已在项目中正确设置.您可以通过选择帐户>从Braintree控制面板中找到您的API密钥.我的用户>查看API密钥.不要在Stack Overflow上发布API密钥.如果您仍然无法集成或有任何疑问,请联系Braintree support.

原文链接:https://www.f2er.com/android/315097.html

猜你在找的Android相关文章