Invoice is sent before payment #49

Closed
opened 2022-07-25 15:13:27 -04:00 by dachary · 12 comments

The invoice is sent before the user paid. An invoice can only be sent after the user paid. The URL is incomplete, something must be missing in the template.

Hello dachary!

An invoice is generated for your Hostea VM aoisufdao.

- Configuration: s1-2
- Invoice generated on: 7/25/2022
- Total Amount: 10.0 EUR

To pay, please click the link below:

/billing/invoice/payment/6TjVrglktZ3pz2YY8IFWbBPVN54w9E4w/

Cheers,
Hostea team
The invoice is sent **before** the user paid. An invoice can only be sent **after** the user paid. The URL is incomplete, something must be missing in the template. ``` Hello dachary! An invoice is generated for your Hostea VM aoisufdao. - Configuration: s1-2 - Invoice generated on: 7/25/2022 - Total Amount: 10.0 EUR To pay, please click the link below: /billing/invoice/payment/6TjVrglktZ3pz2YY8IFWbBPVN54w9E4w/ Cheers, Hostea team ```
realaravinth added spent time 2022-07-26 04:54:50 -04:00
40min

This is the monthly payment notification. “Invoice generated” is probably misleading, but it is similar to Digital Ocean phrasing. I'd be happy to replace it, if you have something better.

The URL is incomplete, something must be missing in the template

I couldn't reproduce this issue locally. As mentioned, this is the monthly payment notification. Here's the email that was sent when ran locally:

Hello atm!

An invoice is generated for your Hostea VM asdfasdf.

- Configuration: s1-2
- Invoice generated on: 7/26/2022
- Total Amount: 10.0 EUR

To pay, please click the link below:

http://localhost:8000/billing/invoice/payment/AjI6TOWRmNGwvpNs2ZLmC84Bsqe0lLcp/

Cheers,
Hostea team

So I'm guessing this has something to do with configuration

This is the monthly payment notification. “Invoice generated” is probably misleading, but it is similar to Digital Ocean phrasing. I'd be happy to replace it, if you have something better. > The URL is incomplete, something must be missing in the template I couldn't reproduce this issue locally. As mentioned, this is the monthly payment notification. Here's the email that was sent when ran locally: ``` Hello atm! An invoice is generated for your Hostea VM asdfasdf. - Configuration: s1-2 - Invoice generated on: 7/26/2022 - Total Amount: 10.0 EUR To pay, please click the link below: http://localhost:8000/billing/invoice/payment/AjI6TOWRmNGwvpNs2ZLmC84Bsqe0lLcp/ Cheers, Hostea team ``` So I'm guessing this has something to do with configuration

I was wrong in assuming that this is a subscription renewal email, seems like a new VM payment notification.

I was wrong in assuming that this is a subscription renewal email, seems like a new VM payment notification.

Behaviour is limited to production instance.

Email from local instance when I created a new VM:

Hello atm!

An invoice is generated for your Hostea VM demo-oidc.

- Configuration: s1-2
- Invoice generated on: 7/26/2022
- Total Amount: 10.0 EUR

To pay, please click the link below:

http://localhost:8000/billing/invoice/payment/5faLFJnAYsdhfQKN50aBkHpRsdu70rbr/

Cheers,
Hostea team

Email from production instance when I created a new VM:

Hello realaravinth!

An invoice is generated for your Hostea VM realaravinth-test.

- Configuration: s1-2
- Invoice generated on: 7/26/2022
- Total Amount: 10.0 EUR

To pay, please click the link below:

/billing/invoice/payment/nF25TC7C3s7FRx3YImyIXPZlE1AyYEkq/

Cheers,
Hostea team
Behaviour is limited to production instance. Email from local instance when I created a new VM: ``` Hello atm! An invoice is generated for your Hostea VM demo-oidc. - Configuration: s1-2 - Invoice generated on: 7/26/2022 - Total Amount: 10.0 EUR To pay, please click the link below: http://localhost:8000/billing/invoice/payment/5faLFJnAYsdhfQKN50aBkHpRsdu70rbr/ Cheers, Hostea team ``` Email from production instance when I created a new VM: ``` Hello realaravinth! An invoice is generated for your Hostea VM realaravinth-test. - Configuration: s1-2 - Invoice generated on: 7/26/2022 - Total Amount: 10.0 EUR To pay, please click the link below: /billing/invoice/payment/nF25TC7C3s7FRx3YImyIXPZlE1AyYEkq/ Cheers, Hostea team ```

Aaaand found the error 🎉:

(venv)  () debian@gitea-host:/srv/hosteadashboard/dashboard$ python manage.py shell
Found local_settings
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.conf import settings
>>> settings.PAYMENT_HOST
'hosteadashboard.hostea.org'
>>> from billing.utils import get_invoice_link
>>> from billing.models import Payment
>>> get_invoice_link(Payment.objects.get(instance_name="realaravinth-test"))
'/billing/invoice/payment/nF25TC7C3s7FRx3YImyIXPZlE1AyYEkq/' # should return absolute URL but it didn't

