com.google.android.gms.wallet.MaskedWalletRequest Java Examples

The following examples show how to use com.google.android.gms.wallet.MaskedWalletRequest. 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 vote down vote up
/**
 * Creates a MaskedWalletRequest for direct merchant integration (no payment processor)
 *
 * @param itemInfo {@link com.google.android.gms.samples.wallet.ItemInfo} containing details
 *                 of an item.
 * @param publicKey base64-encoded public encryption key. See instructions for more details.
 * @return {@link MaskedWalletRequest} instance
 */
public static MaskedWalletRequest createMaskedWalletRequest(ItemInfo itemInfo,
                                                            String publicKey) {
    // Validate the public key
    if (publicKey == null || publicKey.contains("REPLACE_ME")) {
        throw new IllegalArgumentException("Invalid public key, see README for instructions.");
    }

    // Create direct integration parameters
    // [START direct_integration_parameters]
    PaymentMethodTokenizationParameters parameters =
            PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN)
                .addParameter("publicKey", publicKey)
                .build();
    // [END direct_integration_parameters]

    return createMaskedWalletRequest(itemInfo, parameters);
}
 
Example #2
Source File: WalletUtil.java    From androidpay-quickstart with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a MaskedWalletRequest for processing payments with Stripe
 *
 * @param itemInfo {@link com.google.android.gms.samples.wallet.ItemInfo} containing details
 *                 of an item.
 * @param publishableKey Stripe publishable key.
 * @param version Stripe API version.
 * @return {@link MaskedWalletRequest} instance
 */
public static MaskedWalletRequest createStripeMaskedWalletRequest(ItemInfo itemInfo,
                                                                  String publishableKey,
                                                                  String version) {
    // Validate Stripe configuration
    if ("REPLACE_ME".equals(publishableKey) || "REPLACE_ME".equals(version)) {
        throw new IllegalArgumentException("Invalid Stripe configuration, see README for instructions.");
    }

    // [START stripe_integration_parameters]
    PaymentMethodTokenizationParameters parameters = PaymentMethodTokenizationParameters.newBuilder()
            .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)
            .addParameter("gateway", "stripe")
            .addParameter("stripe:publishableKey", publishableKey)
            .addParameter("stripe:version", version)
            .build();
    // [END stripe_integration_parameters]

  return createMaskedWalletRequest(itemInfo, parameters);
}
 
Example #3
Source File: MainActivity.java    From io2014-codelabs with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: WalletUtil.java    From androidpay-quickstart with Apache License 2.0 5 votes vote down vote up
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 vote down vote up
private void showAndroidPay() {
    if (getParentActivity() == null || androidPayContainer == null) {
        return;
    }

    WalletFragmentOptions.Builder optionsBuilder = WalletFragmentOptions.newBuilder();
    optionsBuilder.setEnvironment(paymentForm.invoice.test ? WalletConstants.ENVIRONMENT_TEST : WalletConstants.ENVIRONMENT_PRODUCTION);
    optionsBuilder.setMode(WalletFragmentMode.BUY_BUTTON);

    WalletFragmentStyle walletFragmentStyle;
    if (androidPayPublicKey != null) {
        androidPayContainer.setBackgroundColor(androidPayBackgroundColor);
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.BUY_WITH)
                .setBuyButtonAppearance(androidPayBlackTheme ? WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER : WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_DARK)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);
    } else {
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.LOGO_ONLY)
                .setBuyButtonAppearance(WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.WRAP_CONTENT);
    }

    optionsBuilder.setFragmentStyle(walletFragmentStyle);
    WalletFragment walletFragment = WalletFragment.newInstance(optionsBuilder.build());
    FragmentManager fragmentManager = getParentActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(fragment_container_id, walletFragment);
    fragmentTransaction.commit();

    ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices);
    if (shippingOption != null) {
        arrayList.addAll(shippingOption.prices);
    }
    totalPriceDecimal = getTotalPriceDecimalString(arrayList);

    PaymentMethodTokenizationParameters parameters;
    if (androidPayPublicKey != null) {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN)
                .addParameter("publicKey", androidPayPublicKey)
                .build();
    } else {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)
                .addParameter("gateway", "stripe")
                .addParameter("stripe:publishableKey", stripeApiKey)
                .addParameter("stripe:version", StripeApiHandler.VERSION)
                .build();
    }

    MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder()
            .setPaymentMethodTokenizationParameters(parameters)
            .setEstimatedTotalPrice(totalPriceDecimal)
            .setCurrencyCode(paymentForm.invoice.currency)
            .build();

    WalletFragmentInitParams initParams = WalletFragmentInitParams.newBuilder()
            .setMaskedWalletRequest(maskedWalletRequest)
            .setMaskedWalletRequestCode(LOAD_MASKED_WALLET_REQUEST_CODE)
            .build();

    walletFragment.initialize(initParams);
    androidPayContainer.setVisibility(View.VISIBLE);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(androidPayContainer, "alpha", 0.0f, 1.0f));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(180);
    animatorSet.start();
}
 
