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();
}
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);
}
}
});
}
});
}
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());
}
}
});
}
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);
}
});
}
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);
}
}
});
}
Aggregations