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
- Your app calls
pay()from the SDK with the amount and optionalinterval - The user is redirected to the secure NETWORKCOIN.ID checkout page
- The user selects a saved card or adds a new one
- Payment is processed through Stripe
- User is redirected back to your app with the result
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
| Field | Type | Required | Description |
|---|---|---|---|
| amount | number | Yes | Amount in smallest currency unit (cents) |
| currency | string | No | ISO 4217 code. Default: usd |
| description | string | No | What the charge is for |
| successUrl | string | Yes | Where to redirect after successful payment |
| cancelUrl | string | Yes | Where to redirect if user cancels |
| interval | 'month' | 'year' | No | If 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_...