当前位置:  开发笔记 > 运维 > 正文

braintree集成导致Android问题

如何解决《braintree集成导致Android问题》经验,为你挑选了0个好方法。

我从服务器获取客户端令牌,但是当调用设置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, Header[] headers, 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),
                        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集成是全新的.问题是什么 我哪里错了?或者还有什么建议.

推荐阅读
手机用户2402852307
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有