newOS for Developers

Back to Payment Hub

Stripe Payment Intent

intermediate

Create a Stripe checkout session for subscription payments.

Endpoint

POST /payment/stripe/checkout/session

Creates a Stripe checkout session and returns a redirect URL.

Request / Response

// Request
interface StripeCheckoutRequest {
  priceId: string;  // Stripe Price ID, e.g., "price_1QclmIKijqiCtsstf2dyEFS5"
}

// Response
interface StripeCheckoutResponse {
  checkoutSessionUrl: string;  // Redirect user to this URL
}

Implementation

import { stripeCheckoutSessionCreate, execProgressiveHandler } from "newgraph-signals";

// Create checkout session
const [signal, progress] = stripeCheckoutSessionCreate();

// Execute with price ID
await execProgressiveHandler(stripeCheckoutSessionCreate, {
  priceId: "price_1QclmIKijqiCtsstf2dyEFS5"  // Pro monthly
});

// Get the checkout URL from signal
const checkoutUrl = signal.value.checkoutUrl;

// Redirect user to Stripe checkout
if (checkoutUrl) {
  window.location.href = checkoutUrl;
}

Checkout Flow

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  User clicks    │ ──▶ │  POST /payment/ │ ──▶ │  Stripe hosted  │
│  "Subscribe"    │     │  stripe/...     │     │  checkout page  │
└─────────────────┘     └─────────────────┘     └────────┬────────┘
                                                         │
┌─────────────────┐     ┌─────────────────┐     ┌────────▼────────┐
│  UI: isPro      │ ◀── │  Webhook sets   │ ◀── │  Payment        │
│  = true         │     │  subscription   │     │  complete       │
└─────────────────┘     └─────────────────┘     └─────────────────┘

Price IDs

Price IDs are configured in Stripe dashboard. Common patterns:

price_xxx_monthly
Monthly subscription
price_xxx_yearly
Annual subscription (discounted)

Edge Cases

Session expires — Checkout URLs expire after 24 hours
Already subscribed — Check isPro before creating new session
Webhook delay — Subscription status may take a few seconds to update