billing.utils.get_invoice_link is the utility function used to generated invoice links. It is dependant on settings.PAYMENT_HOST to generate absolute URLs.

I was under the impression that urllib.parse.urlparse from the stdlib will fail when a non-URL is passed but apparently that is not the case:

>>> urlparse(settings.PAYMENT_HOST)
ParseResult(scheme='', netloc='', path='hosteadashboard.hostea.org', params='', query='', fragment='')

note: settings.PAYMENT_HOST=hosteadashboard.hostea.org in production

I thought about defaulting to http when I wrote URL generation but that didn't seem right then. I also understand that PAYMENT_HOST should simply be a hostname and not a valid URL.

I see three options:

  1. Default to using http + settings.PAYMENT_HOST
  2. Introduce new parameter to accept dashboard URL
  3. Make modifications in enough to set an absolute URL for settings.PAYMENT_HOST
Aaaand found the error 🎉: ```python (venv) (eǝ) debian@gitea-host:/srv/hosteadashboard/dashboard$ python manage.py shell Found local_settings Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.conf import settings >>> settings.PAYMENT_HOST 'hosteadashboard.hostea.org' >>> from billing.utils import get_invoice_link >>> from billing.models import Payment >>> get_invoice_link(Payment.objects.get(instance_name="realaravinth-test")) '/billing/invoice/payment/nF25TC7C3s7FRx3YImyIXPZlE1AyYEkq/' # should return absolute URL but it didn't ``` [`billing.utils.get_invoice_link`](https://gitea.hostea.org/Hostea/dashboard/src/commit/6c31555a5253592dbbaea73e3775cf97f23e71b9/billing/utils.py#L38) is the utility function used to generated invoice links. It is dependant on `settings.PAYMENT_HOST` to generate absolute URLs. I was under the impression that `urllib.parse.urlparse` from the stdlib will fail when a non-URL is passed but apparently that is not the case: ```python >>> urlparse(settings.PAYMENT_HOST) ParseResult(scheme='', netloc='', path='hosteadashboard.hostea.org', params='', query='', fragment='') ``` **note: `settings.PAYMENT_HOST=hosteadashboard.hostea.org` in production** I thought about defaulting to `http` when I wrote URL generation but that didn't seem right then. I also understand that `PAYMENT_HOST` should simply be a hostname and not a valid URL. I see three options: 1. Default to using `http` + `settings.PAYMENT_HOST` 2. Introduce new parameter to accept dashboard URL 3. Make modifications in enough to set an absolute URL for `settings.PAYMENT_HOST`
realaravinth added spent time 2022-07-26 06:49:20 -04:00
2h
Poster
Owner

Make modifications in enough to set an absolute URL for settings.PAYMENT_HOST

That's the most reasonable course of action. This one is on me: good sleuth work on your part.

> Make modifications in enough to set an absolute URL for settings.PAYMENT_HOST That's the most reasonable course of action. This one is on me: good sleuth work on your part.
Poster
Owner
https://lab.enough.community/main/infrastructure/-/merge_requests/574
Poster
Owner

seems like a new VM payment notification.

Right. You can reproduce the problem by going to the current dashboard and trying to create a new VM. The invoice will be sent to you before you get a chance to pay.

> seems like a new VM payment notification. Right. You can reproduce the problem by going to the current dashboard and trying to create a new VM. The invoice will be sent to you before you get a chance to pay.

seems like a new VM payment notification.

Right. You can reproduce the problem by going to the current dashboard and trying to create a new VM. The invoice will be sent to you before you get a chance to pay.

This is the intended behavoir, this email is to notify the user that they have a pending invoince.

> > seems like a new VM payment notification. > > Right. You can reproduce the problem by going to the current dashboard and trying to create a new VM. The invoice will be sent to you before you get a chance to pay. This is the intended behavoir, this email is to notify the user that they have a pending invoince.
Poster
Owner

https://en.wikipedia.org/wiki/Invoice reads

An invoice, bill or tab is a commercial document issued by a seller to a buyer relating to a sale transaction and indicating the products, quantities, and agreed-upon prices for products or services the seller had provided the buyer.

It cannot be issued before the sale happened, i.e. before payment is received.

https://en.wikipedia.org/wiki/Invoice reads > An invoice, bill or tab is a commercial document issued by a seller to a buyer relating to a sale transaction and indicating the products, quantities, and agreed-upon prices for products or services the seller had provided the buyer. It cannot be issued **before** the sale happened, i.e. before payment is received.

Alright, so what do we call the payment notification?

Alright, so what do we call the payment notification?
Poster
Owner

I think you can just skip it entirely. There is no commitment and no action whatsoever until payment is made anyway.

I think you can just skip it entirely. There is no commitment and no action whatsoever until payment is made anyway.
Poster
Owner

An invoice sent in advance is called a pro forma. It is common in traditional accounting but unheard of in online transactions.

An invoice sent in advance is called a [pro forma](https://en.wiktionary.org/wiki/pro_forma#Adjective). It is common in traditional accounting but unheard of in online transactions.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Total Time Spent: 2 hours 40 minutes
realaravinth
2 hours 40 minutes
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Hostea/dashboard#49
There is no content yet.