From 32f58dba1590c6ea4a4ee46a60bfa8ad3b63e344 Mon Sep 17 00:00:00 2001 From: Adam Humpherys Date: Mon, 29 Oct 2018 12:46:13 -0600 Subject: [PATCH] updated documentation, bugfix with custom logging --- src/Cardknox.NET/Cardknox.cs | 104 ++++++++++++++++--------------- src/Cardknox.NET/Cardknox.csproj | 4 +- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/src/Cardknox.NET/Cardknox.cs b/src/Cardknox.NET/Cardknox.cs index 1758c61..c53f401 100644 --- a/src/Cardknox.NET/Cardknox.cs +++ b/src/Cardknox.NET/Cardknox.cs @@ -13,32 +13,34 @@ namespace CardknoxApi /// public class Cardknox { + #region events /// - /// + /// Event Handler for when a request has started. The results will contain the non-sensitive field values being sent to the API endpoint /// /// /// public delegate void RequestStartedEventHandler(object sender, CardknoxEventArgs e); /// - /// + /// Fired when a request has been started, returns non-sensitive field values sent to API endpoint /// public event RequestStartedEventHandler RequestStarted; /// - /// + /// Event Handler for when a request has completed. The results will contain the field values being received from the API endpoint /// /// /// public delegate void RequestCompletedEventHandler(object sender, CardknoxEventArgs e); /// - /// + /// Fired when a request has completed, returns field values returned from API endpoint /// public event RequestCompletedEventHandler RequestCompleted; + #endregion private CardknoxRequest _request { get; } private NameValueCollection _values { get; } /// - /// + /// Initiate new Cardknox request /// /// The object that is used to make the request. public Cardknox(CardknoxRequest request) @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); @@ -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)); diff --git a/src/Cardknox.NET/Cardknox.csproj b/src/Cardknox.NET/Cardknox.csproj index cdb9b56..274d728 100644 --- a/src/Cardknox.NET/Cardknox.csproj +++ b/src/Cardknox.NET/Cardknox.csproj @@ -8,13 +8,13 @@ Cardknox.API.Wrapper false CardknoxApi - 3.1 + 3.1.1 https://cardknox.adamh.us/ https://github.com/ahwm/Cardknox-API-Wrapper/blob/master/LICENSE API Wrapper for Cardknox Payment Processor written in C# Refer to https://kb.cardknox.com/api for full API reference. - Logging is live + Maintenance release to fix an issue with logging cardknox gateway processor payment api © 2018 Adam Humpherys 3.0.0.0