Search in sources :

Example 11 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.

the class PayPal method requestBillingAgreement.

/**
 * Starts the Billing Agreement flow for PayPal with custom PayPal approval handler.
 *
 * @param fragment A {@link BraintreeFragment} used to process the request.
 * @param request A {@link PayPalRequest} used to customize the request.
 * @param handler A {@link PayPalApprovalHandler} for custom approval handling.
 */
public static void requestBillingAgreement(BraintreeFragment fragment, PayPalRequest request, PayPalApprovalHandler handler) {
    if (request.getAmount() == null) {
        fragment.sendAnalyticsEvent("paypal.billing-agreement.selected");
        if (request.shouldOfferCredit()) {
            fragment.sendAnalyticsEvent("paypal.billing-agreement.credit.offered");
        }
        requestOneTimePayment(fragment, request, true, handler);
    } else {
        fragment.postCallback(new BraintreeException("There must be no amount specified for the Billing Agreement flow"));
    }
}
Also used : BraintreeException(com.braintreepayments.api.exceptions.BraintreeException)

Example 12 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.

the class CardBuilder method buildGraphQL.

protected void buildGraphQL(Context context, JSONObject base, JSONObject input) throws BraintreeException, JSONException {
    try {
        base.put(GraphQLQueryHelper.QUERY_KEY, GraphQLQueryHelper.getQuery(context, R.raw.tokenize_credit_card_mutation));
    } catch (Resources.NotFoundException | IOException e) {
        throw new BraintreeException("Unable to read GraphQL query", e);
    }
    base.put(OPERATION_NAME_KEY, "TokenizeCreditCard");
    JSONObject creditCard = new JSONObject().put(NUMBER_KEY, mCardnumber).put(EXPIRATION_MONTH_KEY, mExpirationMonth).put(EXPIRATION_YEAR_KEY, mExpirationYear).put(CVV_KEY, mCvv).put(CARDHOLDER_NAME_KEY, mCardholderName);
    JSONObject billingAddress = new JSONObject().put(FIRST_NAME_KEY, mFirstName).put(LAST_NAME_KEY, mLastName).put(COMPANY_KEY, mCompany).put(COUNTRY_CODE_KEY, mCountryCode).put(COUNTRY_NAME_KEY, mCountryName).put(COUNTRY_CODE_ALPHA2_KEY, mCountryCodeAlpha2).put(COUNTRY_CODE_ALPHA3_KEY, mCountryCodeAlpha3).put(COUNTRY_CODE_NUMERIC_KEY, mCountryCodeNumeric).put(LOCALITY_KEY, mLocality).put(POSTAL_CODE_KEY, mPostalCode).put(REGION_KEY, mRegion).put(STREET_ADDRESS_KEY, mStreetAddress).put(EXTENDED_ADDRESS_KEY, mExtendedAddress);
    if (billingAddress.length() > 0) {
        creditCard.put(BILLING_ADDRESS_KEY, billingAddress);
    }
    input.put(CREDIT_CARD_KEY, creditCard);
}
Also used : JSONObject(org.json.JSONObject) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) IOException(java.io.IOException)

Aggregations

BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)12 JSONException (org.json.JSONException)4 Test (org.junit.Test)4 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)3 Configuration (com.braintreepayments.api.models.Configuration)3 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Intent (android.content.Intent)2 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)2 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)2 Context (android.content.Context)1 Resources (android.content.res.Resources)1 NotFoundException (android.content.res.Resources.NotFoundException)1 Uri (android.net.Uri)1 BrowserSwitchException (com.braintreepayments.api.exceptions.BrowserSwitchException)1 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 AndroidPayConfiguration (com.braintreepayments.api.models.AndroidPayConfiguration)1 MetadataBuilder (com.braintreepayments.api.models.MetadataBuilder)1 PayPalConfiguration (com.braintreepayments.api.models.PayPalConfiguration)1 PayPalPaymentResource (com.braintreepayments.api.models.PayPalPaymentResource)1