com.braintreepayments.api.models.PaymentMethodNonce Java Examples

The following examples show how to use com.braintreepayments.api.models.PaymentMethodNonce. 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: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@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 #2
Source File: BraintreeFragmentTestUtils.java    From braintree_android with MIT License 6 votes vote down vote up
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 #3
Source File: AddCardActivity.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethod) {
    if (!mPerformedThreeDSecureVerification && shouldRequestThreeDSecureVerification()) {
        mPerformedThreeDSecureVerification = true;

        if (mDropInRequest.getThreeDSecureRequest() == null) {
            ThreeDSecureRequest threeDSecureRequest = new ThreeDSecureRequest().amount(mDropInRequest.getAmount());
            mDropInRequest.threeDSecureRequest(threeDSecureRequest);
        }

        if (mDropInRequest.getThreeDSecureRequest().getAmount() == null && mDropInRequest.getAmount() != null) {
            mDropInRequest.getThreeDSecureRequest().amount(mDropInRequest.getAmount());
        }

        mDropInRequest.getThreeDSecureRequest().nonce(paymentMethod.getNonce());
        ThreeDSecure.performVerification(mBraintreeFragment, mDropInRequest.getThreeDSecureRequest());
    } else {
        mBraintreeFragment.sendAnalyticsEvent("sdk.exit.success");
        finish(paymentMethod, null);
    }
}
 
Example #4
Source File: TokenizationClientTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test(timeout = 10000)
public void tokenize_tokenizesAPayPalAccountWithATokenizationKey() throws InterruptedException, JSONException {
    final CountDownLatch latch = new CountDownLatch(1);
    BraintreeFragment fragment = getFragmentWithAuthorization(mActivity, TOKENIZATION_KEY);

    JSONObject otcJson = new JSONObject(FixturesHelper.stringFromFixture("paypal_otc_response.json"));
    PayPalAccountBuilder paypalAccountBuilder =
            new PayPalAccountBuilder().oneTouchCoreData(otcJson);

    TokenizationClient.tokenize(fragment, paypalAccountBuilder,
            new PaymentMethodNonceCallback() {
                @Override
                public void success(PaymentMethodNonce paymentMethodNonce) {
                    assertIsANonce(paymentMethodNonce.getNonce());
                    assertEquals("PayPal", paymentMethodNonce.getTypeLabel());
                    latch.countDown();
                }

                @Override
                public void failure(Exception exception) {
                    fail(exception.getMessage());
                }
            });

    latch.await();
}
 
Example #5
Source File: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@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 #6
Source File: PayPalUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void requestBillingAgreement_paypalCreditReturnedInResponse() throws Exception {
    BraintreeFragment fragment = mMockFragmentBuilder
            .successResponse(stringFromFixture("paypal_hermes_billing_agreement_response.json"))
            .build();

    MockStaticTokenizationClient.mockTokenizeSuccess(PayPalAccountNonce.fromJson(stringFromFixture("payment_methods/paypal_account_response.json")));

    PayPal.requestBillingAgreement(fragment, new PayPalRequest().offerCredit(true), new PayPalApprovalHandler() {
        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            paypalApprovalCallback.onComplete(new Intent()
                    .setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&ba_token=EC-HERMES-SANDBOX-EC-TOKEN"))
            );
        }
    });

    ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    verify(fragment).postCallback(nonceCaptor.capture());
    verify(fragment).sendAnalyticsEvent("paypal.credit.accepted");

    assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
    PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) nonceCaptor.getValue();
    assertNotNull(payPalAccountNonce.getCreditFinancing());
    assertEquals(18, payPalAccountNonce.getCreditFinancing().getTerm());
}
 
