newOS for Developers
Back to Payment Hub
Subscription Payment
intermediateSet up recurring billing for Pro access with magic subscription codes.
Endpoint
POST /payment/magicApply a magic code to grant Pro subscription without payment.
Request / Response
// Request
interface MagicCreateRequest {
spell: string; // Magic subscription code
}
// Response
interface MagicCreateResponse {
status: string; // Success message or error
}Implementation
import { magicSubscription, execProgressiveHandler } from "newgraph-signals";
// Apply magic subscription code
const [signal, progress] = magicSubscription();
try {
await execProgressiveHandler(magicSubscription, {
spell: "YOUR_MAGIC_CODE"
});
const status = signal.value.status;
if (status && !status.includes("Hogwarts")) {
// Success - user now has Pro access
console.log("Subscription activated:", status);
} else {
// Invalid code
console.log("Invalid magic code");
}
} catch (error) {
if (error.status === 400) {
console.log("User is already a subscriber");
}
}Status Messages
SuccessReturns subscription confirmation message
400"As a subscriber, you already have all the magic..."
Invalid"No magic for you. Go back to Hogwarts..."
Stripe Checkout Alternative
For standard payment flow without magic codes, use the Stripe Intent skill to create a checkout session.
Edge Cases
Already subscribed — Returns 400 status with friendly message
Invalid code — Returns Hogwarts error message
Expired code — Magic codes may have usage limits or expiry