Accept Crypto Subscriptions

๐Ÿš€ How It Works

โœ… Step 1: Create a Product

Every subscription plan is associated with a product. Create the product first using the following API request:

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 Membership",
    "description": "Monthly plan for premium users",
    "isActive": true,
    "unitLabel": "month",
    "url": "https://example.com/product",
    "metadata": {
      "category": "SaaS"
    },
    "visibility": 10,
    "defaultPriceData": {
      "currency": "usdc",
      "unitAmount": 50000000,
      "interval": "month",
      "intervalCount": 1,
      "type": "recurring"
    }
  }'

The response will include a unique productId. Save this for the next step.


โœ… Step 2: Create a Subscription Checkout Session

Using the created productโ€™s ID, generate a checkout session to enable the user to subscribe:

curl --request POST \
  --url https://api.copperx.dev/api/v1/checkout/sessions \
  --header 'Authorization: Bearer {API_KEY}' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "mode": "subscription",
    "lineItems": {
      "data": [
        {
          "priceData": {
            "currency": "usdc",
            "unitAmount": "50000000",
            "interval": "month",
            "productId": "{PRODUCT_ID}"
          }
        }
      ]
    },
    "successUrl": "https://yourapp.com/success?session_id={CHECKOUT_SESSION_ID}",
    "cancelUrl": "https://yourapp.com/cancel"
  }'

The API response will provide a hosted checkout session URL. Redirect your user to this URL to complete the subscription.


โœ… Step 3: Automate Recurring Billing

Copperxโ€™s smart contracts automatically handle the recurring charges based on the interval (monthly, yearly, etc.) and send blockchain-verified payment confirmations.


โœ… Step 4: Stay Updated with Webhooks

Copperx sends webhook events for key actions:

  • customer.subscription.created

  • customer.subscription.started

  • customer.subscription.unpaid

Use these events to manage access and provide real-time updates to your users.

Last updated