Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logo-2

PayLoop

PayLoop is a non-custodial subscription payment protocol for USDC on Stellar, enabling crypto users to pay for recurring services like newsletters, SaaS tools, DAO memberships, and trading signal platforms, directly from their wallet.


The Problem

Recurring payments are the backbone of the internet economy. Subscriptions power SaaS, media, APIs, and community tools.

  • $500B+/year subscription economy
  • $300B+ in stablecoins onchain ()
  • No permissionless way to connect the two

Yet crypto has never had a reliable, non-custodial subscription primitive. Users are forced to either:

  • Trust custodial platforms (centralized, KYC-heavy)
  • Use credit cards and fiat rails that exclude the crypto-native population
  • Manually send payments on schedule (impractical at scale)
  • Use pull-payment hacks with no spending guardrails

For agents specifically, this is a hard stop.

An AI agent that needs to:

  • Renew access to a data API
  • Pay for a premium tool
  • Maintain a DAO membership

cannot do so autonomously without a programmable payment layer underneath it.

πŸ‘‰ PayLoop fills that gap on Stellar.


How It Works

Users fund their wallet with Stellar USDC.

They create a Policy defining:

  • Merchant address
  • Recurring amount
  • Billing interval
  • Safety cap (maximum spend)

The first charge executes instantly during policy creation, ensuring upfront payment.

From that point forward, the system becomes fully automated:

  • The smart contract enforces payment rules on-chain (none can manipulate this)
  • The relayer executes recurring charges at each interval
  • The indexer tracks all policy and payment state
  • The user retains full control, can pause, resume, or revoke anytime

🧠 System Architecture

User Wallet (Stellar)
        ↓
Frontend (Next.js)
        ↓
Backend API (Node.js)
        ↓
Relayer + Indexer
        ↓
Soroban Smart Contract
mermaid-diagram (1)

πŸ”„ Payment Flow Diagram

Create Policy
      ↓
Approve USDC
      ↓
First Charge (Instant)
      ↓
Relayer Executes Future Charges
      ↓
Indexer Tracks State
mermaid-diagram (3)

Merchant Integration

PayLoop enables seamless onboarding for real world use:

User-initiated flow

Users manually create a policy for any merchant

Merchant-initiated flow

Merchants generate:

  • Payment links
  • Embeddable buttons

Flow:

User clicks link
      ↓
Redirect to PayLoop
      ↓
Policy pre-filled
      ↓
Approve USDC
      ↓
Subscribe

πŸ‘‰ Similar to Stripe Checkout but fully onchain


X402 β€” Turning APIs into Paid Endpoints

PayLoop integrates x402, an HTTP-native payment protocol.

πŸ‘‰ Call API β†’ Pay β†’ Access

Flow

Client (user / agent) β†’ API call
        ↓
Server β†’ 402 Payment Required
        ↓
Client creates subscription (policy)
        ↓
Retry request
        ↓
API verifies subscription β†’ returns data
x402

This embeds payments directly into HTTP requests, making APIs natively monetizable.


Agent-Native Payments

PayLoop is built for the agent economy.

AI agents can:

  • Discover APIs
  • Create subscription policies
  • Approve payments
  • Retry requests
  • Continue execution

Fully autonomous. No human interaction required.

This transforms agents from:

πŸ‘‰ Passive tools β†’ Economic actors

AGENT-FLOW

🧩 Project Structure

/frontend        β†’ Next.js App
/backend         β†’ Node.js API + Relayer
/contracts       β†’ Soroban Smart Contracts

πŸ›  Installation

1. Clone Repository

git clone https://github.com/Shadow-Ash/payloop
cd payloop

2. Setup Frontend (Terminal 1)

npm install
npm run dev

3. Setup backend (Terminal 2)

cd backend
npm install
npm run dev

πŸ”‘ Environment Variables

Backend (.env)

PORT=4000
DATABASE_URL=
SOROBAN_RPC=https://soroban-testnet.stellar.org
STELLAR_RPC_URL=
CONTRACT_ID=

RELAYER_SECRET_KEY=
RELAYER_POLL_INTERVAL_MS=15000
RELAYER_BATCH_SIZE=10
RELAYER_LEASE_SECONDS=900
RELAYER_MAX_ATTEMPTS=5
WEBHOOK_SIGNING_SECRET=

Frontend (.env)

NEXT_PUBLIC_BACKEND_URL=

πŸ§ͺ API Endpoints

Get Policies

GET /policies?user=ADDRESS

Get Policy by ID

GET /policies/:id

Get Charges by Policy

GET /charges/:policy_id

x402 Protected API

POST /protected

πŸš€ Deployment

Backend (Heroku)

  • Connect GitHub repo
  • Add environment variables
  • Deploy automatically

Frontend (Vercel)

  • Import repo
  • Set:
NEXT_PUBLIC_BACKEND_URL

What's Next (Upcoming Features)

While the core system is live and functional, the roadmap focuses on expanding flexibility, intelligence, and real-world adoption.

- Usage-Based Billing (Dynamic Payments)

Moving beyond fixed subscriptions, PayLoop will support invoice-style payments where merchants can request variable amounts per cycle.

- Advanced x402 Payment Flows

Enabling per-request payments, hybrid subscription + usage models, and dynamic pricing.

- Merchant API & Developer Toolkit

  • Create paid APIs in minutes
  • Define pricing logic
  • Monitor usage and revenue

- Multi-Policy & Multi-Merchant Management

Better dashboards and controls for users and agents.

- Real-Time Analytics & Spend Intelligence

  • Payment patterns
  • Agent activity

- Multi-Token & Cross-Chain Support

Expand beyond USDC on Stellar.

- Agent-to-Agent Commerce

Agents can:

  • Sell services
  • Pay each other
  • Form decentralized economies

- Payment Optimization & Smart Routing

Agents dynamically select the most cost-efficient services.


License: MIT

About

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages