server endpoint
This commit is contained in:
@@ -89,3 +89,18 @@ func (r InitiatePayment) Validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type InitiatePayments struct {
|
||||
PaymentBase `json:",inline"`
|
||||
QuoteRef string `json:"quoteRef,omitempty"`
|
||||
}
|
||||
|
||||
func (r InitiatePayments) Validate() error {
|
||||
if err := r.PaymentBase.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if r.QuoteRef == "" {
|
||||
return merrors.InvalidArgument("quoteRef is required", "quoteRef")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -57,9 +57,9 @@ type PaymentQuoteAggregate struct {
|
||||
}
|
||||
|
||||
type PaymentQuotes struct {
|
||||
QuoteRef string `json:"quoteRef,omitempty"`
|
||||
QuoteRef string `json:"quoteRef,omitempty"`
|
||||
Aggregate *PaymentQuoteAggregate `json:"aggregate,omitempty"`
|
||||
Quotes []PaymentQuote `json:"quotes,omitempty"`
|
||||
Quotes []PaymentQuote `json:"quotes,omitempty"`
|
||||
}
|
||||
|
||||
type Payment struct {
|
||||
@@ -81,6 +81,11 @@ type paymentQuotesResponse struct {
|
||||
Quote *PaymentQuotes `json:"quote"`
|
||||
}
|
||||
|
||||
type paymentsResponse struct {
|
||||
authResponse `json:",inline"`
|
||||
Payments []Payment `json:"payments"`
|
||||
}
|
||||
|
||||
type paymentResponse struct {
|
||||
authResponse `json:",inline"`
|
||||
Payment *Payment `json:"payment"`
|
||||
@@ -102,6 +107,14 @@ func PaymentQuotesResponse(logger mlogger.Logger, resp *orchestratorv1.QuotePaym
|
||||
})
|
||||
}
|
||||
|
||||
// Payments wraps a list of payments with refreshed access token.
|
||||
func PaymentsResponse(logger mlogger.Logger, payments []*orchestratorv1.Payment, token *TokenData) http.HandlerFunc {
|
||||
return response.Ok(logger, paymentsResponse{
|
||||
Payments: toPayments(payments),
|
||||
authResponse: authResponse{AccessToken: *token},
|
||||
})
|
||||
}
|
||||
|
||||
// Payment wraps a payment with refreshed access token.
|
||||
func PaymentResponse(logger mlogger.Logger, payment *orchestratorv1.Payment, token *TokenData) http.HandlerFunc {
|
||||
return response.Ok(logger, paymentResponse{
|
||||
@@ -216,6 +229,22 @@ func toPaymentQuotes(resp *orchestratorv1.QuotePaymentsResponse) *PaymentQuotes
|
||||
}
|
||||
}
|
||||
|
||||
func toPayments(items []*orchestratorv1.Payment) []Payment {
|
||||
if len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
result := make([]Payment, 0, len(items))
|
||||
for _, item := range items {
|
||||
if p := toPayment(item); p != nil {
|
||||
result = append(result, *p)
|
||||
}
|
||||
}
|
||||
if len(result) == 0 {
|
||||
return nil
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func toPayment(p *orchestratorv1.Payment) *Payment {
|
||||
if p == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user