Search in sources :

Example 6 with Authorization

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

the class VenmoUnitTest method onActivityResult_withSuccessfulVaultCall_sendsAnalyticsEvent.

@Test
public void onActivityResult_withSuccessfulVaultCall_sendsAnalyticsEvent() 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);
    Intent responseIntent = new Intent().putExtra(Venmo.EXTRA_PAYMENT_METHOD_NONCE, "nonce");
    Venmo.onActivityResult(fragment, Activity.RESULT_OK, responseIntent);
    verify(fragment).sendAnalyticsEvent(endsWith("pay-with-venmo.vault.success"));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Authorization

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

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

the class AnalyticsIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    try {
        Authorization authorization = Authorization.fromString(intent.getStringExtra(EXTRA_AUTHORIZATION));
        Configuration configuration = Configuration.fromJson(intent.getStringExtra(EXTRA_CONFIGURATION));
        AnalyticsSender.send(this, authorization, new BraintreeHttpClient(authorization), configuration.getAnalytics().getUrl(), true);
    } catch (InvalidArgumentException | JSONException ignored) {
    }
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Configuration(com.braintreepayments.api.models.Configuration) JSONException(org.json.JSONException)

Example 9 with Authorization

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

the class PayPalUnitTest method setup.

@Before
public void setup() throws Exception {
    spy(PayPal.class);
    doReturn(true).when(PayPal.class, "isManifestValid", any(Context.class));
    spy(Recipe.class);
    doReturn(true).when(Recipe.class, "isValidBrowserTarget", any(Context.class), anyString(), anyString());
    Authorization authorization = mock(Authorization.class);
    when(authorization.getBearer()).thenReturn("authorization");
    when(authorization.toString()).thenReturn("authorization");
    Configuration configuration = new TestConfigurationBuilder().withAnalytics().paypal(new TestPayPalConfigurationBuilder(true).environment("offline").billingAgreementsEnabled(false)).buildConfiguration();
    mMockFragmentBuilder = new MockFragmentBuilder().authorization(authorization).configuration(configuration);
}
Also used : Context(android.content.Context) Authorization(com.braintreepayments.api.models.Authorization) TestPayPalConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestPayPalConfigurationBuilder) Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) Before(org.junit.Before)

Example 10 with Authorization

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

the class VenmoUnitTest method performAppSwitch_whenProfileIdIsNull_appSwitchesWithMerchantId.

@Test
public void performAppSwitch_whenProfileIdIsNull_appSwitchesWithMerchantId() throws InvalidArgumentException, JSONException {
    Configuration configuration = getConfigurationFromFixture();
    Authorization clientToken = Authorization.fromString(stringFromFixture("base_64_client_token.txt"));
    disableSignatureVerification();
    BraintreeFragment fragment = new MockFragmentBuilder().context(VenmoInstalledContextFactory.venmoInstalledContext(true, RuntimeEnvironment.application)).authorization(clientToken).configuration(configuration).build();
    when(fragment.getSessionId()).thenReturn("a-session-id");
    when(fragment.getIntegrationType()).thenReturn("custom");
    Venmo.authorizeAccount(fragment, false, null);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.VENMO));
    assertEquals("com.venmo/com.venmo.controller.SetupMerchantActivity", captor.getValue().getComponent().flattenToString());
    Bundle extras = captor.getValue().getExtras();
    assertEquals("merchant-id", extras.getString(Venmo.EXTRA_MERCHANT_ID));
    assertEquals("access-token", extras.getString(Venmo.EXTRA_ACCESS_TOKEN));
}
Also used : Authorization(com.braintreepayments.api.models.Authorization) Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Authorization (com.braintreepayments.api.models.Authorization)17 Configuration (com.braintreepayments.api.models.Configuration)14 Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 Intent (android.content.Intent)9 Bundle (android.os.Bundle)5 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)4 SharedPreferences (android.content.SharedPreferences)3 SharedPreferencesHelper.clearSharedPreferences (com.braintreepayments.testutils.SharedPreferencesHelper.clearSharedPreferences)3 AuthorizationException (com.braintreepayments.api.exceptions.AuthorizationException)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 FragmentManager (android.app.FragmentManager)1 Context (android.content.Context)1 AppSwitchNotAvailableException (com.braintreepayments.api.exceptions.AppSwitchNotAvailableException)1 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)1 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)1 VenmoAccountBuilder (com.braintreepayments.api.models.VenmoAccountBuilder)1 VenmoAccountNonce (com.braintreepayments.api.models.VenmoAccountNonce)1 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)1