Skip to content

Commit

Permalink
Backport changes from 1998
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbrm committed Sep 26, 2023
1 parent 1234d9a commit 424d3f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions services/skus/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ type OrderItem struct {
IssuerConfig *IssuerConfig `json:"-" db:"-"`
}

func (x *OrderItem) IsLeo() bool {
if x == nil {
return false
}

return x.SKU == "brave-leo-premium"
}

// OrderNew represents a request to create an order in the database.
type OrderNew struct {
MerchantID string `db:"merchant_id"`
Expand Down
17 changes: 13 additions & 4 deletions services/skus/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ func (s *Service) CreateOrderFromRequest(ctx context.Context, req model.CreateOr

// TODO: we ultimately need to figure out how to provision numPerInterval and numIntervals
// on the order item instead of the order itself to support multiple orders with
// different time limited v2 issuers. For now leo sku needs 192 as num per interval
if orderItem.SKU == "brave-leo-premium" {
// different time limited v2 issuers.
// For now leo sku needs 192 as num per interval.
if orderItem.IsLeo() {
numPerInterval = 192 // 192 credentials per day for leo
}

Expand Down Expand Up @@ -1765,8 +1766,16 @@ func (s *Service) CreateOrder(ctx context.Context, req *model.CreateOrderRequest
}
}

if err := s.Datastore.AppendOrderMetadataInt(ctx, &order.ID, "numPerInterval", 2); err != nil {
return nil, fmt.Errorf("failed to update order metadata: %w", err)
// Backporting changes from https://github.com/brave-intl/bat-go/pull/1998.
{
numPerInterval := 2
if nitems == 1 && items[0].IsLeo() {
numPerInterval = 192
}

if err := s.Datastore.AppendOrderMetadataInt(ctx, &order.ID, "numPerInterval", numPerInterval); err != nil {
return nil, fmt.Errorf("failed to update order metadata: %w", err)
}
}

return order, nil
Expand Down

0 comments on commit 424d3f7

Please sign in to comment.