diff --git a/src/Cardknox.NET/Cardknox.csproj b/src/Cardknox.NET/Cardknox.csproj index d873e3d..89a34cd 100644 --- a/src/Cardknox.NET/Cardknox.csproj +++ b/src/Cardknox.NET/Cardknox.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1;netcoreapp3.1;netstandard2.0;net45;net50 + netcoreapp2.1;netcoreapp3.1;netstandard2.0;net45;net5.0 TheScripters The Scripters Cardknox.API.Wrapper @@ -9,7 +9,7 @@ 4.3.1 true CardknoxApi - 5.0-beta.3 + 5.0-beta.4 https://github.com/TheScripters/Cardknox-API-Wrapper API Wrapper for Cardknox Payment Processor written in C# with support for payments, recurring transactions, and reporting. Refer to https://kb.cardknox.com for full API reference or https://github.com/TheScripters/Cardknox-API-Wrapper/wiki/ for library reference Customer-based operations are now completed against the Recurring v1 API diff --git a/src/Cardknox.NET/RecurringClient.cs b/src/Cardknox.NET/RecurringClient.cs index 92a943f..38e112c 100644 --- a/src/Cardknox.NET/RecurringClient.cs +++ b/src/Cardknox.NET/RecurringClient.cs @@ -378,6 +378,245 @@ public RecurringResponse CustomerTransaction(CustomerTransaction _cust, bool for } #endregion + #region PaymentMethod + + /// + /// Use this command to add a new payment method to a customer's account profile. + /// + /// + /// + /// + public RecurringResponse PaymentMethodAdd(PaymentMethodAdd _pmt, bool force = false) + { + if (Values.AllKeys.Length > 4 && !force) + throw new InvalidOperationException("A new instance of Recurring is required to perform this operation unless 'force' is set to 'true'."); + else if (force) + { + string[] toRemove = Values.AllKeys; + foreach (var v in toRemove) + Values.Remove(v); + Values.Add("xKey", Request.Key); + Values.Add("xVersion", Request.CardknoxVersion); + Values.Add("xSoftwareName", Request.Software); + Values.Add("xSoftwareVersion", Request.SoftwareVersion); + } + + // BEGIN required information + Values.Add("xCommand", _pmt.Operation); + Values.Add("xCustomerID", _pmt.CustomerID); + Values.Add("xToken", _pmt.Token); + Values.Add("xTokenType", _pmt.TokenType); + // END required information + + if (!String.IsNullOrWhiteSpace(_pmt.TokenAlias)) + Values.Add("xTokenAlias", _pmt.TokenAlias); + + // CONDITIONALLY REQUIRED + if (!String.IsNullOrWhiteSpace(_pmt.Exp)) + Values.Add("xExp", _pmt.Exp); + if (!String.IsNullOrWhiteSpace(_pmt.Routing)) + Values.Add("xRouting", _pmt.Routing); + if (!String.IsNullOrWhiteSpace(_pmt.Name)) + Values.Add("xName", _pmt.Name); + + if (!String.IsNullOrWhiteSpace(_pmt.Street)) + Values.Add("xStreet", _pmt.Street); + if (!String.IsNullOrWhiteSpace(_pmt.Zip)) + Values.Add("xZip", _pmt.Zip); + if (_pmt.SetToDefault) + Values.Add("xSetToDefault", _pmt.SetToDefault.ToString()); + + if (RequestStarted == null) + Log.LogRequest(Values); + else RequestStarted.Invoke(this, new CardknoxEventArgs(Values)); + + var resp = MakeRequest(); + if (RequestCompleted == null) + Log.LogResponse(resp); + else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp)); + + return new RecurringResponse(resp); + } + + /// + /// Use this command to update an existing payment method. + /// Note: All fields with values must be passed in (even the fields that are not being updated). Any fields not passed in are treated as being set to blank. + /// + /// + /// + /// + public RecurringResponse PaymentMethodUpdate(PaymentMethodUpdate _pmt, bool force = false) + { + if (Values.AllKeys.Length > 4 && !force) + throw new InvalidOperationException("A new instance of Recurring is required to perform this operation unless 'force' is set to 'true'."); + else if (force) + { + string[] toRemove = Values.AllKeys; + foreach (var v in toRemove) + Values.Remove(v); + Values.Add("xKey", Request.Key); + Values.Add("xVersion", Request.CardknoxVersion); + Values.Add("xSoftwareName", Request.Software); + Values.Add("xSoftwareVersion", Request.SoftwareVersion); + } + + // BEGIN required information + Values.Add("xCommand", _pmt.Operation); + Values.Add("xCustomerID", _pmt.CustomerID); + Values.Add("xToken", _pmt.Token); + Values.Add("xTokenType", _pmt.TokenType); + // END required information + + if (!String.IsNullOrWhiteSpace(_pmt.TokenAlias)) + Values.Add("xTokenAlias", _pmt.TokenAlias); + + // CONDITIONALLY REQUIRED + if (!String.IsNullOrWhiteSpace(_pmt.Exp)) + Values.Add("xExp", _pmt.Exp); + if (!String.IsNullOrWhiteSpace(_pmt.Routing)) + Values.Add("xRouting", _pmt.Routing); + if (!String.IsNullOrWhiteSpace(_pmt.Name)) + Values.Add("xName", _pmt.Name); + + if (!String.IsNullOrWhiteSpace(_pmt.Street)) + Values.Add("xStreet", _pmt.Street); + if (!String.IsNullOrWhiteSpace(_pmt.Zip)) + Values.Add("xZip", _pmt.Zip); + if (_pmt.SetToDefault) + Values.Add("xSetToDefault", _pmt.SetToDefault.ToString()); + + if (RequestStarted == null) + Log.LogRequest(Values); + else RequestStarted.Invoke(this, new CardknoxEventArgs(Values)); + + var resp = MakeRequest(); + if (RequestCompleted == null) + Log.LogResponse(resp); + else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp)); + + return new RecurringResponse(resp); + } + + /// + /// Use this command to remove a payment method. + /// Note: The payment method is not completely deleted from the database; instead, the removed property is set to true. Customers with active schedules cannot be removed. + /// + /// + /// + /// + public RecurringResponse PaymentMethodRemove(PaymentMethodRemove _pmt, bool force = false) + { + if (Values.AllKeys.Length > 4 && !force) + throw new InvalidOperationException("A new instance of Recurring is required to perform this operation unless 'force' is set to 'true'."); + else if (force) + { + string[] toRemove = Values.AllKeys; + foreach (var v in toRemove) + Values.Remove(v); + Values.Add("xKey", Request.Key); + Values.Add("xVersion", Request.CardknoxVersion); + Values.Add("xSoftwareName", Request.Software); + Values.Add("xSoftwareVersion", Request.SoftwareVersion); + } + + // BEGIN required information + Values.Add("xCommand", _pmt.Operation); + Values.Add("xPaymentMethodID", _pmt.PaymentMethodID); + + if (RequestStarted == null) + Log.LogRequest(Values); + else RequestStarted.Invoke(this, new CardknoxEventArgs(Values)); + + var resp = MakeRequest(); + if (RequestCompleted == null) + Log.LogResponse(resp); + else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp)); + + return new RecurringResponse(resp); + } + + /// + /// Use this command to retrieve details of a payment method. + /// + /// + /// + /// + public RecurringResponse PaymentMethodGet(PaymentMethodGet _pmt, bool force = false) + { + if (Values.AllKeys.Length > 4 && !force) + throw new InvalidOperationException("A new instance of Recurring is required to perform this operation unless 'force' is set to 'true'."); + else if (force) + { + string[] toRemove = Values.AllKeys; + foreach (var v in toRemove) + Values.Remove(v); + Values.Add("xKey", Request.Key); + Values.Add("xVersion", Request.CardknoxVersion); + Values.Add("xSoftwareName", Request.Software); + Values.Add("xSoftwareVersion", Request.SoftwareVersion); + } + + // BEGIN required information + Values.Add("xCommand", _pmt.Operation); + Values.Add("xPaymentMethodID", _pmt.PaymentMethodID); + Values.Add("xRemoved", _pmt.Removed.ToString()); + + if (RequestStarted == null) + Log.LogRequest(Values); + else RequestStarted.Invoke(this, new CardknoxEventArgs(Values)); + + var resp = MakeRequest(); + if (RequestCompleted == null) + Log.LogResponse(resp); + else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp)); + + return new RecurringResponse(resp); + } + + /// + /// Use this command to find payment methods using specific search parameters. + /// + /// + /// + /// + public RecurringResponse PaymentMethodFind(PaymentMethodFind _pmt, bool force = false) + { + if (Values.AllKeys.Length > 4 && !force) + throw new InvalidOperationException("A new instance of Recurring is required to perform this operation unless 'force' is set to 'true'."); + else if (force) + { + string[] toRemove = Values.AllKeys; + foreach (var v in toRemove) + Values.Remove(v); + Values.Add("xKey", Request.Key); + Values.Add("xVersion", Request.CardknoxVersion); + Values.Add("xSoftwareName", Request.Software); + Values.Add("xSoftwareVersion", Request.SoftwareVersion); + } + + // BEGIN required information + Values.Add("xCommand", _pmt.Operation); + + if (!String.IsNullOrWhiteSpace(_pmt.CustomerID)) + Values.Add("xCustomerID", _pmt.CustomerID); + if (!String.IsNullOrWhiteSpace(_pmt.Name)) + Values.Add("xName", _pmt.Name); + Values.Add("xRemoved", _pmt.Removed.ToString()); + + if (RequestStarted == null) + Log.LogRequest(Values); + else RequestStarted.Invoke(this, new CardknoxEventArgs(Values)); + + var resp = MakeRequest(); + if (RequestCompleted == null) + Log.LogResponse(resp); + else RequestCompleted.Invoke(this, new CardknoxEventArgs(resp)); + + return new RecurringResponse(resp); + } + + #endregion + #region private methods private NameValueCollection MakeRequest() { diff --git a/src/Cardknox.NET/RecurringOperations/PaymentMethod.cs b/src/Cardknox.NET/RecurringOperations/PaymentMethod.cs new file mode 100644 index 0000000..6699e7b --- /dev/null +++ b/src/Cardknox.NET/RecurringOperations/PaymentMethod.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CardknoxApi.RecurringOperations +{ + /// + /// Use this command to add a new payment method to a customer's account profile. + /// + public class PaymentMethodAdd + { + internal string Operation => "paymentmethod:add"; + + /// + /// Customer's unique ID number + /// + public string CustomerID { get; set; } + /// + /// Cardknox token that references a previously used payment method to use for the charge + /// + public string Token { get; set; } + /// + /// The xToken payment type + /// Valid Values: + /// + /// CC (Credit Card) + /// Check (Check) + /// Ach + /// + /// + public string TokenType { get; set; } + /// + /// Custom name for the xToken + /// + public string TokenAlias { get; set; } + /// + /// Credit card expiration date + /// + public string Exp { get; set; } + /// + /// ACH payment routing number + /// + public string Routing { get; set; } + /// + /// Name on the customer's account + /// + public string Name { get; set; } + /// + /// The billing street address of the cardholder + /// + public string Street { get; set; } + /// + /// The billing zip code of the cardholder + /// + public string Zip { get; set; } + /// + /// Sets this payment as the default payment method + /// Note: If there are no other payment methods, this method is automatically set as the default + /// + public bool SetToDefault { get; set; } + } + + /// + /// Use this command to update an existing payment method. + /// Note: All fields with values must be passed in (even the fields that are not being updated). Any fields not passed in are treated as being set to blank. + /// + public class PaymentMethodUpdate : PaymentMethodAdd + { + internal new string Operation => "paymentmethod:update"; + + /// + /// Payment method's unique ID + /// + public string PaymentMethodID { get; set; } + } + + /// + /// Use this command to remove a payment method. + /// Note: The payment method is not completely deleted from the database; instead, the removed property is set to true. Customers with active schedules cannot be removed. + /// + public class PaymentMethodRemove + { + internal string Operation => "paymentmethod:remove"; + + /// + /// Payment method's unique ID + /// + public string PaymentMethodID { get; set; } + } + + /// + /// Use this command to retrieve details of a payment method. + /// + public class PaymentMethodGet + { + internal string Operation => "report:paymentmethod"; + + /// + /// Payment method's unique ID + /// + public string PaymentMethodID { get; set; } + + /// + /// Indicates whether to return deleted rows. + /// + public bool Removed { get; set; } = false; + } + + /// + /// Use this command to find payment methods using specific search parameters. + /// + public class PaymentMethodFind + { + internal string Operation => "report:paymentmethods"; + + /// + /// Customer's unique ID number + /// + public string CustomerID { get; set; } + + /// + /// Name on the customer's account + /// + public string Name { get; set; } + + /// + /// Indicates whether to return deleted rows. + /// + public bool Removed { get; set; } = false; + } +} diff --git a/src/Cardknox.NET/global.json b/src/Cardknox.NET/global.json new file mode 100644 index 0000000..7089204 --- /dev/null +++ b/src/Cardknox.NET/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "5.0.100", + "rollForward": "latestMajor" + } +} \ No newline at end of file