diff --git a/Source/Chargify.NET/Adjustment.cs b/Source/Chargify.NET/Adjustment.cs
index c5c173e..acfd0d0 100644
--- a/Source/Chargify.NET/Adjustment.cs
+++ b/Source/Chargify.NET/Adjustment.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -44,46 +44,46 @@ namespace ChargifyNET
public class Adjustment : ChargifyBase, IAdjustment, IComparable
{
#region Field Keys
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string SuccessKey = "success";
private const string MemoKey = "memo";
private const string AmountInCentsKey = "amount_in_cents";
private const string EndingBalanceInCentsKey = "ending_balance_in_cents";
private const string TypeKey = "type";
private const string TransactionTypeKey = "transaction_type";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string CreatedAtKey = "created_at";
- private const string ProductIDKey = "product_id";
+ private const string ProductIdKey = "product_id";
#endregion
#region Constructors
///
/// Constructor. Values set to default
///
- public Adjustment() : base() { }
+ public Adjustment()
+ { }
///
/// Constructor
///
- /// XML containing adjustment info (in expected format)
- public Adjustment(string AdjustmentXML)
- : base()
+ /// XML containing adjustment info (in expected format)
+ public Adjustment(string adjustmentXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(AdjustmentXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "AdjustmentXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(adjustmentXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(adjustmentXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "adjustment")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain adjustment information", "AdjustmentXML");
+ throw new ArgumentException("XML does not contain adjustment information", nameof(adjustmentXml));
}
///
@@ -91,12 +91,11 @@ public Adjustment(string AdjustmentXML)
///
/// XML containing adjustment info (in expected format)
internal Adjustment(XmlNode adjustmentNode)
- : base()
{
- if (adjustmentNode == null) throw new ArgumentNullException("adjustmentNode");
- if (adjustmentNode.Name != "adjustment") throw new ArgumentException("Not a vaild adjustment node", "adjustmentNode");
- if (adjustmentNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "adjustmentNode");
- this.LoadFromNode(adjustmentNode);
+ if (adjustmentNode == null) throw new ArgumentNullException(nameof(adjustmentNode));
+ if (adjustmentNode.Name != "adjustment") throw new ArgumentException("Not a vaild adjustment node", nameof(adjustmentNode));
+ if (adjustmentNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(adjustmentNode));
+ LoadFromNode(adjustmentNode);
}
///
@@ -104,20 +103,19 @@ internal Adjustment(XmlNode adjustmentNode)
///
/// Json containing adjustment info (in expected format)
public Adjustment(JsonObject adjustmentObject)
- : base()
{
- if (adjustmentObject == null) throw new ArgumentNullException("adjustmentObject");
- if (adjustmentObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild charge object", "adjustmentObject");
- this.LoadFromJSON(adjustmentObject);
+ if (adjustmentObject == null) throw new ArgumentNullException(nameof(adjustmentObject));
+ if (adjustmentObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild charge object", nameof(adjustmentObject));
+ LoadFromJson(adjustmentObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
switch (key)
{
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case EndingBalanceInCentsKey:
@@ -129,11 +127,11 @@ private void LoadFromJSON(JsonObject obj)
case TransactionTypeKey:
_transactionType = obj.GetJSONContentAsTransactionType(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
- case ProductIDKey:
- _productID = obj.GetJSONContentAsInt(key);
+ case ProductIdKey:
+ _productId = obj.GetJSONContentAsInt(key);
break;
case CreatedAtKey:
_createdAt = obj.GetJSONContentAsDateTime(key);
@@ -147,8 +145,6 @@ private void LoadFromJSON(JsonObject obj)
case AmountInCentsKey:
_amountInCents = obj.GetJSONContentAsInt(key);
break;
- default:
- break;
}
}
}
@@ -163,7 +159,7 @@ private void LoadFromNode(XmlNode adjustmentNode)
{
switch (dataNode.Name)
{
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case EndingBalanceInCentsKey:
@@ -175,11 +171,11 @@ private void LoadFromNode(XmlNode adjustmentNode)
case TransactionTypeKey:
_transactionType = dataNode.GetNodeContentAsTransactionType();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
- case ProductIDKey:
- _productID = dataNode.GetNodeContentAsInt();
+ case ProductIdKey:
+ _productId = dataNode.GetNodeContentAsInt();
break;
case CreatedAtKey:
_createdAt = dataNode.GetNodeContentAsDateTime();
@@ -193,18 +189,16 @@ private void LoadFromNode(XmlNode adjustmentNode)
case AmountInCentsKey:
_amountInCents = dataNode.GetNodeContentAsInt();
break;
- default:
- break;
}
}
- }
+ }
#endregion
#region IAdjustment Members
///
/// The ID of the adjustment
///
- public int ID
+ public int ID
{
get { return _id; }
}
@@ -224,7 +218,7 @@ public int AmountInCents
///
public decimal Amount
{
- get { return Convert.ToDecimal(this._amountInCents) / 100; }
+ get { return Convert.ToDecimal(_amountInCents) / 100; }
}
///
@@ -241,7 +235,7 @@ public int EndingBalanceInCents
///
public decimal EndingBalance
{
- get { return Convert.ToDecimal(this._endingBalanceInCents) / 100; }
+ get { return Convert.ToDecimal(_endingBalanceInCents) / 100; }
}
///
@@ -267,18 +261,18 @@ public TransactionType TransactionType
///
public int SubscriptionID
{
- get { return _subscriptionID; }
+ get { return _subscriptionId; }
}
- private int _subscriptionID = int.MinValue;
+ private int _subscriptionId = int.MinValue;
///
/// The subscribed product at the time of the adjustment
///
public int ProductID
{
- get { return _productID; }
+ get { return _productId; }
}
- private int _productID = int.MinValue;
+ private int _productId = int.MinValue;
///
/// The date the adjustment was created
@@ -305,7 +299,7 @@ public bool Success
{
get { return _success; }
}
- private bool _success = false;
+ private bool _success;
#endregion
@@ -317,7 +311,7 @@ public bool Success
/// The comparison value
public int CompareTo(IAdjustment other)
{
- return this._amountInCents.CompareTo(other.AmountInCents);
+ return _amountInCents.CompareTo(other.AmountInCents);
}
#endregion
@@ -329,7 +323,7 @@ public int CompareTo(IAdjustment other)
/// The comparison value
public int CompareTo(Adjustment other)
{
- return this._amountInCents.CompareTo(other.AmountInCents);
+ return _amountInCents.CompareTo(other.AmountInCents);
}
#endregion
}
diff --git a/Source/Chargify.NET/BillingManagementInfo.cs b/Source/Chargify.NET/BillingManagementInfo.cs
index 40219ad..dba9522 100644
--- a/Source/Chargify.NET/BillingManagementInfo.cs
+++ b/Source/Chargify.NET/BillingManagementInfo.cs
@@ -28,12 +28,14 @@
//
#endregion
+
+
namespace ChargifyNET
{
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -53,19 +55,19 @@ public class BillingManagementInfo : ChargifyBase, IBillingManagementInfo, IComp
///
/// Constructor
///
- private BillingManagementInfo() : base() { }
+ private BillingManagementInfo()
+ { }
///
/// Constructor
///
- /// An XML string containing a billingManagementInfo node
- public BillingManagementInfo(string billingManagementInfoXML)
- : base()
+ /// An XML string containing a billingManagementInfo node
+ public BillingManagementInfo(string billingManagementInfoXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(billingManagementInfoXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "billingManagementInfoXML");
+ doc.LoadXml(billingManagementInfoXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(billingManagementInfoXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -76,7 +78,7 @@ public BillingManagementInfo(string billingManagementInfoXML)
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain billing management information", "billingManagementInfoXML");
+ throw new ArgumentException("XML does not contain billing management information", nameof(billingManagementInfoXml));
}
///
@@ -84,12 +86,11 @@ public BillingManagementInfo(string billingManagementInfoXML)
///
/// An xml node with component information
internal BillingManagementInfo(XmlNode billingManagementInfoNode)
- : base()
{
- if (billingManagementInfoNode == null) throw new ArgumentNullException("billingManagementInfoNode");
- if (billingManagementInfoNode.Name != "management_link") throw new ArgumentException("Not a vaild billing management node", "billingManagementInfoNode");
- if (billingManagementInfoNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "billingManagementInfoNode");
- this.LoadFromNode(billingManagementInfoNode);
+ if (billingManagementInfoNode == null) throw new ArgumentNullException(nameof(billingManagementInfoNode));
+ if (billingManagementInfoNode.Name != "management_link") throw new ArgumentException("Not a vaild billing management node", nameof(billingManagementInfoNode));
+ if (billingManagementInfoNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(billingManagementInfoNode));
+ LoadFromNode(billingManagementInfoNode);
}
///
@@ -97,14 +98,13 @@ internal BillingManagementInfo(XmlNode billingManagementInfoNode)
///
/// An JsonObject with billing management information
public BillingManagementInfo(JsonObject billingManagementInfoObject)
- : base()
{
- if (billingManagementInfoObject == null) throw new ArgumentNullException("billingManagementInfoObject");
- if (billingManagementInfoObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild management object", "billingManagementInfoObject");
- this.LoadFromJSON(billingManagementInfoObject);
+ if (billingManagementInfoObject == null) throw new ArgumentNullException(nameof(billingManagementInfoObject));
+ if (billingManagementInfoObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild management object", nameof(billingManagementInfoObject));
+ LoadFromJson(billingManagementInfoObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get component info, and parse it out
foreach (string key in obj.Keys)
@@ -126,8 +126,6 @@ private void LoadFromJSON(JsonObject obj)
case ExpiresAtKey:
_expiresAt = obj.GetJSONContentAsDateTime(key);
break;
- default:
- break;
}
}
}
@@ -154,8 +152,6 @@ private void LoadFromNode(XmlNode obj)
case NewLinkAvailableAtKey:
_newLinkAvailableAt = dataNode.GetNodeContentAsDateTime();
break;
- default:
- break;
}
}
}
@@ -168,7 +164,7 @@ private void LoadFromNode(XmlNode obj)
///
public string URL
{
- get { return this._url; }
+ get { return _url; }
}
private string _url = string.Empty;
@@ -177,7 +173,7 @@ public string URL
///
public int FetchCount
{
- get { return this._fetchCount; }
+ get { return _fetchCount; }
}
private int _fetchCount = int.MinValue;
@@ -186,7 +182,7 @@ public int FetchCount
///
public DateTime CreatedAt
{
- get { return this._createdAt; }
+ get { return _createdAt; }
}
private DateTime _createdAt = DateTime.MinValue;
@@ -195,7 +191,7 @@ public DateTime CreatedAt
///
public DateTime NewLinkAvailableAt
{
- get { return this._newLinkAvailableAt; }
+ get { return _newLinkAvailableAt; }
}
private DateTime _newLinkAvailableAt = DateTime.MinValue;
@@ -204,10 +200,10 @@ public DateTime NewLinkAvailableAt
///
public DateTime ExpiresAt
{
- get { return this._expiresAt; }
+ get { return _expiresAt; }
}
private DateTime _expiresAt = DateTime.MinValue;
-
+
#endregion
#region ICompare Members
@@ -219,7 +215,7 @@ public DateTime ExpiresAt
public int CompareTo(BillingManagementInfo other)
{
// compare
- return this.URL.CompareTo(other.URL);
+ return string.Compare(URL, other.URL, StringComparison.InvariantCultureIgnoreCase);
}
///
@@ -229,7 +225,7 @@ public int CompareTo(BillingManagementInfo other)
///
public int CompareTo(IBillingManagementInfo other)
{
- return this.URL.CompareTo(other.URL);
+ return string.Compare(URL, other.URL, StringComparison.CurrentCultureIgnoreCase);
}
#endregion
}
diff --git a/Source/Chargify.NET/Charge.cs b/Source/Chargify.NET/Charge.cs
index b8ffec0..5c4e49e 100644
--- a/Source/Chargify.NET/Charge.cs
+++ b/Source/Chargify.NET/Charge.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -47,14 +47,14 @@ public class Charge : ChargifyBase, ICharge, IComparable
private const string AmountInCentsKey = "amount_in_cents";
private const string CreatedAtKey = "created_at";
private const string EndingBalanceInCentsKey = "ending_balance_in_cents";
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string KindKey = "kind";
- private const string PaymentIDKey = "payment_id";
- private const string ProductIDKey = "product_id";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string PaymentIdKey = "payment_id";
+ private const string ProductIdKey = "product_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string TypeKey = "type";
private const string TransactionTypeKey = "transaction_type";
- private const string GatewayTransactionIDKey = "gateway_transaction_id";
+ private const string GatewayTransactionIdKey = "gateway_transaction_id";
#endregion
#region Constructors
@@ -62,30 +62,30 @@ public class Charge : ChargifyBase, ICharge, IComparable
///
/// Constructor. Values set to default
///
- public Charge() : base() { }
+ public Charge()
+ { }
///
/// Constructor
///
/// XML containing charge info (in expected format)
public Charge(string chargeXml)
- : base()
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
doc.LoadXml(chargeXml);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "chargeXml");
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(chargeXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "charge")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain charge information", "ChargeXML");
+ throw new ArgumentException("XML does not contain charge information", nameof(chargeXml));
}
///
@@ -93,26 +93,25 @@ public Charge(string chargeXml)
///
/// XML containing charge info (in expected format)
internal Charge(XmlNode chargeNode)
- : base()
{
- if (chargeNode == null) throw new ArgumentNullException("ChargeNode");
- if (chargeNode.Name != "charge") throw new ArgumentException("Not a vaild charge node", "chargeNode");
- if (chargeNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "chargeNode");
- this.LoadFromNode(chargeNode);
+ if (chargeNode == null) throw new ArgumentNullException(nameof(chargeNode));
+ if (chargeNode.Name != "charge") throw new ArgumentException("Not a vaild charge node", nameof(chargeNode));
+ if (chargeNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(chargeNode));
+ LoadFromNode(chargeNode);
}
///
/// Constructor
///
/// Json containing charge info (in expected format)
- public Charge(JsonObject chargeObject) : base()
+ public Charge(JsonObject chargeObject)
{
- if (chargeObject == null) throw new ArgumentNullException("chargeObject");
- if (chargeObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild charge object", "chargeObject");
- this.LoadFromJSON(chargeObject);
+ if (chargeObject == null) throw new ArgumentNullException(nameof(chargeObject));
+ if (chargeObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild charge object", nameof(chargeObject));
+ LoadFromJson(chargeObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -133,20 +132,20 @@ private void LoadFromJSON(JsonObject obj)
case EndingBalanceInCentsKey:
_endingBalanceInCents = obj.GetJSONContentAsInt(key);
break;
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case KindKey:
_kind = obj.GetJSONContentAsString(key);
break;
- case PaymentIDKey:
- _paymentID = obj.GetJSONContentAsNullableInt(key);
+ case PaymentIdKey:
+ _paymentId = obj.GetJSONContentAsNullableInt(key);
break;
- case ProductIDKey:
- _productID = obj.GetJSONContentAsInt(key);
+ case ProductIdKey:
+ _productId = obj.GetJSONContentAsInt(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case TypeKey:
_chargeType = obj.GetJSONContentAsString(key);
@@ -154,10 +153,8 @@ private void LoadFromJSON(JsonObject obj)
case TransactionTypeKey:
_transactionType = obj.GetJSONContentAsString(key);
break;
- case GatewayTransactionIDKey:
- _gatewayTransactionID = obj.GetJSONContentAsNullableInt(key);
- break;
- default:
+ case GatewayTransactionIdKey:
+ _gatewayTransactionId = obj.GetJSONContentAsNullableInt(key);
break;
}
}
@@ -188,20 +185,20 @@ private void LoadFromNode(XmlNode subscriptionNode)
case EndingBalanceInCentsKey:
_endingBalanceInCents = dataNode.GetNodeContentAsInt();
break;
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case KindKey:
_kind = dataNode.GetNodeContentAsString();
break;
- case PaymentIDKey:
- _paymentID = dataNode.GetNodeContentAsNullableInt();
+ case PaymentIdKey:
+ _paymentId = dataNode.GetNodeContentAsNullableInt();
break;
- case ProductIDKey:
- _productID = dataNode.GetNodeContentAsInt();
+ case ProductIdKey:
+ _productId = dataNode.GetNodeContentAsInt();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case TypeKey:
_chargeType = dataNode.GetNodeContentAsString();
@@ -209,10 +206,8 @@ private void LoadFromNode(XmlNode subscriptionNode)
case TransactionTypeKey:
_transactionType = dataNode.GetNodeContentAsString();
break;
- case GatewayTransactionIDKey:
- _gatewayTransactionID = dataNode.GetNodeContentAsNullableInt();
- break;
- default:
+ case GatewayTransactionIdKey:
+ _gatewayTransactionId = dataNode.GetNodeContentAsNullableInt();
break;
}
}
@@ -231,7 +226,7 @@ public bool Success
{
get { return _success; }
}
- private bool _success = false;
+ private bool _success;
///
/// Get the amount (in cents)
@@ -247,7 +242,7 @@ public int AmountInCents
///
public decimal Amount
{
- get { return Convert.ToDecimal(this._amountInCents) / 100; }
+ get { return Convert.ToDecimal(_amountInCents) / 100; }
}
///
@@ -262,67 +257,67 @@ public string Memo
///
/// The date the charge was created
///
- public DateTime CreatedAt { get { return this._createdAt; } }
+ public DateTime CreatedAt { get { return _createdAt; } }
private DateTime _createdAt = DateTime.MinValue;
///
/// The ending balance of the subscription, in cents
///
- public int EndingBalanceInCents { get { return this._endingBalanceInCents; } }
+ public int EndingBalanceInCents { get { return _endingBalanceInCents; } }
private int _endingBalanceInCents = int.MinValue;
///
/// The ending balance of the subscription, in dollars and cents (formatted as decimal)
///
- public decimal EndingBalance { get { return Convert.ToDecimal(this._endingBalanceInCents) / 100; } }
+ public decimal EndingBalance { get { return Convert.ToDecimal(_endingBalanceInCents) / 100; } }
///
/// The ID of the charge
///
- public int ID { get { return this._id; } }
+ public int ID { get { return _id; } }
private int _id = int.MinValue;
///
/// The kind of charge
///
- public string Kind { get { return this._kind; } }
+ public string Kind { get { return _kind; } }
private string _kind = string.Empty;
///
/// The ID of the payment associated with this charge
///
- public int? PaymentID { get { return this._paymentID; } }
- private int? _paymentID = null;
+ public int? PaymentID { get { return _paymentId; } }
+ private int? _paymentId;
///
/// The product ID the subscription was subscribed to at the time of the charge
///
- public int ProductID { get { return this._productID; } }
- private int _productID = int.MinValue;
+ public int ProductID { get { return _productId; } }
+ private int _productId = int.MinValue;
///
/// The subscription ID that this charge was applied to
///
- public int SubscriptionID { get { return this._subscriptionID; } }
- private int _subscriptionID = int.MinValue;
+ public int SubscriptionID { get { return _subscriptionId; } }
+ private int _subscriptionId = int.MinValue;
///
/// The type of charge
///
- public string ChargeType { get { return this._chargeType; } }
+ public string ChargeType { get { return _chargeType; } }
private string _chargeType = string.Empty;
///
/// The type of transaction
///
- public string TransactionType { get { return this._transactionType; } }
+ public string TransactionType { get { return _transactionType; } }
private string _transactionType = string.Empty;
///
/// The ID of the gateway transaction, useful for debugging.
///
- public int? GatewayTransactionID { get { return this._gatewayTransactionID; } }
- private int? _gatewayTransactionID = null;
+ public int? GatewayTransactionID { get { return _gatewayTransactionId; } }
+ private int? _gatewayTransactionId;
#endregion
@@ -335,7 +330,7 @@ public string Memo
/// The result of the comparison
public int CompareTo(ICharge other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
@@ -349,7 +344,7 @@ public int CompareTo(ICharge other)
/// The result of the comparison
public int CompareTo(Charge other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
diff --git a/Source/Chargify.NET/Chargify.NET.csproj b/Source/Chargify.NET/Chargify.NET.csproj
index e6f2df7..c660603 100644
--- a/Source/Chargify.NET/Chargify.NET.csproj
+++ b/Source/Chargify.NET/Chargify.NET.csproj
@@ -100,6 +100,7 @@
+
diff --git a/Source/Chargify.NET/ChargifyBase.cs b/Source/Chargify.NET/ChargifyBase.cs
index 0d44c7f..353d781 100644
--- a/Source/Chargify.NET/ChargifyBase.cs
+++ b/Source/Chargify.NET/ChargifyBase.cs
@@ -30,7 +30,7 @@
//setting CLSCompliant attribute to true
using System;
-[assembly:CLSCompliant(true)]
+[assembly: CLSCompliant(true)]
namespace ChargifyNET
{
@@ -56,14 +56,16 @@ protected ChargifyBase() { }
/// The object represented as an HTML formatted string
public virtual string ToHTMLString()
{
+
+#if !DOTNET
if (HttpContext.Current != null)
{
- return HttpContext.Current.Server.HtmlEncode(this.ToString()).Replace("\n\t", "
· ").Replace("\n", "
").Replace(" ", " ");
- }
- else
- {
- return this.ToString().Replace("\n\t", "
· ").Replace("\n", "
").Replace(" ", " ");
+ return HttpContext.Current.Server.HtmlEncode(ToString()).Replace("\n\t", "
· ").Replace("\n", "
").Replace(" ", " ");
}
+ return ToString().Replace("\n\t", "
· ").Replace("\n", "
").Replace(" ", " ");
+#else
+ return this.ToString().Replace("\n\t", "
· ").Replace("\n", "
").Replace(" ", " ");
+#endif
}
}
}
diff --git a/Source/Chargify.NET/ChargifyConnect.cs b/Source/Chargify.NET/ChargifyConnect.cs
index 3872b56..da4ba0c 100644
--- a/Source/Chargify.NET/ChargifyConnect.cs
+++ b/Source/Chargify.NET/ChargifyConnect.cs
@@ -30,7 +30,7 @@
namespace ChargifyNET
{
#region Imports
- using ChargifyNET.Json;
+ using Json;
using System;
using System.Collections.Generic;
using System.IO;
@@ -69,9 +69,9 @@ public ChargifyConnect() { }
/// Your Chargify api password
public ChargifyConnect(string url, string apiKey, string password)
{
- this.URL = url;
+ URL = url;
this.apiKey = apiKey;
- this.Password = password;
+ Password = password;
}
///
@@ -83,26 +83,20 @@ public ChargifyConnect(string url, string apiKey, string password)
/// Your Chargify hosted page shared key
public ChargifyConnect(string url, string apiKey, string password, string sharedKey)
{
- this.URL = url;
+ URL = url;
this.apiKey = apiKey;
- this.Password = password;
- this.SharedKey = sharedKey;
+ Password = password;
+ SharedKey = sharedKey;
}
#endregion
#region Properties
- private static string UserAgent
- {
- get
- {
- if (_userAgent == null)
- {
- _userAgent = String.Format("Chargify.NET Client v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
- }
- return _userAgent;
- }
- }
+ private static string UserAgent => _userAgent ??
+ (_userAgent =
+ string.Format("Chargify.NET Client v" +
+ System.Reflection.Assembly.GetExecutingAssembly().GetName().Version));
+
private static string _userAgent;
///
@@ -133,7 +127,7 @@ private static string UserAgent
///
/// Should the library require a CVV?
///
- public bool CvvRequired { get { return this._cvvRequired; } set { this._cvvRequired = value; } }
+ public bool CvvRequired { get { return _cvvRequired; } set { _cvvRequired = value; } }
private bool _cvvRequired = true;
///
@@ -142,20 +136,20 @@ private static string UserAgent
///
public SecurityProtocolType? ProtocolType
{
- get { return this._protocolType; }
+ get { return _protocolType; }
set
{
if (value.HasValue)
{
- this._protocolType = value;
+ _protocolType = value;
}
else
{
- this._protocolType = null;
+ _protocolType = null;
}
}
}
- private SecurityProtocolType? _protocolType = null;
+ private SecurityProtocolType? _protocolType;
///
/// The timeout (in milliseconds) for any call to Chargify. The default is 180000
@@ -164,11 +158,11 @@ public int Timeout
{
get
{
- return this._timeout;
+ return _timeout;
}
set
{
- this._timeout = value;
+ _timeout = value;
}
}
@@ -180,9 +174,9 @@ public bool HasConnected
get
{
bool result = true;
- if (string.IsNullOrEmpty(this.apiKey)) result = false;
- if (string.IsNullOrEmpty(this.Password)) result = false;
- if (string.IsNullOrEmpty(this.URL)) result = false;
+ if (string.IsNullOrEmpty(apiKey)) result = false;
+ if (string.IsNullOrEmpty(Password)) result = false;
+ if (string.IsNullOrEmpty(URL)) result = false;
return result;
}
}
@@ -208,7 +202,7 @@ public HttpWebResponse LastResponse
return _lastResponse;
}
}
- private HttpWebResponse _lastResponse = null;
+ private HttpWebResponse _lastResponse;
#endregion
@@ -217,10 +211,10 @@ public HttpWebResponse LastResponse
/// Allows you to set a group of metadata for a specific resource
///
/// The type of resource. Currently either Subscription or Customer
- /// The Chargify identifier for the resource
+ /// The Chargify identifier for the resource
/// The list of metadatum to set
/// The metadata result containing the response
- public List SetMetadataFor(int chargifyID, List metadatum)
+ public List SetMetadataFor(int chargifyId, List metadatum)
{
// make sure data is valid
if (metadatum == null) { throw new ArgumentNullException("metadatum"); }
@@ -230,7 +224,7 @@ public List SetMetadataFor(int chargifyID, List metadatu
//if (metadatum.Select(m => m.Value == null).Count() > 0) { throw new ArgumentNullException("Metadata.Value"); }
// create XML for creation of metadata
- var metadataXml = new StringBuilder(GetXMLStringIfApplicable());
+ var metadataXml = new StringBuilder(GetXmlStringIfApplicable());
metadataXml.Append("");
foreach (var metadata in metadatum)
{
@@ -241,7 +235,7 @@ public List SetMetadataFor(int chargifyID, List metadatu
}
else
{
- metadataXml.AppendFormat("{0}", chargifyID);
+ metadataXml.AppendFormat("{0}", chargifyId);
}
metadataXml.AppendFormat("{0}", metadata.Name);
metadataXml.AppendFormat("{0}", metadata.Value);
@@ -249,30 +243,30 @@ public List SetMetadataFor(int chargifyID, List metadatu
}
metadataXml.Append("");
- string url = string.Empty;
+ string url;
switch (typeof(T).Name.ToLowerInvariant())
{
case "customer":
- url = string.Format("customers/{0}/metadata.{1}", chargifyID, GetMethodExtension());
+ url = $"customers/{chargifyId}/metadata.{GetMethodExtension()}";
break;
case "subscription":
- url = string.Format("subscriptions/{0}/metadata.{1}", chargifyID, GetMethodExtension());
+ url = $"subscriptions/{chargifyId}/metadata.{GetMethodExtension()}";
break;
default:
- throw new Exception(string.Format("Must be of type '{0}'", string.Join(", ", MetadataTypes.ToArray())));
+ throw new Exception($"Must be of type '{string.Join(", ", _metadataTypes.ToArray())}'");
}
// now make the request
- string response = this.DoRequest(url, HttpRequestMethod.Post, metadataXml.ToString());
+ string response = DoRequest(url, HttpRequestMethod.Post, metadataXml.ToString());
var retVal = new List();
// now build the object based on response as XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response); // get the XML into an XML document
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response); // get the XML into an XML document
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode parentNode in Doc.ChildNodes)
+ foreach (XmlNode parentNode in doc.ChildNodes)
{
if (parentNode.Name == "metadata")
{
@@ -294,56 +288,56 @@ public List SetMetadataFor(int chargifyID, List metadatu
/// Allows you to set a single metadata for a specific resource
///
/// The type of resource. Currently either Subscription or Customer
- /// The Chargify identifier for the resource
+ /// The Chargify identifier for the resource
/// The list of metadata to set
/// The metadata result containing the response
- public List SetMetadataFor(int chargifyID, Metadata metadata)
+ public List SetMetadataFor(int chargifyId, Metadata metadata)
{
// make sure data is valid
- if (metadata == null) throw new ArgumentNullException("metadata");
+ if (metadata == null) throw new ArgumentNullException(nameof(metadata));
//if (chargifyID < 0 || metadata.ResourceID < 0) throw new ArgumentOutOfRangeException("Metadata.ResourceID");
- if (string.IsNullOrEmpty(metadata.Name)) throw new ArgumentNullException("Metadata.Name");
- if (metadata.Value == null) throw new ArgumentNullException("Metadata.Value");
+ if (string.IsNullOrEmpty(metadata.Name)) throw new ArgumentNullException(nameof(metadata), "Metadata.Name");
+ if (metadata.Value == null) throw new ArgumentNullException(nameof(metadata), "Metadata.Value");
// create XML for creation of metadata
- var MetadataXML = new StringBuilder(GetXMLStringIfApplicable());
- MetadataXML.Append("");
+ var metadataXml = new StringBuilder(GetXmlStringIfApplicable());
+ metadataXml.Append("");
if (metadata.ResourceID > 0)
{
- MetadataXML.AppendFormat("{0}", metadata.ResourceID);
+ metadataXml.AppendFormat("{0}", metadata.ResourceID);
}
else
{
- MetadataXML.AppendFormat("{0}", chargifyID);
+ metadataXml.AppendFormat("{0}", chargifyId);
}
- MetadataXML.AppendFormat("{0}", metadata.Name);
- MetadataXML.AppendFormat("{0}", metadata.Value);
- MetadataXML.Append("");
+ metadataXml.AppendFormat("{0}", metadata.Name);
+ metadataXml.AppendFormat("{0}", metadata.Value);
+ metadataXml.Append("");
- string url = string.Empty;
+ string url;
switch (typeof(T).Name.ToLowerInvariant())
{
case "customer":
- url = string.Format("customers/{0}/metadata.{1}", chargifyID, GetMethodExtension());
+ url = $"customers/{chargifyId}/metadata.{GetMethodExtension()}";
break;
case "subscription":
- url = string.Format("subscriptions/{0}/metadata.{1}", chargifyID, GetMethodExtension());
+ url = $"subscriptions/{chargifyId}/metadata.{GetMethodExtension()}";
break;
default:
- throw new Exception(string.Format("Must be of type '{0}'", string.Join(", ", MetadataTypes.ToArray())));
+ throw new Exception($"Must be of type '{string.Join(", ", _metadataTypes.ToArray())}'");
}
// now make the request
- string response = this.DoRequest(url, HttpRequestMethod.Post, MetadataXML.ToString());
+ string response = DoRequest(url, HttpRequestMethod.Post, metadataXml.ToString());
var retVal = new List();
// now build the object based on response as XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response); // get the XML into an XML document
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response); // get the XML into an XML document
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode parentNode in Doc.ChildNodes)
+ foreach (XmlNode parentNode in doc.ChildNodes)
{
if (parentNode.Name == "metadata")
{
@@ -370,22 +364,22 @@ public List SetMetadataFor(int chargifyID, Metadata metadata)
/// Retrieve all metadata for a specific resource (like a specific customer or subscription).
///
/// The type of resource. Currently either Subscription or Customer
- /// The Chargify identifier for the resource
+ /// The Chargify identifier for the resource
/// Which page to return
/// The metadata result containing the response
- public IMetadataResult GetMetadataFor(int resourceID, int? page)
+ public IMetadataResult GetMetadataFor(int resourceId, int? page)
{
- string url = string.Empty;
+ string url;
switch (typeof(T).Name.ToLowerInvariant())
{
case "customer":
- url = string.Format("customers/{0}/metadata.{1}", resourceID, GetMethodExtension());
+ url = string.Format("customers/{0}/metadata.{1}", resourceId, GetMethodExtension());
break;
case "subscription":
- url = string.Format("subscriptions/{0}/metadata.{1}", resourceID, GetMethodExtension());
+ url = string.Format("subscriptions/{0}/metadata.{1}", resourceId, GetMethodExtension());
break;
default:
- throw new Exception(string.Format("Must be of type '{0}'", string.Join(", ", MetadataTypes.ToArray())));
+ throw new Exception(string.Format("Must be of type '{0}'", string.Join(", ", _metadataTypes.ToArray())));
}
string qs = string.Empty;
@@ -395,7 +389,7 @@ public IMetadataResult GetMetadataFor(int resourceID, int? page)
// Construct the url to access Chargify
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
// change the response to the object
return response.ConvertResponseTo("metadata");
@@ -408,22 +402,22 @@ public IMetadataResult GetMetadataFor(int resourceID, int? page)
/// The metadata result containing the response
public IMetadataResult GetMetadata()
{
- string response = string.Empty;
+ string response;
switch (typeof(T).Name.ToLowerInvariant())
{
case "customer":
- response = this.DoRequest(string.Format("customers/metadata.{0}", GetMethodExtension()), HttpRequestMethod.Get, null);
+ response = DoRequest(string.Format("customers/metadata.{0}", GetMethodExtension()), HttpRequestMethod.Get, null);
break;
case "subscription":
- response = this.DoRequest(string.Format("subscriptions/metadata.{0}", GetMethodExtension()), HttpRequestMethod.Get, null);
+ response = DoRequest(string.Format("subscriptions/metadata.{0}", GetMethodExtension()), HttpRequestMethod.Get, null);
break;
default:
- throw new Exception(string.Format("Must be of type '{0}'", string.Join(", ", MetadataTypes.ToArray())));
+ throw new Exception(string.Format("Must be of type '{0}'", string.Join(", ", _metadataTypes.ToArray())));
}
// change the response to the object
return response.ConvertResponseTo("metadata");
}
- private static List MetadataTypes = new List { "Customer", "Subscription" };
+ private static List _metadataTypes = new List { "Customer", "Subscription" };
#endregion
#region Customers
@@ -431,16 +425,16 @@ public IMetadataResult GetMetadata()
///
/// Load the requested customer from chargify
///
- /// The chargify ID of the customer
+ /// The chargify ID of the customer
/// The customer with the specified chargify ID
- public ICustomer LoadCustomer(int ChargifyID)
+ public ICustomer LoadCustomer(int chargifyId)
{
try
{
// make sure data is valid
- if (ChargifyID == int.MinValue) throw new ArgumentNullException("ChargifyID");
+ if (chargifyId == int.MinValue) throw new ArgumentNullException("chargifyId");
// now make the request
- string response = this.DoRequest(string.Format("customers/{0}.{1}", ChargifyID, GetMethodExtension()));
+ string response = DoRequest(string.Format("customers/{0}.{1}", chargifyId, GetMethodExtension()));
// change the response to the object
return response.ConvertResponseTo("customer");
}
@@ -454,16 +448,16 @@ public ICustomer LoadCustomer(int ChargifyID)
///
/// Load the requested customer from chargify
///
- /// The system ID of the customer
+ /// The system ID of the customer
/// The customer with the specified chargify ID
- public ICustomer LoadCustomer(string SystemID)
+ public ICustomer LoadCustomer(string systemId)
{
try
{
// make sure data is valid
- if (SystemID == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "SystemID");
+ if (systemId == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "systemId");
// now make the request
- string response = this.DoRequest(string.Format("customers/lookup.{0}?reference={1}", GetMethodExtension(), SystemID));
+ string response = DoRequest(string.Format("customers/lookup.{0}?reference={1}", GetMethodExtension(), systemId));
// change the response to the object
return response.ConvertResponseTo("customer");
}
@@ -477,67 +471,67 @@ public ICustomer LoadCustomer(string SystemID)
///
/// Create a new chargify customer
///
- ///
+ ///
/// A customer object containing customer attributes. The customer cannot be an existing saved chargify customer
///
/// The created chargify customer
- public ICustomer CreateCustomer(ICustomer Customer)
+ public ICustomer CreateCustomer(ICustomer customer)
{
// make sure data is valid
- if (Customer == null) throw new ArgumentNullException("Customer");
- if (Customer.IsSaved) throw new ArgumentException("Customer already saved", "Customer");
- return CreateCustomer(Customer.FirstName, Customer.LastName, Customer.Email, Customer.Phone, Customer.Organization, Customer.SystemID,
- Customer.ShippingAddress, Customer.ShippingAddress2, Customer.ShippingCity, Customer.ShippingState,
- Customer.ShippingZip, Customer.ShippingCountry);
+ if (customer == null) throw new ArgumentNullException("customer");
+ if (customer.IsSaved) throw new ArgumentException("Customer already saved", "customer");
+ return CreateCustomer(customer.FirstName, customer.LastName, customer.Email, customer.Phone, customer.Organization, customer.SystemID,
+ customer.ShippingAddress, customer.ShippingAddress2, customer.ShippingCity, customer.ShippingState,
+ customer.ShippingZip, customer.ShippingCountry);
}
///
/// Create a new chargify customer
///
- /// The first name of the customer
- /// The last name of the customer
- /// The email address of the customer
- /// The phone number of the customer
- /// The organization of the customer
- /// The system ID of the customer
- /// The shipping address of the customer, if applicable.
- /// The shipping address (line 2) of the customer, if applicable.
- /// The shipping city of the customer, if applicable.
- /// The shipping state of the customer, if applicable.
- /// The shipping zip of the customer, if applicable.
- /// The shipping country of the customer, if applicable.
+ /// The first name of the customer
+ /// The last name of the customer
+ /// The email address of the customer
+ /// The phone number of the customer
+ /// The organization of the customer
+ /// The system ID of the customer
+ /// The shipping address of the customer, if applicable.
+ /// The shipping address (line 2) of the customer, if applicable.
+ /// The shipping city of the customer, if applicable.
+ /// The shipping state of the customer, if applicable.
+ /// The shipping zip of the customer, if applicable.
+ /// The shipping country of the customer, if applicable.
/// The created chargify customer
- public ICustomer CreateCustomer(string FirstName, string LastName, string EmailAddress, string Phone, string Organization, string SystemID,
- string ShippingAddress, string ShippingAddress2, string ShippingCity, string ShippingState,
- string ShippingZip, string ShippingCountry)
+ public ICustomer CreateCustomer(string firstName, string lastName, string emailAddress, string phone, string organization, string systemId,
+ string shippingAddress, string shippingAddress2, string shippingCity, string shippingState,
+ string shippingZip, string shippingCountry)
{
// make sure data is valid
- if (string.IsNullOrEmpty(FirstName)) throw new ArgumentNullException("FirstName");
+ if (string.IsNullOrEmpty(firstName)) throw new ArgumentNullException(nameof(firstName));
#if !DEBUG
- if (string.IsNullOrEmpty(LastName)) throw new ArgumentNullException("LastName");
- if (string.IsNullOrEmpty(EmailAddress)) throw new ArgumentNullException("EmailAddress");
- if (SystemID == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "SystemID");
+ if (string.IsNullOrEmpty(lastName)) throw new ArgumentNullException(nameof(lastName));
+ if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentNullException(nameof(emailAddress));
+ if (systemId == string.Empty) throw new ArgumentException("Empty systemId not allowed", nameof(systemId));
// make sure that the system ID is unique
- if (this.LoadCustomer(SystemID) != null) throw new ArgumentException("Not unique", "SystemID");
+ if (this.LoadCustomer(systemId) != null) throw new ArgumentException("Not unique", nameof(systemId));
#endif
// create XML for creation of customer
- var CustomerXML = new StringBuilder(GetXMLStringIfApplicable());
- CustomerXML.Append("");
- if (!string.IsNullOrEmpty(EmailAddress)) CustomerXML.AppendFormat("{0}", EmailAddress);
- if (!string.IsNullOrEmpty(Phone)) CustomerXML.AppendFormat("<{0}>{1}{2}>", CustomerAttributes.PhoneKey, Phone, CustomerAttributes.PhoneKey);
- if (!string.IsNullOrEmpty(FirstName)) CustomerXML.AppendFormat("{0}", FirstName);
- if (!string.IsNullOrEmpty(LastName)) CustomerXML.AppendFormat("{0}", LastName);
- if (!string.IsNullOrEmpty(Organization)) CustomerXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Organization));
- if (!string.IsNullOrEmpty(SystemID)) CustomerXML.AppendFormat("{0}", SystemID);
- if (!string.IsNullOrEmpty(ShippingAddress)) CustomerXML.AppendFormat("{0}", ShippingAddress);
- if (!string.IsNullOrEmpty(ShippingAddress2)) CustomerXML.AppendFormat("{0}", ShippingAddress2);
- if (!string.IsNullOrEmpty(ShippingCity)) CustomerXML.AppendFormat("{0}", ShippingCity);
- if (!string.IsNullOrEmpty(ShippingState)) CustomerXML.AppendFormat("{0}", ShippingState);
- if (!string.IsNullOrEmpty(ShippingZip)) CustomerXML.AppendFormat("{0}", ShippingZip);
- if (!string.IsNullOrEmpty(ShippingCountry)) CustomerXML.AppendFormat("{0}", ShippingCountry);
- CustomerXML.Append("");
+ var customerXml = new StringBuilder(GetXmlStringIfApplicable());
+ customerXml.Append("");
+ if (!string.IsNullOrEmpty(emailAddress)) customerXml.AppendFormat("{0}", emailAddress);
+ if (!string.IsNullOrEmpty(phone)) customerXml.AppendFormat("<{0}>{1}{2}>", CustomerAttributes.PhoneKey, phone, CustomerAttributes.PhoneKey);
+ if (!string.IsNullOrEmpty(firstName)) customerXml.AppendFormat("{0}", firstName);
+ if (!string.IsNullOrEmpty(lastName)) customerXml.AppendFormat("{0}", lastName);
+ if (!string.IsNullOrEmpty(organization)) customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(organization));
+ if (!string.IsNullOrEmpty(systemId)) customerXml.AppendFormat("{0}", systemId);
+ if (!string.IsNullOrEmpty(shippingAddress)) customerXml.AppendFormat("{0}", shippingAddress);
+ if (!string.IsNullOrEmpty(shippingAddress2)) customerXml.AppendFormat("{0}", shippingAddress2);
+ if (!string.IsNullOrEmpty(shippingCity)) customerXml.AppendFormat("{0}", shippingCity);
+ if (!string.IsNullOrEmpty(shippingState)) customerXml.AppendFormat("{0}", shippingState);
+ if (!string.IsNullOrEmpty(shippingZip)) customerXml.AppendFormat("{0}", shippingZip);
+ if (!string.IsNullOrEmpty(shippingCountry)) customerXml.AppendFormat("{0}", shippingCountry);
+ customerXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("customers.{0}", GetMethodExtension()), HttpRequestMethod.Post, CustomerXML.ToString());
+ string response = DoRequest(string.Format("customers.{0}", GetMethodExtension()), HttpRequestMethod.Post, customerXml.ToString());
// change the response to the object
return response.ConvertResponseTo("customer");
}
@@ -545,34 +539,34 @@ public ICustomer CreateCustomer(string FirstName, string LastName, string EmailA
///
/// Create a new chargify customer
///
- /// The first name of the customer
- /// The last name of the customer
- /// The email address of the customer
- /// The phone number of the customer
- /// The organization of the customer
- /// The system ID fro the customer
+ /// The first name of the customer
+ /// The last name of the customer
+ /// The email address of the customer
+ /// The phone number of the customer
+ /// The organization of the customer
+ /// The system ID fro the customer
/// The created chargify customer
- public ICustomer CreateCustomer(string FirstName, string LastName, string EmailAddress, string Phone, string Organization, string SystemID)
+ public ICustomer CreateCustomer(string firstName, string lastName, string emailAddress, string phone, string organization, string systemId)
{
// make sure data is valid
- if (string.IsNullOrEmpty(FirstName)) throw new ArgumentNullException("FirstName");
- if (string.IsNullOrEmpty(LastName)) throw new ArgumentNullException("LastName");
- if (string.IsNullOrEmpty(EmailAddress)) throw new ArgumentNullException("EmailAddress");
- if (SystemID == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "SystemID");
+ if (string.IsNullOrEmpty(firstName)) throw new ArgumentNullException("firstName");
+ if (string.IsNullOrEmpty(lastName)) throw new ArgumentNullException("lastName");
+ if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentNullException("emailAddress");
+ if (systemId == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "systemId");
// make sure that the system ID is unique
- if (this.LoadCustomer(SystemID) != null) throw new ArgumentException("Not unique", "SystemID");
+ if (LoadCustomer(systemId) != null) throw new ArgumentException("Not unique", "systemId");
// create XML for creation of customer
- var CustomerXML = new StringBuilder(GetXMLStringIfApplicable());
- CustomerXML.Append("");
- CustomerXML.AppendFormat("{0}", EmailAddress);
- CustomerXML.AppendFormat("{0}", FirstName);
- CustomerXML.AppendFormat("{0}", LastName);
- if (!string.IsNullOrEmpty(Phone)) CustomerXML.AppendFormat("<{0}>{1}{2}>", CustomerAttributes.PhoneKey, Phone, CustomerAttributes.PhoneKey);
- if (!string.IsNullOrEmpty(Organization)) CustomerXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Organization));
- if (!string.IsNullOrEmpty(SystemID)) CustomerXML.AppendFormat("{0}", SystemID);
- CustomerXML.Append("");
+ var customerXml = new StringBuilder(GetXmlStringIfApplicable());
+ customerXml.Append("");
+ customerXml.AppendFormat("{0}", emailAddress);
+ customerXml.AppendFormat("{0}", firstName);
+ customerXml.AppendFormat("{0}", lastName);
+ if (!string.IsNullOrEmpty(phone)) customerXml.AppendFormat("<{0}>{1}{2}>", CustomerAttributes.PhoneKey, phone, CustomerAttributes.PhoneKey);
+ if (!string.IsNullOrEmpty(organization)) customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(organization));
+ if (!string.IsNullOrEmpty(systemId)) customerXml.AppendFormat("{0}", systemId);
+ customerXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("customers.{0}", GetMethodExtension()), HttpRequestMethod.Post, CustomerXML.ToString());
+ string response = DoRequest(string.Format("customers.{0}", GetMethodExtension()), HttpRequestMethod.Post, customerXml.ToString());
// change the response to the object
return response.ConvertResponseTo("customer");
}
@@ -580,35 +574,35 @@ public ICustomer CreateCustomer(string FirstName, string LastName, string EmailA
///
/// Update the specified chargify customer
///
- /// The customer to update
+ /// The customer to update
/// The updated customer
- public ICustomer UpdateCustomer(ICustomer Customer)
+ public ICustomer UpdateCustomer(ICustomer customer)
{
// make sure data is OK
- if (Customer == null) throw new ArgumentNullException("Customer");
- if (Customer.ChargifyID == int.MinValue) throw new ArgumentException("Invalid chargify ID detected", "Customer.ChargifyID");
- ICustomer OldCust = this.LoadCustomer(Customer.ChargifyID);
+ if (customer == null) throw new ArgumentNullException(nameof(customer));
+ if (customer.ChargifyID == int.MinValue) throw new ArgumentException("Invalid chargify ID detected", nameof(customer));
+ ICustomer oldCust = LoadCustomer(customer.ChargifyID);
bool isUpdateRequired = false;
// create XML for creation of customer
- var customerXml = new StringBuilder(GetXMLStringIfApplicable());
+ var customerXml = new StringBuilder(GetXmlStringIfApplicable());
customerXml.Append("");
- if (OldCust != null)
- {
- if (OldCust.ChargifyID != Customer.ChargifyID) throw new ArgumentException("Not unique", "Customer.SystemID");
- if (OldCust.FirstName != Customer.FirstName) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.FirstName)); isUpdateRequired = true; }
- if (OldCust.LastName != Customer.LastName) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.LastName)); isUpdateRequired = true; }
- if (OldCust.Email != Customer.Email) { customerXml.AppendFormat("{0}", Customer.Email); isUpdateRequired = true; }
- if (OldCust.Organization != Customer.Organization) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.Organization)); isUpdateRequired = true; }
- if (OldCust.Phone != Customer.Phone) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.Phone)); isUpdateRequired = true; }
- if (OldCust.SystemID != Customer.SystemID) { customerXml.AppendFormat("{0}", Customer.SystemID); isUpdateRequired = true; }
- if (OldCust.ShippingAddress != Customer.ShippingAddress) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.ShippingAddress)); isUpdateRequired = true; }
- if (OldCust.ShippingAddress2 != Customer.ShippingAddress2) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.ShippingAddress2)); isUpdateRequired = true; }
- if (OldCust.ShippingCity != Customer.ShippingCity) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.ShippingCity)); isUpdateRequired = true; }
- if (OldCust.ShippingState != Customer.ShippingState) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.ShippingState)); isUpdateRequired = true; }
- if (OldCust.ShippingZip != Customer.ShippingZip) { customerXml.AppendFormat("{0}", Customer.ShippingZip); isUpdateRequired = true; }
- if (OldCust.ShippingCountry != Customer.ShippingCountry) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Customer.ShippingCountry)); isUpdateRequired = true; }
+ if (oldCust != null)
+ {
+ if (oldCust.ChargifyID != customer.ChargifyID) throw new ArgumentException("System ID is not unique", nameof(customer));
+ if (oldCust.FirstName != customer.FirstName) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.FirstName)); isUpdateRequired = true; }
+ if (oldCust.LastName != customer.LastName) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.LastName)); isUpdateRequired = true; }
+ if (oldCust.Email != customer.Email) { customerXml.AppendFormat("{0}", customer.Email); isUpdateRequired = true; }
+ if (oldCust.Organization != customer.Organization) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.Organization)); isUpdateRequired = true; }
+ if (oldCust.Phone != customer.Phone) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.Phone)); isUpdateRequired = true; }
+ if (oldCust.SystemID != customer.SystemID) { customerXml.AppendFormat("{0}", customer.SystemID); isUpdateRequired = true; }
+ if (oldCust.ShippingAddress != customer.ShippingAddress) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.ShippingAddress)); isUpdateRequired = true; }
+ if (oldCust.ShippingAddress2 != customer.ShippingAddress2) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.ShippingAddress2)); isUpdateRequired = true; }
+ if (oldCust.ShippingCity != customer.ShippingCity) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.ShippingCity)); isUpdateRequired = true; }
+ if (oldCust.ShippingState != customer.ShippingState) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.ShippingState)); isUpdateRequired = true; }
+ if (oldCust.ShippingZip != customer.ShippingZip) { customerXml.AppendFormat("{0}", customer.ShippingZip); isUpdateRequired = true; }
+ if (oldCust.ShippingCountry != customer.ShippingCountry) { customerXml.AppendFormat("{0}", HttpUtility.HtmlEncode(customer.ShippingCountry)); isUpdateRequired = true; }
}
customerXml.Append("");
@@ -617,7 +611,7 @@ public ICustomer UpdateCustomer(ICustomer Customer)
try
{
// now make the request
- string response = this.DoRequest(string.Format("customers/{0}.{1}", Customer.ChargifyID, GetMethodExtension()), HttpRequestMethod.Put, customerXml.ToString());
+ string response = DoRequest(string.Format("customers/{0}.{1}", customer.ChargifyID, GetMethodExtension()), HttpRequestMethod.Put, customerXml.ToString());
// change the response to the object
return response.ConvertResponseTo("customer");
}
@@ -629,41 +623,41 @@ public ICustomer UpdateCustomer(ICustomer Customer)
}
else
{
- return Customer;
+ return customer;
}
}
///
/// Get a list of customers (will return 50 for each page)
///
- /// The page number to load
+ /// The page number to load
/// A list of customers for the specified page
- public IDictionary GetCustomerList(int PageNumber)
+ public IDictionary GetCustomerList(int pageNumber)
{
- return GetCustomerList(PageNumber, false);
+ return GetCustomerList(pageNumber, false);
}
///
/// Get a list of customers (will return 50 for each page)
///
- /// The page number to load
- /// If true, the dictionary will be keyed by Chargify ID and not the reference value.
+ /// The page number to load
+ /// If true, the dictionary will be keyed by Chargify ID and not the reference value.
/// A list of customers for the specified page
- public IDictionary GetCustomerList(int PageNumber, bool keyByChargifyID)
+ public IDictionary GetCustomerList(int pageNumber, bool keyByChargifyId)
{
// make sure data is valid
- if (PageNumber < 1) throw new ArgumentException("Page number must be greater than 1", "PageNumber");
+ if (pageNumber < 1) throw new ArgumentException("Page number must be greater than 1", "pageNumber");
// now make the request
- string response = this.DoRequest(string.Format("customers.{0}?page={1}", GetMethodExtension(), PageNumber));
+ string response = DoRequest(string.Format("customers.{0}?page={1}", GetMethodExtension(), pageNumber));
var retValue = new Dictionary();
if (response.IsXml())
{
// now build customer object based on response as XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response); // get the XML into an XML document
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response); // get the XML into an XML document
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "customers")
{
@@ -671,11 +665,11 @@ public IDictionary GetCustomerList(int PageNumber, bool keyBy
{
if (customerNode.Name == "customer")
{
- ICustomer LoadedCustomer = new Customer(customerNode);
- string key = keyByChargifyID ? LoadedCustomer.ChargifyID.ToString() : LoadedCustomer.SystemID;
+ ICustomer loadedCustomer = new Customer(customerNode);
+ string key = keyByChargifyId ? loadedCustomer.ChargifyID.ToString() : loadedCustomer.SystemID;
if (!retValue.ContainsKey(key))
{
- retValue.Add(key, LoadedCustomer);
+ retValue.Add(key, loadedCustomer);
}
else
{
@@ -693,14 +687,15 @@ public IDictionary GetCustomerList(int PageNumber, bool keyBy
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("customer"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("customer"))
{
JsonObject customerObj = (array.Items[i] as JsonObject)["customer"] as JsonObject;
- ICustomer LoadedCustomer = new Customer(customerObj);
- string key = keyByChargifyID ? LoadedCustomer.ChargifyID.ToString() : LoadedCustomer.SystemID;
+ ICustomer loadedCustomer = new Customer(customerObj);
+ string key = keyByChargifyId ? loadedCustomer.ChargifyID.ToString() : loadedCustomer.SystemID;
if (!retValue.ContainsKey(key))
{
- retValue.Add(key, LoadedCustomer);
+ retValue.Add(key, loadedCustomer);
}
else
{
@@ -727,18 +722,18 @@ public IDictionary GetCustomerList()
/// Get a list of all customers. Be careful calling this method because a large number of
/// customers will result in multiple calls to Chargify
///
- /// If true, the key will be the ChargifyID, otherwise it will be the reference value
+ /// If true, the key will be the ChargifyID, otherwise it will be the reference value
/// A list of customers
- public IDictionary GetCustomerList(bool keyByChargifyID)
+ public IDictionary GetCustomerList(bool keyByChargifyId)
{
var retValue = new Dictionary();
- int PageCount = 1000;
- for (int Page = 1; PageCount > 0; Page++)
+ int pageCount = 1000;
+ for (int page = 1; pageCount > 0; page++)
{
- IDictionary PageList = GetCustomerList(Page, keyByChargifyID);
- foreach (ICustomer cust in PageList.Values)
+ IDictionary pageList = GetCustomerList(page, keyByChargifyId);
+ foreach (ICustomer cust in pageList.Values)
{
- string key = keyByChargifyID ? cust.ChargifyID.ToString() : cust.SystemID;
+ string key = keyByChargifyId ? cust.ChargifyID.ToString() : cust.SystemID;
if (!retValue.ContainsKey(key))
{
retValue.Add(key, cust);
@@ -748,7 +743,7 @@ public IDictionary GetCustomerList(bool keyByChargifyID)
//throw new InvalidOperationException("Duplicate key values detected");
}
}
- PageCount = PageList.Count;
+ pageCount = pageList.Count;
}
return retValue;
}
@@ -756,18 +751,18 @@ public IDictionary GetCustomerList(bool keyByChargifyID)
///
/// Delete the specified customer
///
- /// The integer identifier of the customer
+ /// The integer identifier of the customer
/// True if the customer was deleted, false otherwise.
/// This method does not currently work, but it will once they open up the API. This will always return false, as Chargify will send a Http Forbidden everytime.
- public bool DeleteCustomer(int ChargifyID)
+ public bool DeleteCustomer(int chargifyId)
{
try
{
// make sure data is valid
- if (ChargifyID < 0) throw new ArgumentNullException("ChargifyID");
+ if (chargifyId < 0) throw new ArgumentNullException("chargifyId");
// now make the request
- this.DoRequest(string.Format("customers/{0}.{1}", ChargifyID, GetMethodExtension()), HttpRequestMethod.Delete, string.Empty);
+ DoRequest(string.Format("customers/{0}.{1}", chargifyId, GetMethodExtension()), HttpRequestMethod.Delete, string.Empty);
return true;
}
catch (ChargifyException cex)
@@ -786,21 +781,21 @@ public bool DeleteCustomer(int ChargifyID)
///
/// Delete the specified customer
///
- /// The system identifier of the customer.
+ /// The system identifier of the customer.
/// True if the customer was deleted, false otherwise.
/// This method does not currently work, but it will once they open up the API. This will always return false, as Chargify will send a Http Forbidden everytime.
- public bool DeleteCustomer(string SystemID)
+ public bool DeleteCustomer(string systemId)
{
try
{
// make sure data is valid
- if (SystemID == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "SystemID");
+ if (systemId == string.Empty) throw new ArgumentException("Empty SystemID not allowed", "systemId");
- ICustomer customer = LoadCustomer(SystemID);
- if (customer == null) { throw new ArgumentException("Not a known customer", "SystemID"); }
+ ICustomer customer = LoadCustomer(systemId);
+ if (customer == null) { throw new ArgumentException("Not a known customer", "systemId"); }
// now make the request
- this.DoRequest(string.Format("customers/{0}.{1}", customer.ChargifyID, GetMethodExtension()), HttpRequestMethod.Delete, string.Empty);
+ DoRequest(string.Format("customers/{0}.{1}", customer.ChargifyID, GetMethodExtension()), HttpRequestMethod.Delete, string.Empty);
return true;
}
catch (ChargifyException cex)
@@ -822,29 +817,30 @@ public bool DeleteCustomer(string SystemID)
///
/// Method that updates a product
///
- /// The ID of the product to update
- /// The details of the updated product
+ /// The ID of the product to update
+ /// The details of the updated product
/// The updated product
- public IProduct UpdateProduct(int ProductID, IProduct UpdatedProduct)
- {
- var ExistingProduct = LoadProduct(ProductID.ToString(), false);
- if (ExistingProduct == null) throw new ArgumentException(string.Format("No product with ID {0} exists.", ProductID));
- if (UpdatedProduct == null) throw new ArgumentNullException("Coupon");
- if (UpdatedProduct.ProductFamily.ID <= 0) throw new ArgumentOutOfRangeException("Product's ProductFamily-> ID must be > 0");
- if (ProductID <= 0) throw new ArgumentOutOfRangeException("ProductID is not valid");
-
- var ProductXML = new StringBuilder(GetXMLStringIfApplicable());
- ProductXML.Append("");
- if (!string.IsNullOrWhiteSpace(UpdatedProduct.Name) && ExistingProduct.Name != UpdatedProduct.Name) ProductXML.AppendFormat("{0}", HttpUtility.HtmlEncode(UpdatedProduct.Name));
- if (UpdatedProduct.PriceInCents != int.MinValue && ExistingProduct.PriceInCents != UpdatedProduct.PriceInCents) ProductXML.AppendFormat("{0}", UpdatedProduct.PriceInCents);
- if (UpdatedProduct.Interval != int.MinValue && ExistingProduct.Interval != UpdatedProduct.Interval) ProductXML.AppendFormat("{0}", UpdatedProduct.Interval);
- ProductXML.AppendFormat("{0}", Enum.GetName(typeof(IntervalUnit), UpdatedProduct.IntervalUnit).ToLowerInvariant());
- if (!string.IsNullOrEmpty(UpdatedProduct.Handle) && ExistingProduct.Handle != UpdatedProduct.Handle) ProductXML.AppendFormat("{0}", UpdatedProduct.Handle);
- if (!string.IsNullOrEmpty(UpdatedProduct.AccountingCode) && ExistingProduct.AccountingCode != UpdatedProduct.AccountingCode) ProductXML.AppendFormat("{0}", UpdatedProduct.AccountingCode);
- if (!string.IsNullOrEmpty(UpdatedProduct.Description) && ExistingProduct.Description != UpdatedProduct.Description) ProductXML.AppendFormat("{0}", HttpUtility.HtmlEncode(UpdatedProduct.Description));
- ProductXML.Append("");
-
- string response = this.DoRequest(string.Format("products/{0}.{1}", ProductID, GetMethodExtension()), HttpRequestMethod.Put, ProductXML.ToString());
+ public IProduct UpdateProduct(int productId, IProduct updatedProduct)
+ {
+ var existingProduct = LoadProduct(productId.ToString(), false);
+ if (existingProduct == null) throw new ArgumentException(string.Format("No product with ID {0} exists.", productId));
+ if (updatedProduct == null) throw new ArgumentNullException(nameof(updatedProduct));
+ if (updatedProduct.ProductFamily.ID <= 0) throw new ArgumentOutOfRangeException(nameof(updatedProduct), "Product's ProductFamily-> ID must be > 0");
+ if (productId <= 0) throw new ArgumentOutOfRangeException(nameof(updatedProduct), "ProductID is not valid");
+
+ var productXml = new StringBuilder(GetXmlStringIfApplicable());
+ productXml.Append("");
+ if (!string.IsNullOrWhiteSpace(updatedProduct.Name) && existingProduct.Name != updatedProduct.Name) productXml.AppendFormat("{0}", HttpUtility.HtmlEncode(updatedProduct.Name));
+ if (updatedProduct.PriceInCents != int.MinValue && existingProduct.PriceInCents != updatedProduct.PriceInCents) productXml.AppendFormat("{0}", updatedProduct.PriceInCents);
+ if (updatedProduct.Interval != int.MinValue && existingProduct.Interval != updatedProduct.Interval) productXml.AppendFormat("{0}", updatedProduct.Interval);
+ var intervalUnit = Enum.GetName(typeof(IntervalUnit), updatedProduct.IntervalUnit);
+ if (intervalUnit != null) productXml.AppendFormat("{0}", intervalUnit.ToLowerInvariant());
+ if (!string.IsNullOrEmpty(updatedProduct.Handle) && existingProduct.Handle != updatedProduct.Handle) productXml.AppendFormat("{0}", updatedProduct.Handle);
+ if (!string.IsNullOrEmpty(updatedProduct.AccountingCode) && existingProduct.AccountingCode != updatedProduct.AccountingCode) productXml.AppendFormat("{0}", updatedProduct.AccountingCode);
+ if (!string.IsNullOrEmpty(updatedProduct.Description) && existingProduct.Description != updatedProduct.Description) productXml.AppendFormat("{0}", HttpUtility.HtmlEncode(updatedProduct.Description));
+ productXml.Append("");
+
+ string response = DoRequest(string.Format("products/{0}.{1}", productId, GetMethodExtension()), HttpRequestMethod.Put, productXml.ToString());
// change the response to the object
return response.ConvertResponseTo("product");
}
@@ -852,45 +848,47 @@ public IProduct UpdateProduct(int ProductID, IProduct UpdatedProduct)
///
/// Method to create a new product and add it to the site
///
- /// The product family ID, required for adding products
- /// The new product details
+ /// The product family ID, required for adding products
+ /// The new product details
/// The completed product information
/// This is largely undocumented currently, especially the fact that you need the product family ID
- public IProduct CreateProduct(int ProductFamilyID, IProduct NewProduct)
+ public IProduct CreateProduct(int productFamilyId, IProduct newProduct)
{
- if (NewProduct == null) throw new ArgumentNullException("NewProduct");
- return CreateProduct(ProductFamilyID, NewProduct.Name, NewProduct.Handle, NewProduct.PriceInCents, NewProduct.Interval, NewProduct.IntervalUnit, NewProduct.AccountingCode, NewProduct.Description);
+ if (newProduct == null) throw new ArgumentNullException("newProduct");
+ return CreateProduct(productFamilyId, newProduct.Name, newProduct.Handle, newProduct.PriceInCents, newProduct.Interval, newProduct.IntervalUnit, newProduct.AccountingCode, newProduct.Description);
}
///
/// Allows the creation of a product
///
- /// The family to which this product belongs
- /// The name of the product
- /// The handle to be used for this product
- /// The price (in cents)
- /// The time interval used to determine the recurring nature of this product
- /// Either days, or months
- /// The accounting code used for this product
- /// The product description
+ /// The family to which this product belongs
+ /// The name of the product
+ /// The handle to be used for this product
+ /// The price (in cents)
+ /// The time interval used to determine the recurring nature of this product
+ /// Either days, or months
+ /// The accounting code used for this product
+ /// The product description
/// The created product
- public IProduct CreateProduct(int ProductFamilyID, string Name, string Handle, int PriceInCents, int Interval, IntervalUnit IntervalUnit, string AccountingCode, string Description)
+ public IProduct CreateProduct(int productFamilyId, string name, string handle, int priceInCents, int interval, IntervalUnit intervalUnit, string accountingCode, string description)
{
// make sure data is valid
- if (string.IsNullOrEmpty(Name)) throw new ArgumentNullException("Name");
+ if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));
// create XML for creation of the new product
- var ProductXML = new StringBuilder(GetXMLStringIfApplicable());
- ProductXML.Append("");
- ProductXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Name));
- ProductXML.AppendFormat("{0}", PriceInCents);
- ProductXML.AppendFormat("{0}", Interval);
- ProductXML.AppendFormat("{0}", Enum.GetName(typeof(IntervalUnit), IntervalUnit).ToLowerInvariant());
- if (!string.IsNullOrEmpty(Handle)) ProductXML.AppendFormat("{0}", Handle);
- if (!string.IsNullOrEmpty(AccountingCode)) ProductXML.AppendFormat("{0}", AccountingCode);
- if (!string.IsNullOrEmpty(Description)) ProductXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Description));
- ProductXML.Append("");
+ var productXml = new StringBuilder(GetXmlStringIfApplicable());
+ productXml.Append("");
+ productXml.AppendFormat("{0}", HttpUtility.HtmlEncode(name));
+ productXml.AppendFormat("{0}", priceInCents);
+ productXml.AppendFormat("{0}", interval);
+ var intervalUnitName = Enum.GetName(typeof(IntervalUnit), intervalUnit);
+ if (intervalUnitName != null)
+ productXml.AppendFormat("{0}", intervalUnitName.ToLowerInvariant());
+ if (!string.IsNullOrEmpty(handle)) productXml.AppendFormat("{0}", handle);
+ if (!string.IsNullOrEmpty(accountingCode)) productXml.AppendFormat("{0}", accountingCode);
+ if (!string.IsNullOrEmpty(description)) productXml.AppendFormat("{0}", HttpUtility.HtmlEncode(description));
+ productXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("product_families/{0}/products.{1}", ProductFamilyID, GetMethodExtension()), HttpRequestMethod.Post, ProductXML.ToString());
+ string response = DoRequest(string.Format("product_families/{0}/products.{1}", productFamilyId, GetMethodExtension()), HttpRequestMethod.Post, productXml.ToString());
// change the response to the object
return response.ConvertResponseTo("product");
}
@@ -898,34 +896,34 @@ public IProduct CreateProduct(int ProductFamilyID, string Name, string Handle, i
///
/// Load the requested product from chargify by its handle
///
- /// The Chargify ID or handle of the product
+ /// The Chargify ID or handle of the product
/// The product with the specified chargify ID
- public IProduct LoadProduct(string Handle)
+ public IProduct LoadProduct(string handle)
{
- return LoadProduct(Handle, true);
+ return LoadProduct(handle, true);
}
///
/// Load the requested product from chargify
///
- /// The Chargify ID or handle of the product
- /// If true, then the ProductID represents the handle, if false the ProductID represents the Chargify ID
+ /// The Chargify ID or handle of the product
+ /// If true, then the ProductID represents the handle, if false the ProductID represents the Chargify ID
/// The product with the specified chargify ID
- public IProduct LoadProduct(string ProductID, bool IsHandle)
+ public IProduct LoadProduct(string productId, bool isHandle)
{
try
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductID)) throw new ArgumentNullException("ProductID");
+ if (string.IsNullOrEmpty(productId)) throw new ArgumentNullException("productId");
// now make the request
string response;
- if (IsHandle)
+ if (isHandle)
{
- response = this.DoRequest(string.Format("products/handle/{0}.{1}", ProductID, GetMethodExtension()));
+ response = DoRequest(string.Format("products/handle/{0}.{1}", productId, GetMethodExtension()));
}
else
{
- response = this.DoRequest(string.Format("products/{0}.{1}", ProductID, GetMethodExtension()));
+ response = DoRequest(string.Format("products/{0}.{1}", productId, GetMethodExtension()));
}
// Convert the Chargify response into the object we're looking for
return response.ConvertResponseTo("product");
@@ -944,17 +942,17 @@ public IProduct LoadProduct(string ProductID, bool IsHandle)
public IDictionary GetProductList()
{
// now make the request
- string response = this.DoRequest(string.Format("products.{0}", GetMethodExtension()));
+ string response = DoRequest(string.Format("products.{0}", GetMethodExtension()));
// loop through the child nodes of this node
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a product list based on response XML
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "products")
{
@@ -962,10 +960,10 @@ public IDictionary GetProductList()
{
if (productNode.Name == "product")
{
- IProduct LoadedProduct = new Product(productNode);
- if (!retValue.ContainsKey(LoadedProduct.ID))
+ IProduct loadedProduct = new Product(productNode);
+ if (!retValue.ContainsKey(loadedProduct.ID))
{
- retValue.Add(LoadedProduct.ID, LoadedProduct);
+ retValue.Add(loadedProduct.ID, loadedProduct);
}
else
{
@@ -983,13 +981,14 @@ public IDictionary GetProductList()
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("product"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("product"))
{
JsonObject productObj = (array.Items[i] as JsonObject)["product"] as JsonObject;
- IProduct LoadedProduct = new Product(productObj);
- if (!retValue.ContainsKey(LoadedProduct.ID))
+ IProduct loadedProduct = new Product(productObj);
+ if (!retValue.ContainsKey(loadedProduct.ID))
{
- retValue.Add(LoadedProduct.ID, LoadedProduct);
+ retValue.Add(loadedProduct.ID, loadedProduct);
}
else
{
@@ -1013,18 +1012,18 @@ public IDictionary GetProductList()
public IProductFamily CreateProductFamily(IProductFamily newFamily)
{
// make sure data is valid
- if (newFamily == null) throw new ArgumentNullException("newFamily");
- if (string.IsNullOrEmpty(newFamily.Name)) throw new ArgumentNullException("Name");
+ if (newFamily == null) throw new ArgumentNullException(nameof(newFamily));
+ if (string.IsNullOrEmpty(newFamily.Name)) throw new ArgumentNullException(nameof(newFamily), "The product family name is blank, but required.");
// create XML for creation of the new product family
- var ProductFamilyXML = new StringBuilder(GetXMLStringIfApplicable());
- ProductFamilyXML.Append("");
- ProductFamilyXML.AppendFormat("{0}", HttpUtility.HtmlEncode(newFamily.Name));
- if (!string.IsNullOrEmpty(newFamily.Handle)) ProductFamilyXML.AppendFormat("{0}", newFamily.Handle);
- if (!string.IsNullOrEmpty(newFamily.AccountingCode)) ProductFamilyXML.AppendFormat("{0}", HttpUtility.HtmlEncode(newFamily.AccountingCode));
- if (!string.IsNullOrEmpty(newFamily.Description)) ProductFamilyXML.AppendFormat("{0}", HttpUtility.HtmlEncode(newFamily.Description));
- ProductFamilyXML.Append("");
+ var productFamilyXml = new StringBuilder(GetXmlStringIfApplicable());
+ productFamilyXml.Append("");
+ productFamilyXml.AppendFormat("{0}", HttpUtility.HtmlEncode(newFamily.Name));
+ if (!string.IsNullOrEmpty(newFamily.Handle)) productFamilyXml.AppendFormat("{0}", newFamily.Handle);
+ if (!string.IsNullOrEmpty(newFamily.AccountingCode)) productFamilyXml.AppendFormat("{0}", HttpUtility.HtmlEncode(newFamily.AccountingCode));
+ if (!string.IsNullOrEmpty(newFamily.Description)) productFamilyXml.AppendFormat("{0}", HttpUtility.HtmlEncode(newFamily.Description));
+ productFamilyXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("product_families.{0}", GetMethodExtension()), HttpRequestMethod.Post, ProductFamilyXML.ToString());
+ string response = DoRequest(string.Format("product_families.{0}", GetMethodExtension()), HttpRequestMethod.Post, productFamilyXml.ToString());
// change the response to the object
return response.ConvertResponseTo("product_family");
}
@@ -1036,17 +1035,17 @@ public IProductFamily CreateProductFamily(IProductFamily newFamily)
public IDictionary GetProductFamilyList()
{
// now make the request
- string response = this.DoRequest(string.Format("product_families.{0}", GetMethodExtension()));
+ string response = DoRequest(string.Format("product_families.{0}", GetMethodExtension()));
// loop through the child nodes of this node
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a product family list based on response XML
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "product_families")
{
@@ -1054,10 +1053,10 @@ public IDictionary GetProductFamilyList()
{
if (productFamilyNode.Name == "product_family")
{
- IProductFamily LoadedProductFamily = new ProductFamily(productFamilyNode);
- if (!retValue.ContainsKey(LoadedProductFamily.ID))
+ IProductFamily loadedProductFamily = new ProductFamily(productFamilyNode);
+ if (!retValue.ContainsKey(loadedProductFamily.ID))
{
- retValue.Add(LoadedProductFamily.ID, LoadedProductFamily);
+ retValue.Add(loadedProductFamily.ID, loadedProductFamily);
}
else
{
@@ -1075,13 +1074,14 @@ public IDictionary GetProductFamilyList()
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("product_family"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("product_family"))
{
JsonObject productFamilyObj = (array.Items[i] as JsonObject)["product_family"] as JsonObject;
- IProductFamily LoadedProductFamily = new ProductFamily(productFamilyObj);
- if (!retValue.ContainsKey(LoadedProductFamily.ID))
+ IProductFamily loadedProductFamily = new ProductFamily(productFamilyObj);
+ if (!retValue.ContainsKey(loadedProductFamily.ID))
{
- retValue.Add(LoadedProductFamily.ID, LoadedProductFamily);
+ retValue.Add(loadedProductFamily.ID, loadedProductFamily);
}
else
{
@@ -1097,44 +1097,44 @@ public IDictionary GetProductFamilyList()
///
/// Load the requested product family from chargify by its handle
///
- /// The Chargify ID or handle of the product
+ /// The Chargify ID or handle of the product
/// The product family with the specified chargify ID
- public IProductFamily LoadProductFamily(string Handle)
+ public IProductFamily LoadProductFamily(string handle)
{
- return LoadProductFamily(Handle, true);
+ return LoadProductFamily(handle, true);
}
///
/// Load the requested product family from chargify by its handle
///
- /// The Chargify ID of the product
+ /// The Chargify ID of the product
/// The product family with the specified chargify ID
- public IProductFamily LoadProductFamily(int ID)
+ public IProductFamily LoadProductFamily(int id)
{
- return LoadProductFamily(ID.ToString(), false);
+ return LoadProductFamily(id.ToString(), false);
}
///
/// Load the requested product family from chargify
///
- /// The Chargify identifier (ID or handle) of the product family
- /// If true, then the ProductID represents the handle, if false the ProductFamilyID represents the Chargify ID
+ /// The Chargify identifier (ID or handle) of the product family
+ /// If true, then the ProductID represents the handle, if false the ProductFamilyID represents the Chargify ID
/// The product family with the specified chargify ID
- private IProductFamily LoadProductFamily(string ProductFamilyIdentifier, bool IsHandle)
+ private IProductFamily LoadProductFamily(string productFamilyIdentifier, bool isHandle)
{
try
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductFamilyIdentifier)) throw new ArgumentNullException("ProductFamilyID");
+ if (string.IsNullOrEmpty(productFamilyIdentifier)) throw new ArgumentNullException(nameof(productFamilyIdentifier));
// now make the request
string response;
- if (IsHandle)
+ if (isHandle)
{
- response = this.DoRequest(string.Format("product_families/lookup.{0}?handle={1}", GetMethodExtension(), ProductFamilyIdentifier));
+ response = DoRequest(string.Format("product_families/lookup.{0}?handle={1}", GetMethodExtension(), productFamilyIdentifier));
}
else
{
- response = this.DoRequest(string.Format("product_families/{0}.{1}", ProductFamilyIdentifier, GetMethodExtension()));
+ response = DoRequest(string.Format("product_families/{0}.{1}", productFamilyIdentifier, GetMethodExtension()));
}
// Convert the Chargify response into the object we're looking for
return response.ConvertResponseTo("product_family");
@@ -1152,39 +1152,39 @@ private IProductFamily LoadProductFamily(string ProductFamilyIdentifier, bool Is
///
/// Method to get the secure URL (with pretty id) for updating the payment details for a subscription.
///
- /// The first name of the customer to add to the pretty url
- /// The last name of the customer to add to the pretty url
- /// The ID of the subscription to update
+ /// The first name of the customer to add to the pretty url
+ /// The last name of the customer to add to the pretty url
+ /// The ID of the subscription to update
/// The secure url of the update page
- public string GetPrettySubscriptionUpdateURL(string FirstName, string LastName, int SubscriptionID)
+ public string GetPrettySubscriptionUpdateURL(string firstName, string lastName, int subscriptionId)
{
- if (string.IsNullOrEmpty(this.SharedKey)) throw new ArgumentException("SharedKey is required to generate the hosted page url");
+ if (string.IsNullOrEmpty(SharedKey)) throw new ArgumentException("SharedKey is required to generate the hosted page url");
- string message = UpdateShortName + "--" + SubscriptionID + "--" + SharedKey;
+ string message = UpdateShortName + "--" + subscriptionId + "--" + SharedKey;
string token = message.GetChargifyHostedToken();
- string prettyID = string.Format("{0}-{1}-{2}", SubscriptionID, FirstName.Trim().ToLower(), LastName.Trim().ToLower());
- string methodString = string.Format("{0}/{1}/{2}", UpdateShortName, prettyID, token);
+ string prettyId = string.Format("{0}-{1}-{2}", subscriptionId, firstName.Trim().ToLower(), lastName.Trim().ToLower());
+ string methodString = string.Format("{0}/{1}/{2}", UpdateShortName, prettyId, token);
// just in case?
methodString = HttpUtility.UrlEncode(methodString);
- string updateUrl = string.Format("{0}{1}{2}", this.URL, (this.URL.EndsWith("/") ? "" : "/"), methodString);
+ string updateUrl = string.Format("{0}{1}{2}", URL, (URL.EndsWith("/") ? "" : "/"), methodString);
return updateUrl;
}
///
/// Method to get the secure URL for updating the payment details for a subscription.
///
- /// The ID of the subscription to update
+ /// The ID of the subscription to update
/// The secure url of the update page
- public string GetSubscriptionUpdateURL(int SubscriptionID)
+ public string GetSubscriptionUpdateURL(int subscriptionId)
{
- if (string.IsNullOrEmpty(this.SharedKey)) throw new ArgumentException("SharedKey is required to generate the hosted page url");
+ if (string.IsNullOrEmpty(SharedKey)) throw new ArgumentException("SharedKey is required to generate the hosted page url");
- string message = UpdateShortName + "--" + SubscriptionID + "--" + SharedKey;
+ string message = UpdateShortName + "--" + subscriptionId + "--" + SharedKey;
string token = message.GetChargifyHostedToken();
- string methodString = string.Format("{0}/{1}/{2}", UpdateShortName, SubscriptionID, token);
+ string methodString = string.Format("{0}/{1}/{2}", UpdateShortName, subscriptionId, token);
methodString = HttpUtility.UrlEncode(methodString);
- string updateURL = string.Format("{0}{1}{2}", this.URL, (this.URL.EndsWith("/") ? "" : "/"), methodString);
- return updateURL;
+ string updateUrl = string.Format("{0}{1}{2}", URL, (URL.EndsWith("/") ? "" : "/"), methodString);
+ return updateUrl;
}
///
@@ -1192,13 +1192,13 @@ public string GetSubscriptionUpdateURL(int SubscriptionID)
/// on how reactivation works, and how to reactivate subscriptions through the Admin interface, see
/// http://support.chargify.com/faqs/features/reactivation
///
- /// The ID of the subscription to reactivate
+ /// The ID of the subscription to reactivate
/// The newly reactivated subscription, or nothing.
- public ISubscription ReactivateSubscription(int SubscriptionID)
+ public ISubscription ReactivateSubscription(int subscriptionId)
{
try
{
- return ReactivateSubscription(SubscriptionID, false);
+ return ReactivateSubscription(subscriptionId, false);
}
catch (ChargifyException cex)
{
@@ -1212,12 +1212,12 @@ public ISubscription ReactivateSubscription(int SubscriptionID)
/// on how reactivation works, and how to reactivate subscriptions through the Admin interface, see
/// http://support.chargify.com/faqs/features/reactivation
///
- /// The ID of the subscription to reactivate
+ /// The ID of the subscription to reactivate
/// If true, the reactivated subscription will include a trial if one is available.
/// The newly reactivated subscription, or nothing.
- public ISubscription ReactivateSubscription(int SubscriptionID, bool includeTrial)
+ public ISubscription ReactivateSubscription(int subscriptionId, bool includeTrial)
{
- return ReactivateSubscription(SubscriptionID, includeTrial, null, null);
+ return ReactivateSubscription(subscriptionId, includeTrial, null, null);
}
///
@@ -1225,18 +1225,18 @@ public ISubscription ReactivateSubscription(int SubscriptionID, bool includeTria
/// on how reactivation works, and how to reactivate subscriptions through the Admin interface, see
/// http://support.chargify.com/faqs/features/reactivation
///
- /// The ID of the subscription to reactivate
+ /// The ID of the subscription to reactivate
/// If true, the reactivated subscription will include a trial if one is available.
/// If true, the existing subscription balance will NOT be cleared/reset before adding the additional reactivation charges.
/// The coupon code to be applied during reactivation.
/// The newly reactivated subscription, or nothing.
- public ISubscription ReactivateSubscription(int SubscriptionID, bool includeTrial, bool? preserveBalance, string couponCode)
+ public ISubscription ReactivateSubscription(int subscriptionId, bool includeTrial, bool? preserveBalance, string couponCode)
{
try
{
// make sure data is valid
- if (SubscriptionID < 0) throw new ArgumentNullException("SubscriptionID");
- string requestString = string.Format("subscriptions/{0}/reactivate.{1}", SubscriptionID, GetMethodExtension());
+ if (subscriptionId < 0) throw new ArgumentNullException("subscriptionId");
+ string requestString = string.Format("subscriptions/{0}/reactivate.{1}", subscriptionId, GetMethodExtension());
StringBuilder queryString = new StringBuilder();
@@ -1256,10 +1256,10 @@ public ISubscription ReactivateSubscription(int SubscriptionID, bool includeTria
}
// Append the query string to the request, if applicable.
- if (queryString.Length > 0) requestString += "?" + queryString.ToString();
+ if (queryString.Length > 0) requestString += "?" + queryString;
// now make the request
- string response = this.DoRequest(requestString, HttpRequestMethod.Put, string.Empty);
+ string response = DoRequest(requestString, HttpRequestMethod.Put, string.Empty);
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -1273,27 +1273,27 @@ public ISubscription ReactivateSubscription(int SubscriptionID, bool includeTria
///
/// Delete a subscription
///
- /// The ID of the sucscription
- /// The message to associate with the subscription
+ /// The ID of the sucscription
+ /// The message to associate with the subscription
///
- public bool DeleteSubscription(int SubscriptionID, string CancellationMessage)
+ public bool DeleteSubscription(int subscriptionId, string cancellationMessage)
{
try
{
// make sure data is valid
- if (SubscriptionID < 0) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId < 0) throw new ArgumentNullException("subscriptionId");
- StringBuilder SubscriptionXML = new StringBuilder("");
- if (!string.IsNullOrEmpty(CancellationMessage))
+ StringBuilder subscriptionXml = new StringBuilder("");
+ if (!string.IsNullOrEmpty(cancellationMessage))
{
// create XML for creation of customer
- SubscriptionXML = new StringBuilder(GetXMLStringIfApplicable());
- SubscriptionXML.Append("");
- SubscriptionXML.AppendFormat("{0}", CancellationMessage);
- SubscriptionXML.Append("");
+ subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
+ subscriptionXml.Append("");
+ subscriptionXml.AppendFormat("{0}", cancellationMessage);
+ subscriptionXml.Append("");
}
// now make the request
- this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Delete, SubscriptionXML.ToString());
+ DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Delete, subscriptionXml.ToString());
return true;
}
catch (ChargifyException cex)
@@ -1306,16 +1306,16 @@ public bool DeleteSubscription(int SubscriptionID, string CancellationMessage)
///
/// Load the requested customer from chargify
///
- /// The ID of the subscription
+ /// The ID of the subscription
/// The subscription with the specified ID
- public ISubscription LoadSubscription(int SubscriptionID)
+ public ISubscription LoadSubscription(int subscriptionId)
{
try
{
// make sure data is valid
- if (SubscriptionID < 0) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId < 0) throw new ArgumentNullException("subscriptionId");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()));
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()));
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -1350,17 +1350,17 @@ public IDictionary GetSubscriptionList(List();
if (response.IsXml())
{
// now build a transaction list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "subscriptions")
{
@@ -1368,10 +1368,10 @@ public IDictionary GetSubscriptionList(List GetSubscriptionList(List GetSubscriptionList(List GetSubscriptionList()
{
var retValue = new Dictionary();
- int PageCount = 1000;
- for (int Page = 1; PageCount > 0; Page++)
+ int pageCount = 1000;
+ for (int page = 1; pageCount > 0; page++)
{
- IDictionary PageList = GetSubscriptionList(Page, 50);
- foreach (ISubscription subscription in PageList.Values)
+ IDictionary pageList = GetSubscriptionList(page, 50);
+ foreach (ISubscription subscription in pageList.Values)
{
if (!retValue.ContainsKey(subscription.SubscriptionID))
{
@@ -1430,7 +1431,7 @@ public IDictionary GetSubscriptionList()
throw new InvalidOperationException("Duplicate subscriptionID values detected");
}
}
- PageCount = PageList.Count;
+ pageCount = pageList.Count;
}
return retValue;
//return GetSubscriptionList(int.MinValue, int.MinValue);
@@ -1440,9 +1441,9 @@ public IDictionary GetSubscriptionList()
/// Method that returns a list of subscriptions.
///
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// Null if there are no results, object otherwise.
- public IDictionary GetSubscriptionList(int page, int per_page)
+ public IDictionary GetSubscriptionList(int page, int perPage)
{
string qs = string.Empty;
@@ -1452,25 +1453,25 @@ public IDictionary GetSubscriptionList(int page, int per_pag
qs += string.Format("page={0}", page);
}
- if (per_page != int.MinValue)
+ if (perPage != int.MinValue)
{
if (qs.Length > 0) { qs += "&"; }
- qs += string.Format("per_page={0}", per_page);
+ qs += string.Format("per_page={0}", perPage);
}
string url = string.Format("subscriptions.{0}", GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a transaction list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "subscriptions")
{
@@ -1478,10 +1479,10 @@ public IDictionary GetSubscriptionList(int page, int per_pag
{
if (subscriptionNode.Name == "subscription")
{
- ISubscription LoadedSubscription = new Subscription(subscriptionNode);
- if (!retValue.ContainsKey(LoadedSubscription.SubscriptionID))
+ ISubscription loadedSubscription = new Subscription(subscriptionNode);
+ if (!retValue.ContainsKey(loadedSubscription.SubscriptionID))
{
- retValue.Add(LoadedSubscription.SubscriptionID, LoadedSubscription);
+ retValue.Add(loadedSubscription.SubscriptionID, loadedSubscription);
}
else
{
@@ -1499,13 +1500,14 @@ public IDictionary GetSubscriptionList(int page, int per_pag
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("subscription"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("subscription"))
{
JsonObject subscriptionObj = (array.Items[i] as JsonObject)["subscription"] as JsonObject;
- ISubscription LoadedSubscription = new Subscription(subscriptionObj);
- if (!retValue.ContainsKey(LoadedSubscription.SubscriptionID))
+ ISubscription loadedSubscription = new Subscription(subscriptionObj);
+ if (!retValue.ContainsKey(loadedSubscription.SubscriptionID))
{
- retValue.Add(LoadedSubscription.SubscriptionID, LoadedSubscription);
+ retValue.Add(loadedSubscription.SubscriptionID, loadedSubscription);
}
else
{
@@ -1521,25 +1523,25 @@ public IDictionary GetSubscriptionList(int page, int per_pag
///
/// Get a list of all subscriptions for a customer.
///
- /// The ChargifyID of the customer
+ /// The ChargifyID of the customer
/// A list of subscriptions
- public IDictionary GetSubscriptionListForCustomer(int ChargifyID)
+ public IDictionary GetSubscriptionListForCustomer(int chargifyId)
{
try
{
// make sure data is valid
- if (ChargifyID == int.MinValue) throw new ArgumentNullException("ChargifyID");
+ if (chargifyId == int.MinValue) throw new ArgumentNullException("chargifyId");
// now make the request
- string response = this.DoRequest(string.Format("customers/{0}/subscriptions.{1}", ChargifyID, GetMethodExtension()));
+ string response = DoRequest(string.Format("customers/{0}/subscriptions.{1}", chargifyId, GetMethodExtension()));
var retValue = new Dictionary();
if (response.IsXml())
{
// now build customer object based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response); // get the XML into an XML document
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response); // get the XML into an XML document
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "subscriptions")
{
@@ -1547,10 +1549,10 @@ public IDictionary GetSubscriptionListForCustomer(int Chargi
{
if (subscriptionNode.Name == "subscription")
{
- ISubscription LoadedSubscription = new Subscription(subscriptionNode);
- if (!retValue.ContainsKey(LoadedSubscription.SubscriptionID))
+ ISubscription loadedSubscription = new Subscription(subscriptionNode);
+ if (!retValue.ContainsKey(loadedSubscription.SubscriptionID))
{
- retValue.Add(LoadedSubscription.SubscriptionID, LoadedSubscription);
+ retValue.Add(loadedSubscription.SubscriptionID, loadedSubscription);
}
else
{
@@ -1568,13 +1570,14 @@ public IDictionary GetSubscriptionListForCustomer(int Chargi
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("subscription"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("subscription"))
{
JsonObject subscriptionObj = (array.Items[i] as JsonObject)["subscription"] as JsonObject;
- ISubscription LoadedSubscription = new Subscription(subscriptionObj);
- if (!retValue.ContainsKey(LoadedSubscription.SubscriptionID))
+ ISubscription loadedSubscription = new Subscription(subscriptionObj);
+ if (!retValue.ContainsKey(loadedSubscription.SubscriptionID))
{
- retValue.Add(LoadedSubscription.SubscriptionID, LoadedSubscription);
+ retValue.Add(loadedSubscription.SubscriptionID, loadedSubscription);
}
else
{
@@ -1599,33 +1602,29 @@ public IDictionary GetSubscriptionListForCustomer(int Chargi
/// The subscription
public ISubscription CreateSubscription(ISubscriptionCreateOptions options)
{
- if (options == null) throw new ArgumentNullException("options");
+ if (options == null) throw new ArgumentNullException(nameof(options));
// Customer
- var customerSpecifiedAlready = false;
- if (options.CustomerID.HasValue && !customerSpecifiedAlready)
- {
- customerSpecifiedAlready = true;
- }
+ bool customerSpecifiedAlready = options.CustomerID.HasValue;
+
if (!string.IsNullOrEmpty(options.CustomerReference))
{
- if (customerSpecifiedAlready == true) { throw new ArgumentException("Customer information should only be specified once", "options"); }
- else { customerSpecifiedAlready = true; }
+ if (customerSpecifiedAlready) { throw new ArgumentException("Customer information should only be specified once", nameof(options)); }
+ customerSpecifiedAlready = true;
}
if (options.CustomerAttributes != null)
{
- if (customerSpecifiedAlready == true) throw new ArgumentException("Customer information should only be specified once", "options");
- else { customerSpecifiedAlready = true; }
+ if (customerSpecifiedAlready) throw new ArgumentException("Customer information should only be specified once", nameof(options));
+ customerSpecifiedAlready = true;
}
if (!customerSpecifiedAlready) { throw new ArgumentException("No customer information was specified. Please specify either the CustomerID, CustomerReference or CustomerAttributes and try again.", "options"); }
// Product
- var productSpecifiedAlready = false;
- if (options.ProductID.HasValue && !productSpecifiedAlready) productSpecifiedAlready = true;
+ bool productSpecifiedAlready = options.ProductID.HasValue;
if (!string.IsNullOrEmpty(options.ProductHandle))
{
- if (productSpecifiedAlready == true) { throw new ArgumentException("Product information should only be specified once", "options"); }
- else { productSpecifiedAlready = true; }
+ if (productSpecifiedAlready) { throw new ArgumentException("Product information should only be specified once", nameof(options)); }
+ productSpecifiedAlready = true;
}
if (!productSpecifiedAlready) { throw new ArgumentException("No product information was specified. Please specify either the ProductID or ProductHandle and try again.", "options"); }
@@ -1634,11 +1633,11 @@ public ISubscription CreateSubscription(ISubscriptionCreateOptions options)
using (StringWriter textWriter = new Utf8StringWriter())
{
serializer.Serialize(textWriter, options);
- subscriptionXml.Append(textWriter.ToString());
+ subscriptionXml.Append(textWriter);
}
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -1646,286 +1645,286 @@ public ISubscription CreateSubscription(ISubscriptionCreateOptions options)
///
/// Create a new subscription without passing credit card information.
///
- /// The handle to the product
- /// The Chargify ID of the customer
- /// Optional, type of payment collection method
+ /// The handle to the product
+ /// The Chargify ID of the customer
+ /// Optional, type of payment collection method
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, int ChargifyID, PaymentCollectionMethod? PaymentCollectionMethod = PaymentCollectionMethod.Automatic)
+ public ISubscription CreateSubscription(string productHandle, int chargifyId, PaymentCollectionMethod? paymentCollectionMethod = PaymentCollectionMethod.Automatic)
{
// make sure data is valid
- if (ChargifyID == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "ChargifyID");
+ if (chargifyId == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "chargifyId");
// Create the subscription
- return CreateSubscription(ProductHandle, ChargifyID, string.Empty, PaymentCollectionMethod);
+ return CreateSubscription(productHandle, chargifyId, string.Empty, paymentCollectionMethod);
}
///
/// Create a new subscription
///
- /// The handle to the product
- /// The Chargify ID of the customer
- /// The credit card attributes
+ /// The handle to the product
+ /// The Chargify ID of the customer
+ /// The credit card attributes
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, int ChargifyID, ICreditCardAttributes CreditCardAttributes)
+ public ISubscription CreateSubscription(string productHandle, int chargifyId, ICreditCardAttributes creditCardAttributes)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (ChargifyID == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "ChargifyID");
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (chargifyId == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "chargifyId");
- return CreateSubscription(ProductHandle, ChargifyID, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress,
- CreditCardAttributes.BillingCity, CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip,
- CreditCardAttributes.BillingCountry, string.Empty, CreditCardAttributes.FirstName, CreditCardAttributes.LastName);
+ return CreateSubscription(productHandle, chargifyId, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress,
+ creditCardAttributes.BillingCity, creditCardAttributes.BillingState, creditCardAttributes.BillingZip,
+ creditCardAttributes.BillingCountry, string.Empty, creditCardAttributes.FirstName, creditCardAttributes.LastName);
}
///
/// Create a subscription
///
- /// The handle of the product
- /// The ID of the customer who should be used in this new subscription
- /// The credit card attributes to use for the new subscription
- /// The date that should be used for the next_billing_at
+ /// The handle of the product
+ /// The ID of the customer who should be used in this new subscription
+ /// The credit card attributes to use for the new subscription
+ /// The date that should be used for the next_billing_at
/// The new subscription, if successful. Null otherwise.
- public ISubscription CreateSubscription(string ProductHandle, int ChargifyID, ICreditCardAttributes CreditCardAttributes, DateTime NextBillingAt)
+ public ISubscription CreateSubscription(string productHandle, int chargifyId, ICreditCardAttributes creditCardAttributes, DateTime nextBillingAt)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (ChargifyID == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "ChargifyID");
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (chargifyId == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "chargifyId");
- return CreateSubscription(new SubscriptionCreateOptions() { ProductHandle = ProductHandle, CustomerID = ChargifyID, CreditCardAttributes = (CreditCardAttributes) CreditCardAttributes, NextBillingAt = NextBillingAt });
+ return CreateSubscription(new SubscriptionCreateOptions() { ProductHandle = productHandle, CustomerID = chargifyId, CreditCardAttributes = (CreditCardAttributes) creditCardAttributes, NextBillingAt = nextBillingAt });
}
///
/// Create a subscription using a coupon for discounted rate, without using credit card information.
///
- /// The product to subscribe to
- /// The ID of the Customer to add the subscription for
- /// The discount coupon code
+ /// The product to subscribe to
+ /// The ID of the Customer to add the subscription for
+ /// The discount coupon code
/// If sucessful, the subscription object. Otherwise null.
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, int ChargifyID, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, int chargifyId, string couponCode)
{
- if (ChargifyID == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "ChargifyID");
- if (string.IsNullOrEmpty(CouponCode)) throw new ArgumentException("CouponCode can't be empty", "CouponCode");
- return CreateSubscription(ProductHandle, ChargifyID, CouponCode, default(PaymentCollectionMethod?));
+ if (chargifyId == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "chargifyId");
+ if (string.IsNullOrEmpty(couponCode)) throw new ArgumentException("CouponCode can't be empty", "couponCode");
+ return CreateSubscription(productHandle, chargifyId, couponCode, default(PaymentCollectionMethod?));
}
///
/// Create a subscription using a coupon for discounted rate
///
- /// The product to subscribe to
- /// The ID of the Customer to add the subscription for
- /// The credit card attributes to use for this transaction
- /// The discount coupon code
+ /// The product to subscribe to
+ /// The ID of the Customer to add the subscription for
+ /// The credit card attributes to use for this transaction
+ /// The discount coupon code
///
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, int ChargifyID, ICreditCardAttributes CreditCardAttributes, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, int chargifyId, ICreditCardAttributes creditCardAttributes, string couponCode)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (ChargifyID == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "ChargifyID");
- if (string.IsNullOrEmpty(CouponCode)) throw new ArgumentException("CouponCode can't be empty", "CouponCode");
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (chargifyId == int.MinValue) throw new ArgumentException("Invalid Customer ID detected", "chargifyId");
+ if (string.IsNullOrEmpty(couponCode)) throw new ArgumentException("CouponCode can't be empty", "couponCode");
- return CreateSubscription(ProductHandle, ChargifyID, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress,
- CreditCardAttributes.BillingCity, CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip,
- CreditCardAttributes.BillingCountry, CouponCode);
+ return CreateSubscription(productHandle, chargifyId, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress,
+ creditCardAttributes.BillingCity, creditCardAttributes.BillingState, creditCardAttributes.BillingZip,
+ creditCardAttributes.BillingCountry, couponCode);
}
///
/// Create a new subscription without requiring credit card information
///
- /// The handle to the product
- /// The System ID of the customer
+ /// The handle to the product
+ /// The System ID of the customer
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, string SystemID)
+ public ISubscription CreateSubscription(string productHandle, string systemId)
{
- if (SystemID == string.Empty) throw new ArgumentException("Invalid system ID detected", "ChargifyID");
- return CreateSubscription(ProductHandle, SystemID, string.Empty);
+ if (systemId == string.Empty) throw new ArgumentException("Invalid system ID detected", nameof(systemId));
+ return CreateSubscription(productHandle, systemId, string.Empty);
}
///
/// Create a new subscription
///
- /// The handle to the product
- /// The System ID of the customer
- /// The credit card attributes
+ /// The handle to the product
+ /// The System ID of the customer
+ /// The credit card attributes
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, string SystemID, ICreditCardAttributes CreditCardAttributes)
+ public ISubscription CreateSubscription(string productHandle, string systemId, ICreditCardAttributes creditCardAttributes)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (SystemID == string.Empty) throw new ArgumentException("Invalid system ID detected", "ChargifyID");
+ if (creditCardAttributes == null) throw new ArgumentNullException(nameof(creditCardAttributes));
+ if (systemId == string.Empty) throw new ArgumentException("Invalid system ID detected", nameof(systemId));
- return CreateSubscription(ProductHandle, SystemID, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress,
- CreditCardAttributes.BillingCity, CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip,
- CreditCardAttributes.BillingCountry, string.Empty);
+ return CreateSubscription(productHandle, systemId, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress,
+ creditCardAttributes.BillingCity, creditCardAttributes.BillingState, creditCardAttributes.BillingZip,
+ creditCardAttributes.BillingCountry, string.Empty);
}
///
/// Create a new subscription without passing credit card info
///
- /// The handle to the product
- /// The System ID of the customer
- /// The discount coupon code
+ /// The handle to the product
+ /// The System ID of the customer
+ /// The discount coupon code
/// The xml describing the new subscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, string SystemID, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, string systemId, string couponCode)
{
// make sure data is valid
- if (SystemID == string.Empty) throw new ArgumentException("Invalid system customer ID detected", "ChargifyID");
+ if (systemId == string.Empty) throw new ArgumentException("Invalid system customer ID detected", nameof(systemId));
- return CreateSubscription(ProductHandle, SystemID, CouponCode);
+ return CreateSubscription(productHandle, systemId, couponCode);
}
///
/// Create a new subscription
///
- /// The handle to the product
- /// The System ID of the customer
- /// The credit card attributes
- /// The discount coupon code
+ /// The handle to the product
+ /// The System ID of the customer
+ /// The credit card attributes
+ /// The discount coupon code
/// The xml describing the new subsscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, string SystemID, ICreditCardAttributes CreditCardAttributes, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, string systemId, ICreditCardAttributes creditCardAttributes, string couponCode)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (SystemID == string.Empty) throw new ArgumentException("Invalid system customer ID detected", "ChargifyID");
+ if (creditCardAttributes == null) throw new ArgumentNullException(nameof(creditCardAttributes));
+ if (systemId == string.Empty) throw new ArgumentException("Invalid system customer ID detected", nameof(systemId));
- return CreateSubscription(ProductHandle, SystemID, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress,
- CreditCardAttributes.BillingCity, CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip,
- CreditCardAttributes.BillingCountry, CouponCode);
+ return CreateSubscription(productHandle, systemId, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress,
+ creditCardAttributes.BillingCity, creditCardAttributes.BillingState, creditCardAttributes.BillingZip,
+ creditCardAttributes.BillingCountry, couponCode);
}
///
/// Create a new subscription and a new customer at the same time without submitting PaymentProfile attributes
///
- /// The handle to the product
- /// The attributes for the new customer
+ /// The handle to the product
+ /// The attributes for the new customer
/// The xml describing the new subsscription
- /// The type of subscription, recurring (automatic) billing, or invoice (if applicable)
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, PaymentCollectionMethod? PaymentCollectionMethod = PaymentCollectionMethod.Automatic)
+ /// The type of subscription, recurring (automatic) billing, or invoice (if applicable)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes, PaymentCollectionMethod? paymentCollectionMethod = PaymentCollectionMethod.Automatic)
{
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName, CustomerAttributes.LastName,
- CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, string.Empty, DateTime.MinValue, null, PaymentCollectionMethod);
+ if (customerAttributes == null) throw new ArgumentNullException(nameof(customerAttributes));
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName, customerAttributes.LastName,
+ customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, string.Empty, DateTime.MinValue, null, paymentCollectionMethod);
}
///
/// Create a new subscription and a new customer at the same time and import the card data from a specific vault storage
///
- /// The handle to the product
- /// The attributes for the new customer
- /// DateTime for this customer to be assessed at
- /// Data concerning the existing profile in vault storage
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// DateTime for this customer to be assessed at
+ /// Data concerning the existing profile in vault storage
/// The xml describing the new subscription
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, DateTime NextBillingAt, IPaymentProfileAttributes ExistingProfile)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes, DateTime nextBillingAt, IPaymentProfileAttributes existingProfile)
{
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- if (ExistingProfile == null) throw new ArgumentNullException("ExistingProfile");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, string.Empty, NextBillingAt, ExistingProfile, null);
+ if (customerAttributes == null) throw new ArgumentNullException(nameof(customerAttributes));
+ if (existingProfile == null) throw new ArgumentNullException(nameof(existingProfile));
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, string.Empty, nextBillingAt, existingProfile, null);
}
///
/// Create a new subscription and a new customer at the same time and use the card data from another payment profile (from the same customer).
///
- /// The handle to the product
- /// The attributes for the new customer
- /// DateTime for this customer to be assessed at
- /// The ID of the existing payment profile to use when creating the new subscription.
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// DateTime for this customer to be assessed at
+ /// The ID of the existing payment profile to use when creating the new subscription.
/// The new subscription
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, DateTime NextBillingAt, int ExistingProfileID)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes, DateTime nextBillingAt, int existingProfileId)
{
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- if (ExistingProfileID <= 0) throw new ArgumentNullException("ExistingProfileID");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, string.Empty, NextBillingAt, ExistingProfileID);
+ if (customerAttributes == null) throw new ArgumentNullException(nameof(customerAttributes));
+ if (existingProfileId <= 0) throw new ArgumentNullException(nameof(existingProfileId));
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, string.Empty, nextBillingAt, existingProfileId);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
- /// DateTime for this customer to be assessed at
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
+ /// DateTime for this customer to be assessed at
/// The xml describing the new subscription
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes, DateTime NextBillingAt)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes, ICreditCardAttributes creditCardAttributes, DateTime nextBillingAt)
{
// version bump
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (NextBillingAt == DateTime.MinValue) throw new ArgumentOutOfRangeException("NextBillingAt");
- if (NextBillingAt == null) throw new ArgumentNullException("NextBillingAt");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity,
- CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FirstName, CreditCardAttributes.LastName, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity, CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip,
- CreditCardAttributes.BillingCountry, string.Empty, null, NextBillingAt);
+ if (customerAttributes == null) throw new ArgumentNullException(nameof(customerAttributes));
+ if (creditCardAttributes == null) throw new ArgumentNullException(nameof(creditCardAttributes));
+ if (nextBillingAt == DateTime.MinValue) throw new ArgumentOutOfRangeException(nameof(nextBillingAt));
+
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, customerAttributes.ShippingAddress, customerAttributes.ShippingCity,
+ customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FirstName, creditCardAttributes.LastName, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity, creditCardAttributes.BillingState, creditCardAttributes.BillingZip,
+ creditCardAttributes.BillingCountry, string.Empty, null, nextBillingAt);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes,
- ICreditCardAttributes CreditCardAttributes)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes,
+ ICreditCardAttributes creditCardAttributes)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CustomerAttributes.VatNumber,
- CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, string.Empty, int.MinValue, int.MinValue);
+ if (creditCardAttributes == null) throw new ArgumentNullException(nameof(creditCardAttributes));
+ if (customerAttributes == null) throw new ArgumentNullException(nameof(customerAttributes));
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, customerAttributes.VatNumber,
+ customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, string.Empty, int.MinValue, int.MinValue);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
- /// The components to set on the subscription initially
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
+ /// The components to set on the subscription initially
///
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes, Dictionary ComponentsWithQuantity)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes, ICreditCardAttributes creditCardAttributes, Dictionary componentsWithQuantity)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FirstName, CreditCardAttributes.LastName, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, string.Empty, ComponentsWithQuantity, null);
+ if (creditCardAttributes == null) throw new ArgumentNullException(nameof(creditCardAttributes));
+ if (customerAttributes == null) throw new ArgumentNullException(nameof(customerAttributes));
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FirstName, creditCardAttributes.LastName, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, string.Empty, componentsWithQuantity, null);
}
- private ISubscription CreateSubscription(string ProductHandle, string NewSystemID, string FirstName, string LastName, string EmailAddress, string Phone,
- string Organization, string ShippingAddress, string ShippingCity, string ShippingState, string ShippingZip, string ShippingCountry,
- string CardFirstName, string CardLastName, string FullNumber, int ExpirationMonth, int ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry, string CouponCode, Dictionary ComponentsWithQuantity, DateTime? NextBillingAt)
+ private ISubscription CreateSubscription(string productHandle, string newSystemId, string firstName, string lastName, string emailAddress, string phone,
+ string organization, string shippingAddress, string shippingCity, string shippingState, string shippingZip, string shippingCountry,
+ string cardFirstName, string cardLastName, string fullNumber, int expirationMonth, int expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry, string couponCode, Dictionary componentsWithQuantity, DateTime? nextBillingAt)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- var product = this.LoadProduct(ProductHandle);
- if (product == null) throw new ArgumentException("The product doesn't exist", ProductHandle);
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException(nameof(productHandle));
+ var product = LoadProduct(productHandle);
+ if (product == null) throw new ArgumentException("The product doesn't exist", productHandle);
// if ((ComponentsWithQuantity.Count < 0)) throw new ArgumentNullException("ComponentsWithQuantity", "No components specified");
- if (string.IsNullOrEmpty(FirstName)) throw new ArgumentNullException("FirstName");
- if (string.IsNullOrEmpty(LastName)) throw new ArgumentNullException("LastName");
- if (string.IsNullOrEmpty(EmailAddress)) throw new ArgumentNullException("EmailAddress");
- if (string.IsNullOrEmpty(FullNumber)) throw new ArgumentNullException("FullNumber");
+ if (string.IsNullOrEmpty(firstName)) throw new ArgumentNullException(nameof(firstName));
+ if (string.IsNullOrEmpty(lastName)) throw new ArgumentNullException(nameof(lastName));
+ if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentNullException(nameof(emailAddress));
+ if (string.IsNullOrEmpty(fullNumber)) throw new ArgumentNullException(nameof(fullNumber));
//if (NewSystemID == string.Empty) throw new ArgumentNullException("NewSystemID");
- if ((ExpirationMonth <= 0) && (ExpirationMonth > 12)) throw new ArgumentException("Not within range", "ExpirationMonth");
- if (ExpirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "ExpirationYear");
- if (this._cvvRequired && string.IsNullOrEmpty(CVV)) throw new ArgumentNullException("CVV");
- if (this._cvvRequired && ((CVV.Length < 3) || (CVV.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "CVV");
+ if ((expirationMonth <= 0) && (expirationMonth > 12)) throw new ArgumentException("Not within range", nameof(expirationMonth));
+ if (expirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", nameof(expirationYear));
+ if (_cvvRequired && string.IsNullOrEmpty(cvv)) throw new ArgumentNullException(nameof(cvv));
+ if (_cvvRequired && ((cvv.Length < 3) || (cvv.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", nameof(cvv));
//if (!string.IsNullOrEmpty(NewSystemID))
//{
@@ -1934,41 +1933,41 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
//}
// create XML for creation of customer
- var subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ var subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
+ subscriptionXml.AppendFormat("{0}", productHandle);
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", FirstName);
- subscriptionXml.AppendFormat("{0}", LastName);
- subscriptionXml.AppendFormat("{0}", EmailAddress);
- if (!string.IsNullOrEmpty(Phone)) subscriptionXml.AppendFormat("{0}", Phone);
- subscriptionXml.AppendFormat("{0}", (Organization != null) ? HttpUtility.HtmlEncode(Organization) : "null");
- subscriptionXml.AppendFormat("{0}", NewSystemID.ToString());
- if (!string.IsNullOrEmpty(ShippingAddress)) subscriptionXml.AppendFormat("{0}", ShippingAddress);
- if (!string.IsNullOrEmpty(ShippingCity)) subscriptionXml.AppendFormat("{0}", ShippingCity);
- if (!string.IsNullOrEmpty(ShippingState)) subscriptionXml.AppendFormat("{0}", ShippingState);
- if (!string.IsNullOrEmpty(ShippingZip)) subscriptionXml.AppendFormat("{0}", ShippingZip);
- if (!string.IsNullOrEmpty(ShippingCountry)) subscriptionXml.AppendFormat("{0}", ShippingCountry);
+ subscriptionXml.AppendFormat("{0}", firstName);
+ subscriptionXml.AppendFormat("{0}", lastName);
+ subscriptionXml.AppendFormat("{0}", emailAddress);
+ if (!string.IsNullOrEmpty(phone)) subscriptionXml.AppendFormat("{0}", phone);
+ subscriptionXml.AppendFormat("{0}", (organization != null) ? HttpUtility.HtmlEncode(organization) : "null");
+ subscriptionXml.AppendFormat("{0}", newSystemId);
+ if (!string.IsNullOrEmpty(shippingAddress)) subscriptionXml.AppendFormat("{0}", shippingAddress);
+ if (!string.IsNullOrEmpty(shippingCity)) subscriptionXml.AppendFormat("{0}", shippingCity);
+ if (!string.IsNullOrEmpty(shippingState)) subscriptionXml.AppendFormat("{0}", shippingState);
+ if (!string.IsNullOrEmpty(shippingZip)) subscriptionXml.AppendFormat("{0}", shippingZip);
+ if (!string.IsNullOrEmpty(shippingCountry)) subscriptionXml.AppendFormat("{0}", shippingCountry);
subscriptionXml.Append("");
subscriptionXml.Append("");
- if (!string.IsNullOrWhiteSpace(CardFirstName)) subscriptionXml.AppendFormat("{0}", CardFirstName);
- if (!string.IsNullOrWhiteSpace(CardLastName)) subscriptionXml.AppendFormat("{0}", CardLastName);
- subscriptionXml.AppendFormat("{0}", FullNumber);
- subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired) { subscriptionXml.AppendFormat("{0}", CVV); }
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry);
+ if (!string.IsNullOrWhiteSpace(cardFirstName)) subscriptionXml.AppendFormat("{0}", cardFirstName);
+ if (!string.IsNullOrWhiteSpace(cardLastName)) subscriptionXml.AppendFormat("{0}", cardLastName);
+ subscriptionXml.AppendFormat("{0}", fullNumber);
+ subscriptionXml.AppendFormat("{0}", expirationMonth);
+ subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired) { subscriptionXml.AppendFormat("{0}", cvv); }
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry);
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); }
- if (NextBillingAt.HasValue) { subscriptionXml.AppendFormat("{0}", NextBillingAt.Value.ToString("o")); }
- if (ComponentsWithQuantity != null && ComponentsWithQuantity.Count > 0)
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
+ if (nextBillingAt.HasValue) { subscriptionXml.AppendFormat("{0}", nextBillingAt.Value.ToString("o")); }
+ if (componentsWithQuantity != null && componentsWithQuantity.Count > 0)
{
subscriptionXml.Append(@"");
- foreach (var item in ComponentsWithQuantity)
+ foreach (var item in componentsWithQuantity)
{
subscriptionXml.Append("");
subscriptionXml.Append(string.Format("{0}", item.Key));
@@ -1979,7 +1978,7 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
}
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -1987,198 +1986,203 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
///
/// Create a new subscription, specifying a coupon
///
- /// The product to subscribe to
- /// Details about the customer
- /// Payment details
- /// The coupon to use
- /// Components to set on the subscription initially
+ /// The product to subscribe to
+ /// Details about the customer
+ /// Payment details
+ /// The coupon to use
+ /// Components to set on the subscription initially
/// Details about the subscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes, string CouponCode, Dictionary ComponentsWithQuantity)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes, ICreditCardAttributes creditCardAttributes, string couponCode, Dictionary componentsWithQuantity)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName, CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization,
- CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FirstName, CreditCardAttributes.LastName, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, CouponCode, ComponentsWithQuantity, null);
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName, customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization,
+ customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FirstName, creditCardAttributes.LastName, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, couponCode, componentsWithQuantity, null);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
- /// The component to allocate when creating the subscription
- /// The quantity to allocate of the component when creating the subscription
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
+ /// The component to allocate when creating the subscription
+ /// The quantity to allocate of the component when creating the subscription
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes, int ComponentID, int AllocatedQuantity)
+ public ISubscription CreateSubscription(string productHandle, ICustomerAttributes customerAttributes, ICreditCardAttributes creditCardAttributes, int componentId, int allocatedQuantity)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CustomerAttributes.VatNumber,
- CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, string.Empty, ComponentID, AllocatedQuantity);
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, customerAttributes.VatNumber,
+ customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, string.Empty, componentId, allocatedQuantity);
}
///
/// Create a new subscription and a new customer at the same time using no credit card information
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The discount coupon code
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The discount coupon code
/// The xml describing the new subsscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes, string couponCode)
{
// make sure data is valid
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName, CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CouponCode, DateTime.MinValue, null, null);
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName, customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, couponCode, DateTime.MinValue, null, null);
}
///
/// Create a new subscription and a new customer at the same time using no credit card information
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The discount coupon code
- /// DateTime for this customer to be assessed at
- /// Data concerning the existing profile in vault storage
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The discount coupon code
+ /// DateTime for this customer to be assessed at
+ /// Data concerning the existing profile in vault storage
/// The xml describing the new subsscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes, string CouponCode, DateTime NextBillingAt, IPaymentProfileAttributes ExistingProfile)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes, string couponCode, DateTime nextBillingAt, IPaymentProfileAttributes existingProfile)
{
// make sure data is valid
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- if (ExistingProfile == null) throw new ArgumentNullException("ExistingProfile");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName, CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CouponCode, NextBillingAt, ExistingProfile, null);
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ if (existingProfile == null) throw new ArgumentNullException("existingProfile");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName, customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, couponCode, nextBillingAt, existingProfile, null);
}
///
/// Create a new subscription and a new customer at the same time using no credit card information
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The discount coupon code
- /// DateTime for this customer to be assessed at
- /// The ID of the data concerning the existing profile in vault storage
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The discount coupon code
+ /// DateTime for this customer to be assessed at
+ /// The ID of the data concerning the existing profile in vault storage
/// The xml describing the new subsscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes, string CouponCode, DateTime NextBillingAt, int ExistingProfileID)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes, string couponCode, DateTime nextBillingAt, int existingProfileId)
{
// make sure data is valid
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- if (ExistingProfileID <= 0) throw new ArgumentNullException("ExistingProfileID");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName, CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CouponCode, NextBillingAt, ExistingProfileID);
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ if (existingProfileId <= 0) throw new ArgumentNullException("existingProfileId");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName, customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, couponCode, nextBillingAt, existingProfileId);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
- /// The discount coupon code
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
+ /// The discount coupon code
/// The xml describing the new subsscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes,
- ICreditCardAttributes CreditCardAttributes, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes,
+ ICreditCardAttributes creditCardAttributes, string couponCode)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CustomerAttributes.VatNumber,
- CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, CouponCode, int.MinValue, int.MinValue);
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, customerAttributes.VatNumber,
+ customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, couponCode, int.MinValue, int.MinValue);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
- /// The discount coupon code
- /// Specify the time of first assessment
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
+ /// The discount coupon code
+ /// Specify the time of first assessment
/// The new subscription object
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes, ICreditCardAttributes CreditCardAttributes, DateTime NextBillingAt, string CouponCode)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes, ICreditCardAttributes creditCardAttributes, DateTime nextBillingAt, string couponCode)
{
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- if (NextBillingAt == null || NextBillingAt == DateTime.MinValue) throw new ArgumentNullException("NextBillingAt");
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ if (nextBillingAt == null || nextBillingAt == DateTime.MinValue) throw new ArgumentNullException("nextBillingAt");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization,
- CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FirstName, CreditCardAttributes.LastName, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, CouponCode, null, NextBillingAt);
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization,
+ customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FirstName, creditCardAttributes.LastName, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, couponCode, null, nextBillingAt);
}
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The attributes for the new customer
- /// The credit card attributes
- /// The discount coupon code
- /// The component to allocate when creating the subscription
- /// The quantity to allocate of the component when creating the subscription
+ /// The handle to the product
+ /// The attributes for the new customer
+ /// The credit card attributes
+ /// The discount coupon code
+ /// The component to allocate when creating the subscription
+ /// The quantity to allocate of the component when creating the subscription
/// The xml describing the new subsscription
- public ISubscription CreateSubscriptionUsingCoupon(string ProductHandle, ICustomerAttributes CustomerAttributes,
- ICreditCardAttributes CreditCardAttributes, string CouponCode, int ComponentID, int AllocatedQuantity)
+ public ISubscription CreateSubscriptionUsingCoupon(string productHandle, ICustomerAttributes customerAttributes,
+ ICreditCardAttributes creditCardAttributes, string couponCode, int componentId, int allocatedQuantity)
{
// make sure data is valid
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- if (CustomerAttributes == null) throw new ArgumentNullException("CustomerAttributes");
- return CreateSubscription(ProductHandle, CustomerAttributes.SystemID, CustomerAttributes.FirstName,
- CustomerAttributes.LastName, CustomerAttributes.Email, CustomerAttributes.Phone, CustomerAttributes.Organization, CustomerAttributes.VatNumber,
- CustomerAttributes.ShippingAddress, CustomerAttributes.ShippingCity, CustomerAttributes.ShippingState, CustomerAttributes.ShippingZip, CustomerAttributes.ShippingCountry,
- CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth,
- CreditCardAttributes.ExpirationYear, CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity,
- CreditCardAttributes.BillingState, CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry, CouponCode, ComponentID, AllocatedQuantity);
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ if (customerAttributes == null) throw new ArgumentNullException("customerAttributes");
+ return CreateSubscription(productHandle, customerAttributes.SystemID, customerAttributes.FirstName,
+ customerAttributes.LastName, customerAttributes.Email, customerAttributes.Phone, customerAttributes.Organization, customerAttributes.VatNumber,
+ customerAttributes.ShippingAddress, customerAttributes.ShippingCity, customerAttributes.ShippingState, customerAttributes.ShippingZip, customerAttributes.ShippingCountry,
+ creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth,
+ creditCardAttributes.ExpirationYear, creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity,
+ creditCardAttributes.BillingState, creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry, couponCode, componentId, allocatedQuantity);
}
///
/// Create a new subscription
///
- /// The handle to the product
- /// The Chargify ID of the customer
- /// The discount coupon code
- /// Optional, type of payment collection method
+ /// The handle to the product
+ /// The Chargify ID of the customer
+ /// The discount coupon code
+ /// Optional, type of payment collection method
/// The xml describing the new subsscription
- public ISubscription CreateSubscription(string ProductHandle, int ChargifyID, string CouponCode, PaymentCollectionMethod? PaymentCollectionMethod)
+ public ISubscription CreateSubscription(string productHandle, int chargifyId, string couponCode, PaymentCollectionMethod? paymentCollectionMethod)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (ChargifyID == int.MinValue) throw new ArgumentNullException("ChargifyID");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException(nameof(productHandle));
+ if (chargifyId == int.MinValue) throw new ArgumentNullException(nameof(chargifyId));
// make sure that the system ID is unique
- if (this.LoadCustomer(ChargifyID) == null) throw new ArgumentException("Customer Not Found", "SystemID");
+ if (LoadCustomer(chargifyId) == null) throw new ArgumentException("Customer not found with that ID", nameof(chargifyId));
- IProduct subscribingProduct = this.LoadProduct(ProductHandle);
+ IProduct subscribingProduct = LoadProduct(productHandle);
if (subscribingProduct == null) throw new ArgumentException("Product not found");
if (subscribingProduct.RequireCreditCard) throw new ChargifyNetException("Product requires credit card information");
// create XML for creation of customer
- StringBuilder SubscriptionXML = new StringBuilder(GetXMLStringIfApplicable());
- SubscriptionXML.Append("");
- SubscriptionXML.AppendFormat("{0}", ProductHandle);
- SubscriptionXML.AppendFormat("{0}", ChargifyID);
- if (!string.IsNullOrEmpty(CouponCode)) { SubscriptionXML.AppendFormat("{0}", CouponCode); }
- if (PaymentCollectionMethod.HasValue)
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
+ subscriptionXml.Append("");
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ subscriptionXml.AppendFormat("{0}", chargifyId);
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
+ if (paymentCollectionMethod.HasValue)
{
- if (PaymentCollectionMethod.Value != ChargifyNET.PaymentCollectionMethod.Unknown) { SubscriptionXML.AppendFormat("{0}", Enum.GetName(typeof(PaymentCollectionMethod), PaymentCollectionMethod.Value).ToLowerInvariant()); }
+ if (paymentCollectionMethod.Value != PaymentCollectionMethod.Unknown)
+ {
+ var paymentCollectionMethodName = Enum.GetName(typeof(PaymentCollectionMethod), paymentCollectionMethod.Value);
+ if (paymentCollectionMethodName != null)
+ subscriptionXml.AppendFormat("{0}", paymentCollectionMethodName.ToLowerInvariant());
+ }
}
- SubscriptionXML.Append("");
+ subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, SubscriptionXML.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2186,34 +2190,34 @@ public ISubscription CreateSubscription(string ProductHandle, int ChargifyID, st
///
/// Create a new subscription
///
- /// The handle to the product
- /// The Chargify ID of the customer
- /// The full number of the credit card
- /// The expritation month of the credit card
- /// The expiration year of the credit card
- /// The CVV for the credit card
- /// The billing address
- /// The billing city
- /// The billing state or province
- /// The billing zip code or postal code
- /// The billing country
- /// The discount coupon code
- /// The first name, as it appears on the credit card
- /// The last name, as it appears on the credit card
+ /// The handle to the product
+ /// The Chargify ID of the customer
+ /// The full number of the credit card
+ /// The expritation month of the credit card
+ /// The expiration year of the credit card
+ /// The CVV for the credit card
+ /// The billing address
+ /// The billing city
+ /// The billing state or province
+ /// The billing zip code or postal code
+ /// The billing country
+ /// The discount coupon code
+ /// The first name, as it appears on the credit card
+ /// The last name, as it appears on the credit card
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, int ChargifyID, string FullNumber, int ExpirationMonth, int ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry, string CouponCode, string FirstName, string LastName)
+ private ISubscription CreateSubscription(string productHandle, int chargifyId, string fullNumber, int expirationMonth, int expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry, string couponCode, string firstName, string lastName)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (ChargifyID == int.MinValue) throw new ArgumentNullException("ChargifyID");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException(nameof(productHandle));
+ if (chargifyId == int.MinValue) throw new ArgumentNullException(nameof(chargifyId));
// make sure that the system ID is unique
- if (this.LoadCustomer(ChargifyID) == null) throw new ArgumentException("Customer Not Found", "SystemID");
- if (string.IsNullOrEmpty(FullNumber)) throw new ArgumentNullException("FullNumber");
- if ((ExpirationMonth <= 0) && (ExpirationMonth > 12)) throw new ArgumentException("Not within range", "ExpirationMonth");
- if (ExpirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "ExpirationYear");
- if (this._cvvRequired && string.IsNullOrEmpty(CVV)) throw new ArgumentNullException("CVV");
+ if (LoadCustomer(chargifyId) == null) throw new ArgumentException("Customer not found with that ID", nameof(chargifyId));
+ if (string.IsNullOrEmpty(fullNumber)) throw new ArgumentNullException(nameof(fullNumber));
+ if ((expirationMonth <= 0) && (expirationMonth > 12)) throw new ArgumentException("Not within range", nameof(expirationMonth));
+ if (expirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", nameof(expirationYear));
+ if (_cvvRequired && string.IsNullOrEmpty(cvv)) throw new ArgumentNullException(nameof(cvv));
// Since the hosted pages don't necessarily use these - I'm not sure if we should be including them.
//if (string.IsNullOrEmpty(BillingZip)) throw new ArgumentNullException("BillingZip");
@@ -2223,27 +2227,27 @@ private ISubscription CreateSubscription(string ProductHandle, int ChargifyID, s
//if (string.IsNullOrEmpty(BillingCountry)) throw new ArgumentNullException("BillingCountry");
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
- subscriptionXml.AppendFormat("{0}", ChargifyID);
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ subscriptionXml.AppendFormat("{0}", chargifyId);
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(FirstName)) { subscriptionXml.AppendFormat("{0}", FirstName); }
- if (!string.IsNullOrEmpty(LastName)) { subscriptionXml.AppendFormat("{0}", LastName); }
- subscriptionXml.AppendFormat("{0}", FullNumber);
- subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired) { subscriptionXml.AppendFormat("{0}", CVV); }
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry);
+ if (!string.IsNullOrEmpty(firstName)) { subscriptionXml.AppendFormat("{0}", firstName); }
+ if (!string.IsNullOrEmpty(lastName)) { subscriptionXml.AppendFormat("{0}", lastName); }
+ subscriptionXml.AppendFormat("{0}", fullNumber);
+ subscriptionXml.AppendFormat("{0}", expirationMonth);
+ subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired) { subscriptionXml.AppendFormat("{0}", cvv); }
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry);
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); }
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2251,33 +2255,33 @@ private ISubscription CreateSubscription(string ProductHandle, int ChargifyID, s
///
/// Create a new subscription
///
- /// The handle to the product
- /// The Chargify ID of the customer
- /// The full number of the credit card
- /// The expritation month of the credit card
- /// The expiration year of the credit card
- /// The CVV for the credit card
- /// The billing address
- /// The billing city
- /// The billing state or province
- /// The billing zip code or postal code
- /// The billing country
- /// The discount coupon code
+ /// The handle to the product
+ /// The Chargify ID of the customer
+ /// The full number of the credit card
+ /// The expritation month of the credit card
+ /// The expiration year of the credit card
+ /// The CVV for the credit card
+ /// The billing address
+ /// The billing city
+ /// The billing state or province
+ /// The billing zip code or postal code
+ /// The billing country
+ /// The discount coupon code
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, int ChargifyID, string FullNumber, int ExpirationMonth, int ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry, string CouponCode)
+ private ISubscription CreateSubscription(string productHandle, int chargifyId, string fullNumber, int expirationMonth, int expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry, string couponCode)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (ChargifyID == int.MinValue) throw new ArgumentNullException("ChargifyID");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
+ if (chargifyId == int.MinValue) throw new ArgumentNullException("chargifyId");
// make sure that the system ID is unique
- if (this.LoadCustomer(ChargifyID) == null) throw new ArgumentException("Customer Not Found", "SystemID");
- if (string.IsNullOrEmpty(FullNumber)) throw new ArgumentNullException("FullNumber");
- if ((ExpirationMonth <= 0) && (ExpirationMonth > 12)) throw new ArgumentException("Not within range", "ExpirationMonth");
- if (ExpirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "ExpirationYear");
- if (this._cvvRequired && string.IsNullOrEmpty(CVV)) throw new ArgumentNullException("CVV");
- if (this._cvvRequired && ((CVV.Length < 3) || (CVV.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "CVV");
+ if (LoadCustomer(chargifyId) == null) throw new ArgumentException("Customer Not Found", nameof(chargifyId));
+ if (string.IsNullOrEmpty(fullNumber)) throw new ArgumentNullException("fullNumber");
+ if ((expirationMonth <= 0) && (expirationMonth > 12)) throw new ArgumentException("Not within range", "expirationMonth");
+ if (expirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "expirationYear");
+ if (_cvvRequired && string.IsNullOrEmpty(cvv)) throw new ArgumentNullException("cvv");
+ if (_cvvRequired && ((cvv.Length < 3) || (cvv.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "cvv");
// Since the hosted pages don't use these - I'm not sure if we should be including them.
//if (string.IsNullOrEmpty(BillingZip)) throw new ArgumentNullException("BillingZip");
@@ -2287,25 +2291,25 @@ private ISubscription CreateSubscription(string ProductHandle, int ChargifyID, s
//if (string.IsNullOrEmpty(BillingCountry)) throw new ArgumentNullException("BillingCountry");
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
- subscriptionXml.AppendFormat("{0}", ChargifyID);
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ subscriptionXml.AppendFormat("{0}", chargifyId);
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", FullNumber);
- subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired) { subscriptionXml.AppendFormat("{0}", CVV); }
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry);
+ subscriptionXml.AppendFormat("{0}", fullNumber);
+ subscriptionXml.AppendFormat("{0}", expirationMonth);
+ subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired) { subscriptionXml.AppendFormat("{0}", cvv); }
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry);
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); }
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2313,33 +2317,33 @@ private ISubscription CreateSubscription(string ProductHandle, int ChargifyID, s
///
/// Create a new subscription
///
- /// The handle to the product
- /// The System ID of the customer
- /// The discount coupon code
+ /// The handle to the product
+ /// The System ID of the customer
+ /// The discount coupon code
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, string SystemID, string CouponCode)
+ private ISubscription CreateSubscription(string productHandle, string systemId, string couponCode)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (SystemID == string.Empty) throw new ArgumentNullException("SystemID");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
+ if (systemId == string.Empty) throw new ArgumentNullException("systemId");
// make sure that the system ID is unique
- if (this.LoadCustomer(SystemID) == null) throw new ArgumentException("Customer Not Found", "SystemID");
+ if (LoadCustomer(systemId) == null) throw new ArgumentException("Customer Not Found", "systemId");
- IProduct subscribingProduct = this.LoadProduct(ProductHandle);
- if (subscribingProduct == null) throw new ArgumentException("Product not found", "ProductHandle");
+ IProduct subscribingProduct = LoadProduct(productHandle);
+ if (subscribingProduct == null) throw new ArgumentException("Product not found", "productHandle");
if (subscribingProduct.RequireCreditCard) throw new ChargifyNetException("Product requires credit card information");
// create XML for creation of customer
- StringBuilder SubscriptionXML = new StringBuilder(GetXMLStringIfApplicable());
- SubscriptionXML.Append("");
- SubscriptionXML.AppendFormat("{0}", ProductHandle);
- SubscriptionXML.AppendFormat("{0}", SystemID.ToString());
- if (!string.IsNullOrEmpty(CouponCode)) { SubscriptionXML.AppendFormat("{0}", CouponCode); }
- SubscriptionXML.Append("");
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
+ subscriptionXml.Append("");
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ subscriptionXml.AppendFormat("{0}", systemId);
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
+ subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, SubscriptionXML.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2347,39 +2351,39 @@ private ISubscription CreateSubscription(string ProductHandle, string SystemID,
///
/// Create a new subscription
///
- /// The handle to the product
- /// The System ID of the customer
- /// The full number of the credit card
- /// The expritation month of the credit card
- /// The expiration year of the credit card
- /// The CVV for the credit card
- /// The billing address
- /// The billing city
- /// The billing state or province
- /// The billing zip code or postal code
- /// The billing country
- /// The discount coupon code
- /// The first name, as listed on the credit card
- /// The last name, as listed on the credit card
+ /// The handle to the product
+ /// The System ID of the customer
+ /// The full number of the credit card
+ /// The expritation month of the credit card
+ /// The expiration year of the credit card
+ /// The CVV for the credit card
+ /// The billing address
+ /// The billing city
+ /// The billing state or province
+ /// The billing zip code or postal code
+ /// The billing country
+ /// The discount coupon code
+ /// The first name, as listed on the credit card
+ /// The last name, as listed on the credit card
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, string SystemID, string FullNumber, int ExpirationMonth, int ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry, string CouponCode, string FirstName, string LastName)
+ private ISubscription CreateSubscription(string productHandle, string systemId, string fullNumber, int expirationMonth, int expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry, string couponCode, string firstName, string lastName)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- var product = this.LoadProduct(ProductHandle);
- if (product == null) throw new ArgumentException("That product doesn't exist", "ProductHandle");
- if (SystemID == string.Empty) throw new ArgumentNullException("SystemID");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException(nameof(productHandle));
+ var product = LoadProduct(productHandle);
+ if (product == null) throw new ArgumentException("That product doesn't exist", nameof(productHandle));
+ if (systemId == string.Empty) throw new ArgumentNullException(nameof(systemId));
// make sure that the system ID is unique
- if (this.LoadCustomer(SystemID) == null) throw new ArgumentException("Customer Not Found", "SystemID");
+ if (LoadCustomer(systemId) == null) throw new ArgumentException("Customer Not Found", nameof(systemId));
if (product.RequireCreditCard)
{
- if (string.IsNullOrEmpty(FullNumber)) throw new ArgumentNullException("FullNumber");
- if ((ExpirationMonth <= 0) && (ExpirationMonth > 12)) throw new ArgumentException("Not within range", "ExpirationMonth");
- if (ExpirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "ExpirationYear");
- if (this._cvvRequired && string.IsNullOrEmpty(CVV)) throw new ArgumentNullException("CVV");
- if (this._cvvRequired && ((CVV.Length < 3) || (CVV.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "CVV");
+ if (string.IsNullOrEmpty(fullNumber)) throw new ArgumentNullException(nameof(fullNumber));
+ if ((expirationMonth <= 0) && (expirationMonth > 12)) throw new ArgumentException("Not within range", nameof(expirationMonth));
+ if (expirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", nameof(expirationYear));
+ if (_cvvRequired && string.IsNullOrEmpty(cvv)) throw new ArgumentNullException(nameof(cvv));
+ if (_cvvRequired && ((cvv.Length < 3) || (cvv.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", nameof(cvv));
}
// Don't throw exceptions on these, since we don't know if they are absolutely needed.
//if (string.IsNullOrEmpty(BillingAddress)) throw new ArgumentNullException("BillingAddress");
@@ -2389,30 +2393,30 @@ private ISubscription CreateSubscription(string ProductHandle, string SystemID,
//if (string.IsNullOrEmpty(BillingCountry)) throw new ArgumentNullException("BillingCountry");
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
- subscriptionXml.AppendFormat("{0}", SystemID.ToString());
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ subscriptionXml.AppendFormat("{0}", systemId);
if (product.RequireCreditCard)
{
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(FirstName)) { subscriptionXml.AppendFormat("{0}", FirstName); }
- if (!string.IsNullOrEmpty(LastName)) { subscriptionXml.AppendFormat("{0}", LastName); }
- subscriptionXml.AppendFormat("{0}", FullNumber);
- subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired) { subscriptionXml.AppendFormat("{0}", CVV); }
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry);
+ if (!string.IsNullOrEmpty(firstName)) { subscriptionXml.AppendFormat("{0}", firstName); }
+ if (!string.IsNullOrEmpty(lastName)) { subscriptionXml.AppendFormat("{0}", lastName); }
+ subscriptionXml.AppendFormat("{0}", fullNumber);
+ subscriptionXml.AppendFormat("{0}", expirationMonth);
+ subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired) { subscriptionXml.AppendFormat("{0}", cvv); }
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry);
subscriptionXml.Append("");
}
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); }
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2420,33 +2424,33 @@ private ISubscription CreateSubscription(string ProductHandle, string SystemID,
///
/// Create a new subscription
///
- /// The handle to the product
- /// The System ID of the customer
- /// The full number of the credit card
- /// The expritation month of the credit card
- /// The expiration year of the credit card
- /// The CVV for the credit card
- /// The billing address
- /// The billing city
- /// The billing state or province
- /// The billing zip code or postal code
- /// The billing country
- /// The discount coupon code
+ /// The handle to the product
+ /// The System ID of the customer
+ /// The full number of the credit card
+ /// The expritation month of the credit card
+ /// The expiration year of the credit card
+ /// The CVV for the credit card
+ /// The billing address
+ /// The billing city
+ /// The billing state or province
+ /// The billing zip code or postal code
+ /// The billing country
+ /// The discount coupon code
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, string SystemID, string FullNumber, int ExpirationMonth, int ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry, string CouponCode)
+ private ISubscription CreateSubscription(string productHandle, string systemId, string fullNumber, int expirationMonth, int expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry, string couponCode)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (SystemID == string.Empty) throw new ArgumentNullException("SystemID");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
+ if (systemId == string.Empty) throw new ArgumentNullException("systemId");
// make sure that the system ID is unique
- if (this.LoadCustomer(SystemID) == null) throw new ArgumentException("Customer Not Found", "SystemID");
- if (string.IsNullOrEmpty(FullNumber)) throw new ArgumentNullException("FullNumber");
- if ((ExpirationMonth <= 0) && (ExpirationMonth > 12)) throw new ArgumentException("Not within range", "ExpirationMonth");
- if (ExpirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "ExpirationYear");
- if (this._cvvRequired && string.IsNullOrEmpty(CVV)) throw new ArgumentNullException("CVV");
- if (this._cvvRequired && ((CVV.Length < 3) || (CVV.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "CVV");
+ if (LoadCustomer(systemId) == null) throw new ArgumentException("Customer Not Found", "systemId");
+ if (string.IsNullOrEmpty(fullNumber)) throw new ArgumentNullException("fullNumber");
+ if ((expirationMonth <= 0) && (expirationMonth > 12)) throw new ArgumentException("Not within range", "expirationMonth");
+ if (expirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "expirationYear");
+ if (_cvvRequired && string.IsNullOrEmpty(cvv)) throw new ArgumentNullException("cvv");
+ if (_cvvRequired && ((cvv.Length < 3) || (cvv.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "cvv");
//if (string.IsNullOrEmpty(BillingAddress)) throw new ArgumentNullException("BillingAddress");
//if (string.IsNullOrEmpty(BillingCity)) throw new ArgumentNullException("BillingCity");
//if (string.IsNullOrEmpty(BillingState)) throw new ArgumentNullException("BillingState");
@@ -2454,25 +2458,25 @@ private ISubscription CreateSubscription(string ProductHandle, string SystemID,
//if (string.IsNullOrEmpty(BillingCountry)) throw new ArgumentNullException("BillingCountry");
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
- subscriptionXml.AppendFormat("{0}", SystemID.ToString());
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ subscriptionXml.AppendFormat("{0}", systemId);
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", FullNumber);
- subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired) { subscriptionXml.AppendFormat("{0}", CVV); }
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry);
+ subscriptionXml.AppendFormat("{0}", fullNumber);
+ subscriptionXml.AppendFormat("{0}", expirationMonth);
+ subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired) { subscriptionXml.AppendFormat("{0}", cvv); }
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry);
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); }
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2480,58 +2484,58 @@ private ISubscription CreateSubscription(string ProductHandle, string SystemID,
///
/// Create a new subscription
///
- /// The handle to the product
- /// The reference field value of the customer
- /// The first name of the customer
- /// The last name of the customer
- /// The email address of the customer
- /// The phone number of the customer
- /// The customer's organization
- /// The discount coupon code
- /// The next date that the billing should be processed (DateTime.Min if unspecified)
- /// The id of the payment profile to use when creating the subscription (existing data)
+ /// The handle to the product
+ /// The reference field value of the customer
+ /// The first name of the customer
+ /// The last name of the customer
+ /// The email address of the customer
+ /// The phone number of the customer
+ /// The customer's organization
+ /// The discount coupon code
+ /// The next date that the billing should be processed (DateTime.Min if unspecified)
+ /// The id of the payment profile to use when creating the subscription (existing data)
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, string NewSystemID, string FirstName, string LastName, string EmailAddress, string Phone,
- string Organization, string CouponCode, DateTime NextBillingAt, int PaymentProfileID)
+ private ISubscription CreateSubscription(string productHandle, string newSystemId, string firstName, string lastName, string emailAddress, string phone,
+ string organization, string couponCode, DateTime nextBillingAt, int paymentProfileId)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (string.IsNullOrEmpty(FirstName)) throw new ArgumentNullException("FirstName");
- if (string.IsNullOrEmpty(LastName)) throw new ArgumentNullException("LastName");
- if (string.IsNullOrEmpty(EmailAddress)) throw new ArgumentNullException("EmailAddress");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
+ if (string.IsNullOrEmpty(firstName)) throw new ArgumentNullException("firstName");
+ if (string.IsNullOrEmpty(lastName)) throw new ArgumentNullException("lastName");
+ if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentNullException("emailAddress");
- ICustomer existingCustomer = this.LoadCustomer(NewSystemID);
- IProduct subscribingProduct = this.LoadProduct(ProductHandle);
- if (subscribingProduct == null) throw new ArgumentException("Product not found", "ProductHandle");
+ ICustomer existingCustomer = LoadCustomer(newSystemId);
+ IProduct subscribingProduct = LoadProduct(productHandle);
+ if (subscribingProduct == null) throw new ArgumentException("Product not found", "productHandle");
// create XML for creation of customer
- StringBuilder SubscriptionXML = new StringBuilder(GetXMLStringIfApplicable());
- SubscriptionXML.Append("");
- SubscriptionXML.AppendFormat("{0}", ProductHandle);
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
+ subscriptionXml.Append("");
+ subscriptionXml.AppendFormat("{0}", productHandle);
if (existingCustomer == null)
{
- SubscriptionXML.Append("");
- SubscriptionXML.AppendFormat("{0}", FirstName);
- SubscriptionXML.AppendFormat("{0}", LastName);
- SubscriptionXML.AppendFormat("{0}", EmailAddress);
- if (!String.IsNullOrEmpty(Phone)) SubscriptionXML.AppendFormat("{0}", Phone);
- SubscriptionXML.AppendFormat("{0}", (Organization != null) ? HttpUtility.HtmlEncode(Organization) : "null");
- SubscriptionXML.AppendFormat("{0}", NewSystemID.ToString());
- SubscriptionXML.Append("");
+ subscriptionXml.Append("");
+ subscriptionXml.AppendFormat("{0}", firstName);
+ subscriptionXml.AppendFormat("{0}", lastName);
+ subscriptionXml.AppendFormat("{0}", emailAddress);
+ if (!String.IsNullOrEmpty(phone)) subscriptionXml.AppendFormat("{0}", phone);
+ subscriptionXml.AppendFormat("{0}", (organization != null) ? HttpUtility.HtmlEncode(organization) : "null");
+ subscriptionXml.AppendFormat("{0}", newSystemId);
+ subscriptionXml.Append("");
}
else
{
- SubscriptionXML.AppendFormat("{0}", existingCustomer.ChargifyID);
+ subscriptionXml.AppendFormat("{0}", existingCustomer.ChargifyID);
}
- if (!string.IsNullOrEmpty(CouponCode)) { SubscriptionXML.AppendFormat("{0}", CouponCode); } // Optional
- SubscriptionXML.AppendFormat("{0}", PaymentProfileID);
- if (NextBillingAt != DateTime.MinValue) { SubscriptionXML.AppendFormat("{0}", NextBillingAt); }
- SubscriptionXML.Append("");
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); } // Optional
+ subscriptionXml.AppendFormat("{0}", paymentProfileId);
+ if (nextBillingAt != DateTime.MinValue) { subscriptionXml.AppendFormat("{0}", nextBillingAt); }
+ subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, SubscriptionXML.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2539,80 +2543,85 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
///
/// Create a new subscription
///
- /// The handle to the product
- /// The reference field value of the customer
- /// The first name of the customer
- /// The last name of the customer
- /// The email address of the customer
- /// The phone number of the customer
- /// The customer's organization
- /// The discount coupon code
- /// The next date that the billing should be processed
- /// The paymentProfile object to use when creating the subscription (existing data)
- /// The type of subscription, recurring (automatic) billing, or invoice (if applicable)
+ /// The handle to the product
+ /// The reference field value of the customer
+ /// The first name of the customer
+ /// The last name of the customer
+ /// The email address of the customer
+ /// The phone number of the customer
+ /// The customer's organization
+ /// The discount coupon code
+ /// The next date that the billing should be processed
+ /// The paymentProfile object to use when creating the subscription (existing data)
+ /// The type of subscription, recurring (automatic) billing, or invoice (if applicable)
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, string NewSystemID, string FirstName, string LastName, string EmailAddress, string Phone,
- string Organization, string CouponCode, DateTime NextBillingAt, IPaymentProfileAttributes PaymentProfile, PaymentCollectionMethod? PaymentCollectionMethod)
+ private ISubscription CreateSubscription(string productHandle, string newSystemId, string firstName, string lastName, string emailAddress, string phone,
+ string organization, string couponCode, DateTime nextBillingAt, IPaymentProfileAttributes paymentProfile, PaymentCollectionMethod? paymentCollectionMethod)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- if (string.IsNullOrEmpty(FirstName)) throw new ArgumentNullException("FirstName");
- if (string.IsNullOrEmpty(LastName)) throw new ArgumentNullException("LastName");
- if (string.IsNullOrEmpty(EmailAddress)) throw new ArgumentNullException("EmailAddress");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
+ if (string.IsNullOrEmpty(firstName)) throw new ArgumentNullException("firstName");
+ if (string.IsNullOrEmpty(lastName)) throw new ArgumentNullException("lastName");
+ if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentNullException("emailAddress");
//if (!string.IsNullOrEmpty(NewSystemID))
//{
// // make sure that the system ID is unique
// if (this.LoadCustomer(NewSystemID) != null) throw new ArgumentException("Not unique", "NewSystemID");
//}
- IProduct subscribingProduct = this.LoadProduct(ProductHandle);
- if (subscribingProduct == null) throw new ArgumentException("Product not found", "ProductHandle");
+ IProduct subscribingProduct = LoadProduct(productHandle);
+ if (subscribingProduct == null) throw new ArgumentException("Product not found", "productHandle");
if (subscribingProduct.RequireCreditCard)
{
// Product requires credit card and no payment information passed in.
- if (PaymentProfile == null) throw new ChargifyNetException("Product requires credit card information");
+ if (paymentProfile == null) throw new ChargifyNetException("Product requires credit card information");
}
// create XML for creation of customer
- var subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ var subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
+ subscriptionXml.AppendFormat("{0}", productHandle);
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", FirstName);
- subscriptionXml.AppendFormat("{0}", LastName);
- subscriptionXml.AppendFormat("{0}", EmailAddress);
- if (!String.IsNullOrEmpty(Phone)) subscriptionXml.AppendFormat("{0}", Phone);
- subscriptionXml.AppendFormat("{0}", (Organization != null) ? HttpUtility.HtmlEncode(Organization) : "null");
- subscriptionXml.AppendFormat("{0}", NewSystemID.ToString());
+ subscriptionXml.AppendFormat("{0}", firstName);
+ subscriptionXml.AppendFormat("{0}", lastName);
+ subscriptionXml.AppendFormat("{0}", emailAddress);
+ if (!String.IsNullOrEmpty(phone)) subscriptionXml.AppendFormat("{0}", phone);
+ subscriptionXml.AppendFormat("{0}", (organization != null) ? HttpUtility.HtmlEncode(organization) : "null");
+ subscriptionXml.AppendFormat("{0}", newSystemId);
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); } // Optional
- if (PaymentProfile != null)
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); } // Optional
+ if (paymentProfile != null)
{
// The round-trip "o" format uses ISO 8601 for date/time representation, neat.
- subscriptionXml.AppendFormat("{0}", NextBillingAt.ToString("o"));
+ subscriptionXml.AppendFormat("{0}", nextBillingAt.ToString("o"));
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", PaymentProfile.VaultToken);
- subscriptionXml.AppendFormat("{0}", PaymentProfile.CustomerVaultToken);
- subscriptionXml.AppendFormat("{0}", PaymentProfile.CurrentVault.ToString().ToLowerInvariant());
- subscriptionXml.AppendFormat("{0}", PaymentProfile.ExpirationYear);
- subscriptionXml.AppendFormat("{0}", PaymentProfile.ExpirationMonth);
- if (PaymentProfile.CardType != CardType.Unknown) { subscriptionXml.AppendFormat("{0}", PaymentProfile.CardType.ToString().ToLowerInvariant()); } // Optional
- if (PaymentProfile.LastFour != String.Empty) { subscriptionXml.AppendFormat("{0}", PaymentProfile.LastFour); } // Optional
- if (PaymentProfile.BankName != String.Empty) { subscriptionXml.AppendFormat("{0}", PaymentProfile.BankName); }
- if (PaymentProfile.BankRoutingNumber != String.Empty) { subscriptionXml.AppendFormat("{0}", PaymentProfile.BankRoutingNumber); }
- if (PaymentProfile.BankAccountNumber != String.Empty) { subscriptionXml.AppendFormat("{0}", PaymentProfile.BankAccountNumber); }
- if (PaymentProfile.BankAccountType != BankAccountType.Unknown) { subscriptionXml.AppendFormat("{0}", PaymentProfile.BankAccountType.ToString().ToLowerInvariant()); }
- if (PaymentProfile.BankAccountHolderType != BankAccountHolderType.Unknown) { subscriptionXml.AppendFormat("{0}", PaymentProfile.BankAccountHolderType.ToString().ToLowerInvariant()); }
+ subscriptionXml.AppendFormat("{0}", paymentProfile.VaultToken);
+ subscriptionXml.AppendFormat("{0}", paymentProfile.CustomerVaultToken);
+ subscriptionXml.AppendFormat("{0}", paymentProfile.CurrentVault.ToString().ToLowerInvariant());
+ subscriptionXml.AppendFormat("{0}", paymentProfile.ExpirationYear);
+ subscriptionXml.AppendFormat("{0}", paymentProfile.ExpirationMonth);
+ if (paymentProfile.CardType != CardType.Unknown) { subscriptionXml.AppendFormat("{0}", paymentProfile.CardType.ToString().ToLowerInvariant()); } // Optional
+ if (paymentProfile.LastFour != String.Empty) { subscriptionXml.AppendFormat("{0}", paymentProfile.LastFour); } // Optional
+ if (paymentProfile.BankName != String.Empty) { subscriptionXml.AppendFormat("{0}", paymentProfile.BankName); }
+ if (paymentProfile.BankRoutingNumber != String.Empty) { subscriptionXml.AppendFormat("{0}", paymentProfile.BankRoutingNumber); }
+ if (paymentProfile.BankAccountNumber != String.Empty) { subscriptionXml.AppendFormat("{0}", paymentProfile.BankAccountNumber); }
+ if (paymentProfile.BankAccountType != BankAccountType.Unknown) { subscriptionXml.AppendFormat("{0}", paymentProfile.BankAccountType.ToString().ToLowerInvariant()); }
+ if (paymentProfile.BankAccountHolderType != BankAccountHolderType.Unknown) { subscriptionXml.AppendFormat("{0}", paymentProfile.BankAccountHolderType.ToString().ToLowerInvariant()); }
subscriptionXml.Append("");
}
- if (PaymentCollectionMethod.HasValue)
+ if (paymentCollectionMethod.HasValue)
{
- if (PaymentCollectionMethod.Value != ChargifyNET.PaymentCollectionMethod.Unknown) { subscriptionXml.AppendFormat("{0}", Enum.GetName(typeof(PaymentCollectionMethod), PaymentCollectionMethod.Value).ToLowerInvariant()); }
+ if (paymentCollectionMethod.Value != PaymentCollectionMethod.Unknown)
+ {
+ var paymentCollectionMethodName = Enum.GetName(typeof(PaymentCollectionMethod), paymentCollectionMethod.Value);
+ if (paymentCollectionMethodName != null)
+ subscriptionXml.AppendFormat("{0}", paymentCollectionMethodName.ToLowerInvariant());
+ }
}
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2620,52 +2629,53 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
///
/// Create a new subscription and a new customer at the same time
///
- /// The handle to the product
- /// The system ID for the new customer
- /// The first name of the new customer
- /// The last nameof the new customer
- /// The email address for the new customer
- /// The phone number for the customer
- /// The organization of the new customer
- /// The shipping address of the customer
- /// The shipping city of the customer
- /// The shipping state of the customer
- /// The shipping zip of the customer
- /// The shipping country of the customer
- /// The full number of the credit card
- /// The expritation month of the credit card
- /// The expiration year of the credit card
- /// The CVV for the credit card
- /// The billing address
- /// The billing city
- /// The billing state or province
- /// The billing zip code or postal code
- /// The billing country
- /// The discount coupon code
- /// The component to add while creating the subscription
- /// The quantity of the component to allocate when creating the component usage for the new subscription
+ /// The handle to the product
+ /// The system ID for the new customer
+ /// The first name of the new customer
+ /// The last nameof the new customer
+ /// The email address for the new customer
+ /// The phone number for the customer
+ /// The organization of the new customer
+ /// The value added tax number
+ /// The shipping address of the customer
+ /// The shipping city of the customer
+ /// The shipping state of the customer
+ /// The shipping zip of the customer
+ /// The shipping country of the customer
+ /// The full number of the credit card
+ /// The expritation month of the credit card
+ /// The expiration year of the credit card
+ /// The CVV for the credit card
+ /// The billing address
+ /// The billing city
+ /// The billing state or province
+ /// The billing zip code or postal code
+ /// The billing country
+ /// The discount coupon code
+ /// The component to add while creating the subscription
+ /// The quantity of the component to allocate when creating the component usage for the new subscription
/// The xml describing the new subsscription
- private ISubscription CreateSubscription(string ProductHandle, string NewSystemID, string FirstName, string LastName, string EmailAddress, string Phone,
- string Organization, string VatNumber, string ShippingAddress, string ShippingCity, string ShippingState, string ShippingZip, string ShippingCountry,
- string FullNumber, int ExpirationMonth, int ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry, string CouponCode, int ComponentID, int AllocatedQuantity)
+ private ISubscription CreateSubscription(string productHandle, string newSystemId, string firstName, string lastName, string emailAddress, string phone,
+ string organization, string vatNumber, string shippingAddress, string shippingCity, string shippingState, string shippingZip, string shippingCountry,
+ string fullNumber, int expirationMonth, int expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry, string couponCode, int componentId, int allocatedQuantity)
{
// make sure data is valid
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
- var product = this.LoadProduct(ProductHandle);
- if (product == null) throw new ArgumentException("The product doesn't exist", ProductHandle);
- if ((ComponentID != int.MinValue) && (AllocatedQuantity == int.MinValue)) throw new ArgumentNullException("AllocatedQuantity");
-
- if (string.IsNullOrEmpty(FirstName)) throw new ArgumentNullException("FirstName");
- if (string.IsNullOrEmpty(LastName)) throw new ArgumentNullException("LastName");
- if (string.IsNullOrEmpty(EmailAddress)) throw new ArgumentNullException("EmailAddress");
- if (string.IsNullOrEmpty(FullNumber)) throw new ArgumentNullException("FullNumber");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
+ var product = LoadProduct(productHandle);
+ if (product == null) throw new ArgumentException("The product doesn't exist", productHandle);
+ if ((componentId != int.MinValue) && (allocatedQuantity == int.MinValue)) throw new ArgumentNullException("allocatedQuantity");
+
+ if (string.IsNullOrEmpty(firstName)) throw new ArgumentNullException("firstName");
+ if (string.IsNullOrEmpty(lastName)) throw new ArgumentNullException("lastName");
+ if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentNullException("emailAddress");
+ if (string.IsNullOrEmpty(fullNumber)) throw new ArgumentNullException("fullNumber");
//if (NewSystemID == string.Empty) throw new ArgumentNullException("NewSystemID");
- if ((ExpirationMonth <= 0) && (ExpirationMonth > 12)) throw new ArgumentException("Not within range", "ExpirationMonth");
- if (ExpirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "ExpirationYear");
- if (this._cvvRequired && string.IsNullOrEmpty(CVV)) throw new ArgumentNullException("CVV");
- if (this._cvvRequired && ((CVV.Length < 3) || (CVV.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "CVV");
+ if ((expirationMonth <= 0) && (expirationMonth > 12)) throw new ArgumentException("Not within range", "expirationMonth");
+ if (expirationYear < DateTime.Today.Year) throw new ArgumentException("Not within range", "expirationYear");
+ if (_cvvRequired && string.IsNullOrEmpty(cvv)) throw new ArgumentNullException("cvv");
+ if (_cvvRequired && ((cvv.Length < 3) || (cvv.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "cvv");
// Don't throw exceptions, as there's no product property (yet) to know if the product requires these fields.
//if (string.IsNullOrEmpty(BillingAddress)) throw new ArgumentNullException("BillingAddress");
@@ -2681,47 +2691,47 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
//}
// create XML for creation of customer
- var subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ var subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
+ subscriptionXml.AppendFormat("{0}", productHandle);
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", FirstName.ToHtmlEncoded());
- subscriptionXml.AppendFormat("{0}", LastName.ToHtmlEncoded());
- subscriptionXml.AppendFormat("{0}", EmailAddress);
- if (!string.IsNullOrEmpty(Phone)) subscriptionXml.AppendFormat("{0}", Phone.ToHtmlEncoded());
- subscriptionXml.AppendFormat("{0}", (Organization != null) ? Organization.ToHtmlEncoded() : "null");
- subscriptionXml.AppendFormat("{0}", (VatNumber != null) ? VatNumber.ToHtmlEncoded() : null);
- subscriptionXml.AppendFormat("{0}", NewSystemID);
- if (!string.IsNullOrEmpty(ShippingAddress)) subscriptionXml.AppendFormat("{0}", ShippingAddress.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(ShippingCity)) subscriptionXml.AppendFormat("{0}", ShippingCity.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(ShippingState)) subscriptionXml.AppendFormat("{0}", ShippingState.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(ShippingZip)) subscriptionXml.AppendFormat("{0}", ShippingZip.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(ShippingCountry)) subscriptionXml.AppendFormat("{0}", ShippingCountry.ToHtmlEncoded());
+ subscriptionXml.AppendFormat("{0}", firstName.ToHtmlEncoded());
+ subscriptionXml.AppendFormat("{0}", lastName.ToHtmlEncoded());
+ subscriptionXml.AppendFormat("{0}", emailAddress);
+ if (!string.IsNullOrEmpty(phone)) subscriptionXml.AppendFormat("{0}", phone.ToHtmlEncoded());
+ subscriptionXml.AppendFormat("{0}", (organization != null) ? organization.ToHtmlEncoded() : "null");
+ subscriptionXml.AppendFormat("{0}", (vatNumber != null) ? vatNumber.ToHtmlEncoded() : null);
+ subscriptionXml.AppendFormat("{0}", newSystemId);
+ if (!string.IsNullOrEmpty(shippingAddress)) subscriptionXml.AppendFormat("{0}", shippingAddress.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(shippingCity)) subscriptionXml.AppendFormat("{0}", shippingCity.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(shippingState)) subscriptionXml.AppendFormat("{0}", shippingState.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(shippingZip)) subscriptionXml.AppendFormat("{0}", shippingZip.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(shippingCountry)) subscriptionXml.AppendFormat("{0}", shippingCountry.ToHtmlEncoded());
subscriptionXml.Append("");
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", FullNumber);
- subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired) { subscriptionXml.AppendFormat("{0}", CVV); }
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip.ToHtmlEncoded());
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry.ToHtmlEncoded());
+ subscriptionXml.AppendFormat("{0}", fullNumber);
+ subscriptionXml.AppendFormat("{0}", expirationMonth);
+ subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired) { subscriptionXml.AppendFormat("{0}", cvv); }
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip.ToHtmlEncoded());
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry.ToHtmlEncoded());
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(CouponCode)) { subscriptionXml.AppendFormat("{0}", CouponCode); }
- if (ComponentID != int.MinValue)
+ if (!string.IsNullOrEmpty(couponCode)) { subscriptionXml.AppendFormat("{0}", couponCode); }
+ if (componentId != int.MinValue)
{
subscriptionXml.Append(@"");
subscriptionXml.Append("");
- subscriptionXml.Append(string.Format("{0}", ComponentID));
- subscriptionXml.Append(string.Format("{0}", AllocatedQuantity));
+ subscriptionXml.Append(string.Format("{0}", componentId));
+ subscriptionXml.Append(string.Format("{0}", allocatedQuantity));
subscriptionXml.Append("");
subscriptionXml.Append("");
}
subscriptionXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2729,155 +2739,155 @@ private ISubscription CreateSubscription(string ProductHandle, string NewSystemI
///
/// Update the credit card information for an existing subscription
///
- /// The subscription to update credit card info for
- /// The attributes for the updated credit card
+ /// The subscription to update credit card info for
+ /// The attributes for the updated credit card
/// The new subscription resulting from the change
- public ISubscription UpdateSubscriptionCreditCard(ISubscription Subscription, ICreditCardAttributes CreditCardAttributes)
+ public ISubscription UpdateSubscriptionCreditCard(ISubscription subscription, ICreditCardAttributes creditCardAttributes)
{
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- return UpdateSubscriptionCreditCard(Subscription.SubscriptionID, CreditCardAttributes);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ return UpdateSubscriptionCreditCard(subscription.SubscriptionID, creditCardAttributes);
}
///
/// Update the credit card information for an existing subscription
///
- /// The ID of the suscription to update
- /// The attributes for the update credit card
+ /// The ID of the suscription to update
+ /// The attributes for the update credit card
/// The new subscription resulting from the change
- public ISubscription UpdateSubscriptionCreditCard(int SubscriptionID, ICreditCardAttributes CreditCardAttributes)
+ public ISubscription UpdateSubscriptionCreditCard(int subscriptionId, ICreditCardAttributes creditCardAttributes)
{
// make sure data is OK
- if (CreditCardAttributes == null) throw new ArgumentNullException("CreditCardAttributes");
- return UpdateTheSubscriptionCreditCard(SubscriptionID, CreditCardAttributes.FirstName, CreditCardAttributes.LastName, CreditCardAttributes.FullNumber, CreditCardAttributes.ExpirationMonth, CreditCardAttributes.ExpirationYear,
- CreditCardAttributes.CVV, CreditCardAttributes.BillingAddress, CreditCardAttributes.BillingCity, CreditCardAttributes.BillingState,
- CreditCardAttributes.BillingZip, CreditCardAttributes.BillingCountry);
+ if (creditCardAttributes == null) throw new ArgumentNullException("creditCardAttributes");
+ return UpdateTheSubscriptionCreditCard(subscriptionId, creditCardAttributes.FirstName, creditCardAttributes.LastName, creditCardAttributes.FullNumber, creditCardAttributes.ExpirationMonth, creditCardAttributes.ExpirationYear,
+ creditCardAttributes.CVV, creditCardAttributes.BillingAddress, creditCardAttributes.BillingCity, creditCardAttributes.BillingState,
+ creditCardAttributes.BillingZip, creditCardAttributes.BillingCountry);
}
///
/// Update the credit card information for an existing subscription
///
- /// The subscription to update credit card info for
- /// The full number of the credit card (optional - set to null if not required)
- /// The expiration month of the credit card (optional - set to null if not required)
- /// The expiration year of the credit card (optional - set to null if not required)
- /// The CVV for the credit card (optional - set to null if not required)
- /// The billing address (optional - set to null if not required)
- /// The billing city (optional - set to null if not required)
- /// The billing state or province (optional - set to null if not required)
- /// The billing zip code or postal code (optional - set to null if not required)
- /// The billing country (optional - set to null if not required)
+ /// The subscription to update credit card info for
+ /// The full number of the credit card (optional - set to null if not required)
+ /// The expiration month of the credit card (optional - set to null if not required)
+ /// The expiration year of the credit card (optional - set to null if not required)
+ /// The CVV for the credit card (optional - set to null if not required)
+ /// The billing address (optional - set to null if not required)
+ /// The billing city (optional - set to null if not required)
+ /// The billing state or province (optional - set to null if not required)
+ /// The billing zip code or postal code (optional - set to null if not required)
+ /// The billing country (optional - set to null if not required)
/// The new subscription resulting from the change
- public ISubscription UpdateSubscriptionCreditCard(ISubscription Subscription, string FullNumber, int? ExpirationMonth, int? ExpirationYear, string CVV,
- string BillingAddress, string BillingCity, string BillingState, string BillingZip, string BillingCountry)
+ public ISubscription UpdateSubscriptionCreditCard(ISubscription subscription, string fullNumber, int? expirationMonth, int? expirationYear, string cvv,
+ string billingAddress, string billingCity, string billingState, string billingZip, string billingCountry)
{
// make sure data is OK
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- return UpdateTheSubscriptionCreditCard(Subscription.SubscriptionID, string.Empty, string.Empty, FullNumber, ExpirationMonth, ExpirationYear, CVV, BillingAddress, BillingCity,
- BillingState, BillingZip, BillingCountry);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ return UpdateTheSubscriptionCreditCard(subscription.SubscriptionID, string.Empty, string.Empty, fullNumber, expirationMonth, expirationYear, cvv, billingAddress, billingCity,
+ billingState, billingZip, billingCountry);
}
///
/// Update the credit card information for an existing subscription
///
- /// The ID of the suscription to update
- /// The full number of the credit card (optional - set to null if not required)
- /// The expiration month of the credit card (optional - set to null if not required)
- /// The expiration year of the credit card (optional - set to null if not required)
- /// The CVV for the credit card (optional - set to null if not required)
- /// The billing address (optional - set to null if not required)
- /// The billing city (optional - set to null if not required)
- /// The billing state or province (optional - set to null if not required)
- /// The billing zip code or postal code (optional - set to null if not required)
- /// The billing country (optional - set to null if not required)
+ /// The ID of the suscription to update
+ /// The full number of the credit card (optional - set to null if not required)
+ /// The expiration month of the credit card (optional - set to null if not required)
+ /// The expiration year of the credit card (optional - set to null if not required)
+ /// The CVV for the credit card (optional - set to null if not required)
+ /// The billing address (optional - set to null if not required)
+ /// The billing city (optional - set to null if not required)
+ /// The billing state or province (optional - set to null if not required)
+ /// The billing zip code or postal code (optional - set to null if not required)
+ /// The billing country (optional - set to null if not required)
/// The new subscription resulting from the change
- public ISubscription UpdateSubscriptionCreditCard(int SubscriptionID, string FullNumber, int? ExpirationMonth, int? ExpirationYear, string CVV,
- string BillingAddress, string BillingCity, string BillingState, string BillingZip, string BillingCountry)
+ public ISubscription UpdateSubscriptionCreditCard(int subscriptionId, string fullNumber, int? expirationMonth, int? expirationYear, string cvv,
+ string billingAddress, string billingCity, string billingState, string billingZip, string billingCountry)
{
// make sure data is OK
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
- return UpdateTheSubscriptionCreditCard(SubscriptionID, string.Empty, string.Empty, FullNumber, ExpirationMonth, ExpirationYear, CVV, BillingAddress, BillingCity,
- BillingState, BillingZip, BillingCountry);
+ return UpdateTheSubscriptionCreditCard(subscriptionId, string.Empty, string.Empty, fullNumber, expirationMonth, expirationYear, cvv, billingAddress, billingCity,
+ billingState, billingZip, billingCountry);
}
///
/// Update the credit card information for an existing subscription
///
- /// The ID of the suscription to update
- /// The billing first name (first name on the card)
- /// The billing last name (last name on the card)
- /// The full number of the credit card (optional - set to null if not required)
- /// The expiration month of the credit card (optional - set to null if not required)
- /// The expiration year of the credit card (optional - set to null if not required)
- /// The CVV for the credit card (optional - set to null if not required)
- /// The billing address (optional - set to null if not required)
- /// The billing city (optional - set to null if not required)
- /// The billing state or province (optional - set to null if not required)
- /// The billing zip code or postal code (optional - set to null if not required)
- /// The billing country (optional - set to null if not required)
+ /// The ID of the suscription to update
+ /// The billing first name (first name on the card)
+ /// The billing last name (last name on the card)
+ /// The full number of the credit card (optional - set to null if not required)
+ /// The expiration month of the credit card (optional - set to null if not required)
+ /// The expiration year of the credit card (optional - set to null if not required)
+ /// The CVV for the credit card (optional - set to null if not required)
+ /// The billing address (optional - set to null if not required)
+ /// The billing city (optional - set to null if not required)
+ /// The billing state or province (optional - set to null if not required)
+ /// The billing zip code or postal code (optional - set to null if not required)
+ /// The billing country (optional - set to null if not required)
/// The new subscription resulting from the change
- public ISubscription UpdateSubscriptionCreditCard(int SubscriptionID, string FirstName, string LastName, string FullNumber, int? ExpirationMonth, int? ExpirationYear, string CVV,
- string BillingAddress, string BillingCity, string BillingState, string BillingZip, string BillingCountry)
+ public ISubscription UpdateSubscriptionCreditCard(int subscriptionId, string firstName, string lastName, string fullNumber, int? expirationMonth, int? expirationYear, string cvv,
+ string billingAddress, string billingCity, string billingState, string billingZip, string billingCountry)
{
// make sure data is OK
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
- return UpdateTheSubscriptionCreditCard(SubscriptionID, FirstName, LastName, FullNumber, ExpirationMonth, ExpirationYear, CVV, BillingAddress, BillingCity,
- BillingState, BillingZip, BillingCountry);
+ return UpdateTheSubscriptionCreditCard(subscriptionId, firstName, lastName, fullNumber, expirationMonth, expirationYear, cvv, billingAddress, billingCity,
+ billingState, billingZip, billingCountry);
}
///
/// Method to update the payment profile
///
- /// The subscription to update
- /// The billing first name
- /// The billing last name
- /// The credit card number
- /// The expiration month
- /// The expiration year
- /// The CVV as written on the back of the card
- /// The billing address
- /// The billing city
- /// The billing state
- /// The billing zip/postal code
- /// The billing country
+ /// The subscription to update
+ /// The billing first name
+ /// The billing last name
+ /// The credit card number
+ /// The expiration month
+ /// The expiration year
+ /// The CVV as written on the back of the card
+ /// The billing address
+ /// The billing city
+ /// The billing state
+ /// The billing zip/postal code
+ /// The billing country
/// The updated subscription
- private ISubscription UpdateTheSubscriptionCreditCard(int SubscriptionID, string FirstName, string LastName, string FullNumber, int? ExpirationMonth, int? ExpirationYear, string CVV,
- string BillingAddress, string BillingCity, string BillingState, string BillingZip, string BillingCountry)
+ private ISubscription UpdateTheSubscriptionCreditCard(int subscriptionId, string firstName, string lastName, string fullNumber, int? expirationMonth, int? expirationYear, string cvv,
+ string billingAddress, string billingCity, string billingState, string billingZip, string billingCountry)
{
// make sure data is OK
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (string.IsNullOrEmpty("FullNumber")) throw new ArgumentNullException("FullNumber");
- if (!string.IsNullOrWhiteSpace(CVV) && this._cvvRequired && ((CVV.Length < 3) || (CVV.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "CVV");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (string.IsNullOrEmpty("FullNumber")) throw new ArgumentNullException("fullNumber");
+ if (!string.IsNullOrWhiteSpace(cvv) && _cvvRequired && ((cvv.Length < 3) || (cvv.Length > 4))) throw new ArgumentException("CVV must be 3 or 4 digits", "cvv");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- var subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ var subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
subscriptionXml.Append("");
- if (!string.IsNullOrEmpty(FirstName)) subscriptionXml.AppendFormat("{0}", FirstName);
- if (!string.IsNullOrEmpty(LastName)) subscriptionXml.AppendFormat("{0}", LastName);
- if (!string.IsNullOrEmpty(FullNumber)) subscriptionXml.AppendFormat("{0}", FullNumber);
- if (ExpirationMonth != null && ExpirationMonth.Value != int.MinValue) subscriptionXml.AppendFormat("{0}", ExpirationMonth);
- if (ExpirationYear != null && ExpirationYear.Value != int.MinValue) subscriptionXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired && !string.IsNullOrEmpty(CVV)) subscriptionXml.AppendFormat("{0}", CVV);
- if (!string.IsNullOrEmpty(BillingAddress)) subscriptionXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity)) subscriptionXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState)) subscriptionXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip)) subscriptionXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry)) subscriptionXml.AppendFormat("{0}", BillingCountry);
+ if (!string.IsNullOrEmpty(firstName)) subscriptionXml.AppendFormat("{0}", firstName);
+ if (!string.IsNullOrEmpty(lastName)) subscriptionXml.AppendFormat("{0}", lastName);
+ if (!string.IsNullOrEmpty(fullNumber)) subscriptionXml.AppendFormat("{0}", fullNumber);
+ if (expirationMonth != null && expirationMonth.Value != int.MinValue) subscriptionXml.AppendFormat("{0}", expirationMonth);
+ if (expirationYear != null && expirationYear.Value != int.MinValue) subscriptionXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired && !string.IsNullOrEmpty(cvv)) subscriptionXml.AppendFormat("{0}", cvv);
+ if (!string.IsNullOrEmpty(billingAddress)) subscriptionXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity)) subscriptionXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState)) subscriptionXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip)) subscriptionXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry)) subscriptionXml.AppendFormat("{0}", billingCountry);
subscriptionXml.Append("");
subscriptionXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2891,98 +2901,98 @@ private ISubscription UpdateTheSubscriptionCreditCard(int SubscriptionID, string
///
/// Update the specified chargify subscription
///
- /// The subscription to update
+ /// The subscription to update
/// The updated subscriptionn, null otherwise.
- public ISubscription UpdateSubscription(ISubscription Subscription)
+ public ISubscription UpdateSubscription(ISubscription subscription)
{
- return UpdateSubscription(Subscription.SubscriptionID, Subscription.Product.Handle, Subscription.Customer.SystemID, Subscription.Customer.FirstName,
- Subscription.Customer.LastName, Subscription.Customer.Email, Subscription.Customer.Phone, Subscription.Customer.Organization, Subscription.PaymentProfile.FullNumber, Subscription.PaymentProfile.ExpirationMonth,
- Subscription.PaymentProfile.ExpirationYear, string.Empty, Subscription.PaymentProfile.BillingAddress, Subscription.PaymentProfile.BillingCity, Subscription.PaymentProfile.BillingState,
- Subscription.PaymentProfile.BillingZip, Subscription.PaymentProfile.BillingCountry);
+ return UpdateSubscription(subscription.SubscriptionID, subscription.Product.Handle, subscription.Customer.SystemID, subscription.Customer.FirstName,
+ subscription.Customer.LastName, subscription.Customer.Email, subscription.Customer.Phone, subscription.Customer.Organization, subscription.PaymentProfile.FullNumber, subscription.PaymentProfile.ExpirationMonth,
+ subscription.PaymentProfile.ExpirationYear, string.Empty, subscription.PaymentProfile.BillingAddress, subscription.PaymentProfile.BillingCity, subscription.PaymentProfile.BillingState,
+ subscription.PaymentProfile.BillingZip, subscription.PaymentProfile.BillingCountry);
}
///
/// Method to change the subscription product WITH proration.
///
- /// The subscription to migrate
- /// The product to migrate the subscription to
- /// Boolean, default false. If true, the customer will migrate to the new product
+ /// The subscription to migrate
+ /// The product to migrate the subscription to
+ /// Boolean, default false. If true, the customer will migrate to the new product
/// if one is available. If false, the trial period will be ignored.
- /// Boolean, default false. If true, initial charges will be assessed.
+ /// Boolean, default false. If true, initial charges will be assessed.
/// If false, initial charges will be ignored.
///
- public ISubscription MigrateSubscriptionProduct(ISubscription Subscription, IProduct Product, bool IncludeTrial, bool IncludeInitialCharge)
+ public ISubscription MigrateSubscriptionProduct(ISubscription subscription, IProduct product, bool includeTrial, bool includeInitialCharge)
{
// make sure data is OK
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- if (Product == null) throw new ArgumentNullException("Product");
- return MigrateSubscriptionProduct(Subscription.SubscriptionID, Product.Handle, IncludeTrial, IncludeInitialCharge);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ if (product == null) throw new ArgumentNullException("product");
+ return MigrateSubscriptionProduct(subscription.SubscriptionID, product.Handle, includeTrial, includeInitialCharge);
}
///
/// Method to change the subscription product WITH proration.
///
- /// The subscription to migrate
- /// The product to migrate to
- /// Boolean, default false. If true, the customer will migrate to the new product
+ /// The subscription to migrate
+ /// The product to migrate to
+ /// Boolean, default false. If true, the customer will migrate to the new product
/// if one is available. If false, the trial period will be ignored.
- /// Boolean, default false. If true, initial charges will be assessed.
+ /// Boolean, default false. If true, initial charges will be assessed.
/// If false, initial charges will be ignored.
/// The completed subscription if migrated successfully, null otherwise.
- public ISubscription MigrateSubscriptionProduct(int SubscriptionID, IProduct Product, bool IncludeTrial, bool IncludeInitialCharge)
+ public ISubscription MigrateSubscriptionProduct(int subscriptionId, IProduct product, bool includeTrial, bool includeInitialCharge)
{
// make sure data is OK
- if (Product == null) throw new ArgumentNullException("Product");
- return MigrateSubscriptionProduct(SubscriptionID, Product.Handle, IncludeTrial, IncludeInitialCharge);
+ if (product == null) throw new ArgumentNullException("product");
+ return MigrateSubscriptionProduct(subscriptionId, product.Handle, includeTrial, includeInitialCharge);
}
///
/// Method to change the subscription product WITH proration.
///
- /// The subscription to migrate
- /// The product handle of the product to migrate to
- /// Boolean, default false. If true, the customer will migrate to the new product
+ /// The subscription to migrate
+ /// The product handle of the product to migrate to
+ /// Boolean, default false. If true, the customer will migrate to the new product
/// if one is available. If false, the trial period will be ignored.
- /// Boolean, default false. If true, initial charges will be assessed.
+ /// Boolean, default false. If true, initial charges will be assessed.
/// If false, initial charges will be ignored.
/// The completed subscription if migrated successfully, null otherwise.
- public ISubscription MigrateSubscriptionProduct(ISubscription Subscription, string ProductHandle, bool IncludeTrial, bool IncludeInitialCharge)
+ public ISubscription MigrateSubscriptionProduct(ISubscription subscription, string productHandle, bool includeTrial, bool includeInitialCharge)
{
// make sure data is OK
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- return MigrateSubscriptionProduct(Subscription.SubscriptionID, ProductHandle, IncludeTrial, IncludeInitialCharge);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ return MigrateSubscriptionProduct(subscription.SubscriptionID, productHandle, includeTrial, includeInitialCharge);
}
///
/// Method to change the subscription product WITH proration.
///
- /// The subscription to migrate
- /// The product handle of the product to migrate to
- /// Boolean, default false. If true, the customer will migrate to the new product
+ /// The subscription to migrate
+ /// The product handle of the product to migrate to
+ /// Boolean, default false. If true, the customer will migrate to the new product
/// if one is available. If false, the trial period will be ignored.
- /// Boolean, default false. If true, initial charges will be assessed.
+ /// Boolean, default false. If true, initial charges will be assessed.
/// If false, initial charges will be ignored.
/// The completed subscription if migrated successfully, null otherwise.
- public ISubscription MigrateSubscriptionProduct(int SubscriptionID, string ProductHandle, bool IncludeTrial, bool IncludeInitialCharge)
+ public ISubscription MigrateSubscriptionProduct(int subscriptionId, string productHandle, bool includeTrial, bool includeInitialCharge)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- StringBuilder migrationXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder migrationXml = new StringBuilder(GetXmlStringIfApplicable());
migrationXml.Append("");
- migrationXml.AppendFormat("{0}", ProductHandle);
- if (IncludeTrial) { migrationXml.Append("1"); }
- if (IncludeInitialCharge) { migrationXml.Append("1"); }
+ migrationXml.AppendFormat("{0}", productHandle);
+ if (includeTrial) { migrationXml.Append("1"); }
+ if (includeInitialCharge) { migrationXml.Append("1"); }
migrationXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/migrations.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, migrationXml.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/migrations.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, migrationXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -2997,79 +3007,79 @@ public ISubscription MigrateSubscriptionProduct(int SubscriptionID, string Produ
/// Update the product information for an existing subscription
///
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
- /// The suscription to update
- /// The new product
- /// Optional, determines if the product change should be done immediately or at the time of assessment.
+ /// The suscription to update
+ /// The new product
+ /// Optional, determines if the product change should be done immediately or at the time of assessment.
/// The new subscription resulting from the change
- public ISubscription EditSubscriptionProduct(ISubscription Subscription, IProduct Product, bool? ProductChangeDelayed = null)
+ public ISubscription EditSubscriptionProduct(ISubscription subscription, IProduct product, bool? productChangeDelayed = null)
{
// make sure data is OK
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- if (Product == null) throw new ArgumentNullException("Product");
- return EditSubscriptionProduct(Subscription.SubscriptionID, Product.Handle, ProductChangeDelayed);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ if (product == null) throw new ArgumentNullException("product");
+ return EditSubscriptionProduct(subscription.SubscriptionID, product.Handle, productChangeDelayed);
}
///
/// Update the product information for an existing subscription
///
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
- /// The ID of the suscription to update
- /// The new product
- /// Optional, determines if the product change should be done immediately or at the time of assessment.
+ /// The ID of the suscription to update
+ /// The new product
+ /// Optional, determines if the product change should be done immediately or at the time of assessment.
/// The new subscription resulting from the change
- public ISubscription EditSubscriptionProduct(int SubscriptionID, IProduct Product, bool? ProductChangeDelayed = null)
+ public ISubscription EditSubscriptionProduct(int subscriptionId, IProduct product, bool? productChangeDelayed = null)
{
// make sure data is OK
- if (Product == null) throw new ArgumentNullException("Product");
- return EditSubscriptionProduct(SubscriptionID, Product.Handle, ProductChangeDelayed);
+ if (product == null) throw new ArgumentNullException("product");
+ return EditSubscriptionProduct(subscriptionId, product.Handle, productChangeDelayed);
}
///
/// Update the product information for an existing subscription
///
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
- /// The suscription to update
- /// The handle to the new product
- /// Optional, determines if the product change should be done immediately or at the time of assessment.
+ /// The suscription to update
+ /// The handle to the new product
+ /// Optional, determines if the product change should be done immediately or at the time of assessment.
/// The new subscription resulting from the change
- public ISubscription EditSubscriptionProduct(ISubscription Subscription, string ProductHandle, bool? ProductChangeDelayed = null)
+ public ISubscription EditSubscriptionProduct(ISubscription subscription, string productHandle, bool? productChangeDelayed = null)
{
// make sure data is OK
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- return EditSubscriptionProduct(Subscription.SubscriptionID, ProductHandle, ProductChangeDelayed);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ return EditSubscriptionProduct(subscription.SubscriptionID, productHandle, productChangeDelayed);
}
///
/// Update the product information for an existing subscription
///
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
- /// The ID of the suscription to update
- /// The handle to the new product
- /// Optional, determines if the product change should be done immediately or at the time of assessment.
+ /// The ID of the suscription to update
+ /// The handle to the new product
+ /// Optional, determines if the product change should be done immediately or at the time of assessment.
/// The new subscription resulting from the change
- public ISubscription EditSubscriptionProduct(int SubscriptionID, string ProductHandle, bool? ProductChangeDelayed = null)
+ public ISubscription EditSubscriptionProduct(int subscriptionId, string productHandle, bool? productChangeDelayed = null)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (string.IsNullOrEmpty(ProductHandle)) throw new ArgumentNullException("ProductHandle");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (string.IsNullOrEmpty(productHandle)) throw new ArgumentNullException("productHandle");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- var subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ var subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", ProductHandle);
- if (ProductChangeDelayed != null && ProductChangeDelayed.HasValue)
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ if (productChangeDelayed != null)
{
//product_change_delayed
- subscriptionXml.AppendFormat("{0}", ProductChangeDelayed.Value.ToString().ToLowerInvariant());
+ subscriptionXml.AppendFormat("{0}", productChangeDelayed.Value.ToString().ToLowerInvariant());
}
subscriptionXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3090,7 +3100,7 @@ public ISubscription CancelDelayedProductChange(int subscriptionId)
if (subscriptionId <= 0) throw new ArgumentNullException("subscriptionId");
// create XML for creation of customer
- var subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ var subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
subscriptionXml.AppendFormat("{0}", string.Empty);
subscriptionXml.Append("");
@@ -3098,7 +3108,7 @@ public ISubscription CancelDelayedProductChange(int subscriptionId)
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3112,73 +3122,73 @@ public ISubscription CancelDelayedProductChange(int subscriptionId)
///
/// Update a subscription changing customer, product and credit card information at the same time
///
- /// The ID of the subscription to update
- /// The handle to the product (optional - set to null if not required)
- /// The system ID for the customer (optional - set to Guid.Empty if not required)
- /// The first name of the new customer (optional - set to null if not required)
- /// The last name of the new customer (optional - set to null if not required)
- /// The email address for the new customer (optional - set to null if not required)
- /// The phone number of the customer (optional - set to null if not required)
- /// The organization of the new customer (optional - set to null if not required)
- /// The full number of the credit card (optional - set to null if not required)
- /// The expritation month of the credit card (optional - set to null if not required)
- /// The expiration year of the credit card (optional - set to null if not required)
- /// The CVV for the credit card (optional - set to null if not required)
- /// The billing address (optional - set to null if not required)
- /// The billing city (optional - set to null if not required)
- /// The billing state or province (optional - set to null if not required)
- /// The billing zip code or postal code (optional - set to null if not required)
- /// The billing country (optional - set to null if not required)
+ /// The ID of the subscription to update
+ /// The handle to the product (optional - set to null if not required)
+ /// The system ID for the customer (optional - set to Guid.Empty if not required)
+ /// The first name of the new customer (optional - set to null if not required)
+ /// The last name of the new customer (optional - set to null if not required)
+ /// The email address for the new customer (optional - set to null if not required)
+ /// The phone number of the customer (optional - set to null if not required)
+ /// The organization of the new customer (optional - set to null if not required)
+ /// The full number of the credit card (optional - set to null if not required)
+ /// The expritation month of the credit card (optional - set to null if not required)
+ /// The expiration year of the credit card (optional - set to null if not required)
+ /// The CVV for the credit card (optional - set to null if not required)
+ /// The billing address (optional - set to null if not required)
+ /// The billing city (optional - set to null if not required)
+ /// The billing state or province (optional - set to null if not required)
+ /// The billing zip code or postal code (optional - set to null if not required)
+ /// The billing country (optional - set to null if not required)
/// The xml describing the new subsscription
- private ISubscription UpdateSubscription(int SubscriptionID, string ProductHandle, string SystemID, string FirstName, string LastName, string EmailAddress, string Phone,
- string Organization, string FullNumber, int? ExpirationMonth, int? ExpirationYear,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry)
+ private ISubscription UpdateSubscription(int subscriptionId, string productHandle, string systemId, string firstName, string lastName, string emailAddress, string phone,
+ string organization, string fullNumber, int? expirationMonth, int? expirationYear,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
//if (!string.IsNullOrEmpty(ProductHandle) && existingSubscription.Product.Handle != ProductHandle)
- subscriptionXml.AppendFormat("{0}", ProductHandle);
- if (!string.IsNullOrEmpty(FirstName) || !string.IsNullOrEmpty(LastName) || !string.IsNullOrEmpty(EmailAddress) ||
- !string.IsNullOrEmpty(Organization) || SystemID != string.Empty)
+ subscriptionXml.AppendFormat("{0}", productHandle);
+ if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName) || !string.IsNullOrEmpty(emailAddress) ||
+ !string.IsNullOrEmpty(organization) || systemId != string.Empty)
{
subscriptionXml.Append("");
//if (!string.IsNullOrEmpty(FirstName) && existingSubscription.Customer.FirstName != FirstName)
- subscriptionXml.AppendFormat("{0}", FirstName);
+ subscriptionXml.AppendFormat("{0}", firstName);
//if (!string.IsNullOrEmpty(LastName) && existingSubscription.Customer.LastName != LastName)
- subscriptionXml.AppendFormat("{0}", LastName);
- if (!string.IsNullOrEmpty(EmailAddress) && existingSubscription.Customer.Email != EmailAddress) subscriptionXml.AppendFormat("{0}", EmailAddress);
- if (!string.IsNullOrEmpty(Phone) && existingSubscription.Customer.Phone != Phone) subscriptionXml.AppendFormat("<{0}>{1}{2}>", CustomerAttributes.PhoneKey, Phone, CustomerAttributes.PhoneKey);
- if (!string.IsNullOrEmpty(Organization) && existingSubscription.Customer.Organization != Organization) subscriptionXml.AppendFormat("{0}", HttpUtility.HtmlEncode(Organization));
- if ((SystemID != string.Empty) && (existingSubscription.Customer.SystemID != SystemID)) subscriptionXml.AppendFormat("{0}", SystemID.ToString());
+ subscriptionXml.AppendFormat("{0}", lastName);
+ if (!string.IsNullOrEmpty(emailAddress) && existingSubscription.Customer.Email != emailAddress) subscriptionXml.AppendFormat("{0}", emailAddress);
+ if (!string.IsNullOrEmpty(phone) && existingSubscription.Customer.Phone != phone) subscriptionXml.AppendFormat("<{0}>{1}{2}>", CustomerAttributes.PhoneKey, phone, CustomerAttributes.PhoneKey);
+ if (!string.IsNullOrEmpty(organization) && existingSubscription.Customer.Organization != organization) subscriptionXml.AppendFormat("{0}", HttpUtility.HtmlEncode(organization));
+ if ((systemId != string.Empty) && (existingSubscription.Customer.SystemID != systemId)) subscriptionXml.AppendFormat("{0}", systemId);
subscriptionXml.Append("");
}
- if (!string.IsNullOrEmpty(FullNumber) || ExpirationMonth == null || ExpirationYear == null || !string.IsNullOrEmpty(CVV) ||
- !string.IsNullOrEmpty(BillingAddress) || !string.IsNullOrEmpty(BillingCity) || !string.IsNullOrEmpty(BillingState) ||
- !string.IsNullOrEmpty(BillingZip) || !string.IsNullOrEmpty(BillingCountry))
+ if (!string.IsNullOrEmpty(fullNumber) || expirationMonth == null || expirationYear == null || !string.IsNullOrEmpty(cvv) ||
+ !string.IsNullOrEmpty(billingAddress) || !string.IsNullOrEmpty(billingCity) || !string.IsNullOrEmpty(billingState) ||
+ !string.IsNullOrEmpty(billingZip) || !string.IsNullOrEmpty(billingCountry))
{
StringBuilder paymentProfileXml = new StringBuilder();
- if ((!string.IsNullOrEmpty(FullNumber)) && (existingSubscription.PaymentProfile.FullNumber != FullNumber)) paymentProfileXml.AppendFormat("{0}", FullNumber);
- if ((ExpirationMonth == null) && (existingSubscription.PaymentProfile.ExpirationMonth != ExpirationMonth)) paymentProfileXml.AppendFormat("{0}", ExpirationMonth);
- if ((ExpirationYear == null) && (existingSubscription.PaymentProfile.ExpirationYear != ExpirationYear)) paymentProfileXml.AppendFormat("{0}", ExpirationYear);
- if (this._cvvRequired && !string.IsNullOrEmpty(CVV)) paymentProfileXml.AppendFormat("{0}", CVV);
- if (!string.IsNullOrEmpty(BillingAddress) && existingSubscription.PaymentProfile.BillingAddress != BillingAddress) paymentProfileXml.AppendFormat("{0}", BillingAddress);
- if (!string.IsNullOrEmpty(BillingCity) && existingSubscription.PaymentProfile.BillingCity != BillingCity) paymentProfileXml.AppendFormat("{0}", BillingCity);
- if (!string.IsNullOrEmpty(BillingState) && existingSubscription.PaymentProfile.BillingState != BillingState) paymentProfileXml.AppendFormat("{0}", BillingState);
- if (!string.IsNullOrEmpty(BillingZip) && existingSubscription.PaymentProfile.BillingZip != BillingZip) paymentProfileXml.AppendFormat("{0}", BillingZip);
- if (!string.IsNullOrEmpty(BillingCountry) && existingSubscription.PaymentProfile.BillingCountry != BillingCountry) paymentProfileXml.AppendFormat("{0}", BillingCountry);
+ if ((!string.IsNullOrEmpty(fullNumber)) && (existingSubscription.PaymentProfile.FullNumber != fullNumber)) paymentProfileXml.AppendFormat("{0}", fullNumber);
+ if ((expirationMonth == null) && (existingSubscription.PaymentProfile.ExpirationMonth != expirationMonth)) paymentProfileXml.AppendFormat("{0}", expirationMonth);
+ if ((expirationYear == null) && (existingSubscription.PaymentProfile.ExpirationYear != expirationYear)) paymentProfileXml.AppendFormat("{0}", expirationYear);
+ if (_cvvRequired && !string.IsNullOrEmpty(cvv)) paymentProfileXml.AppendFormat("{0}", cvv);
+ if (!string.IsNullOrEmpty(billingAddress) && existingSubscription.PaymentProfile.BillingAddress != billingAddress) paymentProfileXml.AppendFormat("{0}", billingAddress);
+ if (!string.IsNullOrEmpty(billingCity) && existingSubscription.PaymentProfile.BillingCity != billingCity) paymentProfileXml.AppendFormat("{0}", billingCity);
+ if (!string.IsNullOrEmpty(billingState) && existingSubscription.PaymentProfile.BillingState != billingState) paymentProfileXml.AppendFormat("{0}", billingState);
+ if (!string.IsNullOrEmpty(billingZip) && existingSubscription.PaymentProfile.BillingZip != billingZip) paymentProfileXml.AppendFormat("{0}", billingZip);
+ if (!string.IsNullOrEmpty(billingCountry) && existingSubscription.PaymentProfile.BillingCountry != billingCountry) paymentProfileXml.AppendFormat("{0}", billingCountry);
if (paymentProfileXml.Length > 0)
{
- subscriptionXml.AppendFormat("{0}", paymentProfileXml.ToString());
+ subscriptionXml.AppendFormat("{0}", paymentProfileXml);
}
}
@@ -3186,7 +3196,7 @@ private ISubscription UpdateSubscription(int SubscriptionID, string ProductHandl
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions.{0}", GetMethodExtension()), HttpRequestMethod.Post, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3200,26 +3210,26 @@ private ISubscription UpdateSubscription(int SubscriptionID, string ProductHandl
///
/// Method to allow users to change the next_assessment_at date
///
- /// The subscription to modify
- /// The date to next bill the customer
+ /// The subscription to modify
+ /// The date to next bill the customer
/// Subscription if successful, null otherwise.
- public ISubscription UpdateBillingDateForSubscription(int SubscriptionID, DateTime NextBillingAt)
+ public ISubscription UpdateBillingDateForSubscription(int subscriptionId, DateTime nextBillingAt)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", NextBillingAt.ToString("o"));
+ subscriptionXml.AppendFormat("{0}", nextBillingAt.ToString("o"));
subscriptionXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3233,24 +3243,24 @@ public ISubscription UpdateBillingDateForSubscription(int SubscriptionID, DateTi
///
/// Method to allow users to change the cancel_at_end_of_period flag
///
- /// The subscription to modify
- /// True if the subscription should cancel at the end of the current period
- /// The reason for cancelling the subscription
+ /// The subscription to modify
+ /// True if the subscription should cancel at the end of the current period
+ /// The reason for cancelling the subscription
/// Subscription if successful, null otherwise.
- public ISubscription UpdateDelayedCancelForSubscription(int SubscriptionID, bool CancelAtEndOfPeriod, string CancellationMessage)
+ public ISubscription UpdateDelayedCancelForSubscription(int subscriptionId, bool cancelAtEndOfPeriod, string cancellationMessage)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
// create XML for creation of customer
- StringBuilder subscriptionXml = new StringBuilder(GetXMLStringIfApplicable());
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
subscriptionXml.Append("");
- subscriptionXml.AppendFormat("{0}", CancelAtEndOfPeriod ? "1" : "0");
- if (!String.IsNullOrEmpty(CancellationMessage)) { subscriptionXml.AppendFormat("{0}", CancellationMessage); }
+ subscriptionXml.AppendFormat("{0}", cancelAtEndOfPeriod ? "1" : "0");
+ if (!String.IsNullOrEmpty(cancellationMessage)) { subscriptionXml.AppendFormat("{0}", cancellationMessage); }
subscriptionXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3266,48 +3276,50 @@ public ISubscription UpdateDelayedCancelForSubscription(int SubscriptionID, bool
/// Useful when reactivating subscriptions, and making sure not to charge the user
/// their existing balance when then cancelled.
///
- /// The ID of the subscription to modify.
+ /// The ID of the subscription to modify.
/// True if successful, false otherwise.
- public bool ResetSubscriptionBalance(int SubscriptionID)
+ public bool ResetSubscriptionBalance(int subscriptionId)
{
try
{
// make sure data is valid
- if (SubscriptionID < 0) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId < 0) throw new ArgumentNullException("subscriptionId");
// now make the request
- this.DoRequest(string.Format("subscriptions/{0}/reset_balance.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, string.Empty);
+ DoRequest(string.Format("subscriptions/{0}/reset_balance.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, string.Empty);
return true;
}
catch (ChargifyException cex)
{
if (cex.StatusCode == HttpStatusCode.NotFound) return false;
- throw cex;
+ throw;
}
}
///
/// Update the collection method of the subscription
///
- /// The ID of the subscription of who's collection method should be updated
- /// The collection method to set
+ /// The ID of the subscription of who's collection method should be updated
+ /// The collection method to set
/// The full details of the updated subscription
- public ISubscription UpdatePaymentCollectionMethod(int SubscriptionID, PaymentCollectionMethod PaymentCollectionMethod)
+ public ISubscription UpdatePaymentCollectionMethod(int subscriptionId, PaymentCollectionMethod paymentCollectionMethod)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- StringBuilder SubscriptionXML = new StringBuilder(GetXMLStringIfApplicable());
- SubscriptionXML.Append("");
- SubscriptionXML.AppendFormat("{0}", Enum.GetName(typeof(PaymentCollectionMethod), PaymentCollectionMethod).ToLowerInvariant());
- SubscriptionXML.Append("");
+ StringBuilder subscriptionXml = new StringBuilder(GetXmlStringIfApplicable());
+ subscriptionXml.Append("");
+ var paymentCollectionMethodName = Enum.GetName(typeof(PaymentCollectionMethod), paymentCollectionMethod);
+ if (paymentCollectionMethodName != null)
+ subscriptionXml.AppendFormat("{0}", paymentCollectionMethodName.ToLowerInvariant());
+ subscriptionXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, SubscriptionXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, subscriptionXml.ToString());
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3324,48 +3336,48 @@ public ISubscription UpdatePaymentCollectionMethod(int SubscriptionID, PaymentCo
///
/// This API endpoint allows you to set certain subscription fields that are usually managed for you automatically. Some of the fields can be set via the normal Subscriptions Update API, but others can only be set using this endpoint.
///
- ///
- ///
+ ///
+ ///
/// The details returned by Chargify
- public bool SetSubscriptionOverride(int SubscriptionID, ISubscriptionOverride OverrideDetails)
+ public bool SetSubscriptionOverride(int subscriptionId, ISubscriptionOverride overrideDetails)
{
- if (OverrideDetails == null) throw new ArgumentNullException("OverrideDetails");
- return SetSubscriptionOverride(SubscriptionID, OverrideDetails.ActivatedAt, OverrideDetails.CanceledAt, OverrideDetails.CancellationMessage, OverrideDetails.ExpiresAt);
+ if (overrideDetails == null) throw new ArgumentNullException("overrideDetails");
+ return SetSubscriptionOverride(subscriptionId, overrideDetails.ActivatedAt, overrideDetails.CanceledAt, overrideDetails.CancellationMessage, overrideDetails.ExpiresAt);
}
///
/// This API endpoint allows you to set certain subscription fields that are usually managed for you automatically. Some of the fields can be set via the normal Subscriptions Update API, but others can only be set using this endpoint.
///
- ///
- ///
- ///
- ///
- ///
+ ///
+ ///
+ ///
+ ///
+ ///
/// The details returned by Chargify
- public bool SetSubscriptionOverride(int SubscriptionID, DateTime? ActivatedAt = null, DateTime? CanceledAt = null, string CancellationMessage = null, DateTime? ExpiresAt = null)
+ public bool SetSubscriptionOverride(int subscriptionId, DateTime? activatedAt = null, DateTime? canceledAt = null, string cancellationMessage = null, DateTime? expiresAt = null)
{
try
{
// make sure data is valid
- if (ActivatedAt == null && CanceledAt == null && CancellationMessage == null && ExpiresAt == null)
+ if (activatedAt == null && canceledAt == null && cancellationMessage == null && expiresAt == null)
{
throw new ArgumentException("No valid parameters provided");
}
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("No subscription found with that ID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("No subscription found with that ID", "subscriptionId");
// create XML for creation of a charge
- var OverrideXML = new StringBuilder(GetXMLStringIfApplicable());
- OverrideXML.Append("");
- if (ActivatedAt.HasValue) { OverrideXML.AppendFormat("{0}", ActivatedAt.Value.ToString("o")); }
- if (!string.IsNullOrEmpty(CancellationMessage)) { OverrideXML.AppendFormat("{0}", HttpUtility.HtmlEncode(CancellationMessage)); }
- if (CanceledAt.HasValue) { OverrideXML.AppendFormat("{0}", CanceledAt.Value.ToString("o")); }
- if (ExpiresAt.HasValue) { OverrideXML.AppendFormat("{0}", ExpiresAt.Value.ToString("o")); }
- OverrideXML.Append("");
+ var overrideXml = new StringBuilder(GetXmlStringIfApplicable());
+ overrideXml.Append("");
+ if (activatedAt.HasValue) { overrideXml.AppendFormat("{0}", activatedAt.Value.ToString("o")); }
+ if (!string.IsNullOrEmpty(cancellationMessage)) { overrideXml.AppendFormat("{0}", HttpUtility.HtmlEncode(cancellationMessage)); }
+ if (canceledAt.HasValue) { overrideXml.AppendFormat("{0}", canceledAt.Value.ToString("o")); }
+ if (expiresAt.HasValue) { overrideXml.AppendFormat("{0}", expiresAt.Value.ToString("o")); }
+ overrideXml.Append("");
// now make the request
- var result = this.DoRequest(string.Format("subscriptions/{0}/override.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Put, OverrideXML.ToString());
+ var result = DoRequest(string.Format("subscriptions/{0}/override.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Put, overrideXml.ToString());
return result == string.Empty;
}
catch (ChargifyException cex)
@@ -3385,38 +3397,38 @@ public bool SetSubscriptionOverride(int SubscriptionID, DateTime? ActivatedAt =
///
/// Return a preview of charges for a subscription product migrations
///
- /// SubscriptionID
- /// ProductID
- /// Should the migration preview consider subscription coupons?
- /// Should the migration preview consider a setup fee
- /// Should the migration preview consider the product trial?
+ /// SubscriptionID
+ /// ProductID
+ /// Should the migration preview consider subscription coupons?
+ /// Should the migration preview consider a setup fee
+ /// Should the migration preview consider the product trial?
///
- public IMigration PreviewMigrateSubscriptionProduct(int SubscriptionID, int ProductID, bool? IncludeTrial, bool? IncludeInitialCharge, bool? IncludeCoupons)
+ public IMigration PreviewMigrateSubscriptionProduct(int subscriptionId, int productId, bool? includeTrial, bool? includeInitialCharge, bool? includeCoupons)
{
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (ProductID == int.MinValue) throw new ArgumentNullException("ProductID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (productId == int.MinValue) throw new ArgumentNullException("productId");
// make sure subscription exists
- ISubscription existingSubscription = this.LoadSubscription(SubscriptionID);
- if (existingSubscription == null) throw new ArgumentException("Subscription not found", "Subscription.SubscriptionID");
+ ISubscription existingSubscription = LoadSubscription(subscriptionId);
+ if (existingSubscription == null) throw new ArgumentException("Subscription not found", nameof(subscriptionId));
// create XML for creation of customer
- StringBuilder MigrationXML = new StringBuilder(GetXMLStringIfApplicable());
- MigrationXML.Append("");
- MigrationXML.AppendFormat("{0}", ProductID);
- if (IncludeTrial.HasValue) { MigrationXML.Append(string.Format("{0}", IncludeTrial.Value ? "1" : "0")); }
- if (IncludeInitialCharge.HasValue) { MigrationXML.Append(string.Format("{0}", IncludeInitialCharge.Value ? "1" : "0")); }
- if (IncludeCoupons.HasValue) { MigrationXML.Append(string.Format("{0}", IncludeCoupons.Value ? "1" : "0")); }
+ StringBuilder migrationXml = new StringBuilder(GetXmlStringIfApplicable());
+ migrationXml.Append("");
+ migrationXml.AppendFormat("{0}", productId);
+ if (includeTrial.HasValue) { migrationXml.Append(string.Format("{0}", includeTrial.Value ? "1" : "0")); }
+ if (includeInitialCharge.HasValue) { migrationXml.Append(string.Format("{0}", includeInitialCharge.Value ? "1" : "0")); }
+ if (includeCoupons.HasValue) { migrationXml.Append(string.Format("{0}", includeCoupons.Value ? "1" : "0")); }
else
{
// Default is yes, if unspecified.
- MigrationXML.Append("1");
+ migrationXml.Append("1");
}
- MigrationXML.Append("");
+ migrationXml.Append("");
try
{
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/migrations/preview.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, MigrationXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/migrations/preview.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, migrationXml.ToString());
// change the response to the object
return response.ConvertResponseTo("migration");
}
@@ -3430,25 +3442,25 @@ public IMigration PreviewMigrateSubscriptionProduct(int SubscriptionID, int Prod
///
/// Return a preview of charges for a subscription product migrations
///
- /// Active Subscription
- /// Active Product
+ /// Active Subscription
+ /// Active Product
/// The migration preview data, if able. Null otherwise.
- public IMigration PreviewMigrateSubscriptionProduct(int SubscriptionID, int ProductID)
+ public IMigration PreviewMigrateSubscriptionProduct(int subscriptionId, int productId)
{
- return PreviewMigrateSubscriptionProduct(SubscriptionID, ProductID, null, null, null);
+ return PreviewMigrateSubscriptionProduct(subscriptionId, productId, null, null, null);
}
///
/// Return a preview of charges for a subscription product migrations
///
- /// Active Subscription
- /// Active Product
+ /// Active Subscription
+ /// Active Product
/// The migration preview data, if able. Null otherwise.
- public IMigration PreviewMigrateSubscriptionProduct(ISubscription Subscription, IProduct Product)
+ public IMigration PreviewMigrateSubscriptionProduct(ISubscription subscription, IProduct product)
{
- if (Subscription == null) throw new ArgumentNullException("Subscription");
- if (Product == null) throw new ArgumentNullException("Product");
- return PreviewMigrateSubscriptionProduct(Subscription.SubscriptionID, Product.ID);
+ if (subscription == null) throw new ArgumentNullException("subscription");
+ if (product == null) throw new ArgumentNullException("product");
+ return PreviewMigrateSubscriptionProduct(subscription.SubscriptionID, product.ID);
}
#endregion
@@ -3457,18 +3469,18 @@ public IMigration PreviewMigrateSubscriptionProduct(ISubscription Subscription,
///
/// Method for retrieving information about a coupon using the ID of that coupon.
///
- /// The ID of the product family that the coupon belongs to
- /// The ID of the coupon
+ /// The ID of the product family that the coupon belongs to
+ /// The ID of the coupon
/// The object if found, null otherwise.
- public ICoupon LoadCoupon(int ProductFamilyID, int CouponID)
+ public ICoupon LoadCoupon(int productFamilyId, int couponId)
{
try
{
// make sure data is valid
- if (ProductFamilyID < 0) throw new ArgumentException("Invalid ProductFamilyID");
- if (CouponID < 0) throw new ArgumentException("Invalid CouponID");
+ if (productFamilyId < 0) throw new ArgumentException("Invalid ProductFamilyID");
+ if (couponId < 0) throw new ArgumentException("Invalid CouponID");
// now make the request
- string response = this.DoRequest(string.Format("product_families/{0}/coupons/{1}.{2}", ProductFamilyID, CouponID, GetMethodExtension()));
+ string response = DoRequest(string.Format("product_families/{0}/coupons/{1}.{2}", productFamilyId, couponId, GetMethodExtension()));
// change the response to the object
return response.ConvertResponseTo("coupon");
@@ -3478,21 +3490,21 @@ public ICoupon LoadCoupon(int ProductFamilyID, int CouponID)
// Throw if anything but not found, since not found is telling us that it's working correctly
// but that there just isn't a coupon with that ID.
if (cex.StatusCode == HttpStatusCode.NotFound) return null;
- throw cex;
+ throw;
}
}
///
/// Retrieve the coupon corresponding to the coupon code, useful for coupon validation.
///
- /// The ID of the product family the coupon belongs to
- /// The code used to represent the coupon
+ /// The ID of the product family the coupon belongs to
+ /// The code used to represent the coupon
/// The object if found, otherwise null.
- public ICoupon FindCoupon(int ProductFamilyID, string CouponCode)
+ public ICoupon FindCoupon(int productFamilyId, string couponCode)
{
try
{
- string response = this.DoRequest(string.Format("product_families/{0}/coupons/find.{1}?code={2}", ProductFamilyID, GetMethodExtension(), CouponCode));
+ string response = DoRequest(string.Format("product_families/{0}/coupons/find.{1}?code={2}", productFamilyId, GetMethodExtension(), couponCode));
// change the response to the object
return response.ConvertResponseTo("coupon");
}
@@ -3501,22 +3513,22 @@ public ICoupon FindCoupon(int ProductFamilyID, string CouponCode)
// Throw if anything but not found, since not found is telling us that it's working correctly
// but that there just isn't a coupon with that code.
if (cex.StatusCode == HttpStatusCode.NotFound) return null;
- throw cex;
+ throw;
}
}
///
/// Method to add a coupon to a subscription using the API
///
- /// The ID of the subscription to modify
- /// The code of the coupon to apply to the subscription
+ /// The ID of the subscription to modify
+ /// The code of the coupon to apply to the subscription
/// The subscription details if successful, null otherwise.
- public ISubscription AddCoupon(int SubscriptionID, string CouponCode)
+ public ISubscription AddCoupon(int subscriptionId, string couponCode)
{
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
- if (string.IsNullOrEmpty(CouponCode)) throw new ArgumentException("Coupon code is empty", "CouponCode");
- string response = this.DoRequest(string.Format("subscriptions/{0}/add_coupon.{1}?code={2}", SubscriptionID, GetMethodExtension(), CouponCode), HttpRequestMethod.Post, null);
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", "subscriptionId");
+ if (string.IsNullOrEmpty(couponCode)) throw new ArgumentException("Coupon code is empty", "couponCode");
+ string response = DoRequest(string.Format("subscriptions/{0}/add_coupon.{1}?code={2}", subscriptionId, GetMethodExtension(), couponCode), HttpRequestMethod.Post, null);
// change the response to the object
return response.ConvertResponseTo("subscription");
}
@@ -3524,16 +3536,16 @@ public ISubscription AddCoupon(int SubscriptionID, string CouponCode)
///
/// Create a new one-time credit
///
- /// The coupon parameters
- /// The ID of the product family to add this coupon to.
+ /// The coupon parameters
+ /// The ID of the product family to add this coupon to.
/// The object if successful, null otherwise.
- public ICoupon CreateCoupon(ICoupon Coupon, int ProductFamilyID)
+ public ICoupon CreateCoupon(ICoupon coupon, int productFamilyId)
{
- if (Coupon == null) throw new ArgumentNullException("Coupon");
- string xml = BuildCouponXML(ProductFamilyID, Coupon.Name, Coupon.Code, Coupon.Description, Coupon.Amount, Coupon.Percentage, Coupon.AllowNegativeBalance,
- Coupon.IsRecurring, Coupon.DurationPeriodCount, Coupon.EndDate);
+ if (coupon == null) throw new ArgumentNullException("coupon");
+ string xml = BuildCouponXml(productFamilyId, coupon.Name, coupon.Code, coupon.Description, coupon.Amount, coupon.Percentage, coupon.AllowNegativeBalance,
+ coupon.IsRecurring, coupon.DurationPeriodCount, coupon.EndDate);
- string response = this.DoRequest(string.Format("coupons.{0}", GetMethodExtension()), HttpRequestMethod.Post, xml);
+ string response = DoRequest(string.Format("coupons.{0}", GetMethodExtension()), HttpRequestMethod.Post, xml);
// change the response to the object
return response.ConvertResponseTo("coupon");
}
@@ -3541,18 +3553,18 @@ public ICoupon CreateCoupon(ICoupon Coupon, int ProductFamilyID)
///
/// Update an existing coupon
///
- /// Coupon object
+ /// Coupon object
/// The updated coupon if successful, null otherwise.
- public ICoupon UpdateCoupon(ICoupon Coupon)
+ public ICoupon UpdateCoupon(ICoupon coupon)
{
- if (Coupon == null) throw new ArgumentNullException("Coupon");
- if (Coupon.ProductFamilyID <= 0) throw new ArgumentOutOfRangeException("Coupon.ProductFamilyID must be > 0");
- if (Coupon.ID <= 0) throw new ArgumentOutOfRangeException("Coupon ID is not valid");
+ if (coupon == null) throw new ArgumentNullException(nameof(coupon));
+ if (coupon.ProductFamilyID <= 0) throw new ArgumentOutOfRangeException(nameof(coupon), "Coupon.ProductFamilyID must be > 0");
+ if (coupon.ID <= 0) throw new ArgumentOutOfRangeException(nameof(coupon), "Coupon ID is not valid");
- string xml = BuildCouponXML(Coupon.ProductFamilyID, Coupon.Name, Coupon.Code, Coupon.Description, Coupon.Amount, Coupon.Percentage, Coupon.AllowNegativeBalance,
- Coupon.IsRecurring, Coupon.DurationPeriodCount, Coupon.EndDate);
+ string xml = BuildCouponXml(coupon.ProductFamilyID, coupon.Name, coupon.Code, coupon.Description, coupon.Amount, coupon.Percentage, coupon.AllowNegativeBalance,
+ coupon.IsRecurring, coupon.DurationPeriodCount, coupon.EndDate);
- string response = this.DoRequest(string.Format("coupons/{0}.{1}", Coupon.ID, GetMethodExtension()), HttpRequestMethod.Put, xml);
+ string response = DoRequest(string.Format("coupons/{0}.{1}", coupon.ID, GetMethodExtension()), HttpRequestMethod.Put, xml);
// change the response to the object
return response.ConvertResponseTo("coupon");
}
@@ -3560,7 +3572,7 @@ public ICoupon UpdateCoupon(ICoupon Coupon)
///
/// Builds the coupon XML based on all the coupon values entered.
///
- /// The id of the product family the coupon should belong to
+ /// The id of the product family the coupon should belong to
/// The name of the coupon
/// The code for the coupon
/// The description of the coupons effect
@@ -3571,13 +3583,13 @@ public ICoupon UpdateCoupon(ICoupon Coupon)
/// How long does the coupon last?
/// At what point will the coupon no longer be valid?
///
- private string BuildCouponXML(int ProductFamilyID, string name, string code, string description, decimal amount, int percentage, bool allowNegativeBalance,
+ private string BuildCouponXml(int productFamilyId, string name, string code, string description, decimal amount, int percentage, bool allowNegativeBalance,
bool recurring, int durationPeriodCount, DateTime endDate)
{
// make sure data is valid
//if (id <= 0 && !id.Equals(int.MinValue)) throw new ArgumentOutOfRangeException("id", id, "id must be > 0 if specified.");
// Don't use ID here, since it's only being used to build the URL
- if (ProductFamilyID < 0 && !ProductFamilyID.Equals(int.MinValue)) throw new ArgumentOutOfRangeException("ProductFamilyID", ProductFamilyID, "Product Family must be >= 0");
+ if (productFamilyId < 0 && !productFamilyId.Equals(int.MinValue)) throw new ArgumentOutOfRangeException("productFamilyId", productFamilyId, "Product Family must be >= 0");
if (amount < 0) throw new ArgumentNullException("amount");
if (percentage < 0) throw new ArgumentNullException("percentage");
if (amount > 0 && percentage > 0) throw new ArgumentException("Only one of amount or percentage can have a value > 0");
@@ -3588,30 +3600,30 @@ private string BuildCouponXML(int ProductFamilyID, string name, string code, str
throw new ArgumentOutOfRangeException("durationPeriodCount", durationPeriodCount, "duration period count must be 0 if not recurring");
// create XML for creation of a credit
- StringBuilder CouponXML = new StringBuilder(GetXMLStringIfApplicable());
- CouponXML.Append("");
- CouponXML.AppendFormat("{0}", HttpUtility.HtmlEncode(name));
- CouponXML.AppendFormat("{0}
", code);
- if (!String.IsNullOrEmpty(description)) CouponXML.AppendFormat("{0}", HttpUtility.HtmlEncode(description));
- if (amount > 0) CouponXML.AppendFormat("{0}", amount.ToChargifyCurrencyFormat());
- if (percentage > 0) CouponXML.AppendFormat("{0}", percentage);
- CouponXML.AppendFormat("{0}", allowNegativeBalance.ToString().ToLower());
- CouponXML.AppendFormat("{0}", recurring.ToString().ToLower());
+ StringBuilder couponXml = new StringBuilder(GetXmlStringIfApplicable());
+ couponXml.Append("");
+ couponXml.AppendFormat("{0}", HttpUtility.HtmlEncode(name));
+ couponXml.AppendFormat("{0}
", code);
+ if (!String.IsNullOrEmpty(description)) couponXml.AppendFormat("{0}", HttpUtility.HtmlEncode(description));
+ if (amount > 0) couponXml.AppendFormat("{0}", amount.ToChargifyCurrencyFormat());
+ if (percentage > 0) couponXml.AppendFormat("{0}", percentage);
+ couponXml.AppendFormat("{0}", allowNegativeBalance.ToString().ToLower());
+ couponXml.AppendFormat("{0}", recurring.ToString().ToLower());
if (recurring)
{
if (durationPeriodCount > 0)
{
- CouponXML.AppendFormat("{0}", durationPeriodCount);
+ couponXml.AppendFormat("{0}", durationPeriodCount);
}
else
{
- CouponXML.Append("");
+ couponXml.Append("");
}
}
- if (!endDate.Equals(DateTime.MinValue)) CouponXML.AppendFormat("{0}", endDate.ToString("yyyy-MM-ddTHH:mm:sszzz"));
- if (ProductFamilyID > 0) CouponXML.AppendFormat("{0}", ProductFamilyID);
- CouponXML.Append("");
- return CouponXML.ToString();
+ if (!endDate.Equals(DateTime.MinValue)) couponXml.AppendFormat("{0}", endDate.ToString("yyyy-MM-ddTHH:mm:sszzz"));
+ if (productFamilyId > 0) couponXml.AppendFormat("{0}", productFamilyId);
+ couponXml.Append("");
+ return couponXml.ToString();
}
#endregion
@@ -3621,14 +3633,14 @@ private string BuildCouponXML(int ProductFamilyID, string name, string code, str
///
/// Create a new one-time charge
///
- /// The subscription that will be charged
- /// The charge parameters
+ /// The subscription that will be charged
+ /// The charge parameters
///
- public ICharge CreateCharge(int SubscriptionID, ICharge Charge)
+ public ICharge CreateCharge(int subscriptionId, ICharge charge)
{
// make sure data is valid
- if (Charge == null) throw new ArgumentNullException("Charge");
- return CreateCharge(SubscriptionID, Charge.Amount, Charge.Memo);
+ if (charge == null) throw new ArgumentNullException("charge");
+ return CreateCharge(subscriptionId, charge.Amount, charge.Memo);
}
/////
@@ -3649,29 +3661,29 @@ public ICharge CreateCharge(int SubscriptionID, ICharge Charge)
///
/// Create a new one-time charge, with options
///
- /// The subscription that will be charged
+ /// The subscription that will be charged
/// The amount to charge the customer
/// A description of the charge
/// (Optional) Should the charge be billed during the next assessment? Default = false
/// (Optional) Should the subscription balance be taken into consideration? Default = true
/// The charge details
- public ICharge CreateCharge(int SubscriptionID, decimal amount, string memo, bool useNegativeBalance = false, bool delayCharge = false)
+ public ICharge CreateCharge(int subscriptionId, decimal amount, string memo, bool useNegativeBalance = false, bool delayCharge = false)
{
// make sure data is valid
- if (amount < 0) throw new ArgumentNullException("Amount"); // Chargify will throw a 422 if a negative number is in this field.
- if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException("Memo");
+ if (amount < 0) throw new ArgumentNullException(nameof(amount)); // Chargify will throw a 422 if a negative number is in this field.
+ if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException(nameof(memo));
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", nameof(subscriptionId));
// create XML for creation of a charge
- StringBuilder ChargeXML = new StringBuilder(GetXMLStringIfApplicable());
- ChargeXML.Append("");
- ChargeXML.AppendFormat("{0}", amount.ToChargifyCurrencyFormat());
- ChargeXML.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
- ChargeXML.AppendFormat("{0}", delayCharge ? "1" : "0");
- ChargeXML.AppendFormat("{0}", !useNegativeBalance ? "1" : "0");
- ChargeXML.Append("");
+ StringBuilder chargeXml = new StringBuilder(GetXmlStringIfApplicable());
+ chargeXml.Append("");
+ chargeXml.AppendFormat("{0}", amount.ToChargifyCurrencyFormat());
+ chargeXml.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
+ chargeXml.AppendFormat("{0}", delayCharge ? "1" : "0");
+ chargeXml.AppendFormat("{0}", !useNegativeBalance ? "1" : "0");
+ chargeXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/charges.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, ChargeXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/charges.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, chargeXml.ToString());
// change the response to the object
return response.ConvertResponseTo("charge");
}
@@ -3683,38 +3695,38 @@ public ICharge CreateCharge(int SubscriptionID, decimal amount, string memo, boo
///
/// Create a new one-time credit
///
- /// The subscription that will be credited
- /// The credit parameters
+ /// The subscription that will be credited
+ /// The credit parameters
/// The object if successful, null otherwise.
- public ICredit CreateCredit(int SubscriptionID, ICredit Credit)
+ public ICredit CreateCredit(int subscriptionId, ICredit credit)
{
// make sure data is valid
- if (Credit == null) throw new ArgumentNullException("Credit");
- return CreateCredit(SubscriptionID, Credit.Amount, Credit.Memo);
+ if (credit == null) throw new ArgumentNullException("credit");
+ return CreateCredit(subscriptionId, credit.Amount, credit.Memo);
}
///
/// Create a new one-time credit
///
- /// The subscription that will be credited
+ /// The subscription that will be credited
/// The amount to credit the customer
/// A note regarding the reason for the credit
/// The object if successful, null otherwise.
- public ICredit CreateCredit(int SubscriptionID, decimal amount, string memo)
+ public ICredit CreateCredit(int subscriptionId, decimal amount, string memo)
{
// make sure data is valid
- if (amount < 0) throw new ArgumentNullException("Amount");
- if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException("Memo");
+ if (amount < 0) throw new ArgumentNullException(nameof(amount));
+ if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException(nameof(memo));
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", nameof(subscriptionId));
// create XML for creation of a credit
- StringBuilder CreditXML = new StringBuilder(GetXMLStringIfApplicable());
- CreditXML.Append("");
- CreditXML.AppendFormat("{0}", amount.ToChargifyCurrencyFormat());
- CreditXML.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
- CreditXML.Append("");
+ StringBuilder creditXml = new StringBuilder(GetXmlStringIfApplicable());
+ creditXml.Append("");
+ creditXml.AppendFormat("{0}", amount.ToChargifyCurrencyFormat());
+ creditXml.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
+ creditXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/credits.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, CreditXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/credits.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, creditXml.ToString());
// change the response to the object
return response.ConvertResponseTo("credit");
}
@@ -3725,23 +3737,23 @@ public ICredit CreateCredit(int SubscriptionID, decimal amount, string memo)
///
/// Method to update the allocated amount of a component for a subscription
///
- /// The ID of the subscription to modify the allocation for
- /// The ID of the component
- /// The amount of component to allocate to the subscription
+ /// The ID of the subscription to modify the allocation for
+ /// The ID of the component
+ /// The amount of component to allocate to the subscription
/// The ComponentAttributes object with UnitBalance filled in, null otherwise.
- public IComponentAttributes UpdateComponentAllocationForSubscription(int SubscriptionID, int ComponentID, int NewAllocatedQuantity)
+ public IComponentAttributes UpdateComponentAllocationForSubscription(int subscriptionId, int componentId, int newAllocatedQuantity)
{
// make sure data is valid
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (ComponentID == int.MinValue) throw new ArgumentNullException("ComponentID");
- if (NewAllocatedQuantity < 0) throw new ArgumentOutOfRangeException("NewAllocatedQuantity");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (componentId == int.MinValue) throw new ArgumentNullException("componentId");
+ if (newAllocatedQuantity < 0) throw new ArgumentOutOfRangeException("newAllocatedQuantity");
// create XML for change of allocation
- StringBuilder AllocationXML = new StringBuilder(GetXMLStringIfApplicable());
- AllocationXML.Append("");
- AllocationXML.AppendFormat("{0}", NewAllocatedQuantity);
- AllocationXML.Append("");
+ StringBuilder allocationXml = new StringBuilder(GetXmlStringIfApplicable());
+ allocationXml.Append("");
+ allocationXml.AppendFormat("{0}", newAllocatedQuantity);
+ allocationXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/components/{1}.{2}", SubscriptionID, ComponentID, GetMethodExtension()), HttpRequestMethod.Put, AllocationXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/components/{1}.{2}", subscriptionId, componentId, GetMethodExtension()), HttpRequestMethod.Put, allocationXml.ToString());
// change the response to the object
return response.ConvertResponseTo("component");
}
@@ -3749,16 +3761,16 @@ public IComponentAttributes UpdateComponentAllocationForSubscription(int Subscri
///
/// Method to retrieve the current information (including allocation) of a component against a subscription
///
- /// The ID of the subscription in question
- /// The ID of the component
+ /// The ID of the subscription in question
+ /// The ID of the component
/// The ComponentAttributes object, null otherwise.
- public IComponentAttributes GetComponentInfoForSubscription(int SubscriptionID, int ComponentID)
+ public IComponentAttributes GetComponentInfoForSubscription(int subscriptionId, int componentId)
{
// make sure data is valid
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (ComponentID == int.MinValue) throw new ArgumentNullException("ComponentID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (componentId == int.MinValue) throw new ArgumentNullException("componentId");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/components/{1}.{2}", SubscriptionID, ComponentID, GetMethodExtension()));
+ string response = DoRequest(string.Format("subscriptions/{0}/components/{1}.{2}", subscriptionId, componentId, GetMethodExtension()));
// change the response to the object
return response.ConvertResponseTo("component");
}
@@ -3766,15 +3778,15 @@ public IComponentAttributes GetComponentInfoForSubscription(int SubscriptionID,
///
/// Returns all components "attached" to that subscription.
///
- /// The ID of the subscription to query about
+ /// The ID of the subscription to query about
/// A dictionary of components, if applicable.
- public IDictionary GetComponentsForSubscription(int SubscriptionID)
+ public IDictionary GetComponentsForSubscription(int subscriptionId)
{
// make sure data is valid
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/components.{1}", SubscriptionID, GetMethodExtension()));
+ string response = DoRequest(string.Format("subscriptions/{0}/components.{1}", subscriptionId, GetMethodExtension()));
var retValue = new Dictionary();
if (response.IsXml())
{
@@ -3792,10 +3804,10 @@ public IDictionary GetComponentsForSubscription(int S
{
if (componentNode.Name == "component")
{
- IComponentAttributes LoadedComponent = new ComponentAttributes(componentNode);
- if (!retValue.ContainsKey(LoadedComponent.ComponentID))
+ IComponentAttributes loadedComponent = new ComponentAttributes(componentNode);
+ if (!retValue.ContainsKey(loadedComponent.ComponentID))
{
- retValue.Add(LoadedComponent.ComponentID, LoadedComponent);
+ retValue.Add(loadedComponent.ComponentID, loadedComponent);
}
else
{
@@ -3813,13 +3825,14 @@ public IDictionary GetComponentsForSubscription(int S
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("component"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("component"))
{
JsonObject componentObj = (array.Items[i] as JsonObject)["component"] as JsonObject;
- IComponentAttributes LoadedComponent = new ComponentAttributes(componentObj);
- if (!retValue.ContainsKey(LoadedComponent.ComponentID))
+ IComponentAttributes loadedComponent = new ComponentAttributes(componentObj);
+ if (!retValue.ContainsKey(loadedComponent.ComponentID))
{
- retValue.Add(LoadedComponent.ComponentID, LoadedComponent);
+ retValue.Add(loadedComponent.ComponentID, loadedComponent);
}
else
{
@@ -3835,16 +3848,16 @@ public IDictionary GetComponentsForSubscription(int S
///
/// Method for getting a list of components for a specific product family
///
- /// The product family ID
+ /// The product family ID
/// Filter flag for archived components
/// A dictionary of components if there are results, null otherwise.
- public IDictionary GetComponentsForProductFamily(int ChargifyID, bool includeArchived)
+ public IDictionary GetComponentsForProductFamily(int chargifyId, bool includeArchived)
{
// make sure data is valid
- if (ChargifyID == int.MinValue) throw new ArgumentNullException("ChargifyID");
+ if (chargifyId == int.MinValue) throw new ArgumentNullException("chargifyId");
// now make the request
- string response = this.DoRequest(string.Format("product_families/{0}/components.{1}?include_archived={2}", ChargifyID, GetMethodExtension(), includeArchived ? "1" : "0"));
+ string response = DoRequest(string.Format("product_families/{0}/components.{1}?include_archived={2}", chargifyId, GetMethodExtension(), includeArchived ? "1" : "0"));
var retValue = new Dictionary();
if (response.IsXml())
{
@@ -3862,10 +3875,10 @@ public IDictionary GetComponentsForProductFamily(int Chargi
{
if (componentNode.Name == "component")
{
- IComponentInfo LoadedComponent = new ComponentInfo(componentNode);
- if (!retValue.ContainsKey(LoadedComponent.ID))
+ IComponentInfo loadedComponent = new ComponentInfo(componentNode);
+ if (!retValue.ContainsKey(loadedComponent.ID))
{
- retValue.Add(LoadedComponent.ID, LoadedComponent);
+ retValue.Add(loadedComponent.ID, loadedComponent);
}
else
{
@@ -3883,13 +3896,14 @@ public IDictionary GetComponentsForProductFamily(int Chargi
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("component"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("component"))
{
JsonObject componentObj = (array.Items[i] as JsonObject)["component"] as JsonObject;
- IComponentInfo LoadedComponent = new ComponentInfo(componentObj);
- if (!retValue.ContainsKey(LoadedComponent.ID))
+ IComponentInfo loadedComponent = new ComponentInfo(componentObj);
+ if (!retValue.ContainsKey(loadedComponent.ID))
{
- retValue.Add(LoadedComponent.ID, LoadedComponent);
+ retValue.Add(loadedComponent.ID, loadedComponent);
}
else
{
@@ -3905,35 +3919,35 @@ public IDictionary GetComponentsForProductFamily(int Chargi
///
/// Method for getting a list of components for a specific product family
///
- /// The product family ID
+ /// The product family ID
/// A dictionary of components if there are results, null otherwise.
- public IDictionary GetComponentsForProductFamily(int ChargifyID)
+ public IDictionary GetComponentsForProductFamily(int chargifyId)
{
- return GetComponentsForProductFamily(ChargifyID, false);
+ return GetComponentsForProductFamily(chargifyId, false);
}
///
/// Method for getting a list of component usages for a specific subscription
///
- /// The subscription ID to examine
- /// The ID of the component to examine
+ /// The subscription ID to examine
+ /// The ID of the component to examine
/// A dictionary of usages if there are results, null otherwise.
- public IDictionary GetComponentList(int SubscriptionID, int ComponentID)
+ public IDictionary GetComponentList(int subscriptionId, int componentId)
{
// make sure data is valid
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (ComponentID == int.MinValue) throw new ArgumentNullException("ComponentID");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException("subscriptionId");
+ if (componentId == int.MinValue) throw new ArgumentNullException("componentId");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/components/{1}/usages.{2}", SubscriptionID, ComponentID, GetMethodExtension()));
+ string response = DoRequest(string.Format("subscriptions/{0}/components/{1}/usages.{2}", subscriptionId, componentId, GetMethodExtension()));
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a product list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response); // get the XML into an XML document
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response); // get the XML into an XML document
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "usages")
{
@@ -3941,10 +3955,10 @@ public IDictionary GetComponentList(int SubscriptionID, int
{
if (usageNode.Name == "usage")
{
- IComponent LoadedComponent = new Component(usageNode);
- if (!retValue.ContainsKey(LoadedComponent.ID))
+ IComponent loadedComponent = new Component(usageNode);
+ if (!retValue.ContainsKey(loadedComponent.ID))
{
- retValue.Add(LoadedComponent.ID, LoadedComponent);
+ retValue.Add(loadedComponent.ID, loadedComponent);
}
else
{
@@ -3962,13 +3976,14 @@ public IDictionary GetComponentList(int SubscriptionID, int
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("component"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("component"))
{
JsonObject componentObj = (array.Items[i] as JsonObject)["component"] as JsonObject;
- IComponent LoadedComponent = new Component(componentObj);
- if (!retValue.ContainsKey(LoadedComponent.ID))
+ IComponent loadedComponent = new Component(componentObj);
+ if (!retValue.ContainsKey(loadedComponent.ID))
{
- retValue.Add(LoadedComponent.ID, LoadedComponent);
+ retValue.Add(loadedComponent.ID, loadedComponent);
}
else
{
@@ -3984,25 +3999,25 @@ public IDictionary GetComponentList(int SubscriptionID, int
///
/// Method for adding a metered component usage to the subscription
///
- /// The subscriptionID to modify
- /// The ID of the (metered or quantity) component to add a usage of
- /// The number of usages to add
- /// The memo for the usage
+ /// The subscriptionID to modify
+ /// The ID of the (metered or quantity) component to add a usage of
+ /// The number of usages to add
+ /// The memo for the usage
/// The usage added if successful, otherwise null.
- public IUsage AddUsage(int SubscriptionID, int ComponentID, int Quantity, string Memo)
+ public IUsage AddUsage(int subscriptionId, int componentId, int quantity, string memo)
{
// Chargify DOES currently allow a negative value for "quantity", so allow users to call this method that way.
//if (Quantity < 0) throw new ArgumentNullException("Quantity");
- if (string.IsNullOrEmpty(Memo)) throw new ArgumentNullException("Memo");
+ if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException("memo");
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", "subscriptionId");
// create XML for addition of usage
- StringBuilder UsageXML = new StringBuilder(GetXMLStringIfApplicable());
- UsageXML.Append("");
- UsageXML.AppendFormat("{0}", Quantity);
- UsageXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Memo));
- UsageXML.Append("");
- string response = this.DoRequest(string.Format("subscriptions/{0}/components/{1}/usages.{2}", SubscriptionID, ComponentID, GetMethodExtension()), HttpRequestMethod.Post, UsageXML.ToString());
+ StringBuilder usageXml = new StringBuilder(GetXmlStringIfApplicable());
+ usageXml.Append("");
+ usageXml.AppendFormat("{0}", quantity);
+ usageXml.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
+ usageXml.Append("");
+ string response = DoRequest(string.Format("subscriptions/{0}/components/{1}/usages.{2}", subscriptionId, componentId, GetMethodExtension()), HttpRequestMethod.Post, usageXml.ToString());
// change the response to the object
return response.ConvertResponseTo("usage");
}
@@ -4010,23 +4025,23 @@ public IUsage AddUsage(int SubscriptionID, int ComponentID, int Quantity, string
///
/// Method for turning on or off a component
///
- /// The ID of the subscription to modify
- /// The ID of the component (on/off only) to modify
- /// True if wanting to turn the component "on", false otherwise.
+ /// The ID of the subscription to modify
+ /// The ID of the component (on/off only) to modify
+ /// True if wanting to turn the component "on", false otherwise.
/// IComponentAttributes object if successful, null otherwise.
- public IComponentAttributes SetComponent(int SubscriptionID, int ComponentID, bool SetEnabled)
+ public IComponentAttributes SetComponent(int subscriptionId, int componentId, bool setEnabled)
{
try
{
- if (ComponentID == int.MinValue) throw new ArgumentException("Not an ComponentID", "ComponentID");
+ if (componentId == int.MinValue) throw new ArgumentException("Not an ComponentID", "componentId");
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", "subscriptionId");
// create XML for addition of usage
- StringBuilder ComponentXML = new StringBuilder(GetXMLStringIfApplicable());
- ComponentXML.Append("");
- ComponentXML.AppendFormat("{0}", SetEnabled.ToString(CultureInfo.InvariantCulture));
- ComponentXML.Append("");
- string response = this.DoRequest(string.Format("subscriptions/{0}/components/{1}.{2}", SubscriptionID, ComponentID, GetMethodExtension()), HttpRequestMethod.Put, ComponentXML.ToString());
+ StringBuilder componentXml = new StringBuilder(GetXmlStringIfApplicable());
+ componentXml.Append("");
+ componentXml.AppendFormat("{0}", setEnabled.ToString(CultureInfo.InvariantCulture));
+ componentXml.Append("");
+ string response = DoRequest(string.Format("subscriptions/{0}/components/{1}.{2}", subscriptionId, componentId, GetMethodExtension()), HttpRequestMethod.Put, componentXml.ToString());
return response.ConvertResponseTo("component");
}
catch (ChargifyException cex)
@@ -4042,26 +4057,26 @@ public IComponentAttributes SetComponent(int SubscriptionID, int ComponentID, bo
///
/// Returns the 50 most recent Allocations, ordered by most recent first.
///
- /// The subscriptionID to scope this request
- /// The componentID to scope this request
- /// Pass an integer in the page parameter via the query string to access subsequent pages of 50 transactions
+ /// The subscriptionID to scope this request
+ /// The componentID to scope this request
+ /// Pass an integer in the page parameter via the query string to access subsequent pages of 50 transactions
/// A dictionary of allocation objects keyed by ComponentID, or null.
- public IDictionary> GetAllocationListForSubscriptionComponent(int SubscriptionID, int ComponentID, int? Page = 0)
+ public IDictionary> GetAllocationListForSubscriptionComponent(int subscriptionId, int componentId, int? page = 0)
{
// make sure data is valid
- if (SubscriptionID == int.MinValue) throw new ArgumentNullException("SubscriptionID");
- if (Page.HasValue && Page.Value < 0) throw new ArgumentOutOfRangeException("Page number must be a positive integer", "Page");
+ if (subscriptionId == int.MinValue) throw new ArgumentNullException(nameof(subscriptionId));
+ if (page.HasValue && page.Value < 0) throw new ArgumentOutOfRangeException(nameof(page), "Page number must be a positive integer");
try
{
string qs = string.Empty;
// Add the request options to the query string
- if (Page.Value > 0) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("page={0}", Page); }
+ if (page != null && page.Value > 0) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("page={0}", page); }
// now make the request
- string url = string.Format("subscriptions/{0}/components/{1}/allocations.{2}", SubscriptionID, ComponentID, GetMethodExtension());
+ string url = string.Format("subscriptions/{0}/components/{1}/allocations.{2}", subscriptionId, componentId, GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new Dictionary>();
if (response.IsXml())
{
@@ -4085,9 +4100,9 @@ public IDictionary> GetAllocationListForSubscrip
}
}
- if (!retValue.ContainsKey(ComponentID) && childComponentAllocations.Count > 0)
+ if (!retValue.ContainsKey(componentId) && childComponentAllocations.Count > 0)
{
- retValue.Add(ComponentID, childComponentAllocations);
+ retValue.Add(componentId, childComponentAllocations);
}
}
}
@@ -4100,7 +4115,8 @@ public IDictionary> GetAllocationListForSubscrip
List childComponentAllocations = new List();
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey(ComponentAllocation.AllocationRootKey))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey(ComponentAllocation.AllocationRootKey))
{
JsonObject componentObj = (array.Items[i] as JsonObject)[ComponentAllocation.AllocationRootKey] as JsonObject;
IComponentAllocation loadedComponentAllocation = new ComponentAllocation(componentObj);
@@ -4108,9 +4124,9 @@ public IDictionary> GetAllocationListForSubscrip
}
}
- if (!retValue.ContainsKey(ComponentID) && childComponentAllocations.Count > 0)
+ if (!retValue.ContainsKey(componentId) && childComponentAllocations.Count > 0)
{
- retValue.Add(ComponentID, childComponentAllocations);
+ retValue.Add(componentId, childComponentAllocations);
}
}
// return the dictionary
@@ -4121,68 +4137,64 @@ public IDictionary> GetAllocationListForSubscrip
if (cEx.StatusCode == HttpStatusCode.NotFound) return null;
throw;
}
- catch (Exception)
- {
- throw;
- }
}
///
/// Creates a new Allocation, setting the current allocated quantity for the component and recording a memo.
///
- ///
- ///
- ///
+ ///
+ ///
+ ///
///
- public IComponentAllocation CreateComponentAllocation(int SubscriptionID, int ComponentID, ComponentAllocation Allocation)
+ public IComponentAllocation CreateComponentAllocation(int subscriptionId, int componentId, ComponentAllocation allocation)
{
- if (Allocation == null) throw new ArgumentNullException("Allocation");
- return CreateComponentAllocation(SubscriptionID, ComponentID, Allocation.Quantity, Allocation.Memo, Allocation.UpgradeScheme, Allocation.DowngradeScheme);
+ if (allocation == null) throw new ArgumentNullException("allocation");
+ return CreateComponentAllocation(subscriptionId, componentId, allocation.Quantity, allocation.Memo, allocation.UpgradeScheme, allocation.DowngradeScheme);
}
///
/// Creates a new Allocation, setting the current allocated quantity for the component and recording a memo.
///
- /// The ID of the subscription to apply this quantity allocation to
- /// The ID of the component to apply this quantity allocation to
- /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
+ /// The ID of the subscription to apply this quantity allocation to
+ /// The ID of the component to apply this quantity allocation to
+ /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
///
- public IComponentAllocation CreateComponentAllocation(int SubscriptionID, int ComponentID, int Quantity)
+ public IComponentAllocation CreateComponentAllocation(int subscriptionId, int componentId, int quantity)
{
- return CreateComponentAllocation(SubscriptionID, ComponentID, Quantity, string.Empty, ComponentUpgradeProrationScheme.Unknown, ComponentDowngradeProrationScheme.Unknown);
+ return CreateComponentAllocation(subscriptionId, componentId, quantity, string.Empty, ComponentUpgradeProrationScheme.Unknown, ComponentDowngradeProrationScheme.Unknown);
}
///
/// Creates a new Allocation, setting the current allocated quantity for the component and recording a memo.
///
- /// The ID of the subscription to apply this quantity allocation to
- /// The ID of the component to apply this quantity allocation to
- /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
- /// (optional) A memo to record along with the allocation
+ /// The ID of the subscription to apply this quantity allocation to
+ /// The ID of the component to apply this quantity allocation to
+ /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
+ /// (optional) A memo to record along with the allocation
///
- public IComponentAllocation CreateComponentAllocation(int SubscriptionID, int ComponentID, int Quantity, string Memo)
+ public IComponentAllocation CreateComponentAllocation(int subscriptionId, int componentId, int quantity, string memo)
{
- return CreateComponentAllocation(SubscriptionID, ComponentID, Quantity, Memo, ComponentUpgradeProrationScheme.Unknown, ComponentDowngradeProrationScheme.Unknown);
+ return CreateComponentAllocation(subscriptionId, componentId, quantity, memo, ComponentUpgradeProrationScheme.Unknown, ComponentDowngradeProrationScheme.Unknown);
}
///
/// Creates a new Allocation, setting the current allocated quantity for the component and recording a memo.
///
- /// The ID of the subscription to apply this quantity allocation to
- /// The ID of the component to apply this quantity allocation to
- /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
- /// (optional) A memo to record along with the allocation
- /// (optional) The scheme used if the proration is an upgrade. Defaults to the site setting if one is not provided.
- /// (optional) The scheme used if the proration is a downgrade. Defaults to the site setting if one is not provided.
+ /// The ID of the subscription to apply this quantity allocation to
+ /// The ID of the component to apply this quantity allocation to
+ /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
+ /// (optional) A memo to record along with the allocation
+ /// (optional) The scheme used if the proration is an upgrade. Defaults to the site setting if one is not provided.
+ /// (optional) The scheme used if the proration is a downgrade. Defaults to the site setting if one is not provided.
/// The component allocation object, null otherwise.
- public IComponentAllocation CreateComponentAllocation(int SubscriptionID, int ComponentID, int Quantity, string Memo, ComponentUpgradeProrationScheme UpgradeScheme, ComponentDowngradeProrationScheme DowngradeScheme)
+ public IComponentAllocation CreateComponentAllocation(int subscriptionId, int componentId, int quantity, string memo, ComponentUpgradeProrationScheme upgradeScheme, ComponentDowngradeProrationScheme downgradeScheme)
{
try
{
- string xml = BuildComponentAllocationXML(Quantity, Memo, UpgradeScheme, DowngradeScheme);
+ string xml = BuildComponentAllocationXml(quantity, memo, upgradeScheme, downgradeScheme);
// perform the request, keep the response
- string response = this.DoRequest(string.Format("subscriptions/{0}/components/{1}/allocations.{2}", SubscriptionID, ComponentID, GetMethodExtension()), HttpRequestMethod.Post, xml);
+ string response = DoRequest(string.Format("subscriptions/{0}/components/{1}/allocations.{2}", subscriptionId, componentId, GetMethodExtension()), HttpRequestMethod.Post, xml);
// change the response to the object
return response.ConvertResponseTo("allocation");
@@ -4192,40 +4204,40 @@ public IComponentAllocation CreateComponentAllocation(int SubscriptionID, int Co
if (cEx.StatusCode == HttpStatusCode.NotFound) return null;
throw;
}
- catch (Exception)
- {
- throw;
- }
}
///
/// Constructs the XML needed to create a component allocation
///
- /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
- /// (optional) A memo to record along with the allocation
- /// (optional) The scheme used if the proration is an upgrade. Defaults to the site setting if one is not provided.
- /// (optional) The scheme used if the proration is a downgrade. Defaults to the site setting if one is not provided.
+ /// The allocated quantity to which to set the line-items allocated quantity. This should always be an integer. For On/Off components, use 1 for on and 0 for off.
+ /// (optional) A memo to record along with the allocation
+ /// (optional) The scheme used if the proration is an upgrade. Defaults to the site setting if one is not provided.
+ /// (optional) The scheme used if the proration is a downgrade. Defaults to the site setting if one is not provided.
/// The formatted XML
- private string BuildComponentAllocationXML(int Quantity, string Memo, ComponentUpgradeProrationScheme UpgradeScheme, ComponentDowngradeProrationScheme DowngradeScheme)
+ private string BuildComponentAllocationXml(int quantity, string memo, ComponentUpgradeProrationScheme upgradeScheme, ComponentDowngradeProrationScheme downgradeScheme)
{
// make sure data is valid
- if (Quantity < 0 && !Quantity.Equals(int.MinValue)) throw new ArgumentOutOfRangeException("Quantity", Quantity, "Quantity must be valid");
+ if (quantity < 0 && !quantity.Equals(int.MinValue)) throw new ArgumentOutOfRangeException("quantity", quantity, "Quantity must be valid");
// create XML for creation of a ComponentAllocation
- StringBuilder ComponentAllocationXML = new StringBuilder(GetXMLStringIfApplicable());
- ComponentAllocationXML.Append("");
- ComponentAllocationXML.Append(string.Format("{0}", Quantity));
- if (!string.IsNullOrEmpty(Memo)) { ComponentAllocationXML.Append(string.Format("{0}", HttpUtility.HtmlEncode(Memo))); }
- if (UpgradeScheme != ComponentUpgradeProrationScheme.Unknown)
+ StringBuilder componentAllocationXml = new StringBuilder(GetXmlStringIfApplicable());
+ componentAllocationXml.Append("");
+ componentAllocationXml.Append(string.Format("{0}", quantity));
+ if (!string.IsNullOrEmpty(memo)) { componentAllocationXml.Append(string.Format("{0}", HttpUtility.HtmlEncode(memo))); }
+ if (upgradeScheme != ComponentUpgradeProrationScheme.Unknown)
{
- ComponentAllocationXML.Append(string.Format("{0}", Enum.GetName(typeof(ComponentUpgradeProrationScheme), UpgradeScheme).ToLowerInvariant().Replace("_", "-")));
+ var componentUpgradeProrationSchemeName = Enum.GetName(typeof(ComponentUpgradeProrationScheme), upgradeScheme);
+ if (componentUpgradeProrationSchemeName != null)
+ componentAllocationXml.Append(string.Format("{0}", componentUpgradeProrationSchemeName.ToLowerInvariant().Replace("_", "-")));
}
- if (DowngradeScheme != ComponentDowngradeProrationScheme.Unknown)
+ if (downgradeScheme != ComponentDowngradeProrationScheme.Unknown)
{
- ComponentAllocationXML.Append(string.Format("{0}", Enum.GetName(typeof(ComponentDowngradeProrationScheme), DowngradeScheme).ToLowerInvariant().Replace("_", "-")));
+ var componentDowngradeProrationSchemeName = Enum.GetName(typeof(ComponentDowngradeProrationScheme), downgradeScheme);
+ if (componentDowngradeProrationSchemeName != null)
+ componentAllocationXml.Append(string.Format("{0}", componentDowngradeProrationSchemeName.ToLowerInvariant().Replace("_", "-")));
}
- ComponentAllocationXML.Append("");
- return ComponentAllocationXML.ToString();
+ componentAllocationXml.Append("");
+ return componentAllocationXml.ToString();
}
#endregion
@@ -4254,83 +4266,83 @@ public IDictionary GetTransactionList(List k
/// Method for getting a list of transactions
///
/// A list of transaction types to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
/// The dictionary of transaction records if successful, otherwise null.
- public IDictionary GetTransactionList(List kinds, int since_id, int max_id)
+ public IDictionary GetTransactionList(List kinds, int sinceId, int maxId)
{
- return GetTransactionList(int.MinValue, int.MinValue, kinds, since_id, max_id, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionList(int.MinValue, int.MinValue, kinds, sinceId, maxId, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting a list of transactions
///
/// A list of transaction types to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
- /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
- /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
+ /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
/// The dictionary of transaction records if successful, otherwise null.
- public IDictionary GetTransactionList(List kinds, int since_id, int max_id, DateTime since_date, DateTime until_date)
+ public IDictionary GetTransactionList(List kinds, int sinceId, int maxId, DateTime sinceDate, DateTime untilDate)
{
- return GetTransactionList(int.MinValue, int.MinValue, kinds, since_id, max_id, since_date, until_date);
+ return GetTransactionList(int.MinValue, int.MinValue, kinds, sinceId, maxId, sinceDate, untilDate);
}
///
/// Method for getting a list of transactions
///
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// The dictionary of transaction records if successful, otherwise null.
- public IDictionary GetTransactionList(int page, int per_page)
+ public IDictionary GetTransactionList(int page, int perPage)
{
- return GetTransactionList(page, per_page, null, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionList(page, perPage, null, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting a list of transactions
///
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A list of the types of transactions to return.
/// The dictionary of transaction records if successful, otherwise null.
- public IDictionary GetTransactionList(int page, int per_page, List kinds)
+ public IDictionary GetTransactionList(int page, int perPage, List kinds)
{
- return GetTransactionList(page, per_page, kinds, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionList(page, perPage, kinds, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting a list of transactions
///
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A list of transaction types to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
/// The dictionary of transaction records if successful, otherwise null.
- public IDictionary GetTransactionList(int page, int per_page, List kinds, int since_id, int max_id)
+ public IDictionary GetTransactionList(int page, int perPage, List kinds, int sinceId, int maxId)
{
- return GetTransactionList(page, per_page, kinds, since_id, max_id, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionList(page, perPage, kinds, sinceId, maxId, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting a list of transactions
///
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A list of transaction types to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
- /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
- /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
+ /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
/// The dictionary of transaction records if successful, otherwise null.
- public IDictionary GetTransactionList(int page, int per_page, List kinds, int since_id, int max_id, DateTime since_date, DateTime until_date)
+ public IDictionary GetTransactionList(int page, int perPage, List kinds, int sinceId, int maxId, DateTime sinceDate, DateTime untilDate)
{
string qs = string.Empty;
// Add the transaction options to the query string ...
if (page != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("page={0}", page); }
- if (per_page != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("per_page={0}", per_page); }
+ if (perPage != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("per_page={0}", perPage); }
if (kinds != null)
{
@@ -4345,25 +4357,25 @@ public IDictionary GetTransactionList(int page, int per_page,
}
}
- if (since_id != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_id={0}", since_id); }
- if (max_id != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("max_id={0}", max_id); }
- if (since_date != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_date={0}", since_date.ToString(DateTimeFormat)); }
- if (until_date != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("until_date={0}", until_date.ToString(DateTimeFormat)); }
+ if (sinceId != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_id={0}", sinceId); }
+ if (maxId != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("max_id={0}", maxId); }
+ if (sinceDate != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_date={0}", sinceDate.ToString(DateTimeFormat)); }
+ if (untilDate != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("until_date={0}", untilDate.ToString(DateTimeFormat)); }
// Construct the url to access Chargify
string url = string.Format("transactions.{0}", GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a transaction list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "transactions")
{
@@ -4371,10 +4383,10 @@ public IDictionary GetTransactionList(int page, int per_page,
{
if (transactionNode.Name == "transaction")
{
- ITransaction LoadedTransaction = new Transaction(transactionNode);
- if (!retValue.ContainsKey(LoadedTransaction.ID))
+ ITransaction loadedTransaction = new Transaction(transactionNode);
+ if (!retValue.ContainsKey(loadedTransaction.ID))
{
- retValue.Add(LoadedTransaction.ID, LoadedTransaction);
+ retValue.Add(loadedTransaction.ID, loadedTransaction);
}
else
{
@@ -4392,13 +4404,14 @@ public IDictionary GetTransactionList(int page, int per_page,
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("transaction"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("transaction"))
{
JsonObject transactionObj = (array.Items[i] as JsonObject)["transaction"] as JsonObject;
- ITransaction LoadedTransaction = new Transaction(transactionObj);
- if (!retValue.ContainsKey(LoadedTransaction.ID))
+ ITransaction loadedTransaction = new Transaction(transactionObj);
+ if (!retValue.ContainsKey(loadedTransaction.ID))
{
- retValue.Add(LoadedTransaction.ID, LoadedTransaction);
+ retValue.Add(loadedTransaction.ID, loadedTransaction);
}
else
{
@@ -4414,107 +4427,107 @@ public IDictionary GetTransactionList(int page, int per_page,
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId)
{
- if (SubscriptionID < 0) throw new ArgumentNullException("SubscriptionID");
+ if (subscriptionId < 0) throw new ArgumentNullException("subscriptionId");
- return GetTransactionsForSubscription(SubscriptionID, int.MinValue, int.MinValue, null, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, int.MinValue, int.MinValue, null, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// A list of the types of transactions to return.
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, List kinds)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, List kinds)
{
- return GetTransactionsForSubscription(SubscriptionID, int.MinValue, int.MinValue, kinds, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, int.MinValue, int.MinValue, kinds, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// A list of the types of transactions to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, List kinds, int since_id, int max_id)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, List kinds, int sinceId, int maxId)
{
- return GetTransactionsForSubscription(SubscriptionID, int.MinValue, int.MinValue, kinds, since_id, max_id, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, int.MinValue, int.MinValue, kinds, sinceId, maxId, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// A list of the types of transactions to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
- /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
- /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
+ /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, List kinds, int since_id, int max_id, DateTime since_date, DateTime until_date)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, List kinds, int sinceId, int maxId, DateTime sinceDate, DateTime untilDate)
{
- return GetTransactionsForSubscription(SubscriptionID, int.MinValue, int.MinValue, kinds, since_id, max_id, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, int.MinValue, int.MinValue, kinds, sinceId, maxId, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, int page, int per_page)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, int page, int perPage)
{
- return GetTransactionsForSubscription(SubscriptionID, page, per_page, null, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, page, perPage, null, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A list of the types of transactions to return.
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, int page, int per_page, List kinds)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, int page, int perPage, List kinds)
{
- return GetTransactionsForSubscription(SubscriptionID, page, per_page, kinds, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, page, perPage, kinds, int.MinValue, int.MinValue, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A list of the types of transactions to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, int page, int per_page, List kinds, int since_id, int max_id)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, int page, int perPage, List kinds, int sinceId, int maxId)
{
- return GetTransactionsForSubscription(SubscriptionID, page, per_page, kinds, since_id, max_id, DateTime.MinValue, DateTime.MinValue);
+ return GetTransactionsForSubscription(subscriptionId, page, perPage, kinds, sinceId, maxId, DateTime.MinValue, DateTime.MinValue);
}
///
/// Method for getting the list of transactions for a subscription
///
- /// The subscriptionID to get a list of transactions for
+ /// The subscriptionID to get a list of transactions for
/// The page number
- /// The number of results per page (used for pagination)
+ /// The number of results per page (used for pagination)
/// A list of the types of transactions to return.
- /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
- /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
- /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
- /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
+ /// Returns transactions with an ID greater than or equal to the one specified. Use int.MinValue to not specify a since_id.
+ /// Returns transactions with an id less than or equal to the one specified. Use int.MinValue to not specify a max_id.
+ /// Returns transactions with a created_at date greater than or equal to the one specified. Use DateTime.MinValue to not specify a since_date.
+ /// Returns transactions with a created_at date less than or equal to the one specified. Use DateTime.MinValue to not specify an until_date.
/// A dictionary of transactions if successful, otherwise null.
- public IDictionary GetTransactionsForSubscription(int SubscriptionID, int page, int per_page, List kinds, int since_id, int max_id, DateTime since_date, DateTime until_date)
+ public IDictionary GetTransactionsForSubscription(int subscriptionId, int page, int perPage, List kinds, int sinceId, int maxId, DateTime sinceDate, DateTime untilDate)
{
string qs = string.Empty;
@@ -4524,10 +4537,10 @@ public IDictionary GetTransactionsForSubscription(int Subscri
qs += string.Format("page={0}", page);
}
- if (per_page != int.MinValue)
+ if (perPage != int.MinValue)
{
if (qs.Length > 0) { qs += "&"; }
- qs += string.Format("per_page={0}", per_page);
+ qs += string.Format("per_page={0}", perPage);
}
if (kinds != null)
@@ -4543,24 +4556,24 @@ public IDictionary GetTransactionsForSubscription(int Subscri
}
}
- if (since_id != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_id={0}", since_id); }
- if (max_id != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("max_id={0}", max_id); }
- if (since_date != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_date={0}", since_date.ToString(DateTimeFormat)); }
- if (until_date != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("until_date={0}", until_date.ToString(DateTimeFormat)); }
+ if (sinceId != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_id={0}", sinceId); }
+ if (maxId != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("max_id={0}", maxId); }
+ if (sinceDate != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("since_date={0}", sinceDate.ToString(DateTimeFormat)); }
+ if (untilDate != DateTime.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("until_date={0}", untilDate.ToString(DateTimeFormat)); }
// now make the request
- string url = string.Format("subscriptions/{0}/transactions.{1}", SubscriptionID, GetMethodExtension());
+ string url = string.Format("subscriptions/{0}/transactions.{1}", subscriptionId, GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a transaction list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response); // get the XML into an XML document
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response); // get the XML into an XML document
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "transactions")
{
@@ -4568,10 +4581,10 @@ public IDictionary GetTransactionsForSubscription(int Subscri
{
if (transactionNode.Name == "transaction")
{
- ITransaction LoadedTransaction = new Transaction(transactionNode);
- if (!retValue.ContainsKey(LoadedTransaction.ID))
+ ITransaction loadedTransaction = new Transaction(transactionNode);
+ if (!retValue.ContainsKey(loadedTransaction.ID))
{
- retValue.Add(LoadedTransaction.ID, LoadedTransaction);
+ retValue.Add(loadedTransaction.ID, loadedTransaction);
}
else
{
@@ -4589,13 +4602,14 @@ public IDictionary GetTransactionsForSubscription(int Subscri
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i < array.Length; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("transaction"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("transaction"))
{
JsonObject transactionObj = (array.Items[i] as JsonObject)["transaction"] as JsonObject;
- ITransaction LoadedTransaction = new Transaction(transactionObj);
- if (!retValue.ContainsKey(LoadedTransaction.ID))
+ ITransaction loadedTransaction = new Transaction(transactionObj);
+ if (!retValue.ContainsKey(loadedTransaction.ID))
{
- retValue.Add(LoadedTransaction.ID, LoadedTransaction);
+ retValue.Add(loadedTransaction.ID, loadedTransaction);
}
else
{
@@ -4611,16 +4625,16 @@ public IDictionary GetTransactionsForSubscription(int Subscri
///
/// Load the requested transaction from Chargify
///
- /// The ID of the transaction
+ /// The ID of the transaction
/// The transaction with the specified ID
- public ITransaction LoadTransaction(int ID)
+ public ITransaction LoadTransaction(int id)
{
try
{
// make sure data is valid
- if (ID < 0) throw new ArgumentNullException("ID");
+ if (id < 0) throw new ArgumentNullException("id");
// now make the request
- string response = this.DoRequest(string.Format("transactions/{0}.{1}", ID, GetMethodExtension()));
+ string response = DoRequest(string.Format("transactions/{0}.{1}", id, GetMethodExtension()));
// Convert the Chargify response into the object we're looking for
return response.ConvertResponseTo("transaction");
}
@@ -4637,39 +4651,39 @@ public ITransaction LoadTransaction(int ID)
///
/// Create a refund
///
- /// The ID of the subscription to modify
- /// The ID of the payment that the credit will be applied to
- /// The amount (in dollars and cents) like 10.00 is $10.00
- /// A helpful explanation for the refund.
+ /// The ID of the subscription to modify
+ /// The ID of the payment that the credit will be applied to
+ /// The amount (in dollars and cents) like 10.00 is $10.00
+ /// A helpful explanation for the refund.
/// The IRefund object indicating successful, or unsuccessful.
- public IRefund CreateRefund(int SubscriptionID, int PaymentID, decimal Amount, string Memo)
+ public IRefund CreateRefund(int subscriptionId, int paymentId, decimal amount, string memo)
{
- int AmountInCents = Convert.ToInt32(Amount * 100);
- return CreateRefund(SubscriptionID, PaymentID, AmountInCents, Memo);
+ int amountInCents = Convert.ToInt32(amount * 100);
+ return CreateRefund(subscriptionId, paymentId, amountInCents, memo);
}
///
/// Create a refund
///
- /// The ID of the subscription to modify
- /// The ID of the payment that the credit will be applied to
- /// The amount (in cents only) like 100 is $1.00
- /// A helpful explanation for the refund.
+ /// The ID of the subscription to modify
+ /// The ID of the payment that the credit will be applied to
+ /// The amount (in cents only) like 100 is $1.00
+ /// A helpful explanation for the refund.
/// The IRefund object indicating successful, or unsuccessful.
- public IRefund CreateRefund(int SubscriptionID, int PaymentID, int AmountInCents, string Memo)
+ public IRefund CreateRefund(int subscriptionId, int paymentId, int amountInCents, string memo)
{
- if (AmountInCents < 0) throw new ArgumentNullException("AmountInCents");
- if (string.IsNullOrEmpty(Memo)) throw new ArgumentException("Can't have an empty memo", "Memo");
+ if (amountInCents < 0) throw new ArgumentNullException("amountInCents");
+ if (string.IsNullOrEmpty(memo)) throw new ArgumentException("Can't have an empty memo", "memo");
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", "subscriptionId");
// create XML for addition of refund
- StringBuilder RefundXML = new StringBuilder(GetXMLStringIfApplicable());
- RefundXML.Append("");
- RefundXML.AppendFormat("{0}", PaymentID);
- RefundXML.AppendFormat("{0}", AmountInCents);
- RefundXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Memo));
- RefundXML.Append("");
- string response = this.DoRequest(string.Format("subscriptions/{0}/refunds.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, RefundXML.ToString());
+ StringBuilder refundXml = new StringBuilder(GetXmlStringIfApplicable());
+ refundXml.Append("");
+ refundXml.AppendFormat("{0}", paymentId);
+ refundXml.AppendFormat("{0}", amountInCents);
+ refundXml.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
+ refundXml.Append("");
+ string response = DoRequest(string.Format("subscriptions/{0}/refunds.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, refundXml.ToString());
// change the response to the object
return response.ConvertResponseTo("refund");
}
@@ -4679,16 +4693,16 @@ public IRefund CreateRefund(int SubscriptionID, int PaymentID, int AmountInCents
///
/// Method for getting a specific statement
///
- /// The ID of the statement to retrieve
+ /// The ID of the statement to retrieve
/// The statement if found, null otherwise.
- public IStatement LoadStatement(int StatementID)
+ public IStatement LoadStatement(int statementId)
{
try
{
// make sure data is valid
- if (StatementID <= 0) throw new ArgumentNullException("StatementID");
+ if (statementId <= 0) throw new ArgumentNullException("statementId");
// now make the request
- string response = this.DoRequest(string.Format("statements/{0}.{1}", StatementID, GetMethodExtension()));
+ string response = DoRequest(string.Format("statements/{0}.{1}", statementId, GetMethodExtension()));
// Convert the Chargify response into the object we're looking for
return response.ConvertResponseTo("statement");
}
@@ -4702,17 +4716,17 @@ public IStatement LoadStatement(int StatementID)
///
/// Individual PDF Statements can be retrieved by using the Accept/Content-Type header application/pdf or appending .pdf as the format portion of the URL:
///
- /// The ID of the statement to retrieve the byte[] for
+ /// The ID of the statement to retrieve the byte[] for
/// A byte[] of the PDF data, to be sent to the user in a download
- public byte[] LoadStatementPDF(int StatementID)
+ public byte[] LoadStatementPDF(int statementId)
{
try
{
// make sure data is valid
- if (StatementID <= 0) throw new ArgumentNullException("StatementID");
+ if (statementId <= 0) throw new ArgumentNullException("statementId");
// now make the request
- byte[] response = this.DoFileRequest(string.Format("statements/{0}.pdf", StatementID), HttpRequestMethod.Get, string.Empty);
+ byte[] response = DoFileRequest(string.Format("statements/{0}.pdf", statementId), HttpRequestMethod.Get, string.Empty);
return response;
}
@@ -4726,53 +4740,53 @@ public byte[] LoadStatementPDF(int StatementID)
///
/// Method for getting a list of statment ids for a specific subscription
///
- /// The ID of the subscription to retrieve the statements for
+ /// The ID of the subscription to retrieve the statements for
/// The list of statements, an empty dictionary otherwise.
- public IList GetStatementIDs(int SubscriptionID)
+ public IList GetStatementIDs(int subscriptionId)
{
- return GetStatementIDs(SubscriptionID, int.MinValue, int.MinValue);
+ return GetStatementIDs(subscriptionId, int.MinValue, int.MinValue);
}
///
/// Method for getting a list of statment ids for a specific subscription
///
- /// The ID of the subscription to retrieve the statements for
+ /// The ID of the subscription to retrieve the statements for
/// The page number to return
- /// The number of results to return per page
+ /// The number of results to return per page
/// The list of statements, an empty dictionary otherwise.
- public IList GetStatementIDs(int SubscriptionID, int page, int per_page)
+ public IList GetStatementIDs(int subscriptionId, int page, int perPage)
{
string qs = string.Empty;
// Add the transaction options to the query string ...
if (page != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("page={0}", page); }
- if (per_page != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("per_page={0}", per_page); }
+ if (perPage != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("per_page={0}", perPage); }
// Construct the url to access Chargify
- string url = string.Format("subscriptions/{0}/statements/ids.{1}", SubscriptionID, GetMethodExtension());
+ string url = string.Format("subscriptions/{0}/statements/ids.{1}", subscriptionId, GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new List();
if (response.IsXml())
{
// now build a statement list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "statement_ids")
{
- foreach (XmlNode statementIDNode in elementNode.ChildNodes)
+ foreach (XmlNode statementIdNode in elementNode.ChildNodes)
{
- if (statementIDNode.Name == "id")
+ if (statementIdNode.Name == "id")
{
- int statementID = Convert.ToInt32(statementIDNode.InnerText);
- if (!retValue.Contains(statementID))
+ int statementId = Convert.ToInt32(statementIdNode.InnerText);
+ if (!retValue.Contains(statementId))
{
- retValue.Add(statementID);
+ retValue.Add(statementId);
}
else
{
@@ -4785,23 +4799,26 @@ public IList GetStatementIDs(int SubscriptionID, int page, int per_page)
}
else if (response.IsJSON())
{
- JsonObject statementIDSObj = JsonObject.Parse(response);
- if (!statementIDSObj.ContainsKey("statement_ids"))
+ JsonObject statementIdsObj = JsonObject.Parse(response);
+ if (!statementIdsObj.ContainsKey("statement_ids"))
throw new InvalidOperationException("Returned JSON not valid");
- JsonArray array = (statementIDSObj["statement_ids"]) as JsonArray;
- for (int i = 0; i <= array.Length - 1; i++)
+ JsonArray jsonArray = (statementIdsObj["statement_ids"]) as JsonArray;
+ if (jsonArray != null)
{
- JsonNumber statementIDValue = array.Items[i] as JsonNumber;
- if (statementIDValue == null)
- throw new InvalidOperationException("Statement ID is not a valid number");
- if (!retValue.Contains(statementIDValue.IntValue))
- {
- retValue.Add(statementIDValue.IntValue);
- }
- else
+ for (int i = 0; i <= jsonArray.Length - 1; i++)
{
- throw new InvalidOperationException("Duplicate ID values detected");
+ JsonNumber statementIdValue = jsonArray.Items[i] as JsonNumber;
+ if (statementIdValue == null)
+ throw new InvalidOperationException("Statement ID is not a valid number");
+ if (!retValue.Contains(statementIdValue.IntValue))
+ {
+ retValue.Add(statementIdValue.IntValue);
+ }
+ else
+ {
+ throw new InvalidOperationException("Duplicate ID values detected");
+ }
}
}
}
@@ -4812,42 +4829,42 @@ public IList GetStatementIDs(int SubscriptionID, int page, int per_page)
///
/// Method for getting a list of statments for a specific subscription
///
- /// The ID of the subscription to retrieve the statements for
+ /// The ID of the subscription to retrieve the statements for
/// The list of statements, an empty dictionary otherwise.
- public IDictionary GetStatementList(int SubscriptionID)
+ public IDictionary GetStatementList(int subscriptionId)
{
- return GetStatementList(SubscriptionID, int.MinValue, int.MinValue);
+ return GetStatementList(subscriptionId, int.MinValue, int.MinValue);
}
///
/// Method for getting a list of statments for a specific subscription
///
- /// The ID of the subscription to retrieve the statements for
+ /// The ID of the subscription to retrieve the statements for
/// The page number to return
- /// The number of results to return per page
+ /// The number of results to return per page
/// The list of statements, an empty dictionary otherwise.
- public IDictionary GetStatementList(int SubscriptionID, int page, int per_page)
+ public IDictionary GetStatementList(int subscriptionId, int page, int perPage)
{
string qs = string.Empty;
// Add the transaction options to the query string ...
if (page != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("page={0}", page); }
- if (per_page != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("per_page={0}", per_page); }
+ if (perPage != int.MinValue) { if (qs.Length > 0) { qs += "&"; } qs += string.Format("per_page={0}", perPage); }
// Construct the url to access Chargify
- string url = string.Format("subscriptions/{0}/statements.{1}", SubscriptionID, GetMethodExtension());
+ string url = string.Format("subscriptions/{0}/statements.{1}", subscriptionId, GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new Dictionary();
if (response.IsXml())
{
// now build a statement list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0) throw new InvalidOperationException("Returned XML not valid");
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "statements")
{
@@ -4855,10 +4872,10 @@ public IDictionary GetStatementList(int SubscriptionID, int pag
{
if (statementNode.Name == "statement")
{
- IStatement LoadedStatement = new Statement(statementNode);
- if (!retValue.ContainsKey(LoadedStatement.ID))
+ IStatement loadedStatement = new Statement(statementNode);
+ if (!retValue.ContainsKey(loadedStatement.ID))
{
- retValue.Add(LoadedStatement.ID, LoadedStatement);
+ retValue.Add(loadedStatement.ID, loadedStatement);
}
else
{
@@ -4876,13 +4893,14 @@ public IDictionary GetStatementList(int SubscriptionID, int pag
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("statement"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey("statement"))
{
JsonObject statementObj = (array.Items[i] as JsonObject)["statement"] as JsonObject;
- IStatement LoadedStatement = new Statement(statementObj);
- if (!retValue.ContainsKey(LoadedStatement.ID))
+ IStatement loadedStatement = new Statement(statementObj);
+ if (!retValue.ContainsKey(loadedStatement.ID))
{
- retValue.Add(LoadedStatement.ID, LoadedStatement);
+ retValue.Add(loadedStatement.ID, loadedStatement);
}
else
{
@@ -4903,7 +4921,7 @@ public IDictionary GetStatementList(int SubscriptionID, int pag
/// The site statistics if applicable.
public ISiteStatistics GetSiteStatistics()
{
- string response = this.DoRequest("stats.json");
+ string response = DoRequest("stats.json");
if (response.IsJSON())
{
JsonObject obj = JsonObject.Parse(response);
@@ -4922,83 +4940,83 @@ public ISiteStatistics GetSiteStatistics()
///
/// Method for applying an adjustment to a subscription
///
- /// The ID of the subscription to adjust
+ /// The ID of the subscription to adjust
/// The amount (in dollars and cents)
/// A helpful explaination of the adjustment
/// The adjustment object if successful, null otherwise.
- public IAdjustment CreateAdjustment(int SubscriptionID, decimal amount, string memo)
+ public IAdjustment CreateAdjustment(int subscriptionId, decimal amount, string memo)
{
- return CreateAdjustment(SubscriptionID, amount, int.MinValue, memo, AdjustmentMethod.Default);
+ return CreateAdjustment(subscriptionId, amount, int.MinValue, memo, AdjustmentMethod.Default);
}
///
/// Method for applying an adjustment to a subscription
///
- /// The ID of the subscription to adjust
+ /// The ID of the subscription to adjust
/// The amount (in dollars and cents)
/// A helpful explaination of the adjustment
/// A string that toggles how the adjustment should be applied
/// The adjustment object if successful, null otherwise.
- public IAdjustment CreateAdjustment(int SubscriptionID, decimal amount, string memo, AdjustmentMethod method)
+ public IAdjustment CreateAdjustment(int subscriptionId, decimal amount, string memo, AdjustmentMethod method)
{
- return CreateAdjustment(SubscriptionID, amount, int.MinValue, memo, method);
+ return CreateAdjustment(subscriptionId, amount, int.MinValue, memo, method);
}
///
/// Method for applying an adjustment to a subscription
///
- /// The ID of the subscription to adjust
- /// The amount (in cents)
+ /// The ID of the subscription to adjust
+ /// The amount (in cents)
/// A helpful explaination of the adjustment
/// The adjustment object if successful, null otherwise.
- public IAdjustment CreateAdjustment(int SubscriptionID, int amount_in_cents, string memo)
+ public IAdjustment CreateAdjustment(int subscriptionId, int amountInCents, string memo)
{
- return CreateAdjustment(SubscriptionID, decimal.MinValue, amount_in_cents, memo, AdjustmentMethod.Default);
+ return CreateAdjustment(subscriptionId, decimal.MinValue, amountInCents, memo, AdjustmentMethod.Default);
}
///
/// Method for applying an adjustment to a subscription
///
- /// The ID of the subscription to adjust
- /// The amount (in cents)
+ /// The ID of the subscription to adjust
+ /// The amount (in cents)
/// A helpful explaination of the adjustment
/// A string that toggles how the adjustment should be applied
/// The adjustment object if successful, null otherwise.
- public IAdjustment CreateAdjustment(int SubscriptionID, int amount_in_cents, string memo, AdjustmentMethod method)
+ public IAdjustment CreateAdjustment(int subscriptionId, int amountInCents, string memo, AdjustmentMethod method)
{
- return CreateAdjustment(SubscriptionID, decimal.MinValue, amount_in_cents, memo, method);
+ return CreateAdjustment(subscriptionId, decimal.MinValue, amountInCents, memo, method);
}
///
/// Method for applying an adjustment to a subscription
///
- /// The ID of the subscription to adjust
+ /// The ID of the subscription to adjust
/// The amount (in dollars and cents)
- /// The amount (in cents)
+ /// The amount (in cents)
/// A helpful explaination of the adjustment
/// A string that toggles how the adjustment should be applied
/// The adjustment object if successful, null otherwise.
- private IAdjustment CreateAdjustment(int SubscriptionID, decimal amount, int amount_in_cents, string memo, AdjustmentMethod method)
+ private IAdjustment CreateAdjustment(int subscriptionId, decimal amount, int amountInCents, string memo, AdjustmentMethod method)
{
- int value_in_cents = 0;
- if (amount == decimal.MinValue) value_in_cents = amount_in_cents;
- if (amount_in_cents == int.MinValue) value_in_cents = Convert.ToInt32(amount * 100);
- if (value_in_cents == int.MinValue) value_in_cents = 0;
- decimal value = Convert.ToDecimal((double) (value_in_cents) / 100.0);
+ int valueInCents = 0;
+ if (amount == decimal.MinValue) valueInCents = amountInCents;
+ if (amountInCents == int.MinValue) valueInCents = Convert.ToInt32(amount * 100);
+ if (valueInCents == int.MinValue) valueInCents = 0;
+ decimal value = Convert.ToDecimal(valueInCents / 100.0);
// make sure data is valid
- if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException("Memo");
+ if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException(nameof(memo));
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", "subscriptionId");
// create XML for creation of an adjustment
- StringBuilder AdjustmentXML = new StringBuilder(GetXMLStringIfApplicable());
- AdjustmentXML.Append("");
- AdjustmentXML.AppendFormat("{0}", value.ToChargifyCurrencyFormat());
- AdjustmentXML.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
- if (method != AdjustmentMethod.Default) { AdjustmentXML.AppendFormat("{0}", method.ToString().ToLowerInvariant()); }
- AdjustmentXML.Append("");
+ StringBuilder adjustmentXml = new StringBuilder(GetXmlStringIfApplicable());
+ adjustmentXml.Append("");
+ adjustmentXml.AppendFormat("{0}", value.ToChargifyCurrencyFormat());
+ adjustmentXml.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
+ if (method != AdjustmentMethod.Default) { adjustmentXml.AppendFormat("{0}", method.ToString().ToLowerInvariant()); }
+ adjustmentXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/adjustments.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, AdjustmentXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/adjustments.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, adjustmentXml.ToString());
// change the response to the object
return response.ConvertResponseTo("adjustment");
}
@@ -5008,15 +5026,15 @@ private IAdjustment CreateAdjustment(int SubscriptionID, decimal amount, int amo
///
/// From http://docs.chargify.com/api-billing-portal
///
- public IBillingManagementInfo GetManagementLink(int ChargifyID)
+ public IBillingManagementInfo GetManagementLink(int chargifyId)
{
try
{
// make sure data is valid
- if (ChargifyID < 0) throw new ArgumentNullException("ChargifyID");
+ if (chargifyId < 0) throw new ArgumentNullException("chargifyId");
// now make the request
- string response = this.DoRequest(string.Format("portal/customers/{0}/management_link.{1}", ChargifyID, GetMethodExtension()));
+ string response = DoRequest(string.Format("portal/customers/{0}/management_link.{1}", chargifyId, GetMethodExtension()));
// Convert the Chargify response into the object we're looking for
return response.ConvertResponseTo("management_link");
@@ -5038,7 +5056,7 @@ public IDictionary GetInvoiceList()
{
// Construct the url to access Chargify
string url = string.Format("invoices.{0}", GetMethodExtension());
- string response = this.DoRequest(url);
+ string response = DoRequest(url);
var retValue = new Dictionary();
if (response.IsXml())
{
@@ -5048,7 +5066,7 @@ public IDictionary GetInvoiceList()
else if (response.IsJSON())
{
// now build an invoice list based on response JSON
- retValue = GetListedJSONResponse("invoice", response);
+ retValue = GetListedJsonResponse("invoice", response);
}
return retValue;
}
@@ -5058,10 +5076,10 @@ public IDictionary GetInvoiceList()
///
/// Clean up a site in test mode.
///
- /// What should be cleaned? DEFAULT IS CUSTOMERS ONLY.
+ /// What should be cleaned? DEFAULT IS CUSTOMERS ONLY.
/// True if complete, false otherwise
/// If used against a production site, the result will always be false.
- public bool ClearTestSite(SiteCleanupScope? CleanupScope = SiteCleanupScope.Customers)
+ public bool ClearTestSite(SiteCleanupScope? cleanupScope = SiteCleanupScope.Customers)
{
bool retVal = false;
@@ -5069,14 +5087,16 @@ public bool ClearTestSite(SiteCleanupScope? CleanupScope = SiteCleanupScope.Cust
{
var qs = string.Empty;
- if (CleanupScope != null && CleanupScope.HasValue)
+ if (cleanupScope != null)
{
- qs += string.Format("cleanup_scope={0}", Enum.GetName(typeof(SiteCleanupScope), CleanupScope.Value).ToLowerInvariant());
+ var cleanupScopeName = Enum.GetName(typeof(SiteCleanupScope), cleanupScope.Value);
+ if (cleanupScopeName != null)
+ qs += string.Format("cleanup_scope={0}", cleanupScopeName.ToLowerInvariant());
}
string url = string.Format("sites/clear_data.{0}", GetMethodExtension());
if (!string.IsNullOrEmpty(qs)) { url += "?" + qs; }
- string response = this.DoRequest(url, HttpRequestMethod.Post, null);
+ DoRequest(url, HttpRequestMethod.Post, null);
// All we're expecting back is 200 OK when it works, and 403 FORBIDDEN when it's not being called appropriately.
retVal = true;
@@ -5093,13 +5113,13 @@ public bool ClearTestSite(SiteCleanupScope? CleanupScope = SiteCleanupScope.Cust
/// These payments are considered external payments.A common case to apply such a payment is when a
/// customer pays by check or some other means for their subscription.
///
- /// The ID of the subscription to apply this manual payment record to
- /// The decimal amount of the payment (ie. 10.00 for $10)
- /// The memo to include with the manual payment
+ /// The ID of the subscription to apply this manual payment record to
+ /// The decimal amount of the payment (ie. 10.00 for $10)
+ /// The memo to include with the manual payment
/// The payment result, null otherwise.
- public IPayment AddPayment(int SubscriptionID, decimal Amount, string Memo)
+ public IPayment AddPayment(int subscriptionId, decimal amount, string memo)
{
- return AddPayment(SubscriptionID, Convert.ToInt32(Amount * 100), Memo);
+ return AddPayment(subscriptionId, Convert.ToInt32(amount * 100), memo);
}
///
@@ -5107,26 +5127,26 @@ public IPayment AddPayment(int SubscriptionID, decimal Amount, string Memo)
/// These payments are considered external payments.A common case to apply such a payment is when a
/// customer pays by check or some other means for their subscription.
///
- /// The ID of the subscription to apply this manual payment record to
- /// The amount in cents of the payment (ie. $10 would be 1000 cents)
- /// The memo to include with the manual payment
+ /// The ID of the subscription to apply this manual payment record to
+ /// The amount in cents of the payment (ie. $10 would be 1000 cents)
+ /// The memo to include with the manual payment
/// The payment result, null otherwise.
- public IPayment AddPayment(int SubscriptionID, int AmountInCents, string Memo)
+ public IPayment AddPayment(int subscriptionId, int amountInCents, string memo)
{
// make sure data is valid
- if (string.IsNullOrEmpty(Memo)) throw new ArgumentNullException("Memo");
+ if (string.IsNullOrEmpty(memo)) throw new ArgumentNullException("memo");
// make sure that the SubscriptionID is unique
- if (this.LoadSubscription(SubscriptionID) == null) throw new ArgumentException("Not an SubscriptionID", "SubscriptionID");
+ if (LoadSubscription(subscriptionId) == null) throw new ArgumentException("Not an SubscriptionID", "subscriptionId");
// create XML for creation of a payment
- var PaymentXML = new StringBuilder(GetXMLStringIfApplicable());
- PaymentXML.Append("");
- PaymentXML.AppendFormat("{0}", AmountInCents);
- PaymentXML.AppendFormat("{0}", HttpUtility.HtmlEncode(Memo));
- PaymentXML.Append("");
+ var paymentXml = new StringBuilder(GetXmlStringIfApplicable());
+ paymentXml.Append("");
+ paymentXml.AppendFormat("{0}", amountInCents);
+ paymentXml.AppendFormat("{0}", HttpUtility.HtmlEncode(memo));
+ paymentXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/payments.{1}", SubscriptionID, GetMethodExtension()), HttpRequestMethod.Post, PaymentXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/payments.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, paymentXml.ToString());
// change the response to the object
return response.ConvertResponseTo("payment");
@@ -5138,17 +5158,17 @@ public IPayment AddPayment(int SubscriptionID, int AmountInCents, string Memo)
///
/// Retrieve a payment profile
///
- /// The ID of the payment profile
+ /// The ID of the payment profile
/// The payment profile, null if not found.
- public IPaymentProfileView LoadPaymentProfile(int ID)
+ public IPaymentProfileView LoadPaymentProfile(int id)
{
try
{
// make sure data is valid
- if (ID < 0) throw new ArgumentNullException("ID");
+ if (id < 0) throw new ArgumentNullException("id");
// now make the request
- string response = this.DoRequest(string.Format("payment_profiles/{0}.{1}", ID, GetMethodExtension()));
+ string response = DoRequest(string.Format("payment_profiles/{0}.{1}", id, GetMethodExtension()));
// Convert the Chargify response into the object we're looking for
return response.ConvertResponseTo("payment_profile");
@@ -5163,44 +5183,48 @@ public IPaymentProfileView LoadPaymentProfile(int ID)
///
/// Updates a payment profile
///
- /// The ID of the customer to whom the profile belongs
- /// The payment profile object
- /// credit_card or bank_account
+ /// The payment profile object
/// The updated payment profile if successful, null or exception otherwise.
- public IPaymentProfileView UpdatePaymentProfile(PaymentProfileView PaymentProfile)
+ public IPaymentProfileView UpdatePaymentProfile(PaymentProfileView paymentProfile)
{
try
{
- if (PaymentProfile.Id < 0) throw new ArgumentException("PaymentProfileID");
- var xml = new StringBuilder(GetXMLStringIfApplicable());
+ if (paymentProfile.Id < 0) throw new ArgumentException("PaymentProfileID");
+ var xml = new StringBuilder(GetXmlStringIfApplicable());
xml.Append("");
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BillingAddress)) xml.AppendFormat("{0}", PaymentProfile.BillingAddress);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BillingAddress2)) xml.AppendFormat("{0}", PaymentProfile.BillingAddress2);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BillingCity)) xml.AppendFormat("{0}", PaymentProfile.BillingCity);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BillingCountry)) xml.AppendFormat("{0}", PaymentProfile.BillingCountry);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BillingState)) xml.AppendFormat("{0}", PaymentProfile.BillingState);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BillingZip)) xml.AppendFormat("{0}", PaymentProfile.BillingZip);
- if (PaymentProfile.CustomerID != int.MinValue) xml.AppendFormat("{0}", PaymentProfile.CustomerID);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.FirstName)) xml.AppendFormat("{0}", PaymentProfile.FirstName);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.LastName)) xml.AppendFormat("{0}", PaymentProfile.LastName);
- xml.AppendFormat("{0}", Enum.GetName(typeof(PaymentProfileType), PaymentProfile.PaymentType).ToLowerInvariant());
- if (PaymentProfile.PaymentType == PaymentProfileType.Credit_Card)
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BillingAddress)) xml.AppendFormat("{0}", paymentProfile.BillingAddress);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BillingAddress2)) xml.AppendFormat("{0}", paymentProfile.BillingAddress2);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BillingCity)) xml.AppendFormat("{0}", paymentProfile.BillingCity);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BillingCountry)) xml.AppendFormat("{0}", paymentProfile.BillingCountry);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BillingState)) xml.AppendFormat("{0}", paymentProfile.BillingState);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BillingZip)) xml.AppendFormat("{0}", paymentProfile.BillingZip);
+ if (paymentProfile.CustomerID != int.MinValue) xml.AppendFormat("{0}", paymentProfile.CustomerID);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.FirstName)) xml.AppendFormat("{0}", paymentProfile.FirstName);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.LastName)) xml.AppendFormat("{0}", paymentProfile.LastName);
+ var paymentTypeName = Enum.GetName(typeof(PaymentProfileType), paymentProfile.PaymentType);
+ if (paymentTypeName != null)
+ xml.AppendFormat("{0}", paymentTypeName.ToLowerInvariant());
+ if (paymentProfile.PaymentType == PaymentProfileType.Credit_Card)
{
- if (!string.IsNullOrWhiteSpace(PaymentProfile.CardType)) xml.AppendFormat("{0}", PaymentProfile.CardType);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.FullNumber)) xml.AppendFormat("{0}", PaymentProfile.FullNumber);
- if (PaymentProfile.ExpirationMonth != int.MinValue) xml.AppendFormat("{0}", PaymentProfile.ExpirationMonth);
- if (PaymentProfile.ExpirationYear != int.MinValue) xml.AppendFormat("{0}", PaymentProfile.ExpirationYear);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.CardType)) xml.AppendFormat("{0}", paymentProfile.CardType);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.FullNumber)) xml.AppendFormat("{0}", paymentProfile.FullNumber);
+ if (paymentProfile.ExpirationMonth != int.MinValue) xml.AppendFormat("{0}", paymentProfile.ExpirationMonth);
+ if (paymentProfile.ExpirationYear != int.MinValue) xml.AppendFormat("{0}", paymentProfile.ExpirationYear);
}
- else if (PaymentProfile.PaymentType == PaymentProfileType.Bank_Account)
+ else if (paymentProfile.PaymentType == PaymentProfileType.Bank_Account)
{
- xml.AppendFormat("{0}", Enum.GetName(typeof(BankAccountHolderType), PaymentProfile.BankAccountHolderType).ToLowerInvariant());
- xml.AppendFormat("{0}", Enum.GetName(typeof(BankAccountType), PaymentProfile.BankAccountType).ToLowerInvariant());
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BankName)) xml.AppendFormat("{0}", PaymentProfile.BankName);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BankRoutingNumber)) xml.AppendFormat("{0}", PaymentProfile.BankRoutingNumber);
- if (!string.IsNullOrWhiteSpace(PaymentProfile.BankAccountNumber)) xml.AppendFormat("{0}", PaymentProfile.BankAccountNumber);
+ var bankAccountHolderTypeName = Enum.GetName(typeof(BankAccountHolderType), paymentProfile.BankAccountHolderType);
+ if (bankAccountHolderTypeName != null)
+ xml.AppendFormat("{0}", bankAccountHolderTypeName.ToLowerInvariant());
+ var bankAccountTypeName = Enum.GetName(typeof(BankAccountType), paymentProfile.BankAccountType);
+ if (bankAccountTypeName != null)
+ xml.AppendFormat("{0}", bankAccountTypeName.ToLowerInvariant());
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BankName)) xml.AppendFormat("{0}", paymentProfile.BankName);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BankRoutingNumber)) xml.AppendFormat("{0}", paymentProfile.BankRoutingNumber);
+ if (!string.IsNullOrWhiteSpace(paymentProfile.BankAccountNumber)) xml.AppendFormat("{0}", paymentProfile.BankAccountNumber);
}
xml.Append("");
- string response = this.DoRequest(string.Format("payment_profiles/{0}.{1}", PaymentProfile.Id, GetMethodExtension()), HttpRequestMethod.Put, xml.ToString());
+ string response = DoRequest(string.Format("payment_profiles/{0}.{1}", paymentProfile.Id, GetMethodExtension()), HttpRequestMethod.Put, xml.ToString());
return response.ConvertResponseTo("payment_profile");
}
catch (ChargifyException cex)
@@ -5216,18 +5240,23 @@ public IPaymentProfileView UpdatePaymentProfile(PaymentProfileView PaymentProfil
/// Renewal Preview is an object representing a subscription’s next assessment.
/// You can retrieve it to see a snapshot of how much your customer will be charged on their next renewal.
///
- /// Integer, the id for the subscription that is to be previewed
+ /// Integer, the id for the subscription that is to be previewed
/// The snapshot of how much your customer will be charged on their next renewal
- public IRenewalDetails PreviewRenewal(int subscriptionID)
+ public IRenewalDetails PreviewRenewal(int subscriptionId)
{
// now make the request
- string response = this.DoRequest($"/subscriptions/{subscriptionID}/renewals/preview.{GetMethodExtension()}", HttpRequestMethod.Post, null);
+ string response = DoRequest($"/subscriptions/{subscriptionId}/renewals/preview.{GetMethodExtension()}", HttpRequestMethod.Post, null);
// change the response to the object
return response.ConvertResponseTo("renewal_preview");
}
#endregion
#region Notes
+ ///
+ /// Create a note
+ ///
+ /// The note to create
+ ///
public INote CreateNote(INote note)
{
return CreateNote(note.SubscriptionID, note.Body, note.Sticky);
@@ -5238,38 +5267,61 @@ private INote CreateNote(int subscriptionId, string body, bool sticky = false)
// make sure data is valid
if (subscriptionId > 0) throw new ArgumentNullException(nameof(subscriptionId));
// make sure that the system ID is unique
- if (this.LoadSubscription(subscriptionId) != null) throw new ArgumentException("Not valid", "subscriptionId");
+ if (LoadSubscription(subscriptionId) != null) throw new ArgumentException("Not valid", "subscriptionId");
// create XML for creation of customer
- var NoteXML = new StringBuilder(GetXMLStringIfApplicable());
- NoteXML.Append("");
- NoteXML.AppendFormat("{0}", body);
- NoteXML.AppendFormat("{0}", sticky);
- NoteXML.Append("");
+ var noteXml = new StringBuilder(GetXmlStringIfApplicable());
+ noteXml.Append("");
+ noteXml.AppendFormat("{0}", body);
+ noteXml.AppendFormat("{0}", sticky);
+ noteXml.Append("");
// now make the request
- string response = this.DoRequest(string.Format("subscriptions/{0}/notes.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, NoteXML.ToString());
+ string response = DoRequest(string.Format("subscriptions/{0}/notes.{1}", subscriptionId, GetMethodExtension()), HttpRequestMethod.Post, noteXml.ToString());
// change the response to the object
return response.ConvertResponseTo("note");
}
- public IDictionary GetNotesForSubscription(int SubscriptionID)
+ ///
+ /// Retrieve the notes
+ ///
+ ///
+ ///
+ public IDictionary GetNotesForSubscription(int subscriptionId)
{
// TODO
throw new NotImplementedException();
}
- public INote LoadNote(int SubscriptionID, int NoteID)
+ ///
+ /// Load the note
+ ///
+ /// The id of the subscription
+ /// The id of the note to retrieve
+ ///
+ public INote LoadNote(int subscriptionId, int noteId)
{
// TODO
throw new NotImplementedException();
}
- public bool DeleteNote(int SubscriptionID, int NoteID)
+ ///
+ /// Deletes a note from a subscription
+ ///
+ /// The id of the subscription
+ /// The id of the note to delete
+ ///
+ public bool DeleteNote(int subscriptionId, int noteId)
{
// TODO
throw new NotImplementedException();
}
- public INote UpdateNote(int SubscriptionID, INote UpdatedNote)
+ ///
+ /// Updates a note
+ ///
+ /// The id of the subscription
+ /// The updated note
+ ///
+ public INote UpdateNote(int subscriptionId, INote updatedNote)
{
// TODO
throw new NotImplementedException();
@@ -5277,7 +5329,7 @@ public INote UpdateNote(int SubscriptionID, INote UpdatedNote)
#endregion
#region Utility Methods
- private Dictionary GetListedJSONResponse(string key, string response)
+ private Dictionary GetListedJsonResponse(string key, string response)
where T : class, IChargifyEntity
{
var retValue = Activator.CreateInstance>();
@@ -5287,9 +5339,10 @@ private Dictionary GetListedJSONResponse(string key, string response)
JsonArray array = JsonArray.Parse(response, ref position);
for (int i = 0; i <= array.Length - 1; i++)
{
- if ((array.Items[i] as JsonObject).ContainsKey("statement"))
+ var jsonObject = array.Items[i] as JsonObject;
+ if (jsonObject != null && jsonObject.ContainsKey(key))
{
- JsonObject jsonObj = (array.Items[i] as JsonObject)["statement"] as JsonObject;
+ JsonObject jsonObj = (array.Items[i] as JsonObject)[key] as JsonObject;
T value = (T) Activator.CreateInstance(typeof(T), jsonObj);
if (!retValue.ContainsKey(value.ID))
{
@@ -5308,15 +5361,15 @@ private Dictionary GetListedXmlResponse(string key, string response)
where T : class, IChargifyEntity
{
// now build an invoice list based on response XML
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(response);
- if (Doc.ChildNodes.Count == 0)
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(response);
+ if (doc.ChildNodes.Count == 0)
throw new InvalidOperationException("Returned XML not valid");
var retValue = Activator.CreateInstance>();
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == string.Format("{0}s", key))
{
@@ -5350,13 +5403,13 @@ private Dictionary GetListedXmlResponse(string key, string response)
/// Either "json" or "xml" depending on how UseJSON is set.
private string GetMethodExtension()
{
- return (this.UseJSON == true) ? "json" : "xml";
+ return UseJSON ? "json" : "xml";
}
- private string GetXMLStringIfApplicable()
+ private string GetXmlStringIfApplicable()
{
string result = string.Empty;
- if (!this.UseJSON)
+ if (!UseJSON)
{
result = "";
}
@@ -5383,9 +5436,9 @@ private string DoRequest(string methodString)
private byte[] DoFileRequest(string methodString, HttpRequestMethod requestMethod, string postData)
{
// make sure values are set
- if (string.IsNullOrEmpty(this.URL)) throw new InvalidOperationException("URL not set");
- if (string.IsNullOrEmpty(this.apiKey)) throw new InvalidOperationException("apiKey not set");
- if (string.IsNullOrEmpty(this.Password)) throw new InvalidOperationException("Password not set");
+ if (string.IsNullOrEmpty(URL)) throw new InvalidOperationException("URL not set");
+ if (string.IsNullOrEmpty(apiKey)) throw new InvalidOperationException("apiKey not set");
+ if (string.IsNullOrEmpty(Password)) throw new InvalidOperationException("Password not set");
if (_protocolType != null)
{
@@ -5393,7 +5446,7 @@ private byte[] DoFileRequest(string methodString, HttpRequestMethod requestMetho
}
// create the URI
- string addressString = string.Format("{0}{1}{2}", this.URL, (this.URL.EndsWith("/") ? "" : "/"), methodString);
+ string addressString = string.Format("{0}{1}{2}", URL, (URL.EndsWith("/") ? "" : "/"), methodString);
var uriBuilder = new UriBuilder(addressString)
{
Scheme = Uri.UriSchemeHttps,
@@ -5402,15 +5455,15 @@ private byte[] DoFileRequest(string methodString, HttpRequestMethod requestMetho
Uri address = uriBuilder.Uri;
// Create the web request
- HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
+ HttpWebRequest request = (HttpWebRequest) WebRequest.Create(address);
request.Timeout = 180000;
- string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(this.apiKey + ":" + this.Password));
+ string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(apiKey + ":" + Password));
request.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
// Set type to POST
request.Method = requestMethod.ToString().ToUpper();
request.SendChunked = false;
- if (!this.UseJSON)
+ if (!UseJSON)
{
request.ContentType = "text/xml";
request.Accept = "application/xml";
@@ -5436,11 +5489,11 @@ private byte[] DoFileRequest(string methodString, HttpRequestMethod requestMetho
// only write if there's data to write ...
if (!string.IsNullOrEmpty(postData))
{
- if (this.UseJSON == true)
+ if (UseJSON)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(postData);
- dataToPost = XmlToJsonConverter.XmlToJSON(doc);
+ dataToPost = XmlToJsonConverter.XmlToJson(doc);
}
// Wrap the request stream with a text-based writer
@@ -5459,34 +5512,34 @@ private byte[] DoFileRequest(string methodString, HttpRequestMethod requestMetho
}
else if (!hasWritten && string.IsNullOrEmpty(postData))
{
- request.ContentLength = (postData != null) ? postData.Length : 0;
+ request.ContentLength = postData?.Length ?? 0;
}
}
// request the data
try
{
- if (LogRequest != null)
- {
- LogRequest(requestMethod, addressString, dataToPost);
- }
+ LogRequest?.Invoke(requestMethod, addressString, dataToPost);
byte[] retValue = { };
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
+ if (response == null) return retValue;
+
+ var responseStream = response.GetResponseStream();
+ if (responseStream != null)
{
- using (var ms = new MemoryStream())
+ using (StreamReader reader = new StreamReader(responseStream))
{
- reader.BaseStream.CopyStream(ms);
- retValue = ms.ToArray();
+ using (var ms = new MemoryStream())
+ {
+ reader.BaseStream.CopyStream(ms);
+ retValue = ms.ToArray();
+ }
+ _lastResponse = response;
}
- _lastResponse = response;
}
- if (LogResponse != null)
- {
- LogResponse(response.StatusCode, addressString, string.Empty);
- }
+ LogResponse?.Invoke(response.StatusCode, addressString, string.Empty);
}
// return the result
return retValue;
@@ -5535,9 +5588,9 @@ private byte[] DoFileRequest(string methodString, HttpRequestMethod requestMetho
private string DoRequest(string methodString, HttpRequestMethod requestMethod, string postData)
{
// make sure values are set
- if (string.IsNullOrEmpty(this.URL)) throw new InvalidOperationException("URL not set");
- if (string.IsNullOrEmpty(this.apiKey)) throw new InvalidOperationException("apiKey not set");
- if (string.IsNullOrEmpty(this.Password)) throw new InvalidOperationException("Password not set");
+ if (string.IsNullOrEmpty(URL)) throw new InvalidOperationException("URL not set");
+ if (string.IsNullOrEmpty(apiKey)) throw new InvalidOperationException("apiKey not set");
+ if (string.IsNullOrEmpty(Password)) throw new InvalidOperationException("Password not set");
if (_protocolType != null)
{
@@ -5545,7 +5598,7 @@ private string DoRequest(string methodString, HttpRequestMethod requestMethod, s
}
// create the URI
- string addressString = string.Format("{0}{1}{2}", this.URL, (this.URL.EndsWith("/") ? string.Empty : "/"), methodString);
+ string addressString = string.Format("{0}{1}{2}", URL, (URL.EndsWith("/") ? string.Empty : "/"), methodString);
var uriBuilder = new UriBuilder(addressString)
{
@@ -5555,16 +5608,16 @@ private string DoRequest(string methodString, HttpRequestMethod requestMethod, s
Uri address = uriBuilder.Uri;
// Create the web request
- HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
- request.Timeout = this._timeout;
- string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(this.apiKey + ":" + this.Password));
+ HttpWebRequest request = (HttpWebRequest) WebRequest.Create(address);
+ request.Timeout = _timeout;
+ string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(apiKey + ":" + Password));
request.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
request.UserAgent = UserAgent;
request.SendChunked = false;
// Set Content-Type and Accept headers
request.Method = requestMethod.ToString().ToUpper();
- if (!this.UseJSON)
+ if (!UseJSON)
{
request.ContentType = "text/xml";
request.Accept = "application/xml";
@@ -5583,11 +5636,11 @@ private string DoRequest(string methodString, HttpRequestMethod requestMethod, s
// only write if there's data to write ...
if (!string.IsNullOrEmpty(postData))
{
- if (this.UseJSON == true)
+ if (UseJSON)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(postData);
- dataToPost = XmlToJsonConverter.XmlToJSON(doc);
+ dataToPost = XmlToJsonConverter.XmlToJson(doc);
}
// Wrap the request stream with a text-based writer
@@ -5606,29 +5659,29 @@ private string DoRequest(string methodString, HttpRequestMethod requestMethod, s
}
else if (!hasWritten && string.IsNullOrEmpty(postData))
{
- request.ContentLength = (postData != null) ? postData.Length : 0;
+ request.ContentLength = postData?.Length ?? 0;
}
}
// request the data
try
{
- if (LogRequest != null)
- {
- LogRequest(requestMethod, addressString, dataToPost);
- }
+ LogRequest?.Invoke(requestMethod, addressString, dataToPost);
string retValue = string.Empty;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- retValue = reader.ReadToEnd();
- _lastResponse = response;
- }
-
- if (LogResponse != null)
+ if (response != null)
{
- LogResponse(response.StatusCode, addressString, retValue);
+ var responseStream = response.GetResponseStream();
+ if (responseStream != null)
+ {
+ using (StreamReader reader = new StreamReader(responseStream))
+ {
+ retValue = reader.ReadToEnd();
+ _lastResponse = response;
+ }
+ }
+ LogResponse?.Invoke(response.StatusCode, addressString, retValue);
}
}
// return the result
diff --git a/Source/Chargify.NET/ChargifyEntity.cs b/Source/Chargify.NET/ChargifyEntity.cs
index 3a69f19..e6ac922 100644
--- a/Source/Chargify.NET/ChargifyEntity.cs
+++ b/Source/Chargify.NET/ChargifyEntity.cs
@@ -13,13 +13,7 @@ public class ChargifyEntity : IChargifyEntity
///
/// The unique id within Chargify
///
- public int ID
- {
- get
- {
- return this.m_id;
- }
- }
+ public int ID => m_id;
///
/// The id value
diff --git a/Source/Chargify.NET/ChargifyException.cs b/Source/Chargify.NET/ChargifyException.cs
index 00e1dd3..509b0eb 100644
--- a/Source/Chargify.NET/ChargifyException.cs
+++ b/Source/Chargify.NET/ChargifyException.cs
@@ -34,12 +34,10 @@ namespace ChargifyNET
using System;
using System.Net;
using System.Diagnostics;
- using System.Runtime.Serialization;
- using System.Security.Permissions;
using System.Xml;
using System.Collections.Generic;
using System.IO;
- using ChargifyNET.Json;
+ using Json;
using System.Xml.Linq;
using System.Linq;
#endregion
@@ -67,7 +65,7 @@ internal ChargifyError() { }
/// The string error message to relay to the user
internal ChargifyError(string message)
{
- this.Message = message;
+ Message = message;
}
///
@@ -76,7 +74,7 @@ internal ChargifyError(string message)
/// The XML node that contains the error message
internal ChargifyError(XmlNode errorNode)
{
- this.Message = errorNode.Value;
+ Message = errorNode.Value;
}
///
@@ -85,7 +83,7 @@ internal ChargifyError(XmlNode errorNode)
/// The JsonString obj that contains the error message
internal ChargifyError(JsonString errorStr)
{
- this.Message = errorStr.Value;
+ Message = errorStr.Value;
}
#endregion
@@ -97,68 +95,73 @@ internal ChargifyError(JsonString errorStr)
/// The list of errors returned from Chargify
internal static List ParseChargifyErrors(HttpWebResponse response)
{
+ List errors = new List();
if (response != null)
{
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
+ var responseStream = response.GetResponseStream();
+ if (responseStream != null)
{
- string errorResponse = reader.ReadToEnd();
- List errors = new List();
+ using (StreamReader reader = new StreamReader(responseStream))
+ {
+ string errorResponse = reader.ReadToEnd();
- // Response is frequently " " ...
- if (string.IsNullOrEmpty(errorResponse.Trim())) return errors;
+ // Response is frequently " " ...
+ if (string.IsNullOrEmpty(errorResponse.Trim())) return errors;
- if (errorResponse.IsXml())
- {
- // New way - Linq-y
- XDocument xdoc = XDocument.Parse(errorResponse);
- if (xdoc.Descendants("error").Count() > 0)
- {
- var results = from e in xdoc.Descendants("error")
- select new ChargifyError
- {
- Message = e.Value
- };
- errors = results.ToList();
- }
- else
+ if (errorResponse.IsXml())
{
- var results = from e in xdoc.Descendants("errors")
- select new ChargifyError
- {
- Message = e.Value
- };
- errors = results.ToList();
+ // New way - Linq-y
+ XDocument xdoc = XDocument.Parse(errorResponse);
+ if (xdoc.Descendants("error").Any())
+ {
+ var results = from e in xdoc.Descendants("error")
+ select new ChargifyError
+ {
+ Message = e.Value
+ };
+ errors = results.ToList();
+ }
+ else
+ {
+ var results = from e in xdoc.Descendants("errors")
+ select new ChargifyError
+ {
+ Message = e.Value
+ };
+ errors = results.ToList();
+ }
}
- }
- else if (errorResponse.IsJSON())
- {
- // slightly different json response from the usual
- int position = 0;
- JsonObject obj = JsonObject.Parse(errorResponse, ref position);
- if (obj.ContainsKey("errors"))
+ else if (errorResponse.IsJSON())
{
- JsonArray array = obj["errors"] as JsonArray;
- for (int i = 0; i <= array.Length - 1; i++)
+ // slightly different json response from the usual
+ int position = 0;
+ JsonObject obj = JsonObject.Parse(errorResponse, ref position);
+ if (obj.ContainsKey("errors"))
{
- if (((array.Items[i] as JsonString) != null) && (!string.IsNullOrEmpty((array.Items[i] as JsonString).Value)))
+ JsonArray array = obj["errors"] as JsonArray;
+ if (array != null && array.Length > 0)
{
- JsonString errorStr = array.Items[i] as JsonString;
- ChargifyError anError = new ChargifyError(errorStr);
- if (!errors.Contains(anError))
+ for (int i = 0; i <= array.Length - 1; i++)
{
- errors.Add(anError);
+ if ((((JsonString) array.Items[i]) != null) && (!string.IsNullOrEmpty(((JsonString) array.Items[i]).Value)))
+ {
+ JsonString errorStr = array.Items[i] as JsonString;
+ ChargifyError anError = new ChargifyError(errorStr);
+ if (!errors.Contains(anError))
+ {
+ errors.Add(anError);
+ }
+ }
}
}
}
}
+
}
- return errors;
}
+ return errors;
}
- else
- {
- throw new ChargifyNetException("Unknown Error");
- }
+ throw new ChargifyNetException("Unknown Error");
}
}
@@ -224,7 +227,7 @@ public string StatusDescription
return _statusDescription;
}
}
- private string _statusDescription = "";
+ private string _statusDescription;
///
/// Get the status code
@@ -236,7 +239,7 @@ public HttpStatusCode StatusCode
return _statusCode;
}
}
- private HttpStatusCode _statusCode = HttpStatusCode.Accepted;
+ private HttpStatusCode _statusCode;
///
/// Get the last data posted that potentially caused the exception
@@ -260,7 +263,7 @@ public List ErrorMessages
return _errors;
}
}
- private List _errors = null;
+ private List _errors;
/////
///// Get object data
@@ -280,7 +283,7 @@ public override string ToString()
// Used for the LogResponse Action
string retVal = string.Empty;
retVal += string.Format("Request: {0}\n", LastDataPosted);
- retVal += string.Format("Response: {0} {1}\n", StatusCode.ToString(), StatusDescription.ToString());
+ retVal += string.Format("Response: {0} {1}\n", StatusCode, StatusDescription);
retVal += string.Format("Errors: {0}\n", string.Join(", ", _errors.ToList().Select(e => e.Message).ToArray()));
return retVal;
}
diff --git a/Source/Chargify.NET/ChargifyPage.cs b/Source/Chargify.NET/ChargifyPage.cs
index 14838e0..e0c62a3 100644
--- a/Source/Chargify.NET/ChargifyPage.cs
+++ b/Source/Chargify.NET/ChargifyPage.cs
@@ -31,16 +31,15 @@
namespace ChargifyNET
{
#region Imports
- using System.Web.UI;
using System.Configuration;
- using ChargifyNET.Configuration;
-
+ using System.Web.UI;
+ using Configuration;
#endregion
///
/// Base Web.UI.Page that contains the Chargify property accessor
///
- public partial class ChargifyPage : Page
+ public class ChargifyPage : Page
{
///
/// The ChargifyConnect object that allows you to make API calls via Chargify.NET
@@ -49,42 +48,45 @@ protected ChargifyConnect Chargify
{
get
{
- if (this._chargify == null)
+ if (_chargify == null)
{
// new instance
- this._chargify = new ChargifyConnect();
+ _chargify = new ChargifyConnect();
bool azureDeployed = UsefulExtensions.IsRunningAzure();
if (!azureDeployed)
{
ChargifyAccountRetrieverSection config = ConfigurationManager.GetSection("chargify") as ChargifyAccountRetrieverSection;
- ChargifyAccountElement accountInfo = config.GetDefaultOrFirst();
- this._chargify.apiKey = accountInfo.ApiKey;
- this._chargify.Password = accountInfo.ApiPassword;
- this._chargify.URL = accountInfo.Site;
- this._chargify.SharedKey = accountInfo.SharedKey;
- this._chargify.UseJSON = config.UseJSON;
+ if (config != null)
+ {
+ ChargifyAccountElement accountInfo = config.GetDefaultOrFirst();
+ _chargify.apiKey = accountInfo.ApiKey;
+ _chargify.Password = accountInfo.ApiPassword;
+ _chargify.URL = accountInfo.Site;
+ _chargify.SharedKey = accountInfo.SharedKey;
+ _chargify.UseJSON = config.UseJSON;
+ }
}
else
{
// Is azure deployed
- this._chargify.apiKey = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_API_KEY");
- this._chargify.Password = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_API_PASSWORD");
- this._chargify.URL = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_SITE_URL");
- this._chargify.SharedKey = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_SHARED_KEY");
+ _chargify.apiKey = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_API_KEY");
+ _chargify.Password = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_API_PASSWORD");
+ _chargify.URL = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_SITE_URL");
+ _chargify.SharedKey = UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_SHARED_KEY");
if (!string.IsNullOrEmpty(UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_USE_JSON")))
{
- this._chargify.UseJSON = bool.Parse(UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_USE_JSON"));
+ _chargify.UseJSON = bool.Parse(UsefulExtensions.GetLateBoundRoleEnvironmentValue("CHARGIFY_USE_JSON"));
}
else
{
- this._chargify.UseJSON = false;
+ _chargify.UseJSON = false;
}
}
-
+
}
- return this._chargify;
+ return _chargify;
}
}
- private ChargifyConnect _chargify = null;
+ private ChargifyConnect _chargify;
}
}
diff --git a/Source/Chargify.NET/Component.cs b/Source/Chargify.NET/Component.cs
index 68b7170..98513d7 100644
--- a/Source/Chargify.NET/Component.cs
+++ b/Source/Chargify.NET/Component.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -42,7 +42,7 @@ namespace ChargifyNET
public class Component : ChargifyBase, IComponent, IComparable
{
#region Field Keys
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string QuantityKey = "quantity";
private const string MemoKey = "memo";
#endregion
@@ -51,18 +51,19 @@ public class Component : ChargifyBase, IComponent, IComparable
///
/// Constructor
///
- private Component() : base() { }
+ private Component()
+ { }
///
/// Constructor
///
- /// An XML string containing a component node
- public Component(string ComponentXML) : base()
+ /// An XML string containing a component node
+ public Component(string componentXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(ComponentXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "ComponentXML");
+ doc.LoadXml(componentXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -73,7 +74,7 @@ public Component(string ComponentXML) : base()
}
}
// if we get here, then no component info was found
- throw new ArgumentException("XML does not contain component information", "ComponentXML");
+ throw new ArgumentException("XML does not contain component information", nameof(componentXml));
}
///
@@ -81,12 +82,11 @@ public Component(string ComponentXML) : base()
///
/// An xml node with usage information
internal Component(XmlNode usageNode)
- : base()
{
- if (usageNode == null) throw new ArgumentNullException("usageNode");
- if (usageNode.Name != "usage") throw new ArgumentException("Not a vaild usage node", "usageNode");
- if (usageNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "usageNode");
- this.LoadFromNode(usageNode);
+ if (usageNode == null) throw new ArgumentNullException(nameof(usageNode));
+ if (usageNode.Name != "usage") throw new ArgumentException("Not a vaild usage node", nameof(usageNode));
+ if (usageNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(usageNode));
+ LoadFromNode(usageNode);
}
///
@@ -94,21 +94,20 @@ internal Component(XmlNode usageNode)
///
/// An JsonObject with usage information
public Component(JsonObject usageObject)
- : base()
{
- if (usageObject == null) throw new ArgumentNullException("usageObject");
- if (usageObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild usage object", "usageObject");
- this.LoadFromJSON(usageObject);
+ if (usageObject == null) throw new ArgumentNullException(nameof(usageObject));
+ if (usageObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild usage object", nameof(usageObject));
+ LoadFromJson(usageObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get product info, and parse it out
foreach (string key in obj.Keys)
{
switch (key)
{
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsString(key);
break;
case QuantityKey:
@@ -117,8 +116,6 @@ private void LoadFromJSON(JsonObject obj)
case MemoKey:
_memo = obj.GetJSONContentAsString(key);
break;
- default:
- break;
}
}
}
@@ -130,7 +127,7 @@ private void LoadFromNode(XmlNode usageNode)
{
switch (dataNode.Name)
{
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsString();
break;
case QuantityKey:
@@ -139,8 +136,6 @@ private void LoadFromNode(XmlNode usageNode)
case MemoKey:
_memo = dataNode.GetNodeContentAsString();
break;
- default:
- break;
}
}
}
@@ -164,7 +159,7 @@ public int Quantity
{
get { return _quantity; }
}
- private int _quantity = 0;
+ private int _quantity;
///
/// An optional description for this metered component
@@ -184,7 +179,7 @@ public string Memo
///
public int CompareTo(IComponent other)
{
- return this.ID.CompareTo(other.ID);
+ return string.Compare(ID, other.ID, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -196,7 +191,7 @@ public int CompareTo(IComponent other)
///
public int CompareTo(Component other)
{
- return this.ID.CompareTo(other.ID);
+ return string.Compare(ID, other.ID, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/ComponentAllocation.cs b/Source/Chargify.NET/ComponentAllocation.cs
index 779c618..16a2e00 100644
--- a/Source/Chargify.NET/ComponentAllocation.cs
+++ b/Source/Chargify.NET/ComponentAllocation.cs
@@ -28,12 +28,15 @@
//
#endregion
+using System;
+using System.Xml;
+using ChargifyNET.Json;
+
namespace ChargifyNET
{
#region Imports
- using System;
- using System.Xml;
- using ChargifyNET.Json;
+
+
#endregion
@@ -52,8 +55,8 @@ public class ComponentAllocation : ChargifyBase, IComponentAllocation, IComparab
/// The XML key which represents a collection of ComponentAllocation's
///
public static readonly string AllocationsRootKey = "allocations";
- private const string ComponentIDKey = "component_id";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string ComponentIdKey = "component_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string QuantityKey = "quantity";
private const string PreviousQuantityKey = "previous_quantity";
private const string MemoKey = "memo";
@@ -67,21 +70,19 @@ public class ComponentAllocation : ChargifyBase, IComponentAllocation, IComparab
/// Default Constructor
///
public ComponentAllocation()
- : base()
{
}
///
/// Constructor
///
- /// The raw XML containing the component allocation node
- public ComponentAllocation(string componentAllocationXML)
- : base()
+ /// The raw XML containing the component allocation node
+ public ComponentAllocation(string componentAllocationXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(componentAllocationXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "componentAllocationXML");
+ doc.LoadXml(componentAllocationXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentAllocationXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -92,7 +93,7 @@ public ComponentAllocation(string componentAllocationXML)
}
}
// if we get here, then no component info was found
- throw new ArgumentException("XML does not contain component allocation information", "componentAllocationXML");
+ throw new ArgumentException("XML does not contain component allocation information", nameof(componentAllocationXml));
}
///
@@ -100,11 +101,10 @@ public ComponentAllocation(string componentAllocationXML)
///
/// The JSON component allocation object
public ComponentAllocation(JsonObject componentAllocationObject)
- : base()
{
- if (componentAllocationObject == null) throw new ArgumentNullException("componentAllocationObject");
- if (componentAllocationObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild component allocation object", "componentAllocationObject");
- this.LoadFromJSON(componentAllocationObject);
+ if (componentAllocationObject == null) throw new ArgumentNullException(nameof(componentAllocationObject));
+ if (componentAllocationObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild component allocation object", nameof(componentAllocationObject));
+ LoadFromJson(componentAllocationObject);
}
///
@@ -112,46 +112,43 @@ public ComponentAllocation(JsonObject componentAllocationObject)
///
/// The XML component allocation node
internal ComponentAllocation(XmlNode componentAllocationNode)
- : base()
{
- if (componentAllocationNode == null) throw new ArgumentNullException("componentAllocationNode");
- if (componentAllocationNode.Name != "allocation") throw new ArgumentException("Not a vaild component allocation node", "componentAllocationNode");
- if (componentAllocationNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "componentAllocationNode");
- this.LoadFromNode(componentAllocationNode);
+ if (componentAllocationNode == null) throw new ArgumentNullException(nameof(componentAllocationNode));
+ if (componentAllocationNode.Name != "allocation") throw new ArgumentException("Not a vaild component allocation node", nameof(componentAllocationNode));
+ if (componentAllocationNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentAllocationNode));
+ LoadFromNode(componentAllocationNode);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get component allocation info, and parse it out
foreach (string key in obj.Keys)
{
switch (key)
{
- case ComponentIDKey:
- this._componentID = obj.GetJSONContentAsInt(key);
+ case ComponentIdKey:
+ _componentId = obj.GetJSONContentAsInt(key);
break;
- case SubscriptionIDKey:
- this._subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case QuantityKey:
- this.Quantity = obj.GetJSONContentAsInt(key);
+ Quantity = obj.GetJSONContentAsInt(key);
break;
case PreviousQuantityKey:
- this._previousQuantity = obj.GetJSONContentAsInt(key);
+ _previousQuantity = obj.GetJSONContentAsInt(key);
break;
case MemoKey:
- this.Memo = obj.GetJSONContentAsString(key);
+ Memo = obj.GetJSONContentAsString(key);
break;
case ProrationUpgradeSchemeKey:
- this.UpgradeScheme = obj.GetJSONContentAsProrationUpgradeScheme(key);
+ UpgradeScheme = obj.GetJSONContentAsProrationUpgradeScheme(key);
break;
case ProrationDowngradeSchemeKey:
- this.DowngradeScheme = obj.GetJSONContentAsProrationDowngradeScheme(key);
+ DowngradeScheme = obj.GetJSONContentAsProrationDowngradeScheme(key);
break;
case TimestampKey:
- this._timeStamp = obj.GetJSONContentAsDateTime(key);
- break;
- default:
+ _timeStamp = obj.GetJSONContentAsDateTime(key);
break;
}
}
@@ -164,31 +161,29 @@ private void LoadFromNode(XmlNode obj)
{
switch (dataNode.Name)
{
- case ComponentIDKey:
- this._componentID = dataNode.GetNodeContentAsInt();
+ case ComponentIdKey:
+ _componentId = dataNode.GetNodeContentAsInt();
break;
- case SubscriptionIDKey:
- this._subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case QuantityKey:
- this.Quantity = dataNode.GetNodeContentAsInt();
+ Quantity = dataNode.GetNodeContentAsInt();
break;
case PreviousQuantityKey:
- this._previousQuantity = dataNode.GetNodeContentAsInt();
+ _previousQuantity = dataNode.GetNodeContentAsInt();
break;
case MemoKey:
- this.Memo = dataNode.GetNodeContentAsString();
+ Memo = dataNode.GetNodeContentAsString();
break;
case ProrationUpgradeSchemeKey:
- this.UpgradeScheme = dataNode.GetNodeContentAsProrationUpgradeScheme();
+ UpgradeScheme = dataNode.GetNodeContentAsProrationUpgradeScheme();
break;
case ProrationDowngradeSchemeKey:
- this.DowngradeScheme = dataNode.GetNodeContentAsProrationDowngradeScheme();
+ DowngradeScheme = dataNode.GetNodeContentAsProrationDowngradeScheme();
break;
case TimestampKey:
- this._timeStamp = dataNode.GetNodeContentAsDateTime();
- break;
- default:
+ _timeStamp = dataNode.GetNodeContentAsDateTime();
break;
}
}
@@ -204,20 +199,20 @@ private void LoadFromNode(XmlNode obj)
///
/// The allocated quantity that was in effect before this allocation was created
///
- public int PreviousQuantity { get { return this._previousQuantity; } }
+ public int PreviousQuantity { get { return _previousQuantity; } }
private int _previousQuantity = int.MinValue;
///
/// The integer component ID for the allocation. This references a component that you have created in your Product setup
///
- public int ComponentID { get { return this._componentID; } }
- private int _componentID = int.MinValue;
+ public int ComponentID { get { return _componentId; } }
+ private int _componentId = int.MinValue;
///
/// The integer subscription ID for the allocation. This references a unique subscription in your Site
///
- public int SubscriptionID { get { return this._subscriptionID; } }
- private int _subscriptionID = int.MinValue;
+ public int SubscriptionID { get { return _subscriptionId; } }
+ private int _subscriptionId = int.MinValue;
///
/// The memo passed when the allocation was created
@@ -227,7 +222,7 @@ private void LoadFromNode(XmlNode obj)
///
/// The time that the allocation was recorded, in ISO 8601 format and UTC timezone, i.e. 2012-11-20T22:00:37Z
///
- public DateTime TimeStamp { get { return this._timeStamp; } }
+ public DateTime TimeStamp { get { return _timeStamp; } }
private DateTime _timeStamp = DateTime.MinValue;
///
diff --git a/Source/Chargify.NET/ComponentAttributes.cs b/Source/Chargify.NET/ComponentAttributes.cs
index 134330a..cac475a 100644
--- a/Source/Chargify.NET/ComponentAttributes.cs
+++ b/Source/Chargify.NET/ComponentAttributes.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -44,8 +44,8 @@ public class ComponentAttributes : ChargifyBase, IComponentAttributes, IComparab
{
#region Field Keys
private const string AllocatedQuantityKey = "allocated_quantity";
- private const string ComponentIDKey = "component_id";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string ComponentIdKey = "component_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string NameKey = "name";
private const string UnitNameKey = "unit_name";
private const string KindKey = "kind";
@@ -58,19 +58,19 @@ public class ComponentAttributes : ChargifyBase, IComponentAttributes, IComparab
///
/// Constructor
///
- private ComponentAttributes() : base() { }
+ private ComponentAttributes()
+ { }
///
/// Constructor
///
- /// An XML string containing a component node
- public ComponentAttributes(string componentAttributesXML)
- : base()
+ /// An XML string containing a component node
+ public ComponentAttributes(string componentAttributesXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(componentAttributesXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "componentAttributesXML");
+ doc.LoadXml(componentAttributesXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentAttributesXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -81,7 +81,7 @@ public ComponentAttributes(string componentAttributesXML)
}
}
// if we get here, then no component info was found
- throw new ArgumentException("XML does not contain component information", "componentAttributesXML");
+ throw new ArgumentException("XML does not contain component information", nameof(componentAttributesXml));
}
///
@@ -89,12 +89,11 @@ public ComponentAttributes(string componentAttributesXML)
///
/// An xml node with usage information
internal ComponentAttributes(XmlNode componentAttributeNode)
- : base()
{
- if (componentAttributeNode == null) throw new ArgumentNullException("componentAttributeNode");
- if (componentAttributeNode.Name != "component") throw new ArgumentException("Not a vaild component node", "componentAttributeNode");
- if (componentAttributeNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "componentAttributeNode");
- this.LoadFromNode(componentAttributeNode);
+ if (componentAttributeNode == null) throw new ArgumentNullException(nameof(componentAttributeNode));
+ if (componentAttributeNode.Name != "component") throw new ArgumentException("Not a vaild component node", nameof(componentAttributeNode));
+ if (componentAttributeNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentAttributeNode));
+ LoadFromNode(componentAttributeNode);
}
///
@@ -102,14 +101,13 @@ internal ComponentAttributes(XmlNode componentAttributeNode)
///
/// An JsonObject with component information
public ComponentAttributes(JsonObject componentAttributesObject)
- : base()
{
- if (componentAttributesObject == null) throw new ArgumentNullException("componentAttributesObject");
- if (componentAttributesObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild component object", "componentAttributesObject");
- this.LoadFromJSON(componentAttributesObject);
+ if (componentAttributesObject == null) throw new ArgumentNullException(nameof(componentAttributesObject));
+ if (componentAttributesObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild component object", nameof(componentAttributesObject));
+ LoadFromJson(componentAttributesObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get component info, and parse it out
foreach (string key in obj.Keys)
@@ -119,11 +117,11 @@ private void LoadFromJSON(JsonObject obj)
case AllocatedQuantityKey:
_allocatedQuantity = obj.GetJSONContentAsInt(key);
break;
- case ComponentIDKey:
- _componentID = obj.GetJSONContentAsInt(key);
+ case ComponentIdKey:
+ _componentId = obj.GetJSONContentAsInt(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case NameKey:
_name = obj.GetJSONContentAsString(key);
@@ -144,8 +142,6 @@ private void LoadFromJSON(JsonObject obj)
case EnabledKey:
_enabled = obj.GetJSONContentAsBoolean(key);
break;
- default:
- break;
}
}
}
@@ -160,11 +156,11 @@ private void LoadFromNode(XmlNode obj)
case AllocatedQuantityKey:
_allocatedQuantity = dataNode.GetNodeContentAsDecimal();
break;
- case ComponentIDKey:
- _componentID = dataNode.GetNodeContentAsInt();
+ case ComponentIdKey:
+ _componentId = dataNode.GetNodeContentAsInt();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case NameKey:
_name = dataNode.GetNodeContentAsString();
@@ -185,8 +181,6 @@ private void LoadFromNode(XmlNode obj)
case EnabledKey:
_enabled = dataNode.GetNodeContentAsBoolean();
break;
- default:
- break;
}
}
}
@@ -217,18 +211,18 @@ public string Kind
///
public int SubscriptionID
{
- get { return _subscriptionID; }
+ get { return _subscriptionId; }
}
- private int _subscriptionID = int.MinValue;
+ private int _subscriptionId = int.MinValue;
///
/// The ID of the component itself
///
public int ComponentID
{
- get { return _componentID; }
+ get { return _componentId; }
}
- private int _componentID = int.MinValue;
+ private int _componentId = int.MinValue;
///
/// The quantity allocated to this subscription
@@ -261,10 +255,10 @@ public string UnitName
///
/// The balance of units of this component against the subscription
///
- public int UnitBalance
+ public int UnitBalance
{
// Clamp the response to 0+, since that's what makes sense.
- get { return (_unitBalance < 0 ? 0 : _unitBalance); }
+ get { return (_unitBalance < 0 ? 0 : _unitBalance); }
}
private int _unitBalance = int.MinValue;
@@ -272,11 +266,11 @@ public int UnitBalance
/// The status of whether this component is enabled or disabled.
/// (On/Off components only)
///
- public bool Enabled
+ public bool Enabled
{
get { return _enabled; }
}
- private bool _enabled = false;
+ private bool _enabled;
#endregion
@@ -287,7 +281,7 @@ public bool Enabled
///
public int CompareTo(ComponentAttributes other)
{
- return this.ComponentID.CompareTo(other.ComponentID);
+ return ComponentID.CompareTo(other.ComponentID);
}
#endregion
@@ -299,7 +293,7 @@ public int CompareTo(ComponentAttributes other)
///
public int CompareTo(IComponentAttributes other)
{
- return this.ComponentID.CompareTo(other.ComponentID);
+ return ComponentID.CompareTo(other.ComponentID);
}
#endregion
diff --git a/Source/Chargify.NET/ComponentInfo.cs b/Source/Chargify.NET/ComponentInfo.cs
index 8b77e17..c05246b 100644
--- a/Source/Chargify.NET/ComponentInfo.cs
+++ b/Source/Chargify.NET/ComponentInfo.cs
@@ -32,9 +32,9 @@ namespace ChargifyNET
{
#region Imports
using System;
- using System.Xml;
- using ChargifyNET.Json;
using System.Collections.Generic;
+ using System.Xml;
+ using Json;
#endregion
///
@@ -44,13 +44,13 @@ public class ComponentInfo : ChargifyBase, IComponentInfo, IComparable
/// Constructor
///
- private ComponentInfo() : base() { }
+ private ComponentInfo()
+ { }
///
/// Constructor
///
- /// An XML string containing a component node
- public ComponentInfo(string componentInfoXML)
- : base()
+ /// An XML string containing a component node
+ public ComponentInfo(string componentInfoXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(componentInfoXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "componentInfoXML");
+ doc.LoadXml(componentInfoXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentInfoXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -86,7 +86,7 @@ public ComponentInfo(string componentInfoXML)
}
}
// if we get here, then no component info was found
- throw new ArgumentException("XML does not contain component information", "componentInfoXML");
+ throw new ArgumentException("XML does not contain component information", nameof(componentInfoXml));
}
///
@@ -94,12 +94,11 @@ public ComponentInfo(string componentInfoXML)
///
/// An xml node with component information
internal ComponentInfo(XmlNode componentInfoNode)
- : base()
{
- if (componentInfoNode == null) throw new ArgumentNullException("componentInfoNode");
- if (componentInfoNode.Name != "component") throw new ArgumentException("Not a vaild component node", "componentInfoNode");
- if (componentInfoNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "componentInfoNode");
- this.LoadFromNode(componentInfoNode);
+ if (componentInfoNode == null) throw new ArgumentNullException(nameof(componentInfoNode));
+ if (componentInfoNode.Name != "component") throw new ArgumentException("Not a vaild component node", nameof(componentInfoNode));
+ if (componentInfoNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(componentInfoNode));
+ LoadFromNode(componentInfoNode);
}
///
@@ -107,14 +106,13 @@ internal ComponentInfo(XmlNode componentInfoNode)
///
/// An JsonObject with component information
public ComponentInfo(JsonObject componentInfoObject)
- : base()
{
- if (componentInfoObject == null) throw new ArgumentNullException("componentInfoObject");
- if (componentInfoObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild component object", "componentInfoObject");
- this.LoadFromJSON(componentInfoObject);
+ if (componentInfoObject == null) throw new ArgumentNullException(nameof(componentInfoObject));
+ if (componentInfoObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild component object", nameof(componentInfoObject));
+ LoadFromJson(componentInfoObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get component info, and parse it out
foreach (string key in obj.Keys)
@@ -124,24 +122,24 @@ private void LoadFromJSON(JsonObject obj)
case CreatedAtKey:
_createdAt = obj.GetJSONContentAsDateTime(key);
break;
- case IDKey:
- case ComponentIDKey:
+ case IdKey:
+ case ComponentIdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case NameKey:
_name = obj.GetJSONContentAsString(key);
break;
- case DescriptionKey:
- _description = obj.GetJSONContentAsString(key);
- break;
+ case DescriptionKey:
+ _description = obj.GetJSONContentAsString(key);
+ break;
case PricePerUnitInCentsKey:
_pricePerUnit = obj.GetJSONContentAsInt(key);
break;
case PricingSchemeKey:
_pricingScheme = obj.GetJSONContentAsPricingSchemeType(key);
break;
- case ProductFamilyIDKey:
- _productFamilyID = obj.GetJSONContentAsInt(key);
+ case ProductFamilyIdKey:
+ _productFamilyId = obj.GetJSONContentAsInt(key);
break;
case UnitNameKey:
_unitName = obj.GetJSONContentAsString(key);
@@ -156,12 +154,13 @@ private void LoadFromJSON(JsonObject obj)
_unitPrice = obj.GetJSONContentAsDecimal(key);
break;
case PricesKey:
- _prices = new List();
+ _prices = new List();
JsonArray pricesArray = obj[key] as JsonArray;
if (pricesArray != null)
{
- foreach (JsonObject priceObj in pricesArray.Items)
+ foreach (var jsonValue in pricesArray.Items)
{
+ var priceObj = (JsonObject) jsonValue;
if (priceObj == null) continue;
var bracketInfo = new PriceBracketInfo();
@@ -178,8 +177,6 @@ private void LoadFromJSON(JsonObject obj)
case "unit_price":
bracketInfo.UnitPrice = priceObj.GetJSONContentAsDecimal(bracketKey);
break;
- default:
- break;
}
}
_prices.Add(bracketInfo);
@@ -190,12 +187,10 @@ private void LoadFromJSON(JsonObject obj)
{
throw new JsonParseException(string.Format("Unable to parse price brackets ({0} != {1})", pricesArray.Length, _prices.Count));
}
- break;
+ break;
case ArchivedKey:
_archived = obj.GetJSONContentAsBoolean(key);
break;
- default:
- break;
}
}
}
@@ -210,24 +205,24 @@ private void LoadFromNode(XmlNode obj)
case CreatedAtKey:
_createdAt = dataNode.GetNodeContentAsDateTime();
break;
- case IDKey:
- case ComponentIDKey:
+ case IdKey:
+ case ComponentIdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case NameKey:
_name = dataNode.GetNodeContentAsString();
break;
- case DescriptionKey:
- _description = dataNode.GetNodeContentAsString();
- break;
+ case DescriptionKey:
+ _description = dataNode.GetNodeContentAsString();
+ break;
case PricePerUnitInCentsKey:
_pricePerUnit = dataNode.GetNodeContentAsInt();
break;
case PricingSchemeKey:
_pricingScheme = dataNode.GetNodeContentAsPricingSchemeType();
break;
- case ProductFamilyIDKey:
- _productFamilyID = dataNode.GetNodeContentAsInt();
+ case ProductFamilyIdKey:
+ _productFamilyId = dataNode.GetNodeContentAsInt();
break;
case UnitNameKey:
_unitName = dataNode.GetNodeContentAsString();
@@ -259,18 +254,14 @@ private void LoadFromNode(XmlNode obj)
case "unit_price":
bracketInfo.UnitPrice = bracketNode.GetNodeContentAsDecimal();
break;
- default:
- break;
}
}
_prices.Add(bracketInfo);
}
- break;
+ break;
case ArchivedKey:
_archived = dataNode.GetNodeContentAsBoolean();
break;
- default:
- break;
}
}
}
@@ -305,14 +296,14 @@ public string Name
}
private string _name = string.Empty;
- ///
- /// The description of the component as created by the Chargify user
- ///
- public string Description
- {
- get { return _description; }
- }
- private string _description = string.Empty;
+ ///
+ /// The description of the component as created by the Chargify user
+ ///
+ public string Description
+ {
+ get { return _description; }
+ }
+ private string _description = string.Empty;
///
/// Price of the component per unit (in cents)
@@ -330,7 +321,7 @@ public int PricePerUnitInCents
[Obsolete("This value is depreciated since 1.5, please use UnitPrice instead.")]
public decimal PricePerUnit
{
- get { return Convert.ToDecimal(this._pricePerUnit) / 100; }
+ get { return Convert.ToDecimal(_pricePerUnit) / 100; }
}
///
@@ -347,9 +338,9 @@ public PricingSchemeType PricingScheme
///
public int ProductFamilyID
{
- get { return _productFamilyID; }
+ get { return _productFamilyId; }
}
- private int _productFamilyID = int.MinValue;
+ private int _productFamilyId = int.MinValue;
///
/// The name for the unit this component is measured in.
@@ -381,18 +372,18 @@ public ComponentType Kind
///
/// The amount the customer will be charged per unit. This field is only populated for 'per_unit' pricing schemes.
///
- public decimal UnitPrice
- {
- get { return _unitPrice; }
+ public decimal UnitPrice
+ {
+ get { return _unitPrice; }
}
private decimal _unitPrice = decimal.MinValue;
///
/// An list of price brackets. If the component uses the 'per_unit' pricing scheme, an empty list will be returned.
///
- public List Prices
+ public List Prices
{
- get { return _prices; }
+ get { return _prices; }
}
private List _prices = new List();
@@ -400,7 +391,7 @@ public List Prices
/// Boolean flag describing whether a component is archived or not
///
public bool Archived { get { return _archived; } }
- private bool _archived = false;
+ private bool _archived;
#endregion
@@ -413,7 +404,7 @@ public List Prices
/// The CompareTo value based on comparing IDs
public int CompareTo(IComponentInfo other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
@@ -427,7 +418,7 @@ public int CompareTo(IComponentInfo other)
/// The CompareTo value based on comparing IDs
public int CompareTo(ComponentInfo other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
diff --git a/Source/Chargify.NET/Configuration/ChargifyAccountElementCollection.cs b/Source/Chargify.NET/Configuration/ChargifyAccountElementCollection.cs
index ed9dac3..7cda6a8 100644
--- a/Source/Chargify.NET/Configuration/ChargifyAccountElementCollection.cs
+++ b/Source/Chargify.NET/Configuration/ChargifyAccountElementCollection.cs
@@ -55,7 +55,7 @@ protected override ConfigurationElement CreateNewElement()
///
protected override object GetElementKey(ConfigurationElement element)
{
- return ((ChargifyAccountElement)element).Name;
+ return ((ChargifyAccountElement) element).Name;
}
///
@@ -67,14 +67,14 @@ public ChargifyAccountElement this[int index]
{
get
{
- return (ChargifyAccountElement)base.BaseGet(index);
+ return (ChargifyAccountElement) BaseGet(index);
}
set
{
- if (base.BaseGet(index) != null)
- base.BaseRemoveAt(index);
+ if (BaseGet(index) != null)
+ BaseRemoveAt(index);
- this.BaseAdd(index, value);
+ BaseAdd(index, value);
}
}
}
diff --git a/Source/Chargify.NET/Configuration/ChargifyAccountRetrieverSection.cs b/Source/Chargify.NET/Configuration/ChargifyAccountRetrieverSection.cs
index e28ba16..217072a 100644
--- a/Source/Chargify.NET/Configuration/ChargifyAccountRetrieverSection.cs
+++ b/Source/Chargify.NET/Configuration/ChargifyAccountRetrieverSection.cs
@@ -32,7 +32,6 @@ namespace ChargifyNET.Configuration
{
#region Imports
using System.Configuration;
-
#endregion
///
@@ -46,7 +45,7 @@ public class ChargifyAccountRetrieverSection : ConfigurationSection
[ConfigurationProperty("defaultAccount")]
public string DefaultAccount
{
- get { return (string)base["defaultAccount"]; }
+ get { return (string) base["defaultAccount"]; }
set { base["defaultAccount"] = value; }
}
@@ -56,10 +55,10 @@ public string DefaultAccount
[ConfigurationProperty("useJSON")]
public bool UseJSON
{
- get
+ get
{
- if (base["useJSON"] != null) { return (bool)base["useJSON"]; }
- else { return false; }
+ if (base["useJSON"] != null) { return (bool) base["useJSON"]; }
+ return false;
}
set { base["useJSON"] = value; }
}
@@ -67,10 +66,10 @@ public bool UseJSON
///
/// The collection of Chargify Account elements
///
- [ConfigurationProperty("accounts", IsDefaultCollection=true)]
+ [ConfigurationProperty("accounts", IsDefaultCollection = true)]
public ChargifyAccountElementCollection Accounts
{
- get { return (ChargifyAccountElementCollection)this["accounts"]; }
+ get { return (ChargifyAccountElementCollection) this["accounts"]; }
set { this["accounts"] = value; }
}
@@ -80,11 +79,11 @@ public ChargifyAccountElementCollection Accounts
public ChargifyAccountElement GetDefaultOrFirst()
{
ChargifyAccountElement result = null;
- if (!string.IsNullOrEmpty(this.DefaultAccount))
+ if (!string.IsNullOrEmpty(DefaultAccount))
{
- foreach (ChargifyAccountElement element in this.Accounts)
+ foreach (ChargifyAccountElement element in Accounts)
{
- if (element.Name == this.DefaultAccount)
+ if (element.Name == DefaultAccount)
{
result = element;
break;
@@ -94,17 +93,14 @@ public ChargifyAccountElement GetDefaultOrFirst()
else
{
// If there are account elements in the web.config then ..
- if (this.Accounts.Count > 0)
+ if (Accounts.Count > 0)
{
- result = this.Accounts[0] as ChargifyAccountElement;
+ result = Accounts[0];
}
}
if (result == null) { throw new ConfigurationErrorsException("No accounts listed for Chargify in web.config"); }
- else
- {
- return result;
- }
+ return result;
}
///
@@ -114,11 +110,11 @@ public ChargifyAccountElement GetDefaultOrFirst()
public string GetSharedKeyForDefaultOrFirstSite()
{
ChargifyAccountElement result = null;
- if (!string.IsNullOrEmpty(this.DefaultAccount))
+ if (!string.IsNullOrEmpty(DefaultAccount))
{
- foreach (ChargifyAccountElement element in this.Accounts)
+ foreach (ChargifyAccountElement element in Accounts)
{
- if (element.Name == this.DefaultAccount)
+ if (element.Name == DefaultAccount)
{
result = element;
break;
@@ -128,17 +124,14 @@ public string GetSharedKeyForDefaultOrFirstSite()
else
{
// If there are account elements in the web.config then ..
- if (this.Accounts.Count > 0)
+ if (Accounts.Count > 0)
{
- result = this.Accounts[0] as ChargifyAccountElement;
+ result = Accounts[0];
}
}
if (result == null) { throw new ConfigurationErrorsException("No accounts listed for Chargify in web.config"); }
- else
- {
- return result.SharedKey;
- }
+ return result.SharedKey;
}
}
}
diff --git a/Source/Chargify.NET/Coupon.cs b/Source/Chargify.NET/Coupon.cs
index 2e835b3..91eeb64 100644
--- a/Source/Chargify.NET/Coupon.cs
+++ b/Source/Chargify.NET/Coupon.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -47,9 +47,9 @@ public class Coupon : ChargifyBase, ICoupon, IComparable
private const string CreatedAtKey = "created_at";
private const string DescriptionKey = "description";
private const string EndDateKey = "end_date";
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string NameKey = "name";
- private const string ProductFamilyIDKey = "product_family_id";
+ private const string ProductFamilyIdKey = "product_family_id";
private const string StartDateKey = "start_date";
private const string UpdatedAtKey = "updated_at";
private const string DurationIntervalKey = "duration_interval";
@@ -67,32 +67,30 @@ public class Coupon : ChargifyBase, ICoupon, IComparable
/// Constructor. Values set to default
///
public Coupon()
- : base()
{
}
///
/// Constructor
///
- /// XML containing coupon info (in expected format)
- public Coupon(string CouponXML)
- : base()
+ /// XML containing coupon info (in expected format)
+ public Coupon(string couponXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(CouponXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "CouponXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(couponXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(couponXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "coupon")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain coupon information", "CouponXML");
+ throw new ArgumentException("XML does not contain coupon information", nameof(couponXml));
}
///
@@ -100,12 +98,11 @@ public Coupon(string CouponXML)
///
/// XML containing coupon info (in expected format)
internal Coupon(XmlNode couponNode)
- : base()
{
- if (couponNode == null) throw new ArgumentNullException("CouponNode");
- if (couponNode.Name != "coupon") throw new ArgumentException("Not a vaild coupon node", "couponNode");
- if (couponNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "couponNode");
- this.LoadFromNode(couponNode);
+ if (couponNode == null) throw new ArgumentNullException(nameof(couponNode));
+ if (couponNode.Name != "coupon") throw new ArgumentException("Not a vaild coupon node", nameof(couponNode));
+ if (couponNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(couponNode));
+ LoadFromNode(couponNode);
}
///
@@ -113,18 +110,17 @@ internal Coupon(XmlNode couponNode)
///
/// JsonObject containing coupon info (in expected format)
public Coupon(JsonObject couponObject)
- : base()
{
- if (couponObject == null) throw new ArgumentNullException("couponObject");
- if (couponObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild coupon object", "couponObject");
- this.LoadFromJSON(couponObject);
+ if (couponObject == null) throw new ArgumentNullException(nameof(couponObject));
+ if (couponObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild coupon object", nameof(couponObject));
+ LoadFromJson(couponObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing coupon data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get coupon info, and parse it out
foreach (string key in obj.Keys)
@@ -146,14 +142,14 @@ private void LoadFromJSON(JsonObject obj)
case EndDateKey:
_endDate = obj.GetJSONContentAsDateTime(key);
break;
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case NameKey:
_name = obj.GetJSONContentAsString(key);
break;
- case ProductFamilyIDKey:
- _productFamilyID = obj.GetJSONContentAsInt(key);
+ case ProductFamilyIdKey:
+ _productFamilyId = obj.GetJSONContentAsInt(key);
break;
case StartDateKey:
_startDate = obj.GetJSONContentAsDateTime(key);
@@ -182,8 +178,6 @@ private void LoadFromJSON(JsonObject obj)
case AllowNegativeBalanceKey:
_allowNegativeBalance = obj.GetJSONContentAsBoolean(key);
break;
- default:
- break;
}
}
}
@@ -213,14 +207,14 @@ private void LoadFromNode(XmlNode couponNode)
case EndDateKey:
_endDate = dataNode.GetNodeContentAsDateTime();
break;
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case NameKey:
_name = dataNode.GetNodeContentAsString();
break;
- case ProductFamilyIDKey:
- _productFamilyID = dataNode.GetNodeContentAsInt();
+ case ProductFamilyIdKey:
+ _productFamilyId = dataNode.GetNodeContentAsInt();
break;
case StartDateKey:
_startDate = dataNode.GetNodeContentAsDateTime();
@@ -249,8 +243,6 @@ private void LoadFromNode(XmlNode couponNode)
case AllowNegativeBalanceKey:
_allowNegativeBalance = dataNode.GetNodeContentAsBoolean();
break;
- default:
- break;
}
}
}
@@ -339,9 +331,9 @@ public string Name
///
public int ProductFamilyID
{
- get { return _productFamilyID; }
+ get { return _productFamilyId; }
}
- private int _productFamilyID = int.MinValue;
+ private int _productFamilyId = int.MinValue;
///
/// The date this coupon became active
@@ -409,7 +401,7 @@ public bool IsRecurring
get { return _isRecurring; }
set { _isRecurring = value; }
}
- private bool _isRecurring = false;
+ private bool _isRecurring;
///
/// The date this coupon was archived
@@ -425,7 +417,7 @@ public bool AllowNegativeBalance
get { return _allowNegativeBalance; }
set { _allowNegativeBalance = value; }
}
- private bool _allowNegativeBalance = false;
+ private bool _allowNegativeBalance;
#endregion
@@ -436,7 +428,7 @@ public bool AllowNegativeBalance
///
public int CompareTo(ICoupon other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
@@ -448,7 +440,7 @@ public int CompareTo(ICoupon other)
///
public int CompareTo(Coupon other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
}
diff --git a/Source/Chargify.NET/Credit.cs b/Source/Chargify.NET/Credit.cs
index 9a880f0..f92f9fb 100644
--- a/Source/Chargify.NET/Credit.cs
+++ b/Source/Chargify.NET/Credit.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -52,32 +52,30 @@ public class Credit : ChargifyBase, ICredit, IComparable
/// Constructor. Values set to default
///
public Credit()
- : base()
{
}
///
/// Constructor
///
- /// XML containing credit info (in expected format)
- public Credit(string CreditXML)
- : base()
+ /// XML containing credit info (in expected format)
+ public Credit(string creditXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(CreditXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "CreditXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(creditXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(creditXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "credit")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain credit information", "CreditXML");
+ throw new ArgumentException("XML does not contain credit information", nameof(creditXml));
}
///
@@ -85,12 +83,11 @@ public Credit(string CreditXML)
///
/// XML containing credit info (in expected format)
internal Credit(XmlNode creditNode)
- : base()
{
- if (creditNode == null) throw new ArgumentNullException("CreditNode");
- if (creditNode.Name != "credit") throw new ArgumentException("Not a vaild credit node", "creditNode");
- if (creditNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "creditNode");
- this.LoadFromNode(creditNode);
+ if (creditNode == null) throw new ArgumentNullException(nameof(creditNode));
+ if (creditNode.Name != "credit") throw new ArgumentException("Not a vaild credit node", nameof(creditNode));
+ if (creditNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(creditNode));
+ LoadFromNode(creditNode);
}
///
@@ -99,16 +96,16 @@ internal Credit(XmlNode creditNode)
/// JsonObject containing credit info (in expected format)
public Credit(JsonObject creditObject)
{
- if (creditObject == null) throw new ArgumentNullException("creditObject");
- if (creditObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild credit object", "creditObject");
- this.LoadFromJSON(creditObject);
+ if (creditObject == null) throw new ArgumentNullException(nameof(creditObject));
+ if (creditObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild credit object", nameof(creditObject));
+ LoadFromJson(creditObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject with credit data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -123,8 +120,6 @@ private void LoadFromJSON(JsonObject obj)
case AmountInCentsKey:
_amountInCents = obj.GetJSONContentAsInt(key);
break;
- default:
- break;
}
}
}
@@ -148,8 +143,6 @@ private void LoadFromNode(XmlNode creditNode)
case AmountInCentsKey:
_amountInCents = dataNode.GetNodeContentAsInt();
break;
- default:
- break;
}
}
@@ -165,7 +158,7 @@ public bool Success
{
get { return _success; }
}
- private bool _success = false;
+ private bool _success;
///
/// Get the amount, in cents
@@ -181,7 +174,7 @@ public int AmountInCents
///
public decimal Amount
{
- get { return Convert.ToDecimal(this._amountInCents) / 100; }
+ get { return Convert.ToDecimal(_amountInCents) / 100; }
}
///
@@ -203,7 +196,7 @@ public string Memo
///
public int CompareTo(ICredit other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
@@ -215,7 +208,7 @@ public int CompareTo(ICredit other)
///
public int CompareTo(Credit other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
diff --git a/Source/Chargify.NET/CreditCardAttributes.cs b/Source/Chargify.NET/CreditCardAttributes.cs
index 33b0c98..3b30d29 100644
--- a/Source/Chargify.NET/CreditCardAttributes.cs
+++ b/Source/Chargify.NET/CreditCardAttributes.cs
@@ -46,34 +46,35 @@ public class CreditCardAttributes : PaymentProfileBase, ICreditCardAttributes
///
/// Contructor
///
- public CreditCardAttributes() : base() { }
+ public CreditCardAttributes()
+ { }
///
/// Constructor
///
- /// The first name on the credit card
- /// The last name on the credit card
- /// The full credit card number
- /// The expiration year
- /// The expiration month
- /// The CVV number of the credit card
- /// THe billing address of the credit card
- /// The billing city of the credit card
- /// The billing state or province of the credit card
- /// The billing zip code or postal code of the credit card
- /// The billing country of the credit card
- public CreditCardAttributes(string FirstName, string LastName, string FullNumber, int ExpirationYear, int ExpirationMonth,
- string CVV, string BillingAddress, string BillingCity, string BillingState, string BillingZip,
- string BillingCountry)
- : base(FirstName, LastName, FullNumber, ExpirationYear, ExpirationMonth)
+ /// The first name on the credit card
+ /// The last name on the credit card
+ /// The full credit card number
+ /// The expiration year
+ /// The expiration month
+ /// The CVV number of the credit card
+ /// THe billing address of the credit card
+ /// The billing city of the credit card
+ /// The billing state or province of the credit card
+ /// The billing zip code or postal code of the credit card
+ /// The billing country of the credit card
+ public CreditCardAttributes(string firstName, string lastName, string fullNumber, int expirationYear, int expirationMonth,
+ string cvv, string billingAddress, string billingCity, string billingState, string billingZip,
+ string billingCountry)
+ : base(firstName, lastName, fullNumber, expirationYear, expirationMonth)
{
- this.CVV = CVV;
- this.BillingAddress = BillingAddress;
- this.BillingCity = BillingCity;
- this.BillingState = BillingState;
- this.BillingZip = BillingZip;
- this.BillingCountry = BillingCountry;
+ CVV = cvv;
+ BillingAddress = billingAddress;
+ BillingCity = billingCity;
+ BillingState = billingState;
+ BillingZip = billingZip;
+ BillingCountry = billingCountry;
}
#endregion
@@ -88,7 +89,7 @@ public CreditCardAttributes(string FirstName, string LastName, string FullNumber
///
/// Ignore, used for determining if the value should be serialized
///
- public bool ShouldSerializeCVV()
+ public bool ShouldSerializeCvv()
{
return !string.IsNullOrEmpty(CVV);
}
@@ -96,7 +97,7 @@ public bool ShouldSerializeCVV()
#endregion
#region Operators
-
+
///
/// Equals operator for two credit card attributes
///
@@ -104,19 +105,19 @@ public bool ShouldSerializeCVV()
public static bool operator ==(CreditCardAttributes a, CreditCardAttributes b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
-
- return a.FullNumber == b.FullNumber &&
- a.CVV == b.CVV &&
- a.ExpirationMonth == b.ExpirationMonth &&
- a.ExpirationYear == b.ExpirationYear &&
- a.BillingAddress == b.BillingAddress &&
- a.BillingCity == b.BillingCity &&
- a.BillingState == b.BillingState &&
- a.BillingZip == b.BillingZip &&
+ if (((object) a == null) || ((object) b == null)) { return false; }
+
+ return a.FullNumber == b.FullNumber &&
+ a.CVV == b.CVV &&
+ a.ExpirationMonth == b.ExpirationMonth &&
+ a.ExpirationYear == b.ExpirationYear &&
+ a.BillingAddress == b.BillingAddress &&
+ a.BillingCity == b.BillingCity &&
+ a.BillingState == b.BillingState &&
+ a.BillingZip == b.BillingZip &&
a.BillingCountry == b.BillingCountry;
}
@@ -136,10 +137,10 @@ public bool ShouldSerializeCVV()
public static bool operator ==(ICreditCardAttributes a, CreditCardAttributes b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if ((a == null) || ((object) b == null)) { return false; }
return a.FullNumber == b.FullNumber &&
a.CVV == b.CVV &&
@@ -168,10 +169,10 @@ public bool ShouldSerializeCVV()
public static bool operator ==(CreditCardAttributes a, ICreditCardAttributes b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if (((object) a == null) || (b == null)) { return false; }
return a.FullNumber == b.FullNumber &&
a.CVV == b.CVV &&
@@ -203,7 +204,7 @@ public bool ShouldSerializeCVV()
/// A string representation of the object
public override string ToString()
{
- return string.Format("{0} CVV: {1}\nName on Card: {2} {3}\nExpires {4}/{5}\nBilling Address:\n\t{6}\n\t{7}\n\t{8}\n\t{9}\n\t{10}", this.FullNumber, this.CVV, this.FirstName, this.LastName, this.ExpirationMonth, this.ExpirationYear, this.BillingAddress, this.BillingCity, this.BillingState, this.BillingCountry, this.BillingZip);
+ return string.Format("{0} CVV: {1}\nName on Card: {2} {3}\nExpires {4}/{5}\nBilling Address:\n\t{6}\n\t{7}\n\t{8}\n\t{9}\n\t{10}", FullNumber, CVV, FirstName, LastName, ExpirationMonth, ExpirationYear, BillingAddress, BillingCity, BillingState, BillingCountry, BillingZip);
}
///
@@ -224,14 +225,11 @@ public override bool Equals(object obj)
{
if (obj == null) return false;
- if (typeof(ICreditCardAttributes).IsAssignableFrom(obj.GetType()))
- {
- return (this == (obj as ICreditCardAttributes));
- }
- else
+ if (obj is ICreditCardAttributes)
{
- return base.Equals(obj);
+ return (this == (ICreditCardAttributes) obj);
}
+ return ReferenceEquals(this, obj);
}
#endregion
}
diff --git a/Source/Chargify.NET/Customer.cs b/Source/Chargify.NET/Customer.cs
index 3ab4fb3..d112bb0 100644
--- a/Source/Chargify.NET/Customer.cs
+++ b/Source/Chargify.NET/Customer.cs
@@ -35,7 +35,7 @@ namespace ChargifyNET
using System.Diagnostics;
using System.Web;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -43,63 +43,63 @@ namespace ChargifyNET
///
[Serializable]
[DebuggerDisplay("Full Name: {FullName}, SystemID: {SystemID}, ChargifyID: {ChargifyID}")]
- public class Customer : CustomerAttributes, ICustomer, IComparable
+ public class Customer : CustomerAttributes, ICustomer, IComparable
{
#region Constructors
///
/// Constructor. Values set to default
///
- public Customer() : base()
+ public Customer()
{
}
///
/// Constructor. Values specified
///
- /// The customer's first name
- /// The customer's last name
- /// The customer's email address
- /// The customer's organization
- /// The customer's system ID
- public Customer(string FirstName, string LastName, string Email, string Organization, string SystemID)
- : base(FirstName, LastName, Email, Organization, SystemID)
+ /// The customer's first name
+ /// The customer's last name
+ /// The customer's email address
+ /// The customer's organization
+ /// The customer's system ID
+ public Customer(string firstName, string lastName, string email, string organization, string systemId)
+ : base(firstName, lastName, email, organization, systemId)
{
}
///
/// Constructor
///
- /// XML containing customer info (in expected format)
- public Customer(string CustomerXML) : base(CustomerXML)
- {
+ /// XML containing customer info (in expected format)
+ public Customer(string customerXml) : base(customerXml)
+ {
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(CustomerXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "CustomerXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(customerXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(customerXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "customer")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no customer info was found
- throw new ArgumentException("XML does not contain customer information", "CustomerXML");
+ throw new ArgumentException("XML does not contain customer information", nameof(customerXml));
}
///
/// Constructor
///
/// XML containing customer info (in expected format)
- internal Customer(XmlNode customerNode) : base()
+ internal Customer(XmlNode customerNode)
{
- if (customerNode == null) throw new ArgumentNullException("CustomerNode");
- if (customerNode.Name != "customer") throw new ArgumentException("Not a vaild customer node", "customerNode");
- if (customerNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "customerNode");
- this.LoadFromNode(customerNode);
+ if (customerNode == null) throw new ArgumentNullException(nameof(customerNode));
+ if (customerNode.Name != "customer") throw new ArgumentException("Not a vaild customer node", nameof(customerNode));
+ if (customerNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(customerNode));
+ LoadFromNode(customerNode);
}
///
@@ -107,11 +107,10 @@ internal Customer(XmlNode customerNode) : base()
///
/// JsonObject containing customer info (in expected format)
public Customer(JsonObject customerObject)
- : base()
{
- if (customerObject == null) throw new ArgumentNullException("customerObject");
- if (customerObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild customer object", "customerObject");
- this.LoadFromJSON(customerObject);
+ if (customerObject == null) throw new ArgumentNullException(nameof(customerObject));
+ if (customerObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild customer object", nameof(customerObject));
+ LoadFromJSON(customerObject);
}
///
@@ -124,55 +123,53 @@ private void LoadFromJSON(JsonObject obj)
{
switch (key)
{
- case CustomerAttributes.FirstNameKey:
- this.FirstName = obj.GetJSONContentAsString(key);
+ case FirstNameKey:
+ FirstName = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.LastNameKey:
- this.LastName = obj.GetJSONContentAsString(key);
+ case LastNameKey:
+ LastName = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.EmailKey:
- this.Email = obj.GetJSONContentAsString(key);
+ case EmailKey:
+ Email = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.PhoneKey:
- this.Phone = obj.GetJSONContentAsString(key);
+ case PhoneKey:
+ Phone = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.OrganizationKey:
- this.Organization = HttpUtility.HtmlDecode(obj.GetJSONContentAsString(key));
+ case OrganizationKey:
+ Organization = HttpUtility.HtmlDecode(obj.GetJSONContentAsString(key));
break;
- case CustomerAttributes.ReferenceKey:
- this.SystemID = obj.GetJSONContentAsString(key);
+ case ReferenceKey:
+ SystemID = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.IDKey:
- _chargifyID = obj.GetJSONContentAsInt(key);
+ case IdKey:
+ _chargifyId = obj.GetJSONContentAsInt(key);
break;
- case CustomerAttributes.CreatedAtKey:
+ case CreatedAtKey:
_created = obj.GetJSONContentAsDateTime(key);
break;
- case CustomerAttributes.UpdatedAtKey:
+ case UpdatedAtKey:
_lastUpdated = obj.GetJSONContentAsDateTime(key);
break;
- case CustomerAttributes.ShippingAddressKey:
- this.ShippingAddress = obj.GetJSONContentAsString(key);
- break;
- case CustomerAttributes.ShippingAddress2Key:
- this.ShippingAddress2 = obj.GetJSONContentAsString(key);
+ case ShippingAddressKey:
+ ShippingAddress = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.ShippingCountryKey:
- this.ShippingCountry = obj.GetJSONContentAsString(key);
+ case ShippingAddress2Key:
+ ShippingAddress2 = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.ShippingCityKey:
- this.ShippingCity = obj.GetJSONContentAsString(key);
+ case ShippingCountryKey:
+ ShippingCountry = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.ShippingStateKey:
- this.ShippingState = obj.GetJSONContentAsString(key);
+ case ShippingCityKey:
+ ShippingCity = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.ShippingZipKey:
- this.ShippingZip = obj.GetJSONContentAsString(key);
+ case ShippingStateKey:
+ ShippingState = obj.GetJSONContentAsString(key);
break;
- case CustomerAttributes.VatNumberKey:
- this.VatNumber = obj.GetJSONContentAsString(key);
+ case ShippingZipKey:
+ ShippingZip = obj.GetJSONContentAsString(key);
break;
- default:
+ case VatNumberKey:
+ VatNumber = obj.GetJSONContentAsString(key);
break;
}
}
@@ -188,55 +185,53 @@ private void LoadFromNode(XmlNode customerNode)
{
switch (dataNode.Name)
{
- case CustomerAttributes.FirstNameKey:
- this.FirstName = dataNode.GetNodeContentAsString();
+ case FirstNameKey:
+ FirstName = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.LastNameKey:
- this.LastName = dataNode.GetNodeContentAsString();
+ case LastNameKey:
+ LastName = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.EmailKey:
- this.Email = dataNode.GetNodeContentAsString();
+ case EmailKey:
+ Email = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.PhoneKey:
- this.Phone = dataNode.GetNodeContentAsString();
+ case PhoneKey:
+ Phone = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.OrganizationKey:
- this.Organization = HttpUtility.HtmlDecode(dataNode.GetNodeContentAsString());
+ case OrganizationKey:
+ Organization = HttpUtility.HtmlDecode(dataNode.GetNodeContentAsString());
break;
- case CustomerAttributes.ReferenceKey:
- this.SystemID = dataNode.GetNodeContentAsString();
+ case ReferenceKey:
+ SystemID = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.IDKey:
- _chargifyID = dataNode.GetNodeContentAsInt();
+ case IdKey:
+ _chargifyId = dataNode.GetNodeContentAsInt();
break;
- case CustomerAttributes.CreatedAtKey:
+ case CreatedAtKey:
_created = dataNode.GetNodeContentAsDateTime();
break;
- case CustomerAttributes.UpdatedAtKey:
+ case UpdatedAtKey:
_lastUpdated = dataNode.GetNodeContentAsDateTime();
break;
- case CustomerAttributes.ShippingAddressKey:
- this.ShippingAddress = dataNode.GetNodeContentAsString();
- break;
- case CustomerAttributes.ShippingAddress2Key:
- this.ShippingAddress2 = dataNode.GetNodeContentAsString();
+ case ShippingAddressKey:
+ ShippingAddress = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.ShippingCountryKey:
- this.ShippingCountry = dataNode.GetNodeContentAsString();
+ case ShippingAddress2Key:
+ ShippingAddress2 = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.ShippingCityKey:
- this.ShippingCity = dataNode.GetNodeContentAsString();
+ case ShippingCountryKey:
+ ShippingCountry = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.ShippingStateKey:
- this.ShippingState = dataNode.GetNodeContentAsString();
+ case ShippingCityKey:
+ ShippingCity = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.ShippingZipKey:
- this.ShippingZip = dataNode.GetNodeContentAsString();
+ case ShippingStateKey:
+ ShippingState = dataNode.GetNodeContentAsString();
break;
- case CustomerAttributes.VatNumberKey:
- this.VatNumber = dataNode.GetNodeContentAsString();
+ case ShippingZipKey:
+ ShippingZip = dataNode.GetNodeContentAsString();
break;
- default:
+ case VatNumberKey:
+ VatNumber = dataNode.GetNodeContentAsString();
break;
}
}
@@ -249,18 +244,18 @@ private void LoadFromNode(XmlNode customerNode)
///
/// Get the customer's chargify ID
///
- public int ChargifyID
+ public int ChargifyID
{
get
{
- return _chargifyID;
+ return _chargifyId;
}
}
- private int _chargifyID = int.MinValue;
+ private int _chargifyId = int.MinValue;
///
/// Get the date and time the customer was created a Chargify
///
- public DateTime Created
+ public DateTime Created
{
get
{
@@ -271,7 +266,7 @@ public DateTime Created
///
/// Get the date and time the customer was last updated at chargify
///
- public DateTime LastUpdated
+ public DateTime LastUpdated
{
get
{
@@ -284,11 +279,11 @@ public DateTime LastUpdated
/// Get a boolean value that indicates whether or not this customer is currently saved
/// in the Chargify system
///
- public bool IsSaved
+ public bool IsSaved
{
get
{
- return !(this.ChargifyID == int.MinValue);
+ return !(ChargifyID == int.MinValue);
}
}
@@ -303,10 +298,10 @@ public bool IsSaved
public static bool operator ==(Customer a, Customer b)
{
// If both are null or both are the same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) return true;
+ if (ReferenceEquals(a, b)) return true;
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null))
+ if (((object) a == null) || ((object) b == null))
{
return false;
}
@@ -334,10 +329,10 @@ public bool IsSaved
public static bool operator ==(Customer a, ICustomer b)
{
// If both are null or both are the same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) return true;
+ if (ReferenceEquals(a, b)) return true;
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null))
+ if (((object) a == null) || (b == null))
{
return false;
}
@@ -365,10 +360,10 @@ public bool IsSaved
public static bool operator ==(ICustomer a, Customer b)
{
// If both are null or both are the same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) return true;
+ if (ReferenceEquals(a, b)) return true;
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null))
+ if ((a == null) || ((object) b == null))
{
return false;
}
@@ -435,28 +430,28 @@ public override int GetHashCode()
public override bool Equals(object obj)
{
// If both are null or both are the same instance, return true.
- if (System.Object.ReferenceEquals(this, obj)) return true;
+ if (ReferenceEquals(this, obj)) return true;
// If one is null, but not both, return false.
- if (((object)this == null) || ((object)obj == null))
+ if (obj == null)
{
return false;
}
// Return true if the fields match.
- return this.ChargifyID == ((Customer)obj).ChargifyID &&
- this.Created == ((Customer)obj).Created &&
- this.Email == ((Customer)obj).Email &&
- this.FirstName == ((Customer)obj).FirstName &&
- this.LastName == ((Customer)obj).LastName &&
- this.Organization == ((Customer)obj).Organization &&
- this.ShippingAddress == ((Customer)obj).ShippingAddress &&
- this.ShippingAddress2 == ((Customer)obj).ShippingAddress2 &&
- this.ShippingCity == ((Customer)obj).ShippingCity &&
- this.ShippingCountry == ((Customer)obj).ShippingCountry &&
- this.ShippingState == ((Customer)obj).ShippingState &&
- this.ShippingZip == ((Customer)obj).ShippingZip &&
- this.SystemID == ((Customer)obj).SystemID;
+ return ChargifyID == ((Customer) obj).ChargifyID &&
+ Created == ((Customer) obj).Created &&
+ Email == ((Customer) obj).Email &&
+ FirstName == ((Customer) obj).FirstName &&
+ LastName == ((Customer) obj).LastName &&
+ Organization == ((Customer) obj).Organization &&
+ ShippingAddress == ((Customer) obj).ShippingAddress &&
+ ShippingAddress2 == ((Customer) obj).ShippingAddress2 &&
+ ShippingCity == ((Customer) obj).ShippingCity &&
+ ShippingCountry == ((Customer) obj).ShippingCountry &&
+ ShippingState == ((Customer) obj).ShippingState &&
+ ShippingZip == ((Customer) obj).ShippingZip &&
+ SystemID == ((Customer) obj).SystemID;
}
///
@@ -465,7 +460,7 @@ public override bool Equals(object obj)
/// The string representation of the object
public override string ToString()
{
- return this.FullName;
+ return FullName;
}
#endregion
@@ -479,7 +474,7 @@ public override string ToString()
/// The result of the comparison
public int CompareTo(ICustomer other)
{
- return this.FullName.CompareTo(other.FullName);
+ return string.Compare(FullName, other.FullName, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -493,7 +488,7 @@ public int CompareTo(ICustomer other)
/// The result of the comparison
public int CompareTo(Customer other)
{
- return this.FullName.CompareTo(other.FullName);
+ return string.Compare(FullName, other.FullName, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/CustomerAttributes.cs b/Source/Chargify.NET/CustomerAttributes.cs
index c3d24b1..48c8db4 100644
--- a/Source/Chargify.NET/CustomerAttributes.cs
+++ b/Source/Chargify.NET/CustomerAttributes.cs
@@ -33,10 +33,10 @@ namespace ChargifyNET
#region Imports
using System;
using System.Diagnostics;
- using System.Xml;
- using ChargifyNET.Json;
using System.Web;
+ using System.Xml;
using System.Xml.Serialization;
+ using Json;
#endregion
///
@@ -54,7 +54,7 @@ public class CustomerAttributes : ChargifyBase, ICustomerAttributes, IComparable
internal const string OrganizationKey = "organization";
internal const string VatNumberKey = "vat_number";
internal const string ReferenceKey = "reference";
- internal const string IDKey = "id";
+ internal const string IdKey = "id";
internal const string CreatedAtKey = "created_at";
internal const string UpdatedAtKey = "updated_at";
internal const string ShippingAddressKey = "address";
@@ -70,85 +70,79 @@ public class CustomerAttributes : ChargifyBase, ICustomerAttributes, IComparable
///
/// Constructor. Values set to default
///
- public CustomerAttributes() : base()
+ public CustomerAttributes()
{
}
///
/// Constructor. Values specified
///
- /// The customer's first name
- /// The customer's last name
- /// The customer's email address
- /// The customer's organization
- /// The customer's system ID
- public CustomerAttributes(string FirstName, string LastName, string Email, string Organization, string SystemID) : base()
+ /// The customer's first name
+ /// The customer's last name
+ /// The customer's email address
+ /// The customer's organization
+ /// The customer's system ID
+ public CustomerAttributes(string firstName, string lastName, string email, string organization, string systemId)
{
- this.FirstName = FirstName;
- this.LastName = LastName;
- this.Email = Email;
- this.Organization = Organization;
- this.SystemID = SystemID;
+ FirstName = firstName;
+ LastName = lastName;
+ Email = email;
+ Organization = organization;
+ SystemID = systemId;
}
///
/// Constructor. Values specified
///
- /// The customer's first name
- /// The customer's last name
- /// The customer's email address
- /// The customer's phone number
- /// The customer's organization
- /// The customer's system ID
- public CustomerAttributes(string FirstName, string LastName, string Email, string Phone, string Organization, string SystemID)
- : base()
+ /// The customer's first name
+ /// The customer's last name
+ /// The customer's email address
+ /// The customer's phone number
+ /// The customer's organization
+ /// The customer's system ID
+ public CustomerAttributes(string firstName, string lastName, string email, string phone, string organization, string systemId)
{
- this.FirstName = FirstName;
- this.LastName = LastName;
- this.Email = Email;
- this.Phone = Phone;
- this.Organization = Organization;
- this.SystemID = SystemID;
+ FirstName = firstName;
+ LastName = lastName;
+ Email = email;
+ Phone = phone;
+ Organization = organization;
+ SystemID = systemId;
}
///
/// Constructor
///
- /// XML containing customer info (in expected format)
- public CustomerAttributes(string CustomerAttributesXML)
- : base()
- {
+ /// XML containing customer info (in expected format)
+ public CustomerAttributes(string customerAttributesXml)
+ {
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(CustomerAttributesXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "CustomerAttributesXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(customerAttributesXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(customerAttributesXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
switch (elementNode.Name)
{
case "customer_attributes":
case "customer":
- this.LoadFromNode(elementNode);
- break;
- default:
+ LoadFromNode(elementNode);
break;
}
}
-
- return;
}
///
/// Constructor
///
/// XML node containing customer info (in expected format)
- internal CustomerAttributes(XmlNode customerAttributesNode) : base()
+ internal CustomerAttributes(XmlNode customerAttributesNode)
{
- if (customerAttributesNode == null) throw new ArgumentNullException("CustomerAttributesNode");
- if (customerAttributesNode.Name != "customer_attributes") throw new ArgumentException("Not a vaild customer attributes node", "customerAttributesNode");
- if (customerAttributesNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "customerAttributesNode");
- this.LoadFromNode(customerAttributesNode);
+ if (customerAttributesNode == null) throw new ArgumentNullException(nameof(customerAttributesNode));
+ if (customerAttributesNode.Name != "customer_attributes") throw new ArgumentException("Not a vaild customer attributes node", nameof(customerAttributesNode));
+ if (customerAttributesNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(customerAttributesNode));
+ LoadFromNode(customerAttributesNode);
}
///
@@ -156,59 +150,56 @@ internal CustomerAttributes(XmlNode customerAttributesNode) : base()
///
/// JsonObject containing customer info (in expected format)
public CustomerAttributes(JsonObject customerAttributesObject)
- : base()
{
- if (customerAttributesObject == null) throw new ArgumentNullException("customerAttributesObject");
- if (customerAttributesObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild customer attributes object", "customerAttributesObject");
+ if (customerAttributesObject == null) throw new ArgumentNullException(nameof(customerAttributesObject));
+ if (customerAttributesObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild customer attributes object", nameof(customerAttributesObject));
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing customer attribute data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
switch (key)
{
case FirstNameKey:
- this.FirstName = obj.GetJSONContentAsString(key);
+ FirstName = obj.GetJSONContentAsString(key);
break;
case LastNameKey:
- this.LastName = obj.GetJSONContentAsString(key);
+ LastName = obj.GetJSONContentAsString(key);
break;
case EmailKey:
- this.Email = obj.GetJSONContentAsString(key);
+ Email = obj.GetJSONContentAsString(key);
break;
case PhoneKey:
- this.Phone = obj.GetJSONContentAsString(key);
+ Phone = obj.GetJSONContentAsString(key);
break;
case OrganizationKey:
- this.Organization = HttpUtility.HtmlDecode(obj.GetJSONContentAsString(key));
+ Organization = HttpUtility.HtmlDecode(obj.GetJSONContentAsString(key));
break;
case ReferenceKey:
- _systemID = obj.GetJSONContentAsString(key);
+ _systemId = obj.GetJSONContentAsString(key);
break;
case ShippingAddressKey:
- this.ShippingAddress = obj.GetJSONContentAsString(key);
+ ShippingAddress = obj.GetJSONContentAsString(key);
break;
case ShippingAddress2Key:
- this.ShippingAddress2 = obj.GetJSONContentAsString(key);
+ ShippingAddress2 = obj.GetJSONContentAsString(key);
break;
case ShippingCityKey:
- this.ShippingCity = obj.GetJSONContentAsString(key);
+ ShippingCity = obj.GetJSONContentAsString(key);
break;
case ShippingStateKey:
- this.ShippingState = obj.GetJSONContentAsString(key);
+ ShippingState = obj.GetJSONContentAsString(key);
break;
case ShippingZipKey:
- this.ShippingZip = obj.GetJSONContentAsString(key);
+ ShippingZip = obj.GetJSONContentAsString(key);
break;
case ShippingCountryKey:
- this.ShippingCountry = obj.GetJSONContentAsString(key);
- break;
- default:
+ ShippingCountry = obj.GetJSONContentAsString(key);
break;
}
}
@@ -225,42 +216,40 @@ private void LoadFromNode(XmlNode customerNode)
switch (dataNode.Name)
{
case FirstNameKey:
- this.FirstName = dataNode.GetNodeContentAsString();
+ FirstName = dataNode.GetNodeContentAsString();
break;
case LastNameKey:
- this.LastName = dataNode.GetNodeContentAsString();
+ LastName = dataNode.GetNodeContentAsString();
break;
case EmailKey:
- this.Email = dataNode.GetNodeContentAsString();
+ Email = dataNode.GetNodeContentAsString();
break;
case PhoneKey:
- this.Phone = dataNode.GetNodeContentAsString();
+ Phone = dataNode.GetNodeContentAsString();
break;
case OrganizationKey:
- this.Organization = HttpUtility.HtmlDecode(dataNode.GetNodeContentAsString());
+ Organization = HttpUtility.HtmlDecode(dataNode.GetNodeContentAsString());
break;
case ReferenceKey:
- _systemID = dataNode.GetNodeContentAsString();
+ _systemId = dataNode.GetNodeContentAsString();
break;
case ShippingAddressKey:
- this.ShippingAddress = dataNode.GetNodeContentAsString();
+ ShippingAddress = dataNode.GetNodeContentAsString();
break;
case ShippingAddress2Key:
- this.ShippingAddress2 = dataNode.GetNodeContentAsString();
+ ShippingAddress2 = dataNode.GetNodeContentAsString();
break;
case ShippingCityKey:
- this.ShippingCity = dataNode.GetNodeContentAsString();
+ ShippingCity = dataNode.GetNodeContentAsString();
break;
case ShippingStateKey:
- this.ShippingState = dataNode.GetNodeContentAsString();
+ ShippingState = dataNode.GetNodeContentAsString();
break;
case ShippingZipKey:
- this.ShippingZip = dataNode.GetNodeContentAsString();
+ ShippingZip = dataNode.GetNodeContentAsString();
break;
case ShippingCountryKey:
- this.ShippingCountry = dataNode.GetNodeContentAsString();
- break;
- default:
+ ShippingCountry = dataNode.GetNodeContentAsString();
break;
}
}
@@ -338,7 +327,7 @@ public bool ShouldSerializeOrganization()
///
/// The customers vat number
///
- [XmlIgnore()]
+ [XmlIgnore]
public string VatNumber { get; set; }
///
/// Ignore, used for determining if the value should be serialized
@@ -434,18 +423,18 @@ public string SystemID
{
get
{
- return _systemID;
+ return _systemId;
}
set
{
- _systemID = value;
+ _systemId = value;
}
}
- private string _systemID = string.Empty;
+ private string _systemId = string.Empty;
///
/// Ignore, used for determining if the value should be serialized
///
- public bool ShouldSerializeSystemID()
+ public bool ShouldSerializeSystemId()
{
return !string.IsNullOrEmpty(SystemID);
}
@@ -458,7 +447,7 @@ public string FullName
{
get
{
- return string.Format("{0} {1}", this.LastName, this.FirstName).Trim();
+ return string.Format("{0} {1}", LastName, FirstName).Trim();
}
}
@@ -473,7 +462,7 @@ public string FullName
/// The result of the comparison
public int CompareTo(ICustomerAttributes other)
{
- return this.FullName.CompareTo(other.FullName);
+ return string.Compare(FullName, other.FullName, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -487,7 +476,7 @@ public int CompareTo(ICustomerAttributes other)
/// The result of the comparison
public int CompareTo(CustomerAttributes other)
{
- return this.FullName.CompareTo(other.FullName);
+ return string.Compare(FullName, other.FullName, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -500,7 +489,7 @@ public int CompareTo(CustomerAttributes other)
/// The full name of the customer
public override string ToString()
{
- return this.FullName;
+ return FullName;
}
#endregion
diff --git a/Source/Chargify.NET/Data/Controls/CountryDropDownList.cs b/Source/Chargify.NET/Data/Controls/CountryDropDownList.cs
index e5cfb62..6e66eee 100644
--- a/Source/Chargify.NET/Data/Controls/CountryDropDownList.cs
+++ b/Source/Chargify.NET/Data/Controls/CountryDropDownList.cs
@@ -5,6 +5,7 @@
using System.Web.UI.WebControls;
using ChargifyNET.Data;
+// ReSharper disable once CheckNamespace
namespace ChargifyNET.Controls
{
///
@@ -26,7 +27,7 @@ protected override void OnLoad(EventArgs e)
{
// Since the data comes in as Unicode, we need to ASCII encode it for HTML.
string countryName = Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(country.Value));
- this.Items.Add(new ListItem(countryName, country.Key));
+ Items.Add(new ListItem(countryName, country.Key));
}
}
base.OnLoad(e);
diff --git a/Source/Chargify.NET/Data/CountryNameLookup.cs b/Source/Chargify.NET/Data/CountryNameLookup.cs
index da0d369..e1057aa 100644
--- a/Source/Chargify.NET/Data/CountryNameLookup.cs
+++ b/Source/Chargify.NET/Data/CountryNameLookup.cs
@@ -13,24 +13,24 @@ namespace ChargifyNET.Data
///
public sealed class CountryNameLookup
{
- private static XmlDocument countries;
- private const string countriesFilename = @"ISO_3166-1_list_en.xml";
+ private static XmlDocument _countries;
+ private const string CountriesFilename = @"ISO_3166-1_list_en.xml";
///
/// Constructor
///
public CountryNameLookup()
{
- countries = new XmlDocument();
+ _countries = new XmlDocument();
- var resourceFileWithNamespace = string.Format("{0}.{1}", GetType().Namespace, countriesFilename);
+ var resourceFileWithNamespace = $"{GetType().Namespace}.{CountriesFilename}";
var fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceFileWithNamespace);
if (fileStream != null)
{
using (var reader = new StreamReader(fileStream))
{
- countries.LoadXml(reader.ReadToEnd());
+ _countries.LoadXml(reader.ReadToEnd());
}
}
}
@@ -43,10 +43,12 @@ public CountryNameLookup()
public string GetCountryName(string countryCode2)
{
string result = String.Empty;
- var countryNode = countries.SelectSingleNode(string.Format(@"/ISO_3166-1_List_en/ISO_3166-1_Entry/ISO_3166-1_Alpha-2_Code_element[.=""{0}""]", countryCode2)).ParentNode;
- if (countryNode != null)
+ var selectSingleNode = _countries.SelectSingleNode($@"/ISO_3166-1_List_en/ISO_3166-1_Entry/ISO_3166-1_Alpha-2_Code_element[.=""{countryCode2}""]");
+ var countryNode = selectSingleNode?.ParentNode;
+ var singleCountryNode = countryNode?.SelectSingleNode("ISO_3166-1_Country_name");
+ if (singleCountryNode != null)
{
- var countryName = countryNode.SelectSingleNode("ISO_3166-1_Country_name").InnerText.ToLower();
+ var countryName = singleCountryNode.InnerText.ToLower();
result = char.ToUpper(countryName[0]) + countryName.Substring(1);
}
return result;
@@ -59,14 +61,14 @@ public string GetCountryName(string countryCode2)
/// The dictionary of data in ISO 3166-1 Alpha 2
public Dictionary GetData()
{
- Dictionary result = new Dictionary();
- XDocument doc = XDocument.Parse(countries.OuterXml);
+ Dictionary result;
+ XDocument doc = XDocument.Parse(_countries.OuterXml);
result = (from c in doc.Descendants("ISO_3166-1_Entry")
select new
{
- Code = (string)c.Element("ISO_3166-1_Alpha-2_Code_element").Value,
- Name = (string)c.Element("ISO_3166-1_Country_name").Value
+ Code = c.Element("ISO_3166-1_Alpha-2_Code_element")?.Value,
+ Name = c.Element("ISO_3166-1_Country_name")?.Value
}).ToDictionary(c => c.Code, c => c.Name);
return result;
diff --git a/Source/Chargify.NET/GlobalSuppressions.cs b/Source/Chargify.NET/GlobalSuppressions.cs
new file mode 100644
index 0000000..f9ff4eb
--- /dev/null
+++ b/Source/Chargify.NET/GlobalSuppressions.cs
@@ -0,0 +1,9 @@
+
+// This file is used by Code Analysis to maintain SuppressMessage
+// attributes that are applied to this project.
+// Project-level suppressions either have no target or are given
+// a specific target and scoped to a namespace, type, member, etc.
+
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Potential Code Quality Issues", "RECS0022:A catch clause that catches System.Exception and has an empty body", Justification = "", Scope = "member", Target = "~M:ChargifyNET.UsefulExtensions.GetLateBoundRoleEnvironmentValue(System.String)~System.String")]
+[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Potential Code Quality Issues", "RECS0022:A catch clause that catches System.Exception and has an empty body", Justification = "", Scope = "member", Target = "~M:ChargifyNET.UsefulExtensions.IsRunningAzure~System.Boolean")]
+
diff --git a/Source/Chargify.NET/HttpRequestMethod.cs b/Source/Chargify.NET/HttpRequestMethod.cs
index 42fead6..ba11e0b 100644
--- a/Source/Chargify.NET/HttpRequestMethod.cs
+++ b/Source/Chargify.NET/HttpRequestMethod.cs
@@ -52,10 +52,22 @@ public enum HttpRequestMethod
Delete
}
+ ///
+ /// The type of payment profile
+ ///
public enum PaymentProfileType
{
+ ///
+ /// Credit card
+ ///
Credit_Card,
+ ///
+ /// Direct bank account
+ ///
Bank_Account,
+ ///
+ /// Paypal account
+ ///
PayPal_Account
}
}
\ No newline at end of file
diff --git a/Source/Chargify.NET/Interfaces/IAdjustment.cs b/Source/Chargify.NET/Interfaces/IAdjustment.cs
index fe421e4..43d51ea 100644
--- a/Source/Chargify.NET/Interfaces/IAdjustment.cs
+++ b/Source/Chargify.NET/Interfaces/IAdjustment.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IBillingManagementInfo.cs b/Source/Chargify.NET/Interfaces/IBillingManagementInfo.cs
index 0f30581..9e74b5b 100644
--- a/Source/Chargify.NET/Interfaces/IBillingManagementInfo.cs
+++ b/Source/Chargify.NET/Interfaces/IBillingManagementInfo.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ICharge.cs b/Source/Chargify.NET/Interfaces/ICharge.cs
index e4ecac9..035cc20 100644
--- a/Source/Chargify.NET/Interfaces/ICharge.cs
+++ b/Source/Chargify.NET/Interfaces/ICharge.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IChargifyConnect.cs b/Source/Chargify.NET/Interfaces/IChargifyConnect.cs
index 5b7055c..05f84c4 100644
--- a/Source/Chargify.NET/Interfaces/IChargifyConnect.cs
+++ b/Source/Chargify.NET/Interfaces/IChargifyConnect.cs
@@ -1,4 +1,5 @@
-#region License, Terms and Conditions
+
+#region License, Terms and Conditions
//
// IChargifyConnect.cs
//
@@ -26,6 +27,8 @@
// DEALINGS IN THE SOFTWARE.
//
#endregion
+
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
@@ -315,10 +318,39 @@ public interface IChargifyConnect
#endregion
#region Notes
+ ///
+ /// Create note
+ ///
+ /// The new note information
+ /// The note (with id) if successful, null otherwise.
INote CreateNote(INote NewNote);
+ ///
+ /// Gets the notes for a particular subscription
+ ///
+ /// The id of the subscription
+ /// The collection of notes, keyed by note id. Empty collection otherwise.
IDictionary GetNotesForSubscription(int SubscriptionID);
+ ///
+ /// Load a particular note
+ ///
+ /// The related subscription id
+ /// The id of the ntoe
+ ///
INote LoadNote(int SubscriptionID, int NoteID);
+
+ ///
+ /// Delete a note
+ ///
+ /// The related subscription id
+ /// The id of the ntoe
+ /// True if successful, false otherwise.
bool DeleteNote(int SubscriptionID, int NoteID);
+ ///
+ ///
+ ///
+ /// The related subscription id
+ /// The updated note information
+ /// The updated note, if successful. Null otherwise.
INote UpdateNote(int SubscriptionID, INote UpdatedNote);
#endregion
@@ -694,6 +726,7 @@ public interface IChargifyConnect
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
/// The suscription to update
/// The new product
+ /// Should the product change be delayed?
/// The new subscription resulting from the change
ISubscription EditSubscriptionProduct(ISubscription Subscription, IProduct Product, bool? ProductChangeDelayed = null);
///
@@ -702,6 +735,7 @@ public interface IChargifyConnect
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
/// The suscription to update
/// The handle to the new product
+ /// Should the product change be delayed?
/// The new subscription resulting from the change
ISubscription EditSubscriptionProduct(ISubscription Subscription, string ProductHandle, bool? ProductChangeDelayed = null);
///
@@ -710,6 +744,7 @@ public interface IChargifyConnect
/// Does NOT prorate. Use MigrateSubscriptionProduct to get proration to work.
/// The ID of the suscription to update
/// The new product
+ /// Should the product change be delayed?
/// The new subscription resulting from the change
ISubscription EditSubscriptionProduct(int SubscriptionID, IProduct Product, bool? ProductChangeDelayed = null);
///
diff --git a/Source/Chargify.NET/Interfaces/IComponent.cs b/Source/Chargify.NET/Interfaces/IComponent.cs
index 0e1b3a6..b6c3e93 100644
--- a/Source/Chargify.NET/Interfaces/IComponent.cs
+++ b/Source/Chargify.NET/Interfaces/IComponent.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IComponentAllocation.cs b/Source/Chargify.NET/Interfaces/IComponentAllocation.cs
index 525ea21..d0f6047 100644
--- a/Source/Chargify.NET/Interfaces/IComponentAllocation.cs
+++ b/Source/Chargify.NET/Interfaces/IComponentAllocation.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IComponentAttributes.cs b/Source/Chargify.NET/Interfaces/IComponentAttributes.cs
index 1060181..1d1797a 100644
--- a/Source/Chargify.NET/Interfaces/IComponentAttributes.cs
+++ b/Source/Chargify.NET/Interfaces/IComponentAttributes.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/IComponentInfo.cs b/Source/Chargify.NET/Interfaces/IComponentInfo.cs
index 5944042..9b6b629 100644
--- a/Source/Chargify.NET/Interfaces/IComponentInfo.cs
+++ b/Source/Chargify.NET/Interfaces/IComponentInfo.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
@@ -101,10 +102,10 @@ public interface IComponentInfo : IComparable
///
/// The name of the component as created by the Chargify user
///
- string Name { get; }
-
- ///
- /// The description of the component as created by the Chargify user
+ string Name { get; }
+
+ ///
+ /// The description of the component as created by the Chargify user
///
string Description { get; }
diff --git a/Source/Chargify.NET/Interfaces/ICoupon.cs b/Source/Chargify.NET/Interfaces/ICoupon.cs
index 13194c4..e457a48 100644
--- a/Source/Chargify.NET/Interfaces/ICoupon.cs
+++ b/Source/Chargify.NET/Interfaces/ICoupon.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ICredit.cs b/Source/Chargify.NET/Interfaces/ICredit.cs
index d8c7ca5..83a0065 100644
--- a/Source/Chargify.NET/Interfaces/ICredit.cs
+++ b/Source/Chargify.NET/Interfaces/ICredit.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ICreditCardAttributes.cs b/Source/Chargify.NET/Interfaces/ICreditCardAttributes.cs
index c0db5c6..b626ad4 100644
--- a/Source/Chargify.NET/Interfaces/ICreditCardAttributes.cs
+++ b/Source/Chargify.NET/Interfaces/ICreditCardAttributes.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/ICustomer.cs b/Source/Chargify.NET/Interfaces/ICustomer.cs
index c5e7bc5..f9a30ac 100644
--- a/Source/Chargify.NET/Interfaces/ICustomer.cs
+++ b/Source/Chargify.NET/Interfaces/ICustomer.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ICustomerAttributes.cs b/Source/Chargify.NET/Interfaces/ICustomerAttributes.cs
index e895c87..d44f4ec 100644
--- a/Source/Chargify.NET/Interfaces/ICustomerAttributes.cs
+++ b/Source/Chargify.NET/Interfaces/ICustomerAttributes.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IInvoice.cs b/Source/Chargify.NET/Interfaces/IInvoice.cs
index b307194..a701648 100644
--- a/Source/Chargify.NET/Interfaces/IInvoice.cs
+++ b/Source/Chargify.NET/Interfaces/IInvoice.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IInvoicePaymentAndCredit.cs b/Source/Chargify.NET/Interfaces/IInvoicePaymentAndCredit.cs
index 1b20f50..b66ce2c 100644
--- a/Source/Chargify.NET/Interfaces/IInvoicePaymentAndCredit.cs
+++ b/Source/Chargify.NET/Interfaces/IInvoicePaymentAndCredit.cs
@@ -1,3 +1,5 @@
+
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/IMetadata.cs b/Source/Chargify.NET/Interfaces/IMetadata.cs
index 69fd2cf..4cb2bf6 100644
--- a/Source/Chargify.NET/Interfaces/IMetadata.cs
+++ b/Source/Chargify.NET/Interfaces/IMetadata.cs
@@ -1,3 +1,4 @@
+
#region License, Terms and Conditions
//
// IMetadata.cs
@@ -27,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/IMetadataResult.cs b/Source/Chargify.NET/Interfaces/IMetadataResult.cs
index c794a75..3735b35 100644
--- a/Source/Chargify.NET/Interfaces/IMetadataResult.cs
+++ b/Source/Chargify.NET/Interfaces/IMetadataResult.cs
@@ -1,3 +1,4 @@
+
#region License, Terms and Conditions
//
// IMetadataResult.cs
@@ -27,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IMigration.cs b/Source/Chargify.NET/Interfaces/IMigration.cs
index bd2971f..1aa57bd 100644
--- a/Source/Chargify.NET/Interfaces/IMigration.cs
+++ b/Source/Chargify.NET/Interfaces/IMigration.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/INote.cs b/Source/Chargify.NET/Interfaces/INote.cs
index 840ca1b..b7f30b1 100644
--- a/Source/Chargify.NET/Interfaces/INote.cs
+++ b/Source/Chargify.NET/Interfaces/INote.cs
@@ -28,19 +28,46 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
using System;
#endregion
+ ///
+ /// Notes allow you to record information about a particular Subscription in a free text format.
+ ///
public interface INote : IComparable
{
+ ///
+ /// The note's unique ID
+ ///
int ID { get; }
+
+ ///
+ /// The main text context of the note
+ ///
string Body { get; }
+
+ ///
+ /// The ID of the related subscription
+ ///
int SubscriptionID { get; }
+
+ ///
+ /// The date and time the note was created
+ ///
DateTime CreatedAt { get; }
+
+ ///
+ /// Last update timestamp
+ ///
DateTime UpdatedAt { get; }
+
+ ///
+ /// Whether or not it is pinned to the top of the list of notes
+ ///
bool Sticky { get; }
}
}
diff --git a/Source/Chargify.NET/Interfaces/IPayment.cs b/Source/Chargify.NET/Interfaces/IPayment.cs
index 87e7bf6..710244b 100644
--- a/Source/Chargify.NET/Interfaces/IPayment.cs
+++ b/Source/Chargify.NET/Interfaces/IPayment.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IPaymentProfileAttributes.cs b/Source/Chargify.NET/Interfaces/IPaymentProfileAttributes.cs
index 30dbac6..c2c282b 100644
--- a/Source/Chargify.NET/Interfaces/IPaymentProfileAttributes.cs
+++ b/Source/Chargify.NET/Interfaces/IPaymentProfileAttributes.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IPaymentProfileBase.cs b/Source/Chargify.NET/Interfaces/IPaymentProfileBase.cs
index 3d19332..6e7d8ac 100644
--- a/Source/Chargify.NET/Interfaces/IPaymentProfileBase.cs
+++ b/Source/Chargify.NET/Interfaces/IPaymentProfileBase.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/IPaymentProfileView.cs b/Source/Chargify.NET/Interfaces/IPaymentProfileView.cs
index d0849f0..9ee95b3 100644
--- a/Source/Chargify.NET/Interfaces/IPaymentProfileView.cs
+++ b/Source/Chargify.NET/Interfaces/IPaymentProfileView.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/IProduct.cs b/Source/Chargify.NET/Interfaces/IProduct.cs
index 7120385..2466bd9 100644
--- a/Source/Chargify.NET/Interfaces/IProduct.cs
+++ b/Source/Chargify.NET/Interfaces/IProduct.cs
@@ -1,4 +1,5 @@
-#region License, Terms and Conditions
+
+#region License, Terms and Conditions
//
// IProduct.cs
//
@@ -26,6 +27,8 @@
// DEALINGS IN THE SOFTWARE.
//
#endregion
+
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IProductFamily.cs b/Source/Chargify.NET/Interfaces/IProductFamily.cs
index 9f9e6ce..fd66916 100644
--- a/Source/Chargify.NET/Interfaces/IProductFamily.cs
+++ b/Source/Chargify.NET/Interfaces/IProductFamily.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IProductFamilyAttributes.cs b/Source/Chargify.NET/Interfaces/IProductFamilyAttributes.cs
index 649e967..f701b6f 100644
--- a/Source/Chargify.NET/Interfaces/IProductFamilyAttributes.cs
+++ b/Source/Chargify.NET/Interfaces/IProductFamilyAttributes.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IPublicSignupPage.cs b/Source/Chargify.NET/Interfaces/IPublicSignupPage.cs
index 6b88f2a..89a3413 100644
--- a/Source/Chargify.NET/Interfaces/IPublicSignupPage.cs
+++ b/Source/Chargify.NET/Interfaces/IPublicSignupPage.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IRefund.cs b/Source/Chargify.NET/Interfaces/IRefund.cs
index 84ad558..2ba1c04 100644
--- a/Source/Chargify.NET/Interfaces/IRefund.cs
+++ b/Source/Chargify.NET/Interfaces/IRefund.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IRenewalDetails.cs b/Source/Chargify.NET/Interfaces/IRenewalDetails.cs
index 46cd6b2..54069e0 100644
--- a/Source/Chargify.NET/Interfaces/IRenewalDetails.cs
+++ b/Source/Chargify.NET/Interfaces/IRenewalDetails.cs
@@ -28,14 +28,14 @@
//
#endregion
-using Newtonsoft.Json;
using System;
using System.Collections.Generic;
-using System.Xml.Serialization;
using System.Xml;
+using System.Xml.Serialization;
using ChargifyNET.Json;
-using System.IO;
+using Newtonsoft.Json;
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
@@ -153,12 +153,12 @@ public RenewalLineItem(XmlNode node)
// Deserialize
var obj = node.ConvertNode();
- this.TransactionType = obj.TransactionType;
- this.Kind = obj.Kind;
- this.AmountInCents = obj.AmountInCents;
- this.Memo = obj.Memo;
- this.DiscountAmountInCents = obj.DiscountAmountInCents;
- this.TaxableAmountInCents = obj.TaxableAmountInCents;
+ TransactionType = obj.TransactionType;
+ Kind = obj.Kind;
+ AmountInCents = obj.AmountInCents;
+ Memo = obj.Memo;
+ DiscountAmountInCents = obj.DiscountAmountInCents;
+ TaxableAmountInCents = obj.TaxableAmountInCents;
}
///
@@ -170,12 +170,12 @@ public RenewalLineItem(JsonObject renewalLineItem)
// Deserialize
var obj = JsonConvert.DeserializeObject(renewalLineItem.ToString());
- this.TransactionType = obj.TransactionType;
- this.Kind = obj.Kind;
- this.AmountInCents = obj.AmountInCents;
- this.Memo = obj.Memo;
- this.DiscountAmountInCents = obj.DiscountAmountInCents;
- this.TaxableAmountInCents = obj.TaxableAmountInCents;
+ TransactionType = obj.TransactionType;
+ Kind = obj.Kind;
+ AmountInCents = obj.AmountInCents;
+ Memo = obj.Memo;
+ DiscountAmountInCents = obj.DiscountAmountInCents;
+ TaxableAmountInCents = obj.TaxableAmountInCents;
}
#endregion
diff --git a/Source/Chargify.NET/Interfaces/ISiteStatistics.cs b/Source/Chargify.NET/Interfaces/ISiteStatistics.cs
index 31a0533..b1795cc 100644
--- a/Source/Chargify.NET/Interfaces/ISiteStatistics.cs
+++ b/Source/Chargify.NET/Interfaces/ISiteStatistics.cs
@@ -27,6 +27,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
///
diff --git a/Source/Chargify.NET/Interfaces/IStatement.cs b/Source/Chargify.NET/Interfaces/IStatement.cs
index 0fb2a75..55a14eb 100644
--- a/Source/Chargify.NET/Interfaces/IStatement.cs
+++ b/Source/Chargify.NET/Interfaces/IStatement.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ISubscription.cs b/Source/Chargify.NET/Interfaces/ISubscription.cs
index a248378..5512b4b 100644
--- a/Source/Chargify.NET/Interfaces/ISubscription.cs
+++ b/Source/Chargify.NET/Interfaces/ISubscription.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ISubscriptionCreateOptions.cs b/Source/Chargify.NET/Interfaces/ISubscriptionCreateOptions.cs
index 45c54bf..007c5aa 100644
--- a/Source/Chargify.NET/Interfaces/ISubscriptionCreateOptions.cs
+++ b/Source/Chargify.NET/Interfaces/ISubscriptionCreateOptions.cs
@@ -27,6 +27,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
@@ -158,6 +159,9 @@ public interface ISubscriptionCreateOptions
}
+ ///
+ /// Components
+ ///
[XmlType("component")]
[Serializable]
public class ComponentDetails
@@ -175,6 +179,9 @@ public bool ShouldSerializeComponentID()
return ComponentID.HasValue;
}
+ ///
+ /// Enabled?
+ ///
[XmlElement("enabled")]
public bool? Enabled { get; set; }
///
@@ -185,8 +192,12 @@ public bool ShouldSerializeEnabled()
return Enabled.HasValue;
}
+ ///
+ /// The allocated quantity
+ ///
[XmlElement("allocated_quantity")]
public int? AllocatedQuantity { get; set; }
+
///
/// Ignore, used to determine if the field should be serialized
///
@@ -216,10 +227,16 @@ public bool ShouldSerializeAllocatedQuantity()
//}
}
+ ///
+ /// Calendar billing
+ ///
[XmlType("calendar_billing")]
[Serializable]
public class CalendarBillingAttributes
{
+ ///
+ /// The day that processing is performed
+ ///
[XmlElement("snap_day")]
public string SnapDay { get; set; }
///
@@ -231,6 +248,9 @@ public bool ShouldSerializeSnapDay()
}
}
+ ///
+ /// Subscription creation options
+ ///
[XmlType("subscription")]
[Serializable]
public class SubscriptionCreateOptions: ISubscriptionCreateOptions
diff --git a/Source/Chargify.NET/Interfaces/ISubscriptionOverride.cs b/Source/Chargify.NET/Interfaces/ISubscriptionOverride.cs
index d7bb190..d0799ec 100644
--- a/Source/Chargify.NET/Interfaces/ISubscriptionOverride.cs
+++ b/Source/Chargify.NET/Interfaces/ISubscriptionOverride.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/ITransaction.cs b/Source/Chargify.NET/Interfaces/ITransaction.cs
index 810329d..1ffdfa6 100644
--- a/Source/Chargify.NET/Interfaces/ITransaction.cs
+++ b/Source/Chargify.NET/Interfaces/ITransaction.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Interfaces/IUsage.cs b/Source/Chargify.NET/Interfaces/IUsage.cs
index f5917ec..c726ce7 100644
--- a/Source/Chargify.NET/Interfaces/IUsage.cs
+++ b/Source/Chargify.NET/Interfaces/IUsage.cs
@@ -28,6 +28,7 @@
//
#endregion
+// ReSharper disable once CheckNamespace
namespace ChargifyNET
{
#region Imports
diff --git a/Source/Chargify.NET/Invoice.cs b/Source/Chargify.NET/Invoice.cs
index 70e81ef..08f8b8d 100644
--- a/Source/Chargify.NET/Invoice.cs
+++ b/Source/Chargify.NET/Invoice.cs
@@ -1,19 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Xml;
+using ChargifyNET.Json;
+
namespace ChargifyNET
{
- using System;
- using System.Collections.Generic;
- using System.Xml;
- using ChargifyNET.Json;
-
///
/// Invoice Billing allows you to bill your customers manually by sending them an invoice each month. Subscriptions with invoice billing enabled will not be charged automatically.
///
public class Invoice : ChargifyEntity, IInvoice
{
#region Field Keys
- private const string SubscriptionIDKey = "subscription_id";
- private const string StatementIDKey = "statement_id";
- private const string SiteIDKey = "site_id";
+ private const string SubscriptionIdKey = "subscription_id";
+ private const string StatementIdKey = "statement_id";
+ private const string SiteIdKey = "site_id";
private const string StateKey = "state";
private const string TotalAmountInCentsKey = "total_amount_in_cents";
private const string PaidAtKey = "paid_at";
@@ -29,19 +29,19 @@ public class Invoice : ChargifyEntity, IInvoice
///
/// Constructor
///
- private Invoice() : base() { }
+ private Invoice()
+ { }
///
/// Constructor
///
- /// An XML string containing a invoice node
- public Invoice(string invoiceXML)
- : base()
+ /// An XML string containing a invoice node
+ public Invoice(string invoiceXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(invoiceXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "invoiceXML");
+ doc.LoadXml(invoiceXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(invoiceXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -52,7 +52,7 @@ public Invoice(string invoiceXML)
}
}
// if we get here, then no invoice info was found
- throw new ArgumentException("XML does not contain invoice information", "invoiceXML");
+ throw new ArgumentException("XML does not contain invoice information", nameof(invoiceXml));
}
///
@@ -60,12 +60,11 @@ public Invoice(string invoiceXML)
///
/// An xml node with invoice information
public Invoice(XmlNode invoiceNode)
- : base()
{
- if (invoiceNode == null) throw new ArgumentNullException("invoiceNode");
- if (invoiceNode.Name != "invoice") throw new ArgumentException("Not a vaild invoice node", "invoiceNode");
- if (invoiceNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "invoiceNode");
- this.LoadFromNode(invoiceNode);
+ if (invoiceNode == null) throw new ArgumentNullException(nameof(invoiceNode));
+ if (invoiceNode.Name != "invoice") throw new ArgumentException("Not a vaild invoice node", nameof(invoiceNode));
+ if (invoiceNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(invoiceNode));
+ LoadFromNode(invoiceNode);
}
///
@@ -73,14 +72,13 @@ public Invoice(XmlNode invoiceNode)
///
/// An JsonObject with invoice information
public Invoice(JsonObject invoiceObject)
- : base()
{
- if (invoiceObject == null) throw new ArgumentNullException("invoiceObject");
- if (invoiceObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild invoice object", "invoiceObject");
- this.LoadFromJSON(invoiceObject);
+ if (invoiceObject == null) throw new ArgumentNullException(nameof(invoiceObject));
+ if (invoiceObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild invoice object", nameof(invoiceObject));
+ LoadFromJson(invoiceObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get invoice info, and parse it out
foreach (string key in obj.Keys)
@@ -90,14 +88,14 @@ private void LoadFromJSON(JsonObject obj)
case IDKey:
m_id = obj.GetJSONContentAsInt(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
- case StatementIDKey:
- _statementID = obj.GetJSONContentAsInt(key);
+ case StatementIdKey:
+ _statementId = obj.GetJSONContentAsInt(key);
break;
- case SiteIDKey:
- _siteID = obj.GetJSONContentAsInt(key);
+ case SiteIdKey:
+ _siteId = obj.GetJSONContentAsInt(key);
break;
case StateKey:
_state = obj.GetJSONContentAsSubscriptionState(key);
@@ -125,21 +123,20 @@ private void LoadFromJSON(JsonObject obj)
JsonArray chargesArray = obj[key] as JsonArray;
if (chargesArray != null)
{
- foreach (JsonObject charge in chargesArray.Items)
+ foreach (var jsonValue in chargesArray.Items)
{
+ var charge = (JsonObject) jsonValue;
_charges.Add(charge.GetJSONContentAsCharge("charge"));
}
}
// Sanity check, should be equal.
- if (chargesArray.Length != _charges.Count)
+ if (chargesArray != null && chargesArray.Length != _charges.Count)
{
throw new JsonParseException(string.Format("Unable to parse charges ({0} != {1})", chargesArray.Length, _charges.Count));
}
break;
case PaymentsAndCreditsKey:
break;
- default:
- break;
}
}
}
@@ -154,14 +151,14 @@ private void LoadFromNode(XmlNode obj)
case IDKey:
m_id = dataNode.GetNodeContentAsInt();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
- case StatementIDKey:
- _statementID = dataNode.GetNodeContentAsInt();
+ case StatementIdKey:
+ _statementId = dataNode.GetNodeContentAsInt();
break;
- case SiteIDKey:
- _siteID = dataNode.GetNodeContentAsInt();
+ case SiteIdKey:
+ _siteId = dataNode.GetNodeContentAsInt();
break;
case StateKey:
_state = dataNode.GetNodeContentAsSubscriptionState();
@@ -193,15 +190,11 @@ private void LoadFromNode(XmlNode obj)
case "charge":
_charges.Add(childNode.GetNodeContentAsCharge());
break;
- default:
- break;
}
}
break;
case PaymentsAndCreditsKey:
break;
- default:
- break;
}
}
}
@@ -211,71 +204,71 @@ private void LoadFromNode(XmlNode obj)
///
/// The subscription unique id within Chargify
///
- public int SubscriptionID { get { return this._subscriptionID; } }
- private int _subscriptionID = int.MinValue;
+ public int SubscriptionID { get { return _subscriptionId; } }
+ private int _subscriptionId = int.MinValue;
///
/// The statement unique id within Chargify
///
- public int StatementID { get { return this._statementID; } }
- private int _statementID = int.MinValue;
+ public int StatementID { get { return _statementId; } }
+ private int _statementId = int.MinValue;
///
/// The site unique id within Chargify
///
- public int SiteID { get { return this._siteID; } }
- private int _siteID = int.MinValue;
+ public int SiteID { get { return _siteId; } }
+ private int _siteId = int.MinValue;
///
/// The current state of the subscription associated with this invoice. Please see the documentation for Subscription States
///
- public SubscriptionState State { get { return this._state; } }
+ public SubscriptionState State { get { return _state; } }
private SubscriptionState _state = SubscriptionState.Unknown;
///
/// Gives the current invoice amount in the number of cents (ie. the sum of charges, in cents)
///
- public int TotalAmountInCents { get { return this._totalAmountInCents; } }
+ public int TotalAmountInCents { get { return _totalAmountInCents; } }
private int _totalAmountInCents = int.MinValue;
///
/// Gives the current invoice amount in the number of cents (ie. the sum of charges, in dollars and cents)
///
- public decimal TotalAmount { get { return Convert.ToDecimal(this._totalAmountInCents) / 100; } }
+ public decimal TotalAmount { get { return Convert.ToDecimal(_totalAmountInCents) / 100; } }
///
/// The date/time when the invoice was paid in full
///
- public DateTime PaidAt { get { return this._paidAt; } }
+ public DateTime PaidAt { get { return _paidAt; } }
private DateTime _paidAt = DateTime.MinValue;
///
/// The creation date/time for this invoice
///
- public DateTime CreatedAt { get { return this._createdAt; } }
+ public DateTime CreatedAt { get { return _createdAt; } }
private DateTime _createdAt = DateTime.MinValue;
///
/// The date/time of last update for this invoice
///
- public DateTime UpdatedAt { get { return this._updatedAt; } }
+ public DateTime UpdatedAt { get { return _updatedAt; } }
private DateTime _updatedAt = DateTime.MinValue;
///
/// Gives the current outstanding invoice balance in the number of cents
///
- public int AmountDueInCents { get { return this._amountDueInCents; } }
+ public int AmountDueInCents { get { return _amountDueInCents; } }
private int _amountDueInCents = int.MinValue;
///
/// Gives the current outstanding invoice balance in the number of dollars and cents
///
- public decimal AmountDue { get { return Convert.ToDecimal(this._amountDueInCents) / 100; } }
+ public decimal AmountDue { get { return Convert.ToDecimal(_amountDueInCents) / 100; } }
///
/// The unique (to this site) identifier for this invoice
///
- public string Number { get { return this._number; } }
+ public string Number { get { return _number; } }
private string _number = string.Empty;
///
@@ -287,7 +280,7 @@ private void LoadFromNode(XmlNode obj)
///
/// A list of the financial transactions that modify the amount due
///
- public List PaymentsAndCredits { get { return this._paymentsAndCredits; } }
+ public List PaymentsAndCredits { get { return _paymentsAndCredits; } }
private List _paymentsAndCredits = new List();
#endregion
}
diff --git a/Source/Chargify.NET/Json/JsonArray.cs b/Source/Chargify.NET/Json/JsonArray.cs
index 7e724cf..36305ee 100644
--- a/Source/Chargify.NET/Json/JsonArray.cs
+++ b/Source/Chargify.NET/Json/JsonArray.cs
@@ -14,7 +14,7 @@ public sealed class JsonArray : JsonValue
///
public JsonValue[] Items
{
- get { return (JsonValue[])_items.ToArray(); }
+ get { return _items.ToArray(); }
}
///
@@ -51,7 +51,7 @@ internal static JsonArray Parse(string str, ref int position)
position++;
// Check for empty array
- if (firstItem == true)
+ if (firstItem)
{
firstItem = false;
EatSpaces(str, ref position);
diff --git a/Source/Chargify.NET/Json/JsonBoolean.cs b/Source/Chargify.NET/Json/JsonBoolean.cs
index 6b9a73f..1fecf11 100644
--- a/Source/Chargify.NET/Json/JsonBoolean.cs
+++ b/Source/Chargify.NET/Json/JsonBoolean.cs
@@ -30,7 +30,7 @@ public JsonBoolean(bool value)
///
public override string ToString()
{
- return this.Value.ToString();
+ return Value.ToString();
}
}
}
diff --git a/Source/Chargify.NET/Json/JsonHelper.cs b/Source/Chargify.NET/Json/JsonHelper.cs
index aeac900..7b21208 100644
--- a/Source/Chargify.NET/Json/JsonHelper.cs
+++ b/Source/Chargify.NET/Json/JsonHelper.cs
@@ -51,8 +51,9 @@ public static void ValidateJsonField(JsonObject jsonObject, string fieldName, Ty
if ((jsonObject[fieldName] == null) && (fieldType != null))
throw new NullReferenceException(string.Format("jsonObject field '{0}' == NULL", fieldName));
- if (jsonObject[fieldName].GetType() != fieldType)
- throw new JsonException(string.Format("JSON field: '{0}', type is '{1}', but expecting: '{2}'", fieldName, jsonObject[fieldName].GetType(), fieldType));
+ var jsonValue = jsonObject[fieldName];
+ if (jsonValue != null && jsonValue.GetType() != fieldType)
+ throw new JsonException(string.Format("JSON field: '{0}', type is '{1}', but expecting: '{2}'", fieldName, jsonValue.GetType(), fieldType));
}
}
}
diff --git a/Source/Chargify.NET/Json/JsonNumber.cs b/Source/Chargify.NET/Json/JsonNumber.cs
index c3fc6ba..3eded2c 100644
--- a/Source/Chargify.NET/Json/JsonNumber.cs
+++ b/Source/Chargify.NET/Json/JsonNumber.cs
@@ -1,4 +1,6 @@
-namespace ChargifyNET.Json
+using System.Globalization;
+
+namespace ChargifyNET.Json
{
///
/// Object representing a JsonNumber
@@ -45,16 +47,14 @@ public static bool IsNumberPart(char ch)
internal static JsonNumber Parse(string str, ref int position)
{
- double value;
-
- JsonString.EatSpaces(str, ref position);
+ EatSpaces(str, ref position);
int startPos = position;
while (IsNumberPart(str[position]))
position++;
- value = double.Parse(str.Substring(startPos, position - startPos),
- System.Globalization.CultureInfo.InvariantCulture);
+ var value = double.Parse(str.Substring(startPos, position - startPos),
+ CultureInfo.InvariantCulture);
return new JsonNumber(value);
}
@@ -65,7 +65,7 @@ internal static JsonNumber Parse(string str, ref int position)
///
public override string ToString()
{
- return string.Format("{0}", this.DoubleValue);
+ return string.Format("{0}", DoubleValue);
}
}
}
diff --git a/Source/Chargify.NET/Json/JsonObject.cs b/Source/Chargify.NET/Json/JsonObject.cs
index 7b10e04..220c013 100644
--- a/Source/Chargify.NET/Json/JsonObject.cs
+++ b/Source/Chargify.NET/Json/JsonObject.cs
@@ -22,10 +22,10 @@ public JsonValue this[string key]
if (key == null)
throw new NullReferenceException("key");
- if (this.ContainsKey(key) == false)
+ if (ContainsKey(key) == false)
throw new JsonException("Key does not exists: " + key);
- return (JsonValue)_value[key];
+ return _value[key];
}
}
@@ -58,7 +58,7 @@ public bool TryGetValue(string key, out JsonValue value)
if (key == null)
throw new NullReferenceException("key");
- if (this.ContainsKey(key) == false)
+ if (ContainsKey(key) == false)
return false;
value = this[key];
@@ -84,7 +84,7 @@ void Add(string key, JsonValue value)
if (key == null)
throw new NullReferenceException("key");
- if (ContainsKey(key) == true)
+ if (ContainsKey(key))
throw new JsonException(string.Format("Key '{0}' already exists in JsonObject", key));
_value.Add(key, value);
@@ -109,7 +109,7 @@ public static JsonObject Parse(string str)
internal static JsonObject Parse(string str, ref int position)
{
- JsonString.EatSpaces(str, ref position);
+ EatSpaces(str, ref position);
if (position >= str.Length)
return null;
@@ -124,9 +124,9 @@ internal static JsonObject Parse(string str, ref int position)
// Read starting '{'
position++;
- while (continueReading == true)
+ while (continueReading)
{
- JsonString.EatSpaces(str, ref position);
+ EatSpaces(str, ref position);
if (str[position] != '}')
{
// Read string
@@ -134,7 +134,7 @@ internal static JsonObject Parse(string str, ref int position)
string key = jsonString.Value;
// Read seperator ':'
- JsonString.EatSpaces(str, ref position);
+ EatSpaces(str, ref position);
if (str[position] != ':')
throw new JsonParseException(str, position);
position++;
@@ -145,7 +145,7 @@ internal static JsonObject Parse(string str, ref int position)
jsonObject.Add(key, value);
}
- JsonString.EatSpaces(str, ref position);
+ EatSpaces(str, ref position);
if (str[position] == '}')
continueReading = false;
else if (str[position] != ',')
diff --git a/Source/Chargify.NET/Json/JsonValue.cs b/Source/Chargify.NET/Json/JsonValue.cs
index af52984..68d0228 100644
--- a/Source/Chargify.NET/Json/JsonValue.cs
+++ b/Source/Chargify.NET/Json/JsonValue.cs
@@ -29,7 +29,7 @@ protected static void EatSpaces(string str, ref int position)
/// The JsonValue if parsed, null otherwise.
protected static JsonValue ParseValue(string str, ref int position)
{
- JsonString.EatSpaces(str, ref position);
+ EatSpaces(str, ref position);
char ch = str[position];
diff --git a/Source/Chargify.NET/Json/XmlToJson.cs b/Source/Chargify.NET/Json/XmlToJson.cs
index 5afd956..4ed41ed 100644
--- a/Source/Chargify.NET/Json/XmlToJson.cs
+++ b/Source/Chargify.NET/Json/XmlToJson.cs
@@ -10,21 +10,27 @@ namespace ChargifyNET.Json
///
public static class XmlToJsonConverter
{
+ ///
+ /// Does the node have children?
+ ///
+ /// The xml element node
+ /// True if the element has children, false otherwise.
public static bool HasChildren(this XmlElement node)
{
bool hasChildrenArray = false;
string childName = string.Empty;
foreach (object child in node)
{
- if (child as XmlElement != null)
+ var childElement = child as XmlElement;
+ if (childElement != null)
{
if (childName == string.Empty)
{
- childName = ((XmlElement)child).Name;
+ childName = childElement.Name;
}
else
{
- hasChildrenArray = childName == ((XmlElement)child).Name;
+ hasChildrenArray = childName == childElement.Name;
}
}
}
@@ -36,21 +42,21 @@ public static bool HasChildren(this XmlElement node)
///
/// The document to convert
/// The JSON equivalent string
- public static string XmlToJSON(XmlDocument xmlDoc)
+ public static string XmlToJson(XmlDocument xmlDoc)
{
- StringBuilder sbJSON = new StringBuilder();
- sbJSON.Append("{");
- XmlToJSONnode(sbJSON, xmlDoc.DocumentElement, true);
- sbJSON.Append("}");
- return sbJSON.ToString();
+ StringBuilder sbJson = new StringBuilder();
+ sbJson.Append("{");
+ XmlToJsoNnode(sbJson, xmlDoc.DocumentElement, true);
+ sbJson.Append("}");
+ return sbJson.ToString();
}
// XmlToJSONnode: Output an XmlElement, possibly as part of a higher array
- private static void XmlToJSONnode(StringBuilder sbJSON, XmlElement node, bool showNodeName)
+ private static void XmlToJsoNnode(StringBuilder sbJson, XmlElement node, bool showNodeName)
{
if (showNodeName)
- sbJSON.Append("\"" + SafeJSON(node.Name) + "\": ");
- sbJSON.Append("{");
+ sbJson.Append("\"" + SafeJson(node.Name) + "\": ");
+ sbJson.Append("{");
// Build a sorted list of key-value pairs
// where key is case-sensitive nodeName
// value is an ArrayList of string or XmlElement
@@ -58,9 +64,8 @@ private static void XmlToJSONnode(StringBuilder sbJSON, XmlElement node, bool sh
SortedList childNodeNames = new SortedList();
// Add in all node attributes
- if (node.Attributes != null)
- foreach (XmlAttribute attr in node.Attributes)
- StoreChildNode(childNodeNames, attr.Name, attr.InnerText);
+ foreach (XmlAttribute attr in node.Attributes)
+ StoreChildNode(childNodeNames, attr.Name, attr.InnerText);
// Add in all nodes
foreach (XmlNode cnode in node.ChildNodes)
@@ -76,21 +81,21 @@ private static void XmlToJSONnode(StringBuilder sbJSON, XmlElement node, bool sh
{
ArrayList alChild = (ArrayList)childNodeNames[childname];
if (alChild.Count == 1 && (alChild[0] is string))
- OutputNode(childname, alChild[0], sbJSON, true);
+ OutputNode(childname, alChild[0], sbJson, true);
else
{
var alChildElement = alChild[0] as XmlElement;
//var alParentElementHasChildren = alChildElement != null ? (alChildElement.ParentNode as XmlElement) != null ? (alChildElement.ParentNode as XmlElement).HasChildren() : false : false;
bool hasChildrenArray = alChildElement.HasChildren();
- sbJSON.Append(" \"" + SafeJSON(childname) + string.Format("\": {0} ", hasChildrenArray ? "[" : string.Empty));
- foreach (object Child in alChild)
- OutputNode(childname, Child, sbJSON, false);
- sbJSON.Remove(sbJSON.Length - 2, 2);
- sbJSON.AppendFormat(" {0},", hasChildrenArray ? "]" : string.Empty);
+ sbJson.Append(" \"" + SafeJson(childname) + string.Format("\": {0} ", hasChildrenArray ? "[" : string.Empty));
+ foreach (object child in alChild)
+ OutputNode(childname, child, sbJson, false);
+ sbJson.Remove(sbJson.Length - 2, 2);
+ sbJson.AppendFormat(" {0},", hasChildrenArray ? "]" : string.Empty);
}
}
- sbJSON.Remove(sbJSON.Length - 2, 2);
- sbJSON.Append(" }");
+ sbJson.Remove(sbJson.Length - 2, 2);
+ sbJson.Append(" }");
}
// StoreChildNode: Store data associated with each nodeName
@@ -98,12 +103,13 @@ private static void XmlToJSONnode(StringBuilder sbJSON, XmlElement node, bool sh
private static void StoreChildNode(SortedList childNodeNames, string nodeName, object nodeValue)
{
// Pre-process contraction of XmlElement-s
- if (nodeValue is XmlElement)
+ var nodeElement = nodeValue as XmlElement;
+ if (nodeElement != null)
{
// Convert into "aa":null
// xx into "aa":"xx"
XmlNode cnode = (XmlNode)nodeValue;
- if (cnode.Attributes.Count == 0)
+ if (cnode.Attributes != null && cnode.Attributes.Count == 0)
{
XmlNodeList children = cnode.ChildNodes;
if (children.Count == 0)
@@ -114,48 +120,48 @@ private static void StoreChildNode(SortedList childNodeNames, string nodeName, o
}
// Add nodeValue to ArrayList associated with each nodeName
// If nodeName doesn't exist then add it
- object oValuesAL = childNodeNames[nodeName];
- ArrayList ValuesAL;
- if (oValuesAL == null)
+ object oValuesAl = childNodeNames[nodeName];
+ ArrayList valuesAl;
+ if (oValuesAl == null)
{
- ValuesAL = new ArrayList();
- childNodeNames[nodeName] = ValuesAL;
+ valuesAl = new ArrayList();
+ childNodeNames[nodeName] = valuesAl;
}
else
- ValuesAL = (ArrayList)oValuesAL;
- ValuesAL.Add(nodeValue);
+ valuesAl = (ArrayList)oValuesAl;
+ if (nodeValue != null) valuesAl.Add(nodeValue);
}
- private static void OutputNode(string childname, object alChild, StringBuilder sbJSON, bool showNodeName)
+ private static void OutputNode(string childname, object alChild, StringBuilder sbJson, bool showNodeName)
{
if (alChild == null)
{
if (showNodeName)
- sbJSON.Append("\"" + SafeJSON(childname) + "\": ");
- sbJSON.Append("null");
+ sbJson.Append("\"" + SafeJson(childname) + "\": ");
+ sbJson.Append("null");
}
else if (alChild is string)
{
if (showNodeName)
- sbJSON.Append("\"" + SafeJSON(childname) + "\": ");
+ sbJson.Append("\"" + SafeJson(childname) + "\": ");
string sChild = (string)alChild;
sChild = sChild.Trim();
- sbJSON.Append("\"" + SafeJSON(sChild) + "\"");
+ sbJson.Append("\"" + SafeJson(sChild) + "\"");
}
else
- XmlToJSONnode(sbJSON, (XmlElement)alChild, showNodeName);
- sbJSON.Append(", ");
+ XmlToJsoNnode(sbJson, (XmlElement)alChild, showNodeName);
+ sbJson.Append(", ");
}
// Make a string safe for JSON
- private static string SafeJSON(string sIn)
+ private static string SafeJson(string sIn)
{
StringBuilder sbOut = new StringBuilder(sIn.Length);
foreach (char ch in sIn)
{
if (Char.IsControl(ch) || ch == '\'')
{
- int ich = (int)ch;
+ int ich = ch;
sbOut.Append(@"\u" + ich.ToString("x4"));
continue;
}
diff --git a/Source/Chargify.NET/Metadata.cs b/Source/Chargify.NET/Metadata.cs
index 39f66fd..ffbfe1f 100644
--- a/Source/Chargify.NET/Metadata.cs
+++ b/Source/Chargify.NET/Metadata.cs
@@ -32,7 +32,6 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
-
#endregion
///
@@ -52,21 +51,21 @@ public class Metadata : ChargifyBase, IMetadata, IEquatable
///
/// Meaningful values to subscription or customer records
///
- public Metadata() : base()
+ public Metadata()
{
}
-
+
///
/// Meaningful values to subscription or customer records
///
- /// The XML to parse into a metadata result
- public Metadata(string MetadataXML) : base()
+ /// The XML to parse into a metadata result
+ public Metadata(string metadataXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(MetadataXML);
+ doc.LoadXml(metadataXml);
if (doc.ChildNodes.Count == 0)
- throw new ArgumentException("XML not valid", "MetadataXML");
+ throw new ArgumentException("XML not valid", nameof(metadataXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -77,67 +76,65 @@ public Metadata(string MetadataXML) : base()
}
}
// if we get here, then no metadata result data was found
- throw new ArgumentException("XML does not contain metadata result information", "MetadataResultXML");
+ throw new ArgumentException("XML does not contain metadata result information", nameof(metadataXml));
}
///
/// Meaningful values to subscription or customer records
///
- /// The XML document node to use to parse into a metadata result
- public Metadata(XmlNode MetadataNode) : base()
+ /// The XML document node to use to parse into a metadata result
+ public Metadata(XmlNode metadataNode)
{
- if (MetadataNode == null)
- throw new ArgumentNullException("MetadataNode");
- if (MetadataNode.Name != "metadatum")
- throw new ArgumentException("Not a vaild metadatum results node", "MetadataNode");
- if (MetadataNode.ChildNodes.Count == 0)
- throw new ArgumentException("XML not valid", "MetadataNode");
- LoadFromNode(MetadataNode);
+ if (metadataNode == null)
+ throw new ArgumentNullException(nameof(metadataNode));
+ if (metadataNode.Name != "metadatum")
+ throw new ArgumentException("Not a vaild metadatum results node", nameof(metadataNode));
+ if (metadataNode.ChildNodes.Count == 0)
+ throw new ArgumentException("XML not valid", nameof(metadataNode));
+ LoadFromNode(metadataNode);
}
-
+
private void LoadFromNode(XmlNode metadataNode)
{
foreach (XmlNode childNode in metadataNode.ChildNodes)
{
switch (childNode.Name)
- {
+ {
case "resource-id":
- this.ResourceID = childNode.GetNodeContentAsInt();
+ ResourceID = childNode.GetNodeContentAsInt();
break;
case "name":
- this.Name = childNode.GetNodeContentAsString();
+ Name = childNode.GetNodeContentAsString();
break;
case "value":
- this.Value = childNode.GetNodeContentAsString();
- break;
- default:
+ Value = childNode.GetNodeContentAsString();
break;
}
}
}
-
+
#endregion
-
+
#region IMetadata Members
///
/// The resource id that the metadata belongs to
///
- public int ResourceID { get { return this._resourceID; } set { this._resourceID = value; } }
- private int _resourceID = int.MinValue;
+ public int ResourceID { get { return _resourceId; } set { _resourceId = value; } }
+ private int _resourceId = int.MinValue;
///
/// The value of the attribute that was added to the resource
///
- public string Value { get { return this._value; } set { this._value = value; } }
- private string _value = null;
+ public string Value { get { return _value; } set { _value = value; } }
+ private string _value;
///
/// The name of the attribute that is added to the resource
///
- public string Name { get { return this._name; } set { this._name = value; } }
+ public string Name { get { return _name; } set { _name = value; } }
private string _name = string.Empty;
-
+
#endregion
#region Equality
@@ -150,9 +147,9 @@ public override int GetHashCode()
unchecked
{
int result = 17;
- result = result * 23 + this.ResourceID.GetHashCode();
- result = result * 23 + ((Value != null) ? this.Value.GetHashCode() : 0);
- result = result * 23 + ((Name != null) ? this.Name.GetHashCode() : 0);
+ result = result * 23 + ResourceID.GetHashCode();
+ result = result * 23 + ((Value != null) ? Value.GetHashCode() : 0);
+ result = result * 23 + ((Name != null) ? Name.GetHashCode() : 0);
return result;
}
}
@@ -172,9 +169,9 @@ public bool Equals(Metadata value)
{
return true;
}
- return this.ResourceID == value.ResourceID &&
- Equals(this.Value, value.Value) &&
- Equals(this.Name, value.Name);
+ return ResourceID == value.ResourceID &&
+ Equals(Value, value.Value) &&
+ Equals(Name, value.Name);
}
///
@@ -187,7 +184,7 @@ public override bool Equals(object obj)
Metadata temp = obj as Metadata;
if (temp == null)
return false;
- return this.Equals(temp);
+ return Equals(temp);
}
#endregion
}
diff --git a/Source/Chargify.NET/MetadataResult.cs b/Source/Chargify.NET/MetadataResult.cs
index de01328..dcb6425 100644
--- a/Source/Chargify.NET/MetadataResult.cs
+++ b/Source/Chargify.NET/MetadataResult.cs
@@ -27,13 +27,17 @@
//
#endregion
+using System;
+using System.Collections.Generic;
+using System.Xml;
+using ChargifyNET.Json;
+
namespace ChargifyNET
{
#region Imports
- using System;
- using System.Collections.Generic;
- using System.Xml;
- using ChargifyNET.Json;
+
+
+
#endregion
///
@@ -57,22 +61,20 @@ public class MetadataResult : ChargifyBase, IMetadataResult
/// Constructor
///
public MetadataResult()
- : base()
{
}
///
/// Constructor (xml)
///
- ///
- public MetadataResult(string MetadataResultXML)
- : base()
+ ///
+ public MetadataResult(string metadataResultXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(MetadataResultXML);
+ doc.LoadXml(metadataResultXml);
if (doc.ChildNodes.Count == 0)
- throw new ArgumentException("XML not valid", "MetadataResultXML");
+ throw new ArgumentException("XML not valid", nameof(metadataResultXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -83,37 +85,35 @@ public MetadataResult(string MetadataResultXML)
}
}
// if we get here, then no metadata result data was found
- throw new ArgumentException("XML does not contain metadata result information", "MetadataResultXML");
+ throw new ArgumentException("XML does not contain metadata result information", nameof(metadataResultXml));
}
///
/// Constructor (xml)
///
- ///
- public MetadataResult(XmlNode MetadataResultNode)
- : base()
+ ///
+ public MetadataResult(XmlNode metadataResultNode)
{
- if (MetadataResultNode == null)
- throw new ArgumentNullException("MetadataResultNode");
- if (MetadataResultNode.Name != "results")
- throw new ArgumentException("Not a vaild metadata results node", "MetadataResultNode");
- if (MetadataResultNode.ChildNodes.Count == 0)
- throw new ArgumentException("XML not valid", "MetadataResultNode");
- LoadFromNode(MetadataResultNode);
+ if (metadataResultNode == null)
+ throw new ArgumentNullException(nameof(metadataResultNode));
+ if (metadataResultNode.Name != "results")
+ throw new ArgumentException("Not a vaild metadata results node", nameof(metadataResultNode));
+ if (metadataResultNode.ChildNodes.Count == 0)
+ throw new ArgumentException("XML not valid", nameof(metadataResultNode));
+ LoadFromNode(metadataResultNode);
}
///
/// Constructor (json)
///
- ///
- public MetadataResult(JsonObject MetadataResultObject)
- : base()
+ ///
+ public MetadataResult(JsonObject metadataResultObject)
{
- if (MetadataResultObject == null)
- throw new ArgumentNullException("MetadataResultObject");
- if (MetadataResultObject.Keys.Count <= 0)
- throw new ArgumentException("Not a vaild metadata results object", "MetadataResultObject");
- LoadFromJSON(MetadataResultObject);
+ if (metadataResultObject == null)
+ throw new ArgumentNullException(nameof(metadataResultObject));
+ if (metadataResultObject.Keys.Count <= 0)
+ throw new ArgumentException("Not a vaild metadata results object", nameof(metadataResultObject));
+ LoadFromJson(metadataResultObject);
}
private void LoadFromNode(XmlNode parentNode)
@@ -159,8 +159,6 @@ private void LoadFromNode(XmlNode parentNode)
hasData = true;
newObj.Value = metadatumNode.GetNodeContentAsString();
break;
- default:
- break;
}
}
if (hasData)
@@ -171,13 +169,11 @@ private void LoadFromNode(XmlNode parentNode)
}
break;
- default:
- break;
}
}
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -201,7 +197,7 @@ private void LoadFromJSON(JsonObject obj)
case MetadataKey:
_metadata = new List();
JsonArray viewObj = obj[key] as JsonArray;
- if (viewObj != null && viewObj.Items != null && viewObj.Length > 0)
+ if (viewObj?.Items != null && viewObj.Length > 0)
{
foreach (JsonValue item in viewObj.Items)
{
@@ -224,8 +220,6 @@ private void LoadFromJSON(JsonObject obj)
hasData = true;
newObj.Value = obj.GetJSONContentAsString(subItemKey);
break;
- default:
- break;
}
}
if (hasData)
@@ -235,8 +229,6 @@ private void LoadFromJSON(JsonObject obj)
}
}
break;
- default:
- break;
}
}
}
@@ -252,7 +244,7 @@ public int TotalCount
{
get
{
- return this._totalCount;
+ return _totalCount;
}
}
@@ -265,7 +257,7 @@ public int CurrentPage
{
get
{
- return this._currentPage;
+ return _currentPage;
}
}
@@ -278,7 +270,7 @@ public int TotalPages
{
get
{
- return this._totalPages;
+ return _totalPages;
}
}
@@ -291,7 +283,7 @@ public int PerPage
{
get
{
- return this._perPage;
+ return _perPage;
}
}
@@ -304,7 +296,7 @@ public List Metadata
{
get
{
- return this._metadata;
+ return _metadata;
}
}
diff --git a/Source/Chargify.NET/Migration.cs b/Source/Chargify.NET/Migration.cs
index 9252671..a052577 100644
--- a/Source/Chargify.NET/Migration.cs
+++ b/Source/Chargify.NET/Migration.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -53,32 +53,30 @@ public class Migration : ChargifyBase, IMigration, IComparable
/// Constructor. Values set to default
///
public Migration()
- : base()
{
}
///
/// Constructor
///
- /// XML containing migration info (in expected format)
- public Migration(string MigrationPreviewXML)
- : base()
+ /// XML containing migration info (in expected format)
+ public Migration(string migrationPreviewXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(MigrationPreviewXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "MigrationPreviewXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(migrationPreviewXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(migrationPreviewXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "migration")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain migration preview information", "MigrationPreviewXML");
+ throw new ArgumentException("XML does not contain migration preview information", nameof(migrationPreviewXml));
}
///
@@ -86,12 +84,11 @@ public Migration(string MigrationPreviewXML)
///
/// XML containing migration info (in expected format)
internal Migration(XmlNode migrationNode)
- : base()
{
- if (migrationNode == null) throw new ArgumentNullException("migrationNode");
- if (migrationNode.Name != "migration") throw new ArgumentException("Not a vaild migration node", "migrationNode");
- if (migrationNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "migrationNode");
- this.LoadFromNode(migrationNode);
+ if (migrationNode == null) throw new ArgumentNullException(nameof(migrationNode));
+ if (migrationNode.Name != "migration") throw new ArgumentException("Not a vaild migration node", nameof(migrationNode));
+ if (migrationNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(migrationNode));
+ LoadFromNode(migrationNode);
}
///
@@ -100,16 +97,16 @@ internal Migration(XmlNode migrationNode)
/// JsonObject containing migration info (in expected format)
public Migration(JsonObject migrationObject)
{
- if (migrationObject == null) throw new ArgumentNullException("migrationObject");
- if (migrationObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild migration object", "migrationObject");
- this.LoadFromJSON(migrationObject);
+ if (migrationObject == null) throw new ArgumentNullException(nameof(migrationObject));
+ if (migrationObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild migration object", nameof(migrationObject));
+ LoadFromJson(migrationObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject with migration data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -127,8 +124,6 @@ private void LoadFromJSON(JsonObject obj)
case CreditAppliedInCentsKey:
_creditAppliedInCents = obj.GetJSONContentAsInt(key);
break;
- default:
- break;
}
}
}
@@ -155,8 +150,6 @@ private void LoadFromNode(XmlNode migrationNode)
case CreditAppliedInCentsKey:
_creditAppliedInCents = dataNode.GetNodeContentAsInt();
break;
- default:
- break;
}
}
diff --git a/Source/Chargify.NET/Note.cs b/Source/Chargify.NET/Note.cs
index 36cb39c..008b5ec 100644
--- a/Source/Chargify.NET/Note.cs
+++ b/Source/Chargify.NET/Note.cs
@@ -31,9 +31,9 @@
namespace ChargifyNET
{
#region Imports
- using Json;
using System;
using System.Xml;
+ using Json;
#endregion
///
@@ -42,11 +42,11 @@ namespace ChargifyNET
public class Note : ChargifyBase, INote, IComparable
{
#region Field Keys
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string BodyKey = "body";
private const string StickyKey = "sticky";
private const string UpdatedAtKey = "updated_at";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string CreatedAtKey = "created_at";
#endregion
@@ -54,30 +54,30 @@ public class Note : ChargifyBase, INote, IComparable
///
/// Constructor. Values set to default
///
- public Note() : base() { }
+ public Note()
+ { }
///
/// Constructor
///
- /// XML containing note info (in expected format)
- public Note(string NoteXML)
- : base()
+ /// XML containing note info (in expected format)
+ public Note(string noteXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(NoteXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "NoteXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(noteXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(noteXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "note")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain note information", "NoteXML");
+ throw new ArgumentException("XML does not contain note information", nameof(noteXml));
}
///
@@ -85,12 +85,11 @@ public Note(string NoteXML)
///
/// XML containing note info (in expected format)
internal Note(XmlNode noteNode)
- : base()
{
- if (noteNode == null) throw new ArgumentNullException("noteNode");
- if (noteNode.Name != "note") throw new ArgumentException("Not a vaild note node", "noteNode");
- if (noteNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "noteNode");
- this.LoadFromNode(noteNode);
+ if (noteNode == null) throw new ArgumentNullException(nameof(noteNode));
+ if (noteNode.Name != "note") throw new ArgumentException("Not a vaild note node", nameof(noteNode));
+ if (noteNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(noteNode));
+ LoadFromNode(noteNode);
}
///
@@ -98,27 +97,26 @@ internal Note(XmlNode noteNode)
///
/// Json containing note info (in expected format)
public Note(JsonObject noteObject)
- : base()
{
- if (noteObject == null) throw new ArgumentNullException("noteObject");
- if (noteObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild note object", "noteObject");
- this.LoadFromJSON(noteObject);
+ if (noteObject == null) throw new ArgumentNullException(nameof(noteObject));
+ if (noteObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild note object", nameof(noteObject));
+ LoadFromJson(noteObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
switch (key)
{
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case BodyKey:
_body = obj.GetJSONContentAsString(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case CreatedAtKey:
_createdAt = obj.GetJSONContentAsDateTime(key);
@@ -129,8 +127,6 @@ private void LoadFromJSON(JsonObject obj)
case StickyKey:
_sticky = obj.GetJSONContentAsBoolean(key);
break;
- default:
- break;
}
}
}
@@ -145,14 +141,14 @@ private void LoadFromNode(XmlNode noteNode)
{
switch (dataNode.Name)
{
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case BodyKey:
_body = dataNode.GetNodeContentAsString();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case CreatedAtKey:
_createdAt = dataNode.GetNodeContentAsDateTime();
@@ -163,11 +159,9 @@ private void LoadFromNode(XmlNode noteNode)
case StickyKey:
_sticky = dataNode.GetNodeContentAsBoolean();
break;
- default:
- break;
}
}
- }
+ }
#endregion
#region INote Members
@@ -181,7 +175,7 @@ public string Body
return _body;
}
}
- private string _body = null;
+ private string _body;
///
/// Date and time the note was created
@@ -217,7 +211,7 @@ public bool Sticky
return _sticky;
}
}
- private bool _sticky = false;
+ private bool _sticky;
///
/// The id of the related subscription
@@ -226,10 +220,10 @@ public int SubscriptionID
{
get
{
- return _subscriptionID;
+ return _subscriptionId;
}
}
- private int _subscriptionID = int.MinValue;
+ private int _subscriptionId = int.MinValue;
///
/// Last update timestamp
@@ -252,7 +246,7 @@ public DateTime UpdatedAt
/// The comparison value
public int CompareTo(INote other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
@@ -264,7 +258,7 @@ public int CompareTo(INote other)
/// The comparison value
public int CompareTo(Note other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
}
diff --git a/Source/Chargify.NET/Payment.cs b/Source/Chargify.NET/Payment.cs
index 09be26b..135784e 100644
--- a/Source/Chargify.NET/Payment.cs
+++ b/Source/Chargify.NET/Payment.cs
@@ -30,10 +30,10 @@
namespace ChargifyNET
{
- using Json;
#region Imports
using System;
using System.Xml;
+ using Json;
#endregion
///
@@ -46,17 +46,17 @@ public class Payment : ChargifyBase, IPayment, IComparable
private const string AmountInCentsKey = "amount_in_cents";
private const string CreatedAtKey = "created_at";
private const string EndingBalanceInCentsKey = "ending_balance_in_cents";
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string KindKey = "kind";
private const string MemoKey = "memo";
- private const string PaymentIDKey = "payment_id";
- private const string ProductIDKey = "product_id";
+ private const string PaymentIdKey = "payment_id";
+ private const string ProductIdKey = "product_id";
private const string StartingBalanceInCentsKey = "starting_balance_in_cents";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string SuccessKey = "success";
private const string TypeKey = "type";
private const string TransactionTypeKey = "transaction_type";
- private const string GatewayTransactionIDKey = "gateway_transaction_id";
+ private const string GatewayTransactionIdKey = "gateway_transaction_id";
#endregion
#region Constructors
@@ -64,32 +64,30 @@ public class Payment : ChargifyBase, IPayment, IComparable
/// Default constructor
///
public Payment()
- : base()
{
}
///
/// Constructor
///
- /// XML containing payment info (in expected format)
- public Payment(string PaymentXML)
- : base()
+ /// XML containing payment info (in expected format)
+ public Payment(string paymentXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(PaymentXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "PaymentXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(paymentXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(paymentXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "payment")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain payment information", "PaymentXML");
+ throw new ArgumentException("XML does not contain payment information", nameof(paymentXml));
}
///
@@ -97,12 +95,11 @@ public Payment(string PaymentXML)
///
/// XML containing payment info (in expected format)
internal Payment(XmlNode paymentNode)
- : base()
{
- if (paymentNode == null) throw new ArgumentNullException("PaymentNode");
- if (paymentNode.Name != "payment") throw new ArgumentException("Not a vaild payment node", "paymentNode");
- if (paymentNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "paymentNode");
- this.LoadFromNode(paymentNode);
+ if (paymentNode == null) throw new ArgumentNullException(nameof(paymentNode));
+ if (paymentNode.Name != "payment") throw new ArgumentException("Not a vaild payment node", nameof(paymentNode));
+ if (paymentNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(paymentNode));
+ LoadFromNode(paymentNode);
}
///
@@ -110,18 +107,17 @@ internal Payment(XmlNode paymentNode)
///
/// JsonObject containing payment info (in expected format)
public Payment(JsonObject paymentObject)
- : base()
{
- if (paymentObject == null) throw new ArgumentNullException("paymentObject");
- if (paymentObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild payment object", "paymentObject");
- this.LoadFromJSON(paymentObject);
+ if (paymentObject == null) throw new ArgumentNullException(nameof(paymentObject));
+ if (paymentObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild payment object", nameof(paymentObject));
+ LoadFromJson(paymentObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing object data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get object info, and parse it out
foreach (string key in obj.Keys)
@@ -137,7 +133,7 @@ private void LoadFromJSON(JsonObject obj)
case EndingBalanceInCentsKey:
_endingBalanceInCents = obj.GetJSONContentAsInt(key);
break;
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case KindKey:
@@ -146,17 +142,17 @@ private void LoadFromJSON(JsonObject obj)
case MemoKey:
_memo = obj.GetJSONContentAsString(key);
break;
- case PaymentIDKey:
- _paymentID = obj.GetJSONContentAsNullableInt(key);
+ case PaymentIdKey:
+ _paymentId = obj.GetJSONContentAsNullableInt(key);
break;
- case ProductIDKey:
- _productID = obj.GetJSONContentAsInt(key);
+ case ProductIdKey:
+ _productId = obj.GetJSONContentAsInt(key);
break;
case StartingBalanceInCentsKey:
_startingBalanceInCents = obj.GetJSONContentAsInt(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case SuccessKey:
_success = obj.GetJSONContentAsBoolean(key);
@@ -167,10 +163,8 @@ private void LoadFromJSON(JsonObject obj)
case TransactionTypeKey:
_transactionType = obj.GetJSONContentAsString(key);
break;
- case GatewayTransactionIDKey:
- _gatewayTransactionID = obj.GetJSONContentAsNullableInt(key);
- break;
- default:
+ case GatewayTransactionIdKey:
+ _gatewayTransactionId = obj.GetJSONContentAsNullableInt(key);
break;
}
}
@@ -195,7 +189,7 @@ private void LoadFromNode(XmlNode paymentNode)
case EndingBalanceInCentsKey:
_endingBalanceInCents = dataNode.GetNodeContentAsInt();
break;
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case KindKey:
@@ -204,17 +198,17 @@ private void LoadFromNode(XmlNode paymentNode)
case MemoKey:
_memo = dataNode.GetNodeContentAsString();
break;
- case PaymentIDKey:
- _paymentID = dataNode.GetNodeContentAsNullableInt();
+ case PaymentIdKey:
+ _paymentId = dataNode.GetNodeContentAsNullableInt();
break;
- case ProductIDKey:
- _productID = dataNode.GetNodeContentAsInt();
+ case ProductIdKey:
+ _productId = dataNode.GetNodeContentAsInt();
break;
case StartingBalanceInCentsKey:
_startingBalanceInCents = dataNode.GetNodeContentAsInt();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case SuccessKey:
_success = dataNode.GetNodeContentAsBoolean();
@@ -225,10 +219,8 @@ private void LoadFromNode(XmlNode paymentNode)
case TransactionTypeKey:
_transactionType = dataNode.GetNodeContentAsString();
break;
- case GatewayTransactionIDKey:
- _gatewayTransactionID = dataNode.GetNodeContentAsNullableInt();
- break;
- default:
+ case GatewayTransactionIdKey:
+ _gatewayTransactionId = dataNode.GetNodeContentAsNullableInt();
break;
}
}
@@ -280,14 +272,14 @@ private void LoadFromNode(XmlNode paymentNode)
///
/// The ID of the payment
///
- public int? PaymentID { get { return _paymentID; } }
- private int? _paymentID = null;
+ public int? PaymentID { get { return _paymentId; } }
+ private int? _paymentId;
///
/// The ID of the product
///
- public int ProductID { get { return _productID; } }
- private int _productID = int.MinValue;
+ public int ProductID { get { return _productId; } }
+ private int _productId = int.MinValue;
///
/// The balance of the subscription before the payment
@@ -298,14 +290,14 @@ private void LoadFromNode(XmlNode paymentNode)
///
/// The subscription ID
///
- public int SubscriptionID { get { return _subscriptionID; } }
- private int _subscriptionID = int.MinValue;
+ public int SubscriptionID { get { return _subscriptionId; } }
+ private int _subscriptionId = int.MinValue;
///
/// Was the payment successful?
///
public bool Success { get { return _success; } }
- private bool _success = false;
+ private bool _success;
///
/// The type of payment
@@ -322,8 +314,8 @@ private void LoadFromNode(XmlNode paymentNode)
///
/// The related gateway transaction ID
///
- public int? GatewayTransactionID { get { return _gatewayTransactionID; } }
- private int? _gatewayTransactionID = null;
+ public int? GatewayTransactionID { get { return _gatewayTransactionId; } }
+ private int? _gatewayTransactionId;
#endregion
#region IComparible Members
@@ -334,7 +326,7 @@ private void LoadFromNode(XmlNode paymentNode)
///
public int CompareTo(IPayment other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
///
@@ -344,7 +336,7 @@ public int CompareTo(IPayment other)
///
public int CompareTo(Payment other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
}
diff --git a/Source/Chargify.NET/PaymentProfileAttributes.cs b/Source/Chargify.NET/PaymentProfileAttributes.cs
index 493ffd6..4c9f146 100644
--- a/Source/Chargify.NET/PaymentProfileAttributes.cs
+++ b/Source/Chargify.NET/PaymentProfileAttributes.cs
@@ -46,27 +46,28 @@ public class PaymentProfileAttributes : ChargifyBase, IPaymentProfileAttributes,
///
/// Class which can be used to "import" subscriptions via the API into Chargify
///
- public PaymentProfileAttributes() : base() { /* Nothing */ }
+ public PaymentProfileAttributes()
+ { /* Nothing */ }
///
/// Class which can be used to "import" subscriptions via the API into Chargify
///
- /// The "token" provided by your vault storage for an already stored payment profile
- /// The "customerProfileId" for the owner of the "customerPaymentProfileId" provided as the VaultToken
- /// The vault that stores the payment profile with the provided VaultToken
- /// The year of expiration
- /// The month of expiration
- /// If you know the card type, you may supply it here so that Chargify may display it in the AdminUI
- /// The last four digits of the credit card for use in masked numbers
- public PaymentProfileAttributes(string VaultToken, string CustomerVaultToken, VaultType CurrentVault, int ExpYear, int ExpMonth, CardType CardType, string LastFourDigits) : base()
+ /// The "token" provided by your vault storage for an already stored payment profile
+ /// The "customerProfileId" for the owner of the "customerPaymentProfileId" provided as the VaultToken
+ /// The vault that stores the payment profile with the provided VaultToken
+ /// The year of expiration
+ /// The month of expiration
+ /// If you know the card type, you may supply it here so that Chargify may display it in the AdminUI
+ /// The last four digits of the credit card for use in masked numbers
+ public PaymentProfileAttributes(string vaultToken, string customerVaultToken, VaultType currentVault, int expYear, int expMonth, CardType cardType, string lastFourDigits)
{
- this._vaultToken = VaultToken;
- this._customerVaultToken = CustomerVaultToken;
- this._currentVault = CurrentVault;
- this._expirationYear = ExpYear;
- this._expirationMonth = ExpMonth;
- this._cardType = CardType;
- this._lastFour = LastFourDigits;
+ _vaultToken = vaultToken;
+ _customerVaultToken = customerVaultToken;
+ _currentVault = currentVault;
+ _expirationYear = expYear;
+ _expirationMonth = expMonth;
+ _cardType = cardType;
+ _lastFour = lastFourDigits;
}
#endregion
@@ -77,7 +78,7 @@ public PaymentProfileAttributes(string VaultToken, string CustomerVaultToken, Va
public string VaultToken
{
get { return _vaultToken; }
- set { if (_vaultToken != value) _vaultToken = value; }
+ set { _vaultToken = value; }
}
private string _vaultToken = string.Empty;
@@ -88,7 +89,7 @@ public string VaultToken
public string CustomerVaultToken
{
get { return _customerVaultToken; }
- set { if (_customerVaultToken != value) _customerVaultToken = value; }
+ set { _customerVaultToken = value; }
}
private string _customerVaultToken = string.Empty;
@@ -98,7 +99,7 @@ public string CustomerVaultToken
public VaultType CurrentVault
{
get { return _currentVault; }
- set { if (_currentVault != value) _currentVault = value; }
+ set { _currentVault = value; }
}
private VaultType _currentVault = VaultType.Unknown;
@@ -108,7 +109,7 @@ public VaultType CurrentVault
public int ExpirationYear
{
get { return _expirationYear; }
- set { if (_expirationYear != value) _expirationYear = value; }
+ set { _expirationYear = value; }
}
private int _expirationYear = int.MinValue;
@@ -118,7 +119,7 @@ public int ExpirationYear
public int ExpirationMonth
{
get { return _expirationMonth; }
- set { if (_expirationMonth != value) _expirationMonth = value; }
+ set { _expirationMonth = value; }
}
private int _expirationMonth = int.MinValue;
@@ -129,7 +130,7 @@ public int ExpirationMonth
public CardType CardType
{
get { return _cardType; }
- set { if (_cardType != value) _cardType = value; }
+ set { _cardType = value; }
}
private CardType _cardType = CardType.Unknown;
@@ -140,47 +141,47 @@ public CardType CardType
public string LastFour
{
get { return _lastFour; }
- set { if (_lastFour != value) _lastFour = value; }
+ set { _lastFour = value; }
}
private string _lastFour = string.Empty;
///
/// The name of the bank where the customer's account resides
///
- public string BankName
- {
+ public string BankName
+ {
get { return _bankName; }
- set { if (_bankName != value) _bankName = value; }
+ set { _bankName = value; }
}
private string _bankName = string.Empty;
///
/// The routing number of the bank
///
- public string BankRoutingNumber
- {
+ public string BankRoutingNumber
+ {
get { return _bankRoutingNumber; }
- set { if (_bankRoutingNumber != value) _bankRoutingNumber = value; }
+ set { _bankRoutingNumber = value; }
}
private string _bankRoutingNumber = string.Empty;
///
/// The customer's bank account number
///
- public string BankAccountNumber
+ public string BankAccountNumber
{
get { return _bankAccountNumber; }
- set { if (_bankAccountNumber != value) _bankAccountNumber = value; }
+ set { _bankAccountNumber = value; }
}
private string _bankAccountNumber = string.Empty;
///
/// Either checking or savings
///
- public BankAccountType BankAccountType
- {
+ public BankAccountType BankAccountType
+ {
get { return _bankAccountType; }
- set { if (_bankAccountType != value) _bankAccountType = value; }
+ set { _bankAccountType = value; }
}
private BankAccountType _bankAccountType = BankAccountType.Unknown;
@@ -188,9 +189,9 @@ public BankAccountType BankAccountType
/// Either personal or business
///
public BankAccountHolderType BankAccountHolderType
- {
+ {
get { return _bankAccountHolderType; }
- set { if (_bankAccountHolderType != value) _bankAccountHolderType = value; }
+ set { _bankAccountHolderType = value; }
}
private BankAccountHolderType _bankAccountHolderType = BankAccountHolderType.Unknown;
@@ -205,7 +206,7 @@ public BankAccountHolderType BankAccountHolderType
/// The result of the comparison
public int CompareTo(IPaymentProfileAttributes other)
{
- return this.VaultToken.CompareTo(other.VaultToken);
+ return string.Compare(VaultToken, other.VaultToken, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -219,7 +220,7 @@ public int CompareTo(IPaymentProfileAttributes other)
/// The result of the comparison
public int CompareTo(PaymentProfileAttributes other)
{
- return this.VaultToken.CompareTo(other.VaultToken);
+ return string.Compare(VaultToken, other.VaultToken, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/PaymentProfileBase.cs b/Source/Chargify.NET/PaymentProfileBase.cs
index bae772f..4d81932 100644
--- a/Source/Chargify.NET/PaymentProfileBase.cs
+++ b/Source/Chargify.NET/PaymentProfileBase.cs
@@ -31,7 +31,6 @@
namespace ChargifyNET
{
#region Imports
-
using System.Xml.Serialization;
#endregion
@@ -45,32 +44,32 @@ public class PaymentProfileBase : ChargifyBase, IPaymentProfileBase
///
/// Protected Constructor
///
- protected PaymentProfileBase() : base()
+ protected PaymentProfileBase()
{
- this.Id = int.MinValue;
- this.FirstName = string.Empty;
- this.LastName = string.Empty;
- this.FullNumber = string.Empty;
- this.ExpirationMonth = int.MinValue;
- this.ExpirationYear = int.MinValue;
+ Id = int.MinValue;
+ FirstName = string.Empty;
+ LastName = string.Empty;
+ FullNumber = string.Empty;
+ ExpirationMonth = int.MinValue;
+ ExpirationYear = int.MinValue;
}
-
+
///
/// Protected Constructor
///
- /// The first name on the credit card
- /// The last name on the credit card
- /// The full credit card number
- /// The expiration year
- /// The expiration month
- protected PaymentProfileBase(string FirstName, string LastName, string FullNumber, int ExpirationYear, int ExpirationMonth) : base()
+ /// The first name on the credit card
+ /// The last name on the credit card
+ /// The full credit card number
+ /// The expiration year
+ /// The expiration month
+ protected PaymentProfileBase(string firstName, string lastName, string fullNumber, int expirationYear, int expirationMonth)
{
- this.Id = int.MinValue;
- this.FirstName = FirstName;
- this.LastName = LastName;
- this.FullNumber = FullNumber;
- this.ExpirationMonth = ExpirationMonth;
- this.ExpirationYear = ExpirationYear;
+ Id = int.MinValue;
+ FirstName = firstName;
+ LastName = lastName;
+ FullNumber = fullNumber;
+ ExpirationMonth = expirationMonth;
+ ExpirationYear = expirationYear;
}
#endregion
diff --git a/Source/Chargify.NET/PaymentProfileView.cs b/Source/Chargify.NET/PaymentProfileView.cs
index 1431bd5..30f6317 100644
--- a/Source/Chargify.NET/PaymentProfileView.cs
+++ b/Source/Chargify.NET/PaymentProfileView.cs
@@ -30,17 +30,17 @@
namespace ChargifyNET
{
- using Json;
- using System;
#region Imports
using System.Diagnostics;
using System.Xml;
+ using System;
+ using Json;
#endregion
///
/// Class representing view information for a credit card
///
- [DebuggerDisplay("Type: {Type}, Full Number: {FullNumber}, Expiration: {ExpirationMonth}/{ExpirationYear}, Name: {FirstName} {LastName}")]
+ [DebuggerDisplay("Type: {CardType}, Full Number: {FullNumber}, Expiration: {ExpirationMonth}/{ExpirationYear}, Name: {FirstName} {LastName}")]
public class PaymentProfileView : PaymentProfileBase, IPaymentProfileBase, IPaymentProfileView
{
#region Field Keys
@@ -74,43 +74,53 @@ public class PaymentProfileView : PaymentProfileBase, IPaymentProfileBase, IPaym
///
/// Constructor
///
- public PaymentProfileView() : base() { }
- public PaymentProfileView(string PaymentProfileXML) : base()
+ public PaymentProfileView()
+ { }
+
+ ///
+ /// Constructor
+ ///
+ ///
+ public PaymentProfileView(string paymentProfileXml)
{
// get the XML into an XML document
- var Doc = new XmlDocument();
- Doc.LoadXml(PaymentProfileXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "PaymentProfileXML");
+ var doc = new XmlDocument();
+ doc.LoadXml(paymentProfileXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(paymentProfileXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "payment_profile" || elementNode.Name == "bank_account" || elementNode.Name == "credit_card")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no customer info was found
- throw new ArgumentException("XML does not contain payment_profile information", "PaymentProfileXML");
+ throw new ArgumentException("XML does not contain payment_profile information", nameof(paymentProfileXml));
}
///
/// Constructor
///
- /// XML containing payment_profile info (in expected format)
- internal PaymentProfileView(XmlNode PaymentProfileNode) : base()
+ /// XML containing payment_profile info (in expected format)
+ internal PaymentProfileView(XmlNode paymentProfileNode)
{
- if (PaymentProfileNode == null) throw new ArgumentNullException("PaymentProfileNode");
- if (PaymentProfileNode.Name != "payment_profile" && PaymentProfileNode.Name != "credit_card" && PaymentProfileNode.Name != "bank_account") throw new ArgumentException("Not a vaild payment_profile node", "PaymentProfileNode");
- if (PaymentProfileNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "PaymentProfileNode");
- this.LoadFromNode(PaymentProfileNode);
+ if (paymentProfileNode == null) throw new ArgumentNullException(nameof(paymentProfileNode));
+ if (paymentProfileNode.Name != "payment_profile" && paymentProfileNode.Name != "credit_card" && paymentProfileNode.Name != "bank_account") throw new ArgumentException("Not a vaild payment_profile node", nameof(paymentProfileNode));
+ if (paymentProfileNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(paymentProfileNode));
+ LoadFromNode(paymentProfileNode);
}
- public PaymentProfileView(JsonObject PaymentProfileObject) : base()
+ ///
+ /// Json Constructor
+ ///
+ /// The json object containing payment profile information
+ public PaymentProfileView(JsonObject paymentProfileObject)
{
- if (PaymentProfileObject == null) throw new ArgumentNullException("PaymentProfileObject");
- if (PaymentProfileObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild PaymentProfile node", "PaymentProfileObject");
- this.LoadFromJSON(PaymentProfileObject);
+ if (paymentProfileObject == null) throw new ArgumentNullException(nameof(paymentProfileObject));
+ if (paymentProfileObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild PaymentProfile node", nameof(paymentProfileObject));
+ LoadFromJson(paymentProfileObject);
}
private void LoadFromNode(XmlNode rootNode)
@@ -191,14 +201,11 @@ private void LoadFromNode(XmlNode rootNode)
case MaskedCardNumberKey:
_maskedCardNumber = dataNode.GetNodeContentAsString();
break;
-
- default:
- break;
}
}
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -276,8 +283,6 @@ private void LoadFromJSON(JsonObject obj)
case MaskedCardNumberKey:
_maskedCardNumber = obj.GetJSONContentAsString(key);
break;
- default:
- break;
}
}
}
@@ -289,8 +294,8 @@ private void LoadFromJSON(JsonObject obj)
///
public PaymentProfileType PaymentType
{
- get { return this._paymentType; }
- set { if (this._paymentType != value) { this._paymentType = value; } }
+ get { return _paymentType; }
+ set { _paymentType = value; }
}
private PaymentProfileType _paymentType = PaymentProfileType.Credit_Card;
@@ -299,8 +304,8 @@ public PaymentProfileType PaymentType
///
public int CustomerID
{
- get { return this._customerId; }
- set { if (this._customerId != value) { this._customerId = value; } }
+ get { return _customerId; }
+ set { _customerId = value; }
}
private int _customerId = int.MinValue;
@@ -309,8 +314,8 @@ public int CustomerID
///
public string CVV
{
- get { return this._cvv; }
- set { if (this._cvv != value) { this._cvv = value; } }
+ get { return _cvv; }
+ set { _cvv = value; }
}
private string _cvv = string.Empty;
@@ -319,8 +324,8 @@ public string CVV
///
public string CardType
{
- get { return this._cardType; }
- set { if (this._cardType != value) { this._cardType = value; } }
+ get { return _cardType; }
+ set { _cardType = value; }
}
private string _cardType = string.Empty;
@@ -330,7 +335,7 @@ public string CardType
public string BankName
{
get { return _bankName; }
- set { if (_bankName != value) _bankName = value; }
+ set { _bankName = value; }
}
private string _bankName = string.Empty;
@@ -340,7 +345,7 @@ public string BankName
public string MaskedBankRoutingNumber
{
get { return _maskedBankRoutingNumber; }
- set { if (_maskedBankRoutingNumber != value) _maskedBankRoutingNumber = value; }
+ set { _maskedBankRoutingNumber = value; }
}
private string _maskedBankRoutingNumber = string.Empty;
@@ -350,7 +355,7 @@ public string MaskedBankRoutingNumber
public string BankRoutingNumber
{
get { return _bankRoutingNumber; }
- set { if (_bankRoutingNumber != value) _bankRoutingNumber = value; }
+ set { _bankRoutingNumber = value; }
}
private string _bankRoutingNumber = string.Empty;
@@ -360,7 +365,7 @@ public string BankRoutingNumber
public string MaskedBankAccountNumber
{
get { return _maskedBankAccountNumber; }
- set { if (_maskedBankAccountNumber != value) _maskedBankAccountNumber = value; }
+ set { _maskedBankAccountNumber = value; }
}
private string _maskedBankAccountNumber = string.Empty;
@@ -370,7 +375,7 @@ public string MaskedBankAccountNumber
public string BankAccountNumber
{
get { return _bankAccountNumber; }
- set { if (_bankAccountNumber != value) _bankAccountNumber = value; }
+ set { _bankAccountNumber = value; }
}
private string _bankAccountNumber = string.Empty;
///
@@ -379,7 +384,7 @@ public string BankAccountNumber
public BankAccountType BankAccountType
{
get { return _bankAccountType; }
- set { if (_bankAccountType != value) _bankAccountType = value; }
+ set { _bankAccountType = value; }
}
private BankAccountType _bankAccountType = BankAccountType.Unknown;
@@ -389,7 +394,7 @@ public BankAccountType BankAccountType
public BankAccountHolderType BankAccountHolderType
{
get { return _bankAccountHolderType; }
- set { if (_bankAccountHolderType != value) _bankAccountHolderType = value; }
+ set { _bankAccountHolderType = value; }
}
private BankAccountHolderType _bankAccountHolderType = BankAccountHolderType.Unknown;
@@ -399,7 +404,7 @@ public BankAccountHolderType BankAccountHolderType
public string MaskedCardNumber
{
get { return _maskedCardNumber; }
- set { if (_maskedCardNumber != value) _maskedCardNumber = value; }
+ set { _maskedCardNumber = value; }
}
private string _maskedCardNumber = string.Empty;
@@ -409,7 +414,7 @@ public string MaskedCardNumber
public string PaymentMethodNonce
{
get { return _paymentMethodNonce; }
- set { if (_paymentMethodNonce != value) _paymentMethodNonce = value; }
+ set { _paymentMethodNonce = value; }
}
private string _paymentMethodNonce = string.Empty;
@@ -419,39 +424,18 @@ public string PaymentMethodNonce
public string PayPalEmail
{
get { return _payPalEmail; }
- set { if (_payPalEmail != value) _payPalEmail = value; }
+ set { _payPalEmail = value; }
}
private string _payPalEmail = string.Empty;
#endregion
- #region Equality
- ///
- /// GetHashCode
- ///
- ///
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
-
- ///
- /// Equality Operator
- ///
- ///
- ///
- public override bool Equals(object obj)
- {
- return base.Equals(obj);
- }
- #endregion
-
///
/// Represent this object as a string
///
/// A string representation of the object
public override string ToString()
{
- return string.Format(" {0}: {1}\nName on Card: {2} {3}\nExpires {4}/{5}", this.CardType, this.FullNumber, this.FirstName, this.LastName, this.ExpirationMonth, this.ExpirationYear);
+ return string.Format(" {0}: {1}\nName on Card: {2} {3}\nExpires {4}/{5}", CardType, FullNumber, FirstName, LastName, ExpirationMonth, ExpirationYear);
}
}
diff --git a/Source/Chargify.NET/Product.cs b/Source/Chargify.NET/Product.cs
index fdfaeea..56a4bac 100644
--- a/Source/Chargify.NET/Product.cs
+++ b/Source/Chargify.NET/Product.cs
@@ -32,10 +32,10 @@ namespace ChargifyNET
{
#region Imports
using System;
+ using System.Collections.Generic;
using System.Diagnostics;
using System.Xml;
- using ChargifyNET.Json;
- using System.Collections.Generic;
+ using Json;
#endregion
///
@@ -49,21 +49,21 @@ public class Product : ChargifyBase, IProduct, IComparable
///
/// Constructor
///
- public Product() : base() { }
+ public Product()
+ { }
///
/// Constructor
///
- /// An XML string containing a product node
- public Product(string ProductXML)
- : base()
+ /// An XML string containing a product node
+ public Product(string productXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(ProductXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "ProductXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(productXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(productXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "product")
{
@@ -72,7 +72,7 @@ public Product(string ProductXML)
}
}
// if we get here, then no customer info was found
- throw new ArgumentException("XML does not contain product information", "ProductXML");
+ throw new ArgumentException("XML does not contain product information", nameof(productXml));
}
///
@@ -80,11 +80,10 @@ public Product(string ProductXML)
///
/// An aml node with product information
internal Product(XmlNode productNode)
- : base()
{
- if (productNode == null) throw new ArgumentNullException("productNode");
- if (productNode.Name != "product") throw new ArgumentException("Not a vaild product node", "productNode");
- if (productNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "productNode");
+ if (productNode == null) throw new ArgumentNullException(nameof(productNode));
+ if (productNode.Name != "product") throw new ArgumentException("Not a vaild product node", nameof(productNode));
+ if (productNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(productNode));
LoadFromNode(productNode);
}
@@ -93,18 +92,17 @@ internal Product(XmlNode productNode)
///
/// JsonObject containing product info (in expected format)
public Product(JsonObject productObject)
- : base()
{
- if (productObject == null) throw new ArgumentNullException("productObject");
- if (productObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild product object", "productObject");
- this.LoadFromJSON(productObject);
+ if (productObject == null) throw new ArgumentNullException(nameof(productObject));
+ if (productObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild product object", nameof(productObject));
+ LoadFromJson(productObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing product data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -158,7 +156,7 @@ private void LoadFromJSON(JsonObject obj)
break;
case "return_url":
case "update_return_url":
- _returnURL = obj.GetJSONContentAsString(key);
+ _returnUrl = obj.GetJSONContentAsString(key);
break;
case "return_params":
case "update_return_params":
@@ -185,8 +183,6 @@ private void LoadFromJSON(JsonObject obj)
case "public_signup_pages":
_publicSignupPages = obj.GetJSONContentAsPublicSignupPages(key);
break;
- default:
- break;
}
}
}
@@ -246,7 +242,7 @@ private void LoadFromNode(XmlNode productNode)
break;
case "return_url":
case "update_return_url":
- _returnURL = dataNode.GetNodeContentAsString();
+ _returnUrl = dataNode.GetNodeContentAsString();
break;
case "return_params":
case "update_return_params":
@@ -273,8 +269,6 @@ private void LoadFromNode(XmlNode productNode)
case "public_signup_pages":
_publicSignupPages = dataNode.GetNodeContentAsPublicSignupPages();
break;
- default:
- break;
}
}
}
@@ -297,7 +291,7 @@ public int PriceInCents
_priceInCents = value;
}
}
- private int _priceInCents = 0;
+ private int _priceInCents;
///
/// Get the price, in dollars and cents.
@@ -306,7 +300,7 @@ public decimal Price
{
get
{
- return Convert.ToDecimal(this._priceInCents) / 100;
+ return Convert.ToDecimal(_priceInCents) / 100;
}
}
@@ -333,7 +327,7 @@ public int ID
{
get { return _id; }
}
- private int _id = 0;
+ private int _id;
///
/// Get the handle to this product
@@ -377,7 +371,7 @@ public IProductFamily ProductFamily
return _productFamily;
}
}
- private IProductFamily _productFamily = null;
+ private IProductFamily _productFamily;
///
/// Get the accounting code for this product
@@ -425,7 +419,7 @@ public int Interval
_interval = value;
}
}
- private int _interval = 0;
+ private int _interval;
///
/// Get the up front charge you have specified, in cents.
@@ -438,7 +432,7 @@ public int InitialChargeInCents
_initialChargeInCents = value;
}
}
- private int _initialChargeInCents = 0;
+ private int _initialChargeInCents;
///
/// Get the up front charge for this product, in dollars and cents.
@@ -447,7 +441,7 @@ public decimal InitialCharge
{
get
{
- return Convert.ToDecimal(this._initialChargeInCents) / 100;
+ return Convert.ToDecimal(_initialChargeInCents) / 100;
}
}
@@ -462,7 +456,7 @@ public int TrialPriceInCents
_trialPriceInCents = value;
}
}
- private int _trialPriceInCents = 0;
+ private int _trialPriceInCents;
///
/// Get the price of the trial period for a subscription to this product, in dollars and cents.
@@ -471,7 +465,7 @@ public decimal TrialPrice
{
get
{
- return Convert.ToDecimal(this._trialPriceInCents) / 100; ;
+ return Convert.ToDecimal(_trialPriceInCents) / 100;
}
}
@@ -486,7 +480,7 @@ public int TrialInterval
_trialInterval = value;
}
}
- private int _trialInterval = 0;
+ private int _trialInterval;
///
/// A string representing the trial interval unit for this product, either "month" or "day"
@@ -512,7 +506,7 @@ public int ExpirationInterval
_expirationInterval = value;
}
}
- private int _expirationInterval = 0;
+ private int _expirationInterval;
///
/// A string representing the expiration interval for this product, either "month" or "day"
@@ -532,26 +526,26 @@ public IntervalUnit ExpirationIntervalUnit
///
public string ReturnURL
{
- get { return _returnURL; }
+ get { return _returnUrl; }
set
{
- _returnURL = value;
+ _returnUrl = value;
}
}
- private string _returnURL = string.Empty;
+ private string _returnUrl = string.Empty;
///
/// The URL the buyer is returned to after successful purchase.
///
- public string UpdateReturnURL
+ public string UpdateReturnUrl
{
- get { return _returnURL; }
+ get { return _returnUrl; }
set
{
- _returnURL = value;
+ _returnUrl = value;
}
}
-
+
///
/// The parameter string chargify will use in constructing the return URL.
///
@@ -576,7 +570,7 @@ public bool RequireCreditCard
_requireCreditCard = value;
}
}
- private bool _requireCreditCard = false;
+ private bool _requireCreditCard;
///
/// This product requests a credit card
@@ -589,7 +583,7 @@ public bool RequestCreditCard
_requestCreditCard = value;
}
}
- private bool _requestCreditCard = false;
+ private bool _requestCreditCard;
///
/// Timestamp indicating when this product was created.
@@ -624,6 +618,9 @@ public DateTime ArchivedAt
public List PublicSignupPages { get { return _publicSignupPages; } }
private List _publicSignupPages = new List();
+ ///
+ /// The product version number
+ ///
public int ProductVersion
{
get { return _productVersion; }
@@ -640,10 +637,10 @@ public int ProductVersion
public static bool operator ==(Product a, Product b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if (((object) a == null) || ((object) b == null)) { return false; }
return (a.Handle == b.Handle);
}
@@ -664,10 +661,10 @@ public int ProductVersion
public static bool operator ==(Product a, IProduct b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if (((object) a == null) || (b == null)) { return false; }
return (a.Handle == b.Handle);
}
@@ -688,10 +685,10 @@ public int ProductVersion
public static bool operator ==(IProduct a, Product b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if ((a == null) || ((object) b == null)) { return false; }
return (a.Handle == b.Handle);
}
@@ -725,14 +722,11 @@ public override bool Equals(object obj)
{
if (obj == null) return false;
- if (typeof(IProduct).IsAssignableFrom(obj.GetType()))
- {
- return (this.Handle == (obj as IProduct).Handle);
- }
- else
+ if (obj is IProduct)
{
- return base.Equals(obj);
+ return (Handle == ((IProduct) obj).Handle);
}
+ return ReferenceEquals(this, obj);
}
///
@@ -741,7 +735,7 @@ public override bool Equals(object obj)
/// The string representation of the object
public override string ToString()
{
- return this.Name;
+ return Name;
}
#endregion
@@ -755,7 +749,7 @@ public override string ToString()
/// The result of the comparison
public int CompareTo(IProductFamily other)
{
- return this.Name.CompareTo(other.Name);
+ return string.Compare(Name, other.Name, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -769,7 +763,7 @@ public int CompareTo(IProductFamily other)
/// The result of the comparison
public int CompareTo(Product other)
{
- return this.Name.CompareTo(other.Name);
+ return string.Compare(Name, other.Name, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/ProductFamily.cs b/Source/Chargify.NET/ProductFamily.cs
index e2d7a0d..7849cf4 100644
--- a/Source/Chargify.NET/ProductFamily.cs
+++ b/Source/Chargify.NET/ProductFamily.cs
@@ -34,7 +34,7 @@ namespace ChargifyNET
using System;
using System.Diagnostics;
using System.Xml;
-using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -48,53 +48,54 @@ public class ProductFamily : ProductFamilyAttributes, IProductFamily, IComparabl
///
/// Constructor
///
- public ProductFamily() : base() { }
+ public ProductFamily()
+ { }
///
/// Constructor, values specified.
///
- /// The name of the product family
- /// The description of the product family
- /// The accounting number of the product family
- /// The handle of the product family
- public ProductFamily(string Name, string Description, string AccountingCode, string Handle)
- : base(Name, Description, AccountingCode, Handle)
+ /// The name of the product family
+ /// The description of the product family
+ /// The accounting number of the product family
+ /// The handle of the product family
+ public ProductFamily(string name, string description, string accountingCode, string handle)
+ : base(name, description, accountingCode, handle)
{
}
///
/// Constructor
///
- /// The xml data containing information about the product family (to be parsed)
- public ProductFamily(string ProductFamilyXML)
+ /// The xml data containing information about the product family (to be parsed)
+ public ProductFamily(string productFamilyXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(ProductFamilyXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "ProductFamilyXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(productFamilyXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(productFamilyXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "product_family")
{
- this.LoadNodeData(elementNode);
+ LoadNodeData(elementNode);
return;
}
}
// if we get here, then no product family data was found
- throw new ArgumentException("XML does not contain product family information", "ProductFamilyXML");
+ throw new ArgumentException("XML does not contain product family information", nameof(productFamilyXml));
}
///
/// Constructor
///
/// An xml node containing product family information
- internal ProductFamily(XmlNode productFamilyNode) : base()
+ internal ProductFamily(XmlNode productFamilyNode)
{
- if (productFamilyNode == null) throw new ArgumentNullException("productFamilyNode");
- if (productFamilyNode.Name != "product_family") throw new ArgumentException("Not a vaild product family node", "productFamilyNode");
- if (productFamilyNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "productFamilyNode");
- this.LoadNodeData(productFamilyNode);
+ if (productFamilyNode == null) throw new ArgumentNullException(nameof(productFamilyNode));
+ if (productFamilyNode.Name != "product_family") throw new ArgumentException("Not a vaild product family node", nameof(productFamilyNode));
+ if (productFamilyNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(productFamilyNode));
+ LoadNodeData(productFamilyNode);
}
///
@@ -102,39 +103,36 @@ internal ProductFamily(XmlNode productFamilyNode) : base()
///
/// JsonObject containing product family info (in expected format)
public ProductFamily(JsonObject productFamilyObject)
- : base()
{
- if (productFamilyObject == null) throw new ArgumentNullException("productFamilyObject");
- if (productFamilyObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild product family object. No keys!", "productFamilyObject");
- this.LoadJSONData(productFamilyObject);
+ if (productFamilyObject == null) throw new ArgumentNullException(nameof(productFamilyObject));
+ if (productFamilyObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild product family object. No keys!", nameof(productFamilyObject));
+ LoadJsonData(productFamilyObject);
}
///
/// Load product family data from a JsonObject
///
/// The JsonObject containing product family data
- private void LoadJSONData(JsonObject obj)
+ private void LoadJsonData(JsonObject obj)
{
foreach (string key in obj.Keys)
{
switch (key)
{
case "accounting_code":
- this.AccountingCode = obj.GetJSONContentAsString(key);
+ AccountingCode = obj.GetJSONContentAsString(key);
break;
case "description":
- this.Description = obj.GetJSONContentAsString(key);
+ Description = obj.GetJSONContentAsString(key);
break;
case "id":
_id = obj.GetJSONContentAsInt(key);
break;
case "handle":
- this.Handle = obj.GetJSONContentAsString(key);
+ Handle = obj.GetJSONContentAsString(key);
break;
case "name":
- this.Name = obj.GetJSONContentAsString(key);
- break;
- default:
+ Name = obj.GetJSONContentAsString(key);
break;
}
}
@@ -148,21 +146,19 @@ private void LoadNodeData(XmlNode familyNode)
switch (dataNode.Name)
{
case "accounting_code":
- this.AccountingCode = dataNode.GetNodeContentAsString();
+ AccountingCode = dataNode.GetNodeContentAsString();
break;
case "description":
- this.Description = dataNode.GetNodeContentAsString();
+ Description = dataNode.GetNodeContentAsString();
break;
case "id":
_id = dataNode.GetNodeContentAsInt();
break;
case "handle":
- this.Handle = dataNode.GetNodeContentAsString();
+ Handle = dataNode.GetNodeContentAsString();
break;
case "name":
- this.Name = dataNode.GetNodeContentAsString();
- break;
- default:
+ Name = dataNode.GetNodeContentAsString();
break;
}
}
@@ -180,7 +176,7 @@ public int ID
{
get { return _id; }
}
- private int _id = 0;
+ private int _id;
#endregion
@@ -194,10 +190,10 @@ public int ID
public static bool operator ==(ProductFamily a, ProductFamily b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if (((object) a == null) || ((object) b == null)) { return false; }
return (a.Handle == b.Handle);
}
@@ -209,10 +205,10 @@ public int ID
public static bool operator ==(ProductFamily a, IProductFamily b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if (((object) a == null) || (b == null)) { return false; }
return (a.Handle == b.Handle);
}
@@ -224,10 +220,10 @@ public int ID
public static bool operator ==(IProductFamily a, ProductFamily b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if ((a == null) || ((object) b == null)) { return false; }
return (a.Handle == b.Handle);
}
@@ -279,14 +275,11 @@ public override bool Equals(object obj)
{
if (obj == null) return false;
- if (typeof(IProductFamily).IsAssignableFrom(obj.GetType()))
- {
- return (this.Handle == (obj as IProductFamily).Handle);
- }
- else
+ if (obj is IProductFamily)
{
- return base.Equals(obj);
+ return Handle == ((IProductFamily)obj).Handle;
}
+ return ReferenceEquals(this, obj);
}
///
@@ -295,7 +288,7 @@ public override bool Equals(object obj)
/// The string representation of the object
public override string ToString()
{
- return this.Name;
+ return Name;
}
#endregion
@@ -309,7 +302,7 @@ public override string ToString()
/// The result of the comparison
public int CompareTo(IProductFamily other)
{
- return this.Handle.CompareTo(other.Handle);
+ return string.Compare(Handle, other.Handle, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -323,7 +316,7 @@ public int CompareTo(IProductFamily other)
/// The result of the comparison
public int CompareTo(ProductFamily other)
{
- return this.Handle.CompareTo(other.Handle);
+ return string.Compare(Handle, other.Handle, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/ProductFamilyAttributes.cs b/Source/Chargify.NET/ProductFamilyAttributes.cs
index 9c1be19..ece0c76 100644
--- a/Source/Chargify.NET/ProductFamilyAttributes.cs
+++ b/Source/Chargify.NET/ProductFamilyAttributes.cs
@@ -34,15 +34,15 @@ namespace ChargifyNET
using System;
using System.Diagnostics;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
/// Class representing basic attributes for a customer
///
- [DebuggerDisplay("Name: {Name}, SystemID: {SystemID}")]
+ [DebuggerDisplay("Name: {Name}, Handle: {Handle}")]
[Serializable]
- public class ProductFamilyAttributes : ChargifyBase, IProductFamilyAttributes, IComparable
+ public class ProductFamilyAttributes : ChargifyBase, IProductFamilyAttributes
{
#region Field Keys
internal const string NameKey = "name";
@@ -55,50 +55,49 @@ public class ProductFamilyAttributes : ChargifyBase, IProductFamilyAttributes, I
///
/// Default constructor
///
- public ProductFamilyAttributes() : base()
+ public ProductFamilyAttributes()
{
}
///
/// Constructor, all values specified.
///
- /// The name of the product family
- /// The description of the product family
- /// The accounting code of the product family
- /// The handle of the product family
- public ProductFamilyAttributes(string Name, string Description, string AccountingCode, string Handle)
+ /// The name of the product family
+ /// The description of the product family
+ /// The accounting code of the product family
+ /// The handle of the product family
+ public ProductFamilyAttributes(string name, string description, string accountingCode, string handle)
: this()
{
- this.Description = Description;
- this.AccountingCode = AccountingCode;
- this.Handle = Handle;
+ Name = name;
+ Description = description;
+ AccountingCode = accountingCode;
+ Handle = handle;
}
///
/// Constructor
///
- /// The XML which corresponds to this classes members, to be parsed
- public ProductFamilyAttributes(string ProductFamilyAttributesXML)
+ /// The XML which corresponds to this classes members, to be parsed
+ public ProductFamilyAttributes(string productFamilyAttributesXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(ProductFamilyAttributesXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "ProductFamilyAttributesXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(productFamilyAttributesXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(productFamilyAttributesXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
switch (elementNode.Name)
{
case "product_family_attributes":
case "product_family":
- this.LoadFromNode(elementNode);
- break;
- default:
+ LoadFromNode(elementNode);
break;
}
}
-
- return;
+ // if we get here, then no info was found
+ throw new ArgumentException("XML does not contain information", nameof(productFamilyAttributesXml));
}
///
@@ -106,48 +105,45 @@ public ProductFamilyAttributes(string ProductFamilyAttributesXML)
///
/// The product family XML node
internal ProductFamilyAttributes(XmlNode productFamilyAttributesNode)
- : base()
{
- if (productFamilyAttributesNode == null) throw new ArgumentNullException("productFamilyAttributesNode");
- if (productFamilyAttributesNode.Name != "product_family") throw new ArgumentException("Not a vaild product family attributes node", "productFamilyAttributesNode");
- if (productFamilyAttributesNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "productFamilyAttributesNode");
- this.LoadFromNode(productFamilyAttributesNode);
+ if (productFamilyAttributesNode == null) throw new ArgumentNullException(nameof(productFamilyAttributesNode));
+ if (productFamilyAttributesNode.Name != "product_family") throw new ArgumentException("Not a vaild product family attributes node", nameof(productFamilyAttributesNode));
+ if (productFamilyAttributesNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(productFamilyAttributesNode));
+ LoadFromNode(productFamilyAttributesNode);
}
///
/// Constructor
///
/// The product family JSON object
- public ProductFamilyAttributes(JsonObject productFamilyAttributesObject): base()
- {
- if (productFamilyAttributesObject == null) throw new ArgumentNullException("productFamilyAttributesObject");
- if (productFamilyAttributesObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild product family attributes object", "productFamilyAttributesObject");
- this.LoadFromJSON(productFamilyAttributesObject);
+ public ProductFamilyAttributes(JsonObject productFamilyAttributesObject)
+ {
+ if (productFamilyAttributesObject == null) throw new ArgumentNullException(nameof(productFamilyAttributesObject));
+ if (productFamilyAttributesObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild product family attributes object", nameof(productFamilyAttributesObject));
+ LoadFromJson(productFamilyAttributesObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing product family attribute data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
switch (key)
{
case NameKey:
- this.Name = obj.GetJSONContentAsString(key);
+ Name = obj.GetJSONContentAsString(key);
break;
case DescriptionKey:
- this.Description = obj.GetJSONContentAsString(key);
+ Description = obj.GetJSONContentAsString(key);
break;
case HandleKey:
- this.Handle = obj.GetJSONContentAsString(key);
+ Handle = obj.GetJSONContentAsString(key);
break;
case AccountingCodeKey:
- this.AccountingCode = obj.GetJSONContentAsString(key);
- break;
- default:
+ AccountingCode = obj.GetJSONContentAsString(key);
break;
}
}
@@ -164,23 +160,21 @@ private void LoadFromNode(XmlNode customerNode)
switch (dataNode.Name)
{
case NameKey:
- this.Name = dataNode.GetNodeContentAsString();
+ Name = dataNode.GetNodeContentAsString();
break;
case DescriptionKey:
- this.Description = dataNode.GetNodeContentAsString();
+ Description = dataNode.GetNodeContentAsString();
break;
case HandleKey:
- this.Handle = dataNode.GetNodeContentAsString();
+ Handle = dataNode.GetNodeContentAsString();
break;
case AccountingCodeKey:
- this.AccountingCode = dataNode.GetNodeContentAsString();
- break;
- default:
+ AccountingCode = dataNode.GetNodeContentAsString();
break;
}
}
- }
-
+ }
+
#endregion
#region IComparable Members
@@ -191,7 +185,7 @@ private void LoadFromNode(XmlNode customerNode)
/// The result of the comparison
public int CompareTo(IProductFamilyAttributes other)
{
- return this.Handle.CompareTo(other.Handle);
+ return string.Compare(Handle, other.Handle, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
@@ -203,7 +197,7 @@ public int CompareTo(IProductFamilyAttributes other)
/// The result of the comparison
public int CompareTo(ProductFamilyAttributes other)
{
- return this.Handle.CompareTo(other.Handle);
+ return string.Compare(Handle, other.Handle, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/PublicSignupPage.cs b/Source/Chargify.NET/PublicSignupPage.cs
index 31eb81f..1acc4d4 100644
--- a/Source/Chargify.NET/PublicSignupPage.cs
+++ b/Source/Chargify.NET/PublicSignupPage.cs
@@ -34,7 +34,7 @@ namespace ChargifyNET
using System;
using System.Diagnostics;
using System.Xml;
- using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -56,65 +56,61 @@ public class PublicSignupPage : ChargifyBase, IPublicSignupPage, IComparable
private PublicSignupPage()
- : base()
{
}
///
/// Constructor
///
- /// An XML string containing a node
- public PublicSignupPage(string xml)
- : base()
+ /// An XML string containing a node
+ public PublicSignupPage(string publicSignupPageXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(xml);
+ doc.LoadXml(publicSignupPageXml);
if (doc.ChildNodes.Count == 0)
- throw new ArgumentException("XML not valid", "xml");
+ throw new ArgumentException("XML not valid", nameof(publicSignupPageXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "public_signup_page")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain information", "xml");
+ throw new ArgumentException("XML does not contain information", nameof(publicSignupPageXml));
}
///
/// Constructor
///
- /// An xml node with data
- internal PublicSignupPage(XmlNode node)
- : base()
+ /// An xml node with data
+ internal PublicSignupPage(XmlNode publicSignupPageNode)
{
- if (node == null)
- throw new ArgumentNullException("node");
- if (node.Name != "public_signup_page")
- throw new ArgumentException("Not a vaild xml node", "node");
- if (node.ChildNodes.Count == 0)
- throw new ArgumentException("XML not valid", "node");
-
- this.LoadFromNode(node);
+ if (publicSignupPageNode == null)
+ throw new ArgumentNullException(nameof(publicSignupPageNode));
+ if (publicSignupPageNode.Name != "public_signup_page")
+ throw new ArgumentException("Not a vaild xml node", nameof(publicSignupPageNode));
+ if (publicSignupPageNode.ChildNodes.Count == 0)
+ throw new ArgumentException("XML not valid", nameof(publicSignupPageNode));
+
+ LoadFromNode(publicSignupPageNode);
}
///
/// Constructor
///
- /// JsonObject containing json info (in expected format)
- public PublicSignupPage(JsonObject json)
- : base()
+ /// JsonObject containing json info (in expected format)
+ public PublicSignupPage(JsonObject publicSignupPageJson)
{
- if (json == null)
- throw new ArgumentNullException("json");
- if (json.Keys.Count <= 0)
- throw new ArgumentException("Not a vaild json object", "json");
+ if (publicSignupPageJson == null)
+ throw new ArgumentNullException(nameof(publicSignupPageJson));
+ if (publicSignupPageJson.Keys.Count <= 0)
+ throw new ArgumentException("Not a vaild json object", nameof(publicSignupPageJson));
- this.LoadFromJson(json);
+ LoadFromJson(publicSignupPageJson);
}
private void LoadFromNode(XmlNode node)
@@ -135,8 +131,6 @@ private void LoadFromNode(XmlNode node)
case ReturnParamsKey:
_returnParams = dataNode.GetNodeContentAsString();
break;
- default:
- break;
}
}
}
@@ -159,8 +153,6 @@ private void LoadFromJson(JsonObject obj)
case ReturnParamsKey:
_returnParams = obj.GetJSONContentAsString(key);
break;
- default:
- break;
}
}
}
@@ -201,7 +193,7 @@ private void LoadFromJson(JsonObject obj)
///
public int CompareTo(IPublicSignupPage other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
@@ -213,7 +205,7 @@ public int CompareTo(IPublicSignupPage other)
///
public int CompareTo(PublicSignupPage other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
}
diff --git a/Source/Chargify.NET/Refund.cs b/Source/Chargify.NET/Refund.cs
index 19a464b..9907d10 100644
--- a/Source/Chargify.NET/Refund.cs
+++ b/Source/Chargify.NET/Refund.cs
@@ -32,9 +32,9 @@ namespace ChargifyNET
{
#region Imports
using System;
- using System.Xml;
- using ChargifyNET.Json;
using System.Diagnostics;
+ using System.Xml;
+ using Json;
#endregion
///
@@ -45,7 +45,7 @@ namespace ChargifyNET
public class Refund : ChargifyBase, IRefund, IComparable
{
#region Field Keys
- private const string PaymentIDKey = "id";
+ private const string PaymentIdKey = "id";
private const string SuccessKey = "success";
private const string AmountInCentsKey = "amount_in_cents";
private const string MemoKey = "memo";
@@ -55,19 +55,19 @@ public class Refund : ChargifyBase, IRefund, IComparable
///
/// Constructor
///
- private Refund() : base() { }
+ private Refund()
+ { }
///
/// Constructor
///
- /// An XML string containing a refund node
- public Refund(string refundXML)
- : base()
+ /// An XML string containing a refund node
+ public Refund(string refundXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(refundXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "refundXML");
+ doc.LoadXml(refundXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(refundXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -78,7 +78,7 @@ public Refund(string refundXML)
}
}
// if we get here, then no refund info was found
- throw new ArgumentException("XML does not contain refund information", "refundXML");
+ throw new ArgumentException("XML does not contain refund information", nameof(refundXml));
}
///
@@ -86,12 +86,11 @@ public Refund(string refundXML)
///
/// An xml node with refund information
internal Refund(XmlNode refundNode)
- : base()
{
- if (refundNode == null) throw new ArgumentNullException("refundNode");
- if (refundNode.Name != "refund") throw new ArgumentException("Not a vaild refund node", "refundNode");
- if (refundNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "refundNode");
- this.LoadFromNode(refundNode);
+ if (refundNode == null) throw new ArgumentNullException(nameof(refundNode));
+ if (refundNode.Name != "refund") throw new ArgumentException("Not a vaild refund node", nameof(refundNode));
+ if (refundNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(refundNode));
+ LoadFromNode(refundNode);
}
///
@@ -99,22 +98,21 @@ internal Refund(XmlNode refundNode)
///
/// An JsonObject with refund information
public Refund(JsonObject refundObject)
- : base()
{
- if (refundObject == null) throw new ArgumentNullException("refundObject");
- if (refundObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild refund object", "refundObject");
- this.LoadFromJSON(refundObject);
+ if (refundObject == null) throw new ArgumentNullException(nameof(refundObject));
+ if (refundObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild refund object", nameof(refundObject));
+ LoadFromJson(refundObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get component info, and parse it out
foreach (string key in obj.Keys)
{
switch (key)
{
- case PaymentIDKey:
- _paymentID = obj.GetJSONContentAsInt(key);
+ case PaymentIdKey:
+ _paymentId = obj.GetJSONContentAsInt(key);
break;
case SuccessKey:
_success = obj.GetJSONContentAsBoolean(key);
@@ -125,8 +123,6 @@ private void LoadFromJSON(JsonObject obj)
case MemoKey:
_memo = obj.GetJSONContentAsString(key);
break;
- default:
- break;
}
}
}
@@ -138,8 +134,8 @@ private void LoadFromNode(XmlNode obj)
{
switch (dataNode.Name)
{
- case PaymentIDKey:
- _paymentID = dataNode.GetNodeContentAsInt();
+ case PaymentIdKey:
+ _paymentId = dataNode.GetNodeContentAsInt();
break;
case SuccessKey:
_success = dataNode.GetNodeContentAsBoolean();
@@ -150,8 +146,6 @@ private void LoadFromNode(XmlNode obj)
case MemoKey:
_memo = dataNode.GetNodeContentAsString();
break;
- default:
- break;
}
}
}
@@ -164,9 +158,9 @@ private void LoadFromNode(XmlNode obj)
///
public int PaymentID
{
- get { return _paymentID; }
+ get { return _paymentId; }
}
- private int _paymentID = int.MinValue;
+ private int _paymentId = int.MinValue;
///
/// Was the refund successful?
@@ -175,7 +169,7 @@ public bool Success
{
get { return _success; }
}
- private bool _success = false;
+ private bool _success;
///
/// The amount of the refund and captured payment, represented in cents
@@ -191,7 +185,7 @@ public int AmountInCents
///
public decimal Amount
{
- get { return Convert.ToDecimal(this._amountInCents) / 100; }
+ get { return Convert.ToDecimal(_amountInCents) / 100; }
}
///
@@ -214,7 +208,7 @@ public string Memo
/// The result of the comparison
public int CompareTo(IRefund other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
@@ -228,7 +222,7 @@ public int CompareTo(IRefund other)
/// The result of the comparison
public int CompareTo(Refund other)
{
- return this.AmountInCents.CompareTo(other.AmountInCents);
+ return AmountInCents.CompareTo(other.AmountInCents);
}
#endregion
diff --git a/Source/Chargify.NET/RenewalDetails.cs b/Source/Chargify.NET/RenewalDetails.cs
index 8e24934..cabcfb7 100644
--- a/Source/Chargify.NET/RenewalDetails.cs
+++ b/Source/Chargify.NET/RenewalDetails.cs
@@ -31,12 +31,15 @@
namespace ChargifyNET
{
#region Imports
- using ChargifyNET.Json;
using System;
using System.Collections.Generic;
using System.Xml;
+ using Json;
#endregion
+ ///
+ /// Information that is returned when performing a renewal preview
+ ///
public class RenewalDetails : ChargifyBase, IRenewalDetails, IComparable
{
#region Field Keys
@@ -55,41 +58,42 @@ public class RenewalDetails : ChargifyBase, IRenewalDetails, IComparable
/// Default constructor
///
- public RenewalDetails() : base() { }
+ public RenewalDetails()
+ { }
///
/// Constructor
///
- ///
- public RenewalDetails(string xml) : base()
+ ///
+ public RenewalDetails(string renewalXml)
{
// get the XML into an XML document
var xmlDoc = new XmlDocument();
- xmlDoc.LoadXml(xml);
- if (xmlDoc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid, expecting children.", nameof(xml));
+ xmlDoc.LoadXml(renewalXml);
+ if (xmlDoc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid, expecting children.", nameof(renewalXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in xmlDoc.ChildNodes)
{
if (elementNode.Name == "renewal_preview")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain coupon information", "CouponXML");
+ throw new ArgumentException("XML does not contain coupon information", nameof(renewalXml));
}
///
/// Xml parsing constructor
///
- ///
- internal RenewalDetails(XmlNode node) : base()
+ ///
+ internal RenewalDetails(XmlNode renewalNode)
{
- if (node == null) throw new ArgumentNullException(nameof(node));
- if (node.Name != "renewal_preview") throw new ArgumentException("Not a vaild renewal preview node", nameof(node));
- if (node.ChildNodes.Count == 0) throw new ArgumentException("XML not valid, expecting children", nameof(node));
- this.LoadFromNode(node);
+ if (renewalNode == null) throw new ArgumentNullException(nameof(renewalNode));
+ if (renewalNode.Name != "renewal_preview") throw new ArgumentException("Not a vaild renewal preview node", nameof(renewalNode));
+ if (renewalNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid, expecting children", nameof(renewalNode));
+ LoadFromNode(renewalNode);
}
private void LoadFromNode(XmlNode node)
@@ -125,8 +129,6 @@ private void LoadFromNode(XmlNode node)
case LineItemsKey:
_lineItems = dataNode.GetNodeContentAsRenewalLineItems();
break;
- default:
- break;
}
}
}
@@ -136,12 +138,11 @@ private void LoadFromNode(XmlNode node)
///
///
public RenewalDetails(JsonObject obj)
- : base()
{
- this.LoadFromJSON(obj);
+ LoadFromJson(obj);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get coupon info, and parse it out
foreach (string key in obj.Keys)
@@ -175,8 +176,6 @@ private void LoadFromJSON(JsonObject obj)
case LineItemsKey:
_lineItems = obj.GetJSONContentAsRenewalLineItems(key);
break;
- default:
- break;
}
}
}
@@ -321,11 +320,16 @@ public bool UncalculatedTaxes
return _uncalculatedTaxes;
}
}
- private bool _uncalculatedTaxes = false;
+ private bool _uncalculatedTaxes;
#endregion
#region IComparable
+ ///
+ /// Compare to
+ ///
+ /// The other details to compare
+ ///
public int CompareTo(RenewalDetails other)
{
throw new NotImplementedException();
diff --git a/Source/Chargify.NET/SiteStatistics.cs b/Source/Chargify.NET/SiteStatistics.cs
index 8c74876..bb63009 100644
--- a/Source/Chargify.NET/SiteStatistics.cs
+++ b/Source/Chargify.NET/SiteStatistics.cs
@@ -28,13 +28,11 @@
//
#endregion
-
namespace ChargifyNET
{
#region Imports
-
- using ChargifyNET.Json;
- using System;
+using System;
+using Json;
#endregion
///
@@ -60,7 +58,6 @@ public class SiteStatistics : ChargifyBase, ISiteStatistics
/// Constructor
///
public SiteStatistics()
- : base()
{
}
@@ -69,14 +66,13 @@ public SiteStatistics()
///
/// An JsonObject with stats information
public SiteStatistics(JsonObject statsObject)
- : base()
{
- if (statsObject == null) throw new ArgumentNullException("statsObject");
- if (statsObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild stats object", "statsObject");
- this.LoadFromJSON(statsObject);
+ if (statsObject == null) throw new ArgumentNullException(nameof(statsObject));
+ if (statsObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild stats object", nameof(statsObject));
+ LoadFromJson(statsObject);
}
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
// loop through the keys of this JsonObject to get stats info, and parse it out
foreach (string key in obj.Keys)
@@ -91,34 +87,31 @@ private void LoadFromJSON(JsonObject obj)
break;
case StatsKey:
JsonObject statsObj = obj[key] as JsonObject;
- foreach (string innerKey in statsObj.Keys)
- {
- switch (innerKey)
+ if (statsObj != null)
+ foreach (string innerKey in statsObj.Keys)
{
- case TotalSubscriptionsKey:
- _totalSubscriptions = statsObj.GetJSONContentAsInt(innerKey);
- break;
- case SubscriptionsTodayKey:
- _subscriptionsToday = statsObj.GetJSONContentAsInt(innerKey);
- break;
- case TotalRevenueKey:
- _totalRevenue = statsObj.GetJSONContentAsString(innerKey);
- break;
- case RevenueTodayKey:
- _revenueToday = statsObj.GetJSONContentAsString(innerKey);
- break;
- case RevenueThisMonthKey:
- _revenueThisMonth = statsObj.GetJSONContentAsString(innerKey);
- break;
- case RevenueThisYearKey:
- _revenueThisYear = statsObj.GetJSONContentAsString(innerKey);
- break;
- default:
- break;
+ switch (innerKey)
+ {
+ case TotalSubscriptionsKey:
+ _totalSubscriptions = statsObj.GetJSONContentAsInt(innerKey);
+ break;
+ case SubscriptionsTodayKey:
+ _subscriptionsToday = statsObj.GetJSONContentAsInt(innerKey);
+ break;
+ case TotalRevenueKey:
+ _totalRevenue = statsObj.GetJSONContentAsString(innerKey);
+ break;
+ case RevenueTodayKey:
+ _revenueToday = statsObj.GetJSONContentAsString(innerKey);
+ break;
+ case RevenueThisMonthKey:
+ _revenueThisMonth = statsObj.GetJSONContentAsString(innerKey);
+ break;
+ case RevenueThisYearKey:
+ _revenueThisYear = statsObj.GetJSONContentAsString(innerKey);
+ break;
+ }
}
- }
- break;
- default:
break;
}
}
diff --git a/Source/Chargify.NET/Sites.cs b/Source/Chargify.NET/Sites.cs
index 8c6781e..866da8c 100644
--- a/Source/Chargify.NET/Sites.cs
+++ b/Source/Chargify.NET/Sites.cs
@@ -1,5 +1,8 @@
namespace ChargifyNET
{
+ ///
+ /// The type of cleanup being performed
+ ///
public enum SiteCleanupScope
{
///
diff --git a/Source/Chargify.NET/Statement.cs b/Source/Chargify.NET/Statement.cs
index 544cdb9..2936787 100644
--- a/Source/Chargify.NET/Statement.cs
+++ b/Source/Chargify.NET/Statement.cs
@@ -33,9 +33,9 @@ namespace ChargifyNET
#region Imports
using System;
using System.Collections.Generic;
- using System.Xml;
- using ChargifyNET.Json;
using System.Diagnostics;
+ using System.Xml;
+ using Json;
#endregion
///
@@ -50,10 +50,10 @@ public class Statement : ChargifyBase, IStatement, IComparable
private const string ClosedAtKey = "closed_at";
private const string CreatedAtKey = "created_at";
private const string HtmlViewKey = "html_view";
- private const string IDKey = "id";
+ private const string IdKey = "id";
private const string OpenedAtKey = "opened_at";
private const string SettledAtKey = "settled_at";
- private const string SubscriptionIDKey = "subscription_id";
+ private const string SubscriptionIdKey = "subscription_id";
private const string TextViewKey = "text_view";
private const string UpdatedAtKey = "updated_at";
private const string FuturePaymentsKey = "future_payments";
@@ -83,30 +83,30 @@ public class Statement : ChargifyBase, IStatement, IComparable
///
/// Constructor. Values set to default
///
- public Statement() : base() { }
+ public Statement()
+ { }
///
/// Constructor
///
- /// XML containing statement info (in expected format)
- public Statement(string StatementXML)
- : base()
+ /// XML containing statement info (in expected format)
+ public Statement(string statementXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(StatementXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "StatementXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(statementXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(statementXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "statement")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain charge information", "StatementXML");
+ throw new ArgumentException("XML does not contain charge information", nameof(statementXml));
}
///
@@ -114,30 +114,29 @@ public Statement(string StatementXML)
///
/// XML containing statement info (in expected format)
internal Statement(XmlNode statementNode)
- : base()
{
- if (statementNode == null) throw new ArgumentNullException("statementNode");
- if (statementNode.Name != "statement") throw new ArgumentException("Not a vaild statement node", "statementNode");
- if (statementNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "statementNode");
- this.LoadFromNode(statementNode);
+ if (statementNode == null) throw new ArgumentNullException(nameof(statementNode));
+ if (statementNode.Name != "statement") throw new ArgumentException("Not a vaild statement node", nameof(statementNode));
+ if (statementNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(statementNode));
+ LoadFromNode(statementNode);
}
///
/// Constructor
///
/// Json containing statement info (in expected format)
- public Statement(JsonObject statementObject) : base()
+ public Statement(JsonObject statementObject)
{
- if (statementObject == null) throw new ArgumentNullException("statementObject");
- if (statementObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild statement object", "statementObject");
- this.LoadFromJSON(statementObject);
+ if (statementObject == null) throw new ArgumentNullException(nameof(statementObject));
+ if (statementObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild statement object", nameof(statementObject));
+ LoadFromJson(statementObject);
}
///
/// Loads the values for this object from the Json
///
/// The JsonObject to retrieve the values from
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -155,7 +154,7 @@ private void LoadFromJSON(JsonObject obj)
case HtmlViewKey:
_htmlView = obj.GetJSONContentAsString(key);
break;
- case IDKey:
+ case IdKey:
_id = obj.GetJSONContentAsInt(key);
break;
case OpenedAtKey:
@@ -164,8 +163,8 @@ private void LoadFromJSON(JsonObject obj)
case SettledAtKey:
_settledAt = obj.GetJSONContentAsDateTime(key);
break;
- case SubscriptionIDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case SubscriptionIdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case TextViewKey:
_textView = obj.GetJSONContentAsString(key);
@@ -175,7 +174,7 @@ private void LoadFromJSON(JsonObject obj)
break;
case FuturePaymentsKey:
// TODO: Correct this when the output is corrected
- _futurePayments = (object)obj.GetJSONContentAsString(key);
+ _futurePayments = obj.GetJSONContentAsString(key);
break;
case StartingBalanceKey:
_startingBalanceInCents = obj.GetJSONContentAsInt(key);
@@ -185,7 +184,7 @@ private void LoadFromJSON(JsonObject obj)
break;
case EventsKey:
// TODO: Correct this when the output is corrected
- _events = (object)obj.GetJSONContentAsString(key);
+ _events = obj.GetJSONContentAsString(key);
break;
case CustomerFirstNameKey:
_customerFirstName = obj.GetJSONContentAsString(key);
@@ -237,19 +236,18 @@ private void LoadFromJSON(JsonObject obj)
JsonArray transactionsArray = obj[key] as JsonArray;
if (transactionsArray != null)
{
- foreach (JsonObject transaction in transactionsArray.Items)
+ foreach (var jsonValue in transactionsArray.Items)
{
+ var transaction = (JsonObject) jsonValue;
_transactions.Add(new Transaction(transaction));
}
}
// Sanity check, should be equal.
- if (transactionsArray.Length != _transactions.Count)
+ if (transactionsArray != null && transactionsArray.Length != _transactions.Count)
{
throw new JsonParseException(string.Format("Unable to parse transactions ({0} != {1})", transactionsArray.Length, _transactions.Count));
}
break;
- default:
- break;
}
}
}
@@ -276,7 +274,7 @@ private void LoadFromNode(XmlNode statementNode)
case HtmlViewKey:
_htmlView = dataNode.GetNodeContentAsString();
break;
- case IDKey:
+ case IdKey:
_id = dataNode.GetNodeContentAsInt();
break;
case OpenedAtKey:
@@ -285,8 +283,8 @@ private void LoadFromNode(XmlNode statementNode)
case SettledAtKey:
_settledAt = dataNode.GetNodeContentAsDateTime();
break;
- case SubscriptionIDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case SubscriptionIdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case TextViewKey:
_textView = dataNode.GetNodeContentAsString();
@@ -296,7 +294,7 @@ private void LoadFromNode(XmlNode statementNode)
break;
case FuturePaymentsKey:
// TODO: Correct this when the output is corrected
- _futurePayments = (object)dataNode.GetNodeContentAsString();
+ _futurePayments = dataNode.GetNodeContentAsString();
break;
case StartingBalanceKey:
_startingBalanceInCents = dataNode.GetNodeContentAsInt();
@@ -306,7 +304,7 @@ private void LoadFromNode(XmlNode statementNode)
break;
case EventsKey:
// TODO: Correct this when the output is corrected
- _events = (object)dataNode.GetNodeContentAsString();
+ _events = dataNode.GetNodeContentAsString();
break;
case CustomerFirstNameKey:
_customerFirstName = dataNode.GetNodeContentAsString();
@@ -362,13 +360,9 @@ private void LoadFromNode(XmlNode statementNode)
case "transaction":
_transactions.Add(childNode.GetNodeContentAsTransaction());
break;
- default:
- break;
}
}
break;
- default:
- break;
}
}
}
@@ -391,9 +385,9 @@ public int ID
///
public int SubscriptionID
{
- get { return _subscriptionID; }
+ get { return _subscriptionId; }
}
- private int _subscriptionID = int.MinValue;
+ private int _subscriptionId = int.MinValue;
///
/// The date that the statement was opened
@@ -456,7 +450,7 @@ public object FuturePayments
{
get { return _futurePayments; }
}
- private object _futurePayments = null;
+ private object _futurePayments;
///
/// The subscription's balance at the time the statement was opened (in cents)
@@ -472,7 +466,7 @@ public int StartingBalanceInCents
///
public decimal StartingBalance
{
- get { return Convert.ToDecimal(this._startingBalanceInCents) / 100; }
+ get { return Convert.ToDecimal(_startingBalanceInCents) / 100; }
}
///
@@ -489,7 +483,7 @@ public int EndingBalanceInCents
///
public decimal EndingBalance
{
- get { return Convert.ToDecimal(this._endingBalanceInCents) / 100; }
+ get { return Convert.ToDecimal(_endingBalanceInCents) / 100; }
}
///
@@ -643,7 +637,7 @@ public object Events
{
get { return _events; }
}
- private object _events = null;
+ private object _events;
///
/// The creation date for this statement
@@ -674,7 +668,7 @@ public DateTime UpdatedAt
/// The result of the comparison
public int CompareTo(IStatement other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
@@ -688,7 +682,7 @@ public int CompareTo(IStatement other)
/// The result of the comparison
public int CompareTo(Statement other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
diff --git a/Source/Chargify.NET/Subscription.cs b/Source/Chargify.NET/Subscription.cs
index 90da327..9fc700e 100644
--- a/Source/Chargify.NET/Subscription.cs
+++ b/Source/Chargify.NET/Subscription.cs
@@ -28,14 +28,18 @@
//
#endregion
+using System;
+using System.Diagnostics;
+using System.Text;
+using System.Xml;
+using ChargifyNET.Json;
+
namespace ChargifyNET
{
#region Imports
- using System;
- using System.Diagnostics;
- using System.Text;
- using System.Xml;
- using ChargifyNET.Json;
+
+
+
#endregion
///
@@ -53,7 +57,7 @@ public class Subscription : ChargifyBase, ISubscription, IComparable
/// Constructor. Values set to default
///
- public Subscription() : base()
+ public Subscription()
{
}
///
/// Constructor
///
- /// XML containing subscription info (in expected format)
- public Subscription(string SubscriptionXML) : base()
+ /// XML containing subscription info (in expected format)
+ public Subscription(string subscriptionXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(SubscriptionXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "SubscriptionXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(subscriptionXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(subscriptionXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "subscription")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no customer info was found
- throw new ArgumentException("XML does not contain subscription information", "SubscriptionXML");
+ throw new ArgumentException("XML does not contain subscription information", nameof(subscriptionXml));
}
///
/// Constructor
///
/// XML containing subscription info (in expected format)
- internal Subscription(XmlNode subscriptionNode) : base()
+ internal Subscription(XmlNode subscriptionNode)
{
- if (subscriptionNode == null) throw new ArgumentNullException("SubscriptionNode");
- if (subscriptionNode.Name != "subscription") throw new ArgumentException("Not a vaild subscription node", "subscriptionNode");
- if (subscriptionNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "subscriptionNode");
- this.LoadFromNode(subscriptionNode);
+ if (subscriptionNode == null) throw new ArgumentNullException(nameof(subscriptionNode));
+ if (subscriptionNode.Name != "subscription") throw new ArgumentException("Not a vaild subscription node", nameof(subscriptionNode));
+ if (subscriptionNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(subscriptionNode));
+ LoadFromNode(subscriptionNode);
}
///
@@ -126,25 +130,24 @@ internal Subscription(XmlNode subscriptionNode) : base()
///
/// JsonObject containing subscription info (in expected format)
public Subscription(JsonObject subscriptionObject)
- : base()
{
- if (subscriptionObject == null) throw new ArgumentNullException("subscriptionObject");
- if (subscriptionObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild subscription node", "subscriptionObject");
- this.LoadFromJSON(subscriptionObject);
+ if (subscriptionObject == null) throw new ArgumentNullException(nameof(subscriptionObject));
+ if (subscriptionObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild subscription node", nameof(subscriptionObject));
+ LoadFromJson(subscriptionObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing subscription data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
switch (key)
{
- case IDKey:
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ case IdKey:
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case StateKey:
_state = obj.GetJSONContentAsSubscriptionState(key);
@@ -185,8 +188,8 @@ private void LoadFromJSON(JsonObject obj)
case CancelAtEndOfPeriodKey:
_cancelAtEndOfPeriod = obj.GetJSONContentAsBoolean(key);
break;
- case SignupPaymentIDKey:
- _signupPaymentID = obj.GetJSONContentAsInt(key);
+ case SignupPaymentIdKey:
+ _signupPaymentId = obj.GetJSONContentAsInt(key);
break;
case SignupRevenueKey:
_signupRevenue = obj.GetJSONContentAsDecimal(key);
@@ -230,8 +233,6 @@ private void LoadFromJSON(JsonObject obj)
case NextProductIdKey:
_nextProductId = obj.GetJSONContentAsInt(key);
break;
- default:
- break;
}
}
}
@@ -246,8 +247,8 @@ private void LoadFromNode(XmlNode subscriptionNode)
{
switch (dataNode.Name)
{
- case IDKey:
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ case IdKey:
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case StateKey:
_state = dataNode.GetNodeContentAsSubscriptionState();
@@ -288,8 +289,8 @@ private void LoadFromNode(XmlNode subscriptionNode)
case CancelAtEndOfPeriodKey:
_cancelAtEndOfPeriod = dataNode.GetNodeContentAsBoolean();
break;
- case SignupPaymentIDKey:
- _signupPaymentID = dataNode.GetNodeContentAsInt();
+ case SignupPaymentIdKey:
+ _signupPaymentId = dataNode.GetNodeContentAsInt();
break;
case SignupRevenueKey:
_signupRevenue = dataNode.GetNodeContentAsDecimal();
@@ -332,8 +333,6 @@ private void LoadFromNode(XmlNode subscriptionNode)
case NextProductIdKey:
_nextProductId = dataNode.GetNodeContentAsInt();
break;
- default:
- break;
}
}
@@ -350,10 +349,10 @@ public int SubscriptionID
{
get
{
- return _subscriptionID;
+ return _subscriptionId;
}
}
- private int _subscriptionID;
+ private int _subscriptionId;
///
/// The current state of the subscription.
@@ -387,7 +386,7 @@ public decimal Balance
{
get
{
- return Convert.ToDecimal(this._balanceInCents) / 100;
+ return Convert.ToDecimal(_balanceInCents) / 100;
}
}
@@ -547,7 +546,7 @@ public IProduct Product
return _product;
}
}
- private IProduct _product = null;
+ private IProduct _product;
///
/// Get the credit card information for this subscription
@@ -559,7 +558,7 @@ public IPaymentProfileView PaymentProfile
return _paymentProfile;
}
}
- private IPaymentProfileView _paymentProfile = null;
+ private IPaymentProfileView _paymentProfile;
///
/// Get the customer information for this subscription
@@ -571,7 +570,7 @@ public ICustomer Customer
return _customer;
}
}
- private ICustomer _customer = null;
+ private ICustomer _customer;
///
/// Is this subscription going to automatically cancel at the end of the current period?
@@ -580,16 +579,16 @@ public bool CancelAtEndOfPeriod
{
get { return _cancelAtEndOfPeriod; }
}
- private bool _cancelAtEndOfPeriod = false;
+ private bool _cancelAtEndOfPeriod;
///
/// The ID of the corresponding payment transaction
///
public int SignupPaymentID
{
- get { return _signupPaymentID; }
+ get { return _signupPaymentId; }
}
- private int _signupPaymentID = int.MinValue;
+ private int _signupPaymentId = int.MinValue;
///
/// The revenue accepted upon signup
@@ -623,7 +622,7 @@ public SubscriptionState PreviousState
///
public decimal TotalRevenue
{
- get { return Convert.ToDecimal(this._totalRevenueInCents) / 100; }
+ get { return Convert.ToDecimal(_totalRevenueInCents) / 100; }
}
///
/// The total subscription revenue (in cents)
@@ -637,7 +636,7 @@ public int TotalRevenueInCents
///
/// The type of billing used for this subscription
///
- public PaymentCollectionMethod PaymentCollectionMethod { get { return this._paymentCollectionMethod; } }
+ public PaymentCollectionMethod PaymentCollectionMethod { get { return _paymentCollectionMethod; } }
private PaymentCollectionMethod _paymentCollectionMethod = PaymentCollectionMethod.Unknown;
///
@@ -650,7 +649,7 @@ public int ProductVersionNumber
{
get
{
- return this._productVersionNumber;
+ return _productVersionNumber;
}
}
@@ -670,7 +669,7 @@ public int ProductPriceInCents
///
public decimal ProductPrice
{
- get { return Convert.ToDecimal(this._productPriceInCents) / 100; }
+ get { return Convert.ToDecimal(_productPriceInCents) / 100; }
}
///
@@ -691,7 +690,7 @@ public decimal ProductPrice
public static bool operator ==(Subscription a, Subscription b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null)) { return false; }
@@ -706,10 +705,10 @@ public decimal ProductPrice
public static bool operator ==(Subscription a, ISubscription b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if (((object)a == null) || (b == null)) { return false; }
return (a.SubscriptionID == b.SubscriptionID);
}
@@ -721,10 +720,10 @@ public decimal ProductPrice
public static bool operator ==(ISubscription a, Subscription b)
{
// If both are null, or both are same instance, return true.
- if (System.Object.ReferenceEquals(a, b)) { return true; }
+ if (ReferenceEquals(a, b)) { return true; }
// If one is null, but not both, return false.
- if (((object)a == null) || ((object)b == null)) { return false; }
+ if ((a == null) || ((object)b == null)) { return false; }
return (a.SubscriptionID == b.SubscriptionID);
}
@@ -776,14 +775,11 @@ public override bool Equals(object obj)
{
if (obj == null) return false;
- if (typeof(ISubscription).IsAssignableFrom(obj.GetType()))
- {
- return (this.SubscriptionID == (obj as ISubscription).SubscriptionID);
- }
- else
+ if (obj is ISubscription)
{
- return base.Equals(obj);
+ return (SubscriptionID == (obj as ISubscription).SubscriptionID);
}
+ return ReferenceEquals(this, obj);
}
///
@@ -791,17 +787,17 @@ public override bool Equals(object obj)
///
public override string ToString()
{
- StringBuilder MyString = new StringBuilder();
- if (this.Customer != null)
+ StringBuilder myString = new StringBuilder();
+ if (Customer != null)
{
- MyString.AppendFormat("Customer: {0}", this.Customer.FullName);
+ myString.AppendFormat("Customer: {0}", Customer.FullName);
}
- if (this.Product != null)
+ if (Product != null)
{
- MyString.AppendFormat("{0}Product: {1}", (MyString.Length > 0 ? "\n" : ""), this.Product.Name);
+ myString.AppendFormat("{0}Product: {1}", (myString.Length > 0 ? "\n" : ""), Product.Name);
}
- if (!string.IsNullOrEmpty(this.State.ToString())) MyString.AppendFormat("{0}State: {1}", (MyString.Length > 0 ? "\n" : ""), this.State.ToString());
- return MyString.ToString();
+ if (!string.IsNullOrEmpty(State.ToString())) myString.AppendFormat("{0}State: {1}", (myString.Length > 0 ? "\n" : ""), State);
+ return myString.ToString();
}
#endregion
@@ -815,7 +811,7 @@ public override string ToString()
/// The result of the comparison
public int CompareTo(ISubscription other)
{
- return this.SubscriptionID.CompareTo(other.SubscriptionID);
+ return SubscriptionID.CompareTo(other.SubscriptionID);
}
#endregion
@@ -829,7 +825,7 @@ public int CompareTo(ISubscription other)
/// The result of the comparison
public int CompareTo(Subscription other)
{
- return this.SubscriptionID.CompareTo(other.SubscriptionID);
+ return SubscriptionID.CompareTo(other.SubscriptionID);
}
#endregion
diff --git a/Source/Chargify.NET/SubscriptionOverride.cs b/Source/Chargify.NET/SubscriptionOverride.cs
index fef6138..468abe4 100644
--- a/Source/Chargify.NET/SubscriptionOverride.cs
+++ b/Source/Chargify.NET/SubscriptionOverride.cs
@@ -28,12 +28,14 @@
//
#endregion
+
+
namespace ChargifyNET
{
- using Json;
#region Imports
using System;
using System.Xml;
+ using Json;
#endregion
///
@@ -53,43 +55,43 @@ public class SubscriptionOverride : ChargifyBase, ISubscriptionOverride
///
/// Constructor. Values set to default
///
- public SubscriptionOverride() : base()
+ public SubscriptionOverride()
{
}
///
/// Constructor
///
- /// XML containing subscription override info (in expected format)
- public SubscriptionOverride(string SubscriptionOverrideXML) : base()
+ /// XML containing subscription override info (in expected format)
+ public SubscriptionOverride(string subscriptionOverrideXml)
{
// get the XML into an XML document
var xdoc = new XmlDocument();
- xdoc.LoadXml(SubscriptionOverrideXML);
- if (xdoc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "SubscriptionOverrideXML");
+ xdoc.LoadXml(subscriptionOverrideXml);
+ if (xdoc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(subscriptionOverrideXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in xdoc.ChildNodes)
{
if (elementNode.Name == "subscription")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no customer info was found
- throw new ArgumentException("XML does not contain subscription override information", "SubscriptionOverrideXML");
+ throw new ArgumentException("XML does not contain subscription override information", nameof(subscriptionOverrideXml));
}
///
/// Constructor
///
/// XML containing subscription override info (in expected format)
- internal SubscriptionOverride(XmlNode subscriptionOverrideNode) : base()
+ internal SubscriptionOverride(XmlNode subscriptionOverrideNode)
{
- if (subscriptionOverrideNode == null) throw new ArgumentNullException("subscriptionOverrideNode");
- if (subscriptionOverrideNode.Name != "subscription") throw new ArgumentException("Not a vaild subscription override node", "subscriptionOverrideNode");
- if (subscriptionOverrideNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "subscriptionOverrideNode");
- this.LoadFromNode(subscriptionOverrideNode);
+ if (subscriptionOverrideNode == null) throw new ArgumentNullException(nameof(subscriptionOverrideNode));
+ if (subscriptionOverrideNode.Name != "subscription") throw new ArgumentException("Not a vaild subscription override node", nameof(subscriptionOverrideNode));
+ if (subscriptionOverrideNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(subscriptionOverrideNode));
+ LoadFromNode(subscriptionOverrideNode);
}
///
@@ -97,18 +99,17 @@ internal SubscriptionOverride(XmlNode subscriptionOverrideNode) : base()
///
/// JsonObject containing subscription override info (in expected format)
public SubscriptionOverride(JsonObject subscriptionOverrideObject)
- : base()
{
- if (subscriptionOverrideObject == null) throw new ArgumentNullException("subscriptionOverrideObject");
- if (subscriptionOverrideObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild subscription override node", "subscriptionOverrideObject");
- this.LoadFromJSON(subscriptionOverrideObject);
+ if (subscriptionOverrideObject == null) throw new ArgumentNullException(nameof(subscriptionOverrideObject));
+ if (subscriptionOverrideObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild subscription override node", nameof(subscriptionOverrideObject));
+ LoadFromJson(subscriptionOverrideObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing subscription data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -126,8 +127,6 @@ private void LoadFromJSON(JsonObject obj)
case ExpiresAtKey:
_expiresAt = obj.GetJSONContentAsDateTime(key);
break;
- default:
- break;
}
}
}
@@ -154,8 +153,6 @@ private void LoadFromNode(XmlNode subscriptionNode)
case ExpiresAtKey:
_expiresAt = dataNode.GetNodeContentAsDateTime();
break;
- default:
- break;
}
}
}
@@ -170,11 +167,11 @@ public DateTime ActivatedAt
{
get
{
- return this._activatedAt;
+ return _activatedAt;
}
set
{
- this._activatedAt = value;
+ _activatedAt = value;
}
}
private DateTime _activatedAt = DateTime.MinValue;
@@ -186,11 +183,11 @@ public DateTime CanceledAt
{
get
{
- return this._canceledAt;
+ return _canceledAt;
}
set
{
- this._canceledAt = value;
+ _canceledAt = value;
}
}
private DateTime _canceledAt = DateTime.MinValue;
@@ -202,11 +199,11 @@ public string CancellationMessage
{
get
{
- return this._cancellationMessage;
+ return _cancellationMessage;
}
set
{
- this._cancellationMessage = value;
+ _cancellationMessage = value;
}
}
private string _cancellationMessage = string.Empty;
@@ -218,11 +215,11 @@ public DateTime ExpiresAt
{
get
{
- return this._expiresAt;
+ return _expiresAt;
}
set
{
- this._expiresAt = value;
+ _expiresAt = value;
}
}
private DateTime _expiresAt = DateTime.MinValue;
diff --git a/Source/Chargify.NET/Transaction.cs b/Source/Chargify.NET/Transaction.cs
index fce67e6..0b20f69 100644
--- a/Source/Chargify.NET/Transaction.cs
+++ b/Source/Chargify.NET/Transaction.cs
@@ -31,10 +31,10 @@
namespace ChargifyNET
{
#region Imports
- using System;
- using System.Diagnostics;
- using System.Xml;
- using ChargifyNET.Json;
+using System;
+using System.Diagnostics;
+using System.Xml;
+using Json;
#endregion
///
@@ -47,19 +47,19 @@ public class Transaction : ChargifyBase, ITransaction, IComparable
///
/// Constructor
///
- private Transaction() : base() { }
+ private Transaction()
+ { }
///
/// Constructor
///
- /// An XML string containing a transaction node
- public Transaction(string TransactionXML)
- : base()
+ /// An XML string containing a transaction node
+ public Transaction(string transactionXml)
{
// get the XML into an XML document
XmlDocument doc = new XmlDocument();
- doc.LoadXml(TransactionXML);
- if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "TransactionXML");
+ doc.LoadXml(transactionXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(transactionXml));
// loop through the child nodes of this node
foreach (XmlNode elementNode in doc.ChildNodes)
{
@@ -70,7 +70,7 @@ public Transaction(string TransactionXML)
}
}
// if we get here, then no transaction info was found
- throw new ArgumentException("XML does not contain transaction information", "TransactionXML");
+ throw new ArgumentException("XML does not contain transaction information", nameof(transactionXml));
}
///
@@ -78,11 +78,10 @@ public Transaction(string TransactionXML)
///
/// An xml node with transaction information
internal Transaction(XmlNode transactionNode)
- : base()
{
- if (transactionNode == null) throw new ArgumentNullException("transactionNode");
- if (transactionNode.Name != "transaction") throw new ArgumentException("Not a vaild transaction node", "transactionNode");
- if (transactionNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "transactionNode");
+ if (transactionNode == null) throw new ArgumentNullException(nameof(transactionNode));
+ if (transactionNode.Name != "transaction") throw new ArgumentException("Not a vaild transaction node", nameof(transactionNode));
+ if (transactionNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(transactionNode));
LoadFromNode(transactionNode);
}
@@ -91,18 +90,17 @@ internal Transaction(XmlNode transactionNode)
///
/// JsonObject containing transaction info (in expected format)
public Transaction(JsonObject transactionObject)
- : base()
{
- if (transactionObject == null) throw new ArgumentNullException("transactionObject");
- if (transactionObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild transaction object", "transactionObject");
- this.LoadFromJSON(transactionObject);
+ if (transactionObject == null) throw new ArgumentNullException(nameof(transactionObject));
+ if (transactionObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild transaction object", nameof(transactionObject));
+ LoadFromJson(transactionObject);
}
///
/// Load data from a JsonObject
///
/// The JsonObject containing transaction data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -130,27 +128,25 @@ private void LoadFromJSON(JsonObject obj)
_memo = obj.GetJSONContentAsString(key);
break;
case "subscription_id":
- _subscriptionID = obj.GetJSONContentAsInt(key);
+ _subscriptionId = obj.GetJSONContentAsInt(key);
break;
case "product_id":
- _productID = obj.GetJSONContentAsInt(key);
+ _productId = obj.GetJSONContentAsInt(key);
break;
case "success":
_success = obj.GetJSONContentAsBoolean(key);
break;
case "payment_id":
- _paymentID = obj.GetJSONContentAsInt(key);
+ _paymentId = obj.GetJSONContentAsInt(key);
break;
case "kind":
_kind = obj.GetJSONContentAsEnum(key);
break;
case "gateway_transaction_id":
- _gatewayTransactionID = obj.GetJSONContentAsString(key);
+ _gatewayTransactionId = obj.GetJSONContentAsString(key);
break;
case "gateway_order_id":
- _gatewayOrderID = obj.GetJSONContentAsString(key);
- break;
- default:
+ _gatewayOrderId = obj.GetJSONContentAsString(key);
break;
}
}
@@ -189,27 +185,25 @@ private void LoadFromNode(XmlNode transactionNode)
_memo = dataNode.GetNodeContentAsString();
break;
case "subscription_id":
- _subscriptionID = dataNode.GetNodeContentAsInt();
+ _subscriptionId = dataNode.GetNodeContentAsInt();
break;
case "product_id":
- _productID = dataNode.GetNodeContentAsInt();
+ _productId = dataNode.GetNodeContentAsInt();
break;
case "success":
_success = dataNode.GetNodeContentAsBoolean();
break;
case "payment_id":
- _paymentID = dataNode.GetNodeContentAsInt();
+ _paymentId = dataNode.GetNodeContentAsInt();
break;
case "kind":
_kind = dataNode.GetNodeContentAsEnum();
break;
case "gateway_transaction_id":
- _gatewayTransactionID = dataNode.GetNodeContentAsString();
+ _gatewayTransactionId = dataNode.GetNodeContentAsString();
break;
case "gateway_order_id":
- _gatewayOrderID = dataNode.GetNodeContentAsString();
- break;
- default:
+ _gatewayOrderId = dataNode.GetNodeContentAsString();
break;
}
}
@@ -234,7 +228,7 @@ public int ID
{
get { return _id; }
}
- private int _id = 0;
+ private int _id;
///
/// The amount in cents for the Transaction
@@ -243,14 +237,14 @@ public int AmountInCents
{
get { return _amountInCents; }
}
- private int _amountInCents = 0;
+ private int _amountInCents;
///
/// The amount (in dollars and cents) for the Transaction
///
public decimal Amount
{
- get { return Convert.ToDecimal(this._amountInCents) / 100; }
+ get { return Convert.ToDecimal(_amountInCents) / 100; }
}
///
@@ -276,7 +270,7 @@ public int StartingBalanceInCents
///
public decimal StartingBalance
{
- get { return Convert.ToDecimal(this._startingBalanceInCents) / 100; }
+ get { return Convert.ToDecimal(_startingBalanceInCents) / 100; }
}
///
@@ -286,14 +280,14 @@ public int EndingBalanceInCents
{
get { return _endingBalanceInCents; }
}
- private int _endingBalanceInCents = 0;
+ private int _endingBalanceInCents;
///
/// The remaining balance on the subscription after the Transaction has been processed, in dollars and cents.
///
public decimal EndingBalance
{
- get { return Convert.ToDecimal(this._endingBalanceInCents) / 100; }
+ get { return Convert.ToDecimal(_endingBalanceInCents) / 100; }
}
///
@@ -310,18 +304,18 @@ public string Memo
///
public int SubscriptionID
{
- get { return _subscriptionID; }
+ get { return _subscriptionId; }
}
- private int _subscriptionID = 0;
+ private int _subscriptionId;
///
/// The unique identifier for the associated Product
///
public int ProductID
{
- get { return _productID; }
+ get { return _productId; }
}
- private int _productID = 0;
+ private int _productId;
///
/// Whether or not the Transaction was successful.
@@ -330,7 +324,7 @@ public bool Success
{
get { return _success; }
}
- private bool _success = false;
+ private bool _success;
///
/// The unique identifier for the payment being explicitly refunded (in whole or in part) by this transaction.
@@ -339,9 +333,9 @@ public bool Success
///
public int PaymentID
{
- get { return _paymentID; }
+ get { return _paymentId; }
}
- private int _paymentID = int.MinValue;
+ private int _paymentId = int.MinValue;
///
/// The specific "subtype" for the transaction_type
@@ -350,25 +344,25 @@ public TransactionChargeKind? Kind
{
get { return _kind; }
}
- private TransactionChargeKind? _kind = null;
+ private TransactionChargeKind? _kind;
///
/// The transaction ID from the remote gateway (i.e. Authorize.Net), if one exists
///
public string GatewayTransactionID
{
- get { return _gatewayTransactionID; }
+ get { return _gatewayTransactionId; }
}
- private string _gatewayTransactionID = string.Empty;
+ private string _gatewayTransactionId = string.Empty;
///
/// A gateway-specific identifier for the transaction, separate from the gateway_transaction_id
///
public string GatewayOrderID
{
- get { return _gatewayOrderID; }
+ get { return _gatewayOrderId; }
}
- private string _gatewayOrderID = string.Empty;
+ private string _gatewayOrderId = string.Empty;
#endregion
@@ -381,7 +375,7 @@ public string GatewayOrderID
/// The result of the comparison
public int CompareTo(ITransaction other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
@@ -395,7 +389,7 @@ public int CompareTo(ITransaction other)
/// The result of the comparison
public int CompareTo(Transaction other)
{
- return this.ID.CompareTo(other.ID);
+ return ID.CompareTo(other.ID);
}
#endregion
diff --git a/Source/Chargify.NET/Usage.cs b/Source/Chargify.NET/Usage.cs
index f1dffa6..c9231c6 100644
--- a/Source/Chargify.NET/Usage.cs
+++ b/Source/Chargify.NET/Usage.cs
@@ -33,7 +33,7 @@ namespace ChargifyNET
#region Imports
using System;
using System.Xml;
-using ChargifyNET.Json;
+ using Json;
#endregion
///
@@ -46,32 +46,30 @@ public class Usage : ChargifyBase, IUsage, IComparable
/// Constructor. Values set to default
///
public Usage()
- : base()
{
}
///
/// Constructor
///
- /// XML containing usage info (in expected format)
- public Usage(string UsageXML)
- : base()
+ /// XML containing usage info (in expected format)
+ public Usage(string usageXml)
{
// get the XML into an XML document
- XmlDocument Doc = new XmlDocument();
- Doc.LoadXml(UsageXML);
- if (Doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "ChargeXML");
+ XmlDocument doc = new XmlDocument();
+ doc.LoadXml(usageXml);
+ if (doc.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(usageXml));
// loop through the child nodes of this node
- foreach (XmlNode elementNode in Doc.ChildNodes)
+ foreach (XmlNode elementNode in doc.ChildNodes)
{
if (elementNode.Name == "usage")
{
- this.LoadFromNode(elementNode);
+ LoadFromNode(elementNode);
return;
}
}
// if we get here, then no info was found
- throw new ArgumentException("XML does not contain charge information", "ChargeXML");
+ throw new ArgumentException("XML does not contain charge information", nameof(usageXml));
}
///
@@ -79,12 +77,11 @@ public Usage(string UsageXML)
///
/// XML containing usage info (in expected format)
internal Usage(XmlNode usageNode)
- : base()
{
- if (usageNode == null) throw new ArgumentNullException("usageNode");
- if (usageNode.Name != "usage") throw new ArgumentException("Not a vaild usage node", "usageNode");
- if (usageNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", "usageNode");
- this.LoadFromNode(usageNode);
+ if (usageNode == null) throw new ArgumentNullException(nameof(usageNode));
+ if (usageNode.Name != "usage") throw new ArgumentException("Not a vaild usage node", nameof(usageNode));
+ if (usageNode.ChildNodes.Count == 0) throw new ArgumentException("XML not valid", nameof(usageNode));
+ LoadFromNode(usageNode);
}
///
@@ -93,16 +90,16 @@ internal Usage(XmlNode usageNode)
/// JsonObject containing usage info (in expected format)
public Usage(JsonObject usageObject)
{
- if (usageObject == null) throw new ArgumentNullException("usageObject");
- if (usageObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild usage object", "usageObject");
- this.LoadFromJSON(usageObject);
+ if (usageObject == null) throw new ArgumentNullException(nameof(usageObject));
+ if (usageObject.Keys.Count <= 0) throw new ArgumentException("Not a vaild usage object", nameof(usageObject));
+ LoadFromJson(usageObject);
}
///
/// Load usage data from a JsonObject
///
/// The JsonObject containing usage data
- private void LoadFromJSON(JsonObject obj)
+ private void LoadFromJson(JsonObject obj)
{
foreach (string key in obj.Keys)
{
@@ -117,8 +114,6 @@ private void LoadFromJSON(JsonObject obj)
case "quantity":
_quantity = obj.GetJSONContentAsInt(key);
break;
- default:
- break;
}
}
}
@@ -142,8 +137,6 @@ private void LoadFromNode(XmlNode subscriptionNode)
case "quantity":
_quantity = dataNode.GetNodeContentAsInt();
break;
- default:
- break;
}
}
}
@@ -189,7 +182,7 @@ public string Memo
///
public int CompareTo(Usage other)
{
- return this.ID.CompareTo(other.ID);
+ return string.Compare(ID, other.ID, StringComparison.InvariantCultureIgnoreCase);
}
///
@@ -199,7 +192,7 @@ public int CompareTo(Usage other)
///
public int CompareTo(IUsage other)
{
- return this.ID.CompareTo(other.ID);
+ return string.Compare(ID, other.ID, StringComparison.InvariantCultureIgnoreCase);
}
#endregion
diff --git a/Source/Chargify.NET/UsefulExtensions.cs b/Source/Chargify.NET/UsefulExtensions.cs
index 20bbdd7..1689329 100644
--- a/Source/Chargify.NET/UsefulExtensions.cs
+++ b/Source/Chargify.NET/UsefulExtensions.cs
@@ -3,7 +3,7 @@
#region Imports
using System.IO;
using System.Web;
- using ChargifyNET.Json;
+ using Json;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -16,8 +16,14 @@
using System.Xml.Serialization;
#endregion
+ ///
+ /// Utf8 String Writer
+ ///
public class Utf8StringWriter : StringWriter
{
+ ///
+ /// The encoding for this writer
+ ///
public override Encoding Encoding => Encoding.UTF8;
}
@@ -62,7 +68,7 @@ public static void CopyStream(this Stream input, Stream output)
public static bool IsWebhookRequestValid(this Stream requestStream, string sharedKey, string givenSignature = null)
{
bool retVal = true;
- string possibleData = string.Empty;
+ string possibleData;
using (StreamReader sr = new StreamReader(requestStream))
{
requestStream.Position = 0;
@@ -71,7 +77,7 @@ public static bool IsWebhookRequestValid(this Stream requestStream, string share
if (!string.IsNullOrEmpty(possibleData))
{
- var calculatedSignature = UsefulExtensions.CalculateHMAC256Signature(possibleData, sharedKey);
+ var calculatedSignature = CalculateHMAC256Signature(possibleData, sharedKey);
if (calculatedSignature != givenSignature)
{
retVal = false;
@@ -89,6 +95,7 @@ public static bool IsWebhookRequestValid(this Stream requestStream, string share
/// Method to calculate the expected HMAC-SHA256 signture of a body of text using the site's sharedKey
///
/// The text to run through the hashing algorithm
+ /// The secret used to seed the hash
/// The hex hash of the passed in text
public static string CalculateHMAC256Signature(string text, string secret)
{
@@ -117,11 +124,11 @@ public static bool IsChargifyWebhookContentValid(this string text, string signat
byte[] unencryptedData = Encoding.UTF8.GetBytes(unencryptedText);
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(unencryptedData);
- string hexaHash = "";
- foreach (byte b in hash) { hexaHash += String.Format("{0:x2}", b); }
+ string hexaHash = string.Empty;
+ foreach (byte b in hash) { hexaHash += $"{b:x2}"; }
// I'm not sure if it could be longer, so just compare the same number as characters.
- return (signature == hexaHash.Substring(0, signature.Length)) ? true : false;
+ return signature == hexaHash.Substring(0, signature.Length);
}
///
@@ -230,14 +237,14 @@ public static bool IsJSON(this string value)
{
try
{
- if (value.StartsWith("["))
+ if (value.StartsWith("[", StringComparison.InvariantCultureIgnoreCase))
{
int position = 0;
- Json.JsonArray array = Json.JsonArray.Parse(value, ref position);
+ JsonArray.Parse(value, ref position);
}
else
{
- Json.JsonObject obj = Json.JsonObject.Parse(value);
+ JsonObject.Parse(value);
}
// If we get here, then all was well.
@@ -277,8 +284,7 @@ public static Guid ConvertToGuid(this string value)
/// The JSON result
public static string ToJson(this XmlDocument doc)
{
- string result = string.Empty;
- result = XmlToJsonConverter.XmlToJSON(doc);
+ var result = XmlToJsonConverter.XmlToJson(doc);
result = result.Replace(@"\", @"\\");
return result;
}
@@ -586,6 +592,11 @@ public static ProductFamily GetNodeContentAsProductFamily(this XmlNode node)
return result;
}
+ ///
+ /// Convert the xml node into a renewal line item
+ ///
+ /// The xml node containing renewal line item data
+ /// The renewal line item object, or null
public static RenewalLineItem GetNodeContentAsRenewalLineItem(this XmlNode node)
{
RenewalLineItem result = null;
@@ -596,6 +607,12 @@ public static RenewalLineItem GetNodeContentAsRenewalLineItem(this XmlNode node)
return result;
}
+ ///
+ /// Generic node convert method
+ ///
+ /// The type to convert to
+ /// The xml node to convert
+ /// The object if successful, null otherwise
public static T ConvertNode(this XmlNode node) where T : class
{
using (MemoryStream stm = new MemoryStream())
@@ -613,25 +630,37 @@ public static T ConvertNode(this XmlNode node) where T : class
}
}
+ ///
+ /// Convert the JsonObject to a list of Renewal Line Items
+ ///
+ /// The json object to convert
+ /// The key for this object array
+ /// The list result, or empty list otherwise
public static List GetJSONContentAsRenewalLineItems(this JsonObject obj, string key)
{
var renewalLineItems = new List();
var renewalLineItemsArray = obj[key] as JsonArray;
if (renewalLineItemsArray != null)
{
- foreach (JsonObject renewalLineItem in renewalLineItemsArray.Items)
+ foreach (var jsonValue in renewalLineItemsArray.Items)
{
+ var renewalLineItem = (JsonObject) jsonValue;
renewalLineItems.Add(new RenewalLineItem(renewalLineItem));
}
}
// Sanity check, should be equal.
- if (renewalLineItemsArray.Length != renewalLineItems.Count)
+ if (renewalLineItemsArray != null && renewalLineItemsArray.Length != renewalLineItems.Count)
{
throw new JsonParseException(string.Format("Unable to parse public signup pages ({0} != {1})", renewalLineItemsArray.Length, renewalLineItems.Count));
}
return renewalLineItems;
}
+ ///
+ /// Convert the XmlNode to a list of Renewal Line Items
+ ///
+ /// The xml node to convert
+ /// The list result, or empty list otherwise
public static List GetNodeContentAsRenewalLineItems(this XmlNode node)
{
var lineItems = new List