use of com.braintreepayments.api.models.PayPalPaymentResource in project braintree_android by braintree.
the class PayPal method requestOneTimePayment.
private static void requestOneTimePayment(final BraintreeFragment fragment, final PayPalRequest paypalRequest, final boolean isBillingAgreement, final PayPalApprovalHandler handler) {
final HttpResponseCallback callback = new HttpResponseCallback() {
@Override
public void success(String responseBody) {
final PayPalPaymentResource paypalPaymentResource;
try {
paypalPaymentResource = PayPalPaymentResource.fromJson(responseBody);
} catch (JSONException e) {
fragment.postCallback(e);
return;
}
String redirectUrl = Uri.parse(paypalPaymentResource.getRedirectUrl()).buildUpon().appendQueryParameter(USER_ACTION_KEY, paypalRequest.getUserAction()).toString();
Request request;
if (isBillingAgreement) {
request = getBillingAgreementRequest(fragment, redirectUrl);
} else {
request = getCheckoutRequest(fragment, redirectUrl);
}
startPayPal(fragment, request, handler);
}
@Override
public void failure(Exception e) {
fragment.postCallback(e);
}
};
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
if (!configuration.isPayPalEnabled()) {
fragment.postCallback(new BraintreeException("PayPal is not enabled"));
return;
}
if (!isManifestValid(fragment)) {
fragment.sendAnalyticsEvent("paypal.invalid-manifest");
fragment.postCallback(new BraintreeException("BraintreeBrowserSwitchActivity missing, " + "incorrectly configured in AndroidManifest.xml or another app defines the same browser " + "switch url as this app. See " + "https://developers.braintreepayments.com/guides/client-sdk/android/v2#browser-switch " + "for the correct configuration"));
return;
}
try {
persistPayPalRequest(fragment.getApplicationContext(), paypalRequest);
createPaymentResource(fragment, paypalRequest, isBillingAgreement, callback);
} catch (JSONException | ErrorWithResponse | BraintreeException ex) {
fragment.postCallback(ex);
}
}
});
}
Aggregations