Commit Graph

408 Commits

Author SHA1 Message Date
jordi fita mas 746aa013d3 Group ACSI options and allow for usage in different groups
It turns out that, **this time**, at least, the way to compute the
discount is not by “the more expensive”, but “the more expensive _in a
given group_”.

However, there are a couple of options, such as motorhome, that can be
in different groups but only must be used once.
2024-04-03 12:56:52 +02:00
jordi fita mas b291ac34fc Tag database with version 7 2024-04-03 09:34:36 +02:00
jordi fita mas 6c18529317 Take only into account the more expensive option when computing ACSI
Apparently, this is how it is done, now.
2024-03-25 17:47:43 +01:00
jordi fita mas 75c94a95f5 Remove a paste error from camper.css 2024-03-25 16:43:58 +01:00
jordi fita mas 72f8a329d2 Use pre-authorization to accept payment, rather than charge
Customer wants this because the booking is not automatically created,
thus it is possible to overbook.  They want to accept the payment of
those that they can actually book.
2024-03-24 22:06:59 +01:00
jordi fita mas d71d974abd Change demo’s email address
Since this address is used to send notifications when a new payment is
received, is quite important not to use the same address as in
production, or there is a non-trivial chance of confusion.
2024-03-24 20:28:48 +01:00
jordi fita mas 1b46f4224e Compute the subtotal of dogs using their number, not as a boolean
I swear i believe sometime before we said that the number of dogs is not
important and should be used only as a boolean, but apparently it is
wrong: it should be number_dogs * cost_per_pet.
2024-03-20 18:17:58 +01:00
jordi fita mas fc9ac321d5 Tag database with version 6 2024-03-20 18:10:49 +01:00
jordi fita mas dbbd06cf85 Change the verify for season_calendar_season_id_fkey
It failed in build.opensuse.org; possibly the view in information_scheme
is different.
2024-03-14 22:28:46 +01:00
jordi fita mas 0412ffca05 Compute ACSI discount
After months of keeping what does the ACSI checkbox mean, now customer
told us that we should add a discount based on a series of
arbitrary conditions that, and need to be done NOW!

There is no UI to edit the conditions due to lack of time.
2024-03-14 22:08:01 +01:00
jordi fita mas cc1b334639 Add missing foreign key between season_calendar and season 2024-03-14 18:38:58 +01:00
jordi fita mas cb1e3afb44 Tag database with v5 2024-03-13 20:55:58 +01:00
jordi fita mas 864286e52a Fix the scheme used in flush payments’ cronjob 2024-03-13 18:28:46 +01:00
jordi fita mas 5cf45dcd41 Add flush_payments to clean up draft and pending payments
I always intended to delete draft payments after some time. I follow
WooCommerce’s default times: 1 day for draft and 1 hour for pending. No
other reason than we are used to it.

I added a cron job, rather than a systemd timer, because i want email
notifications, and because i do not yet know how to add many service
files in a Debian package.
2024-03-13 14:54:30 +01:00
jordi fita mas 75e0d8e197 Increase HTTP timeout
We have some clients that are on slow connections that have trouble
uploading large images due to timeout, and receive a “Guru Meditation”
from Varnish that it could not fetch.
2024-03-05 12:05:00 +01:00
jordi fita mas 365fed55b1 Grant SELECT on payment_status to guest
It is necessary to send the details email from the notification handler.
2024-02-29 18:06:50 +01:00
jordi fita mas 0ba088e5e2 Remove an HTML tag from email’s body in plain text 2024-02-29 17:39:00 +01:00
jordi fita mas dc9e45dfde Send a notification email to the company too on successful payment 2024-02-29 16:59:30 +01:00
jordi fita mas 334904fc03 Actually log request to stdout to be captured by systemd 2024-02-29 16:12:08 +01:00
jordi fita mas 9dc4c4ef8d Remove a fmt.Println leftover from a debug session 2024-02-29 16:11:23 +01:00
jordi fita mas 4e2df3f3c3 Return HTTP 200 instead of HTTP 204 for payment notifications
Redsys are a bunch of … something: they **only** recognize HTTP 200
as success; HTTP 204 apparently is an error for they, and don’t get
me started in not understanding what to do with an HTP 301.

