use of com.braintreepayments.api.interfaces.PayPalApprovalHandler in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_customHandlerCancelCallbackIsInvoked.
@Test
public void requestOneTimePayment_customHandlerCancelCallbackIsInvoked() throws InterruptedException {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"), new PayPalApprovalHandler() {
@Override
public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
paypalApprovalCallback.onCancel();
}
});
verify(fragment).postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
use of com.braintreepayments.api.interfaces.PayPalApprovalHandler in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_customHandlerIsCalledCorrectly.
@Test(timeout = 1000)
public void requestOneTimePayment_customHandlerIsCalledCorrectly() throws InterruptedException {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
final CountDownLatch latch = new CountDownLatch(1);
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"), new PayPalApprovalHandler() {
@Override
public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
latch.countDown();
}
});
latch.await();
}
use of com.braintreepayments.api.interfaces.PayPalApprovalHandler in project braintree_android by braintree.
the class PayPal method getDefaultApprovalHandler.
private static PayPalApprovalHandler getDefaultApprovalHandler(final BraintreeFragment fragment) {
return new PayPalApprovalHandler() {
@Override
public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
PendingRequest pendingRequest = PayPalOneTouchCore.getStartIntent(fragment.getApplicationContext(), request);
if (pendingRequest.isSuccess() && pendingRequest.getRequestTarget() == RequestTarget.wallet) {
sendAnalyticsForPayPal(fragment, request, true, RequestTarget.wallet);
fragment.startActivityForResult(pendingRequest.getIntent(), BraintreeRequestCodes.PAYPAL);
} else if (pendingRequest.isSuccess() && pendingRequest.getRequestTarget() == RequestTarget.browser) {
sendAnalyticsForPayPal(fragment, request, true, RequestTarget.browser);
fragment.browserSwitch(BraintreeRequestCodes.PAYPAL, pendingRequest.getIntent());
} else {
sendAnalyticsForPayPal(fragment, request, false, null);
}
}
};
}
use of com.braintreepayments.api.interfaces.PayPalApprovalHandler in project braintree_android by braintree.
the class PayPalUnitTest method requestBillingAgreement_paypalCreditReturnedInResponse.
@Test
public void requestBillingAgreement_paypalCreditReturnedInResponse() throws InterruptedException {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_billing_agreement_response.json")).build();
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(PayPalAccountNonce.fromJson(stringFromFixture("payment_methods/paypal_account_response.json")));
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestBillingAgreement(fragment, new PayPalRequest().offerCredit(true), new PayPalApprovalHandler() {
@Override
public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
paypalApprovalCallback.onComplete(new Intent().setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&ba_token=EC-HERMES-SANDBOX-EC-TOKEN")));
}
});
ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
verify(fragment).postCallback(nonceCaptor.capture());
verify(fragment).sendAnalyticsEvent("paypal.credit.accepted");
assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) nonceCaptor.getValue();
assertNotNull(payPalAccountNonce.getCreditFinancing());
assertEquals(18, payPalAccountNonce.getCreditFinancing().getTerm());
}
use of com.braintreepayments.api.interfaces.PayPalApprovalHandler in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_paypalCreditReturnedInResponse.
@Test
public void requestOneTimePayment_paypalCreditReturnedInResponse() 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(PayPalAccountNonce.fromJson(stringFromFixture("payment_methods/paypal_account_response.json")));
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").offerCredit(true), 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());
verify(fragment).sendAnalyticsEvent("paypal.credit.accepted");
assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) nonceCaptor.getValue();
assertNotNull(payPalAccountNonce.getCreditFinancing());
assertEquals(18, payPalAccountNonce.getCreditFinancing().getTerm());
}
Aggregations