use of com.braintreepayments.api.models.PayPalAccountBuilder in project braintree_android by braintree.
the class TokenizationClientUnitTest method tokenize_tokenizesNonCardPaymentMethodsWithRestWhenGraphQLIsEnabled.
@Test
public void tokenize_tokenizesNonCardPaymentMethodsWithRestWhenGraphQLIsEnabled() {
BraintreeFragment fragment = new MockFragmentBuilder().configuration(new TestConfigurationBuilder().graphQL().build()).build();
TokenizationClient.tokenize(fragment, new PayPalAccountBuilder(), null);
TokenizationClient.tokenize(fragment, new UnionPayCardBuilder(), null);
TokenizationClient.tokenize(fragment, new VenmoAccountBuilder(), null);
verifyZeroInteractions(fragment.getGraphQLHttpClient());
}
use of com.braintreepayments.api.models.PayPalAccountBuilder 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.PayPalAccountBuilder in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_containsPaymentIntent.
@Test
public void requestOneTimePayment_containsPaymentIntent() throws JSONException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
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 {
PayPalAccountBuilder payPalAccountBuilder = (PayPalAccountBuilder) invocation.getArguments()[1];
JSONObject payload = new JSONObject(payPalAccountBuilder.build());
assertEquals(PayPalRequest.INTENT_SALE, payload.getJSONObject("paypalAccount").getString("intent"));
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
latch.countDown();
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").intent(PayPalRequest.INTENT_SALE));
SharedPreferences prefs = BraintreeSharedPreferences.getSharedPreferences(RuntimeEnvironment.application);
assertNull(prefs.getString("com.braintreepayments.api.PayPal.PAYPAL_REQUEST_KEY", null));
latch.await();
}
use of com.braintreepayments.api.models.PayPalAccountBuilder in project braintree_android by braintree.
the class PayPal method parseResponse.
/**
* Parse the PayPal response URL using OneTouchCore.
*
* @param paypalRequest Original {@link PayPalRequest} that started this flow.
* @param result Context that received the result.
* @param intent The {@link Intent} returned in result.
* @return A {@link PayPalAccountBuilder} or null if the intent is invalid.
*/
private static PayPalAccountBuilder parseResponse(PayPalRequest paypalRequest, Request request, Result result, Intent intent) {
PayPalAccountBuilder paypalAccountBuilder = new PayPalAccountBuilder().clientMetadataId(request.getClientMetadataId());
if (request instanceof CheckoutRequest && paypalRequest != null) {
paypalAccountBuilder.intent(paypalRequest.getIntent());
}
if (isAppSwitch(intent)) {
paypalAccountBuilder.source("paypal-app");
} else {
paypalAccountBuilder.source("paypal-browser");
}
JSONObject payload = result.getResponse();
// Modify payload in 'mock' mode to scope the response
try {
JSONObject clientJson = payload.getJSONObject("client");
JSONObject response = payload.getJSONObject("response");
if (EnvironmentManager.MOCK.equalsIgnoreCase(clientJson.getString("client")) && response.getString("code") != null && !(request instanceof CheckoutRequest)) {
payload.put("response", new JSONObject().put("code", "fake-code:" + ((AuthorizationRequest) request).getScopeString()));
}
} catch (JSONException ignored) {
}
paypalAccountBuilder.oneTouchCoreData(payload);
return paypalAccountBuilder;
}
Aggregations