3

I am developing a mobile android app and using Android Pay/Google Wallet to retrieve CC information from the user. I was able to successfully get the GitHub sample application working.

Please see the image below: enter image description here

It appears that the screen shown here uses a dynamic masked wallet fragment. The payment method and shipping address and change buttons are automatically generated by Android APIs.

  1. How can I customize my own UI for this fragment?
  2. How can I listen to the onClick event of the "CHANGE" button?
  3. How can I use the "Android Pay" logo in green (in the image)? The sample app appears to still use the built in "Google Wallet" logo.
code
  • 5,294
  • 16
  • 62
  • 113

2 Answers2

0

I found out how to use the Android Pay logo in the MaskedWalletFragment screen. Simply use the following API: https://developers.google.com/android/reference/com/google/android/gms/wallet/fragment/WalletFragmentStyle.LogoImageType.html#ANDROID_PAY

The key is to call the following:

setMaskedWalletDetailsLogoImageType(int)

Use constant value of 3 for Android Pay. The rest are deprecated.

code
  • 5,294
  • 16
  • 62
  • 113
-1

U have use the methods

  1. .setBuyButtonAppearance(WALLET_APPEARANCE) in CkecoutActivity
  2. .setMaskedWalletDetailsLogoImageType(mWALLET_APPEARANCE) in ConfirmationActivity
  3. .useGoogleWallet() in FullWalletButton

Android wallet is deprecated, in my case i did this:

  1. check id the device have NFC support (android pay use NFC)
  2. if have nfc support use android pay, if dont have i use android wallet.

First in the Constants.java add:

        //values to change buyapparence (android pay-wallet)
        public static final int GOOGLE_WALLET_CLASSIC=1;
        public static final int GOOGLE_WALLET_GRAYSCALE =2;
        public static final int GOOGLE_WALLET_MONOCHROME=3;
        public static final int ANDROID_PAY_DARK = 4;
        public static final int ANDROID_PAY_LIGHT=5;
        public static final int ANDROID_PAY_LIGHT_WITH_BORDER=6;

Then in utils add the nfcController.java with this method:

        public boolean NFCsupport(){
            boolean nfcSupport;
            NfcManager manager = (NfcManager)mAppContext.getSystemService(Context.NFC_SERVICE);
            NfcAdapter adapter = manager.getDefaultAdapter();
            if (adapter != null && adapter.isEnabled()) {
                 nfcSupport=true;
                //Yes NFC available
            }else{
                nfcSupport=false;
                //Your device doesn't support NFC
            }
            return nfcSupport;
        }

Then in your CheckoutActivity.java or when you have wallet implemention add this:

    if(nfcController.NFCsupport()){
                //turn on nfc (other method in util nfcController.java)
                nfcController.enableNfcPower(true);
                //show nfc payment(android pay)
                mWALLET_APPEARANCE=Constants.ANDROID_PAY_LIGHT;
                createAndAddWalletFragment(mWALLET_APPEARANCE);
                Log.d("nfc", "you have nfc support");
            }else{
                Log.d("nfc", "dont have nfc support");
                //show not nfc payment(wallet)
                mWALLET_APPEARANCE=Constants.GOOGLE_WALLET_CLASSIC;
                createAndAddWalletFragment(mWALLET_APPEARANCE);
            }

In your createAndAddWalletFragment(int WALLET_APPEARANCE) change the appearance flags:

        WalletFragmentStyle walletFragmentStyle = new WalletFragmentStyle()
        .setBuyButtonText(BuyButtonText.BUY_WITH_GOOGLE)
        .setBuyButtonAppearance(WALLET_APPEARANCE)
        .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);

Second, sent the wallet_appareance in the intent:

            intent.putExtra("wallet_appearance",mWALLET_APPEARANCE);

and in your confirmationActivity update this funcion to listen the event with the logo correctly in the createAndAddWalletFragment():

     WalletFragmentStyle walletFragmentStyle = new WalletFragmentStyle()
            .setMaskedWalletDetailsLogoImageType(mWALLET_APPEARANCE)//from getintent
            .setMaskedWalletDetailsTextAppearance(
                    R.style.BikestoreWalletFragmentDetailsTextAppearance)
                    .setMaskedWalletDetailsHeaderTextAppearance(
                            R.style.BikestoreWalletFragmentDetailsHeaderTextAppearance)
                    .setMaskedWalletDetailsBackgroundColor(
                            getResources().getColor(R.color.white))
                    .setMaskedWalletDetailsButtonBackgroundResource(
                            R.drawable.bikestore_btn_default_holo_light);

Finally in your fullWalletconfirmationbutton.java in the onCreate method dont forget the function useGoogleWallet to create and setup the fragment:

     // Set up an API client;
            mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .setAccountName(accountName)
                    .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
                            .useGoogleWallet()
                            .setEnvironment(Constants.WALLET_ENVIRONMENT)
                            .setTheme(WalletConstants.THEME_HOLO_LIGHT)
                            .build())
                    .build();

and you have android pay and android wallet support.

tir38
  • 9,810
  • 10
  • 64
  • 107
Osvaldo Bringaz
  • 127
  • 1
  • 7