extended fields #438
@@ -0,0 +1,36 @@
|
|||||||
|
package shared
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// NetworkRegistry provides network configuration lookup by name.
|
||||||
|
type NetworkRegistry struct {
|
||||||
|
networks map[string]Network
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewNetworkRegistry creates a NetworkRegistry from a slice of network configs.
|
||||||
|
func NewNetworkRegistry(networks []Network) *NetworkRegistry {
|
||||||
|
m := make(map[string]Network, len(networks))
|
||||||
|
for _, n := range networks {
|
||||||
|
if n.Name.IsValid() {
|
||||||
|
m[strings.ToLower(n.Name.String())] = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &NetworkRegistry{networks: m}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Network returns the configuration for the named network.
|
||||||
|
func (r *NetworkRegistry) Network(name string) (Network, bool) {
|
||||||
|
if r == nil || r.networks == nil {
|
||||||
|
return Network{}, false
|
||||||
|
}
|
||||||
|
n, ok := r.networks[strings.ToLower(strings.TrimSpace(name))]
|
||||||
|
return n, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// Networks returns all configured networks.
|
||||||
|
func (r *NetworkRegistry) Networks() map[string]Network {
|
||||||
|
if r == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return r.networks
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package sresponse
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/tech/sendico/pkg/api/http/response"
|
"github.com/tech/sendico/pkg/api/http/response"
|
||||||
"github.com/tech/sendico/pkg/mlogger"
|
"github.com/tech/sendico/pkg/mlogger"
|
||||||
@@ -63,6 +64,8 @@ type Payment struct {
|
|||||||
FailureCode string `json:"failureCode,omitempty"`
|
FailureCode string `json:"failureCode,omitempty"`
|
||||||
FailureReason string `json:"failureReason,omitempty"`
|
FailureReason string `json:"failureReason,omitempty"`
|
||||||
LastQuote *PaymentQuote `json:"lastQuote,omitempty"`
|
LastQuote *PaymentQuote `json:"lastQuote,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"createdAt,omitempty"`
|
||||||
|
Meta map[string]string `json:"meta,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type paymentQuoteResponse struct {
|
type paymentQuoteResponse struct {
|
||||||
@@ -251,5 +254,7 @@ func toPayment(p *orchestratorv1.Payment) *Payment {
|
|||||||
FailureCode: p.GetFailureCode().String(),
|
FailureCode: p.GetFailureCode().String(),
|
||||||
FailureReason: p.GetFailureReason(),
|
FailureReason: p.GetFailureReason(),
|
||||||
LastQuote: toPaymentQuote(p.GetLastQuote()),
|
LastQuote: toPaymentQuote(p.GetLastQuote()),
|
||||||
|
CreatedAt: p.GetCreatedAt().AsTime(),
|
||||||
|
Meta: p.GetMetadata(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user