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"));
}
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());
}
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) {
}
}
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);
}
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));
}
Aggregations