private String createRedirectOnErrorUrl(final PaypalRequest request) { final int pageBreakIndexAfterError = request.isPaymentRequired() ? (request.getPageBreakIndex() - 1) : request.getPageBreakIndex(); final String showPaypalErrorMessage = request.isPaymentRequired() ? "&paymentError" + request.getFilledFormToUpdateId() + "=true" : ""; return request.getRedirectToUrl() + (request.getRedirectToUrl().contains("?") ? "&" : "?") + "pageBreaksToPass="******"&filledFormToUpdateId=" + request.getFilledFormToUpdateId() + showPaypalErrorMessage; }
@RemoteMethod public String goToPaypalCSR(final PaypalRequest request) throws Exception { final PaymentReason paymentReason = PaymentReason.CHILD_SITE_CREATION; // Modifying redirect url // Check on hash presence. We sould remove all old hash. if (request.getRedirectToUrl().contains("#")) { request.setRedirectToUrl( request.getRedirectToUrl().substring(0, request.getRedirectToUrl().indexOf("#"))); } if (request.getPageBreakIndex() > request.getTotalPageBreaks()) { // If payment page is last page then update return url with setting that will show message // about registration completion. request.setRedirectToUrl( request.getRedirectToUrl() + "#showSuccessMessageLastPage" + request.getWidgetId()); } else { // Upadting return from paypal url with correct form page. request.setRedirectToUrl( request.getRedirectToUrl() + (request.getRedirectToUrl().contains("?") ? "&" : "?") + "pageBreaksToPass="******"&filledFormToUpdateId=" + request.getFilledFormToUpdateId() + "&childSiteUserId=" + request.getChildSiteUserId() + "&settingsId=" + request.getSettingsId() + "#showSuccessMessage" + request.getWidgetId()); } final PaypalPaymentInfoRequest paymentInfoRequest = new PaypalPaymentInfoRequest( request.getOwnerId(), PaymentSettingsOwnerType.CHILD_SITE_SETTINGS, request.getChargeType(), request.getRedirectToUrl(), createRedirectOnErrorUrl(request), paymentReason, request.getChildSiteUserId()); final int requestId = ServiceLocator.getPaypalPaymentInfoRequestStorage().put(paymentInfoRequest); final ChildSiteSettings childSiteSettings = ServiceLocator.getPersistance().getChildSiteSettingsById(request.getSettingsId()); // Here we should check, which paypal we should use: default Web-Deva`s or own. Tolik final PayPal payPal = (PayPal) new PaymentSettingsOwnerManager(childSiteSettings).getAppropriatePaymentSystem(); final String networkName = childSiteSettings.getChildSiteRegistration().getName(); final String applicationUrl = "http://" + ServiceLocator.getConfigStorage().get().getApplicationUrl(); final String token = payPal.setCustomerBillingAgreement( applicationUrl + "/account/createProfile.action?requestId=" + requestId, request.getRedirectToUrl() + (request.getRedirectToUrl().contains("?") ? "&" : "?") + "pageBreaksToPass="******"&filledFormToUpdateId=" + request.getFilledFormToUpdateId(), (networkName + " fee for child site"), paymentReason, null, request.getOwnerId(), request.getChildSiteUserId()); return (payPal.getPaypalLink() + token); }