use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.
the class ThreeDSecureTest method performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard.
@Test(timeout = 10000)
public void performVerification_acceptsAThreeDSecureRequest_postsPaymentMethodNonceToListenersWhenLookupReturnsACard() throws InterruptedException, InvalidArgumentException {
String clientToken = new TestClientTokenBuilder().withThreeDSecure().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();
}
use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.
the class TokenizationClientTest method tokenize_tokenizesAPayPalAccountWithATokenizationKey.
@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();
}
use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.
the class BraintreeFragmentTestUtils method tokenize.
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];
}
use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.
the class BraintreeFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
if (mContext == null) {
mContext = getActivity().getApplicationContext();
}
mNewActivityNeedsConfiguration = false;
mCrashReporter = CrashReporter.setup(this);
mSessionId = getArguments().getString(EXTRA_SESSION_ID);
mIntegrationType = getArguments().getString(EXTRA_INTEGRATION_TYPE);
mAuthorization = getArguments().getParcelable(EXTRA_AUTHORIZATION_TOKEN);
mAnalyticsDatabase = AnalyticsDatabase.getInstance(getApplicationContext());
if (mHttpClient == null) {
mHttpClient = new BraintreeHttpClient(mAuthorization);
}
if (savedInstanceState != null) {
List<PaymentMethodNonce> paymentMethodNonces = savedInstanceState.getParcelableArrayList(EXTRA_CACHED_PAYMENT_METHOD_NONCES);
if (paymentMethodNonces != null) {
mCachedPaymentMethodNonces.addAll(paymentMethodNonces);
}
mHasFetchedPaymentMethodNonces = savedInstanceState.getBoolean(EXTRA_FETCHED_PAYMENT_METHOD_NONCES);
try {
setConfiguration(Configuration.fromJson(savedInstanceState.getString(EXTRA_CONFIGURATION)));
} catch (JSONException ignored) {
}
} else {
if (mAuthorization instanceof TokenizationKey) {
sendAnalyticsEvent("started.client-key");
} else {
sendAnalyticsEvent("started.client-token");
}
}
fetchConfiguration();
}
use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.
the class BraintreeFragment method postCallback.
protected void postCallback(final PaymentMethodNonce paymentMethodNonce) {
if (paymentMethodNonce instanceof AndroidPayCardNonce) {
for (PaymentMethodNonce cachedPaymentMethodNonce : new ArrayList<>(mCachedPaymentMethodNonces)) {
if (cachedPaymentMethodNonce instanceof AndroidPayCardNonce) {
mCachedPaymentMethodNonces.remove(cachedPaymentMethodNonce);
}
}
}
mCachedPaymentMethodNonces.add(0, paymentMethodNonce);
postOrQueueCallback(new QueuedCallback() {
@Override
public boolean shouldRun() {
return mPaymentMethodNonceCreatedListener != null;
}
@Override
public void run() {
mPaymentMethodNonceCreatedListener.onPaymentMethodNonceCreated(paymentMethodNonce);
}
});
}
Aggregations