Skip to content

Instantly share code, notes, and snippets.

@rubixhacker
Created August 22, 2015 20:02
Show Gist options
  • Save rubixhacker/10d0a5240643ce0973ec to your computer and use it in GitHub Desktop.
Save rubixhacker/10d0a5240643ce0973ec to your computer and use it in GitHub Desktop.
Android Simplify SDK 2.0.0 Alpha with Google Wallet
To pull the alpha sdk inculde the following depenency in your build.gradle
compile 'com.simplify:sdk-android:2.0.0-alpha2@aar'
For Android Pay/Google Wallet include:
compile 'com.google.android.gms:play-services-wallet:7.8.0'
To use Android Pay add the Android Pay button to you view
// Check if WalletFragment already exists
SupportWalletFragment walletFragment = (SupportWalletFragment) getSupportFragmentManager()
.findFragmentByTag(WALLET_FRAGMENT_ID);
if (walletFragment != null) {
return;
}
// Define fragment style
WalletFragmentStyle fragmentStyle = new WalletFragmentStyle()
.setBuyButtonText(BuyButtonText.BUY_NOW)
.setBuyButtonAppearance(BuyButtonAppearance.CLASSIC)
.setBuyButtonWidth(Dimension.MATCH_PARENT);
// Define fragment options
WalletFragmentOptions fragmentOptions = WalletFragmentOptions.newBuilder()
.setEnvironment(WalletConstants.ENVIRONMENT_SANDBOX)
.setFragmentStyle(fragmentStyle)
.setTheme(WalletConstants.THEME_HOLO_LIGHT)
.setMode(WalletFragmentMode.BUY_BUTTON)
.build();
// Create a new instance of WalletFragment
walletFragment = SupportWalletFragment.newInstance(fragmentOptions);
// Initialize the fragment with start params
// Note: If using the provided helper method Simplify.handleAndroidPayResult(int, int, Intent),
// you MUST set the request code to Simplify.REQUEST_CODE_MASKED_WALLET
WalletFragmentInitParams.Builder startParamsBuilder = WalletFragmentInitParams.newBuilder()
.setMaskedWalletRequest(getMaskedWalletRequest())
.setMaskedWalletRequestCode(Simplify.REQUEST_CODE_MASKED_WALLET);
walletFragment.initialize(startParamsBuilder.build());
// Add Wallet fragment to the U
getSupportFragmentManager().beginTransaction()
.replace(R.id.buy_button_holder, walletFragment, WALLET_FRAGMENT_ID)
.commit();
Create a MaskedWalletRequest
private MaskedWalletRequest getMaskedWalletRequest() {
return MaskedWalletRequest.newBuilder()
.setMerchantName("MasterCard labs")
.setPhoneNumberRequired(true)
.setShippingAddressRequired(true)
.setCurrencyCode(CURRENCY_CODE_USD)
.setCart(Cart.newBuilder()
.setCurrencyCode(CURRENCY_CODE_USD)
.setTotalPrice("5.00")
.addLineItem(LineItem.newBuilder()
.setCurrencyCode(CURRENCY_CODE_USD)
.setDescription("Mc labs")
.setQuantity("1")
.setUnitPrice("5.00")
.setTotalPrice("5.00")
.build())
.build())
.setEstimatedTotalPrice("5.00")
.build();
}
In your onActivityResult passed the returned data to Simplify
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// to get back MaskedWallet using call back method.
if (Simplify.handleAndroidPayResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment