Search in sources :

Example 21 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class PayPalRequestUnitTest method getAuthorizationRequest_buildsWithOfflineStageUrl.

@Test
public void getAuthorizationRequest_buildsWithOfflineStageUrl() throws JSONException, InvalidArgumentException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_offline_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.authorization(Authorization.fromString(TOKENIZATION_KEY)).configuration(configuration).build();
    Request request = PayPal.getAuthorizationRequest(fragment);
    assertEquals(EnvironmentManager.MOCK, request.getEnvironment());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Test(org.junit.Test)

Example 22 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class PayPalRequestUnitTest method getCheckoutRequest_buildsWithCustomStageUrl.

@Test
public void getCheckoutRequest_buildsWithCustomStageUrl() throws JSONException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_custom_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build();
    Request request = PayPal.getCheckoutRequest(fragment, null);
    assertEquals("custom", request.getEnvironment());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Test(org.junit.Test)

Example 23 with Request

use of com.paypal.android.sdk.onetouch.core.Request 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());
}
Also used : PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) Intent(android.content.Intent) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with Request

use of com.paypal.android.sdk.onetouch.core.Request 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());
}
Also used : PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) Intent(android.content.Intent) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with Request

use of com.paypal.android.sdk.onetouch.core.Request 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);
}
Also used : PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) Intent(android.content.Intent) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)26 Request (com.paypal.android.sdk.onetouch.core.Request)26 Test (org.junit.Test)23 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)21 Intent (android.content.Intent)12 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)12 Configuration (com.braintreepayments.api.models.Configuration)10 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)8 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)6 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)6 Result (com.paypal.android.sdk.onetouch.core.Result)6 Context (android.content.Context)5 Bundle (android.os.Bundle)5 ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)5 Protocol (com.paypal.android.sdk.onetouch.core.enums.Protocol)5 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)3 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)3 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)3