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

The following examples show how to use com.google.android.gms.wallet.Wallet. 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: FullWalletConfirmationButtonFragment.java    From androidpay-quickstart with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mActivityLaunchIntent = getActivity().getIntent();
    mItemId = mActivityLaunchIntent.getIntExtra(Constants.EXTRA_ITEM_ID, 0);
    mMaskedWallet = mActivityLaunchIntent.getParcelableExtra(Constants.EXTRA_MASKED_WALLET);

    String accountName = getApplication().getAccountName();

    // Set up an API client
    FragmentActivity fragmentActivity = getActivity();

    // [START build_google_api_client]
    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .enableAutoManage(fragmentActivity, this /* onConnectionFailedListener */)
            .setAccountName(accountName) // optional
            .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
                    .setEnvironment(Constants.WALLET_ENVIRONMENT)
                    .setTheme(WalletConstants.THEME_LIGHT)
                    .build())
            .build();
    // [END build_google_api_client]
}
 
Example #2
Source File: FullWalletConfirmationButtonFragment.java    From androidpay-quickstart with Apache License 2.0 5 votes vote down vote up
private void getFullWallet() {
    FullWalletRequest fullWalletRequest = WalletUtil.createFullWalletRequest(mItemInfo,
            mMaskedWallet.getGoogleTransactionId());

    // [START load_full_wallet]
    Wallet.Payments.loadFullWallet(mGoogleApiClient, fullWalletRequest,
            REQUEST_CODE_RESOLVE_LOAD_FULL_WALLET);
    // [END load_full_wallet]
}
 
Example #3
Source File: MainActivity.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
public void requestFullWallet(View view) {
  if (mGoogleApiClient.isConnected()){
    Wallet.Payments.loadFullWallet(mGoogleApiClient,
        generateFullWalletRequest(mMaskedWallet.getGoogleTransactionId()),
        FULL_WALLET_REQUEST_CODE);
  }
}
 
Example #4
Source File: MainActivity.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode,resultCode,data);

  switch (requestCode) {
    case MASKED_WALLET_REQUEST_CODE:
      switch (resultCode) {
        case Activity.RESULT_OK:
          mMaskedWallet =
              data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
          break;
        case Activity.RESULT_CANCELED:
          break;
        default:
          Toast.makeText(this, "An Error Occurred", Toast.LENGTH_LONG).show();
          break;
      }
      break;
    case FULL_WALLET_REQUEST_CODE:
      switch (resultCode) {
        case Activity.RESULT_OK:
          mFullWallet =
              data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
          Toast.makeText(this, mFullWallet.getProxyCard().getPan().toString(), Toast.LENGTH_LONG).show();

          Wallet.Payments.notifyTransactionStatus(mGoogleApiClient,
              generateNotifyTransactionStatusRequest(mFullWallet.getGoogleTransactionId(),
                  NotifyTransactionStatusRequest.Status.SUCCESS));

          break;
        default:
          Toast.makeText(this, "An Error Occurred", Toast.LENGTH_LONG).show();
          break;
      }
      break;
    case WalletConstants.RESULT_ERROR:
      Toast.makeText(this, "An Error Occurred", Toast.LENGTH_LONG).show();
      break;
  }
}
 
Example #5
Source File: MainActivity.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
            .setEnvironment(WalletConstants.ENVIRONMENT_PRODUCTION)
            .setTheme(WalletConstants.THEME_HOLO_LIGHT)
            .build())
        .build();

    setContentView(R.layout.activity_main);
}
 
Example #6
Source File: BraintreeFragment.java    From braintree_android with MIT License 5 votes vote down vote up
protected GoogleApiClient getGoogleApiClient() {
    if (getActivity() == null) {
        postCallback(new GoogleApiClientException(ErrorType.NotAttachedToActivity, 1));
        return null;
    }

    if (mGoogleApiClient == null) {
        mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
                        .setEnvironment(GooglePayment.getEnvironment(getConfiguration().getGooglePayment()))
                        .setTheme(WalletConstants.THEME_LIGHT)
                        .build())
                .build();
    }

    if (!mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) {
        mGoogleApiClient.registerConnectionCallbacks(new ConnectionCallbacks() {
            @Override
            public void onConnected(Bundle bundle) {}

            @Override
            public void onConnectionSuspended(int i) {
                postCallback(new GoogleApiClientException(ErrorType.ConnectionSuspended, i));
            }
        });

        mGoogleApiClient.registerConnectionFailedListener(new OnConnectionFailedListener() {
            @Override
            public void onConnectionFailed(ConnectionResult connectionResult) {
                postCallback(new GoogleApiClientException(ErrorType.ConnectionFailed, connectionResult.getErrorCode()));
            }
        });

        mGoogleApiClient.connect();
    }

    return mGoogleApiClient;
}
 
