Skip to content

Latest commit

Β 

History

History
174 lines (127 loc) Β· 4.55 KB

File metadata and controls

174 lines (127 loc) Β· 4.55 KB

Coinbase Payment Integration Fixes - README

Quick Summary

Your Coinbase payment integration has two issues:

  1. Frontend allows anonymous payments β†’ Creates charges that can't be credited
  2. Balance doesn't update after payment β†’ User thinks payment failed

I've fixed both issues in this repo (frontend), but you also need to apply fixes to the backend.


What Got Fixed

This Repo (Morpheus-Marketplace-APP - Frontend)

Files changed:

  • βœ… src/components/billing/FundingSection.tsx
  • βœ… src/app/api/coinbase/charge/route.ts

Changes:

  1. Prevents anonymous payments (requires login)
  2. Refreshes balance after successful payment
  3. Better error messages and validation

Deploy: Ready to deploy now!

Other Repo (morpheus-marketplace-api - Backend)

File to fix: Webhook handler at /api/v1/webhooks/coinbase

Changes needed:

  1. Add idempotency (prevent double-crediting)
  2. Better validation (handle missing user_id gracefully)
  3. Enhanced logging (easier debugging)

Instructions: See BACKEND_WEBHOOK_FIXES.md


Why Multiple Webhook Events?

From your logs, Coinbase was sending the same webhook multiple times because:

  1. First attempt: Webhook fails with "Missing user_id"
  2. Coinbase retry logic: Retries after 1s, 10s, 30s, 1m, 5m...
  3. Eventually succeeds: After several attempts

With the fixes:

  • Frontend prevents creating charges without userId
  • Backend handles invalid webhooks gracefully (doesn't throw β†’ Coinbase won't retry)
  • Result: Single webhook, single credit, happy users

Deployment Order

1. Deploy Frontend (This Repo) - First

cd Morpheus-Marketplace-APP
git add .
git commit -m "fix: Coinbase payment validation and balance refresh"
git push origin main

2. Deploy Backend (Other Repo) - Second

cd morpheus-marketplace-api
# Apply fixes from BACKEND_WEBHOOK_FIXES.md
git add .
git commit -m "fix: Coinbase webhook idempotency and validation"
git push origin main

3. Test End-to-End

  • Make test payment ($1)
  • Check both frontend and backend logs
  • Verify balance updates
  • Check for duplicate credits

Documentation Files

File What It Contains
ARCHITECTURE.md System diagram, data flow, repository structure
BACKEND_WEBHOOK_FIXES.md Python code fixes for backend webhook handler
COINBASE_PAYMENT_ISSUES.md Original bug report with log analysis
COINBASE_FIXES_SUMMARY.md Technical explanation of all changes
COINBASE_MIGRATION_GUIDE.md Future migration to Payment Links API
QUICKSTART_DEPLOYMENT.md Fast deployment guide
.env.example Environment variables template

Start here: Read ARCHITECTURE.md to understand the system


Quick Test Script

#!/bin/bash
# test-coinbase-payment.sh

echo "πŸ§ͺ Testing Coinbase Payment Integration"
echo ""

echo "1. Testing anonymous payment prevention..."
echo "   β†’ Open app in incognito mode"
echo "   β†’ Go to /billing"
echo "   β†’ Check: 'Pay with Crypto' button disabled? βœ“/βœ—"
read -p "   Press enter when checked..."

echo ""
echo "2. Testing payment flow..."
echo "   β†’ Login to app"
echo "   β†’ Click 'Pay with Crypto'"
echo "   β†’ Enter $1.00 amount"
echo "   β†’ Complete payment on Coinbase"
echo "   β†’ Wait 5 seconds"
echo "   β†’ Check: Balance increased by $1.00? βœ“/βœ—"
read -p "   Press enter when checked..."

echo ""
echo "3. Checking backend logs..."
if command -v curl &> /dev/null; then
    echo "   Fetching recent webhooks..."
    # Add your log query here
    echo "   βœ“ Check logs manually for 'Account credited successfully'"
else
    echo "   ⚠️ curl not found, check logs manually"
fi

echo ""
echo "βœ… Test complete!"
echo "   See logs for any errors"

Still Confused?

Simple explanation:

  1. This repo = Website (Next.js)
  2. Other repo = API server (Python)
  3. Coinbase sends webhooks to β†’ API server (not website)
  4. I fixed: Website payment flow
  5. You need to fix: API server webhook handler

Architecture diagram: See ARCHITECTURE.md


Contact

Questions about:

  • Frontend fixes β†’ Check this repo's documentation
  • Backend fixes β†’ See BACKEND_WEBHOOK_FIXES.md
  • Migration plan β†’ See COINBASE_MIGRATION_GUIDE.md
  • Architecture β†’ See ARCHITECTURE.md

Still stuck? File GitHub issue with:

  • Which repo (frontend or backend)?
  • Error message
  • Logs
  • Steps to reproduce

Created: February 12, 2026
Last updated: February 12, 2026
Status: Frontend fixes ready, backend fixes documented