From Manual Contracts to Instant Digital Payments: A Complete B2B Commerce Solution
How I built a sophisticated white-labeled payment platform for Chamber of Commerce publications, featuring dual product lines, dynamic pricing, digital signatures, and automated contract fulfillment-processing $100-$5,000+ transactions with zero manual intervention.

Project Overview
Lunar Cow Publishing manages advertising for multiple Chamber of Commerce and CVB publications. Their legacy process required manual contract processing, phone/email payment coordination, and physical signatures. I built a fully digital platform enabling instant credit card payments, digital signature capture, automated contract generation, and seamless integration with their existing business management system.
Background & Context
Lunar Cow Publishing operates a B2B platform serving local businesses advertising in Chamber of Commerce publications. Revenue comes from two streams: (1) Standard advertisements with fixed-size placements priced $200-$5,000+, and (2) Enhanced Directory Listings with modular à la carte pricing. The platform supports multiple publications with per-publication custom pricing, premium inventory management, and sales commission tracking.
Key Challenges
Dual Product Payment Architecture
The platform needed to handle two fundamentally different product types: standard advertisements with fixed pricing and premium inventory limits, versus enhanced directory listings with dynamic per-publication custom pricing and complex user inputs (logos, descriptions, color selections). Both required different metadata structures and fulfillment workflows.
Implemented separate Payment Intent creation flows with product-specific metadata schemas. Standard ads store sizeId and handle inventory decrements, while EDL payments store flattened selection data (edlOptions: '1,2,3', logo URL, description text, color choice) in Stripe metadata. A shared contract creation pipeline determines the product type from metadata flags and routes to appropriate fulfillment logic.
Pre-Payment Digital Signature Capture
Legal requirements mandated signed contracts before payment processing, but Stripe Checkout Sessions don't support pre-payment custom steps. The signature needed to be uploaded, stored securely, and linked to the payment before the user submits card details.
Built a custom multi-step checkout using Stripe Elements and Payment Intents API. The flow captures the signature via canvas, uploads to S3, creates a 'pending contract' record with the signature URL and payment intent ID, THEN confirms the payment. This pending contract acts as a bridge, enabling idempotent contract creation after successful payment and supporting abandoned cart recovery.
Race Conditions in Premium Inventory
Certain advertisement sizes have limited availability (e.g., 'Premium Spot - only 3 available'). If two users attempted to purchase the last spot simultaneously, the system could oversell, breaking business commitments to publications.
Implemented atomic inventory management with double-check validation. Availability is verified before Payment Intent creation, then again during post-payment contract creation with an atomic database decrement. If inventory is exhausted between payment and fulfillment (race condition), the second user receives a graceful error with a refund path, preventing overselling while maintaining data consistency.
Per-Publication Dynamic Pricing Without Code Changes
Different Chamber organizations wanted custom pricing for enhanced listings (e.g., $75 for color instead of default $100). The marketing team needed to configure pricing per-publication without developer intervention or code deployments.
Built a database-driven pricing system with a publication_edl_pricing table storing custom prices per option per publication. The payment intent creation queries this table, builds a pricing map, and applies custom prices if available with fallback to defaults. This enables non-technical staff to configure pricing via admin interface with zero code changes.
Complex Metadata Storage for User Inputs
Enhanced directory listings required storing user-uploaded logo URLs (S3 paths), multi-paragraph descriptions, color selections, and boolean flags in Stripe metadata-but metadata only supports string key-value pairs with 500-character limits.
Designed a flattened metadata schema: edlOptions stores comma-separated IDs ('1,2,3'), logo/description/box/color store raw values as strings. The payment processing pipeline reconstructs complex objects from these flattened strings. Form validation enforces character limits to prevent truncation, and the architecture gracefully handles missing values with null coalescing.
Technical Approach
The implementation leverages Stripe's Payment Intents API for maximum flexibility and control. I built a custom checkout flow using Next.js Server Actions for type-safe payment processing, React components with Stripe Elements for secure card collection, and a 'pending contracts' pattern for idempotent fulfillment. The architecture separates concerns: client handles UX and signature capture, server actions create payment intents with rich metadata, webhooks provide backup verification, and a centralized contract creation module handles all fulfillment regardless of payment method.
Custom Multi-Step Checkout Wizard
Accordion-based UI with three steps: (1) Business Search with type-ahead, (2) Business Profile form with validation, (3) Payment Selection with separate flows for credit card vs. check/invoice. Context API manages state across steps with progressive disclosure to reduce cognitive load.
Payment Intent Creation with Rich Metadata
Separate server actions for standard ads vs. EDL listings. Each validates product availability, calculates dynamic pricing, constructs product-specific metadata (advertiser, publication, product details, user inputs), and creates Stripe Payment Intent. Metadata serves as single source of truth for post-payment processing.
Stripe Elements Integration with Signature Capture
Custom PaymentForm component integrates Stripe Elements for card collection with a signature canvas component. Before payment confirmation, the signature is converted to PNG, uploaded to S3, and stored in a pending contract record. Only after successful upload does the form enable payment submission.
Pending Contracts Idempotency Pattern
Database table links payment intents to business context before payment completion. Stores signature URL, advertiser/publication IDs, and product details. Contract creation queries this table first-if contract already exists for this payment intent, return existing ID instead of creating duplicate. Enables safe retry logic and abandoned cart recovery.
Dual Payment Method Support
Credit card flow uses Stripe with instant fulfillment. Check/invoice flow creates pending contract, sends invoice email, and provides admin API endpoint for manual completion after check receipt. Both paths converge at the same contract creation logic, ensuring consistent data structure.
Automated Commission & Sales Attribution
Contract creation determines sales rep from advertiser-publication assignments, calculates whether transaction qualifies for commission (non-house, non-EDL sales only), and stores both commissioned_rep_id and sales_rep_id. Enables accurate monthly commission reports with zero manual reconciliation.
Integration with External Platform (The Observatory)
After successful payment, users redirect to Observatory (internal management platform) with payment intent ID. Welcome emails trigger via Observatory API. Contract data syncs bidirectionally, enabling customers to upload artwork and track project status in a unified interface.
Premium Inventory Management
Database fields track premium_count (null = unlimited). Pre-payment validation checks availability. Post-payment atomic decrement prevents overselling. Race condition handling ensures graceful failure if inventory exhausted between validation and fulfillment.
Results & Impact
The platform transformed Lunar Cow's business operations. Transaction time dropped from days/weeks to minutes. The credit card option significantly improved completion rates compared to check-only. Contract generation, receipt handling, and customer notifications are fully automated, reducing operational overhead. The system supports 10-15 active publications and easily scales to 100+ without code changes. Custom pricing capabilities empower marketing teams to configure promotions independently. Most importantly, the business can now focus on growth instead of manual contract administration.
“The ratecard platform completely transformed how we sell advertising. What used to take days of back-and-forth now happens in minutes, and our customers love the instant gratification of completing their purchase online.”
Key Takeaways
- Payment Intents API provides superior flexibility for custom checkout flows compared to Checkout Sessions
- Always verify payment status server-side-never trust client-side confirmation for fulfillment logic
- Pending contracts pattern enables idempotent operations and graceful handling of edge cases (browser refresh, race conditions)
- Stripe metadata is powerful when structured systematically-treat it as the source of truth for fulfillment
- Database-driven pricing configuration empowers non-technical teams without requiring code deployments
- Atomic inventory operations with double-check validation prevent race conditions in limited availability scenarios
- Pre-payment signature capture requires Payment Intents API-Checkout Sessions don't support custom pre-payment steps
- Comprehensive error handling and timeout detection provide clear user guidance when things go wrong
- Testing 3D Secure flows with test cards is critical-authentication redirects introduce complexity
- Separation of payment method logic (credit card vs. invoice) at UI layer with shared contract creation ensures consistency
Related Services
Interested in similar work for your project?

"I highly recommend Dean to anyone looking for a reliable and professional partner for their software development needs."
Ben Harris - CEO of Lunar Cow Publishing
Need similar work for your project?
Book a free consultation to discuss how we can help you achieve results like these.