forked from syntaxtree/SyntaxTree.FastSpring.Api
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 31b9287
Showing
15 changed files
with
547 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
bin | ||
obj | ||
*.suo | ||
*.user | ||
*.pidb | ||
*.userprefs | ||
*.xml | ||
*.nupkg | ||
**/test-results/* | ||
*Resharper* | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public sealed class Address | ||
{ | ||
[XmlElement("addressLine1")] | ||
public string FirstLine { get; set; } | ||
|
||
[XmlElement("addressLine2")] | ||
public string SecondLine { get; set; } | ||
|
||
[XmlElement("city")] | ||
public string City { get; set; } | ||
|
||
[XmlElement("region")] | ||
public string Region { get; set; } | ||
|
||
[XmlElement("regionCustom")] | ||
public string RegionCustom { get; set; } | ||
|
||
[XmlElement("postalCode")] | ||
public string PostalCode { get; set; } | ||
|
||
[XmlElement("country")] | ||
public string Country { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Net; | ||
using System.Text; | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public sealed class CompanyStore | ||
{ | ||
private readonly StoreCredential _credential; | ||
|
||
private CompanyStore(StoreCredential credential) | ||
{ | ||
_credential = credential; | ||
} | ||
|
||
public Order Order(string reference) | ||
{ | ||
if (reference == null) | ||
throw new ArgumentNullException("reference"); | ||
if (reference.Length == 0) | ||
throw new ArgumentException("Reference is empty.", "reference"); | ||
|
||
var request = Request("GET", "/order/" + reference); | ||
var response = request.GetResponse(); | ||
|
||
if (response == null) | ||
throw new InvalidOperationException("No response."); | ||
|
||
var responseStream = response.GetResponseStream(); | ||
if (responseStream == null) | ||
throw new InvalidOperationException("Unable to acquire response stream."); | ||
|
||
return (Order) new XmlSerializer(typeof (Order)).Deserialize(responseStream); | ||
} | ||
|
||
private WebRequest Request(string method, string uri) | ||
{ | ||
var request = WebRequest.Create(StoreUri(uri)); | ||
request.ContentType = "application/xml"; | ||
request.Method = method; | ||
request.Headers["Authorization"] = AuthorizationHeader(); | ||
return request; | ||
} | ||
|
||
private string AuthorizationHeader() | ||
{ | ||
return "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(_credential.Username + ":" + _credential.Password)); | ||
} | ||
|
||
private string StoreUri(string uri) | ||
{ | ||
return "https://api.fastspring.com/company/" + _credential.Company + uri; | ||
} | ||
|
||
public static CompanyStore StoreFor(StoreCredential credential) | ||
{ | ||
if (credential == null) | ||
throw new ArgumentNullException("credential"); | ||
|
||
return new CompanyStore(credential); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public sealed class Contact | ||
{ | ||
[XmlElement("firstName")] | ||
public string FirstName { get; set; } | ||
|
||
[XmlElement("lastName")] | ||
public string LastName { get; set; } | ||
|
||
[XmlElement("company")] | ||
public string Company { get; set; } | ||
|
||
[XmlElement("email")] | ||
public string Email { get; set; } | ||
|
||
[XmlElement("phoneNumber")] | ||
public string PhoneNumber { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
[XmlRoot(ElementName = "order", IsNullable = false, Namespace = "")] | ||
public sealed class Order | ||
{ | ||
[XmlElement("reference")] | ||
public string Reference { get; set; } | ||
|
||
[XmlElement("status")] | ||
public Status Status { get; set; } | ||
|
||
[XmlElement("statusChanged")] | ||
public DateTime StatusChanged { get; set; } | ||
|
||
[XmlElement("test")] | ||
public bool IsTest { get; set; } | ||
|
||
[XmlElement("due")] | ||
public DateTime Due { get; set; } | ||
|
||
[XmlElement("currency")] | ||
public string Currency { get; set; } | ||
|
||
[XmlElement("referrer")] | ||
public string Referrer { get; set; } | ||
|
||
[XmlElement("originIp")] | ||
public string OriginIP{ get; set; } | ||
|
||
[XmlElement("total")] | ||
public double Total { get; set; } | ||
|
||
[XmlElement("tax")] | ||
public double Tax { get; set; } | ||
|
||
[XmlElement("shipping")] | ||
public double Shipping { get; set; } | ||
|
||
[XmlElement("sourceName")] | ||
public string SourceName { get; set; } | ||
|
||
[XmlElement("sourceKey")] | ||
public string SourceKey { get; set; } | ||
|
||
[XmlElement("sourceCampaign")] | ||
public string SourceCampaign { get; set; } | ||
|
||
[XmlElement("customer")] | ||
public Contact Customer { get; set; } | ||
|
||
[XmlElement("purchaser")] | ||
public Contact Purchaser { get; set; } | ||
|
||
[XmlElement("address")] | ||
public Address Address { get; set; } | ||
|
||
[XmlArray("orderItems")] | ||
[XmlArrayItem("orderItem")] | ||
public OrderItem[] Items { get; set; } | ||
|
||
[XmlArray("payments")] | ||
[XmlArrayItem("payment")] | ||
public Payment[] Payments { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public sealed class OrderItem | ||
{ | ||
[XmlElement("productDisplay")] | ||
public string ProductDisplay { get; set; } | ||
|
||
[XmlElement("productName")] | ||
public string ProductName { get; set; } | ||
|
||
[XmlElement("quantity")] | ||
public int Quantity { get; set; } | ||
|
||
[XmlElement("subscriptionReference")] | ||
public string SubscriptionReference { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public sealed class Payment | ||
{ | ||
[XmlElement("status")] | ||
public Status Status { get; set; } | ||
|
||
[XmlElement("statusChanged")] | ||
public DateTime StatusChanged { get; set; } | ||
|
||
[XmlElement("methodType")] | ||
public PaymentMethod Method { get; set; } | ||
|
||
[XmlElement("declinedReason")] | ||
public PaymentDeclinationReason DeclinationReason { get; set; } | ||
|
||
[XmlElement("currency")] | ||
public string Currency { get; set; } | ||
|
||
[XmlElement("total")] | ||
public double Total { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public enum PaymentDeclinationReason | ||
{ | ||
[XmlEnum("")] | ||
None, | ||
|
||
[XmlEnum("internal-error")] | ||
InternalError, | ||
|
||
[XmlEnum("unsupported-country")] | ||
UnsupportedCountry, | ||
|
||
[XmlEnum("expired-card")] | ||
ExpiredCard, | ||
|
||
[XmlEnum("declined")] | ||
Declined, | ||
|
||
[XmlEnum("risk")] | ||
Risk, | ||
|
||
[XmlEnum("processor-risk")] | ||
ProcessorRisk, | ||
|
||
[XmlEnum("connection")] | ||
Connection, | ||
|
||
[XmlEnum("unknown")] | ||
Unknown, | ||
|
||
[XmlEnum("cc-address-verification")] | ||
CcAddressVerification, | ||
|
||
[XmlEnum("cc-cvv")] | ||
CcCvv, | ||
|
||
[XmlEnum("voice-auth")] | ||
VoiceAuth, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace SyntaxTree.FastSpring.Api | ||
{ | ||
public enum PaymentMethod | ||
{ | ||
[XmlEnum("paypal")] | ||
Paypal, | ||
|
||
[XmlEnum("creditcard")] | ||
CreditCard, | ||
|
||
[XmlEnum("test")] | ||
Test, | ||
|
||
[XmlEnum("bank")] | ||
Bank, | ||
|
||
[XmlEnum("check")] | ||
Check, | ||
|
||
[XmlEnum("purchase-order")] | ||
PurchaseOrder, | ||
|
||
[XmlEnum("free")] | ||
Free, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SyntaxTree.FastSpring.Api")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("SyntaxTree.FastSpring.Api")] | ||
[assembly: AssemblyCopyright("Copyright © SyntaxTree 2012")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("d50dbcd1-b437-47d8-a494-74043d75f6a4")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.