Copperx Docs
LoginGet Started
  • 🏠 Getting Started
    • Introduction to Copperx
    • Use Cases: How You Can Use Copperx
    • Key Concepts & Terminology
  • πŸ”‘Setup & Configuration
    • Setup an account
      • Payment Configuration
      • Business Details
      • Apply your Branding
      • Manage Promo Codes
    • Environments (Testnet vs Mainnet)
    • How to Generate an API Key
  • πŸ’³ Integrate Payments
    • Accept One-Time Crypto Payments
    • Accept Crypto Subscriptions
    • Create Invoices
    • Create a Recurring Invoices
    • Webhooks & Events
  • Error Handling & Troubleshooting
  • πŸ“šAPI & Reference
    • Checkout Session API
    • Invoice API
    • Webhook Events
    • Authentication & Security
  • API Reference
  • πŸ”—No-Code Tools
    • Payment Link
    • Recurring Subscription
    • Recurring Invoice
    • Crypto Invoice
  • πŸ”ŒIntegrations
    • WooCommerce
    • Zapier
    • Stripe
    • BigCommerce
    • Magento
  • βš™οΈSupport
    • Clear Your Stuck Payments
Powered by GitBook
On this page
  1. Integrate Payments

Create a Recurring Invoices

Copperx allows you to create recurring invoices for subscriptions, memberships, and services that require periodic payments.

πŸ”§ How It Works

  1. Create a Recurring Invoice: Provide the relevant customer, amount, and recurrence details.

  2. Invoice Generation & Automation: Copperx’s system automatically generates new invoices at the defined interval.

  3. Notifications & Webhooks: Stay updated with webhooks for successful payments, failures, or other events.

βœ… Step 1: Create a Customer

Before creating an invoice, you’ll need to create a customer:

curl --request POST \
  --url https://api.copperx.dev/api/v1/customers \
  --header 'Authorization: Bearer {API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "email": "customer@example.com",
    "name": "John Doe",
    "metadata": {
      "customerType": "SaaS"
    }
  }'

βœ… Save the customerId from the response.


βœ… Step 2: Create a Product

Next, create the product to be billed:

curl --request POST \
  --url https://api.copperx.dev/api/v1/products \
  --header 'Authorization: Bearer {API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "name": "Pro Plan",
    "description": "Monthly subscription plan",
    "isActive": true,
    "unitLabel": "month",
    "metadata": {
      "category": "SaaS"
    },
    "defaultPriceData": {
      "currency": "usdc",
      "unitAmount": 50000000,
      "interval": "month",
      "type": "recurring"
    }
  }'

βœ… Save the productId from the response.

βœ… Save the defaultPrice.id as a priceId from the response.


βœ… Step 3: Create a Recurring Invoice

Use the customerId and productId and priceId in the invoice creation request:

curl --request POST \
  --url https://api.copperx.dev/api/v1/invoices \
  --header 'Authorization: Bearer {API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "customerId": "{CUSTOMER_ID}",
    "description": "Monthly recurring invoice for Pro Plan",
    "dueDate": "2025-06-15T00:00:00Z",
    "invoiceType": "recurring",
    "collectionMethod": "charge_automatically",
    "lineItems": {
      "object": "list",
      "priceId": "{}"
      "data": [
        {
          "quantity": 1,
          "price": {
            "productId": "{PRODUCT_ID}",
            "unitAmount": "50000000",
            "currency": "usdc",
            "type": "recurring",
            "interval": "month"
          }
        }
      ]
    }
  }'

βœ… Save the invoiceId from the response.


βœ… Step 4: Finalize the Invoice

Finalize the invoice to make it active and ready for payment collection:

curl --request POST \
  --url https://api.copperx.dev/api/v1/invoices/{INVOICE_ID}/finalize \
  --header 'Authorization: Bearer {API_KEY}' \
  --header 'Content-Type: application/json'

πŸ› οΈ Best Practices

βœ… Validate Customer Details: Make sure the customer information is accurate before generating invoices. βœ… Use Webhooks: Listen for events like invoice.paid, customer.subscription.started, and invoice.marked_as_paid to keep your system up to date. βœ… Secure API Calls: Always use HTTPS and a valid API key. βœ… Clear Terms: Clearly communicate the subscription and billing terms to customers.

PreviousCreate InvoicesNextWebhooks & Events

Last updated 5 days ago

πŸ’³