File size: 1,898 Bytes
429334c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | package httpdriver
import (
"context"
"errors"
"net/http"
appstripe "github.com/openmeterio/openmeter/openmeter/app/stripe"
"github.com/openmeterio/openmeter/openmeter/billing"
"github.com/openmeterio/openmeter/openmeter/customer"
"github.com/openmeterio/openmeter/openmeter/namespace/namespacedriver"
"github.com/openmeterio/openmeter/pkg/framework/commonhttp"
"github.com/openmeterio/openmeter/pkg/framework/transport/httptransport"
)
type Handler interface {
AppStripeHandler
}
type AppStripeHandler interface {
AppStripeWebhook() AppStripeWebhookHandler
UpdateStripeAPIKey() UpdateStripeAPIKeyHandler
CreateAppStripeCheckoutSession() CreateAppStripeCheckoutSessionHandler
// Customer Stripe Data handlers
GetCustomerStripeAppData() GetCustomerStripeAppDataHandler
UpsertCustomerStripeAppData() UpsertCustomerStripeAppDataHandler
// Customer Stripe Portal handlers
CreateStripeCustomerPortalSession() CreateStripeCustomerPortalSessionHandler
}
var _ Handler = (*handler)(nil)
type handler struct {
service appstripe.Service
billingService billing.Service
customerService customer.Service
namespaceDecoder namespacedriver.NamespaceDecoder
options []httptransport.HandlerOption
}
func (h *handler) resolveNamespace(ctx context.Context) (string, error) {
ns, ok := h.namespaceDecoder.GetNamespace(ctx)
if !ok {
return "", commonhttp.NewHTTPError(http.StatusInternalServerError, errors.New("internal server error"))
}
return ns, nil
}
func New(
namespaceDecoder namespacedriver.NamespaceDecoder,
service appstripe.Service,
billingService billing.Service,
customerService customer.Service,
options ...httptransport.HandlerOption,
) Handler {
return &handler{
service: service,
billingService: billingService,
customerService: customerService,
namespaceDecoder: namespaceDecoder,
options: options,
}
}
|