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