private void requestAndroidPayMaskedWallet() { AndroidPay.getTokenizationParameters( mBraintreeFragment, new TokenizationParametersListener() { @Override public void onResult( PaymentMethodTokenizationParameters parameters, Collection<Integer> allowedCardNetworks) { MaskedWalletRequest.Builder maskedWalletRequestBuilder = MaskedWalletRequest.newBuilder() .setMerchantName("Braintree") .setCurrencyCode("USD") .setCart(mCart) .setEstimatedTotalPrice(mCart.getTotalPrice()) .setShippingAddressRequired( Settings.isAndroidPayShippingAddressRequired(CustomActivity.this)) .setPhoneNumberRequired( Settings.isAndroidPayPhoneNumberRequired(CustomActivity.this)) .setPaymentMethodTokenizationParameters(parameters) .addAllowedCardNetworks(allowedCardNetworks); Wallet.Payments.loadMaskedWallet( mGoogleApiClient, maskedWalletRequestBuilder.build(), ANDROID_PAY_MASKED_WALLET_REQUEST_CODE); } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == ANDROID_PAY_MASKED_WALLET_REQUEST_CODE) { String googleTransactionId = ((MaskedWallet) data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET)) .getGoogleTransactionId(); FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder() .setGoogleTransactionId(googleTransactionId) .setCart(mCart) .build(); Wallet.Payments.loadFullWallet( mGoogleApiClient, fullWalletRequest, ANDROID_PAY_FULL_WALLET_REQUEST_CODE); } else if (requestCode == ANDROID_PAY_FULL_WALLET_REQUEST_CODE) { AndroidPay.tokenize( mBraintreeFragment, (FullWallet) data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET)); } } else if (resultCode == RESULT_CANCELED) { onCancel(requestCode); } else { int errorCode = -1; if (data != null) { errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1); } onError( new Exception( "Request Code: " + requestCode + " Result Code: " + resultCode + " Error Code: " + errorCode)); } }
@Override public void onConfigurationFetched(Configuration configuration) { if (configuration.isPayPalEnabled()) { mPayPalButton.setVisibility(VISIBLE); } if (configuration.getAndroidPay().isEnabled(this)) { AndroidPay.isReadyToPay( mBraintreeFragment, new BraintreeResponseListener<Boolean>() { @Override public void onResponse(Boolean isReadyToPay) { if (isReadyToPay) { mAndroidPayButton.setVisibility(VISIBLE); } } }); } if (getIntent().getBooleanExtra(MainActivity.EXTRA_COLLECT_DEVICE_DATA, false)) { mDeviceData = DataCollector.collectDeviceData(mBraintreeFragment); } }