A
', 5, '[1, 7]', true) ; select throws_ok( - $$ insert into payment (company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, zone_preferences) values (1, 10, '2024-07-07', '2024-07-07', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, '') $$, + $$ insert into payment (company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, currency_code, zone_preferences) values (1, 10, '2024-07-07', '2024-07-07', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') $$, '23514', 'new row for relation "payment" violates check constraint "departure_after_arrival"', 'Should not be able to insert a payment with a departure date equal or before the arrival date (i.e., at least one night)' ); diff --git a/test/payment_option.sql b/test/payment_option.sql index 31913bd..c79809c 100644 --- a/test/payment_option.sql +++ b/test/payment_option.sql @@ -42,42 +42,6 @@ select col_not_null('payment_option', 'subtotal'); select col_hasnt_default('payment_option', 'subtotal'); -set client_min_messages to warning; -truncate payment_option cascade; -truncate payment cascade; -truncate campsite_type_option cascade; -truncate campsite_type cascade; -truncate media cascade; -truncate media_content cascade; -truncate company cascade; -reset client_min_messages; - -insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, rtc_number, tourist_tax, country_code, currency_code, default_lang_tag) -values (1, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 60, 'ES', 'EUR', 'ca') -; - -insert into media_content (media_type, bytes) -values ('image/x-xpixmap', 'static char *s[]={"1 1 1 1","a c #ffffff","a"};') -; - -insert into media (media_id, company_id, original_filename, content_hash) -values (2, 1, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) -; - -insert into campsite_type (campsite_type_id, company_id, media_id, name, description, max_campers, bookable_nights, active) -values (10, 1, 2, 'Type A', 'A
', 5, '[1, 7]', true) -; - -insert into campsite_type_option (campsite_type_option_id, campsite_type_id, name, range, per_night) -values (11, 10, 'Option 1', '[2, 2]', true) - , (12, 10, 'Option 2', '[4, 8]', true) -; - -insert into payment (payment_id, company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, zone_preferences) -values (15, 1, 10, '2024-07-07', '2024-07-08', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, '') -; - - select * from finish(); diff --git a/test/payment_reference.sql b/test/payment_reference.sql new file mode 100644 index 0000000..9e8d880 --- /dev/null +++ b/test/payment_reference.sql @@ -0,0 +1,74 @@ +-- Test reference +set client_min_messages to warning; +create extension if not exists pgtap; +reset client_min_messages; + +begin; + +select plan(10); + +set search_path to camper, public; + +select has_function('camper', 'reference', array['payment']); +select function_lang_is('camper', 'reference', array['payment'], 'sql'); +select function_returns('camper', 'reference', array['payment'], 'text'); +select isnt_definer('camper', 'reference', array['payment']); +select volatility_is('camper', 'reference', array['payment'], 'stable'); +select function_privs_are('camper', 'reference', array['payment'], 'guest', array['EXECUTE']); +select function_privs_are('camper', 'reference', array['payment'], 'employee', array['EXECUTE']); +select function_privs_are('camper', 'reference', array['payment'], 'admin', array['EXECUTE']); +select function_privs_are('camper', 'reference', array['payment'], 'authenticator', array[]::text[]); + + +set client_min_messages to warning; +truncate payment cascade; +truncate campsite_type cascade; +truncate media cascade; +truncate media_content cascade; +truncate company cascade; +reset client_min_messages; + +insert into company (company_id, business_name, vatin, trade_name, phone, email, web, address, city, province, postal_code, rtc_number, tourist_tax, country_code, currency_code, default_lang_tag) +values (2, 'Company 2', 'XX123', '', '555-555-555', 'a@a', '', '', '', '', '', '', 350, 'ES', 'EUR', 'ca') +; + +insert into media_content (media_type, bytes) +values ('image/x-xpixmap', 'static char *s[]={"1 1 1 1","a c #ffffff","a"};') +; + +insert into media (media_id, company_id, original_filename, content_hash) +values (10, 2, 'cover2.xpm', sha256('static char *s[]={"1 1 1 1","a c #ffffff","a"};')) +; + +insert into campsite_type (campsite_type_id, slug, company_id, name, media_id, max_campers, bookable_nights, overflow_allowed) +values (12, 'c1b6f4fc-32c1-4cd5-b796-0c5059152a52', 2, 'Plots', 10, 6, '[1, 7]', true) +; + +insert into payment (payment_id, slug, company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, currency_code, zone_preferences) +values (22, '4ef35e2f-ef98-42d6-a724-913bd761ca8c', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') + , (23, '6d1b8e4c-c3c6-4fe4-92c1-2cbf94526693', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') + , (24, '8d38a482-8a25-4d85-9929-e5f425fcac04', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') + , (25, 'b770f8b7-f148-4ab4-a786-aa070af598e5', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') + , (26, '31910d73-d343-44b7-8a29-f7e075b64933', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') + , (27, 'c9488490-ac09-4402-90cd-f6f0546f04c0', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') + , (28, '5819823e-c0ac-4baa-a3ae-515fbb70e909', 2, 12, '2024-08-29', '2024-09-03', 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'EUR', '') +; + +select bag_eq( + $$ select payment_id, payment.reference from payment $$, + $$ values (22, '000000224ef3') + , (23, '000000236d1b') + , (24, '000000248d38') + , (25, '00000025b770') + , (26, '000000263191') + , (27, '00000027c948') + , (28, '000000285819') + $$, + 'Should give out the order code for each payment' +); + + +select * +from finish(); + +rollback; diff --git a/test/process_payment_response.sql b/test/process_payment_response.sql index 4000a64..87f7f4a 100644 --- a/test/process_payment_response.sql +++ b/test/process_payment_response.sql @@ -44,14 +44,14 @@ insert into campsite_type (campsite_type_id, slug, company_id, name, media_id, m values (12, 'c1b6f4fc-32c1-4cd5-b796-0c5059152a52', 2, 'Plots', 10, 6, '[1, 7]', true) ; -insert into payment (payment_id, slug, company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, zone_preferences, payment_status, created_at, updated_at) -values (22, '4ef35e2f-ef98-42d6-a724-913bd761ca8c', 2, 12, '2024-08-28', '2024-09-04', 3200, 2, 10420, 4, 20840, 6, 25080, 3, 2450, 4900, 79160, 'pref I before E', 'draft', '2024-01-01 01:01:01', '2024-01-01 01:01:01') - , (24, '6d1b8e4c-c3c6-4fe4-92c1-2cbf94526693', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'pending', '2024-01-02 02:02:02', '2024-01-02 02:02:02') - , (26, '8d38a482-8a25-4d85-9929-e5f425fcac04', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'completed', '2024-01-03 03:03:03', '2024-01-03 03:03:03') - , (28, 'b770f8b7-f148-4ab4-a786-aa070af598e5', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'failed', '2024-01-04 04:04:04', '2024-01-04 04:04:04') - , (30, '31910d73-d343-44b7-8a29-f7e075b64933', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'refunded', '2024-01-05 05:05:05', '2024-01-05 05:05:05') - , (32, 'c9488490-ac09-4402-90cd-f6f0546f04c0', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'pending', '2024-01-05 05:05:05', '2024-01-05 05:05:05') - , (34, '5819823e-c0ac-4baa-a3ae-515fbb70e909', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'pending', '2024-01-05 05:05:05', '2024-01-06 06:06:06') +insert into payment (payment_id, slug, company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, currency_code, zone_preferences, payment_status, created_at, updated_at) +values (22, '4ef35e2f-ef98-42d6-a724-913bd761ca8c', 2, 12, '2024-08-28', '2024-09-04', 3200, 2, 10420, 4, 20840, 6, 25080, 3, 2450, 4900, 79160, 'EUR', 'pref I before E', 'draft', '2024-01-01 01:01:01', '2024-01-01 01:01:01') + , (24, '6d1b8e4c-c3c6-4fe4-92c1-2cbf94526693', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'pending', '2024-01-02 02:02:02', '2024-01-02 02:02:02') + , (26, '8d38a482-8a25-4d85-9929-e5f425fcac04', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'completed', '2024-01-03 03:03:03', '2024-01-03 03:03:03') + , (28, 'b770f8b7-f148-4ab4-a786-aa070af598e5', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'failed', '2024-01-04 04:04:04', '2024-01-04 04:04:04') + , (30, '31910d73-d343-44b7-8a29-f7e075b64933', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'refunded', '2024-01-05 05:05:05', '2024-01-05 05:05:05') + , (32, 'c9488490-ac09-4402-90cd-f6f0546f04c0', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'pending', '2024-01-05 05:05:05', '2024-01-05 05:05:05') + , (34, '5819823e-c0ac-4baa-a3ae-515fbb70e909', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'pending', '2024-01-05 05:05:05', '2024-01-06 06:06:06') ; insert into payment_redsys_response (payment_id, response_code, date_time, secure_payment, transaction_type, amount, currency_code, order_number, authorization_code, merchant_code, terminal_number, error_code) diff --git a/test/ready_payment.sql b/test/ready_payment.sql index 5b58d03..1e8ccae 100644 --- a/test/ready_payment.sql +++ b/test/ready_payment.sql @@ -45,9 +45,9 @@ insert into campsite_type (campsite_type_id, slug, company_id, name, media_id, m values (12, 'c1b6f4fc-32c1-4cd5-b796-0c5059152a52', 2, 'Plots', 10, 6, '[1, 7]', true) ; -insert into payment (payment_id, slug, company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, zone_preferences, payment_status, created_at, updated_at) -values (22, '4ef35e2f-ef98-42d6-a724-913bd761ca8c', 2, 12, '2024-08-28', '2024-09-04', 3200, 2, 10420, 4, 20840, 6, 25080, 3, 2450, 4900, 79160, 'pref I before E', 'draft', '2024-01-01 01:01:01', '2024-01-01') - , (24, '6d1b8e4c-c3c6-4fe4-92c1-2cbf94526693', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, '', 'draft', current_timestamp, current_timestamp) +insert into payment (payment_id, slug, company_id, campsite_type_id, arrival_date, departure_date, subtotal_nights, number_adults, subtotal_adults, number_teenagers, subtotal_teenagers, number_children, subtotal_children, number_dogs, subtotal_dogs, subtotal_tourist_tax, total, currency_code, zone_preferences, payment_status, created_at, updated_at) +values (22, '4ef35e2f-ef98-42d6-a724-913bd761ca8c', 2, 12, '2024-08-28', '2024-09-04', 3200, 2, 10420, 4, 20840, 6, 25080, 3, 2450, 4900, 79160, 'EUR', 'pref I before E', 'draft', '2024-01-01 01:01:01', '2024-01-01') + , (24, '6d1b8e4c-c3c6-4fe4-92c1-2cbf94526693', 2, 12, '2024-08-29', '2024-09-03', 71000, 1, 0, 2, 0, 3, 0, 0, 0, 1750, 72750, 'EUR', '', 'draft', current_timestamp, current_timestamp) ; insert into payment_customer (payment_id, full_name, address, postal_code, city, country_code, email, phone, acsi_card, lang_tag) diff --git a/verify/payment.sql b/verify/payment.sql index 0e36804..cf01473 100644 --- a/verify/payment.sql +++ b/verify/payment.sql @@ -19,6 +19,7 @@ select payment_id , subtotal_dogs , subtotal_tourist_tax , total + , currency_code , down_payment_percent , zone_preferences , payment_status diff --git a/verify/payment_reference.sql b/verify/payment_reference.sql new file mode 100644 index 0000000..ec1d266 --- /dev/null +++ b/verify/payment_reference.sql @@ -0,0 +1,7 @@ +-- Verify camper:order_code on pg + +begin; + +select has_function_privilege('camper.reference(camper.payment)', 'execute'); + +rollback; diff --git a/web/static/camper.css b/web/static/camper.css index 6bce16f..23d0b00 100644 --- a/web/static/camper.css +++ b/web/static/camper.css @@ -289,6 +289,8 @@ main { padding: 2rem 3rem; } +/*{{( pgettext "Reference" "header" )}} | +{{ .Reference }} | +
---|---|
{{( pgettext "Status" "header" )}} | +{{ .StatusLabel }} | +
{{( pgettext "Created at" "payment header" )}} | +{{ .CreatedAt | formatDateTime }} | +
{{( pgettext "Last updated at" "payment header" )}} | +{{ .UpdatedAt | formatDateTime }} | +
{{( pgettext "Accommodation" "title" )}} | +{{ .CampsiteType }} | +
---|---|
{{( pgettext "Area preferences" "header" )}} | +{{ .ZonePreferences }} | +
{{( pgettext "Arrival date" "input" )}} | +{{ .ArrivalDate | formatDate }} | +
{{( pgettext "Departure date" "input" )}} | +{{ .DepartureDate | formatDate }} | +
{{( pgettext "Nights" "cart" )}} | +{{ .NumNights }} | +
{{( pgettext "Adults aged 17 or older" "input" )}} | +{{ .NumAdults }} | +
{{( pgettext "Teenagers from 11 to 16 years old" "input" )}} | +{{ .NumTeenagers }} | +
{{( pgettext "Children from 2 to 10 years old" "input" )}} | +{{ .NumChildren }} | +
{{( pgettext "Dogs" "input" )}} | +{{ .NumDogs }} | +
{{( pgettext "Tourist tax" "cart" )}} | +{{ .SubtotalTouristTax | formatPrice }} | +
{{( pgettext "Down payment" "cart" )}} | +{{ .DownPaymentPercent }} %, {{ .DownPayment | formatPrice }} | +
{{ .Label }} | +{{ .Units }} | +
---|
{{( pgettext "Full name" "input" )}} | +{{ .FullName }} | +
---|---|
{{( pgettext "Address" "input" )}} | +{{ .Address }} | +
{{( pgettext "Postcode" "input" )}} | +{{ .PostalCode }} | +
{{( pgettext "City" "input" )}} | +{{ .City }} | +
{{( pgettext "Country" "input" )}} | +{{ .Country }} | +
{{( pgettext "Email" "input" )}} | +{{ .Email }} | +
{{( pgettext "Phone" "input" )}} | +{{ .Phone }} | +
{{( pgettext "Language" "input" )}} | +{{ .Language }} | +
{{( pgettext "ACSI card?" "input" )}} | +{{if .ACSICard}}{{( gettext "Yes" )}}{{ else }}{{( gettext "No" )}}{{ end }} | +
{{( pgettext "Date" "header" )}} | +{{( pgettext "Reference" "header" )}} | +{{( pgettext "Status" "header" )}} | +{{( pgettext "Down payment" "header" )}} | +{{( pgettext "Total" "header" )}} | +
---|---|---|---|---|
{{ .CreatedAt | formatDate }} | +{{ .Reference }} | +{{ .StatusLabel }} | +{{ .DownPayment | formatPrice }} | +{{ .Total | formatPrice }} | +
{{( gettext "No payments found." )}}
+ {{- end }} +{{- end }} diff --git a/web/templates/admin/booking/payment.gohtml b/web/templates/admin/payment/settings.gohtml similarity index 91% rename from web/templates/admin/booking/payment.gohtml rename to web/templates/admin/payment/settings.gohtml index 702a311..e78cee6 100644 --- a/web/templates/admin/booking/payment.gohtml +++ b/web/templates/admin/payment/settings.gohtml @@ -7,12 +7,13 @@ {{- end }} {{ define "breadcrumb" -}} +