=== Pickle Court Booking ===
Contributors: jouperse
Requires at least: 5.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 2.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lets customers view your pickleball court's availability on a calendar and book a slot,
paying online via PayMongo (GCash, Maya/PayMaya, and QR Ph).

== Installation ==

1. Zip the `pickle-court-booking` folder (or use the one already provided) and upload it via
   Plugins > Add New > Upload Plugin, or copy the folder into wp-content/plugins/.
2. Activate "Pickle Court Booking" from the Plugins page. This creates the bookings database
   table automatically.
3. Go to Pickle Bookings > Settings and configure:
   - Opening/closing hours, slot duration, price per slot, and closed days (these apply to
     every court).
   - Number of courts, and a label for each one (e.g. "Court A", "North Court"). Set this to 1
     if you only have a single court — the court selector on the booking page automatically
     hides itself when there's only one.
   - Payment Methods: tick which of GCash, Maya, QR Ph, and Manual payment (screenshot +
     admin verification) you want customers to see. Untick any to hide it immediately without
     touching your PayMongo keys.
   - If Manual payment is enabled, fill in the instructions customers see (e.g. your GCash
     number) before they upload a screenshot.
   - Email Notifications: optionally set a custom sender name/email, and up to 5 admin email
     addresses under "Booking notification recipients" — each one gets an email the moment a
     visitor submits a booking (manual or PayMongo), before payment is confirmed. Leave them
     blank to just use your WordPress admin email.
   - Your PayMongo API keys (get these from https://dashboard.paymongo.com/developers/api-keys) —
     only needed if GCash, Maya, or QR Ph are enabled.
     Start in Test mode with your sk_test_/pk_test_ keys before switching to Live.
   - The webhook: in your PayMongo Dashboard go to Developers > Webhooks, add a webhook
     pointing at the URL shown on the settings page, subscribed to `payment.paid` and
     `payment.failed`. Paste the signing secret it gives you back into the settings page.
4. Add the shortcode [pickle_booking_calendar] to any page (e.g. create a "Book a Court" page).
5. View bookings any time under Pickle Bookings > Bookings.
6. Pickle Bookings > Schedule Report lets you check vacancy/booked slots for any day or date
   range and download it as a PDF — handy for printing a day sheet for front-desk staff.
7. Pickle Bookings > Sales Report gives you weekly/monthly (or custom-range) revenue totals
   from paid bookings, with a payment-method/court breakdown, exportable as a PDF.

== How payments work ==

When a customer picks a slot and taps "Pay & Book":
1. A PayMongo Payment Intent is created for the slot price.
2. A Payment Method is created for the e-wallet/QR type they picked (GCash, Maya, or QR Ph)
   and attached to the Intent.
3. For GCash/Maya, the customer is redirected to authorize the payment in their wallet app,
   then PayMongo redirects them back to your booking page.
4. For QR Ph, a QR code is shown right on the page; the customer scans it with any
   participating bank or e-wallet app, and the page polls PayMongo until payment clears.
5. Once PayMongo confirms the payment (via webhook, with a client-side poll as backup),
   the booking is marked "Paid" and the slot is locked in. A confirmation email is sent
   to the customer.

Unpaid ("pending") bookings automatically free up their slot after the "hold time" set in
Settings, so a customer who starts checkout but never pays doesn't block the slot forever.

== Manual payment verification ==

If you enable "Manual payment" in Settings, customers get an extra option at checkout: they
send payment directly to you (GCash, bank transfer, cash app, whatever you describe in the
instructions field), then upload a screenshot as proof. The booking is created immediately
with status "Awaiting verification" — the slot is held so nobody else can book it — and you
get an email notification.

Go to Pickle Bookings > Bookings to review it: you'll see the uploaded screenshot as a
thumbnail (click to view full size), with Approve and Reject buttons. Approving marks the
booking Paid and emails the customer a confirmation; rejecting frees the slot back up and
emails the customer that it couldn't be verified. Manual bookings are never auto-expired the
way unpaid PayMongo bookings are — they wait for you either way.

== Turning payment methods on/off ==

In Settings > Payment Methods, tick or untick GCash, Maya, QR Ph, and Manual payment at any
time. Customers only ever see the methods you've enabled, and unticking one hides it
immediately — no need to remove or change your PayMongo API keys.

== Multiple courts ==

Each court shares the same opening hours, slot duration, and price (set once in Settings),
but has its own independent availability. On the booking page, customers pick a court from
the tabs at the top before choosing a date and slot; each court's calendar and slot list only
reflects bookings for that specific court. In Pickle Bookings > Bookings, you can filter the
list by court once more than one is configured.

If you're upgrading from an earlier version of this plugin, just activating/loading the
plugin again applies the small database updates needed (adds the court, payment-screenshot,
and admin-note columns to existing bookings) — no manual steps required.

== Booking multiple dates / time slots in one go ==

On the booking page, customers can tick "Book multiple dates / time slots in one booking"
above the time-slot grid. With it checked, tapping a slot adds it to a running "Selected
slots" cart instead of jumping straight to the details form — they can keep switching days
(and courts, if you have more than one) and add as many slots as they like, remove any of
them from the cart, then tap "Continue to booking details" once they're done. They pay/submit
proof once for the whole cart at the combined total price. Leaving the box unchecked keeps the
original one-slot-at-a-time flow exactly as before.

Behind the scenes, every slot in a multi-slot purchase is stored as its own booking row (so
each one shows correctly on the calendar and in reports) but they're linked by a shared
"booking group", so:
- A single PayMongo payment (one Payment Intent) covers the whole group; when it's paid, every
  slot in the group is marked Paid together.
- A single uploaded screenshot covers the whole group for Manual payment; approving or
  rejecting any one slot in Pickle Bookings > Bookings approves/rejects every slot in that
  same booking at once, and the customer gets one email listing every slot instead of several
  separate emails.
- The Bookings list shows a small "1 of N slots in this booking" note on grouped rows.

== Deleting bookings (clean up test data) ==

Every row in Pickle Bookings > Bookings now has a "Delete" button that permanently removes
just that one row — handy for clearing out bookings you made while testing.

To clear out a batch at once, set any combination of the filters (date range, court, status,
method, phone, customer) and use "Delete filtered booking(s)" above the table — it deletes
every booking matching your current filters. This cannot be undone.

To wipe **every** booking in one go, go to Pickle Bookings > Settings and scroll down to
**Danger Zone**. Keeping the full-wipe button there (instead of on the Bookings page) makes it
much harder to trigger by accident while you're just browsing/filtering the bookings list.

== Notes ==

- All PayMongo API calls happen server-side using your Secret Key, which is never exposed
  to the browser.
- Amounts are stored in PHP (pesos) and converted to centavos automatically for PayMongo.

== Changelog ==

= 2.0.0 =
- Added: Stripe as a second payment gateway (Card), alongside PayMongo. Uses Stripe Checkout
  (a hosted, redirect-based page), so it reuses the exact same booking/redirect flow already
  used for GCash and Maya — no new payment UI to learn.
- Added: a `payment_gateway` column on bookings so payment status polling and webhooks know
  whether to check PayMongo or Stripe for a given booking. Existing bookings are automatically
  backfilled as PayMongo.
- Changed: Sales Report and Schedule Report (and PDF export/email tools) have moved out of this
  plugin into a separate "Pickle Court Booking — Reports Addon" plugin, unlocked by subscription.
  Install the addon and enter a license key under Pickle Bookings > Addons & License to restore
  this functionality.
- Added: Pickle Bookings > Addons & License page, for entering a license key that unlocks addon
  plugins (checked against a central license server — see the separate "PCB License Server" plugin).

= 1.7.0 =
- Changed: all times shown to customers and admins (calendar slots, the Bookings list, booking
  confirmation/rejection emails, admin notification emails) now display in 12-hour format with
  AM/PM (e.g. "8:00 AM") instead of 24-hour format. This is a display-only change — booking
  logic, stored times, and AJAX data all continue to use 24-hour time internally, so nothing
  about how slots are generated, compared, or booked has changed.
- Added: Pickle Bookings > Schedule Report — pick a date or date range (and a court, if you
  have more than one) to see every slot's vacancy/booked/reserved status and who booked it,
  right on the page, with a "Download as PDF" button.
- Added: Pickle Bookings > Sales Report — a weekly, monthly, or custom-range revenue report
  built from paid bookings, with totals, a "Revenue over time" bar chart, a "Revenue trend"
  line chart, a breakdown by payment method (and by court, if you have more than one), an
  itemized list of paid bookings, and a "Download as PDF" button. Both charts group by day for
  a week/month view, or by week/month automatically for longer custom ranges so they don't turn
  into hundreds of unreadable bars/points.
- Added: an "Email this report" section (collapsed by default) on both the Schedule Report and
  Sales Report pages, completely separate from "View" and "Download as PDF" — viewing or
  downloading a report never sends anything. Expand it, check "Yes, email this report...", and
  click Send to email that exact report (as a PDF attachment) to whichever addresses are
  configured under Settings > Email Notifications > Booking notification recipients.
- Fixed: an earlier version of this could email the Schedule Report just from clicking "View
  schedule". Emailing is now only ever triggered by its own dedicated "Send Email" button.
- Fixed: the frontend booking calendar could occasionally show "Security check failed. Please
  refresh the page." — most often caused by a page-caching plugin serving a page with a
  stale security token, or a browser tab left open a long time. The calendar now detects this
  automatically, quietly fetches a fresh token, and retries the action once, so this error
  should no longer be visible to customers in that situation.
- Changed: the Sales Report bar and line charts are now smaller, always scroll horizontally
  (rather than stretching to fit), and their color is configurable — see Settings > Sales
  Report Chart Color.
- Both new reports export real, downloadable .pdf files generated by the plugin itself (no
  external PDF library or server tool required), so they work on any WordPress host.
- No changes to the existing booking calendar's design/behavior or to the Settings page.

= 1.6.0 =
- Changed: the "delete ALL bookings" cleanup tool has moved from Pickle Bookings > Bookings
  to Pickle Bookings > Settings ("Danger Zone" section), so it can't be triggered accidentally
  while browsing/filtering the bookings list. The Bookings page keeps "Delete filtered
  booking(s)", which only ever deletes what your current filters match.
- Fixed: on the customer-facing calendar, the Sun/Mon/Tue… weekday header could drift out of
  alignment with the day-number grid beneath it on narrow phone screens (roughly 320–460px
  wide), because the two rows were separate grids that could round column widths slightly
  differently. They're now built as a single shared grid, so the columns always line up
  exactly regardless of screen size.
- Improved: mobile layout across the booking widget (hero header, court tabs, calendar, time
  slots, booking form, payment options, result screens) and the wp-admin Bookings/Settings
  screens, specifically tuned for the 320–460px phone-width range.

= 1.5.0 =
- Added: customers can now book multiple dates/time slots in a single booking (a "Book
  multiple dates / time slots" option on the booking calendar), paid/verified together as one
  purchase.
- Added: per-row "Delete" button and a "Delete filtered bookings" bulk cleanup tool on the
  Pickle Bookings > Bookings admin page, for removing test/demo data.
- No visual/design changes to the existing single-slot booking flow or admin layout.
