-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSIMResponse.cs
127 lines (111 loc) · 2.26 KB
/
SIMResponse.cs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Specialized;
using System.Text;
using System.Web;
namespace AuthorizeNet
{
public class SIMResponse : IGatewayResponse
{
private NameValueCollection _post;
private string _merchantHash;
public decimal Amount
{
get
{
string sAmount = this.FindKey("x_amount");
decimal result = new decimal(0, 0, 0, false, 2);
decimal.TryParse(sAmount, out result);
return result;
}
}
public bool Approved
{
get
{
return this.ResponseCode == "1";
}
}
public string AuthorizationCode
{
get
{
return this.FindKey("x_auth_code");
}
}
public string CardNumber
{
get
{
return this.FindKey("x_card_num");
}
}
public string InvoiceNumber
{
get
{
return this.FindKey("x_invoice_num");
}
}
public string MD5Hash
{
get
{
return this.FindKey("x_MD5_Hash");
}
}
public string Message
{
get
{
return this.FindKey("x_response_reason_text");
}
}
public string ResponseCode
{
get
{
return this.FindKey("x_response_code");
}
}
public string TransactionID
{
get
{
return this.FindKey("x_trans_id");
}
}
public SIMResponse(NameValueCollection post)
{
this._post = post;
}
public SIMResponse() : this(HttpContext.Current.Request.Form)
{
}
private string FindKey(string key)
{
string result = null;
if (this._post[key] != null)
{
result = this._post[key];
}
return result;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<li>Code = {0}", this.ResponseCode);
sb.AppendFormat("<li>Auth = {0}", this.AuthorizationCode);
sb.AppendFormat("<li>Message = {0}", this.Message);
sb.AppendFormat("<li>TransID = {0}", this.TransactionID);
sb.AppendFormat("<li>Approved = {0}", this.Approved);
return sb.ToString();
}
/// <summary>
/// Validates that what was passed by Auth.net is valid
/// </summary>
public bool Validate(string merchantHash, string apiLogin)
{
return Crypto.IsMatch(merchantHash, apiLogin, this.TransactionID, this.Amount, this.MD5Hash);
}
}
}