@RemoteMethod public GoToPaypalResponse goToPaypal(final PaypalRequest request) throws Exception { final PaymentReason paymentReason = PaymentReason.SHROGGLE_MONTHLY_PAYMENT; final Site site = ServiceLocator.getPersistance().getSite(request.getOwnerId()); if (site == null) { throw new PaymentException( "Cannot pay for null site. Site by Id=" + request.getOwnerId() + " not found."); } final GoToPaypalResponse response = new GoToPaypalResponse(); if (site.getSitePaymentSettings().getSiteStatus() == SiteStatus.ACTIVE && site.getSitePaymentSettings().getChargeType() == ChargeType.SITE_ONE_TIME_FEE) { response.setActivatedWithOneTimeFee(true); return response; } final String redirectOnErrorUrl = "/account/updatePaymentInfo.action?showPaypalError=true"; final PaypalPaymentInfoRequest paymentInfoRequest = new PaypalPaymentInfoRequest( request.getOwnerId(), PaymentSettingsOwnerType.SITE, request.getChargeType(), request.getRedirectToUrl(), redirectOnErrorUrl, paymentReason, null); final int requestId = ServiceLocator.getPaypalPaymentInfoRequestStorage().put(paymentInfoRequest); final String description; if (request.getChargeType().getPaymentPeriod().equals(PaymentPeriod.MONTH)) { description = "Monthly cost of " + site.getTitle() + " site."; } else { description = "Annual cost of " + site.getTitle() + " site."; } // Here we should check, which paypal we should use: default Web-Deva`s or own. Tolik final PayPal payPal = (PayPal) new PaymentSettingsOwnerManager(site).getAppropriatePaymentSystem(); final String applicationUrl = "http://" + ServiceLocator.getConfigStorage().get().getApplicationUrl(); final String token = payPal.setCustomerBillingAgreement( applicationUrl + "/account/createProfile.action?requestId=" + requestId, applicationUrl + "/account/updatePaymentInfo.action", description, paymentReason, site.getSiteId(), null, null); response.setPaypalLink(payPal.getPaypalLink() + token); if (site.getSitePaymentSettings().getSiteStatus() == SiteStatus.ACTIVE) { if (site.getSitePaymentSettings().getPaymentMethod() == PaymentMethod.AUTHORIZE_NET) { response.setJavienActivated(true); } else if (payPal.getProfileStatus(site.getSitePaymentSettings().getRecurringPaymentId()) == PayPalRecurringProfileStatus.ACTIVE) { response.setActiveProfile(true); } } return response; }