Search in sources :

Example 11 with CardBuilder

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

the class CardTest method tokenize_tokenizesACardWithACompleteBillingAddress.

@Test(timeout = 10000)
public void tokenize_tokenizesACardWithACompleteBillingAddress() throws Exception {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").cvv("123").cardholderName("Joe Smith").firstName("Joe").lastName("Smith").company("Company").streetAddress("1 Main St").extendedAddress("Unit 1").locality("Some Town").postalCode("12345").region("Some Region").countryName("United States").countryCodeAlpha2("US").countryCodeAlpha3("USA").countryCodeNumeric("840");
    assertTokenizationSuccessful(new TestClientTokenBuilder().build(), cardBuilder);
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) Test(org.junit.Test)

Example 12 with CardBuilder

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

the class TokenizationClient method tokenize.

/**
 * Create a {@link PaymentMethodNonce} in the Braintree Gateway.
 * <p/>
 * On completion, returns the {@link PaymentMethodNonce} to {@link PaymentMethodNonceCallback}.
 * <p/>
 * If creation fails validation, {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
 * will be called with the resulting {@link ErrorWithResponse}.
 * <p/>
 * If an error not due to validation (server error, network issue, etc.) occurs, {@link
 * com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)} (Throwable)}
 * will be called with the {@link Exception} that occurred.
 *
 * @param paymentMethodBuilder {@link PaymentMethodBuilder} for the {@link PaymentMethodNonce}
 *        to be created.
 */
static void tokenize(final BraintreeFragment fragment, final PaymentMethodBuilder paymentMethodBuilder, final PaymentMethodNonceCallback callback) {
    paymentMethodBuilder.setSessionId(fragment.getSessionId());
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            if (paymentMethodBuilder instanceof CardBuilder && configuration.getGraphQL().isFeatureEnabled(GraphQLConfiguration.TOKENIZE_CREDIT_CARDS_FEATURE)) {
                tokenizeGraphQL(fragment, (CardBuilder) paymentMethodBuilder, callback);
            } else {
                tokenizeRest(fragment, paymentMethodBuilder, callback);
            }
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) CardBuilder(com.braintreepayments.api.models.CardBuilder) GraphQLConfiguration(com.braintreepayments.api.models.GraphQLConfiguration) Configuration(com.braintreepayments.api.models.Configuration)

Example 13 with CardBuilder

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

the class ThreeDSecureVerificationTest method performVerification_returnsAFailedAuthenticationWhenSignatureVerificationFails.

@Test(timeout = 30000)
public void performVerification_returnsAFailedAuthenticationWhenSignatureVerificationFails() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Failed to authenticate, please try a different form of payment.", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_SIGNATURE_VERIFICATION_FAILURE).expirationDate("12/30");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    waitForView(withId(android.R.id.widget_frame));
    clickWebViewText("Password:");
    onDevice().pressTab().typeText("1234");
    clickWebViewText("Submit");
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 14 with CardBuilder

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

the class ThreeDSecureVerificationTest method performVerification_callsCancelListenerWhenBackIsPressed.

@Test(timeout = 30000)
public void performVerification_callsCancelListenerWhenBackIsPressed() throws InterruptedException {
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_VERIFICATON).expirationDate("12/30");
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
            assertEquals(BraintreeRequestCodes.THREE_D_SECURE, requestCode);
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    waitForView(withId(android.R.id.widget_frame));
    pressBack();
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) Test(org.junit.Test)

Example 15 with CardBuilder

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

the class ThreeDSecureVerificationTest method performVerification_failsWithATokenizationKey.

@Test(timeout = 10000)
public void performVerification_failsWithATokenizationKey() throws InterruptedException {
    String clientToken = new TestClientTokenBuilder().withThreeDSecure().build();
    BraintreeFragment fragment = getFragment(TOKENIZATION_KEY, clientToken);
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof AuthorizationException);
            assertEquals("Tokenization key authorization not allowed for this endpoint. Please use an authentication method with upgraded permissions", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_VERIFICATON).expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) TestClientTokenBuilder(com.braintreepayments.api.test.TestClientTokenBuilder) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) AuthorizationException(com.braintreepayments.api.exceptions.AuthorizationException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Aggregations

CardBuilder (com.braintreepayments.api.models.CardBuilder)41 Test (org.junit.Test)39 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)15 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)14 CardNonce (com.braintreepayments.api.models.CardNonce)12 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)11 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)10 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)10 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)7 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JSONException (org.json.JSONException)5 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)3 Matchers.anyString (org.mockito.Matchers.anyString)3 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)2 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)2 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)2 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)2 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1