com.braintreepayments.api.models.CardNonce Java Examples
The following examples show how to use
com.braintreepayments.api.models.CardNonce.
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: ThreeDSecureUnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void performVerification_withCardBuilder_tokenizesAndPerformsVerification() { CardNonce cardNonce = mock(CardNonce.class); when(cardNonce.getNonce()).thenReturn("card-nonce"); MockStaticTokenizationClient.mockTokenizeSuccess(cardNonce); MockStaticCardinal.initCompletesSuccessfully("df-reference-id"); CardBuilder cardBuilder = new CardBuilder(); ThreeDSecureRequest request = new ThreeDSecureRequest() .amount("10"); ThreeDSecure.performVerification(mFragment, cardBuilder, request); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verifyStatic(); TokenizationClient.versionedPath(captor.capture()); assertTrue(captor.getValue().contains("card-nonce")); }
Example #2
Source File: ThreeDSecureVerificationTest.java From braintree_android with MIT License | 6 votes |
@Test(timeout = 10000) public void performVerification_doesALookupAndReturnsACardAndANullACSUrlWhenAuthenticationIsNotRequired() throws InterruptedException { BraintreeFragment fragment = getFragment(); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); CardNonce cardNonce = (CardNonce) paymentMethodNonce; assertEquals("51", cardNonce.getLastTwo()); assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted()); assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); mCountDownLatch.countDown(); } }); CardBuilder cardBuilder = new CardBuilder() .cardNumber(THREE_D_SECURE_VERIFICATON_NOT_REQUIRED) .expirationDate("12/20"); ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT); mCountDownLatch.await(); }
Example #3
Source File: AddCardActivityPowerMockTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void performsThreeDSecureVerificationWhenRequestedEnableAndAmountPresent() throws NoSuchFieldException, IllegalAccessException, JSONException { DropInRequest dropInRequest = new DropInRequest() .amount("1.00") .requestThreeDSecureVerification(true); Configuration configuration = mock(Configuration.class); when(configuration.isThreeDSecureEnabled()).thenReturn(true); setConfiguration(dropInRequest, configuration); mActivity.onPaymentMethodNonceCreated(CardNonce.fromJson( stringFromFixture("responses/visa_credit_card_response.json"))); verifyStatic(); ThreeDSecure.performVerification(any(BraintreeFragment.class), any(ThreeDSecureRequest.class)); }
Example #4
Source File: CardActivity.java From braintree_android with MIT License | 6 votes |
@Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { super.onPaymentMethodNonceCreated(paymentMethodNonce); if (!mThreeDSecureRequested && paymentMethodNonce instanceof CardNonce && Settings.isThreeDSecureEnabled(this)) { mThreeDSecureRequested = true; mLoading = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading), true, false); ThreeDSecure.performVerification(mBraintreeFragment, threeDSecureRequest(paymentMethodNonce), new ThreeDSecureLookupListener() { @Override public void onLookupComplete(ThreeDSecureRequest request, ThreeDSecureLookup lookup) { ThreeDSecure.continuePerformVerification(mBraintreeFragment, request, lookup); } }); } else if (paymentMethodNonce instanceof CardNonce && Settings.isAmexRewardsBalanceEnabled(this)) { mLoading = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading), true, false); AmericanExpress.getRewardsBalance(mBraintreeFragment, paymentMethodNonce.getNonce(), "USD"); } else { Intent intent = new Intent() .putExtra(MainActivity.EXTRA_PAYMENT_RESULT, paymentMethodNonce) .putExtra(MainActivity.EXTRA_DEVICE_DATA, mDeviceData); setResult(RESULT_OK, intent); finish(); } }
Example #5
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@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 #6
Source File: DropInResultUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@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 #7
Source File: ThreeDSecureVerificationTest.java From braintree_android with MIT License | 6 votes |
@Test(timeout = 10000) public void performVerification_doesALookupAndReturnsACardWhenAuthenticationIsUnavailable() throws InterruptedException { BraintreeFragment fragment = getFragment(); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); CardNonce cardNonce = (CardNonce) paymentMethodNonce; assertEquals("69", cardNonce.getLastTwo()); assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted()); assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); mCountDownLatch.countDown(); } }); CardBuilder cardBuilder = new CardBuilder() .cardNumber(THREE_D_SECURE_AUTHENTICATION_UNAVAILABLE) .expirationDate("12/20"); ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT); mCountDownLatch.await(); }
Example #8
Source File: DropInResultUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void fetchDropInResult_callsListenerWithResultWhenThereIsAPaymentMethod() throws InvalidArgumentException, InterruptedException { setupFragment(new BraintreeUnitTestHttpClient() .configuration(new TestConfigurationBuilder().build()) .successResponse(BraintreeUnitTestHttpClient.GET_PAYMENT_METHODS, stringFromFixture("responses/get_payment_methods_two_cards_response.json"))); DropInResult.DropInResultListener listener = new DropInResult.DropInResultListener() { @Override public void onError(Exception exception) { fail("onError called"); } @Override public void onResult(DropInResult result) { assertEquals(PaymentMethodType.VISA, result.getPaymentMethodType()); assertEquals("11", ((CardNonce) result.getPaymentMethodNonce()).getLastTwo()); mCountDownLatch.countDown(); } }; DropInResult.fetchDropInResult(mActivity, base64EncodedClientTokenFromFixture("client_token.json"), listener); mCountDownLatch.await(); }
Example #9
Source File: VaultedPaymentMethodsAdapter.java From braintree-android-drop-in with MIT License | 6 votes |
@Override public void onBindViewHolder(ViewHolder holder, int position) { final PaymentMethodNonce paymentMethodNonce = mPaymentMethodNonces.get(position); PaymentMethodType paymentMethodType = PaymentMethodType.forType(paymentMethodNonce); holder.icon.setImageResource(paymentMethodType.getVaultedDrawable()); holder.title.setText(paymentMethodType.getLocalizedName()); if (paymentMethodNonce instanceof CardNonce) { holder.description.setText("••• ••" + ((CardNonce) paymentMethodNonce).getLastTwo()); } else { holder.description.setText(paymentMethodNonce.getDescription()); } holder.itemView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mSelectedListener.onPaymentMethodNonceCreated(paymentMethodNonce); } }); }
Example #10
Source File: BraintreeFragmentTestUtils.java From braintree_android with MIT License | 6 votes |
public static CardNonce tokenize(BraintreeFragment fragment, CardBuilder cardBuilder) { final CountDownLatch latch = new CountDownLatch(1); final CardNonce[] cardNonce = new CardNonce[1]; PaymentMethodNonceCreatedListener listener = new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { cardNonce[0] = (CardNonce) paymentMethodNonce; latch.countDown(); } }; fragment.addListener(listener); Card.tokenize(fragment, cardBuilder); try { latch.await(); } catch (InterruptedException ignored) {} fragment.removeListener(listener); return cardNonce[0]; }
Example #11
Source File: PaymentMethodItemView.java From braintree-android-drop-in with MIT License | 6 votes |
public void setPaymentMethod(PaymentMethodNonce paymentMethodNonce, boolean usedInList) { mPaymentMethodNonce = paymentMethodNonce; PaymentMethodType paymentMethodType = PaymentMethodType.forType(paymentMethodNonce); if (usedInList) { mIcon.setImageResource(paymentMethodType.getDrawable()); mDeleteIcon.setVisibility(View.VISIBLE); mDivider.setVisibility(View.VISIBLE); } else { mIcon.setImageResource(paymentMethodType.getVaultedDrawable()); mDeleteIcon.setVisibility(View.GONE); mDivider.setVisibility(View.GONE); } mTitle.setText(paymentMethodType.getLocalizedName()); if (paymentMethodNonce instanceof CardNonce) { mDescription.setText("••• ••" + ((CardNonce) paymentMethodNonce).getLastTwo()); } else { mDescription.setText(paymentMethodNonce.getDescription()); } }
Example #12
Source File: BaseActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@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 #13
Source File: BraintreeFragmentUnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void postCallback_postsPaymentMethodNonceToListener() throws InvalidArgumentException { BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY); final AtomicBoolean wasCalled = new AtomicBoolean(false); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertTrue(paymentMethodNonce instanceof CardNonce); wasCalled.set(true); } }); fragment.postCallback(new CardNonce()); assertTrue(wasCalled.get()); }
Example #14
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@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 #15
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void clickingVaultedPaymentMethod_whenCard_sendsAnalyticEvent() { PaymentMethodNonce nonce = mock(CardNonce.class); ArrayList<PaymentMethodNonce> nonces = new ArrayList<>(); nonces.add(nonce); BraintreeFragment fragment = mock(BraintreeFragment.class); setup(fragment); mActivity.onPaymentMethodNoncesUpdated(nonces); RecyclerView recyclerView = mActivity.findViewById(R.id.bt_vaulted_payment_methods); recyclerView.measure(0, 0); recyclerView.layout(0, 0, 100, 10000); recyclerView.findViewHolderForAdapterPosition(0).itemView.callOnClick(); verify(fragment).sendAnalyticsEvent("vaulted-card.select"); }
Example #16
Source File: ThreeDSecureTest.java From braintree_android with MIT License | 6 votes |
@Test(timeout = 10000) public void performVerification_acceptsACardBuilderAndPostsAPaymentMethodNonceToListener() throws InterruptedException { BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, new TestClientTokenBuilder().build()); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); mCountDownLatch.countDown(); } }); CardBuilder cardBuilder = new CardBuilder() .cardNumber("4000000000000051") .expirationDate("12/20"); ThreeDSecure.performVerification(fragment, cardBuilder, "5"); mCountDownLatch.await(); }
Example #17
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void onActivityResult_returnsNonceFromAddCardActivity() throws JSONException { DropInResult result = new DropInResult() .paymentMethodNonce(CardNonce.fromJson( stringFromFixture("responses/visa_credit_card_response.json"))); Intent data = new Intent() .putExtra(DropInResult.EXTRA_DROP_IN_RESULT, result); mActivityController.setup(); mActivity.onActivityResult(1, RESULT_OK, data); assertTrue(mShadowActivity.isFinishing()); assertEquals(RESULT_OK, mShadowActivity.getResultCode()); DropInResult response = mShadowActivity.getResultIntent() .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT); assertEquals(result.getPaymentMethodType(), response.getPaymentMethodType()); assertEquals(result.getPaymentMethodNonce(), response.getPaymentMethodNonce()); }
Example #18
Source File: ThreeDSecureV2UnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void authenticateCardinalJWT_whenCustomerFailsAuthentication_returnsLookupCardNonce() throws JSONException { ThreeDSecureLookup threeDSecureLookup = ThreeDSecureLookup.fromJson( stringFromFixture("three_d_secure/2.0/lookup_response_without_liability_with_liability_shift_possible.json")); String authResponseJson = stringFromFixture("three_d_secure/2.0/authentication_response_with_error.json"); mMockFragmentBuilder.successResponse(authResponseJson); mFragment = mMockFragmentBuilder.build(); ThreeDSecure.authenticateCardinalJWT(mFragment, threeDSecureLookup, "jwt"); ArgumentCaptor<CardNonce> captor = ArgumentCaptor.forClass(CardNonce.class); verify(mFragment).postCallback(captor.capture()); CardNonce cardNonce = captor.getValue(); assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted()); assertTrue(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible()); assertEquals("123456-12345-12345-a-adfa", cardNonce.getNonce()); assertEquals("Failed to authenticate, please try a different form of payment.", cardNonce.getThreeDSecureInfo().getErrorMessage()); assertEquals(authResponseJson, cardNonce.getThreeDSecureInfo().getThreeDSecureAuthenticationResponse().getErrors()); }
Example #19
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void onActivityResult_returnsDeviceData() throws JSONException { mActivity.mDropInRequest = new DropInRequest() .tokenizationKey(TOKENIZATION_KEY) .collectDeviceData(true); mActivity.httpClient = new BraintreeUnitTestHttpClient() .configuration(new TestConfigurationBuilder().build()); mActivityController.setup(); DropInResult result = new DropInResult() .paymentMethodNonce(CardNonce.fromJson( stringFromFixture("responses/visa_credit_card_response.json"))); Intent data = new Intent() .putExtra(DropInResult.EXTRA_DROP_IN_RESULT, result); mActivity.onActivityResult(1, RESULT_OK, data); DropInResult response = mShadowActivity.getResultIntent() .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT); assertNotNull(response.getDeviceData()); }
Example #20
Source File: DropInActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void onActivityResult_storesPaymentMethodType() throws JSONException { mActivityController.setup(); DropInResult result = new DropInResult() .paymentMethodNonce(CardNonce.fromJson( stringFromFixture("responses/visa_credit_card_response.json"))); Intent data = new Intent() .putExtra(DropInResult.EXTRA_DROP_IN_RESULT, result); assertNull(BraintreeSharedPreferences.getSharedPreferences(mActivity) .getString(DropInResult.LAST_USED_PAYMENT_METHOD_TYPE, null)); mActivity.onActivityResult(1, RESULT_OK, data); assertEquals(PaymentMethodType.VISA.getCanonicalName(), BraintreeSharedPreferences.getSharedPreferences(mActivity) .getString(DropInResult.LAST_USED_PAYMENT_METHOD_TYPE, null)); }
Example #21
Source File: ThreeDSecureV2UnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void authenticateCardinalJWT_whenSuccess_returnsThreeDSecureCardNonce() throws JSONException { ThreeDSecureLookup threeDSecureLookup = ThreeDSecureLookup.fromJson(stringFromFixture("three_d_secure/lookup_response_with_version_number2.json")); String authResponseJson = stringFromFixture("three_d_secure/authentication_response.json"); mMockFragmentBuilder.successResponse(authResponseJson); mFragment = mMockFragmentBuilder.build(); ThreeDSecure.authenticateCardinalJWT(mFragment, threeDSecureLookup, "jwt"); ArgumentCaptor<CardNonce> captor = ArgumentCaptor.forClass(CardNonce.class); verify(mFragment).postCallback(captor.capture()); CardNonce cardNonce = captor.getValue(); assertTrue(cardNonce.getThreeDSecureInfo().isLiabilityShifted()); assertTrue(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible()); assertEquals("12345678-1234-1234-1234-123456789012", cardNonce.getNonce()); }
Example #22
Source File: ThreeDSecureV2UnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void performVerification_withCardBuilder_tokenizesAndPerformsVerification() { CardNonce cardNonce = mock(CardNonce.class); when(cardNonce.getNonce()).thenReturn("card-nonce"); MockStaticTokenizationClient.mockTokenizeSuccess(cardNonce); MockStaticCardinal.initCompletesSuccessfully("fake-df"); CardBuilder cardBuilder = new CardBuilder(); ThreeDSecureRequest request = new ThreeDSecureRequest() .amount("10"); ThreeDSecure.performVerification(mFragment, cardBuilder, request); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verifyStatic(); //noinspection ResultOfMethodCallIgnored TokenizationClient.versionedPath(captor.capture()); assertTrue(captor.getValue().contains("card-nonce")); }
Example #23
Source File: UnionPayUnitTest.java From braintree_android with MIT License | 6 votes |
private void mockSuccessCallback() { mockStatic(TokenizationClient.class); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) { UnionPayCardBuilder cardBuilder = (UnionPayCardBuilder) invocation.getArguments()[1]; CardNonce cardNonce = mock(CardNonce.class); boolean hasSmsCode = false; try { hasSmsCode = new JSONObject(cardBuilder.build()).getJSONObject("options").has("smsCode"); } catch (JSONException ignored) {} if (hasSmsCode) { when(cardNonce.getNonce()).thenReturn("nonce"); } ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(cardNonce); return null; } }).when(TokenizationClient.class); TokenizationClient.tokenize(any(BraintreeFragment.class), any(UnionPayCardBuilder.class), any(PaymentMethodNonceCallback.class)); }
Example #24
Source File: AddCardActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
@Test public void addingACardReturnsANonce() { BraintreeUnitTestHttpClient httpClient = new BraintreeUnitTestHttpClient() .configuration(new TestConfigurationBuilder() .creditCards(getSupportedCardConfiguration()) .build()) .successResponse(BraintreeUnitTestHttpClient.TOKENIZE_CREDIT_CARD, stringFromFixture("payment_methods/visa_credit_card.json")); setup(httpClient); setText(mAddCardView, R.id.bt_card_form_card_number, VISA); mAddCardView.findViewById(R.id.bt_button).performClick(); setText(mEditCardView, R.id.bt_card_form_expiration, ExpirationDate.VALID_EXPIRATION); mEditCardView.findViewById(R.id.bt_button).performClick(); assertTrue(mActivity.isFinishing()); DropInResult result = mShadowActivity.getResultIntent() .getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT); assertEquals(RESULT_OK, mShadowActivity.getResultCode()); assertIsANonce(result.getPaymentMethodNonce().getNonce()); assertEquals("11", ((CardNonce) result.getPaymentMethodNonce()).getLastTwo()); }
Example #25
Source File: PaymentMethodUnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void getPaymentMethodNonces_fetchesPaymentMethods() { BraintreeFragment fragment = new MockFragmentBuilder() .successResponse(stringFromFixture("payment_methods/get_payment_methods_response.json")) .build(); PaymentMethod.getPaymentMethodNonces(fragment); ArgumentCaptor<List<PaymentMethodNonce>> captor = ArgumentCaptor.forClass((Class) List.class); verify(fragment).postCallback(captor.capture()); List<PaymentMethodNonce> paymentMethodNonces = captor.getValue(); assertEquals(3, paymentMethodNonces.size()); assertEquals("11", ((CardNonce) paymentMethodNonces.get(0)).getLastTwo()); assertEquals("PayPal", paymentMethodNonces.get(1).getTypeLabel()); assertEquals("happy-venmo-joe", ((VenmoAccountNonce) paymentMethodNonces.get(2)).getUsername()); }
Example #26
Source File: ThreeDSecureUnitTest.java From braintree_android with MIT License | 6 votes |
@Test public void onActivityResult_whenSuccessful_postsPayment() { Uri uri = Uri.parse("http://demo-app.com") .buildUpon() .appendQueryParameter("auth_response", stringFromFixture("three_d_secure/authentication_response.json")) .build(); Intent data = new Intent(); data.setData(uri); ThreeDSecure.onActivityResult(mFragment, RESULT_OK, data); ArgumentCaptor<PaymentMethodNonce> captor = ArgumentCaptor.forClass(PaymentMethodNonce.class); verify(mFragment).postCallback(captor.capture()); PaymentMethodNonce paymentMethodNonce = captor.getValue(); assertIsANonce(paymentMethodNonce.getNonce()); assertEquals("11", ((CardNonce) paymentMethodNonce).getLastTwo()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); }
Example #27
Source File: ThreeDSecureTest.java From braintree_android with MIT License | 6 votes |
@Test(timeout = 10000) public void performVerification_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException { String clientToken = new TestClientTokenBuilder().build(); BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, clientToken); String nonce = tokenize(fragment, new CardBuilder() .cardNumber("4000000000000051") .expirationDate("12/20")).getNonce(); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); assertEquals("51", ((CardNonce) paymentMethodNonce).getLastTwo()); assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified()); mCountDownLatch.countDown(); } }); ThreeDSecure.performVerification(fragment, nonce, "5"); mCountDownLatch.await(); }
Example #28
Source File: CardTest.java From braintree_android with MIT License | 5 votes |
@Test(timeout = 10000) public void tokenize_tokenizesCvvOnly() throws Exception { final CountDownLatch countDownLatch = new CountDownLatch(1); BraintreeFragment fragment = setupBraintreeFragment(TOKENIZATION_KEY); fragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { CardNonce cardNonce = (CardNonce) paymentMethodNonce; assertNotNull(cardNonce.getBinData()); assertEquals("Unknown", cardNonce.getCardType()); assertEquals("", cardNonce.getLastFour()); assertEquals("", cardNonce.getLastTwo()); assertNotNull(cardNonce.getThreeDSecureInfo()); assertFalse(cardNonce.isDefault()); assertEquals("", cardNonce.getDescription()); assertNotNull(cardNonce.getNonce()); countDownLatch.countDown(); } }); CardBuilder cardBuilder = new CardBuilder().cvv("123"); Card.tokenize(fragment, cardBuilder); countDownLatch.await(); }
Example #29
Source File: ThreeDSecure.java From braintree_android with MIT License | 5 votes |
private static void completeVerificationFlowWithNoncePayload(BraintreeFragment fragment, CardNonce noncePayload) { ThreeDSecureInfo info = noncePayload.getThreeDSecureInfo(); fragment.sendAnalyticsEvent(String.format("three-d-secure.verification-flow.liability-shifted.%b", info.isLiabilityShifted())); fragment.sendAnalyticsEvent(String.format("three-d-secure.verification-flow.liability-shift-possible.%b", info.isLiabilityShiftPossible())); fragment.postCallback(noncePayload); }
Example #30
Source File: UnionPayTest.java From braintree_android with MIT License | 5 votes |
@Ignore("Sample merchant account is not set up for Union Pay") @Test(timeout = 10000) public void tokenize_unionPayCredit_withExpirationDate() throws InterruptedException { final UnionPayCardBuilder cardBuilder = new UnionPayCardBuilder() .cardNumber(CardNumber.UNIONPAY_CREDIT) .expirationDate("08/20") .cvv("123") .mobileCountryCode("62") .mobilePhoneNumber("1111111111"); mBraintreeFragment.addListener(new UnionPayListener() { @Override public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {} @Override public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) { assertTrue(smsCodeRequired); cardBuilder.enrollmentId(enrollmentId); cardBuilder.smsCode("12345"); UnionPay.tokenize(mBraintreeFragment, cardBuilder); } }); mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { assertIsANonce(paymentMethodNonce.getNonce()); assertEquals("32", ((CardNonce) paymentMethodNonce).getLastTwo()); mCountDownLatch.countDown(); } }); UnionPay.enroll(mBraintreeFragment, cardBuilder); mCountDownLatch.await(); }