forked from AuthorizeNet/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.java
More file actions
62 lines (49 loc) · 1.52 KB
/
Result.java
File metadata and controls
62 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package net.authorize;
import java.io.Serializable;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public abstract class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
protected Transaction transaction;
protected T target;
/**
* Get the request transaction.
*
* @return Transaction
*/
public Transaction getTransaction() {
return this.transaction;
}
/**
* Get the target (request + response transaction).
*
* @return Transaction
*/
public T getTarget() {
return this.target;
}
/**
* Verify that the relay response post is actually coming from
* AuthorizeNet.
*
* @return boolean true if the txn came from Authorize.Net
*/
public static boolean isAuthorizeNetResponse(String md5Value, String apiLoginId, String amount, String transId, String transHash) {
String md5Check = null;
try {
MessageDigest digest = java.security.MessageDigest.getInstance( MessageDigestAlgorithm);
String salt = md5Value + apiLoginId + transId + amount;
digest.update( salt.getBytes());
md5Check = new BigInteger(1,digest.digest()).toString(16).toUpperCase();
while(md5Check.length() < 32) {
md5Check = "0" + md5Check;
}
} catch (NoSuchAlgorithmException nsae) {
//
}
boolean result = md5Check != null && md5Check.equalsIgnoreCase( transHash);
return result;
}
public static final String MessageDigestAlgorithm = "MD5";
}