Search in sources :

Example 6 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class ThreeDSecureTest method performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.

@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException, InvalidArgumentException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    String nonce = tokenize(fragment, new CardBuilder().cardNumber("4000000000000051").expirationDate("12/20")).getNonce();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo());
            ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
            assertFalse(threeDSecureInfo.isLiabilityShifted());
            assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureRequest request = new ThreeDSecureRequest().nonce(nonce).amount("5");
    ThreeDSecure.performVerification(fragment, request);
    mCountDownLatch.await();
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest) CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) ThreeDSecureInfo(com.braintreepayments.api.models.ThreeDSecureInfo) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 7 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class TokenizationClientTest method tokenize_tokenizesAPayPalAccountWithATokenizationKey.

@Test(timeout = 10000)
public void tokenize_tokenizesAPayPalAccountWithATokenizationKey() throws InterruptedException, JSONException {
    final CountDownLatch latch = new CountDownLatch(1);
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, TOKENIZATION_KEY);
    JSONObject otcJson = new JSONObject(FixturesHelper.stringFromFixture("paypal_otc_response.json"));
    PayPalAccountBuilder paypalAccountBuilder = new PayPalAccountBuilder().oneTouchCoreData(otcJson);
    TokenizationClient.tokenize(fragment, paypalAccountBuilder, new PaymentMethodNonceCallback() {

        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            assertEquals("PayPal", paymentMethodNonce.getTypeLabel());
            latch.countDown();
        }

        @Override
        public void failure(Exception exception) {
            fail(exception.getMessage());
        }
    });
    latch.await();
}
Also used : JSONObject(org.json.JSONObject) PayPalAccountBuilder(com.braintreepayments.api.models.PayPalAccountBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) JSONException(org.json.JSONException) Test(org.junit.Test)

Example 8 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class BraintreeFragmentTestUtils method tokenize.

public static CardNonce tokenize(BraintreeFragment fragment, CardBuilder cardBuilder) {
    final CountDownLatch latch = new CountDownLatch(1);
    final CardNonce[] cardNonce = new CardNonce[1];
    PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            cardNonce[0] = (CardNonce) paymentMethodNonce;
            latch.countDown();
        }
    };
    fragment.addListener(listener);
    Card.tokenize(fragment, cardBuilder);
    try {
        latch.await();
    } catch (InterruptedException ignored) {
    }
    fragment.removeListener(listener);
    return cardNonce[0];
}
Also used : CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) CountDownLatch(java.util.concurrent.CountDownLatch) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce)

Example 9 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class BraintreeFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    if (mContext == null) {
        mContext = getActivity().getApplicationContext();
    }
    mNewActivityNeedsConfiguration = false;
    mCrashReporter = CrashReporter.setup(this);
    mSessionId = getArguments().getString(EXTRA_SESSION_ID);
    mIntegrationType = getArguments().getString(EXTRA_INTEGRATION_TYPE);
    mAuthorization = getArguments().getParcelable(EXTRA_AUTHORIZATION_TOKEN);
    mAnalyticsDatabase = AnalyticsDatabase.getInstance(getApplicationContext());
    if (mHttpClient == null) {
        mHttpClient = new BraintreeHttpClient(mAuthorization);
    }
    if (savedInstanceState != null) {
        List<PaymentMethodNonce> paymentMethodNonces = savedInstanceState.getParcelableArrayList(EXTRA_CACHED_PAYMENT_METHOD_NONCES);
        if (paymentMethodNonces != null) {
            mCachedPaymentMethodNonces.addAll(paymentMethodNonces);
        }
        mHasFetchedPaymentMethodNonces = savedInstanceState.getBoolean(EXTRA_FETCHED_PAYMENT_METHOD_NONCES);
        try {
            setConfiguration(Configuration.fromJson(savedInstanceState.getString(EXTRA_CONFIGURATION)));
        } catch (JSONException ignored) {
        }
    } else {
        if (mAuthorization instanceof TokenizationKey) {
            sendAnalyticsEvent("started.client-key");
        } else {
            sendAnalyticsEvent("started.client-token");
        }
    }
    fetchConfiguration();
}
Also used : TokenizationKey(com.braintreepayments.api.models.TokenizationKey) JSONException(org.json.JSONException) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreeHttpClient(com.braintreepayments.api.internal.BraintreeHttpClient)

Example 10 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class BraintreeFragment method postCallback.

protected void postCallback(final PaymentMethodNonce paymentMethodNonce) {
    if (paymentMethodNonce instanceof AndroidPayCardNonce) {
        for (PaymentMethodNonce cachedPaymentMethodNonce : new ArrayList<>(mCachedPaymentMethodNonces)) {
            if (cachedPaymentMethodNonce instanceof AndroidPayCardNonce) {
                mCachedPaymentMethodNonces.remove(cachedPaymentMethodNonce);
            }
        }
    }
    mCachedPaymentMethodNonces.add(0, paymentMethodNonce);
    postOrQueueCallback(new QueuedCallback() {

        @Override
        public boolean shouldRun() {
            return mPaymentMethodNonceCreatedListener != null;
        }

        @Override
        public void run() {
            mPaymentMethodNonceCreatedListener.onPaymentMethodNonceCreated(paymentMethodNonce);
        }
    });
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) ArrayList(java.util.ArrayList) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) QueuedCallback(com.braintreepayments.api.interfaces.QueuedCallback)

Aggregations

PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)38 Test (org.junit.Test)31 CardNonce (com.braintreepayments.api.models.CardNonce)22 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)21 CardBuilder (com.braintreepayments.api.models.CardBuilder)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)8 JSONException (org.json.JSONException)7 Intent (android.content.Intent)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)5 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)5 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)5 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)4 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)4 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)4 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 ArrayList (java.util.ArrayList)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)3 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3