Search in sources :

Example 1 with PaymentMethodTokenizationParameters

use of com.google.android.gms.wallet.PaymentMethodTokenizationParameters in project braintree_android by braintree.

the class AndroidPayTest method getTokenizationParameters_returnsCorrectParametersInCallback.

@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParametersInCallback() throws Exception {
    String config = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
    final Configuration configuration = Configuration.fromJson(config);
    BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
    AndroidPay.getTokenizationParameters(fragment, new TokenizationParametersListener() {

        @Override
        public void onResult(PaymentMethodTokenizationParameters parameters, Collection<Integer> allowedCardNetworks) {
            assertEquals("braintree", parameters.getParameters().getString("gateway"));
            assertEquals(configuration.getMerchantId(), parameters.getParameters().getString("braintree:merchantId"));
            assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), parameters.getParameters().getString("braintree:authorizationFingerprint"));
            assertEquals("v1", parameters.getParameters().getString("braintree:apiVersion"));
            assertEquals(BuildConfig.VERSION_NAME, parameters.getParameters().getString("braintree:sdkVersion"));
            try {
                JSONObject metadata = new JSONObject(parameters.getParameters().getString("braintree:metadata"));
                assertNotNull(metadata);
                assertEquals(BuildConfig.VERSION_NAME, metadata.getString("version"));
                assertNotNull(metadata.getString("sessionId"));
                assertEquals("custom", metadata.getString("integration"));
                assertEquals("android", metadata.get("platform"));
            } catch (JSONException e) {
                fail("Failed to unpack json from tokenization parameters: " + e.getMessage());
            }
            assertEquals(4, allowedCardNetworks.size());
            assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
            assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
            assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
            assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) PaymentMethodTokenizationParameters(com.google.android.gms.wallet.PaymentMethodTokenizationParameters) JSONException(org.json.JSONException) TokenizationParametersListener(com.braintreepayments.api.interfaces.TokenizationParametersListener) Test(org.junit.Test)

Example 2 with PaymentMethodTokenizationParameters

use of com.google.android.gms.wallet.PaymentMethodTokenizationParameters in project braintree_android by braintree.

the class GooglePaymentTest method getTokenizationParameters_returnsCorrectParametersInCallback.

@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParametersInCallback() throws Exception {
    String config = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
    final Configuration configuration = Configuration.fromJson(config);
    BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
    GooglePayment.getTokenizationParameters(fragment, new TokenizationParametersListener() {

        @Override
        public void onResult(PaymentMethodTokenizationParameters parameters, Collection<Integer> allowedCardNetworks) {
            assertEquals("braintree", parameters.getParameters().getString("gateway"));
            assertEquals(configuration.getMerchantId(), parameters.getParameters().getString("braintree:merchantId"));
            assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), parameters.getParameters().getString("braintree:authorizationFingerprint"));
            assertEquals("v1", parameters.getParameters().getString("braintree:apiVersion"));
            assertEquals(BuildConfig.VERSION_NAME, parameters.getParameters().getString("braintree:sdkVersion"));
            try {
                JSONObject metadata = new JSONObject(parameters.getParameters().getString("braintree:metadata"));
                assertNotNull(metadata);
                assertEquals(BuildConfig.VERSION_NAME, metadata.getString("version"));
                assertNotNull(metadata.getString("sessionId"));
                assertEquals("custom", metadata.getString("integration"));
                assertEquals("android", metadata.get("platform"));
            } catch (JSONException e) {
                fail("Failed to unpack json from tokenization parameters: " + e.getMessage());
            }
            assertEquals(4, allowedCardNetworks.size());
            assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
            assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
            assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
            assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : BraintreeFragmentTestUtils.getFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration) BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) PaymentMethodTokenizationParameters(com.google.android.gms.wallet.PaymentMethodTokenizationParameters) JSONException(org.json.JSONException) TokenizationParametersListener(com.braintreepayments.api.interfaces.TokenizationParametersListener) Test(org.junit.Test)

Example 3 with PaymentMethodTokenizationParameters

use of com.google.android.gms.wallet.PaymentMethodTokenizationParameters in project connect-sdk-client-android by Ingenico-ePayments.

the class WalletUtil method generateMaskedWalletRequest.

public static MaskedWalletRequest generateMaskedWalletRequest(PaymentContext paymentContext, ShoppingCart shoppingCart, String publicKey, Collection<Integer> networks) {
    PaymentMethodTokenizationParameters parameters = PaymentMethodTokenizationParameters.newBuilder().setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN).addParameter(Constants.PAYMENT_METHOD_TOKENIZATION_PARAMETER_PUBLIC_KEY, publicKey).build();
    MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder().setMerchantName(Constants.APPLICATION_IDENTIFIER).setShippingAddressRequired(true).setCurrencyCode(paymentContext.getAmountOfMoney().getCurrencyCode().toString()).setCart(generateCart(paymentContext, shoppingCart)).setEstimatedTotalPrice(paymentContext.getAmountOfMoney().getAmount().toString()).addAllowedCardNetworks(networks).setPaymentMethodTokenizationParameters(parameters).build();
    return maskedWalletRequest;
}
Also used : PaymentMethodTokenizationParameters(com.google.android.gms.wallet.PaymentMethodTokenizationParameters) MaskedWalletRequest(com.google.android.gms.wallet.MaskedWalletRequest)

Aggregations

PaymentMethodTokenizationParameters (com.google.android.gms.wallet.PaymentMethodTokenizationParameters)3 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)2 TokenizationParametersListener (com.braintreepayments.api.interfaces.TokenizationParametersListener)2 Configuration (com.braintreepayments.api.models.Configuration)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)1 MaskedWalletRequest (com.google.android.gms.wallet.MaskedWalletRequest)1