INNER CODE UNIT · Go

findCustomerAndSubscription

theopenlane/core · cmd/catalog/main.go:627

func findCustomerAndSubscription(ctx context.Context, sc stripeClient, orgID string) (*stripe.Customer, *stripe.Subscription, error) {
	// Search for customer by name (which is the org ID)
	customers, err := sc.SearchCustomers(ctx, fmt.Sprintf("name:'%s'", orgID))
	if err != nil {
		return nil, nil, fmt.Errorf("search customers: %w", err)
	}

	if len(customers) == 0 {
		return nil, nil, nil
	}

	if len(customers) > 1 {
		return nil, nil, fmt.Errorf("%w: %s", ErrMultipleCustomersFound, orgID)
	}

	customer := customers[0]

	// Get active subscriptions for the customer

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…