@Test public void testExecute_WithFirstState() throws Exception { ServiceLocator.getConfigStorage().get().setUserSitesUrl("web-deva.com"); User user = TestUtil.createUser(); user.setActiveted(null); Site parentSite = TestUtil.createSite(); DraftChildSiteRegistration registration = TestUtil.createChildSiteRegistration(parentSite); ChildSiteSettings settings = TestUtil.createChildSiteSettings(registration, parentSite); settings.setCreatedDate(new Date()); settings.setUserId(user.getUserId()); settings.setConfirmCode("confirm"); settings.setAccessLevel(SiteAccessLevel.ADMINISTRATOR); FilledForm filledForm = TestUtil.createFilledForm(registration.getFormId()); FilledFormItem filledFormItemDomainName = TestUtil.createFilledFormItem(FormItemName.YOUR_OWN_DOMAIN_NAME); List<String> values = Arrays.asList("domainName"); filledFormItemDomainName.setValues(values); FilledFormItem filledFormItemSiteName = TestUtil.createFilledFormItem(FormItemName.YOUR_PAGE_SITE_NAME); List<String> siteNameValues = Arrays.asList("siteName"); filledFormItemSiteName.setValues(siteNameValues); filledForm.setFilledFormItems(Arrays.asList(filledFormItemDomainName, filledFormItemSiteName)); settings.setFilledFormId(filledForm.getFilledFormId()); action.setSettingsId(settings.getChildSiteSettingsId()); action.setConfirmCode("confirm"); DraftChildSiteRegistration childSiteRegistration = TestUtil.createChildSiteRegistration("name", "comment"); Site blueprint = TestUtil.createBlueprint(); childSiteRegistration.setBlueprintsId(Arrays.asList(blueprint.getSiteId())); settings.setRequiredToUseSiteBlueprint(true); final SitePaymentSettings sitePaymentSettings = new SitePaymentSettings(); sitePaymentSettings.setSiteStatus(SiteStatus.ACTIVE); settings.setSitePaymentSettings(sitePaymentSettings); settings.setChildSiteRegistration(childSiteRegistration); Assert.assertNull(user.getActiveted()); Assert.assertNull(new UsersManager().getLoginedUser()); Assert.assertNull(ServiceLocator.getPersistance().getSiteBySubDomain("domainname")); ForwardResolution resolutionMock = (ForwardResolution) action.show(); Assert.assertNotNull(new UsersManager().getLoginedUser()); Assert.assertEquals(user, new UsersManager().getLoginedUser()); Assert.assertEquals( "/account/registration/childSiteRigistrationConfirmationFirstState.jsp", resolutionMock.getPath()); Assert.assertNotNull(user.getActiveted()); Assert.assertNotNull(new UsersManager().getLoginedUser()); Assert.assertEquals(user, new UsersManager().getLoginedUser()); Site site = ServiceLocator.getPersistance().getSiteBySubDomain("domainname"); Assert.assertNotNull(site); Assert.assertNotNull(new UserRightManager(user).toSite(site).getSiteAccessType()); Assert.assertEquals( settings.getAccessLevel(), new UserRightManager(user).toSite(site).getSiteAccessType()); Assert.assertEquals("domainname", site.getSubDomain()); Assert.assertEquals("http://domainname.web-deva.com", action.getUrl()); Assert.assertNotNull(action.getTellFriendHtml()); Assert.assertEquals(2, site.getPages().size()); Assert.assertEquals("siteName", site.getTitle()); Assert.assertEquals(blueprint, site.getBlueprintParent()); }
@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; }