Let’s just give in, and relax.
2024-02-28 13:42:12 +01:00
jordi fita mas 62d15970bf Reduce booking’s change delay to 500 ms 2024-02-28 13:36:14 +01:00
jordi fita mas 80835256cc Use idiomorph and a delay in the booking form
This is specially for the departure date: Firefox triggers a change each
time the user writes something, but since the date may be outside the
allowed range while the user is typing, the form replaces the input with
the “corrected” one.  The idiomorph thing is to keep the focus in the
“same” field, from the point of view of the user.

It still happens if one is slow enough, but i guess people that want to
write instead of picking the date are usually fast typist. Let’s hope.
2024-02-27 20:06:28 +01:00
jordi fita mas 97831668e5 Add the number of maximum nights that tourist tax applies
This is required by law.

I do not know why i have this value and the tax amount in the database,
but the payment percent and the number of days are hardcoded. I guess i
am such an inconsistent mess.
2024-02-27 20:06:28 +01:00
jordi fita mas 9ba9bac2a8 Tag sqitch with version version 4 2024-02-27 20:06:28 +01:00
oriol carbonell pujolàs 087108fe90 Add plausible script 2024-02-27 20:06:02 +01:00
jordi fita mas 9761f334be Translate footer links 2024-02-26 19:13:17 +01:00
oriol carbonell pujolàs b6387446b4 Add links to credits, terms and conditions, and reservation conditions 2024-02-26 19:10:27 +01:00
jordi fita mas 23e2fe956f Add a warning on the booking page when payment is using test environment
Apparently, the bank has to validate the fucking thing on the actual
domain, because of reasons, so we have to replace the current web in
production with this version in test mode, meaning that users **will**
believe they have paid, when in fact they have not.

The warning is for these few people that actually read such notices.
2024-02-26 16:00:29 +01:00
jordi fita mas 950bae16e1 Make address, postcode, and city require for booking
Customer changed their mind.
2024-02-24 20:03:11 +01:00
oriol carbonell pujolàs c848330751 Fix gap and margin for booking’s checkbox 2024-02-15 16:55:35 +01:00
jordi fita mas 6c14973076 Open port 8069 for camper.tandem.ws
This way i can expose that port when testing webhooks and stuff.
2024-02-15 16:36:31 +01:00
jordi fita mas a159bc75f0 Show a disclaimer on top of book button that it is in fact a prebooking 2024-02-15 15:54:22 +01:00
jordi fita mas 3bc4175580 Add authorization holding for payments
This is the mode they want to work with, but i could not test it because
they do not have it enabled in Redsys.  For now, just add the status and
the code to handle the responses.

Now i store all responses, if they are for a valid payment, just in case
i fucked something up. I also needed it because an authorization hold
needs at least two responses: one to accept the hold, and another for
the settlement.
2024-02-15 15:17:21 +01:00
jordi fita mas f2143cd0e6 Add the admin page to see payments
Had to do a couple of changes to the database: add the currency_code to
the payment relation, to format the price according to the payment’s
currency instead of the company’s; and the reference SQL function, to
replace the equivalent golang function, so that i can use it to index
payments.

The rest is mostly the same as any other page, except that the
individual payment’s page is not a form, but a regular info dump.

I also moved the payment settings as a sub-route of payments, as i
believe this makes more sense than an additional user menu item.
2024-02-14 04:54:42 +01:00
jordi fita mas bd84df8169 Add down payment
Customer wants to require a down payment of 30 % for bookings made
one week or more before the actual date, and to make the full payment
otherwise.

This would require yet another relation to keep these values. Fuck it;
i added them to the function, as they are very unlikely to change.

That forced me to change the test for draft_payment to use relative
dates, otherwise there is no way i can have stable results in the
future.
2024-02-13 23:45:25 +01:00
jordi fita mas af31daba8a Add positive_integer and nonnegative_integer domains
This is easier to read and requires less unit tests, but i only used
them in the new relations and fields for HEAD, because i do not see any
point on creating migrations just for that.
2024-02-13 22:12:30 +01:00
jordi fita mas 7e39e5f549 Create new drafts if trying to modify an already pending payment
This can happen when the customer reaches the payment page, but then
returns back to the booking form via the back button: the browser
remembers the URI with the cart slug, trying to make it ready, and then
it fails because it is already pending.

