Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
nameblue

This section describes how a custom provisioning provider payment gateway can be created.

 

What does this section cover?

Table of Contents

...

Ui expand
titleProvisioning providers metadata file
Code Block
languagexml
titlepaymentgateways.xml
collapsetrue
<paymentgatewaysconfig>
	<paymentgateways>
		<paymentgateway>
			<protocol>PAYEEZY</protocol>
			<name>Payeezy</name>
			<processejbname>ejb/PAYEEZYCRMProcessPayeezyGateway</processejbname>
			<paymentmethods>
				<paymentmethod>
					<type>CREDIT_CARD</type>
					<name>key_credit_card</name>
					<controlVerification>true</controlVerification>
				</paymentmethod>
			</paymentmethods>
			<generalparameters>
				<generalparameter>
					<generalparameterid>mode</generalparameterid>
					<generalparametername>key_mode</generalparametername>
					<generalparametertype>java.lang.String</generalparametertype>
				</generalparameter>
			</generalparameters>
		</paymentgateway>
	</paymentgateways>
</paymentgatewaysconfig>

2.

...

Payment Gateway Parameters Enum

This enum will be used to define the authentication setting parameters. Note that 'order' property will be used to define the parameter's order on the screen.

...

Code Block
languagejava
titlePAYEEZYCRMUIPayeezyPaymentGatewaySettingBean.java
linenumberstrue
collapsetrue
package payeezy.process.paymentgateway.payeezy;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import com.crm.businessobject.paymentgateway.CRMBOPaymentGatewayCurrencyBean;
import com.crm.businessobject.paymentgateway.CRMBOPaymentGatewayParameterBean;
import com.crm.businessobject.paymentgateway.CRMBOPaymentGatewayParameterValueBean;
import com.crm.dataobject.CRMDO;
import com.crm.dataobject.financialtransactions.PaymentCancellationType;
import com.crm.dataobject.financialtransactions.PaymentMethod;
import com.crm.dataobject.paymentgateway.CRMDOPaymentGatewayCurrency;
import com.crm.dataobject.paymentgateway.CRMDOPaymentGatewayParameter;
import com.crm.dataobject.paymentgateway.CRMDOPaymentGatewayParameterValue;
import com.crm.dataobject.paymentgateway.CRMDOPaymentGatewaySetting;
import com.crm.dataobject.paymentgateway.PaymentGatewayLifeCycleState;
import com.crm.dataobject.paymentgateway.PaymentGatewayParameter;
import com.crm.dataobject.platform.CurrenciesScope;
import com.crm.framework.main.LookupBuilder;
import com.crm.process.paymentgateway.CRMUIPaymentGatewaySettingBean;
import payeezy.businessobject.paymentgateway.payeezy.PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean;
import payeezy.dataobject.paymentgateway.payeezy.PayeezyMode;
import payeezy.dataobject.paymentgateway.payeezy.PayeezyParameter;
/**
 * Session Bean implementation class PAYEEZYCRMUIPayeezyPaymentGatewaySettingBean
 */
@Stateless
@LocalBean
public class PAYEEZYCRMUIPayeezyPaymentGatewaySettingBean extends CRMUIPaymentGatewaySettingBean {
       
   
	private static final long serialVersionUID = 1L;
	
	@EJB private PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean payeezyPaymentGatewaySettingBean;
	@EJB private CRMBOPaymentGatewayCurrencyBean paymentGatewayCurrencyBean;
	@EJB private CRMBOPaymentGatewayParameterBean paymentGatewayParameterBean;
	@EJB private CRMBOPaymentGatewayParameterValueBean paymentGatewayParameterValueBean;
	/**
     * @see CRMUIPaymentGatewaySettingBean#CRMUIPaymentGatewaySettingBean()
     */
    public PAYEEZYCRMUIPayeezyPaymentGatewaySettingBean() {
        super();
    }
    