Example #7
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 6 votes vote down vote up
@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 #8
Source File: PayPalTwoFactorAuth.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * Perform a two factor authentication.  Will return a nonce to your
 * {@link com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener}.
 *
 * @param fragment A {@link BraintreeFragment} used to continue two factor authentication.
 * @param paymentMethodNonce A {@link PaymentMethodNonce} returned from
 * {@link #performTwoFactorLookup(BraintreeFragment, PayPalTwoFactorAuthRequest, PayPalTwoFactorAuthCallback)}.
 *
 */
public static void continueTwoFactorAuthentication(BraintreeFragment fragment, PaymentMethodNonce paymentMethodNonce) {
    fragment.sendAnalyticsEvent("paypal-two-factor.continue-two-factor-authentication.started");
    PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce)paymentMethodNonce;
    PayPalTwoFactorAuthSharedPreferences.persistPayPalAccountNonce(fragment, payPalAccountNonce);

    String authenticateUrl = payPalAccountNonce.getAuthenticateUrl();
    if (authenticateUrl == null) {
        // no further auth required; callback with PayPal account nonce immediately
        fragment.sendAnalyticsEvent("paypal-two-factor.continue-two-factor-authentication.no-two-factor-required");
        fragment.postCallback(payPalAccountNonce);
    } else {
        fragment.sendAnalyticsEvent("paypal-two-factor.browser-switch.started");
        fragment.browserSwitch(BraintreeRequestCodes.PAYPAL_TWO_FACTOR_AUTH, authenticateUrl);
    }
}
 
Example #9
Source File: VaultedPaymentMethodsAdapter.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@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: ThreeDSecureVerificationTest.java    From braintree_android with MIT License 6 votes vote down vote up
@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 #11
Source File: Venmo.java    From braintree_android with MIT License 6 votes vote down vote up
private static void vault(final BraintreeFragment fragment, String nonce) {
    VenmoAccountBuilder vaultBuilder = new VenmoAccountBuilder()
            .nonce(nonce);
    TokenizationClient.tokenize(fragment, vaultBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            fragment.postCallback(paymentMethodNonce);
            fragment.sendAnalyticsEvent("pay-with-venmo.vault.success");
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
            fragment.sendAnalyticsEvent("pay-with-venmo.vault.failed");
        }
    });
}
 
Example #12
Source File: PayPalUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void requestOneTimePayment_customHandlerSuccessCallbackIsInvoked() {
    BraintreeFragment fragment = mMockFragmentBuilder
            .successResponse(stringFromFixture("paypal_hermes_response.json"))
            .build();

    MockStaticTokenizationClient.mockTokenizeSuccess(new PayPalAccountNonce());

    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"), new PayPalApprovalHandler() {
        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            paypalApprovalCallback.onComplete(new Intent()
                    .setData(Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN"))
            );
        }
    });

    ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    verify(fragment).postCallback(nonceCaptor.capture());

    assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
}
 
Example #13
Source File: Card.java    From braintree_android with MIT License 6 votes vote down vote up
/**
 * Create a {@link com.braintreepayments.api.models.CardNonce}.
 * <p>
 * On completion, returns the {@link com.braintreepayments.api.models.PaymentMethodNonce} to
 * {@link com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener}.
 * <p>
 * If creation fails validation, {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
 * will be called with the resulting {@link com.braintreepayments.api.exceptions.ErrorWithResponse}.
 * <p>
 * If an error not due to validation (server error, network issue, etc.) occurs, {@link
 * com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
 * will be called with the {@link Exception} that occurred.
 *
 * @param fragment {@link BraintreeFragment}
 * @param cardBuilder {@link CardBuilder}
 */
public static void tokenize(final BraintreeFragment fragment, final CardBuilder cardBuilder) {
    TokenizationClient.tokenize(fragment, cardBuilder, new PaymentMethodNonceCallback() {
        @Override
        public void success(PaymentMethodNonce paymentMethodNonce) {
            DataCollector.collectRiskData(fragment, paymentMethodNonce);

            fragment.postCallback(paymentMethodNonce);
            fragment.sendAnalyticsEvent("card.nonce-received");
        }

        @Override
        public void failure(Exception exception) {
            fragment.postCallback(exception);
            fragment.sendAnalyticsEvent("card.nonce-failed");
        }
    });
}
 
Example #14
Source File: Braintree.java    From react-native-braintree-android with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
  if (requestCode == PAYMENT_REQUEST) {
    switch (resultCode) {
      case Activity.RESULT_OK:
        PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
                BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
        );
        successCallback.invoke(paymentMethodNonce.getNonce());
        break;
      case BraintreePaymentActivity.BRAINTREE_RESULT_DEVELOPER_ERROR:
      case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_ERROR:
      case BraintreePaymentActivity.BRAINTREE_RESULT_SERVER_UNAVAILABLE:
        errorCallback.invoke(
                data.getSerializableExtra(BraintreePaymentActivity.EXTRA_ERROR_MESSAGE)
        );
        break;
      default:
        break;
    }
  }
}
 
