Back to Recipes

Recipes12 minJanuary 15, 2025
Build a Payment Acceptance Platform with MoneyGraph
Complete guide to accepting card payments with MoneyGraph. Includes widget embed, popup checkout, server-side charging, 3DS handling, and subscription payments.
By MoneyGraph Team
# Build a Payment Acceptance Platform with MoneyGraph
This recipe shows you how to build a complete payment acceptance platform using MoneyGraph SDK. You'll learn to accept card payments via embedded widgets, popup checkout, or server-side API calls.
User Journey Overview
┌─────────────────────────────────────────────────────────────────────────────┐
│ PAYMENT ACCEPTANCE FLOW │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ 1. CHECKOUT INITIATION │
│ ├── Customer adds items to cart │
│ ├── Customer clicks "Pay Now" │
│ └── Your app generates external_reference │
│ │
│ 2. PAYMENT COLLECTION │
│ ├── Option A: Widget Embed (embedded on page) │
│ ├── Option B: Popup Checkout (modal overlay) │
│ └── Option C: Server-Side Charge (requires PCI compliance) │
│ │
│ 3. CARD PROCESSING │
│ ├── Card details collected securely │
│ ├── 3DS authentication (if required) │
│ └── Payment authorization │
│ │
│ 4. RESULT HANDLING │
│ ├── success → Fulfill order, redirect to thank-you │
│ ├── pending → Show processing, wait for webhook │
│ ├── requires_action → Redirect to 3DS authentication │
│ └── declined/blocked → Show error, offer retry │
│ │
│ 5. SERVER VERIFICATION │
│ ├── Verify payment via API (mg.payments.verifyPayment) │
│ └── Fulfill order only after verification │
│ │
└─────────────────────────────────────────────────────────────────────────────┘Prerequisites
- MoneyGraph account with payment acceptance enabled
- Public key (
pk_test_*orpk_live_*) for client-side - Secret key (
sk_test_*orsk_live_*) for server-side
AI Agent Quick Start
Use this prompt with your AI coding assistant:
Build a payment acceptance platform using MoneyGraph SDK with these features:- CHECKOUT PAGE
- - Product display with price
- - Embedded payment widget (stratos-embed div)
- - Load https://stratospay.com/embed.js
- - Configure with public_key, external_reference, amount, customer, billing_address
- - Handle onsuccess, onerror callbacks
- SERVER VERIFICATION
- - POST /api/verify-payment endpoint
- - Use mg.payments.verifyPayment(externalReference)
- - Only fulfill order after verification returns success
- WEBHOOK HANDLER
- - POST /webhooks/payments endpoint
- - Handle payment.success, payment.failed, payment.refunded events
- - Update order status in database
- ERROR HANDLING
- - Show user-friendly messages for card_declined, insufficient_funds, expired_card
- - Offer retry option on failure
- TEST MODE
- - Use pk_test_* and sk_test_* keys
- - Test with card 4917484589897107 for success
SDK METHODS: - mg.payments.chargeCard() - Server-side direct charge (PCI required) - mg.payments.verifyPayment() - Verify payment status
IMPORTANT: Always verify payments server-side before fulfilling orders! ```
Integration Options
Option 1: Widget Embed (Recommended)
Best for seamless checkout embedded directly on your page.
<!DOCTYPE html>
<html>
<head>
<title>Checkout</title>
</head>
<body>
<h1>Complete Your Purchase</h1>