AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
String siteId = site.getSiteId();
PaymentGateway paymentGateway = new PaymentGateway();
if (!insertMode) {
paymentGateway = PaymentGatewayDAO.load(siteId, Format.getLong(form.getPaymentGatewayId()));
}
ActionMessages errors = validate(form, insertMode);
if (errors.size() != 0) {
saveMessages(request, errors);
initForm(form, site);
return mapping.findForward("error");
}
if (insertMode) {
paymentGateway.setSite(site);
paymentGateway.setRecCreateBy(adminBean.getUser().getUserId());
paymentGateway.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
paymentGateway.setPaymentGatewayName(form.getPaymentGatewayName());
String provider = form.getPaymentGatewayProvider();
paymentGateway.setPaymentGatewayProvider(provider);
String paymentGatewayData = paymentGateway.getPaymentGatewayData();
if (provider.equals(AuthorizeNetEngine.class.getSimpleName())) {
AuthorizeNet authorizeNet = new AuthorizeNet();
if (!insertMode) {
authorizeNet = (AuthorizeNet) Utility.joxUnMarshall(AuthorizeNet.class, paymentGatewayData);
}
authorizeNet.setLoginId(form.getAuthorizeNetLoginId());
if (!Format.isNullOrEmpty(form.getAuthorizeNetTranKey())) {
authorizeNet.setTranKey(form.getAuthorizeNetTranKey());
}
authorizeNet.setEnvironment(form.getAuthorizeNetEnvironment());
paymentGatewayData = Utility.joxMarshall("AuthorizeNet", authorizeNet);
}
if (provider.equals(PsiGateEngine.class.getSimpleName())) {
PSIGate psiGate = new PSIGate();
if (!insertMode) {
psiGate = (PSIGate) Utility.joxUnMarshall(PSIGate.class, paymentGatewayData);
}
psiGate.setStoreId(form.getPsiGateStoreId());
if (!Format.isNullOrEmpty(form.getPsiGatePassPhrase())) {
psiGate.setPassPhrase(form.getPsiGatePassPhrase());
}
psiGate.setEnvironment(form.getPsiGateEnvironment());
paymentGatewayData = Utility.joxMarshall("PSIGate", psiGate);
}
if (provider.equals(PayPalEngine.class.getSimpleName())) {
PayPalExpressCheckOut payPalExpressCheckOut = new PayPalExpressCheckOut();
if (!insertMode) {
payPalExpressCheckOut = (PayPalExpressCheckOut) Utility.joxUnMarshall(PayPalExpressCheckOut.class, paymentGatewayData);
}
payPalExpressCheckOut.setPaymentPaypalCustClassId(Format.getLong(form.getPaymentPaypalCustClassId()));
payPalExpressCheckOut.setPaymentPaypalApiUsername(form.getPaymentPaypalApiUsername());
payPalExpressCheckOut.setPaymentPaypalEnvironment(form.getPaymentPaypalEnvironment());
if (!Format.isNullOrEmpty(form.getPaymentPaypalExtraAmount())) {
payPalExpressCheckOut.setPaymentPaypalExtraAmount(Format.getDouble(form.getPaymentPaypalExtraAmount()));
}
if (!Format.isNullOrEmpty(form.getPaymentPaypalExtraPercentage())) {
payPalExpressCheckOut.setPaymentPaypalExtraPercentage(Format.getDouble(form.getPaymentPaypalExtraPercentage()));
}
if (!Format.isNullOrEmpty(form.getPaymentPaypalApiPassword())) {
payPalExpressCheckOut.setPaymentPaypalApiPassword(AESEncoder.getInstance().encode(form.getPaymentPaypalApiPassword()));
}
if (!Format.isNullOrEmpty(form.getPaymentPaypalSignature())) {
payPalExpressCheckOut.setPaymentPaypalSignature(AESEncoder.getInstance().encode(form.getPaymentPaypalSignature()));
}
paymentGatewayData = Utility.joxMarshall("PayPalExpressCheckOut", payPalExpressCheckOut);
}
if (provider.equals(PayPalWebsitePaymentProEngine.class.getSimpleName())) {
PayPalWebsitePaymentPro payPalWebsitePaymentPro = new PayPalWebsitePaymentPro();
if (!insertMode) {
payPalWebsitePaymentPro = (PayPalWebsitePaymentPro) Utility.joxUnMarshall(PayPalWebsitePaymentPro.class, paymentGatewayData);
}
payPalWebsitePaymentPro.setPaypalApiUsername(form.getPaypalWebsitePaymentProApiUsername());
payPalWebsitePaymentPro.setPaypalEnvironment(form.getPaypalWebsitePaymentProEnvironment());
if (!Format.isNullOrEmpty(form.getPaypalWebsitePaymentProApiPassword())) {
payPalWebsitePaymentPro.setPaypalApiPassword(AESEncoder.getInstance().encode(form.getPaypalWebsitePaymentProApiPassword()));
}
if (!Format.isNullOrEmpty(form.getPaypalWebsitePaymentProSignature())) {
payPalWebsitePaymentPro.setPaypalSignature(AESEncoder.getInstance().encode(form.getPaypalWebsitePaymentProSignature()));
}
paymentGatewayData = Utility.joxMarshall("PayPalWebsitePaymentProEngine", payPalWebsitePaymentPro);
}
if (provider.equals(PaymentExpressEngine.class.getSimpleName())) {
PaymentExpress paymentExpress = new PaymentExpress();
if (!insertMode) {
paymentExpress = (PaymentExpress) Utility.joxUnMarshall(PaymentExpress.class, paymentGatewayData);
}
paymentExpress.setPostUsername(form.getPaymentExpressPostUsername());
if (!Format.isNullOrEmpty(form.getPaymentExpressPostPassword())) {
paymentExpress.setPostPassword(form.getPaymentExpressPostPassword());
}
paymentExpress.setEnvironment(form.getPaymentExpressEnvironment());
paymentGatewayData = Utility.joxMarshall("PaymentExpress", paymentExpress);
}
if (provider.equals(PayPalPayFlowEngine.class.getSimpleName())) {
PayPalPayFlow paypalPayFlow = new PayPalPayFlow();
if (!insertMode) {
paypalPayFlow = (PayPalPayFlow) Utility.joxUnMarshall(PayPalPayFlow.class, paymentGatewayData);
}
paypalPayFlow.setUser(form.getPaypalPayFlowUser());
paypalPayFlow.setVendor(form.getPaypalPayFlowVendor());
paypalPayFlow.setPartner(form.getPaypalPayFlowPartner());
if (!Format.isNullOrEmpty(form.getPaypalPayFlowPassword())) {
paypalPayFlow.setPassword(AESEncoder.getInstance().encode(form.getPaypalPayFlowPassword()));
}
paypalPayFlow.setEnvironment(form.getPaypalPayFlowEnvironment());
paymentGatewayData = Utility.joxMarshall("PayPalPayFlow", paypalPayFlow);
}
if (provider.equals(EWayCVNAustraliaEngine.class.getSimpleName())) {
EWayCVNAustralia eWayCVNAustralia = new EWayCVNAustralia();
if (!insertMode) {
eWayCVNAustralia = (EWayCVNAustralia) Utility.joxUnMarshall(EWayCVNAustralia.class, paymentGatewayData);
}
eWayCVNAustralia.setCustomerId(form.getEWayCVNAustraliaCustomerId());
eWayCVNAustralia.setEnvironment(form.getEWayCVNAustraliaEnvironment());
paymentGatewayData = Utility.joxMarshall("EWayCVSAustralia", eWayCVNAustralia);
}
paymentGateway.setPaymentGatewayData(paymentGatewayData);
paymentGateway.setRecUpdateBy(adminBean.getUser().getUserId());
paymentGateway.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (insertMode) {
em.persist(paymentGateway);
}
form.setMode("U");
initForm(form, site);
form.setPaymentGatewayId(paymentGateway.getPaymentGatewayId().toString());
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
return mapping.findForward("success");
}