Skip to content

Commit

Permalink
satellite/payments: conditionally add saved trees info to stripe invo…
Browse files Browse the repository at this point in the history
…ices footer

Added logic to calculate saved trees count during invoice generation.
Added saved trees info to invoices footer if number of saved trees is more than 0.

Issue:
#6694

Change-Id: Ifca1cc9ec8bc15b0a589040c951e1ff273aaf62b
  • Loading branch information
VitaliiShpital authored and Storj Robot committed Feb 21, 2024
1 parent 478d67e commit e6ac834
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions satellite/payments/stripe/service.go
Expand Up @@ -1145,12 +1145,25 @@ func (service *Service) createInvoice(ctx context.Context, cusID string, period
}

whitePaperLink := "https://www.storj.io/documents/storj-sustainability-whitepaper.pdf"
footer = stripe.String(fmt.Sprintf(
footerMsg := fmt.Sprintf(
"Estimated Storj Emissions: %.3f kgCO2e\nEstimated Hyperscaler Emissions: %.3f kgCO2e\nMore information on estimates: %s",
impact.EstimatedKgCO2eStorj,
impact.EstimatedKgCO2eHyperscaler,
whitePaperLink,
))
)

savedValue := impact.EstimatedKgCO2eHyperscaler - impact.EstimatedKgCO2eStorj
if savedValue < 0 {
savedValue = 0
}

savedTrees := service.emission.CalculateSavedTrees(savedValue)
if savedTrees > 0 {
treesCalcLink := "https://www.epa.gov/energy/greenhouse-gases-equivalencies-calculator-calculations-and-references#seedlings"
footerMsg += fmt.Sprintf("\nEstimated Trees Saved: %d\nMore information on trees saved: %s", savedTrees, treesCalcLink)
}

footer = stripe.String(footerMsg)
} else {
itemsIter := service.stripeClient.InvoiceItems().List(&stripe.InvoiceItemListParams{
Customer: &cusID,
Expand Down

0 comments on commit e6ac834

Please sign in to comment.