Payments & Subscriptions

NETWORKCOIN.ID includes a built-in payment infrastructure powered by Stripe. Apps can charge users for one-time purchases or create recurring subscriptions — all through the hosted checkout page.

How It Works

  1. Your app calls pay() from the SDK with the amount and optional interval
  2. The user is redirected to the secure NETWORKCOIN.ID checkout page
  3. The user selects a saved card or adds a new one
  4. Payment is processed through Stripe
  5. User is redirected back to your app with the result
Your App → SDK pay() → /checkout → Stripe → redirect back to Your App

One-Time Payments

import { useNetworkCoin } from '@networkcoin/sdk/react';

function BuyButton() {
  const { pay } = useNetworkCoin();

  return (
    <button onClick={() => pay({
      amount: 999,           // $9.99 in cents
      currency: 'usd',
      description: 'Premium Plan',
      successUrl: window.location.origin + '/success',
      cancelUrl: window.location.origin + '/cancel',
    })}>
      Buy for $9.99
    </button>
  );
}

After payment, Stripe confirms the charge and the user is redirected to successUrl with ?payment_status=success&payment_intent=pi_...

Recurring Subscriptions

Add the interval parameter to create a Stripe subscription:

await pay({
  amount: 1999,
  currency: 'usd',
  description: 'Pro Monthly',
  interval: 'month',    // 'month' or 'year'
  successUrl: window.location.origin + '/success',
  cancelUrl: window.location.origin + '/cancel',
});

This creates a Stripe Price and Subscription automatically. The subscription is recorded in the subscriptions table with enriched metadata (IP, country, device, card info).

After subscribing, the user is redirected with ?payment_status=success&subscription_id=sub_...

PaymentOptions Reference

FieldTypeRequiredDescription
amountnumberYesAmount in smallest currency unit (cents)
currencystringNoISO 4217 code. Default: usd
descriptionstringNoWhat the charge is for
successUrlstringYesWhere to redirect after successful payment
cancelUrlstringYesWhere to redirect if user cancels
interval'month' | 'year'NoIf set, creates a recurring subscription

Managing Payment Methods & Subscriptions

Users can manage their saved cards and active subscriptions directly from their account settings panel.
- Add cards via Stripe SetupIntent
- Remove cards from their account
- Select active card at checkout
- Cancel subscriptions at any time.

Cancel Subscription API

POST /api/payments/cancel-subscription
Content-Type: application/json

{
  "subscription_id": "uuid"
}

Environment Variables

Ensure these are set in your .env.local:

NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...