I did not like the idea of modifying a payment that is already not
a draft, because it seems to me that can lead to errors if we receive
Redsys notifications of payments that are being changed back to draft.
In fact, i believe that draft payments maybe should go to a different
relation altogether, so that i can prevent UPDATE on payment by guests,
but maybe i am going overboard now.
2024-02-13 20:16:12 +01:00
jordi fita mas 990a614897 Change draft_payment return type to row of payment
This way i can use the function in the from clause of the query that
i already had to do to get the totals formatted with to_price.  In this
case, i believe it is better to leave out Go’s function because it would
force me to perform two queries.

Instead of binding a nullable string pointer with the payment’s slug,
i wanted to use pgtype’s zeronull.Text type, but it can not work in this
case because it encodes the value as a text, while the parameters is
uuid.  I can not use zero.UUID, because it is a [16]byte array, while i
have it in a string.

Thus, had to create my own ZeroNullUUID type that use a string as a base
but encodes it as a UUID.
2024-02-13 19:51:39 +01:00
jordi fita mas 77a3f78176 Fixed null pointer access on validating booking without dogs or options 2024-02-13 17:05:19 +01:00
jordi fita mas 0f76351ae9 Move down HTMx attributes for booking form
Otherwise, it reloads the form while customers are writing their
details, removing the focus from the form; **very** annoying.

On the plus side, there is nothing to compute when entering these
fields, thus no redundant work is done now.
2024-02-13 05:59:07 +01:00
jordi fita mas 95ae50c1c3 Include details.gohtml when rendering payments/request.gohtml 2024-02-13 05:53:11 +01:00
jordi fita mas 4a7b0112ef Send an email on notification of success payment
To send the actual mail with sendmail, i have stolen the code from
go-mail[0] and removed everything i did not need.  This is because there
is no Go package to send email in Debian 12, and this was easier than
to build the DEB for go-mail.

Once i have the time….

[0]: https://go-mail.dev/
2024-02-13 05:20:35 +01:00
jordi fita mas 1179ba9c9a Add a missing reset client_min_messages 2024-02-13 02:40:02 +01:00
jordi fita mas ff6750fbea Handle payment notifications from Redsys
I have to basically do the reverse of signing the request to verify that
the notification comes from them.  Lots of code just for that.

I return the changed status from the PL/pgSQL function because i will
need to email customers when a payment is completed, and i need to know
when.
2024-02-13 02:38:38 +01:00
jordi fita mas 15dde3f491 Add ready_payment function and use their slug as URL
Now that the payments have slug, i can use them in the URL to show the
actual data of a payment, and kickstart the payment process with Redsys.
2024-02-12 18:06:17 +01:00
jordi fita mas 148d9075da Refactor base URL for the payment success, failure, and notification 2024-02-12 05:21:30 +01:00
jordi fita mas e4636592c5 Add payment relation and use it to compute the booking’s cart
I had to add the payment concept separate from the booking, unlike other
eCommerce solutions that subsume the two into a single “order”, like
WooCommerce, because bookings should be done in a separate Camper
instance that will sync to the public instance, but the payment is done
by the public instance.  There will be a queue or something between
the public and the private instance to pass along the booking
information once the payment is complete, but the public instance still
needs to keep track of payments without creating bookings.

To compute the total for that payment i had to do the same as was doing
until now for the cart.  To prevent duplications, or having functions
with complex return types, i now create a “draft” payment while the
user is filling in the form, and compute the cart there; from Go i only
have to retrieve the data from the relation, that simplifies the work,
actually.

Since the payment is computed way before customers enter their details,
i can not have that data in the same payment relation, unless i allow
NULL values.  Allowing NULL values means that i can create a payment
without customer, thus i moved all customer details to a separate
relation.  It still allows payment without customer, but at least there
are no NULL values.

Draft payments should be removed after a time, but i believe this needs
to be done in a cronjob or similar, not in the Go application.

To update the same payment while filling the same booking form, i now
have a hidden field with the payment slug.  A competent developer would
have used a cookie or something like that; i am not competent.
2024-02-12 05:21:00 +01:00
jordi fita mas d22fe39c80 Add a small note to the booking form when there is overflow
Customer wants to warn customers that plots are not guaranteed to be
next to each other.
2024-02-11 22:06:00 +01:00
jordi fita mas ea997a4154 Allow campsite type option to be just per unit, not per unit per night
Customer told us that there are some options, such as towels, that have
a fixed price for the whole stay, not a per night price.  Thus, had to
add a boolean to know whether to use sum or max when computing the
cart’s total for each option.
2024-02-11 21:45:00 +01:00