Search in sources :

Example 6 with Request

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

the class PayPalRequestUnitTest method getAuthorizationRequest_buildsWithCustomStageUrl.

@Test
public void getAuthorizationRequest_buildsWithCustomStageUrl() throws JSONException, InvalidArgumentException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_custom_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.authorization(Authorization.fromString(TOKENIZATION_KEY)).configuration(configuration).build();
    Request request = PayPal.getAuthorizationRequest(fragment);
    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 7 with Request

use of com.paypal.android.sdk.onetouch.core.Request 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);
}
Also used : PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Request

use of com.paypal.android.sdk.onetouch.core.Request 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();
}
Also used : PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) CountDownLatch(java.util.concurrent.CountDownLatch) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Request

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

the class PayPal method onActivityResult.

/**
 * The result from PayPal's request.
 *
 * @param fragment A {@link BraintreeFragment} used to process the request.
 * @param data Data associated with the result.
 */
protected static void onActivityResult(final BraintreeFragment fragment, int resultCode, Intent data) {
    Request request = getPersistedRequest(fragment.getApplicationContext());
    if (resultCode == Activity.RESULT_OK && data != null && request != null) {
        boolean isAppSwitch = isAppSwitch(data);
        Result result = PayPalOneTouchCore.parseResponse(fragment.getApplicationContext(), request, data);
        switch(result.getResultType()) {
            case Error:
                fragment.postCallback(new BrowserSwitchException(result.getError().getMessage()));
                sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "failed");
                break;
            case Cancel:
                sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "canceled");
                fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
                break;
            case Success:
                onSuccess(fragment, data, request, result);
                sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "succeeded");
                break;
        }
    } else {
        String type;
        if (request != null) {
            type = request.getClass().getSimpleName().toLowerCase();
        } else {
            type = "unknown";
        }
        fragment.sendAnalyticsEvent("paypal." + type + ".canceled");
        if (resultCode != Activity.RESULT_CANCELED) {
            fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
        }
    }
}
Also used : Request(com.paypal.android.sdk.onetouch.core.Request) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest) BrowserSwitchException(com.braintreepayments.api.exceptions.BrowserSwitchException) Result(com.paypal.android.sdk.onetouch.core.Result)

Example 10 with Request

use of com.paypal.android.sdk.onetouch.core.Request 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);
            }
        }
    };
}
Also used : PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) Request(com.paypal.android.sdk.onetouch.core.Request) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest)

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