This document describes the SMS-based delivery confirmation system for vendors who prefer not to use email or login to a portal. Vendors can receive an SMS with a simple link that allows them to confirm deliveries with one click - no login required.
File: db/migrate/20251104205203_add_preferred_contact_method_to_vendors.rb
Adds preferred_contact_method field to vendors table:
'email', 'sms', or 'both''email'Run migration:
bin/rails db:migrate
File: app/models/vendor.rb
Added:
CONTACT_METHODS constantpreferred_contact_methodprefers_email? - Returns true if vendor wants emailprefers_sms? - Returns true if vendor wants SMShas_valid_phone_for_sms? - Checks if phone number is validFile: app/services/sms_service.rb
Added send_vendor_delivery_confirmations method:
Quarry Rentals: Please confirm X delivery(ies) from MM/DD.
Tap to confirm: https://admin.quarryrents.com/vendors/confirm_deliveries/[signed-id]
File: app/jobs/send_delivery_confirmation_emails_job.rb
Now handles multiple contact methods:
prefers_email?prefers_sms? AND has valid phoneFile: app/controllers/vendor_confirmations_controller.rb
Public controller (no authentication required):
GET /vendors/confirm_deliveries/:signed_id - Shows pending deliveriesPOST /vendors/confirm_deliveries/:signed_id/:confirmation_id - Confirms deliverySecurity:
signed_id with 7-day expirationFile: app/views/vendor_confirmations/index.html.erb
Features:
File: app/views/vendors/_form.html.erb
Added "Preferred Contact Method" dropdown with options:
Helper text: "How should we send delivery confirmation requests?"
File: config/routes.rb
Added public routes:
get "/vendors/confirm_deliveries/:signed_id", to: "vendor_confirmations#index"
post "/vendors/confirm_deliveries/:signed_id/:confirmation_id", to: "vendor_confirmations#confirm"
(415) 555-1234)Daily Job Runs (via cron at 5 PM):
bin/rails runner "SendDeliveryConfirmationEmailsJob.perform_now"
System Creates Confirmations:
DeliveryConfirmation recordsSMS Sent (if vendor prefers SMS):
Quarry Rentals: Please confirm 2 deliveries from 11/03.
Tap to confirm: https://admin.quarryrents.com/vendors/confirm_deliveries/eyJfcmF...
Vendor Clicks Link:
After Confirmation:
delivery_confirmed_atQuarry Rentals: Please confirm 3 deliveries from 11/03.
Tap to confirm: https://admin.quarryrents.com/vendors/confirm_deliveries/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt4TmpBME5EQSIsImV4cCI6IjIwMjUtMTEtMTFUMjA6NTI6MDMuODg3WiIsInB1ciI6bnVsbH19--abc123
# Rails console
vendor = Vendor.find_by(name: "Small Bins")
vendor.update!(phone: "(415) 555-1234", preferred_contact_method: "sms")
# Create test order and confirmation
order = Order.create!(
vendor: vendor,
delivery_date: Date.yesterday,
# ... other required fields
)
confirmation = DeliveryConfirmation.create!(
order: order,
vendor: vendor,
confirmation_type: "delivery",
status: "pending"
)
# Send SMS
sms_service = SmsService.new
result = sms_service.send_vendor_delivery_confirmations(vendor, [confirmation])
puts result.inspect
Generate signed ID in console:
vendor = Vendor.first
signed_id = vendor.signed_id(expires_in: 7.days)
puts "https://admin.quarryrents.com/vendors/confirm_deliveries/#{signed_id}"
Visit URL in browser
Click "Confirm Delivery" buttons
Required for SMS:
SIGNALWIRE_PROJECT_ID=your-project-id
SIGNALWIRE_TOKEN=your-token
SIGNALWIRE_SPACE_URL=yourspace.signalwire.com
SIGNALWIRE_FROM_NUMBER=+14157611123
APP_URL=https://admin.quarryrents.com
The SMS confirmation integrates with the ACH payment system:
1. Vendor delivers equipment
↓
2. Vendor receives SMS next day (5 PM)
↓
3. Vendor clicks link and confirms
↓
4. System checks: Customer payment captured? ✓
↓
5. ACH payment triggered for next day
↓
6. Vendor gets paid automatically
preferred_contact_method is 'sms' or 'both'.envtail -f log/production.log | grep SMSSigned IDs expire after 7 days. Vendor will see:
"Invalid or expired confirmation link."
Solution: Resend confirmation by running job again or contact vendor directly.
Check: