All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.website.signup.SignupBillingInformationActionHelper Maven / Gradle / Ivy

/*
 * Copyright 2007-2009, 2015, 2016 by AO Industries, Inc.,
 * 7262 Bull Pen Cir, Mobile, Alabama, 36695, U.S.A.
 * All rights reserved.
 */
package com.aoindustries.website.signup;

import com.aoindustries.creditcards.CreditCard;
import com.aoindustries.encoding.ChainWriter;
import static com.aoindustries.website.signup.ApplicationResources.accessor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

/**
 * Managed5Action and Dedicated5Action both use this to setup the request attributes.  This is implemented
 * here because inheritance is not possible and neither one is logically above the other.
 *
 * @author  AO Industries, Inc.
 */
final public class SignupBillingInformationActionHelper {

	/**
	 * Make no instances.
	 */
	private SignupBillingInformationActionHelper() {}

	public static void setRequestAttributes(HttpServletRequest request) {
		setBillingExpirationYearsRequestAttribute(request);
	}

	public static void setBillingExpirationYearsRequestAttribute(HttpServletRequest request) {
		// Build the list of years
		List billingExpirationYears = new ArrayList(12);
		int startYear = Calendar.getInstance().get(Calendar.YEAR);
		for(int c=0;c<12;c++) billingExpirationYears.add(Integer.toString(startYear+c));

		// Store to request attributes
		request.setAttribute("billingExpirationYears", billingExpirationYears);
	}

	/**
	 * Only shows the first two and last four digits of a card number.
	 *
	 * @deprecated  Please call CreditCard.maskCreditCardNumber directly.
	 */
	@Deprecated
	public static String hideCreditCardNumber(String number) {
		return CreditCard.maskCreditCardNumber(number);
	}

	public static String getBillingCardNumber(SignupBillingInformationForm signupBillingInformationForm) {
		return CreditCard.maskCreditCardNumber(signupBillingInformationForm.getBillingCardNumber());
	}

	public static void setConfirmationRequestAttributes(
		ServletContext servletContext,
		HttpServletRequest request,
		SignupBillingInformationForm signupBillingInformationForm
	) throws IOException {
		// Store as request attribute for the view
		request.setAttribute("billingCardNumber", getBillingCardNumber(signupBillingInformationForm));
	}

	public static void printConfirmation(ChainWriter emailOut, SignupBillingInformationForm signupBillingInformationForm) throws IOException {
		emailOut.print("    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingContact.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingContact()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingEmail.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingEmail()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingCardholderName.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingCardholderName()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingCardNumber.prompt")).print("\n"
					 + "        ").encodeXhtml(getBillingCardNumber(signupBillingInformationForm)).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingExpirationDate.prompt")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingExpirationDate.hidden")).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingStreetAddress.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingStreetAddress()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingCity.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingCity()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingState.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingState()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingZip.prompt")).print("\n"
					 + "        ").encodeXhtml(signupBillingInformationForm.getBillingZip()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingUseMonthly.prompt")).print("\n"
					 + "        ").print(accessor.getMessage(signupBillingInformationForm.getBillingUseMonthly() ? "signupBillingInformationForm.billingUseMonthly.yes" : "signupBillingInformationForm.billingUseMonthly.no")).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupBillingInformationForm.billingPayOneYear.prompt")).print("\n"
					 + "        ").print(accessor.getMessage(signupBillingInformationForm.getBillingPayOneYear() ? "signupBillingInformationForm.billingPayOneYear.yes" : "signupBillingInformationForm.billingPayOneYear.no")).print("\n"
					 + "    \n");
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy