use of com.braintreepayments.api.interfaces.PaymentMethodNonceCallback in project braintree_android by braintree.
the class UnionPayUnitTest method mockSuccessCallback.
/* helpers */
private void mockSuccessCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
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));
}
use of com.braintreepayments.api.interfaces.PaymentMethodNonceCallback 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.interfaces.PaymentMethodNonceCallback in project braintree_android by braintree.
the class CardUnitTest method mockFailureCallback.
private void mockFailureCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).failure(new ErrorWithResponse(422, ""));
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
}
use of com.braintreepayments.api.interfaces.PaymentMethodNonceCallback in project braintree_android by braintree.
the class CardUnitTest method mockSuccessCallback.
/* helpers */
private void mockSuccessCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new CardNonce());
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
}
use of com.braintreepayments.api.interfaces.PaymentMethodNonceCallback in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_isSuccessful.
@Test
public void requestOneTimePayment_isSuccessful() {
final BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Intent intent = new Intent().setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN"));
PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
return null;
}
}).when(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), any(Intent.class));
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"));
verify(fragment).postCallback(any(PayPalAccountNonce.class));
SharedPreferences prefs = BraintreeSharedPreferences.getSharedPreferences(RuntimeEnvironment.application);
assertNull(prefs.getString("com.braintreepayments.api.PayPal.REQUEST_KEY", null));
assertNull(prefs.getString("com.braintreepayments.api.PayPal.REQUEST_TYPE_KEY", null));
}
Aggregations