Java Code Examples for com.braintreepayments.api.models.CardNonce#fromJson()

The following examples show how to use com.braintreepayments.api.models.CardNonce#fromJson() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void isParcelable() throws JSONException {
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));
    DropInResult result = new DropInResult()
            .paymentMethodNonce(cardNonce)
            .deviceData("device_data");
    Parcel parcel = Parcel.obtain();
    result.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    DropInResult parceled = DropInResult.CREATOR.createFromParcel(parcel);

    assertEquals(PaymentMethodType.VISA, parceled.getPaymentMethodType());
    assertEquals(cardNonce.getNonce(), parceled.getPaymentMethodNonce().getNonce());
    assertEquals("device_data", parceled.getDeviceData());
}
 
Example 2
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void onPaymentMethodNonceCreated_requestsThreeDSecureVerificationForCardWhenEnabled()
        throws Exception {
    PackageManager packageManager = mockPackageManagerSupportsThreeDSecure();
    Context context = spy(RuntimeEnvironment.application);
    when(context.getPackageManager()).thenReturn(packageManager);
    mActivity.context = context;
    mActivity.setDropInRequest(new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .amount("1.00")
            .requestThreeDSecureVerification(true));
    mActivity.httpClient = spy(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder()
                    .threeDSecureEnabled(true)
                    .build()));
    mActivityController.setup();
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));

    mActivity.onPaymentMethodNonceCreated(cardNonce);

    verify(mActivity.httpClient).post(matches(BraintreeUnitTestHttpClient.THREE_D_SECURE_LOOKUP),
            anyString(), any(HttpResponseCallback.class));
}
 
Example 3
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void onPaymentMethodNonceCreated_returnsDeviceData() throws JSONException {
    mActivity.mDropInRequest = new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .collectDeviceData(true);
    mActivity.httpClient = new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder().build());
    mActivityController.setup();
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));

    mActivity.onPaymentMethodNonceCreated(cardNonce);

    assertTrue(mActivity.isFinishing());
    assertEquals(RESULT_OK, mShadowActivity.getResultCode());
    DropInResult result = mShadowActivity.getResultIntent()
            .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
    assertNotNull(result.getDeviceData());
}
 
Example 4
Source File: BaseActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void finish_finishesWithPaymentMethodNonceAndDeviceDataInDropInResult()
        throws JSONException {
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));
    setup(new DropInRequest()
            .tokenizationKey(TOKENIZATION_KEY)
            .getIntent(RuntimeEnvironment.application));

    mActivity.finish(cardNonce, "device_data");

    ShadowActivity shadowActivity = shadowOf(mActivity);
    assertTrue(mActivity.isFinishing());
    assertEquals(RESULT_OK, shadowActivity.getResultCode());
    DropInResult result = shadowActivity.getResultIntent()
            .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
    assertNotNull(result);
    assertEquals(cardNonce.getNonce(), result.getPaymentMethodNonce().getNonce());
    assertEquals("device_data", result.getDeviceData());
}
 
Example 5
Source File: DropInResultUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void paymentMethodNonce_setsPaymentMethodTypeAndNonce() throws JSONException {
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));
    DropInResult result = new DropInResult()
            .paymentMethodNonce(cardNonce);

    assertEquals(PaymentMethodType.VISA, result.getPaymentMethodType());
    assertEquals(cardNonce, result.getPaymentMethodNonce());
}
 
Example 6
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void onCancel_reloadsPaymentMethodsIfThreeDSecureWasRequestedPreviously()
        throws Exception {
    PackageManager packageManager = mockPackageManagerSupportsThreeDSecure();
    Context context = spy(RuntimeEnvironment.application);
    when(context.getPackageManager()).thenReturn(packageManager);
    mActivity.context = context;
    mActivity.setDropInRequest(new DropInRequest()
            .clientToken(base64EncodedClientTokenFromFixture("client_token.json"))
            .amount("1.00")
            .requestThreeDSecureVerification(true));
    mActivity.httpClient = spy(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder()
                    .threeDSecureEnabled(true)
                    .build())
            .successResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS,
                    stringFromFixture("responses/get_payment_methods_two_cards_response.json")));
    mActivityController.setup();
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));

    mActivity.onPaymentMethodNonceCreated(cardNonce);
    mActivity.onCancel(BraintreeRequestCodes.THREE_D_SECURE);

    verify(mActivity.httpClient, times(2)).get(matches(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS),
            any(HttpResponseCallback.class));
}
 
Example 7
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void onError_reloadsPaymentMethodsIfThreeDSecureWasRequestedPreviously()
        throws Exception {
    PackageManager packageManager = mockPackageManagerSupportsThreeDSecure();
    Context context = spy(RuntimeEnvironment.application);
    when(context.getPackageManager()).thenReturn(packageManager);
    mActivity.context = context;
    mActivity.setDropInRequest(new DropInRequest()
            .clientToken(base64EncodedClientTokenFromFixture("client_token.json"))
            .amount("1.00")
            .requestThreeDSecureVerification(true));
    mActivity.httpClient = spy(new BraintreeUnitTestHttpClient()
            .configuration(new TestConfigurationBuilder()
                    .threeDSecureEnabled(true)
                    .build())
            .successResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS,
                    stringFromFixture("responses/get_payment_methods_two_cards_response.json")));
    mActivityController.setup();
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));

    mActivity.onPaymentMethodNonceCreated(cardNonce);
    mActivity.onError(new Exception());

    verify(mActivity.httpClient, times(2)).get(matches(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS),
            any(HttpResponseCallback.class));
}
 
Example 8
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void onPaymentMethodNonceCreated_returnsANonce() throws JSONException {
    mActivityController.setup();
    CardNonce cardNonce = CardNonce.fromJson(
            stringFromFixture("responses/visa_credit_card_response.json"));

    mActivity.onPaymentMethodNonceCreated(cardNonce);

    assertTrue(mActivity.isFinishing());
    assertEquals(RESULT_OK, mShadowActivity.getResultCode());
    DropInResult result = mShadowActivity.getResultIntent()
            .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
    assertEquals(cardNonce.getNonce(), result.getPaymentMethodNonce().getNonce());
    assertEquals(cardNonce.getLastTwo(), ((CardNonce) result.getPaymentMethodNonce()).getLastTwo());
}