@@ -102,6 +102,7 @@ func (a *adapter) UpsertInvoiceLines(ctx context.Context, inputIn billing.Upsert
102102 // Totals
103103 SetAmount (line .Totals .Amount ).
104104 SetChargesTotal (line .Totals .ChargesTotal ).
105+ SetCreditsTotal (line .Totals .CreditsTotal ).
105106 SetDiscountsTotal (line .Totals .DiscountsTotal ).
106107 SetTaxesTotal (line .Totals .TaxesTotal ).
107108 SetTaxesInclusiveTotal (line .Totals .TaxesInclusiveTotal ).
@@ -110,6 +111,10 @@ func (a *adapter) UpsertInvoiceLines(ctx context.Context, inputIn billing.Upsert
110111 // ExternalIDs
111112 SetNillableInvoicingAppExternalID (lo .EmptyableToPtr (line .ExternalIDs .Invoicing ))
112113
114+ if len (line .CreditsApplied ) > 0 {
115+ create = create .SetCreditsApplied (& line .CreditsApplied )
116+ }
117+
113118 if line .Subscription != nil {
114119 create = create .SetSubscriptionID (line .Subscription .SubscriptionID ).
115120 SetSubscriptionPhaseID (line .Subscription .PhaseID ).
@@ -144,6 +149,7 @@ func (a *adapter) UpsertInvoiceLines(ctx context.Context, inputIn billing.Upsert
144149 // TODO[OM-1416]: all nillable fileds must be listed explicitly
145150 UpdateQuantity ().
146151 UpdateChildUniqueReferenceID ().
152+ UpdateCreditsApplied ().
147153 Exec (ctx )
148154 },
149155 MarkDeleted : func (ctx context.Context , line * billing.StandardLine ) (* billing.StandardLine , error ) {
@@ -357,6 +363,7 @@ func (a *adapter) upsertDetailedLines(ctx context.Context, in detailedLineDiff)
357363 // Totals
358364 SetAmount (line .Totals .Amount ).
359365 SetChargesTotal (line .Totals .ChargesTotal ).
366+ SetCreditsTotal (line .Totals .CreditsTotal ).
360367 SetDiscountsTotal (line .Totals .DiscountsTotal ).
361368 SetTaxesTotal (line .Totals .TaxesTotal ).
362369 SetTaxesInclusiveTotal (line .Totals .TaxesInclusiveTotal ).
@@ -369,6 +376,10 @@ func (a *adapter) upsertDetailedLines(ctx context.Context, in detailedLineDiff)
369376 create = create .SetTaxConfig (* line .TaxConfig )
370377 }
371378
379+ if len (line .CreditsApplied ) > 0 {
380+ create = create .SetCreditsApplied (& line .CreditsApplied )
381+ }
382+
372383 create = create .SetQuantity (line .Quantity ).
373384 SetFlatFeeLineID (line .FeeLineConfigID ).
374385 SetNillableUsageBasedLineID (nil )
@@ -385,6 +396,7 @@ func (a *adapter) upsertDetailedLines(ctx context.Context, in detailedLineDiff)
385396 })).
386397 UpdateQuantity ().
387398 UpdateChildUniqueReferenceID ().
399+ UpdateCreditsApplied ().
388400 Exec (ctx )
389401 },
390402 MarkDeleted : func (ctx context.Context , line detailedLineWithParent ) (detailedLineWithParent , error ) {
@@ -469,6 +481,7 @@ func (a *adapter) upsertDetailedLinesV2(ctx context.Context, in detailedLineDiff
469481 // Totals
470482 SetAmount (line .Totals .Amount ).
471483 SetChargesTotal (line .Totals .ChargesTotal ).
484+ SetCreditsTotal (line .Totals .CreditsTotal ).
472485 SetDiscountsTotal (line .Totals .DiscountsTotal ).
473486 SetTaxesTotal (line .Totals .TaxesTotal ).
474487 SetTaxesInclusiveTotal (line .Totals .TaxesInclusiveTotal ).
@@ -478,6 +491,10 @@ func (a *adapter) upsertDetailedLinesV2(ctx context.Context, in detailedLineDiff
478491 // ExternalIDs
479492 SetNillableInvoicingAppExternalID (lo .EmptyableToPtr (line .ExternalIDs .Invoicing ))
480493
494+ if len (line .CreditsApplied ) > 0 {
495+ create = create .SetCreditsApplied (& line .CreditsApplied )
496+ }
497+
481498 if line .TaxConfig != nil {
482499 create = create .SetTaxConfig (* line .TaxConfig )
483500 }
@@ -586,7 +603,8 @@ func (a *adapter) upsertUsageBasedConfig(ctx context.Context, lineDiffs entitydi
586603 OnConflict (
587604 sql .ConflictColumns (billinginvoiceusagebasedlineconfig .FieldID ),
588605 sql .ResolveWithNewValues (),
589- ).Exec (ctx )
606+ ).
607+ Exec (ctx )
590608 },
591609 })
592610}
0 commit comments