use of com.braintreepayments.api.interfaces.ConfigurationListener 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.interfaces.ConfigurationListener 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.interfaces.ConfigurationListener 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);
}
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class PaymentMethod method getPaymentMethodNonces.
/**
* Retrieves the current list of {@link PaymentMethodNonce}s for the current customer.
* <p/>
* When finished, the {@link java.util.List} of {@link PaymentMethodNonce}s will be sent to {@link
* PaymentMethodNoncesUpdatedListener#onPaymentMethodNoncesUpdated(List)}.
*
* @param fragment {@link BraintreeFragment}
* @param defaultFirst when {@code true} the customer's default payment method will be first in the list, otherwise
* payment methods will be ordered my most recently used.
*/
public static void getPaymentMethodNonces(final BraintreeFragment fragment, boolean defaultFirst) {
final Uri uri = Uri.parse(TokenizationClient.versionedPath(TokenizationClient.PAYMENT_METHOD_ENDPOINT)).buildUpon().appendQueryParameter("default_first", String.valueOf(defaultFirst)).appendQueryParameter("session_id", fragment.getSessionId()).build();
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fragment.getHttpClient().get(uri.toString(), new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
fragment.postCallback(PaymentMethodNonce.parsePaymentMethodNonces(responseBody));
fragment.sendAnalyticsEvent("get-payment-methods.succeeded");
} catch (JSONException e) {
fragment.postCallback(e);
fragment.sendAnalyticsEvent("get-payment-methods.failed");
}
}
@Override
public void failure(Exception exception) {
fragment.postCallback(exception);
fragment.sendAnalyticsEvent("get-payment-methods.failed");
}
});
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class UnionPay method fetchCapabilities.
/**
* Fetches the capabilities of a card. If the card needs to be enrolled use {@link
* UnionPay#enroll(BraintreeFragment, UnionPayCardBuilder)}.
* <p/>
* On completion, returns the {@link UnionPayCapabilities} to
* {@link com.braintreepayments.api.interfaces.UnionPayListener#onCapabilitiesFetched(UnionPayCapabilities)}
* <p/>
* On error, an exception will be passed back to
* {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
*
* @param fragment {@link BraintreeFragment}
* @param cardNumber The card number to check for Union Pay capabilities.
*/
public static void fetchCapabilities(final BraintreeFragment fragment, final String cardNumber) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
if (!configuration.getUnionPay().isEnabled()) {
fragment.postCallback(new ConfigurationException("UnionPay is not enabled"));
return;
}
String fetchCapabilitiesUrl = Uri.parse(UNIONPAY_CAPABILITIES_PATH).buildUpon().appendQueryParameter("creditCard[number]", cardNumber).build().toString();
fragment.getHttpClient().get(fetchCapabilitiesUrl, new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fragment.postCallback(UnionPayCapabilities.fromJson(responseBody));
fragment.sendAnalyticsEvent("union-pay.capabilities-received");
}
@Override
public void failure(Exception exception) {
fragment.postCallback(exception);
fragment.sendAnalyticsEvent("union-pay.capabilities-failed");
}
});
}
});
}
Aggregations