<commit_before>package main

import (
	"encoding/json"
	"fmt"
	"socialapi/workers/payment/paymentemail"
	"socialapi/workers/payment/paymentwebhook/webhookmodels"
	"socialapi/workers/payment/stripe"
)

func stripeInvoiceCreated(raw []byte, c *Controller) error {
	var invoice *webhookmodels.StripeInvoice

	err := json.Unmarshal(raw, &invoice)
	if err != nil {
		return err
	}

	err = stripe.InvoiceCreatedWebhook(invoice)
	if err != nil {
		return err
	}

	return sendInvoiceCreatedEmail(invoice, c)
}

func sendInvoiceCreatedEmail(req *webhookmodels.StripeInvoice, c *Controller) error {
	emailAddress, err := getEmailForCustomer(req.CustomerId)
	if err != nil {
		return err
	}

	if len(req.Lines.Data) < 0 {
		return fmt.Errorf(
			"Invoice: %s for %s has 0 line items", req.ID, req.CustomerId,
		)
	}

	opts := map[string]string{
		"amountDue": fmt.Sprintf("%v", req.AmountDue),
		"currency":  req.Currency,
		"planName":  req.Lines.Data[0].Plan.Name,
	}<commit_msg>paymentwebhook: fix bug where invoice emails had empty price<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"socialapi/workers/payment/paymentemail"
	"socialapi/workers/payment/paymentwebhook/webhookmodels"
	"socialapi/workers/payment/stripe"
)

func stripeInvoiceCreated(raw []byte, c *Controller) error {
	var invoice *webhookmodels.StripeInvoice

	err := json.Unmarshal(raw, &invoice)
	if err != nil {
		return err
	}

	err = stripe.InvoiceCreatedWebhook(invoice)
	if err != nil {
		return err
	}

	return sendInvoiceCreatedEmail(invoice, c)
}

func sendInvoiceCreatedEmail(req *webhookmodels.StripeInvoice, c *Controller) error {
	emailAddress, err := getEmailForCustomer(req.CustomerId)
	if err != nil {
		return err
	}

	if len(req.Lines.Data) < 0 {
		return fmt.Errorf(
			"Invoice: %s for %s has 0 line items", req.ID, req.CustomerId,
		)
	}

	opts := map[string]string{
		"price":    fmt.Sprintf("%v", req.AmountDue/100),
		"currency": req.Currency,
		"planName": req.Lines.Data[0].Plan.Name,
	}
{'fraction_non_alphanumeric': 0.12977867203219315, 'fraction_numerical': 0.004527162977867203, 'mean_word_length': 4.602816901408451, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6345837', 'n_tokens_mistral': 752, 'n_tokens_neox': 704, 'n_words': 154}