Commit 28cfa136 by Tuomas Riihimäki

Fix verkkomaksut ( paytrail ) api stuff and remove verkkomaksurunner references

1 parent 2ce2e946
......@@ -65,7 +65,7 @@ import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
*/
@Stateless
@LocalBean
@DeclareRoles({ BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER, SpecialPermission.S_VERKKOMAKSU_CHECK, })
@DeclareRoles({ BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER, })
public class BillBean implements BillBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(BillBean.class);
......
......@@ -44,8 +44,11 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -93,7 +96,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
@EJB
private BillFacade billfacade;
@EJB
private VerkkomaksuRunner vmrunner;
private BillPBean billpbean;
private static final Logger logger = LoggerFactory.getLogger(CheckoutFiBean.class);
private static final BigDecimal TO_CENTS = BigDecimal.valueOf(100);
......@@ -195,6 +198,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
}
mdString.append(merchantPassword);
CloseableHttpResponse response = null;
try {
final String calculatedHash = PasswordFunctions.calculateMd5(mdString.toString());
......@@ -205,9 +209,12 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
final HttpPost postRequest = new HttpPost(REMOTE_URL);
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClientBuilder cliBuilder = HttpClientBuilder.create();
CloseableHttpClient cli = cliBuilder.build();
response = cli.execute(postRequest);
final DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(postRequest);
// final DefaultHttpClient client = new DefaultHttpClient();
// HttpResponse response = client.execute(postRequest);
// final StringWriter writer = new StringWriter();
//
......@@ -221,6 +228,14 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
} catch (IOException e) {
logger.warn("Error sending checkout.fi request", e);
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
logger.warn("Error closing checkout.fi request", e);
}
}
return null;
......@@ -352,7 +367,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
&& bill.getPaidDate() == null)
{
logger.info("Trying to mark bill {} paid", bill);
vmrunner.markPaid(bill, Calendar.getInstance());
billpbean.markPaid(bill, Calendar.getInstance(), false);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Marking bill paid from checkout. Received bill status ", statusInt, " for bill ", bill, " stamp ", stamp, " payment: ", payment, " reference ", reference);
ret = true;
} else {
......
......@@ -190,10 +190,7 @@ public class JaasBean implements MoyaRealmBeanRemote {
roleset.add(UserPermission.ANYUSER.getFullName());
if (usr == null) {
if (SpecialPermission.VERKKOMAKSU_CHECKER.name().equals(user)) {
roleset.add(SpecialPermission.VERKKOMAKSU_CHECKER.name());
}
usr = permbean.getAnonEventUser();
roleset.add(SpecialPermission.ANONYMOUS.name());
}
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import java.util.Calendar;
import javax.annotation.security.RunAs;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.beans.BillBeanLocal;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.exceptions.BillException;
import fi.codecrew.moya.model.Bill;
@Stateless
@LocalBean
@RunAs(SpecialPermission.S_VERKKOMAKSU_CHECK)
public class VerkkomaksuRunner {
@EJB
private BillBeanLocal billbean;
public void markPaid(Bill bill, Calendar when) {
try {
billbean.markPaid(bill, when, false);
} catch (BillException x) {
throw new RuntimeException(x);
}
}
}
......@@ -18,8 +18,10 @@
*/
package fi.codecrew.moya.beans;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.Arrays;
......@@ -42,9 +44,14 @@ import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
......@@ -81,11 +88,11 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
private PermissionBeanLocal permbean;
@EJB
private VerkkomaksuRunner vmrunner;
@EJB
private LoggingBeanLocal logbean;
@EJB
private BillFacade billFacade;
@EJB
private BillPBean billpbean;
@Override
public boolean isSvmEnabled()
......@@ -127,7 +134,8 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
} else if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null
&& (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) {
vmrunner.markPaid(bill, Calendar.getInstance());
billpbean.markPaid(bill, Calendar.getInstance(), false);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
ret = true;
} else {
......@@ -195,8 +203,9 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
}
private static final String AUTH_SCOPE = "payment.paytrail.com";
private static final String REMOTE_URL =
"https://payment.verkkomaksut.fi/api-payment/create";
"https://payment.paytrail.com/api-payment/create";
// private static final String url = "http://iudex.fi/api-payment/create";
......@@ -204,31 +213,42 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
{
VerkkomaksutReturnEntry ret = null;
CloseableHttpClient client = null;
try {
// DefaultHttpClient httpClient = new DefaultHttpClient();
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
// new AuthScope("payment.verkkomaksut.fi", 443),
AuthScope.ANY,
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AUTH_SCOPE, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
new UsernamePasswordCredentials(merchantId, merchantPassword));
client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, Arrays.asList(AuthPolicy.BASIC));
clientBuilder.setDefaultCredentialsProvider(credsProvider);
client = clientBuilder.build();
HttpPost postRequest = new HttpPost(REMOTE_URL);
postRequest.setHeader("Content-Type", "application/xml");
postRequest.setHeader("X-Verkkomaksut-Api-Version", "1");
// postRequest.setEntity(new
// StringEntity(outputPayment(paymentMsg)));
postRequest.setEntity(new StringEntity(outputPayment(paymentMsg)));
HttpResponse response = client.execute(postRequest);
logger.info("Got statuscode from suomenverkkomaksut.fi: {} ", response.getStatusLine().getStatusCode());
ret = parseMessageReturn(response.getEntity().getContent());
client.getConnectionManager().shutdown();
} catch (Throwable t)
{
} catch (Throwable t) {
logger.warn("Got exception while creating payment to suomenverkkomaksut", t);
} finally {
try {
if (client != null)
client.close();
} catch (IOException e) {
logger.warn("Error closing client for verkkomaksutfi", e);
}
}
return ret;
......@@ -253,12 +273,19 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
}
private static VerkkomaksutReturnEntry parseMessageReturn(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document parsed = dBuilder.parse(inputStream);
parsed.normalize();
NodeList rootElements = parsed.getChildNodes();
VerkkomaksutReturnEntry ret = null;
for (int i = 0; i < rootElements.getLength(); ++i) {
Node node = rootElements.item(i);
logger.info("Got root: {} {}, name {}", i, node, node.getNodeName());
}
if (rootElements.getLength() != 1) {
logError("Unknown number of entries for root {}", parsed, rootElements.getLength());
} else {
......
......@@ -23,7 +23,6 @@ public enum SpecialPermission {
USER,
ANONYMOUS,
// ORGANISATION_ADMIN,
VERKKOMAKSU_CHECKER,
REST
;
......@@ -31,6 +30,5 @@ public enum SpecialPermission {
public static final String S_SUPERADMIN = "SUPERADMIN";
public static final String S_ANONYMOUS = "ANONYMOUS";
//public static final String S_ORGANISATION_ADMIN = "ORGANISATION_ADMIN";
public static final String S_VERKKOMAKSU_CHECK = "VERKKOMAKSU_CHECKER";
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!