mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* Add webhook events * Properly set AutomaticTax * Use address element * 💄 * Update susbcription on address update * Try scroll modal * Fix * try fix modal scroll * Add toast notification * Add invalidBillingAddress column to d_b_stripe_customer * 💄 * 💄 * Fix * Try fix update * Address feedback
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package billingservice
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
v1 "github.com/gitpod-io/gitpod/usage-api/v1"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
//go:generate mockgen -source=client.go Interface -destination=./mock_billingservice/billingservice.go > mock_billingservice/billingservice.go
|
|
|
|
type Interface interface {
|
|
FinalizeInvoice(ctx context.Context, invoiceId string) error
|
|
CancelSubscription(ctx context.Context, subscriptionId string) error
|
|
OnChargeDispute(ctx context.Context, disputeID string) error
|
|
UpdateCustomerSubscriptionsTaxState(ctx context.Context, customerID string) error
|
|
}
|
|
|
|
type Client struct {
|
|
b v1.BillingServiceClient
|
|
}
|
|
|
|
func New(billingServiceAddress string) (*Client, error) {
|
|
conn, err := grpc.Dial(billingServiceAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to dial billing service gRPC server: %w", err)
|
|
}
|
|
|
|
return &Client{b: v1.NewBillingServiceClient(conn)}, nil
|
|
}
|
|
|
|
func (c *Client) FinalizeInvoice(ctx context.Context, invoiceId string) error {
|
|
_, err := c.b.FinalizeInvoice(ctx, &v1.FinalizeInvoiceRequest{InvoiceId: invoiceId})
|
|
if err != nil {
|
|
return fmt.Errorf("failed RPC to billing service: %s", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) CancelSubscription(ctx context.Context, subscriptionId string) error {
|
|
_, err := c.b.CancelSubscription(ctx, &v1.CancelSubscriptionRequest{SubscriptionId: subscriptionId})
|
|
if err != nil {
|
|
return fmt.Errorf("failed RPC to billing service: %s", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) OnChargeDispute(ctx context.Context, disputeID string) error {
|
|
_, err := c.b.OnChargeDispute(ctx, &v1.OnChargeDisputeRequest{
|
|
DisputeId: disputeID,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("failed RPC to billing service: %s", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) UpdateCustomerSubscriptionsTaxState(ctx context.Context, customerID string) error {
|
|
_, err := c.b.UpdateCustomerSubscriptionsTaxState(ctx, &v1.UpdateCustomerSubscriptionsTaxStateRequest{
|
|
CustomerId: customerID,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("failed RPC to billing service: %s", err)
|
|
}
|
|
|
|
return nil
|
|
}
|