use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestBillingAgreement_persistsPayPalRequest.
@Test
public void requestBillingAgreement_persistsPayPalRequest() {
BraintreeFragment braintreeFragment = mMockFragmentBuilder.build();
SharedPreferences prefs = BraintreeSharedPreferences.getSharedPreferences(RuntimeEnvironment.application);
PayPal.requestOneTimePayment(braintreeFragment, new PayPalRequest("1").intent(PayPalRequest.INTENT_SALE));
assertNotNull(prefs.getString("com.braintreepayments.api.PayPal.PAYPAL_REQUEST_KEY", null));
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_customHandlerSuccessCallbackIsInvoked.
@Test
public void requestOneTimePayment_customHandlerSuccessCallbackIsInvoked() throws InterruptedException {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
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"), 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);
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPal method requestOneTimePayment.
private static void requestOneTimePayment(final BraintreeFragment fragment, final PayPalRequest paypalRequest, final boolean isBillingAgreement, final PayPalApprovalHandler handler) {
final HttpResponseCallback callback = new HttpResponseCallback() {
@Override
public void success(String responseBody) {
final PayPalPaymentResource paypalPaymentResource;
try {
paypalPaymentResource = PayPalPaymentResource.fromJson(responseBody);
} catch (JSONException e) {
fragment.postCallback(e);
return;
}
String redirectUrl = Uri.parse(paypalPaymentResource.getRedirectUrl()).buildUpon().appendQueryParameter(USER_ACTION_KEY, paypalRequest.getUserAction()).toString();
Request request;
if (isBillingAgreement) {
request = getBillingAgreementRequest(fragment, redirectUrl);
} else {
request = getCheckoutRequest(fragment, redirectUrl);
}
startPayPal(fragment, request, handler);
}
@Override
public void failure(Exception e) {
fragment.postCallback(e);
}
};
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
if (!configuration.isPayPalEnabled()) {
fragment.postCallback(new BraintreeException("PayPal is not enabled"));
return;
}
if (!isManifestValid(fragment)) {
fragment.sendAnalyticsEvent("paypal.invalid-manifest");
fragment.postCallback(new BraintreeException("BraintreeBrowserSwitchActivity missing, " + "incorrectly configured in AndroidManifest.xml or another app defines the same browser " + "switch url as this app. See " + "https://developers.braintreepayments.com/guides/client-sdk/android/v2#browser-switch " + "for the correct configuration"));
return;
}
try {
persistPayPalRequest(fragment.getApplicationContext(), paypalRequest);
createPaymentResource(fragment, paypalRequest, isBillingAgreement, callback);
} catch (JSONException | ErrorWithResponse | BraintreeException ex) {
fragment.postCallback(ex);
}
}
});
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPal method onSuccess.
private static void onSuccess(final BraintreeFragment fragment, Intent data, Request request, Result result) {
PayPalRequest paypalRequest = getPersistedPayPalRequest(fragment.getApplicationContext());
TokenizationClient.tokenize(fragment, parseResponse(paypalRequest, request, result, data), new PaymentMethodNonceCallback() {
@Override
public void success(PaymentMethodNonce paymentMethodNonce) {
if (paymentMethodNonce instanceof PayPalAccountNonce && ((PayPalAccountNonce) paymentMethodNonce).getCreditFinancing() != null) {
fragment.sendAnalyticsEvent("paypal.credit.accepted");
}
fragment.postCallback(paymentMethodNonce);
}
@Override
public void failure(Exception exception) {
fragment.postCallback(exception);
}
});
}
Aggregations