From e6ac8341f832ddca54af73dd87d5ce3b71c6e09d Mon Sep 17 00:00:00 2001 From: Vitalii Date: Tue, 13 Feb 2024 17:25:34 +0200 Subject: [PATCH] satellite/payments: conditionally add saved trees info to stripe invoices 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: https://github.com/storj/storj/issues/6694 Change-Id: Ifca1cc9ec8bc15b0a589040c951e1ff273aaf62b --- satellite/payments/stripe/service.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/satellite/payments/stripe/service.go b/satellite/payments/stripe/service.go index c350b976aec0..e44650046d22 100644 --- a/satellite/payments/stripe/service.go +++ b/satellite/payments/stripe/service.go @@ -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,