Search in sources :

Example 21 with PaymentMethodNonceCallback

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCallback in project braintree_android by braintree.

the class PayPal method onSuccess.

private static void onSuccess(final BraintreeFragment fragment, Intent data, Request request, Result result) {
    PayPalRequest paypalRequest = getPersistedPayPalRequest(fragment.getApplicationContext());
    TokenizationClient.tokenize(fragment, parseResponse(paypalRequest, request, result, data), new PaymentMethodNonceCallback() {

        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            if (paymentMethodNonce instanceof PayPalAccountNonce && ((PayPalAccountNonce) paymentMethodNonce).getCreditFinancing() != null) {
                fragment.sendAnalyticsEvent("paypal.credit.accepted");
            }
            fragment.postCallback(paymentMethodNonce);
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
        }
    });
}
Also used : PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) BrowserSwitchException(com.braintreepayments.api.exceptions.BrowserSwitchException)

Example 22 with PaymentMethodNonceCallback

use of com.braintreepayments.api.interfaces.PaymentMethodNonceCallback in project braintree_android by braintree.

the class Venmo method vault.

private static void vault(final BraintreeFragment fragment, String nonce) {
    VenmoAccountBuilder vaultBuilder = new VenmoAccountBuilder().nonce(nonce);
    TokenizationClient.tokenize(fragment, vaultBuilder, new PaymentMethodNonceCallback() {

        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            fragment.postCallback(paymentMethodNonce);
            fragment.sendAnalyticsEvent("pay-with-venmo.vault.success");
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
            fragment.sendAnalyticsEvent("pay-with-venmo.vault.failed");
        }
    });
}
Also used : VenmoAccountBuilder(com.braintreepayments.api.models.VenmoAccountBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) AppSwitchNotAvailableException(com.braintreepayments.api.exceptions.AppSwitchNotAvailableException) JSONException(org.json.JSONException)

Aggregations

PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)22 InvocationOnMock (org.mockito.invocation.InvocationOnMock)17 Answer (org.mockito.stubbing.Answer)17 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)17 Test (org.junit.Test)16 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)15 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)14 Intent (android.content.Intent)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 JSONObject (org.json.JSONObject)12 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)11 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)8 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)6 JSONException (org.json.JSONException)6 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)3 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)3 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)3 Request (com.paypal.android.sdk.onetouch.core.Request)3 SharedPreferences (android.content.SharedPreferences)2