|
5 | 5 | import ca.bc.gov.open.bambora.payment.starter.BamboraProperties;
|
6 | 6 | import ca.bc.gov.open.bambora.payment.starter.managment.models.RecurringPaymentDetails;
|
7 | 7 | import com.sun.jndi.toolkit.url.Uri;
|
8 |
| -import org.springframework.util.DigestUtils; |
| 8 | +import org.apache.commons.codec.digest.DigestUtils; |
9 | 9 |
|
10 | 10 | import java.net.MalformedURLException;
|
11 | 11 | import java.text.MessageFormat;
|
@@ -54,31 +54,26 @@ private Uri buildRecurringPaymentUrl(RecurringPaymentDetails recurringPaymentDet
|
54 | 54 | if (operationType.equals(BamboraConstants.OperationTypes.M.toString()))
|
55 | 55 | paramString.append(formatBamboraParam("&", BamboraConstants.PARAM_PPRDIR_CUSTOMER_CODE, recurringPaymentDetails.getEndUserId()));
|
56 | 56 |
|
57 |
| - //add hash key at end of params |
58 |
| - paramString.append(bamboraProperties.getHashKey()); |
| 57 | + paramString.append(MessageFormat.format("&{0}={1}&{2}={3}", BamboraConstants.PARAM_TRANS_HASH_VALUE, getHash(paramString.toString()), BamboraConstants.PARAM_TRANS_HASH_EXPIRY, getExpiry())); |
59 | 58 |
|
60 |
| - String hashed = getHash(paramString.toString()); |
| 59 | + return new Uri(MessageFormat.format("{0}?{1}", bamboraProperties.getHostedProfileUrl(), paramString.toString())); |
61 | 60 |
|
62 |
| - // Calculate the expiry based on the minutesToExpire value. |
| 61 | + } |
| 62 | + |
| 63 | + private String getExpiry() { |
63 | 64 | SimpleDateFormat sdfDate = new SimpleDateFormat(BamboraConstants.PARAM_TRANS_HASH_EXPIRY_FORMAT);
|
64 | 65 | Calendar cal = Calendar.getInstance();
|
65 | 66 | cal.setTime(new Date());
|
66 | 67 | cal.add(Calendar.MINUTE, bamboraProperties.getMinutesToExpiry());
|
67 |
| - String expiry = sdfDate.format(cal.getTime()); |
68 |
| - |
69 |
| - // Add hash and expiry to the redirect |
70 |
| - String hashedParameter = paramString.toString().replace(bamboraProperties.getHashKey(), MessageFormat.format("&{0}={1}&{2}={3}", BamboraConstants.PARAM_TRANS_HASH_VALUE, hashed, BamboraConstants.PARAM_TRANS_HASH_EXPIRY, expiry)); |
71 |
| - |
72 |
| - return new Uri(MessageFormat.format("{0}?{1}", bamboraProperties.getHostedProfileUrl(), hashedParameter)); |
73 |
| - |
| 68 | + return sdfDate.format(cal.getTime()); |
74 | 69 | }
|
75 | 70 |
|
76 | 71 | private String formatBamboraParam(String prefix, String key, String value) {
|
77 | 72 | return MessageFormat.format("{0}{1}={2}", prefix, key, value).replace(" ", "%20");
|
78 | 73 | }
|
79 | 74 |
|
80 | 75 | private String getHash(String message) {
|
81 |
| - String digest = DigestUtils.md5DigestAsHex(message.getBytes()); |
| 76 | + String digest = DigestUtils.md5Hex(MessageFormat.format("{0}{1}", message, bamboraProperties.getHashKey())); |
82 | 77 | return digest.toUpperCase();
|
83 | 78 | }
|
84 | 79 | }
|
0 commit comments