use of com.braintreepayments.api.interfaces.PayPalApprovalCallback 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.interfaces.PayPalApprovalCallback in project braintree_android by braintree.
the class PayPal method startPayPal.
private static void startPayPal(final BraintreeFragment fragment, Request request, PayPalApprovalHandler handler) {
persistRequest(fragment.getApplicationContext(), request);
PayPalApprovalCallback callback = null;
if (handler == null) {
handler = getDefaultApprovalHandler(fragment);
} else {
callback = new PayPalApprovalCallback() {
@Override
public void onComplete(Intent data) {
PayPal.onActivityResult(fragment, Activity.RESULT_OK, data);
}
@Override
public void onCancel() {
fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
};
}
handler.handleApproval(request, callback);
}
Aggregations