Example #15
Source File: Braintree.java    From react-native-braintree-android with MIT License 6 votes vote down vote up
@ReactMethod
public void setup(final String token, final Callback successCallback, final Callback errorCallback) {
  try {
    this.mBraintreeFragment = BraintreeFragment.newInstance(getCurrentActivity(), token);
    this.mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() {
      @Override
      public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        nonceCallback(paymentMethodNonce.getNonce());
      }
    });
    this.setToken(token);
    successCallback.invoke(this.getToken());
  } catch (InvalidArgumentException e) {
    errorCallback.invoke(e.getMessage());
  }
}
 
Example #16
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@Test
public void clickingVaultedPaymentMethod_whenPayPal_doesNotSendAnalyticEvent() {
    PaymentMethodNonce nonce = mock(PayPalAccountNonce.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, never()).sendAnalyticsEvent("vaulted-card.select");
}
 
Example #17
Source File: ThreeDSecureUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@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 #18
Source File: PayPalUnitTest.java    From braintree_android with MIT License 6 votes vote down vote up
@Test
public void requestOneTimePayment_paypalCreditReturnedInResponse() throws Exception {
    BraintreeFragment fragment = mMockFragmentBuilder
            .successResponse(stringFromFixture("paypal_hermes_response.json"))
            .build();

    MockStaticTokenizationClient.mockTokenizeSuccess(PayPalAccountNonce.fromJson(stringFromFixture("payment_methods/paypal_account_response.json")));

    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").offerCredit(true), new PayPalApprovalHandler() {
        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            paypalApprovalCallback.onComplete(new Intent()
                    .setData(Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN"))
            );
        }
    });

    ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    verify(fragment).postCallback(nonceCaptor.capture());
    verify(fragment).sendAnalyticsEvent("paypal.credit.accepted");

    assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
    PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) nonceCaptor.getValue();
    assertNotNull(payPalAccountNonce.getCreditFinancing());
    assertEquals(18, payPalAccountNonce.getCreditFinancing().getTerm());
}
 
Example #19
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 6 votes vote down vote up
@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 #20
Source File: CardTest.java    From braintree_android with MIT License 5 votes vote down vote up
@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 #21
Source File: FlutterBraintreeCustom.java    From FlutterBraintree with MIT License 5 votes vote down vote up
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
    HashMap<String, Object> nonceMap = new HashMap<String, Object>();
    nonceMap.put("nonce", paymentMethodNonce.getNonce());
    nonceMap.put("typeLabel", paymentMethodNonce.getTypeLabel());
    nonceMap.put("description", paymentMethodNonce.getDescription());
    nonceMap.put("isDefault", paymentMethodNonce.isDefault());

    Intent result = new Intent();
    result.putExtra("type", "paymentMethodNonce");
    result.putExtra("paymentMethodNonce", nonceMap);
    setResult(RESULT_OK, result);
    finish();
}
 
Example #22
Source File: MainActivity.java    From braintree_android with MIT License 5 votes vote down vote up
private void displayNonce(PaymentMethodNonce paymentMethodNonce, String deviceData) {
    mNonce = paymentMethodNonce;
    Log.d("KANYE", mNonce.getNonce());

    mNonceIcon.setImageResource(PaymentMethodType.forType(mNonce).getDrawable());
    mNonceIcon.setVisibility(VISIBLE);

    mNonceString.setText(getString(R.string.nonce_placeholder, mNonce.getNonce()));
    mNonceString.setVisibility(VISIBLE);

    String details = "";
    if (mNonce instanceof CardNonce) {
        details = CardActivity.getDisplayString((CardNonce) mNonce);
    } else if (mNonce instanceof PayPalAccountNonce) {
        details = PayPalActivity.getDisplayString((PayPalAccountNonce) mNonce);
    } else if (mNonce instanceof GooglePaymentCardNonce) {
        details = GooglePaymentActivity.getDisplayString((GooglePaymentCardNonce) mNonce);
    } else if (mNonce instanceof VisaCheckoutNonce) {
        details = VisaCheckoutActivity.getDisplayString((VisaCheckoutNonce) mNonce);
    } else if (mNonce instanceof VenmoAccountNonce) {
        details = VenmoActivity.getDisplayString((VenmoAccountNonce) mNonce);
    } else if (mNonce instanceof LocalPaymentResult) {
        details = LocalPaymentsActivity.getDisplayString((LocalPaymentResult) mNonce);
    }

    mNonceDetails.setText(details);
    mNonceDetails.setVisibility(VISIBLE);

    mDeviceData.setText(getString(R.string.device_data_placeholder, deviceData));
    mDeviceData.setVisibility(VISIBLE);

    mCreateTransactionButton.setEnabled(true);
}
 
