Skip to content

Instantly share code, notes, and snippets.

@henzard
Last active August 29, 2015 14:16
Show Gist options
  • Save henzard/3816437853c91758e145 to your computer and use it in GitHub Desktop.
Save henzard/3816437853c91758e145 to your computer and use it in GitHub Desktop.
Imports Xero.Api.Infrastructure.Interfaces
Imports System.Security.Cryptography.X509Certificates
Imports Xero.Api.Infrastructure.OAuth.Signing
Imports Xero.Api.Infrastructure.OAuth
Imports Xero.Api.Core
Public Class clsXeroConn
Public _api As XeroCoreApi
Public Sub New(ByVal certificateFile As String, ByVal xeroKey As String, ByVal xeroPass As String, ByVal userString As String)
Dim _privateAuth As New PrivateAuthenticator(certificateFile, xeroPass)
Dim _publicAuth As New PublicAuthenticator(certificateFile, xeroPass)
Dim _cons As IConsumer = New Consumer(xeroKey, xeroPass)
Dim _usr As New User(userString)
_api = New XeroCoreApi("https://api.xero.com", _privateAuth, _cons, _usr)
End Sub
ReadOnly Property Api As XeroCoreApi
Get
Return _api
End Get
End Property
End Class
Public Structure AUTaxType
Const OUTPUT = "OUTPUT"
Const INPUT = "INPUT"
Const CAPEXINPUT = "CAPEXINPUT"
Const EXEMPTEXPORT = "EXEMPTEXPORT"
Const EXEMPTEXPENSES = "EXEMPTEXPENSES"
Const EXEMPTCAPITAL = "EXEMPTCAPITAL"
Const EXEMPTOUTPUT = "EXEMPTOUTPUT"
Const INPUTTAXED = "INPUTTAXED"
Const BASEXCLUDED = "BASEXCLUDED"
Const GSTONCAPIMPORTS = "GSTONCAPIMPORTS"
Const GSTONIMPORTS = "GSTONIMPORTS"
End Structure
Public Structure GlobalTaxType
Const OUTPUT = "OUTPUT"
Const INPUT = "INPUT"
Const NONE = "NONE"
Const GSTONIMPORTS = "GSTONIMPORTS"
End Structure
Public Structure NZTaxType
Const INPUT2 = "INPUT2"
Const NONE = "NONE"
Const ZERORATED = "ZERORATED"
Const OUTPUT2 = "OUTPUT2"
Const GSTONIMPORTS = "GSTONIMPORTS"
End Structure
Public Structure UKTaxType
Const CAPEXINPUT = "CAPEXINPUT"
Const CAPEXINPUT2 = "CAPEXINPUT2"
Const CAPEXOUTPUT = "CAPEXOUTPUT"
Const CAPEXOUTPUT2 = "CAPEXOUTPUT2"
Const CAPEXSRINPUT = "CAPEXSRINPUT"
Const CAPEXSROUTPUT = "CAPEXSROUTPUT"
Const ECZRINPUT = "ECZRINPUT"
Const ECZROUTPUT = "ECZROUTPUT"
Const ECZROUTPUTSERVICES = "ECZROUTPUTSERVICES"
Const EXEMPTINPUT = "EXEMPTINPUT"
Const GSTONIMPORTS = "GSTONIMPORTS"
Const INPUT2 = "INPUT2"
Const NONE = "NONE"
Const OUTPUT2 = "OUTPUT2"
Const RRINPUT = "RRINPUT"
Const RROUTPUT = "RROUTPUT"
Const SRINPUT = "SRINPUT"
Const SROUTPUT = "SROUTPUT"
Const ZERORATEDINPUT = "ZERORATEDINPUT"
Const ZERORATEDOUTPUT = "ZERORATEDOUTPUT"
End Structure
Public Structure USTaxType
Const OUTPUT = "OUTPUT"
Const INPUT = "INPUT"
Const NONE = "NONE"
Const GSTONIMPORTS = "GSTONIMPORTS"
End Structure
Public Class User
Implements IUser
Private _userName As String = ""
Public Sub New(userName As String)
_userName = userName
End Sub
Property Name As String Implements IUser.Name
Get
Return _userName
End Get
Set(value As String)
_userName = value
End Set
End Property
End Class
Public Class Consumer
Implements IConsumer
Dim _consumerKey As String
Dim _consumerSecret As String
Public Sub New(ByRef consumerKey As String, ByRef consumerSecret As String)
_consumerKey = consumerKey
_consumerSecret = consumerSecret
End Sub
ReadOnly Property ConsumerKey() As String Implements IConsumer.ConsumerKey
Get
Return _consumerKey
End Get
End Property
ReadOnly Property ConsumerSecret() As String Implements IConsumer.ConsumerSecret
Get
Return _consumerSecret
End Get
End Property
End Class
Public Class PublicAuthenticator
Implements ICertificateAuthenticator
ReadOnly _certificate As X509Certificate2
Private m_User As IUser
Public Sub New(ByRef certificatePath As String, ByRef XeroPass As String)
'_certificate.Import();
_certificate = New X509Certificate2(certificatePath, XeroPass)
End Sub
Public Function GetSignature(consumer As IConsumer, user As IUser, uri As Uri, verb As String, consumer1 As IConsumer) As String Implements IAuthenticator.GetSignature
Return New RsaSha1Signer().CreateSignature(_certificate, New Token() With { _
.ConsumerKey = consumer.ConsumerKey, _
.ConsumerSecret = consumer.ConsumerSecret _
}, uri, verb)
End Function
Public Function GetToken(consumer As IConsumer, user As IUser) As IToken Implements IAuthenticator.GetToken
Return Nothing
End Function
Public Property User As IUser Implements IAuthenticator.User
Get
Return m_User
End Get
Set(value As IUser)
m_User = value
End Set
End Property
Public ReadOnly Property Certificate As X509Certificate Implements ICertificateAuthenticator.Certificate
Get
Return _certificate
End Get
End Property
End Class
Public Class PrivateAuthenticator
Implements ICertificateAuthenticator
ReadOnly _certificate As X509Certificate2
Public Sub New(ByRef certificatePath As String, ByRef XeroPass As String)
'_certificate.Import();
_certificate = New X509Certificate2(certificatePath, XeroPass)
End Sub
Public Sub New(certificate As X509Certificate2)
_certificate = certificate
End Sub
Function GetSignature(consumer As IConsumer, user As IUser, uri As Uri, verb As String, consumer1 As IConsumer) As String Implements IAuthenticator.GetSignature
Return New RsaSha1Signer().CreateSignature(_certificate, New Token() With { _
.ConsumerKey = consumer.ConsumerKey, _
.ConsumerSecret = consumer.ConsumerSecret _
}, uri, verb)
End Function
ReadOnly Property Certificate() As X509Certificate Implements ICertificateAuthenticator.Certificate
Get
Return _certificate
End Get
End Property
Function GetToken(consumer As IConsumer, user As IUser) As IToken Implements IAuthenticator.GetToken
Return Nothing
End Function
Public Property User() As IUser Implements ICertificateAuthenticator.User
Get
Return m_User
End Get
Set(value As IUser)
m_User = value
End Set
End Property
Private m_User As IUser
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment