@simplelayer/graniteer-core 0.3.18 → 0.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,6 @@ export function createBookingCheckoutSession(stripe, params, plan) {
63
63
  }
64
64
  if (!plan.connected)
65
65
  return stripe.checkout.sessions.create(params);
66
- return stripe.checkout.sessions.create(applyConnectToSessionParams(params, plan), { stripeAccount: plan.accountId });
66
+ return stripe.checkout.sessions.create({ ...applyConnectToSessionParams(params, plan), payment_method_types: ['card'] }, { stripeAccount: plan.accountId });
67
67
  }
68
68
  export const CONNECT_MISCONFIGURED_MESSAGE = 'Payments are misconfigured for this location (Stripe connected account or application fee). No charge was attempted.';
@@ -10,7 +10,7 @@ const corsHeaders = {
10
10
  };
11
11
  const LA_TZ = 'America/Los_Angeles';
12
12
  const TRIAL_DAYS = 7;
13
- const TIMEOUT_MS = 20_000;
13
+ const TIMEOUT_MS = 45_000;
14
14
  const JWKS_URL_SUFFIX = '/auth/v1/.well-known/jwks.json';
15
15
  let jwksCache = null;
16
16
  function getJwks(supabaseUrl) {
@@ -401,6 +401,7 @@ export async function handle(req, operator, deps) {
401
401
  .update({ status: newStatus })
402
402
  .eq('id', b.id)
403
403
  .eq('status', 'paid')
404
+ .is('access_revoke_required_at', null)
404
405
  .select('id');
405
406
  if (updErr)
406
407
  return json(500, { error: 'update_failed' });
@@ -408,9 +409,14 @@ export async function handle(req, operator, deps) {
408
409
  // Someone else flipped it in-between — return current view.
409
410
  const { data: fresh } = await admin
410
411
  .from('bookings')
411
- .select('id,status,contact_email,contact_name,contact_phone,ghl_contact_id,during,charged_amount_cents,list_amount_cents,dynamic_discount_cents,credit_applied_cents,google_event_id,rooms(id,name,address,google_calendar_id,slug,booking_mode,hourly_cents,day_cents,half_day_cents,min_booking_minutes)')
412
+ .select('access_revoke_required_at,id,status,contact_email,contact_name,contact_phone,ghl_contact_id,during,charged_amount_cents,list_amount_cents,dynamic_discount_cents,credit_applied_cents,google_event_id,rooms(id,name,address,google_calendar_id,slug,booking_mode,hourly_cents,day_cents,half_day_cents,min_booking_minutes)')
412
413
  .eq('id', b.id)
413
414
  .maybeSingle();
415
+ if (fresh && fresh.status === 'paid' && fresh.access_revoke_required_at) {
416
+ // Webhook flagged this booking (Connect full refund / dispute): no
417
+ // self-service cancel, hence no credit.
418
+ return json(409, { error: 'booking_flagged_contact_support' });
419
+ }
414
420
  if (fresh) {
415
421
  return json(200, {
416
422
  ...await bookingViewForCustomer(fresh, operator),
@@ -208,9 +208,20 @@ export async function handle(req, operator, deps) {
208
208
  .update({ status: 'cancelled_credited' })
209
209
  .eq('id', O.id)
210
210
  .eq('status', 'paid')
211
+ .is('access_revoke_required_at', null)
211
212
  .select('id');
212
213
  if (cErr || !cancelled || cancelled.length === 0) {
213
214
  await admin.from('bookings').update({ status: 'expired' }).eq('id', NEW_ID);
215
+ if (!cErr) {
216
+ const { data: flagRow } = await admin
217
+ .from('bookings')
218
+ .select('status,access_revoke_required_at')
219
+ .eq('id', O.id)
220
+ .maybeSingle();
221
+ if (flagRow && flagRow.status === 'paid' && flagRow.access_revoke_required_at) {
222
+ return json(409, { error: 'booking_flagged_contact_support' });
223
+ }
224
+ }
214
225
  return json(409, { error: 'already_changed' });
215
226
  }
216
227
  // Issue credit for the amount originally charged, split into up to TWO
@@ -1793,7 +1793,32 @@ function buildStripeWebhookHandler(config, connect) {
1793
1793
  // else-if branch further down -- which handles the actual
1794
1794
  // cancelled_* case -- can reuse it without recomputing.
1795
1795
  const bkIsCancelled = bkStatus.startsWith('cancelled_');
1796
+ // Connect-only: non-Connect (GC) completions keep the legacy behavior.
1797
+ const sessionIsPaid = !connect ||
1798
+ session.payment_status === 'paid' || session.payment_status === 'no_payment_required';
1796
1799
  if (booking &&
1800
+ !sessionIsPaid &&
1801
+ bkStatus !== 'paid' &&
1802
+ bkStatus !== 'deposit_paid' &&
1803
+ !bkIsCancelled) {
1804
+ // Delayed-notification payment methods complete the session with
1805
+ // payment_status 'unpaid'; no money has moved, so the booking must
1806
+ // stay pending. Never silent (project invariant).
1807
+ const unpaid = await logOps(supabase, 'booking_session_completed_unpaid', {
1808
+ session_id: session.id,
1809
+ payment_status: session.payment_status ?? null,
1810
+ booking_status: bkStatus,
1811
+ amount_total: session.amount_total ?? null,
1812
+ }, {
1813
+ severity: 'warning',
1814
+ bookingId: booking.id,
1815
+ dedupeKey: `booking_session_completed_unpaid:${booking.id}:${session.id}`,
1816
+ });
1817
+ if (!unpaid.ok) {
1818
+ console.error('[stripe-webhook] unpaid-completion alarm failed to persist', { bookingId: booking.id, sessionId: session.id, error: unpaid.error });
1819
+ }
1820
+ }
1821
+ else if (booking &&
1797
1822
  bkStatus !== 'paid' &&
1798
1823
  bkStatus !== 'deposit_paid' &&
1799
1824
  !bkIsCancelled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplelayer/graniteer-core",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "description": "Shared platform core for Graniteer",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",