diff --git a/ecs.go b/ecs.go index 625bc26..b878d48 100644 --- a/ecs.go +++ b/ecs.go @@ -30,7 +30,7 @@ const ( func checkDeviceStatus(e *Envelope) { e.AddCustomType(Balance{ - Amount: 2018, + Amount: 2147483647, Currency: "POINTS", }) e.AddKVNode("ForceSyncTime", "0") @@ -107,6 +107,21 @@ func purchaseTitle(e *Envelope) { e.AddKVNode("ETickets", "00000000") } +func listPurchaseHistory(e *Envelope) { + e.AddCustomType(Transactions{ + TransactionId: "12345678", + Date: e.Timestamp(), + Type: "SERVICE", + TotalPaid: "7", + Currency: "POINTS", + ItemId: "17", + ItemPricing: "7", + Limits: LimitStruct(DR), + }) + + e.AddKVNode("ListResultTotalSize", "1") +} + // genServiceUrl returns a URL with the given service against a configured URL. // Given a baseUrl of example.com and genServiceUrl("ias", "IdentityAuthenticationSOAP"), // it would return http://ias.example.com/ias/services/ias/IdentityAuthenticationSOAP. diff --git a/main.go b/main.go index 62e402b..515bf8d 100644 --- a/main.go +++ b/main.go @@ -82,6 +82,7 @@ func main() { ecs.Authenticated("GetETickets", getETickets) ecs.Authenticated("PurchaseTitle", purchaseTitle) ecs.Unauthenticated("GetECConfig", getECConfig) + ecs.Authenticated("ListPurchaseHistory", listPurchaseHistory) } ias := r.HandleGroup("ias") diff --git a/structure.go b/structure.go index 72740e8..01df55f 100644 --- a/structure.go +++ b/structure.go @@ -98,12 +98,57 @@ type Balance struct { Currency string `xml:"Currency"` } +type LimitKinds int + +const ( + // PR is presumably "purchased". + PR LimitKinds = 0 + TR = 1 + DR = 2 + SR = 3 + LR = 4 + AT = 10000 +) + +// LimitStruct returns a Limits struct filled for the given kind. +func LimitStruct(kind LimitKinds) Limits { + names := map[LimitKinds]string{ + PR: "PR", + TR: "TR", + DR: "DR", + SR: "SR", + LR: "LR", + AT: "AT", + } + + return Limits{ + Limits: kind, + LimitKind: names[kind], + } +} + +// Limits represents a common XML structure for transaction information. +type Limits struct { + XMLName xml.Name `xml:"Limits"` + Limits LimitKinds `xml:"Limits"` + LimitKind string `xml:"LimitKind"` +} + // Transactions represents a common XML structure. type Transactions struct { - XMLName xml.Name `xml:"Transactions"` - TransactionId string `xml:"TransactionId"` - Date string `xml:"Date"` - Type string `xml:"Type"` + XMLName xml.Name `xml:"Transactions"` + TransactionId string `xml:"TransactionId"` + Date string `xml:"Date"` + Type string `xml:"Type"` + TotalPaid string `xml:"TotalPaid"` + Currency string `xml:"Currency"` + ItemId string `xml:"ItemId"` + ItemPricing string `xml:"ItemPricing"` + Limits Limits `xml:"Limits"` + TitleId string `xml:"TitleId,omitempty"` + ItemCode int `xml:"ItemCode,omitempty"` + ReferenceId int `xml:"ReferenceId,omitempty"` + ReferenceValue string `xml:"ReferenceValue,omitempty"` } // Tickets represents the format to inform a console of available titles for its consumption.