Skip to content

Commit

Permalink
updated documentation, bugfix with custom logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwm committed Oct 29, 2018
1 parent 9e6a5fb commit 32f58db
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 53 deletions.
104 changes: 53 additions & 51 deletions src/Cardknox.NET/Cardknox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,34 @@ namespace CardknoxApi
/// </summary>
public class Cardknox
{
#region events
/// <summary>
///
/// Event Handler for when a request has started. The results will contain the non-sensitive field values being sent to the API endpoint
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void RequestStartedEventHandler(object sender, CardknoxEventArgs e);
/// <summary>
///
/// Fired when a request has been started, returns non-sensitive field values sent to API endpoint
/// </summary>
public event RequestStartedEventHandler RequestStarted;
/// <summary>
///
/// Event Handler for when a request has completed. The results will contain the field values being received from the API endpoint
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void RequestCompletedEventHandler(object sender, CardknoxEventArgs e);
/// <summary>
///
/// Fired when a request has completed, returns field values returned from API endpoint
/// </summary>
public event RequestCompletedEventHandler RequestCompleted;
#endregion

private CardknoxRequest _request { get; }
private NameValueCollection _values { get; }

/// <summary>
///
/// Initiate new Cardknox request
/// </summary>
/// <param name="request">The <see cref="CardknoxRequest"/> object that is used to make the request.</param>
public Cardknox(CardknoxRequest request)
Expand Down Expand Up @@ -128,12 +130,12 @@ public CardknoxResponse CCSale(CCSale _sale, bool force = false)

AddSpecialFields(_sale);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -206,12 +208,12 @@ public CardknoxResponse CCSave(CCSave _save, bool force = false)
if (!IsNullOrWhiteSpace(_save.IP))
_values.Add("xIP", _save.IP);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -253,12 +255,12 @@ public CardknoxResponse CCRefund(CCRefund _refund, bool force = false)
if (_refund.CustReceipt)
_values.Add("xCustReceipt", _refund.CustReceipt.ToString());

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -338,12 +340,12 @@ public CardknoxResponse CCAuthOnly(CCAuthOnly _auth, bool force = false)

AddSpecialFields(_auth);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -400,12 +402,12 @@ public CardknoxResponse CCCapture(CCCapture _capture, bool force = false)

AddSpecialFields(_capture);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -485,12 +487,12 @@ public CardknoxResponse CCCredit(CCCredit _credit, bool force = false)

AddSpecialFields(_credit);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -525,12 +527,12 @@ public CardknoxResponse CCVoid(CCVoid _void, bool force = false)
_values.Add("xRefNum", _void.RefNum);
// END required information

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -580,12 +582,12 @@ public CardknoxResponse CCAdjust(CCAdjust _adjust, bool force = false)
if (!IsNullOrWhiteSpace(_adjust.IP))
_values.Add("xIP", _adjust.IP);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -638,12 +640,12 @@ public CardknoxResponse CCPostAuth(CCPostAuth _auth, bool force = false)

AddSpecialFields(_auth);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -678,12 +680,12 @@ public CardknoxResponse CCVoidRefund(CCVoidRefund _refund, bool force = false)
_values.Add("xRefNum", _refund.RefNum);
// END required information

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -718,12 +720,12 @@ public CardknoxResponse CCVoidRelease(CCVoidRelease _release, bool force = false
_values.Add("xRefNum", _release.RefNum);
// END required information

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -793,12 +795,12 @@ public CardknoxResponse CheckSale(CheckSale _sale, bool force = false)

AddSpecialFields(_sale);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -865,12 +867,12 @@ public CardknoxResponse CheckCredit(CheckCredit _credit, bool force = false)

AddSpecialFields(_credit);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -922,12 +924,12 @@ public CardknoxResponse CheckSave(CheckSave _save, bool force = false)
if (!IsNullOrWhiteSpace(_save.IP))
_values.Add("xIP", _save.IP);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -965,12 +967,12 @@ public CardknoxResponse CheckVoid(CheckVoid _void, bool force = false)
_values.Add("xRefNum", _void.RefNum);
// END required information

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1011,12 +1013,12 @@ public CardknoxResponse CheckRefund(CheckRefund _refund, bool force = false)
if (_refund.CustReceipt)
_values.Add("xCustReceipt", _refund.CustReceipt.ToString());

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1087,12 +1089,12 @@ public CardknoxResponse EBTFSSale(EBTFSSale _sale, bool force = false)

AddSpecialFields(_sale);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1160,12 +1162,12 @@ public CardknoxResponse EBTFSCredit(EBTFSCredit _credit, bool force = false)

AddSpecialFields(_credit);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1220,12 +1222,12 @@ public CardknoxResponse EBTFSBalance(EBTFSBalance _bal, bool force = false)
if (!IsNullOrWhiteSpace(_bal.IP))
_values.Add("xIP", _bal.IP);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1293,12 +1295,12 @@ public CardknoxResponse EBTFSVoucher(EBTFSVoucher _voucher, bool force = false)

AddSpecialFields(_voucher);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1369,12 +1371,12 @@ public CardknoxResponse EBTCBSale(EBTCBSale _sale, bool force = false)

AddSpecialFields(_sale);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1438,12 +1440,12 @@ public CardknoxResponse EBTCBCash(EBTCBCash _cash, bool force = false)
if (_cash.AllowDuplicate)
_values.Add("xAllowDuplicate", _cash.AllowDuplicate.ToString());

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down Expand Up @@ -1493,12 +1495,12 @@ public CardknoxResponse EBTCBBalance(EBTCBBalance _bal, bool force = false)
if (!IsNullOrWhiteSpace(_bal.IP))
_values.Add("xIP", _bal.IP);

if (RequestStarted != null)
if (RequestStarted == null)
Log.LogRequest(_values);
else RequestStarted.Invoke(this, new CardknoxEventArgs(_values));

var resp = MakeRequest();
if (RequestCompleted != null)
if (RequestCompleted == null)
Log.LogResponse(resp);
else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp));

Expand Down
Loading

0 comments on commit 32f58db

Please sign in to comment.