Search in sources :

Example 1 with VenmoAccountNonce

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

the class VenmoUnitTest method onActivityResult_withSuccessfulVaultCall_returnsVenmoAccountNonce.

@Test
public void onActivityResult_withSuccessfulVaultCall_returnsVenmoAccountNonce() throws InvalidArgumentException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).configuration(configuration).authorization(clientToken).sessionId("session-id").successResponse(stringFromFixture("payment_methods/venmo_account_response.json")).build();
    Venmo.authorizeAccount(fragment, true);
    ArgumentCaptor<PaymentMethodNonce> responseCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).postCallback(responseCaptor.capture());
    PaymentMethodNonce capturedNonce = responseCaptor.getValue();
    assertTrue(capturedNonce instanceof VenmoAccountNonce);
    VenmoAccountNonce venmoAccountNonce = (VenmoAccountNonce) capturedNonce;
    assertEquals("Venmo", venmoAccountNonce.getTypeLabel());
    assertEquals("fake-venmo-nonce", venmoAccountNonce.getNonce());
    assertEquals("venmojoe", venmoAccountNonce.getUsername());
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) VenmoAccountNonce(com.braintreepayments.api.models.VenmoAccountNonce) Intent(android.content.Intent) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with VenmoAccountNonce

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

the class VenmoUnitTest method onActivityResult_postsPaymentMethodNonceOnSuccess.

@Test
public void onActivityResult_postsPaymentMethodNonceOnSuccess() {
    BraintreeFragment fragment = new MockFragmentBuilder().build();
    Intent intent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "123456-12345-12345-a-adfa").putExtra(Venmo.EXTRA_USERNAME, "username");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, intent);
    ArgumentCaptor<VenmoAccountNonce> captor = ArgumentCaptor.forClass(VenmoAccountNonce.class);
    verify(fragment).postCallback(captor.capture());
    assertEquals("123456-12345-12345-a-adfa", captor.getValue().getNonce());
    assertEquals("username", captor.getValue().getDescription());
    assertEquals("username", captor.getValue().getUsername());
}
Also used : VenmoAccountNonce(com.braintreepayments.api.models.VenmoAccountNonce) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with VenmoAccountNonce

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

the class Venmo method onActivityResult.

static void onActivityResult(final BraintreeFragment fragment, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        fragment.sendAnalyticsEvent("pay-with-venmo.app-switch.success");
        String nonce = data.getStringExtra(EXTRA_PAYMENT_METHOD_NONCE);
        if (shouldVault(fragment.getApplicationContext()) && fragment.getAuthorization() instanceof ClientToken) {
            vault(fragment, nonce);
        } else {
            String venmoUsername = data.getStringExtra(EXTRA_USERNAME);
            VenmoAccountNonce venmoAccountNonce = new VenmoAccountNonce(nonce, venmoUsername, venmoUsername);
            fragment.postCallback(venmoAccountNonce);
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        fragment.sendAnalyticsEvent("pay-with-venmo.app-switch.canceled");
    }
}
Also used : VenmoAccountNonce(com.braintreepayments.api.models.VenmoAccountNonce) ClientToken(com.braintreepayments.api.models.ClientToken)

Aggregations

VenmoAccountNonce (com.braintreepayments.api.models.VenmoAccountNonce)3 Intent (android.content.Intent)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Authorization (com.braintreepayments.api.models.Authorization)1 ClientToken (com.braintreepayments.api.models.ClientToken)1 Configuration (com.braintreepayments.api.models.Configuration)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1