Search in sources :

Example 1 with ThreeDSecureRequest

use of com.braintreepayments.api.models.ThreeDSecureRequest 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 2 with ThreeDSecureRequest

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

the class ThreeDSecureTest method performVerification_withInvalidThreeDSecureRequest_postsException.

@Test(timeout = 1000)
public void performVerification_withInvalidThreeDSecureRequest_postsException() throws InterruptedException, InvalidArgumentException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("The ThreeDSecureRequest nonce and amount cannot be null", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureRequest request = new ThreeDSecureRequest().amount("5");
    ThreeDSecure.performVerification(fragment, request);
    mCountDownLatch.await();
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 3 with ThreeDSecureRequest

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

the class ThreeDSecure method performVerification.

/**
 * Verification is associated with a transaction amount and your merchant account. To specify a
 * different merchant account (or, in turn, currency), you will need to specify the merchant
 * account id when <a href="https://developers.braintreepayments.com/android/sdk/overview/generate-client-token">
 *     generating a client token</a>
 *
 * During lookup the original payment method nonce is consumed and a new one is returned,
 * which points to the original payment method, as well as the 3D Secure verification.
 * Transactions created with this nonce will be 3D Secure, and benefit from the appropriate
 * liability shift if authentication is successful or fail with a 3D Secure failure.
 *
 * @param fragment the {@link BraintreeFragment} backing the http request. This fragment will
 *                  also be responsible for handling callbacks to it's listeners
 * @param nonce The nonce that represents a card to perform a 3D Secure verification against.
 * @param amount The amount of the transaction in the current merchant account's currency.
 */
public static void performVerification(final BraintreeFragment fragment, final String nonce, final String amount) {
    ThreeDSecureRequest request = new ThreeDSecureRequest().nonce(nonce).amount(amount);
    performVerification(fragment, request);
}
Also used : ThreeDSecureRequest(com.braintreepayments.api.models.ThreeDSecureRequest)

Aggregations

ThreeDSecureRequest (com.braintreepayments.api.models.ThreeDSecureRequest)3 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)2 Test (org.junit.Test)2 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)1 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)1 CardBuilder (com.braintreepayments.api.models.CardBuilder)1 CardNonce (com.braintreepayments.api.models.CardNonce)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 ThreeDSecureInfo (com.braintreepayments.api.models.ThreeDSecureInfo)1 JSONException (org.json.JSONException)1