use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.
the class AndroidPay method requestAndroidPay.
/**
* @deprecated Android Pay is deprecated, use {@link GooglePayment} instead. For more information see the
* <a href="https://developers.braintreepayments.com/guides/pay-with-google/overview">documentation</a>
*
* Launch an Android Pay masked wallet request. This method will show the payment instrument
* chooser to the user.
*
* @param fragment The current {@link BraintreeFragment}.
* @param cart The cart representation with price, currency code, and optionally items.
* @param shippingAddressRequired {@code true} if this request requires a shipping address, {@code false} otherwise.
* @param phoneNumberRequired {@code true} if this request requires a phone number, {@code false} otherwise.
* @param allowedCountries ISO 3166-2 country codes that shipping is allowed to.
*/
@Deprecated
public static void requestAndroidPay(final BraintreeFragment fragment, @NonNull final Cart cart, final boolean shippingAddressRequired, final boolean phoneNumberRequired, final ArrayList<CountrySpecification> allowedCountries) {
fragment.sendAnalyticsEvent("android-pay.selected");
if (!validateManifest(fragment.getApplicationContext())) {
fragment.postCallback(new BraintreeException("AndroidPayActivity was not found in the Android manifest, " + "or did not have a theme of R.style.bt_transparent_activity"));
fragment.sendAnalyticsEvent("android-pay.failed");
return;
}
if (cart == null) {
fragment.postCallback(new BraintreeException("Cannot pass null cart to performMaskedWalletRequest"));
fragment.sendAnalyticsEvent("android-pay.failed");
return;
}
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fragment.sendAnalyticsEvent("android-pay.started");
Intent intent = new Intent(fragment.getApplicationContext(), AndroidPayActivity.class).putExtra(EXTRA_ENVIRONMENT, GooglePayment.getEnvironment(configuration.getAndroidPay())).putExtra(EXTRA_MERCHANT_NAME, configuration.getAndroidPay().getDisplayName()).putExtra(EXTRA_CART, cart).putExtra(EXTRA_TOKENIZATION_PARAMETERS, GooglePayment.getTokenizationParameters(fragment)).putIntegerArrayListExtra(EXTRA_ALLOWED_CARD_NETWORKS, GooglePayment.getAllowedCardNetworks(fragment)).putExtra(EXTRA_SHIPPING_ADDRESS_REQUIRED, shippingAddressRequired).putExtra(EXTRA_PHONE_NUMBER_REQUIRED, phoneNumberRequired).putParcelableArrayListExtra(EXTRA_ALLOWED_COUNTRIES, allowedCountries).putExtra(EXTRA_REQUEST_TYPE, AUTHORIZE);
fragment.startActivityForResult(intent, BraintreeRequestCodes.ANDROID_PAY);
}
});
}
use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_postsExceptionWhenNoAmountIsSet.
@Test
public void requestOneTimePayment_postsExceptionWhenNoAmountIsSet() {
BraintreeFragment fragment = mMockFragmentBuilder.build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest());
ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(fragment).postCallback(captor.capture());
assertTrue(captor.getValue() instanceof BraintreeException);
assertEquals("An amount must be specified for the Single Payment flow.", captor.getValue().getMessage());
}
use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.
the class UnionPayUnitTest method enroll_sendsAnalyticsEventOnFailure.
@Test
public void enroll_sendsAnalyticsEventOnFailure() throws JSONException {
UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder().cardNumber("some-card-number");
BraintreeFragment braintreeFragment = new MockFragmentBuilder().configuration(mConfigurationWithUnionPay).errorResponse(new BraintreeException()).build();
UnionPay.enroll(braintreeFragment, unionPayCardBuilder);
verify(braintreeFragment).sendAnalyticsEvent("union-pay.enrollment-failed");
}
use of com.braintreepayments.api.exceptions.BraintreeException 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.exceptions.BraintreeException 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