(ctx context.Context, org *database.Organization)
| 1215 | } |
| 1216 | |
| 1217 | func (s *Server) planChangeValidationChecks(ctx context.Context, org *database.Organization) error { |
| 1218 | // not a trial plan, check for a payment method and a valid billing address |
| 1219 | var validationErrs []string |
| 1220 | pc, err := s.admin.PaymentProvider.FindCustomer(ctx, org.PaymentCustomerID) |
| 1221 | if err != nil { |
| 1222 | return err |
| 1223 | } |
| 1224 | if !pc.HasPaymentMethod { |
| 1225 | validationErrs = append(validationErrs, "no payment method found") |
| 1226 | } |
| 1227 | |
| 1228 | if !pc.HasBillableAddress { |
| 1229 | validationErrs = append(validationErrs, "no billing address found") |
| 1230 | } |
| 1231 | |
| 1232 | be, err := s.admin.DB.FindBillingIssueByTypeForOrg(ctx, org.ID, database.BillingIssueTypePaymentFailed) |
| 1233 | if err != nil { |
| 1234 | if !errors.Is(err, database.ErrNotFound) { |
| 1235 | return err |
| 1236 | } |
| 1237 | } |
| 1238 | if be != nil { |
| 1239 | validationErrs = append(validationErrs, "a previous payment is due") |
| 1240 | } |
| 1241 | |
| 1242 | if len(validationErrs) > 0 { |
| 1243 | return status.Errorf(codes.FailedPrecondition, "please fix following by visiting billing portal: %s", strings.Join(validationErrs, ", ")) |
| 1244 | } |
| 1245 | |
| 1246 | return nil |
| 1247 | } |
| 1248 | |
| 1249 | func (s *Server) getSubscriptionAndUpdateOrg(ctx context.Context, org *database.Organization) (*billing.Subscription, *database.Organization, error) { |
| 1250 | sub, err := s.admin.Biller.GetActiveSubscription(ctx, org.BillingCustomerID) |
no test coverage detected