    /**
     * Loads a payment gateway setting form.
     * 
     * @param id - the payment gateway setting id to load
     * @return the loaded form
     * @throws Exception
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public CRMDOPaymentGatewaySetting loadForm(String id) throws Exception {
    	
    	CRMDOPaymentGatewaySetting setting = (CRMDOPaymentGatewaySetting)payeezyPaymentGatewaySettingBean.load(id);
    	
    	setting	= payeezyPaymentGatewaySettingBean.setObjectsFromXML(setting);
    	setting	= payeezyPaymentGatewaySettingBean.initializeParameters(setting);
    	setting = setFinancialInformation(setting);
    	setting.setCurrenciesScope(CurrenciesScope.ALLOW_ALL_CURRENCIES);
    	
    	setting.setPaymentGatewayCurrencies(new HashSet(loadCurrenciesTab(setting)));
    	
    	if((setting.getCurrencies()!=null && setting.getCurrencies().size()>0) ||
    			(setting.getPaymentGatewayCurrencies()!=null && setting.getPaymentGatewayCurrencies().size()>0))
    	{
    		setting.setCurrenciesScope(CurrenciesScope.ALLOW_SPECIFIC_CURRENCIES);
    	}
    	
    	setting = setPaymentGatewayParameters(setting);
    	
    	return setting;
    }
    
    
    /**
     * Loads a payment gateway setting form.
     * 
     * @return the loaded form
     * @throws Exception
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public CRMDOPaymentGatewaySetting loadForm() throws Exception {
		
		CRMDOPaymentGatewaySetting setting= payeezyPaymentGatewaySettingBean.load();
		
    	if (setting==null)
    	{
        	setting = createButton();
    	}
    	else
    	{
    		setting = payeezyPaymentGatewaySettingBean.setObjectsFromXML(setting);
        	setting	= payeezyPaymentGatewaySettingBean.initializeParameters(setting);
        	setting = setFinancialInformation(setting);
    	}
    	
    	setting.setCurrenciesScope(CurrenciesScope.ALLOW_ALL_CURRENCIES);
    	
    	setting.setPaymentGatewayCurrencies(new HashSet(loadCurrenciesTab(setting)));
    	
    	if((setting.getCurrencies()!=null && setting.getCurrencies().size()>0) ||
    			(setting.getPaymentGatewayCurrencies()!=null && setting.getPaymentGatewayCurrencies().size()>0))
    	{
    		setting.setCurrenciesScope(CurrenciesScope.ALLOW_SPECIFIC_CURRENCIES);
    	}
    	
    	setting = setPaymentGatewayParameters(setting);
		
		return setting;
		
    }
    
    
    @SuppressWarnings({ "unchecked", "rawtypes" })
	private CRMDOPaymentGatewaySetting setPaymentGatewayParameters(CRMDOPaymentGatewaySetting setting) throws Exception{
    	Set<PaymentGatewayParameter> paymentGatewayParameters = new HashSet<PaymentGatewayParameter>();
    	
    	setting.setPaymentGatewayParameters(new HashSet(paymentGatewayParameterBean.load(setting)));
    	
    	PayeezyParameter[] braintreeParameters = PayeezyParameter.values();
    	for(PayeezyParameter braintreeParameter:braintreeParameters)
    	{
    		PaymentGatewayParameter paymentGatewayParameter = get(setting.getPaymentGatewayParameters(), braintreeParameter, setting);
    		paymentGatewayParameters.add(paymentGatewayParameter);
    	}
    	
    	setting.setGatewayParameters(paymentGatewayParameters);
    	
    	setting = setParametersVisibility(setting);
    	
    	return setting;
    }
    
    
    private PaymentGatewayParameter get(Set<CRMDOPaymentGatewayParameter> parameters, PayeezyParameter braintreeParameter, CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception{
    	PaymentGatewayParameter paymentGatewayParameter = null;
    	CRMDOPaymentGatewayParameter parameter = null;
    	CRMDOPaymentGatewayParameterValue paymentGatewayParameterValue=null;
    	if(parameters!=null)
    	{
    		Iterator<CRMDOPaymentGatewayParameter> iter = parameters.iterator();
    		while(iter.hasNext())
    		{
    			CRMDOPaymentGatewayParameter existingParameter = iter.next();
    			if(existingParameter!=null && existingParameter.getName()!=null && existingParameter.getName().equals(braintreeParameter.toString()))
    			{
    				parameter = existingParameter;
    				ArrayList<CRMDO> paymentGatewayParameterValues= paymentGatewayParameterValueBean.load(parameter);
    				if(paymentGatewayParameterValues!=null && !paymentGatewayParameterValues.isEmpty())
    				{
    					paymentGatewayParameterValue = (CRMDOPaymentGatewayParameterValue) paymentGatewayParameterValues.get(0);
    				}
    				break;
    			}
    		}
    	}

    	if(parameter==null)
    	{
    		parameter =(CRMDOPaymentGatewayParameter) paymentGatewayParameterBean.construct(paymentGatewaySetting);
    		parameter.setType(PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean.GENERAL_PARAMETERS);
    		parameter.setName(braintreeParameter.toString());
    	}
    	
    	if(paymentGatewayParameterValue==null)
    	{
    		paymentGatewayParameterValue=(CRMDOPaymentGatewayParameterValue) paymentGatewayParameterValueBean.construct(parameter);
    	}
    	if(braintreeParameter.equals(PayeezyParameter.MODE) && paymentGatewayParameterValue.getStringValue()==null)
    	{
    		paymentGatewayParameterValue.setStringValue(PayeezyMode.TEST.toString());
    	}
    	parameter.setAlias("name", braintreeParameter.getLabel());
    	
    	paymentGatewayParameter=new PaymentGatewayParameter();
    	paymentGatewayParameter.setParameter(parameter);
    	paymentGatewayParameter.setValue(paymentGatewayParameterValue);
    	paymentGatewayParameter.setType(braintreeParameter.getType());
    	paymentGatewayParameter.setOrder(braintreeParameter.getOrder());
    	return paymentGatewayParameter;
    }
    
    
    
    /**
     * Creates a payment gateway setting.
     * 
     * @return a payment gateway setting.
     * @throws Exception
     */
    public CRMDOPaymentGatewaySetting createButton() throws Exception {
    	return createButton(PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean.PROTOCOL);
    }
    