Example #7
Source File: GooglePaymentConfiguration.java    From braintree_android with MIT License 5 votes vote down vote up
/**
 * @return {@code true} if Google Payment is enabled and supported in the current environment,
 *         {@code false} otherwise. Note: this value only pertains to the Braintree configuration, to check if
 *         the user has Google Payment setup use
 *         {@link com.braintreepayments.api.GooglePayment#isReadyToPay(BraintreeFragment, BraintreeResponseListener)}
 */
public boolean isEnabled(Context context) {
    try {
        Class.forName(Wallet.class.getName());

        return mEnabled && GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) ==
                ConnectionResult.SUCCESS;
    } catch (ClassNotFoundException | NoClassDefFoundError e) {
        return false;
    }
}
 
Example #8
Source File: CollectCardInfoActivity.java    From gateway-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    binding = DataBindingUtil.setContentView(this, R.layout.activity_collect_card_info);

    // get bundle extras and set txn amount and currency for google pay
    Intent i = getIntent();
    googlePayTxnAmount = i.getStringExtra(EXTRA_GOOGLE_PAY_TXN_AMOUNT);
    googlePayTxnCurrency = i.getStringExtra(EXTRA_GOOGLE_PAY_TXN_CURRENCY);

    // init manual text field listeners
    binding.nameOnCard.requestFocus();
    binding.nameOnCard.addTextChangedListener(textChangeListener);
    binding.cardnumber.addTextChangedListener(textChangeListener);
    binding.expiryMonth.addTextChangedListener(textChangeListener);
    binding.expiryYear.addTextChangedListener(textChangeListener);
    binding.cvv.addTextChangedListener(textChangeListener);

    binding.submitButton.setEnabled(false);
    binding.submitButton.setOnClickListener(v -> continueButtonClicked());


    // init Google Pay client
    paymentsClient = Wallet.getPaymentsClient(this, new Wallet.WalletOptions.Builder()
            .setEnvironment(WalletConstants.ENVIRONMENT_TEST)
            .build());

    // init google pay button
    binding.googlePayButton.setOnClickListener(v -> googlePayButtonClicked());

    // check if Google Pay is available
    isReadyToPay();
}
 
Example #9
Source File: GPay.java    From react-native-GPay with MIT License 5 votes vote down vote up
private PaymentsClient getPaymentsClient(int environment, @NonNull Activity activity) {

        if (mPaymentsClient == null) {
            mPaymentsClient =
                    Wallet.getPaymentsClient(
                            activity,
                            new Wallet.WalletOptions.Builder()
                                    .setEnvironment(environment)
                                    .build());
        }

        return mPaymentsClient;
    }
 
Example #10
Source File: GPay.java    From react-native-GPay with MIT License 5 votes vote down vote up
private PaymentsClient getPaymentsClient(int environment, @NonNull Activity activity) {

        if (mPaymentsClient == null) {
            mPaymentsClient =
                    Wallet.getPaymentsClient(
                            activity,
                            new Wallet.WalletOptions.Builder()
                                    .setEnvironment(environment)
                                    .build());
        }

        return mPaymentsClient;
    }
 
Example #11
Source File: CheckoutActivity.java    From in-app-payments-android-quickstart with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_cookie);

  googlePayChargeClient = (GooglePayChargeClient) getLastCustomNonConfigurationInstance();
  if (googlePayChargeClient == null) {
    googlePayChargeClient = ExampleApplication.createGooglePayChargeClient(this);
  }
  googlePayChargeClient.onActivityCreated(this);

  paymentsClient = Wallet.getPaymentsClient(this,
      new Wallet.WalletOptions.Builder()
          .setEnvironment(WalletConstants.ENVIRONMENT_TEST)
          .build());

  orderSheet = new OrderSheet();

  enableGooglePayButton(orderSheet);
  orderSheet.setOnPayWithCardClickListener(this::startCardEntryActivity);
  orderSheet.setOnPayWithGoogleClickListener(this::startGooglePayActivity);

  View buyButton = findViewById(R.id.buy_button);
  buyButton.setOnClickListener(v -> {
    if (InAppPaymentsSdk.INSTANCE.getSquareApplicationId().equals("REPLACE_ME")) {
      showMissingSquareApplicationIdDialog();
    } else {
      showOrderSheet();
    }
  });
}
 
