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());
}
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);
}
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();
}
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);
}
}
}
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);
}
}
};
}
Aggregations