Search in sources :

Example 76 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class GooglePaymentTest method getTokenizationParameters_doesNotIncludeATokenizationKeyWhenNotPresent.

@Test(timeout = 5000)
public void getTokenizationParameters_doesNotIncludeATokenizationKeyWhenNotPresent() throws Exception {
    final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), stringFromFixture("client_token.json"), mBaseConfiguration.build());
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
            assertNull(tokenizationParameters.getString("braintree:clientKey"));
            mLatch.countDown();
        }
    });
    mLatch.countDown();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeFragmentTestUtils.getFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration) BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 77 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class DataCollector method startDeviceCollector.

private static void startDeviceCollector(final BraintreeFragment fragment, final String merchantId, final String deviceSessionId, @Nullable final BraintreeResponseListener<String> listener) throws ClassNotFoundException, NumberFormatException {
    fragment.sendAnalyticsEvent("data-collector.kount.started");
    Class.forName(com.kount.api.DataCollector.class.getName());
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            final com.kount.api.DataCollector dataCollector = com.kount.api.DataCollector.getInstance();
            dataCollector.setContext(fragment.getApplicationContext());
            dataCollector.setMerchantID(Integer.parseInt(merchantId));
            dataCollector.setLocationCollectorConfig(com.kount.api.DataCollector.LocationConfig.COLLECT);
            dataCollector.setEnvironment(getDeviceCollectorEnvironment(configuration.getEnvironment()));
            dataCollector.collectForSession(deviceSessionId, new com.kount.api.DataCollector.CompletionHandler() {

                @Override
                public void completed(String sessionID) {
                    fragment.sendAnalyticsEvent("data-collector.kount.succeeded");
                    if (listener != null) {
                        listener.onResponse(sessionID);
                    }
                }

                @Override
                public void failed(String sessionID, final com.kount.api.DataCollector.Error error) {
                    fragment.sendAnalyticsEvent("data-collector.kount.failed");
                    if (listener != null) {
                        listener.onResponse(sessionID);
                    }
                }
            });
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) PayPalDataCollector(com.paypal.android.sdk.data.collector.PayPalDataCollector)

Example 78 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class DataCollector method collectDeviceData.

/**
 * Collect device information for fraud identification purposes. This should be used in conjunction
 * with a non-aggregate fraud id.
 *
 * @param fragment {@link BraintreeFragment}
 * @param merchantId The fraud merchant id from Braintree.
 * @param listener listener to be called with the device data String to send to Braintree.
 */
public static void collectDeviceData(final BraintreeFragment fragment, final String merchantId, final BraintreeResponseListener<String> listener) {
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            final JSONObject deviceData = new JSONObject();
            try {
                String clientMetadataId = getPayPalClientMetadataId(fragment.getApplicationContext());
                if (!TextUtils.isEmpty(clientMetadataId)) {
                    deviceData.put(CORRELATION_ID_KEY, clientMetadataId);
                }
            } catch (JSONException ignored) {
            }
            if (configuration.getKount().isEnabled()) {
                final String id;
                if (merchantId != null) {
                    id = merchantId;
                } else {
                    id = configuration.getKount().getKountMerchantId();
                }
                try {
                    final String deviceSessionId = UUIDHelper.getFormattedUUID();
                    startDeviceCollector(fragment, id, deviceSessionId, new BraintreeResponseListener<String>() {

                        @Override
                        public void onResponse(String sessionId) {
                            try {
                                deviceData.put(DEVICE_SESSION_ID_KEY, deviceSessionId);
                                deviceData.put(FRAUD_MERCHANT_ID_KEY, id);
                            } catch (JSONException ignored) {
                            }
                            listener.onResponse(deviceData.toString());
                        }
                    });
                } catch (ClassNotFoundException | NoClassDefFoundError | NumberFormatException ignored) {
                    listener.onResponse(deviceData.toString());
                }
            } else {
                listener.onResponse(deviceData.toString());
            }
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeResponseListener(com.braintreepayments.api.interfaces.BraintreeResponseListener) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Example 79 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class GooglePayment method requestPayment.

/**
 * Launch a Google Payments request. This method will show the payment instrument chooser to the user.
 *
 * @param fragment The current {@link BraintreeFragment}.
 * @param request The {@link GooglePaymentRequest} containing options for the transaction.
 */
public static void requestPayment(final BraintreeFragment fragment, @NonNull final GooglePaymentRequest request) {
    fragment.sendAnalyticsEvent("google-payment.selected");
    if (!validateManifest(fragment.getApplicationContext())) {
        fragment.postCallback(new BraintreeException("GooglePaymentActivity was not found in the Android " + "manifest, or did not have a theme of R.style.bt_transparent_activity"));
        fragment.sendAnalyticsEvent("google-payment.failed");
        return;
    }
    if (request == null || request.getTransactionInfo() == null) {
        fragment.postCallback(new BraintreeException("Cannot pass null TransactionInfo to requestPayment"));
        fragment.sendAnalyticsEvent("google-payment.failed");
        return;
    }
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            PaymentDataRequest.Builder paymentDataRequest = PaymentDataRequest.newBuilder().setTransactionInfo(request.getTransactionInfo()).addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_CARD).addAllowedPaymentMethod(WalletConstants.PAYMENT_METHOD_TOKENIZED_CARD).setPaymentMethodTokenizationParameters(getTokenizationParameters(fragment));
            CardRequirements.Builder cardRequirements = CardRequirements.newBuilder().addAllowedCardNetworks(getAllowedCardNetworks(fragment));
            if (request.getAllowPrepaidCards() != null) {
                cardRequirements.setAllowPrepaidCards(request.getAllowPrepaidCards());
            }
            if (request.getBillingAddressFormat() != null) {
                cardRequirements.setBillingAddressFormat(request.getBillingAddressFormat());
            }
            if (request.isBillingAddressRequired() != null) {
                cardRequirements.setBillingAddressRequired(request.isBillingAddressRequired());
            }
            paymentDataRequest.setCardRequirements(cardRequirements.build());
            if (request.isEmailRequired() != null) {
                paymentDataRequest.setEmailRequired(request.isEmailRequired());
            }
            if (request.isPhoneNumberRequired() != null) {
                paymentDataRequest.setPhoneNumberRequired(request.isPhoneNumberRequired());
            }
            if (request.isShippingAddressRequired() != null) {
                paymentDataRequest.setShippingAddressRequired(request.isShippingAddressRequired());
            }
            if (request.getShippingAddressRequirements() != null) {
                paymentDataRequest.setShippingAddressRequirements(request.getShippingAddressRequirements());
            }
            if (request.isUiRequired() != null) {
                paymentDataRequest.setUiRequired(request.isUiRequired());
            }
            fragment.sendAnalyticsEvent("google-payment.started");
            Intent intent = new Intent(fragment.getApplicationContext(), GooglePaymentActivity.class).putExtra(EXTRA_ENVIRONMENT, getEnvironment(configuration.getAndroidPay())).putExtra(EXTRA_PAYMENT_DATA_REQUEST, paymentDataRequest.build());
            fragment.startActivityForResult(intent, BraintreeRequestCodes.GOOGLE_PAYMENT);
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) AndroidPayConfiguration(com.braintreepayments.api.models.AndroidPayConfiguration) Configuration(com.braintreepayments.api.models.Configuration) MetadataBuilder(com.braintreepayments.api.models.MetadataBuilder) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) Intent(android.content.Intent)