Example #12
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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 #13
Source File: CheckoutActivity.java    From androidpay-quickstart with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_checkout);

    // [START basic_google_api_client]
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
                    .setEnvironment(Constants.WALLET_ENVIRONMENT)
                    .build())
            .enableAutoManage(this, this)
            .build();
    // [END basic_google_api_client]

    mItemId = getIntent().getIntExtra(Constants.EXTRA_ITEM_ID, 0);
    mReturnToShopping = (Button) findViewById(R.id.button_return_to_shopping);
    mReturnToShopping.setOnClickListener(this);
    mContinueCheckout = (Button) findViewById(R.id.button_regular_checkout);
    mContinueCheckout.setOnClickListener(this);

    mStripeCheckbox = (CheckBox) findViewById(R.id.checkbox_stripe);
    mStripeCheckbox.setOnCheckedChangeListener(this);

    // Check if user is ready to use Android Pay
    // [START is_ready_to_pay]
    showProgressDialog();
    Wallet.Payments.isReadyToPay(mGoogleApiClient).setResultCallback(
            new ResultCallback<BooleanResult>() {
                @Override
                public void onResult(@NonNull BooleanResult booleanResult) {
                    hideProgressDialog();

                    if (booleanResult.getStatus().isSuccess()) {
                        if (booleanResult.getValue()) {
                            // Show Android Pay buttons and hide regular checkout button
                            // [START_EXCLUDE]
                            Log.d(TAG, "isReadyToPay:true");
                            createAndAddWalletFragment();
                            findViewById(R.id.button_regular_checkout)
                                    .setVisibility(View.GONE);
                            // [END_EXCLUDE]
                        } else {
                            // Hide Android Pay buttons, show a message that Android Pay
                            // cannot be used yet, and display a traditional checkout button
                            // [START_EXCLUDE]
                            Log.d(TAG, "isReadyToPay:false:" + booleanResult.getStatus());
                            findViewById(R.id.layout_android_pay_checkout)
                                    .setVisibility(View.GONE);
                            findViewById(R.id.android_pay_message)
                                    .setVisibility(View.VISIBLE);
                            findViewById(R.id.button_regular_checkout)
                                    .setVisibility(View.VISIBLE);
                            // [END_EXCLUDE]
                        }
                    } else {
                        // Error making isReadyToPay call
                        Log.e(TAG, "isReadyToPay:" + booleanResult.getStatus());
                    }
                }
            });
    // [END is_ready_to_pay]
}
 
Example #14
Source File: MainActivity.java    From io2014-codelabs with Apache License 2.0 4 votes vote down vote up
public void saveToWallet(View view){
  CreateWalletObjectsRequest request = new CreateWalletObjectsRequest(generateOfferObject());
  Wallet.WalletObjects.createWalletObjects(mGoogleApiClient, request, SAVE_TO_WALLET);
}
 
Example #15
Source File: MainActivity.java    From io2014-codelabs with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  mWalletFragment = (SupportWalletFragment) getSupportFragmentManager().findFragmentByTag(WALLET_FRAGMENT_ID);

  WalletFragmentInitParams startParams;
  WalletFragmentInitParams.Builder startParamsBuilder = WalletFragmentInitParams.newBuilder()
      .setMaskedWalletRequest(generateMaskedWalletRequest())
      .setMaskedWalletRequestCode(MASKED_WALLET_REQUEST_CODE);

  startParams = startParamsBuilder.build();

  if(mWalletFragment == null) {
    WalletFragmentStyle walletFragmentStyle = new WalletFragmentStyle()
        .setBuyButtonText(BuyButtonText.BUY_WITH_GOOGLE)
        .setBuyButtonWidth(Dimension.MATCH_PARENT);

    WalletFragmentOptions walletFragmentOptions = WalletFragmentOptions.newBuilder()
        .setEnvironment(WalletConstants.ENVIRONMENT_SANDBOX)
        .setFragmentStyle(walletFragmentStyle)
        .setTheme(WalletConstants.THEME_HOLO_LIGHT)
        .setMode(WalletFragmentMode.BUY_BUTTON)
        .build();

    mWalletFragment = SupportWalletFragment.newInstance(walletFragmentOptions);

    mWalletFragment.initialize(startParams);
  }
  getSupportFragmentManager().beginTransaction()
      .replace(R.id.wallet_button_holder, mWalletFragment, WALLET_FRAGMENT_ID)
      .commit();

  mGoogleApiClient = new GoogleApiClient.Builder(this)
      .addConnectionCallbacks(this)
      .addOnConnectionFailedListener(this)
      .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
          .setEnvironment(WalletConstants.ENVIRONMENT_SANDBOX)
          .setTheme(WalletConstants.THEME_HOLO_LIGHT)
          .build())
      .build();

  setContentView(R.layout.activity_main);
}
 
Example #16
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@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 #17
Source File: PaymentsUtil.java    From android-quickstart with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an instance of {@link PaymentsClient} for use in an {@link Activity} using the
 * environment and theme set in {@link Constants}.
 *
 * @param activity is the caller's activity.
 */
public static PaymentsClient createPaymentsClient(Activity activity) {
  Wallet.WalletOptions walletOptions =
      new Wallet.WalletOptions.Builder().setEnvironment(Constants.PAYMENTS_ENVIRONMENT).build();
  return Wallet.getPaymentsClient(activity, walletOptions);
}