    /**
     * Creates a payment gateway setting.
     * 
     * @param paymentGateway - the payment gateway to create the payment gateway setting
     * @return a payment gateway setting.
     * @throws Exception
     */
    public CRMDOPaymentGatewaySetting createButton(String paymentGateway) throws Exception {
    	
    	CRMDOPaymentGatewaySetting setting = null;
    	
    	if (paymentGateway!=null)
    	{    	
	    	if (paymentGateway.equals(PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean.PROTOCOL))
	    	{
	    		setting = (CRMDOPaymentGatewaySetting)payeezyPaymentGatewaySettingBean.construct(null);
	    	}
	    	
	    	setting = setPaymentGatewayParameters(setting);
    	}
    	
    	return setting;
    }
    
    
    /**
     * Saves a payment gateway setting.
     * 
     * @param paymentGatewaySetting - the payment gateway setting to save
     * @return the saved payment gateway setting
     * @throws Exception
     */
    public CRMDOPaymentGatewaySetting saveButton(CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception {
    	
    	String paymentGateway = paymentGatewaySetting.getPaymentGatewayProtocol();
    	
    	if (paymentGateway.equals(PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean.PROTOCOL))
    	{
    		paymentGatewaySetting 	= setPaymentGatewayParametersToSave(paymentGatewaySetting);
    		paymentGatewaySetting	= (CRMDOPaymentGatewaySetting)payeezyPaymentGatewaySettingBean.validateOnSave(paymentGatewaySetting);
    		paymentGatewaySetting	= (CRMDOPaymentGatewaySetting)payeezyPaymentGatewaySettingBean.save(paymentGatewaySetting);
    	}
    	return paymentGatewaySetting;
    }
    
    /**
     * Loads a payment gateway setting form.
     * 
     * @param paymentGatewaySetting - the payment gateway setting to load
     * @return the loaded form
     * @throws Exception
     */
	public CRMDOPaymentGatewaySetting editButton(CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception {
		return (paymentGatewaySetting!=null && !paymentGatewaySetting.isNew()) ? loadForm(paymentGatewaySetting.getId()) : loadForm();
	}
	
	
	/**
     * Deletes a payment gateway setting.
     * 
     * @param paymentGatewaySetting - the payment gateway setting to delete
     * @return the deleted payment gateway setting 
     * @throws Exception
     */
	public CRMDOPaymentGatewaySetting deleteButton(CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception {
		
		String paymentGateway = paymentGatewaySetting.getPaymentGatewayProtocol();
    	
    	if (paymentGateway.equals(PAYEEZYCRMBOPayeezyPaymentGatewaySettingBean.PROTOCOL))
    	{
    		return (CRMDOPaymentGatewaySetting)payeezyPaymentGatewaySettingBean.validateAndDelete(paymentGatewaySetting);
    	}
    	
		return paymentGatewaySetting;
	}
	
	/**
	 * Adds a payment cancellation type to payment gateway setting.
	 * 
	 * @return the loaded payment cancellation type
	 * @throws Exception
	 */
	@Override
	public PaymentCancellationType addPaymentCancellationTypeButton() throws Exception {
		return new PaymentCancellationType();
	}
	/**
	 * Removes a list of payment cancellation types from a payment gateway setting.
	 * 
	 * @param dtoList - a list of payment cancellation types to delete
	 * @return the updated list
	 * @throws Exception
	 */
	@Override
	public ArrayList<CRMDO> removePaymentCancellationTypeButton(ArrayList<CRMDO> dtoList) throws Exception {
		return setDeleted(dtoList);
	}
	
	/**
	 * Adds a payment method to payment gateway setting.
	 * 
	 * @return the loaded payment method
	 * @throws Exception
	 */
	@Override
	public PaymentMethod addPaymentMethodButton() throws Exception {
		return new PaymentMethod();
	}
	/**
	 * Removes a list of payment methods from a payment gateway setting.
	 * 
	 * @param dtoList - a list of payment methods to delete
	 * @return the updated list
	 * @throws Exception
	 */
	@Override
	public ArrayList<CRMDO> removePaymentMethodButton(ArrayList<CRMDO> dtoList) throws Exception {
		return setDeleted(dtoList);
	}
	
	/**
	 * Sets the payment gateway setting's life cycle state to Not Effective
	 * @param paymentGatewaySetting - he payment gateway setting to change its life cycle state
	 * @return the payment gateway setting
	 * @throws Exception
	 */
	public CRMDOPaymentGatewaySetting setNotEffective(CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception {
		paymentGatewaySetting.setLifeCycleState(PaymentGatewayLifeCycleState.NOT_EFFECTIVE);
		paymentGatewaySetting = (CRMDOPaymentGatewaySetting) payeezyPaymentGatewaySettingBean.validateOnSave(paymentGatewaySetting);
		paymentGatewaySetting = (CRMDOPaymentGatewaySetting) payeezyPaymentGatewaySettingBean.save(paymentGatewaySetting);
		
		return paymentGatewaySetting;
		
	}
   	
	/**
	 * Loads the payment gateway mode options.
	 *  
	 * @return the payment gateway mode options
	 * @throws Exception
	 */
	public LookupBuilder getModeOptions() throws Exception {
		return getModeOptions(null);
	}
	
	/**
	 * Loads the payment gateway mode options.
	 *  
	 * @param emptyValue - an empty value for mode 
	 * @return the payment gateway mode options
	 * @throws Exception
	 */
	public LookupBuilder getModeOptions(String emptyValue) throws Exception {
		
		LookupBuilder builder = new LookupBuilder();
		
		if (emptyValue!=null)
		{
			builder.build("", emptyValue);
		}
		PayeezyMode[] modes = PayeezyMode.values();
		
		for (int i=0; i<modes.length; i++)
		{
			PayeezyMode mode = modes[i];
			builder.build(mode.toString(), mode.getLabel());
		}
		
		return builder;
	}
	
	/**
	 * Adds a currency to payment gateway setting.
	 * 
	 * @return the newly created payment gateway currency
	 * @throws Exception
	 */
	public CRMDOPaymentGatewayCurrency addCurrencyButton(CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception {
		return (CRMDOPaymentGatewayCurrency) paymentGatewayCurrencyBean.construct(paymentGatewaySetting);
	}
	
	/**
	 * Loads the currencies of a payment gateway setting
	 * 
	 * @param paymentGatewaySetting - the payment gateway setting to load the currencies for
	 * @return a list of payment gateway currencies
	 * @throws Exception
	 */
	public ArrayList<CRMDO> loadCurrenciesTab(CRMDOPaymentGatewaySetting paymentGatewaySetting) throws Exception {
		ArrayList<CRMDO> dtos = paymentGatewayCurrencyBean.load(paymentGatewaySetting);
		return dtos;
	}
	
	/**
	 * Resets the supported currencies of the given payment gateway
	 * @param paymentGateway - the payment gateway to reset the currencies for
	 * @return the updated payment gateway
	 * @throws Exception 
	 */	
	@Override
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public CRMDOPaymentGatewaySetting resetCurrencies(CRMDOPaymentGatewaySetting paymentGateway) throws Exception
	{
		if(paymentGateway.getPaymentGatewayCurrencies()!=null)
		{		
			setDeleted(new ArrayList(paymentGateway.getPaymentGatewayCurrencies()));
		}
		
		return paymentGateway;
	}
	
	public CRMDOPaymentGatewaySetting setParametersVisibility(CRMDOPaymentGatewaySetting paymentGateway) throws Exception
	{
		if(paymentGateway.getGatewayParameters()!=null)
		{		
			PayeezyMode mode = getMode(paymentGateway.getGatewayParameters());
			Iterator<PaymentGatewayParameter> iter = paymentGateway.getGatewayParameters().iterator();
			while(iter.hasNext())
			{
				PaymentGatewayParameter parameter = iter.next();
				if(parameter!=null && 
						parameter.getParameter()!=null &&
						parameter.getParameter().getName()!=null)
				{
					if	(parameter.getParameter().getName().equals(PayeezyParameter.TEST_URL.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.TEST_API_KEY.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.TEST_API_SECRET.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.TEST_JS_SECURITY_KEY.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.TEST_MERCHANT_TOKEN.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.TEST_TA_TOKEN.toString()))
					{
						if(mode!=null && mode.equals(PayeezyMode.TEST))
						{
							parameter.setIsVisible(new Integer(1));
						}
						else if(mode!=null && mode.equals(PayeezyMode.LIVE))
						{
							parameter.setIsVisible(new Integer(0));
						}
					}
					if	(parameter.getParameter().getName().equals(PayeezyParameter.LIVE_URL.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.LIVE_API_KEY.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.LIVE_API_SECRET.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.LIVE_JS_SECURITY_KEY.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.LIVE_MERCHANT_TOKEN.toString()) ||
							parameter.getParameter().getName().equals(PayeezyParameter.LIVE_TA_TOKEN.toString()))
					{
						if(mode!=null && mode.equals(PayeezyMode.TEST))
						{
							parameter.setIsVisible(new Integer(0));
						}
						else if(mode!=null && mode.equals(PayeezyMode.LIVE))
						{
							parameter.setIsVisible(new Integer(1));
						}
					}
					else
					{
						parameter.setIsVisible(new Integer(1));
					}
				}
			}
		}
		return paymentGateway;
	}
	
	private PayeezyMode getMode(Set<PaymentGatewayParameter> paymentGatewayParameters){
		PayeezyMode mode = null;
		if(paymentGatewayParameters!=null)
		{
			Iterator<PaymentGatewayParameter> iter = paymentGatewayParameters.iterator();
			while(iter.hasNext())
			{
				PaymentGatewayParameter parameter = iter.next();
				if(parameter!=null &&
						parameter.getParameter()!=null &&
						parameter.getParameter().getName()!=null &&
						parameter.getParameter().getName().equals(PayeezyParameter.MODE.toString()) &&
						parameter.getValue()!=null &&
						parameter.getValue().getStringValue()!=null)
				{
					mode = PayeezyMode.valueOf(PayeezyMode.class,parameter.getValue().getStringValue());
					break;
				}
			}
		}
		
		
		return mode;
	}
}

5.

...

Payment Gateway Process Class

The payment gateway process class should extend com.crm.process.paymentgateway.CRMProcessPaymentGatewayBean and implement its abstract methods for creating/updating/deleting a payment gateway account and card, creating a payment and payment cancellation, and checking whether a currency is supported by the payment gateway. Implement only the methods required by your business model.

...