com.google.android.gms.wallet.Cart Java Examples
The following examples show how to use
com.google.android.gms.wallet.Cart.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WalletUtil.java From androidpay-quickstart with Apache License 2.0 | 6 votes |
/** * * @param itemInfo {@link com.google.android.gms.samples.wallet.ItemInfo} to use for creating * the {@link com.google.android.gms.wallet.FullWalletRequest} * @param googleTransactionId * @return {@link FullWalletRequest} instance */ public static FullWalletRequest createFullWalletRequest(ItemInfo itemInfo, String googleTransactionId) { List<LineItem> lineItems = buildLineItems(itemInfo, false); String cartTotal = calculateCartTotal(lineItems); // [START full_wallet_request] FullWalletRequest request = FullWalletRequest.newBuilder() .setGoogleTransactionId(googleTransactionId) .setCart(Cart.newBuilder() .setCurrencyCode(Constants.CURRENCY_CODE_USD) .setTotalPrice(cartTotal) .setLineItems(lineItems) .build()) .build(); // [END full_wallet_request] return request; }
Example #2
Source File: MainActivity.java From io2014-codelabs with Apache License 2.0 | 6 votes |
private MaskedWalletRequest generateMaskedWalletRequest() { MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder() .setMerchantName("Google I/O Codelab") .setPhoneNumberRequired(true) .setShippingAddressRequired(true) .setCurrencyCode("USD") .setShouldRetrieveWalletObjects(true) .setEstimatedTotalPrice("10.00") .setCart(Cart.newBuilder() .setCurrencyCode("USD") .setTotalPrice("10.00") .addLineItem(LineItem.newBuilder() .setCurrencyCode("USD") .setDescription("Google I/O Sticker") .setQuantity("1") .setUnitPrice("10.00") .setTotalPrice("10.00") .build()) .build()) .build(); return maskedWalletRequest; }
Example #3
Source File: MainActivity.java From io2014-codelabs with Apache License 2.0 | 6 votes |
private FullWalletRequest generateFullWalletRequest(String googleTransactionId) { FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder() .setGoogleTransactionId(googleTransactionId) .setCart(Cart.newBuilder() .setCurrencyCode("USD") .setTotalPrice("10.10") .addLineItem(LineItem.newBuilder() .setCurrencyCode("USD") .setDescription("Google I/O Sticker") .setQuantity("1") .setUnitPrice("10.00") .setTotalPrice("10.00") .build()) .addLineItem(LineItem.newBuilder() .setCurrencyCode("USD") .setDescription("Tax") .setRole(LineItem.Role.TAX) .setTotalPrice(".10") .build()) .build()) .build(); return fullWalletRequest; }
Example #4
Source File: WalletUtil.java From androidpay-quickstart with Apache License 2.0 | 5 votes |
private static MaskedWalletRequest createMaskedWalletRequest(ItemInfo itemInfo, PaymentMethodTokenizationParameters parameters) { // Build a List of all line items List<LineItem> lineItems = buildLineItems(itemInfo, true); // Calculate the cart total by iterating over the line items. String cartTotal = calculateCartTotal(lineItems); // [START masked_wallet_request] MaskedWalletRequest request = MaskedWalletRequest.newBuilder() .setMerchantName(Constants.MERCHANT_NAME) .setPhoneNumberRequired(true) .setShippingAddressRequired(true) .setCurrencyCode(Constants.CURRENCY_CODE_USD) .setEstimatedTotalPrice(cartTotal) // Create a Cart with the current line items. Provide all the information // available up to this point with estimates for shipping and tax included. .setCart(Cart.newBuilder() .setCurrencyCode(Constants.CURRENCY_CODE_USD) .setTotalPrice(cartTotal) .setLineItems(lineItems) .build()) .setPaymentMethodTokenizationParameters(parameters) .build(); return request; // [END masked_wallet_request] }
Example #5
Source File: PaymentFormActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { if (requestCode == LOAD_MASKED_WALLET_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { showEditDoneProgress(true, true); setDonePressed(true); MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET); Cart.Builder cardBuilder = Cart.newBuilder() .setCurrencyCode(paymentForm.invoice.currency) .setTotalPrice(totalPriceDecimal); ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices); if (shippingOption != null) { arrayList.addAll(shippingOption.prices); } for (int a = 0; a < arrayList.size(); a++) { TLRPC.TL_labeledPrice price = arrayList.get(a); String amount = LocaleController.getInstance().formatCurrencyDecimalString(price.amount, paymentForm.invoice.currency, false); cardBuilder.addLineItem(LineItem.newBuilder() .setCurrencyCode(paymentForm.invoice.currency) .setQuantity("1") .setDescription(price.label) .setTotalPrice(amount) .setUnitPrice(amount).build()); } FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder() .setCart(cardBuilder.build()) .setGoogleTransactionId(maskedWallet.getGoogleTransactionId()) .build(); Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, LOAD_FULL_WALLET_REQUEST_CODE); } else { showEditDoneProgress(true, false); setDonePressed(false); } } else if (requestCode == LOAD_FULL_WALLET_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET); String tokenJSON = fullWallet.getPaymentMethodToken().getToken(); try { if (androidPayPublicKey != null) { androidPayCredentials = new TLRPC.TL_inputPaymentCredentialsAndroidPay(); androidPayCredentials.payment_token = new TLRPC.TL_dataJSON(); androidPayCredentials.payment_token.data = tokenJSON; androidPayCredentials.google_transaction_id = fullWallet.getGoogleTransactionId(); String[] descriptions = fullWallet.getPaymentDescriptions(); if (descriptions.length > 0) { cardName = descriptions[0]; } else { cardName = "Android Pay"; } } else { Token token = TokenParser.parseToken(tokenJSON); paymentJson = String.format(Locale.US, "{\"type\":\"%1$s\", \"id\":\"%2$s\"}", token.getType(), token.getId()); Card card = token.getCard(); cardName = card.getType() + " *" + card.getLast4(); } goToNextStep(); showEditDoneProgress(true, false); setDonePressed(false); } catch (JSONException ignore) { showEditDoneProgress(true, false); setDonePressed(false); } } else { showEditDoneProgress(true, false); setDonePressed(false); } } }
Example #6
Source File: PaymentFormActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void onActivityResultFragment(int requestCode, int resultCode, Intent data) { if (requestCode == LOAD_MASKED_WALLET_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { showEditDoneProgress(true, true); setDonePressed(true); MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET); Cart.Builder cardBuilder = Cart.newBuilder() .setCurrencyCode(paymentForm.invoice.currency) .setTotalPrice(totalPriceDecimal); ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices); if (shippingOption != null) { arrayList.addAll(shippingOption.prices); } for (int a = 0; a < arrayList.size(); a++) { TLRPC.TL_labeledPrice price = arrayList.get(a); String amount = LocaleController.getInstance().formatCurrencyDecimalString(price.amount, paymentForm.invoice.currency, false); cardBuilder.addLineItem(LineItem.newBuilder() .setCurrencyCode(paymentForm.invoice.currency) .setQuantity("1") .setDescription(price.label) .setTotalPrice(amount) .setUnitPrice(amount).build()); } FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder() .setCart(cardBuilder.build()) .setGoogleTransactionId(maskedWallet.getGoogleTransactionId()) .build(); Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, LOAD_FULL_WALLET_REQUEST_CODE); } else { showEditDoneProgress(true, false); setDonePressed(false); } } else if (requestCode == LOAD_FULL_WALLET_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET); String tokenJSON = fullWallet.getPaymentMethodToken().getToken(); try { if (androidPayPublicKey != null) { androidPayCredentials = new TLRPC.TL_inputPaymentCredentialsAndroidPay(); androidPayCredentials.payment_token = new TLRPC.TL_dataJSON(); androidPayCredentials.payment_token.data = tokenJSON; androidPayCredentials.google_transaction_id = fullWallet.getGoogleTransactionId(); String[] descriptions = fullWallet.getPaymentDescriptions(); if (descriptions.length > 0) { cardName = descriptions[0]; } else { cardName = "Android Pay"; } } else { Token token = TokenParser.parseToken(tokenJSON); paymentJson = String.format(Locale.US, "{\"type\":\"%1$s\", \"id\":\"%2$s\"}", token.getType(), token.getId()); Card card = token.getCard(); cardName = card.getType() + " *" + card.getLast4(); } goToNextStep(); showEditDoneProgress(true, false); setDonePressed(false); } catch (JSONException ignore) { showEditDoneProgress(true, false); setDonePressed(false); } } else { showEditDoneProgress(true, false); setDonePressed(false); } } }
Example #7
Source File: DropInRequestUnitTest.java From braintree-android-drop-in with MIT License | 4 votes |
@Test public void isParcelable() { Cart cart = Cart.newBuilder() .setTotalPrice("5.00") .build(); GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest() .transactionInfo(TransactionInfo.newBuilder() .setTotalPrice("10") .setCurrencyCode("USD") .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL) .build()) .emailRequired(true); PayPalRequest paypalRequest = new PayPalRequest("10") .currencyCode("USD"); ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest() .nonce("abc-123") .versionRequested(ThreeDSecureRequest.VERSION_2) .amount("10.00") .email("[email protected]") .mobilePhoneNumber("3125551234") .billingAddress(new ThreeDSecurePostalAddress() .givenName("Given") .surname("Surname") .streetAddress("555 Smith St.") .extendedAddress("#5") .locality("Chicago") .region("IL") .postalCode("54321") .countryCodeAlpha2("US") .phoneNumber("3125557890") ) .additionalInformation(new ThreeDSecureAdditionalInformation() .shippingMethodIndicator("GEN") ); DropInRequest dropInRequest = new DropInRequest() .tokenizationKey(TOKENIZATION_KEY) .collectDeviceData(true) .amount("1.00") .googlePaymentRequest(googlePaymentRequest) .disableGooglePayment() .paypalRequest(paypalRequest) .disablePayPal() .disableVenmo() .disableCard() .requestThreeDSecureVerification(true) .threeDSecureRequest(threeDSecureRequest) .maskCardNumber(true) .maskSecurityCode(true) .vaultManager(true) .vaultCard(true) .allowVaultCardOverride(true) .cardholderNameStatus(CardForm.FIELD_OPTIONAL); Parcel parcel = Parcel.obtain(); dropInRequest.writeToParcel(parcel, 0); parcel.setDataPosition(0); DropInRequest parceledDropInRequest = DropInRequest.CREATOR.createFromParcel(parcel); assertEquals(TOKENIZATION_KEY, parceledDropInRequest.getAuthorization()); assertTrue(parceledDropInRequest.shouldCollectDeviceData()); assertEquals("1.00", parceledDropInRequest.getAmount()); assertEquals("10", dropInRequest.getGooglePaymentRequest().getTransactionInfo().getTotalPrice()); assertEquals("USD", dropInRequest.getGooglePaymentRequest().getTransactionInfo().getCurrencyCode()); assertEquals(WalletConstants.TOTAL_PRICE_STATUS_FINAL, dropInRequest.getGooglePaymentRequest().getTransactionInfo().getTotalPriceStatus()); assertTrue(dropInRequest.getGooglePaymentRequest().isEmailRequired()); assertEquals("10", dropInRequest.getPayPalRequest().getAmount()); assertEquals("USD", dropInRequest.getPayPalRequest().getCurrencyCode()); assertFalse(dropInRequest.isGooglePaymentEnabled()); assertFalse(parceledDropInRequest.isPayPalEnabled()); assertFalse(parceledDropInRequest.isVenmoEnabled()); assertFalse(parceledDropInRequest.isCardEnabled()); assertTrue(parceledDropInRequest.shouldRequestThreeDSecureVerification()); assertEquals("abc-123", dropInRequest.getThreeDSecureRequest().getNonce()); assertEquals("2", dropInRequest.getThreeDSecureRequest().getVersionRequested()); assertEquals("10.00", dropInRequest.getThreeDSecureRequest().getAmount()); assertEquals("[email protected]", dropInRequest.getThreeDSecureRequest().getEmail()); assertEquals("3125551234", dropInRequest.getThreeDSecureRequest().getMobilePhoneNumber()); assertEquals("Given", dropInRequest.getThreeDSecureRequest().getBillingAddress().getGivenName()); assertEquals("Surname", dropInRequest.getThreeDSecureRequest().getBillingAddress().getSurname()); assertEquals("555 Smith St.", dropInRequest.getThreeDSecureRequest().getBillingAddress().getStreetAddress()); assertEquals("#5", dropInRequest.getThreeDSecureRequest().getBillingAddress().getExtendedAddress()); assertEquals("Chicago", dropInRequest.getThreeDSecureRequest().getBillingAddress().getLocality()); assertEquals("IL", dropInRequest.getThreeDSecureRequest().getBillingAddress().getRegion()); assertEquals("54321", dropInRequest.getThreeDSecureRequest().getBillingAddress().getPostalCode()); assertEquals("US", dropInRequest.getThreeDSecureRequest().getBillingAddress().getCountryCodeAlpha2()); assertEquals("3125557890", dropInRequest.getThreeDSecureRequest().getBillingAddress().getPhoneNumber()); assertEquals("GEN", dropInRequest.getThreeDSecureRequest().getAdditionalInformation().getShippingMethodIndicator()); assertTrue(parceledDropInRequest.shouldMaskCardNumber()); assertTrue(parceledDropInRequest.shouldMaskSecurityCode()); assertTrue(parceledDropInRequest.isVaultManagerEnabled()); assertTrue(parceledDropInRequest.getDefaultVaultSetting()); assertTrue(parceledDropInRequest.isSaveCardCheckBoxShown()); assertEquals(CardForm.FIELD_OPTIONAL, parceledDropInRequest.getCardholderNameStatus()); }