Search in sources :

Example 26 with PayPalRequest

use of com.braintreepayments.api.models.PayPalRequest 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 27 with PayPalRequest

use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.

the class PayPalUnitTest method requestBillingAgreement_cancelUrlTriggersCancelListener.

@Test
public void requestBillingAgreement_cancelUrlTriggersCancelListener() {
    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/cancel"));
            PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
            return null;
        }
    }).when(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), any(Intent.class));
    PayPal.requestBillingAgreement(fragment, new PayPalRequest());
    verify(fragment).postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
Also used : PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) Intent(android.content.Intent) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with PayPalRequest

use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.

the class PayPalUnitTest method requestBillingAgreement_startsBrowser.

@Test
public void requestBillingAgreement_startsBrowser() throws InvalidArgumentException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_billing_agreement_response.json")).build();
    PayPal.requestBillingAgreement(fragment, new PayPalRequest());
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), captor.capture());
    Intent intent = captor.getValue();
    assertEquals(Intent.ACTION_VIEW, intent.getAction());
    assertEquals("checkout.paypal.com", intent.getData().getHost());
    assertEquals("/one-touch-login-sandbox/index.html", intent.getData().getPath());
    assertEquals("create_payment_resource", intent.getData().getQueryParameter("action"));
    assertEquals("63cc461306c35080ce674a3372bffe1580b4130c7fd33d33968aa76bb93cdd06|created_at=2015-10-13T18:49:48.371382792+0000&merchant_id=dcpspy2brwdjr3qn&public_key=9wwrzqk3vr3t4nc8", intent.getData().getQueryParameter("authorization_fingerprint"));
    assertFalse(intent.getData().getQueryParameterNames().contains("amount"));
    assertFalse(intent.getData().getQueryParameterNames().contains("currency_iso_code"));
    assertEquals("false", intent.getData().getQueryParameter("experience_profile[address_override]"));
    assertEquals("false", intent.getData().getQueryParameter("experience_profile[no_shipping]"));
    assertEquals("dcpspy2brwdjr3qn", intent.getData().getQueryParameter("merchant_id"));
    assertEquals("com.braintreepayments.api.test.braintree://onetouch/v1/success", intent.getData().getQueryParameter("return_url"));
    assertEquals("com.braintreepayments.api.test.braintree://onetouch/v1/cancel", intent.getData().getQueryParameter("cancel_url"));
}
Also used : Intent(android.content.Intent) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with PayPalRequest

use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.

the class PayPalUnitTest method requestOneTimePayment_containsOfferPayPalCreditParam.

@Test
public void requestOneTimePayment_containsOfferPayPalCreditParam() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").offerCredit(true));
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(contains("/paypal_hermes/create_payment_resource"), dataCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject json = new JSONObject(dataCaptor.getValue());
    assertTrue(json.getBoolean("offer_paypal_credit"));
}
Also used : JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with PayPalRequest

use of com.braintreepayments.api.models.PayPalRequest 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)

Aggregations

PayPalRequest (com.braintreepayments.api.models.PayPalRequest)39 Test (org.junit.Test)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)36 JSONObject (org.json.JSONObject)21 Intent (android.content.Intent)18 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 Matchers.anyString (org.mockito.Matchers.anyString)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Answer (org.mockito.stubbing.Answer)12 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)12 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)11 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)11 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)10 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)6 Request (com.paypal.android.sdk.onetouch.core.Request)6 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)5 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)5 SharedPreferences (android.content.SharedPreferences)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)4 BraintreeSharedPreferences (com.braintreepayments.api.internal.BraintreeSharedPreferences)4