Example #23
Source File: GooglePaymentActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
    super.onPaymentMethodNonceCreated(paymentMethodNonce);

    Intent intent = new Intent().putExtra(MainActivity.EXTRA_PAYMENT_RESULT, paymentMethodNonce);
    setResult(RESULT_OK, intent);
    finish();
}
 
Example #24
Source File: UnionPayTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Ignore("Sample merchant account is not set up for Union Pay")
@Test(timeout = 30000)
public void tokenize_unionPayCredit_withExpirationMonthAndYear() throws InterruptedException {
    final UnionPayCardBuilder cardBuilder = new UnionPayCardBuilder()
            .cardNumber(CardNumber.UNIONPAY_CREDIT)
            .expirationMonth("08")
            .expirationYear("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();
}
 
Example #25
Source File: VenmoUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@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, AppCompatActivity.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());
}
 
Example #26
Source File: VisaCheckoutActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
    super.onPaymentMethodNonceCreated(paymentMethodNonce);

    Intent intent = new Intent()
            .putExtra(MainActivity.EXTRA_PAYMENT_RESULT, paymentMethodNonce);
    setResult(RESULT_OK, intent);
    finish();
}
 
Example #27
Source File: DropInActivityUnitTest.java    From braintree-android-drop-in with MIT License 5 votes vote down vote up
@Test
public void vaultEditButton_whenVaultManagerEnabled_isVisible() {
    setup(mock(BraintreeFragment.class));

    List<PaymentMethodNonce> nonceList = new ArrayList<>();
    nonceList.add(mock(CardNonce.class));

    mActivity.setDropInRequest(new DropInRequest()
            .vaultManager(true));

    mActivity.onPaymentMethodNoncesUpdated(nonceList);

    assertEquals(View.VISIBLE, mActivity.findViewById(R.id.bt_vault_edit_button).getVisibility());
}
 
Example #28
Source File: LocalPaymentsActivity.java    From braintree_android with MIT License 5 votes vote down vote up
@Override
public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
    super.onPaymentMethodNonceCreated(paymentMethodNonce);

    Intent intent = new Intent().putExtra(MainActivity.EXTRA_PAYMENT_RESULT, paymentMethodNonce);
    setResult(RESULT_OK, intent);
    finish();
}
 
Example #29
Source File: ThreeDSecureTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_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());

            ThreeDSecureInfo threeDSecureInfo = ((CardNonce) paymentMethodNonce).getThreeDSecureInfo();
            assertFalse(threeDSecureInfo.isLiabilityShifted());
            assertFalse(threeDSecureInfo.isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });

    ThreeDSecureRequest request = new ThreeDSecureRequest()
            .nonce(nonce)
            .amount("5");

    ThreeDSecure.performVerification(fragment, request);

    mCountDownLatch.await();
}
 
Example #30
Source File: BraintreeFragmentUnitTest.java    From braintree_android with MIT License 5 votes vote down vote up
@Test
public void addListener_flushesPaymentMethodNonceCreatedCallback() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mAppCompatActivity, TOKENIZATION_KEY);
    fragment.postCallback(new CardNonce());

    fragment.addListener(new PaymentMethodNonceCreatedListener() {
        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            mCalled.set(true);
        }
    });

    assertTrue(mCalled.get());
}