fix: generate absolute URI when attaching links in invoice and payment
ci/woodpecker/push/woodpecker Pipeline was successful Details

notification

fixes: https://gitea.hostea.org/Hostea/dashboard/issues/37
fix-email-link
Aravinth Manivannan 2022-07-08 18:51:04 +05:30
parent ce0498b013
commit 2c8a5909cb
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
3 changed files with 12 additions and 2 deletions

View File

@ -14,7 +14,7 @@ Hostea Receipt - {{payment.date.month}}/{{payment.date.day}}/{{payment.date.year
To view the receipt online, please see the following link:
{% url 'billing.invoice.details' payment_public_id=payment.public_ref %}
{{link}}
We appreciate your business!

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from enum import Enum, unique
from urllib.parse import urlparse, urlunparse
from datetime import datetime, timedelta, timezone
from payments import get_payment_model, RedirectNeeded, PaymentStatus
@ -33,6 +34,10 @@ def __get_delta():
delta = now - timedelta(seconds=(60 * 60 * 24 * 30)) # one month
return delta
def get_invoice_link(payment: Payment):
invoice_link = reverse("billing.invoice.details", args=(payment.public_ref,))
parsed = urlparse(settings.PAYMENT_HOST)
return urlunparse((parsed.scheme, parsed.netloc, invoice_link, "", "", ""))
def payment_fullfilled(instance: Instance) -> bool:
delta = __get_delta()
@ -87,7 +92,8 @@ def generate_invoice(instance: Instance) -> Payment:
instance=instance,
)
invoice_link = reverse("billing.invoice.details", args=(payment.public_ref,))
invoice_link = get_invoice_link(payment=payment)
ctx = {
"username": instance.owned_by.username,
"link": invoice_link,
@ -102,6 +108,7 @@ def generate_invoice(instance: Instance) -> Payment:
email = instance.owned_by.email
sender = settings.DEFAULT_FROM_EMAIL
send_mail(
subject="[Hostea] An invoice is generated for your Hostea VM",
message=body,

View File

@ -33,6 +33,7 @@ from .utils import (
generate_invoice as generate_invoice_util,
GenerateInvoiceErrorCode,
GenerateInvoiceException,
get_invoice_link
)
@ -111,9 +112,11 @@ def payment_success(request, payment_public_id):
payment = get_object_or_404(
get_payment_model(), public_ref=payment_public_id, paid_by=request.user
)
ctx = {
"username": request.user.username,
"payment": payment,
"link": get_invoice_link(payment=payment),
}
body = render_to_string(