def METHOD_NAME(team):
	team = frappe.get_doc("Team", team)
	stripe = get_stripe()
	res = stripe.Invoice.list(customer=team.stripe_customer_id)
	# remove the invoice with 0 amount
	invoices = [d for d in res["data"] if d["total"] != 0]
	# sort into ascending order of creation
	invoices.reverse()
	last_invoice_period_end = None
	for index, invoice in enumerate(invoices):
		i = frappe.new_doc("Invoice")
		i.team = team.name
		i.customer_name = frappe.utils.get_fullname(team.user)
		i.customer_email = team.user
		i.currency = team.currency
		i.period_start = datetime.fromtimestamp(invoice["period_start"])
		if index != 0:
			i.period_start = frappe.utils.add_days(i.period_start, 1)
		i.period_end = datetime.fromtimestamp(invoice["period_end"])
		i.stripe_invoice_id = invoice["id"]
		i.starting_balance = invoice["starting_balance"] / 100
		i.ending_balance = (invoice["ending_balance"] or 0) / 100
		i.amount_due = invoice["amount_due"] / 100
		i.amount_paid = invoice["amount_paid"] / 100
		i.stripe_invoice_url = invoice["hosted_invoice_url"]
		if invoice["status"] == "paid":
			i.payment_date = datetime.fromtimestamp(invoice["status_transitions"]["paid_at"])
			i.status = "Paid"
		else:
			i.status = "Overdue"
		i.payment_attempt_count = invoice.get("attempt_count")
		last_invoice_period_end = i.period_end
		i.save()
		i.reload()
		entries = frappe.db.get_all(
			"Payment Ledger Entry",
			filters={
				"creation": ("between", [i.period_start, i.period_end]),
				"purpose": "Site Consumption",
				"team": team.name,
				"docstatus": 1,
				"free_usage": False,
			},
		)
		for e in entries:
			ledger_entry = frappe.get_doc("Payment Ledger Entry", e.name)
			TeamInvoice(
				team, i.period_start.month, i.period_start.year
			).update_ledger_entry_in_invoice(ledger_entry, i)
		i.reload()
		if i.total == (invoice["total"] / 100):
			log(
				team.name,
				invoice=i.name,
				stripe_invoice=invoice["id"],
				message="total_match_success",
			)
			i.db_set("docstatus", 1)
		else:
			log(
				team.name,
				invoice=i.name,
				stripe_invoice=invoice["id"],
				message="total_match_failure ❌",
			)
			frappe.cache().sadd(total_match_failure_key, i.name)
	return last_invoice_period_end