Permalink
Browse files

Updates as per previous review.

  • Loading branch information...
NaliniSewak committed Sep 11, 2018
1 parent e5a17a0 commit 10b025ad004e4d68d581cd6a469ad03018fd400a
@@ -5,10 +5,11 @@ android {
defaultConfig {
applicationId "com.google.android.gms.samples.wallet"
// Google Payment API is not supported in SDK versions lower than 19
minSdkVersion 19
/* Google Payment API is not supported in SDK versions lower than 19. This example requires
this version due to use of newer constructs like Optional. */
minSdkVersion 24
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
@@ -24,10 +25,11 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
/* "play-services-wallet" is the only module needed for the Google Pay API and this sample app
but the "play-services" module can also be used.
The version provided is the minimum version required for the most recent version of the
Google Pay API library. Your app may choose a dependency greater than the value above.
See https://developers.google.com/pay/api/android/guides/setup#dependencies for more info.
*/
implementation 'com.google.android.gms:play-services-wallet:16.0.0'
implementation 'com.android.support:appcompat-v7:24.1.1'
// "wallet" is the only module needed for the Google Payment API and this sample app.
// Apps that selectively compile Google Play service APIs need only this dependency.
//implementation 'com.google.android.gms:play-services-wallet:11.8.0'
}
@@ -55,7 +55,10 @@
*/
private View mGooglePayButton;
// Arbitrarily-picked constant integer you define to track a request for payment data activity */
/**
* Arbitrarily-picked constant integer you define to track a request for payment data activity.
* @value #LOAD_PAYMENT_DATA_REQUEST_CODE
*/
private static final int LOAD_PAYMENT_DATA_REQUEST_CODE = 991;
private TextView mGooglePayStatusText;
@@ -128,11 +131,12 @@ public void onComplete(Task<Boolean> task) {
}
/**
* If isReadyToPay returned true, show the button and hide the "checking" text. Otherwise, notify
* the user that Pay with Google is not available. Please adjust to fit in with your current user
* flow. You are not required to explicitly let the user know if isReadyToPay returns false.
* If isReadyToPay returned {@code true}, show the button and hide the "checking" text. Otherwise,
* notify the user that Google Pay is not available. Please adjust to fit in with your current
* user flow. You are not required to explicitly let the user know if isReadyToPay returns {@code
* false}.
*
* @param available IsReadyToPay or not.
* @param available isReadyToPay API response.
*/
private void setGooglePayAvailable(boolean available) {
if (available) {
@@ -190,52 +194,45 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
* Data
*/
private void handlePaymentSuccess(PaymentData paymentData) {
String token = paymentData.toJson();
String paymentInformation = paymentData.toJson();
// Token will be null if PaymentDataRequest was not constructed using fromJson(String).
if (token != null) {
JSONObject tokenObject;
try {
tokenObject = new JSONObject(token);
// If the gateway is set to example, no payment information is returned - instead, the
// token will only consist of "examplePaymentMethodToken".
if (tokenObject
.getJSONObject("paymentMethodData")
.getJSONObject("tokenizationData")
.getString("token")
.equals("examplePaymentMethodToken")) {
AlertDialog alertDialog =
new AlertDialog.Builder(this)
.setTitle("Warning")
.setMessage(
"Gateway name set to \"example\" - please modify "
+ "Constants.java and replace it with your own gateway.")
.setPositiveButton("OK", null)
.create();
alertDialog.show();
}
String billingName =
tokenObject
.getJSONObject("paymentMethodData")
.getJSONObject("info")
.getJSONObject("billingAddress")
.getString("name");
Log.d("BillingName", billingName);
Toast.makeText(this, getString(R.string.payments_show_name, billingName), Toast.LENGTH_LONG)
.show();
if (paymentInformation == null) {
return;
}
JSONObject paymentMethodData;
// Logging token string.
Log.d(
"PaymentData",
tokenObject
.getJSONObject("paymentMethodData")
.getJSONObject("tokenizationData")
.getString("token"));
} catch (JSONException e) {
Log.e("handlePaymentSuccess failed", e.toString());
return;
try {
paymentMethodData = new JSONObject(paymentInformation).getJSONObject("paymentMethodData");
// If the gateway is set to example, no payment information is returned - instead, the
// token will only consist of "examplePaymentMethodToken".
if (paymentMethodData.getJSONObject("tokenizationData").getString("type").equals("PAYMENT_GATEWAY")
&& paymentMethodData
.getJSONObject("tokenizationData")
.getString("token")
.equals("examplePaymentMethodToken")) {
AlertDialog alertDialog =
new AlertDialog.Builder(this)
.setTitle("Warning")
.setMessage(
"Gateway name set to \"example\" - please modify "
+ "Constants.java and replace it with your own gateway.")
.setPositiveButton("OK", null)
.create();
alertDialog.show();
}
String billingName =
paymentMethodData.getJSONObject("info").getJSONObject("billingAddress").getString("name");
Log.d("BillingName", billingName);
Toast.makeText(this, getString(R.string.payments_show_name, billingName), Toast.LENGTH_LONG)
.show();
// Logging Payment Method Tokenization string.
Log.d("PaymentMethodTokenizationData", paymentMethodData.getJSONObject("tokenizationData").getString("token"));
} catch (JSONException e) {
Log.e("handlePaymentSuccess", "Error: " + e.toString());
return;
}
}
@@ -21,36 +21,47 @@
import java.util.HashMap;
import java.util.List;
/**
* This file contains several constants you must edit before proceeding.
* Please take a look at PaymentsUtil.java to see where the constants are used and to potentially
* remove ones not relevant to your integration.
*
* Required changes:
* 1. Update SUPPORTED_NETWORKS and SUPPORTED_METHODS if required (consult your processor if unsure)
* 2. Update CURRENCY_CODE to the currency you use.
* 3. Update SHIPPING_SUPPORTED_COUNTRIES to list the countries where you currently ship. If this is
* not applicable to your app, remove the relevant bits from PaymentsUtil.java.
* 4. If you're integrating with your processor / gateway directly, update GATEWAY_TOKENIZATION_NAME
* and GATEWAY_TOKENIZATION_PARAMETERS per the instructions they provided. You don't need to
* update DIRECT_TOKENIZATION_PUBLIC_KEY.
* 5. If you're using direct integration, please edit Protocol version and public key as per the
* instructions.
*/
public class Constants {
// This file contains several constants you must edit before proceeding.
//
// Please take a look at PaymentsUtil.java to see where the constants are used and to
// potentially remove ones not relevant to your integration.
// Required changes:
// 1. Update SUPPORTED_NETWORKS and SUPPORTED_METHODS if required (consult your processor if
// unsure).
// 2. Update CURRENCY_CODE to the currency you use.
// 3. Update SHIPPING_SUPPORTED_COUNTRIES to list the countries where you currently ship. If
// this is not applicable to your app, remove the relevant bits from PaymentsUtil.java.
// 4. If you're integrating with your processor / gateway directly, update
// GATEWAY_TOKENIZATION_NAME and GATEWAY_TOKENIZATION_PARAMETERS per the instructions they
// provided. You don't need to update DIRECT_TOKENIZATION_PUBLIC_KEY.
// 5. If you're using direct integration, please consult the documentation to learn about
// next steps.
// Changing this to ENVIRONMENT_PRODUCTION will make the API return real card information.
// Please refer to the documentation to read about the required steps needed to enable
// ENVIRONMENT_PRODUCTION.
/**
* Changing this to ENVIRONMENT_PRODUCTION will make the API return real card information.
* Please refer to the documentation to read about the required steps needed to enable
* ENVIRONMENT_PRODUCTION.
* @value #PAYMENTS_ENVIRONMENT
*/
public static final int PAYMENTS_ENVIRONMENT = WalletConstants.ENVIRONMENT_TEST;
// The allowed networks to be requested from the API. If the user has cards from networks not
// specified here in their account, these will not be offered for them to choose in the popup.
public static final List<String> SUPPORTED_NETWORKS =
Arrays.asList("AMEX", "DISCOVER", "JCB", "VISA", "MASTERCARD");
/**
* The allowed networks to be requested from the API. If the user has cards from networks not
* specified here in their account, these will not be offered for them to choose in the popup.
* @value #SUPPORTED_NETWORKS
*/
public static final List<String> SUPPORTED_NETWORKS = Arrays.asList(
"AMEX",
"DISCOVER",
"JCB",
"MASTERCARD",
"VISA");
/*
/**
* The Google Pay API may return cards on file on Google.com (PAN_ONLY) and/or a device token on
* an Android device authenticated with a 3-D Secure cryptogram (CRYPTOGRAM_3DS).
* @value #SUPPORTED_METHODS
*/
public static final List<String> SUPPORTED_METHODS =
Arrays.asList(
@@ -59,21 +70,33 @@
// and/or a device token on an Android device authenticated with a 3-D Secure cryptogram
"CRYPTOGRAM_3DS");
// Required by the API, but not visible to the user.
/**
* Required by the API, but not visible to the user.
* @value #CURRENCY_CODE
*/
public static final String CURRENCY_CODE = "USD";
// Supported countries for shipping (use ISO 3166-1 alpha-2 country codes).
// Relevant only when requesting a shipping address.
/**
* Supported countries for shipping (use ISO 3166-1 alpha-2 country codes).
* Relevant only when requesting a shipping address.
* @value #SHIPPING_SUPPORTED_COUNTRIES
*/
public static final List<String> SHIPPING_SUPPORTED_COUNTRIES = Arrays.asList("US", "GB");
// The name of your payment processor / gateway. Please refer to their documentation for
// more information.
/**
* The name of your payment processor / gateway. Please refer to their documentation for
* more information.
* @value #GATEWAY_TOKENIZATION_NAME
*/
public static final String GATEWAY_TOKENIZATION_NAME = "example";
// Custom parameters required by the processor / gateway.
// In many cases, your processor / gateway will only require a gatewayMerchantId.
// Please refer to your processor's documentation for more information. The number of parameters
// required and their names vary depending on the processor.
/**
* Custom parameters required by the processor / gateway.
* In many cases, your processor / gateway will only require a gatewayMerchantId.
* Please refer to your processor's documentation for more information. The number of parameters
* required and their names vary depending on the processor.
* @value #GATEWAY_TOKENIZATION_PARAMETERS
*/
public static final HashMap<String, String> GATEWAY_TOKENIZATION_PARAMETERS =
new HashMap<String, String>() {
{
@@ -83,8 +106,24 @@
}
};
// Only used for DIRECT tokenization. Can be removed when using GATEWAY tokenization.
/**
* Only used for DIRECT tokenization. Can be removed when using GATEWAY tokenization.
* @value #DIRECT_TOKENIZATION_PUBLIC_KEY
*/
public static final String DIRECT_TOKENIZATION_PUBLIC_KEY = "REPLACE_ME";
/**
* Parameters required for direct tokenization.
* Only used for DIRECT tokenization. Can be removed when using GATEWAY tokenization.
* @value #DIRECT_TOKENIZATION_PARAMETERS
*/
public static final HashMap<String, String> DIRECT_TOKENIZATION_PARAMETERS =
new HashMap<String, String>() {
{
put("protocolVersion", "ECv1");
put("publicKey", DIRECT_TOKENIZATION_PUBLIC_KEY);
}
};
private Constants() {}
}
Oops, something went wrong.

0 comments on commit 10b025a

Please sign in to comment.