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 04:21:00 +00:00
|
|
|
-- Deploy camper:payment to pg
|
|
|
|
-- requires: roles
|
|
|
|
-- requires: schema_camper
|
|
|
|
-- requires: company
|
|
|
|
-- requires: campsite_type
|
|
|
|
-- requires: payment_status
|
2024-02-13 21:12:30 +00:00
|
|
|
-- requires: positive_integer
|
|
|
|
-- requires: nonnegative_integer
|
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 04:21:00 +00:00
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
|
|
|
create table payment (
|
|
|
|
payment_id integer generated by default as identity primary key,
|
|
|
|
company_id integer not null references company,
|
|
|
|
slug uuid not null unique default gen_random_uuid(),
|
|
|
|
campsite_type_id integer not null references campsite_type,
|
|
|
|
arrival_date date not null,
|
|
|
|
departure_date date not null constraint departure_after_arrival check (departure_date > arrival_date),
|
2024-02-13 21:12:30 +00:00
|
|
|
subtotal_nights nonnegative_integer not null,
|
|
|
|
number_adults positive_integer not null,
|
|
|
|
subtotal_adults nonnegative_integer not null,
|
|
|
|
number_teenagers nonnegative_integer not null,
|
|
|
|
subtotal_teenagers nonnegative_integer not null,
|
|
|
|
number_children nonnegative_integer not null,
|
|
|
|
subtotal_children nonnegative_integer not null,
|
|
|
|
number_dogs nonnegative_integer not null,
|
|
|
|
subtotal_dogs nonnegative_integer not null,
|
|
|
|
subtotal_tourist_tax nonnegative_integer not null,
|
|
|
|
total nonnegative_integer not null,
|
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 04:21:00 +00:00
|
|
|
zone_preferences text not null,
|
|
|
|
payment_status text not null default 'draft' references payment_status,
|
|
|
|
created_at timestamp with time zone not null default current_timestamp,
|
|
|
|
updated_at timestamp with time zone not null default current_timestamp
|
|
|
|
);
|
|
|
|
|
|
|
|
grant select, insert, update on table payment to guest;
|
|
|
|
grant select, insert, update on table payment to employee;
|
|
|
|
grant select, insert, update, delete on table payment to admin;
|
|
|
|
|
|
|
|
commit;
|