From a96c31a1a45dd81e212bafe7a022efd2f783c3db Mon Sep 17 00:00:00 2001 From: Rainer Schleevoigt Date: Sun, 8 Oct 2017 14:33:52 +0200 Subject: [PATCH 1/3] Update ReactNativePaymentsModule.java new methods: setTheme(int Theme); setLightTheme(); setDarkTheme(); addAllowedCardNetwork(); --- .../ReactNativePaymentsModule.java | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java b/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java index a47b50d4..150080d5 100644 --- a/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java +++ b/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java @@ -54,6 +54,10 @@ public class ReactNativePaymentsModule extends ReactContextBaseJavaModule implem public static final String REACT_CLASS = "ReactNativePayments"; + private int theme = WalletConstants.THEME_LIGHT; + + private ArrayList cardNetworks = new ArrayList(); + private static ReactApplicationContext reactContext = null; private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() { @@ -141,8 +145,42 @@ public String getName() { return REACT_CLASS; } + + + @Override public Map getConstants() { + final Map constants = new HashMap<>(); + constants.put("CARD_NETWORK_AMEX", WalletConstants.CARD_NETWORK_AMEX); + constants.put("CARD_NETWORK_MASTERCARD", WalletConstants.CARD_NETWORK_MASTERCARD); + constants.put("CARD_NETWORK_VISA", WalletConstants.CARD_NETWORK_VISA); + constants.put("CARD_NETWORK_DISCOVER", WalletConstants.CARD_NETWORK_DISCOVER); + constants.put("CARD_NETWORK_INTERAC", WalletConstants.CARD_NETWORK_INTERAC); + constants.put("CARD_NETWORK_JCB", WalletConstants.CARD_NETWORK_JCB); + constants.put("THEME_DARK", WalletConstants.THEME_DARK); + constants.put("THEME_LIGHT", WalletConstants.THEME_LIGHT); + return constants; + } + + // Public Methods // --------------------------------------------------------------------------------------------- + @ReactMethod + public void setTheme(int theme) { + if (theme == WalletConstants.THEME_LIGHT || theme == WalletConstants.THEME_DARK); + this.theme = theme; + } + @ReactMethod + public void setLightTheme(int theme) { + this.theme = WalletConstants.THEME_LIGHT; + } + @ReactMethod + public void setDarkTheme(int theme) { + this.theme = WalletConstants.THEME_DARK; + } + @ReactMethod + public void addAllowedCardNetwork(int network) { + cardNetworks.add(network); + } + @ReactMethod public void getSupportedGateways(Callback errorCallback, Callback successCallback) { WritableNativeArray supportedGateways = new WritableNativeArray(); @@ -153,10 +191,12 @@ public void getSupportedGateways(Callback errorCallback, Callback successCallbac @ReactMethod public void canMakePayments(ReadableMap paymentMethodData, Callback errorCallback, Callback successCallback) { final Callback callback = successCallback; - IsReadyToPayRequest req = IsReadyToPayRequest.newBuilder() - .addAllowedCardNetwork(WalletConstants.CardNetwork.MASTERCARD) - .addAllowedCardNetwork(WalletConstants.CardNetwork.VISA) - .build(); + + IsReadyToPayRequest.Builder builder = IsReadyToPayRequest.newBuilder(); + for (int network :cardNetworks) { + builder.addAllowedCardNetwork(network); + } + IsReadyToPayRequest req = builder.build(); int environment = getEnvironmentFromPaymentMethodData(paymentMethodData); if (mGoogleApiClient == null) { @@ -344,7 +384,7 @@ private void buildGoogleApiClient(Activity currentActivity, int environment) { .addOnConnectionFailedListener(this) .addApi(Wallet.API, new Wallet.WalletOptions.Builder() .setEnvironment(environment) - .setTheme(WalletConstants.THEME_LIGHT) + .setTheme(theme) .build()) .build(); mGoogleApiClient.connect(); From ea26ed6c61407907c9879a7d04b7eb01da7ff35b Mon Sep 17 00:00:00 2001 From: Rainer Schleevoigt Date: Fri, 13 Oct 2017 15:19:48 +0200 Subject: [PATCH 2/3] Update ReactNativePaymentsModule.java --- .../ReactNativePaymentsModule.java | 99 ++++++++++++------- 1 file changed, 66 insertions(+), 33 deletions(-) diff --git a/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java b/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java index 150080d5..a76bbe31 100644 --- a/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java +++ b/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java @@ -21,7 +21,19 @@ import com.google.android.gms.common.api.ResultCallback; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.identity.intents.model.UserAddress; -import com.google.android.gms.wallet.*; +import com.google.android.gms.wallet.Cart; +import com.google.android.gms.wallet.FullWallet; +import com.google.android.gms.wallet.FullWalletRequest; +import com.google.android.gms.wallet.MaskedWallet; +import com.google.android.gms.wallet.MaskedWalletRequest; +import com.google.android.gms.wallet.PaymentMethodTokenizationParameters; +import com.google.android.gms.wallet.PaymentMethodTokenizationType; +import com.google.android.gms.wallet.Wallet; +import com.google.android.gms.wallet.WalletConstants; +import com.google.android.gms.wallet.IsReadyToPayRequest; +import com.google.android.gms.wallet.LineItem; + + import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.BaseActivityEventListener; @@ -149,14 +161,24 @@ public String getName() { @Override public Map getConstants() { final Map constants = new HashMap<>(); - constants.put("CARD_NETWORK_AMEX", WalletConstants.CARD_NETWORK_AMEX); - constants.put("CARD_NETWORK_MASTERCARD", WalletConstants.CARD_NETWORK_MASTERCARD); - constants.put("CARD_NETWORK_VISA", WalletConstants.CARD_NETWORK_VISA); - constants.put("CARD_NETWORK_DISCOVER", WalletConstants.CARD_NETWORK_DISCOVER); - constants.put("CARD_NETWORK_INTERAC", WalletConstants.CARD_NETWORK_INTERAC); - constants.put("CARD_NETWORK_JCB", WalletConstants.CARD_NETWORK_JCB); + constants.put("ENVIRONMENT_TEST", WalletConstants.ENVIRONMENT_TEST); + constants.put("ENVIRONMENT_PRODUCTION", WalletConstants.ENVIRONMENT_PRODUCTION); + constants.put("THEME_DARK", WalletConstants.THEME_DARK); constants.put("THEME_LIGHT", WalletConstants.THEME_LIGHT); + + constants.put("CARD_NETWORK_AMEX", WalletConstants.CardNetwork.AMEX); + constants.put("CARD_NETWORK_MASTERCARD", WalletConstants.CardNetwork.MASTERCARD); + constants.put("CARD_NETWORK_VISA", WalletConstants.CardNetwork.VISA); + constants.put("CARD_NETWORK_DISCOVER", WalletConstants.CardNetwork.DISCOVER); + constants.put("CARD_NETWORK_INTERAC", WalletConstants.CardNetwork.INTERAC); + constants.put("CARD_NETWORK_JCB", WalletConstants.CardNetwork.JCB); + constants.put("CARD_NETWORK_OTHER", WalletConstants.CardNetwork.OTHER); + + constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY", PaymentMethodTokenizationType.PAYMENT_GATEWAY); // Adyen,Braintree,Stripe,Vantiv + constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_NETWORK_TOKEN", PaymentMethodTokenizationType.NETWORK_TOKEN); + constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT", WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT); + return constants; } @@ -291,33 +313,44 @@ public void getFullWalletAndroid( // --------------------------------------------------------------------------------------------- private static PaymentMethodTokenizationParameters buildTokenizationParametersFromPaymentMethodData(ReadableMap paymentMethodData) { ReadableMap tokenizationParameters = paymentMethodData.getMap("paymentMethodTokenizationParameters"); - String tokenizationType = tokenizationParameters.getString("tokenizationType"); - - - if (tokenizationType.equals("GATEWAY_TOKEN")) { - ReadableMap parameters = tokenizationParameters.getMap("parameters"); - PaymentMethodTokenizationParameters.Builder parametersBuilder = PaymentMethodTokenizationParameters.newBuilder() - .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY) - .addParameter("gateway", parameters.getString("gateway")); - - ReadableMapKeySetIterator iterator = parameters.keySetIterator(); - - while (iterator.hasNextKey()) { - String key = iterator.nextKey(); - - parametersBuilder.addParameter(key, parameters.getString(key)); - } - - return parametersBuilder.build(); + String publicKey = ""; + switch( tokenizationParameters.getString("tokenizationType")) { + case WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT: + publicKey = tokenizationParameters.getMap("parameters").getString("publicKey"); + return PaymentMethodTokenizationParameters.newBuilder() + .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_DIRECT) + .addParameter("publicKey", publicKey) + .build(); + + break; + case PaymentMethodTokenizationType.PAYMENT_GATEWAY: + ReadableMap parameters = tokenizationParameters.getMap("parameters"); + PaymentMethodTokenizationParameters.Builder parametersBuilder = PaymentMethodTokenizationParameters.newBuilder() + .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY) + .addParameter("gateway", parameters.getString("gateway")); + + ReadableMapKeySetIterator iterator = parameters.keySetIterator(); + while (iterator.hasNextKey()) { + String key = iterator.nextKey(); + + parametersBuilder.addParameter(key, parameters.getString(key)); + } + + return parametersBuilder.build(); + break; + case PaymentMethodTokenizationType.NETWORK_TOKEN: + publicKey = tokenizationParameters.getMap("parameters").getString("publicKey"); + + return PaymentMethodTokenizationParameters.newBuilder() + .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN) + .addParameter("publicKey", publicKey) + .build(); + break; + default: + // TODO warning + } - } else { - String publicKey = tokenizationParameters.getMap("parameters").getString("publicKey"); - return PaymentMethodTokenizationParameters.newBuilder() - .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN) - .addParameter("publicKey", publicKey) - .build(); - } } private static List buildLineItems(ReadableArray displayItems) { @@ -371,7 +404,7 @@ private void sendEvent( } private int getEnvironmentFromPaymentMethodData(ReadableMap paymentMethodData) { - return paymentMethodData.hasKey("environment") && paymentMethodData.getString("environment").equals("TEST") + return paymentMethodData.hasKey("environment") && paymentMethodData.getInt("environment") == WalletConstants.ENVIRONMENT_TEST ? WalletConstants.ENVIRONMENT_TEST : WalletConstants.ENVIRONMENT_PRODUCTION; } From 3b688e91ec690a7ea9154cdff5506a5652a7c237 Mon Sep 17 00:00:00 2001 From: Rainer Schleevoigt Date: Fri, 13 Oct 2017 15:25:59 +0200 Subject: [PATCH 3/3] Update ReactNativePaymentsModule.java --- .../reactnativepayments/ReactNativePaymentsModule.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java b/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java index a76bbe31..40833e9c 100644 --- a/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java +++ b/packages/react-native-payments/android/src/main/java/com/reactnativepayments/ReactNativePaymentsModule.java @@ -177,7 +177,7 @@ public String getName() { constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY", PaymentMethodTokenizationType.PAYMENT_GATEWAY); // Adyen,Braintree,Stripe,Vantiv constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_NETWORK_TOKEN", PaymentMethodTokenizationType.NETWORK_TOKEN); - constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT", WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT); + // constants.put("PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT", WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT); return constants; } @@ -315,15 +315,15 @@ private static PaymentMethodTokenizationParameters buildTokenizationParametersFr ReadableMap tokenizationParameters = paymentMethodData.getMap("paymentMethodTokenizationParameters"); String publicKey = ""; switch( tokenizationParameters.getString("tokenizationType")) { - case WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT: + /*case WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_DIRECT: publicKey = tokenizationParameters.getMap("parameters").getString("publicKey"); return PaymentMethodTokenizationParameters.newBuilder() .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_DIRECT) .addParameter("publicKey", publicKey) .build(); - break; - case PaymentMethodTokenizationType.PAYMENT_GATEWAY: + break;*/ + case PaymentMethodTokenizationType.PAYMENT_GATEWAY: ReadableMap parameters = tokenizationParameters.getMap("parameters"); PaymentMethodTokenizationParameters.Builder parametersBuilder = PaymentMethodTokenizationParameters.newBuilder() .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)