Example #6
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void showAndroidPay() {
    if (getParentActivity() == null || androidPayContainer == null) {
        return;
    }

    WalletFragmentOptions.Builder optionsBuilder = WalletFragmentOptions.newBuilder();
    optionsBuilder.setEnvironment(paymentForm.invoice.test ? WalletConstants.ENVIRONMENT_TEST : WalletConstants.ENVIRONMENT_PRODUCTION);
    optionsBuilder.setMode(WalletFragmentMode.BUY_BUTTON);

    WalletFragmentStyle walletFragmentStyle;
    if (androidPayPublicKey != null) {
        androidPayContainer.setBackgroundColor(androidPayBackgroundColor);
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.BUY_WITH)
                .setBuyButtonAppearance(androidPayBlackTheme ? WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER : WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_DARK)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);
    } else {
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.LOGO_ONLY)
                .setBuyButtonAppearance(WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.WRAP_CONTENT);
    }

    optionsBuilder.setFragmentStyle(walletFragmentStyle);
    WalletFragment walletFragment = WalletFragment.newInstance(optionsBuilder.build());
    FragmentManager fragmentManager = getParentActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(fragment_container_id, walletFragment);
    fragmentTransaction.commit();

    ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices);
    if (shippingOption != null) {
        arrayList.addAll(shippingOption.prices);
    }
    totalPriceDecimal = getTotalPriceDecimalString(arrayList);

    PaymentMethodTokenizationParameters parameters;
    if (androidPayPublicKey != null) {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN)
                .addParameter("publicKey", androidPayPublicKey)
                .build();
    } else {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)
                .addParameter("gateway", "stripe")
                .addParameter("stripe:publishableKey", stripeApiKey)
                .addParameter("stripe:version", StripeApiHandler.VERSION)
                .build();
    }

    MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder()
            .setPaymentMethodTokenizationParameters(parameters)
            .setEstimatedTotalPrice(totalPriceDecimal)
            .setCurrencyCode(paymentForm.invoice.currency)
            .build();

    WalletFragmentInitParams initParams = WalletFragmentInitParams.newBuilder()
            .setMaskedWalletRequest(maskedWalletRequest)
            .setMaskedWalletRequestCode(LOAD_MASKED_WALLET_REQUEST_CODE)
            .build();

    walletFragment.initialize(initParams);
    androidPayContainer.setVisibility(View.VISIBLE);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(androidPayContainer, "alpha", 0.0f, 1.0f));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(180);
    animatorSet.start();
}
 
Example #7
Source File: CheckoutActivity.java    From androidpay-quickstart with Apache License 2.0 4 votes vote down vote up
private void createAndAddWalletFragment() {
    // [START fragment_style_and_options]
    WalletFragmentStyle walletFragmentStyle = new WalletFragmentStyle()
            .setBuyButtonText(WalletFragmentStyle.BuyButtonText.BUY_WITH)
            .setBuyButtonAppearance(WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_DARK)
            .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);

    WalletFragmentOptions walletFragmentOptions = WalletFragmentOptions.newBuilder()
            .setEnvironment(Constants.WALLET_ENVIRONMENT)
            .setFragmentStyle(walletFragmentStyle)
            .setTheme(WalletConstants.THEME_LIGHT)
            .setMode(WalletFragmentMode.BUY_BUTTON)
            .build();
    mWalletFragment = SupportWalletFragment.newInstance(walletFragmentOptions);
    // [END fragment_style_and_options]

    // Now initialize the Wallet Fragment
    String accountName = ((BikestoreApplication) getApplication()).getAccountName();
    MaskedWalletRequest maskedWalletRequest;
    if (mUseStripe) {
        // Stripe integration
        maskedWalletRequest = WalletUtil.createStripeMaskedWalletRequest(
                Constants.ITEMS_FOR_SALE[mItemId],
                getString(R.string.stripe_publishable_key),
                getString(R.string.stripe_version));
    } else {
        // Direct integration
        maskedWalletRequest = WalletUtil.createMaskedWalletRequest(
                Constants.ITEMS_FOR_SALE[mItemId],
                getString(R.string.public_key));
    }

    // [START params_builder]
    WalletFragmentInitParams.Builder startParamsBuilder = WalletFragmentInitParams.newBuilder()
            .setMaskedWalletRequest(maskedWalletRequest)
            .setMaskedWalletRequestCode(REQUEST_CODE_MASKED_WALLET)
            .setAccountName(accountName);
    mWalletFragment.initialize(startParamsBuilder.build());

    // add Wallet fragment to the UI
    getSupportFragmentManager().beginTransaction()
            .replace(R.id.dynamic_wallet_button_fragment, mWalletFragment)
            .commit();
    // [END params_builder]
}