Example 80 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class PayPal method requestOneTimePayment.

private static void requestOneTimePayment(final BraintreeFragment fragment, final PayPalRequest paypalRequest, final boolean isBillingAgreement, final PayPalApprovalHandler handler) {
    final HttpResponseCallback callback = new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            final PayPalPaymentResource paypalPaymentResource;
            try {
                paypalPaymentResource = PayPalPaymentResource.fromJson(responseBody);
            } catch (JSONException e) {
                fragment.postCallback(e);
                return;
            }
            String redirectUrl = Uri.parse(paypalPaymentResource.getRedirectUrl()).buildUpon().appendQueryParameter(USER_ACTION_KEY, paypalRequest.getUserAction()).toString();
            Request request;
            if (isBillingAgreement) {
                request = getBillingAgreementRequest(fragment, redirectUrl);
            } else {
                request = getCheckoutRequest(fragment, redirectUrl);
            }
            startPayPal(fragment, request, handler);
        }

        @Override
        public void failure(Exception e) {
            fragment.postCallback(e);
        }
    };
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            if (!configuration.isPayPalEnabled()) {
                fragment.postCallback(new BraintreeException("PayPal is not enabled"));
                return;
            }
            if (!isManifestValid(fragment)) {
                fragment.sendAnalyticsEvent("paypal.invalid-manifest");
                fragment.postCallback(new BraintreeException("BraintreeBrowserSwitchActivity missing, " + "incorrectly configured in AndroidManifest.xml or another app defines the same browser " + "switch url as this app. See " + "https://developers.braintreepayments.com/guides/client-sdk/android/v2#browser-switch " + "for the correct configuration"));
                return;
            }
            try {
                persistPayPalRequest(fragment.getApplicationContext(), paypalRequest);
                createPaymentResource(fragment, paypalRequest, isBillingAgreement, callback);
            } catch (JSONException | ErrorWithResponse | BraintreeException ex) {
                fragment.postCallback(ex);
            }
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) PayPalPaymentResource(com.braintreepayments.api.models.PayPalPaymentResource) PayPalConfiguration(com.braintreepayments.api.models.PayPalConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest) JSONException(org.json.JSONException) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) BrowserSwitchException(com.braintreepayments.api.exceptions.BrowserSwitchException)

Aggregations

Configuration (com.braintreepayments.api.models.Configuration)84 Test (org.junit.Test)66 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)19 JSONException (org.json.JSONException)19 Authorization (com.braintreepayments.api.models.Authorization)14 Intent (android.content.Intent)13 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)12 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)11 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)11 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)11 JSONObject (org.json.JSONObject)11 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 Request (com.paypal.android.sdk.onetouch.core.Request)10 Bundle (android.os.Bundle)9 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)6 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)5