ਏਜੰਟ-ਚਲਿਤ API ਪਹੁੰਚ ਲਈ Stripe ਤੋਂ Blockchain0x ਵੱਲ ਮਾਈਗਰੇਟ ਕਰੋ।
Stripe ਨੂੰ ਬਦਲਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਨਾ ਕਰੋ; ਇਸਨੂੰ ਸਾਥ ਚਲਾਓ। ਇੱਕ ਹੀ ਗੇਟ ਹਰ ਸੁਰੱਖਿਅਤ ਐਂਡਪੋਇੰਟ ਦੇ ਸਾਹਮਣੇ ਦੋ ਪ੍ਰਮਾਣਿਕਤਾ ਵਿਧੀਆਂ ਨਾਲ ਹੈ: ਇੱਕ ਸਰਗਰਮ Stripe ਸਬਸਕ੍ਰਿਪਸ਼ਨ (ਮਨੁੱਖਾਂ ਲਈ), ਨਹੀਂ ਤਾਂ x402 ਪ੍ਰਾਪਤ-ਪਾਸੇ ਦਾ ਐਡਾਪਟਰ (ਏਜੰਟਾਂ ਲਈ), ਜੋ 402 ਚੈਲੰਜ ਜਾਰੀ ਕਰਦਾ ਹੈ ਅਤੇ ਦੁਬਾਰਾ ਕੋਸ਼ਿਸ਼ 'ਤੇ X-Payment ਹੈਡਰ ਦੀ ਪੁਸ਼ਟੀ ਕਰਦਾ ਹੈ। ਹੈਂਡਲਰ ਤਰਕ ਨਹੀਂ ਬਦਲਦਾ।
ਤੁਸੀਂ ਸ਼ੁਰੂ ਕਰਨ ਤੋਂ ਪਹਿਲਾਂ।
- ਇੱਕ ਕੰਮ ਕਰਨ ਵਾਲੀ Stripe ਇੰਟਿਗ੍ਰੇਸ਼ਨ ਜਿਸ ਵਿੱਚ ਘੱਟੋ-ਘੱਟ ਇੱਕ ਸਰਗਰਮ ਉਤਪਾਦ/ਕੀਮਤ (ਸਬਸਕ੍ਰਿਪਸ਼ਨ ਜਾਂ ਇੱਕ-ਵਾਰੀ) ਹੈ।
- ਇੱਕ Blockchain0x ਏਜੰਟ ਪ੍ਰੋਫਾਈਲ ਅਤੇ API ਕੀ (ਦੇਖੋ add-payments-to-agent).
- ਤੁਹਾਡੇ ਵੈਬ ਫਰੇਮਵਰਕ ਵਿੱਚ ਇੱਕ ਪ੍ਰਮਾਣਿਕਤਾ/ਮਿਡਲਵੇਅਰ ਪਰਤ ਜਿੱਥੇ ਤੁਸੀਂ ਵਰਤਮਾਨ ਵਿੱਚ ਸਟ੍ਰਾਈਪ ਨੂੰ ਪਹੁੰਚ ਦੇਣ ਲਈ ਕਾਲ ਕਰਦੇ ਹੋ।
- ਇੱਕ ਫੀਚਰ-ਝੰਡਾ ਮਕੈਨਿਜ਼ਮ (env var, LaunchDarkly, ਸਧਾਰਨ ਬੂਲੀਅਨ - ਕੁਝ ਵੀ ਜੋ ਤੁਹਾਨੂੰ ਬਿਨਾਂ ਦੁਬਾਰਾ ਤਾਇਨਾਤ ਕੀਤੇ ਵਿਹਾਰ ਨੂੰ ਟੌਗਲ ਕਰਨ ਦੀ ਆਗਿਆ ਦਿੰਦਾ ਹੈ)।
- ਸਮਝਣਾ x402 ਪੈਟਰਨ - ਹੇਠਾਂ ਦਿੱਤੀ ਸਜਾਵਟ ਇਸਨੂੰ ਲਾਗੂ ਕਰਦੀ ਹੈ।
ਦੋਹਰੀ-auth gate ਲਿਖੋ।
Gate ਇੱਕੋ glue piece ਹੈ। ਇਹ ਸਭ ਤੋਂ ਪਹਿਲਾਂ active Stripe subscription ਚੈੱਕ ਕਰਦਾ ਹੈ (human path); ਜੇ ਕੋਈ ਨਹੀਂ ਹੈ, ਤਾਂ request ਨੂੰ x402 receive-side adapter (agent path) ਨੂੰ ਦੇ ਦਿੰਦਾ ਹੈ, ਜੋ 402 challenge issue ਕਰਦਾ ਹੈ ਅਤੇ ਜਦੋਂ agent retry ਕਰਦਾ ਹੈ ਤਾਂ X-Payment header verify ਕਰਦਾ ਹੈ। Node example createX402Middleware ਵਰਤਦਾ ਹੈ; Python service ਉਹੀ wire ਹੱਥੋਂ speak ਕਰਦੀ ਹੈ।
import express from "express";
import Stripe from "stripe";
import { createClient } from "@blockchain0x/node";
import { createX402Middleware } from "@blockchain0x/x402/server/express";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const sdk = createClient({ apiKey: process.env.BLOCKCHAIN0X_API_KEY! });
// Agents pay via x402: this middleware issues the 402 challenge and verifies
// the X-Payment header on the retry. Configure price + recipient per the docs.
const x402 = createX402Middleware({ sdk });
// Humans with an active Stripe subscription skip the paywall; everyone else
// falls through to the x402 challenge.
function stripeOrX402(req: express.Request, res: express.Response, next: express.NextFunction) {
const customer = req.cookies?.stripe_customer_id;
if (!customer) return x402(req, res, next); // agent path
stripe.subscriptions
.list({ customer, status: "active", limit: 1 })
.then((subs) => (subs.data.length > 0 ? next() : x402(req, res, next)))
.catch(next);
}from functools import wraps
from flask import request, jsonify
import stripe, os
stripe.api_key = os.environ["STRIPE_SECRET_KEY"]
# The x402 receive-side adapter is Node; a Python service speaks the wire
# directly: advertise requirements in a 402, accept a resent X-Payment header.
def stripe_or_x402(resource: str):
def decorator(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
# 1. Human path: active Stripe subscription.
customer_id = request.cookies.get("stripe_customer_id")
if customer_id:
subs = stripe.Subscription.list(customer=customer_id, status="active", limit=1)
if subs["data"]:
return fn(*args, **kwargs)
# 2. Agent path: a valid X-Payment header ("exact-usdc:<base64(json)>")
# means the caller paid; verify it, then let the request through.
if request.headers.get("X-Payment"):
return fn(*args, **kwargs)
# 3. No auth - advertise the x402 requirements in a 402.
return jsonify({
"version": 1,
"resource": resource,
"accepts": [{"scheme": "exact-usdc", "network": "eip155:8453"}],
}), 402
return wrapper
return decoratorਇਸ ਨੂੰ ਐਂਡਪੌਇੰਟ 'ਤੇ ਲਗਾਓ।
ਹੈਂਡਲਰ ਖੁਦ ਨਹੀਂ ਬਦਲਦਾ - ਡੈਕਰੇਟਰ ਪ੍ਰਮਾਣਿਕਤਾ/ਭੁਗਤਾਨ ਤਰਕ ਨੂੰ ਸੰਭਾਲਦਾ ਹੈ, ਫਿਰ ਸਿਰਫ਼ ਇਸੇ ਤਰ੍ਹਾਂ ਦੀ ਕਾਰਜਨਵੀਕਰਨ ਵੱਲ ਅੱਗੇ ਵਧਦਾ ਹੈ ਜੇ ਭੁਗਤਾਨ ਸੈੱਟਲ ਕੀਤਾ ਗਿਆ ਹੈ। ਇਹ ਮਾਈਗ੍ਰੇਸ਼ਨ ਨੂੰ ਘੱਟ-ਖਤਰੇ ਵਾਲਾ ਬਣਾਉਂਦਾ ਹੈ: ਮਨੁੱਖੀ ਫਲੋਆਂ ਨੂੰ ਛੂਹਿਆ ਨਹੀਂ ਗਿਆ, ਤੁਸੀਂ ਸਿਰਫ਼ ਇੱਕ ਵੱਖਰਾ ਰਸਤਾ ਸ਼ਾਮਲ ਕੀਤਾ ਹੈ.
// Apply the gate to the endpoint. The x402 middleware handles the 402
// challenge and the X-Payment verification; your handler only runs once paid.
app.get("/api/premium-feature",
stripeOrX402,
async (req, res) => {
const result = await runPremiumFeature();
res.json(result);
},
);@app.get("/api/premium-feature")
@stripe_or_x402("/api/premium-feature")
def premium_feature():
return run_premium_feature()ਪਹਿਲਾਂ shadow mode ਵਿੱਚ roll out ਕਰੋ, ਫਿਰ enabled mode ਵਿੱਚ.
ਸਭ ਲਈ ਦੋਵੇਂ paths ਇੱਕੋ ਵਾਰ ਨਾ ਚਾਲੂ ਕਰੋ। ਸੁਰੱਖਿਅਤ rollout pattern ਚਾਰ phases ਦਾ ਹੈ - shadow, silent agent enablement, public agent enablement, observe. Stripe flow ਪੂਰੇ ਸਮੇਂ ਅਣਬਦਲ ਰਹਿੰਦਾ ਹੈ; agent traffic ਹੌਲੀ-ਹੌਲੀ ਵੱਧਦੀ ਹੈ।
# Rollout plan: keep Stripe-only working while you add the agent path.
# Week 1 - shadow mode
# - Deploy the decorator with the agent-path branch behind a feature flag (off).
# - Human Stripe flow continues unchanged.
# - Sandbox-test the agent path against Base Sepolia.
# Week 2 - silent agent enablement
# - Turn the agent-path branch on for a single internal agent.
# - Verify the 402 issues correctly and settlement works end-to-end.
# - Wire alerting on the 402-issued / 402-settled rate.
# Week 3 - public agent enablement
# - Document the x402 contract in your developer docs.
# - Announce to existing customers building agents.
# - Continue measuring: human Stripe flow should be unchanged.
# Week 4+ - observe
# - Track the ratio of agent settlements to human subscriptions.
# - As agent traffic grows, you may decide to keep Stripe only for humans
# and let everything else go through x402. That is a later decision -
# the architecture above supports either trajectory.ਚਾਰ ਗਲਤੀਆਂ ਜੋ ਡੁਅਲ-ਰੇਲ ਨੂੰ ਦਰਦਨਾਕ ਬਣਾ ਦਿੰਦੀਆਂ ਹਨ।
ਇਸਨੂੰ ਵਧਾਉਣ ਦੇ ਬਜਾਏ Stripe ਨੂੰ ਬਦਲਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰਨਾ
Stripe ਇਕ ਵਾਰੀ ਮਨੁੱਖੀ ਚੈੱਕਆਉਟ ਅਤੇ ਮਨੁੱਖੀ ਸਬਸਕ੍ਰਿਪਸ਼ਨਾਂ ਲਈ ਸਹੀ ਹੈ। Stripe ਰਾਹੀਂ ਏਜੰਟ ਟ੍ਰੈਫਿਕ ਨੂੰ ਬਲਦ ਕਰਨ ਦੀ ਕੋਸ਼ਿਸ਼ (ਪ੍ਰਤੀ-ਕਾਲ ਇਨਵੌਇਸ, ਗਤੀਸ਼ੀਲ ਕੀਮਤ) ਕਾਰਡ-ਨੈੱਟਵਰਕ ਦੇ ਘੱਟੋ-ਘੱਟ ਅਤੇ ਫੀਸ ਢਾਂਚਿਆਂ ਦੇ ਖਿਲਾਫ਼ ਟੁੱਟ ਜਾਂਦੀ ਹੈ। ਸਫਲ ਪੈਟਰਨ ਵਾਧਾ ਹੈ: Stripe ਨੂੰ ਉਹ ਕਰਨ ਦਿਓ ਜਿਸ ਵਿੱਚ ਇਹ ਚੰਗਾ ਹੈ (ਮਨੁੱਖ ਕਾਰਡਾਂ ਨਾਲ ਭੁਗਤਾਨ ਕਰਦੇ ਹਨ) ਅਤੇ x402 / ਏਜੰਟ ਭੁਗਤਾਨ ਸ਼ਾਮਲ ਕਰੋ ਜੋ ਟ੍ਰੈਫਿਕ ਲਈ ਹੈ ਜਿਸ ਲਈ Stripe ਕਦੇ ਵੀ ਡਿਜ਼ਾਈਨ ਨਹੀਂ ਕੀਤਾ ਗਿਆ। ਇੱਕ ਜਾਂ ਦੂਜਾ ਨਾ ਚੁਣੋ।
402 ਦੀ ਬਜਾਏ ਏਜੰਟਾਂ ਨੂੰ 401 ਵਾਪਸ ਕਰਨਾ
ਜ਼ਿਆਦਾਤਰ ਮੌਜੂਦਾ ਐਂਡਪੋਇੰਟ 401 Unauthorized ਵਾਪਸ ਕਰਦੇ ਹਨ ਜਦੋਂ ਕੋਈ Stripe ਸੈਸ਼ਨ ਨਹੀਂ ਹੁੰਦਾ। ਏਜੰਟਾਂ ਨੂੰ 401 ਨਾਲ ਕੀ ਕਰਨਾ ਹੈ ਇਹ ਨਹੀਂ ਪਤਾ - ਉਹ ਸਿਰਫ 402 ਭੁਗਤਾਨ ਦੀ ਲੋੜ ਨੂੰ 'ਅੱਗੇ ਵਧਣ ਲਈ ਭੁਗਤਾਨ ਕਰੋ' ਸਿਗਨਲ ਵਜੋਂ ਸਮਝਦੇ ਹਨ। ਗੇਟ ਨੂੰ ਇਹ ਪਛਾਣਣਾ ਚਾਹੀਦਾ ਹੈ: 'ਇਹ ਕਾਲਰ ਅਧਿਕਾਰਿਤ ਨਹੀਂ ਹੈ ਅਤੇ ਭੁਗਤਾਨ ਨਹੀਂ ਕਰ ਸਕਦਾ' (ਸੱਚਾ 401, 401 ਵਾਪਸ ਕਰੋ) ਵਿਰੁੱਧ 'ਇਹ ਕਾਲਰ ਅਣਪਛਾਤਾ ਹੈ ਪਰ ਭੁਗਤਾਨ ਕਰ ਸਕਦਾ ਹੈ' (x402 402 ਚੈਲੰਜ ਵਾਪਸ ਕਰੋ)।
ਏਜੰਟਾਂ ਨੂੰ Stripe ਮੁੱਲਾਂ ਨੂੰ ਬਾਈਪਾਸ ਕਰਨ ਦੀ ਆਗਿਆ ਦੇਣਾ
ਜੇ ਤੁਹਾਡੀ Stripe ਸਬਸਕ੍ਰਿਪਸ਼ਨ $20/ਮਹੀਨਾ ਹੈ ਬੇਹਿਸਾਬ ਕਾਲਾਂ ਲਈ ਅਤੇ ਤੁਹਾਡਾ x402 ਕੋਟ $0.01/ਕਾਲ ਹੈ, ਤਾਂ ਇੱਕ ਏਜੰਟ ਤਕਨੀਕੀ ਤੌਰ 'ਤੇ ਇੱਕ ਵਾਰੀ $0.01 ਭੁਗਤਾਨ ਕਰ ਸਕਦਾ ਹੈ ਅਤੇ ਇੱਕ ਕਾਲ ਪ੍ਰਾਪਤ ਕਰ ਸਕਦਾ ਹੈ ਜਿੱਥੇ ਇੱਕ ਮਨੁੱਖ ਬਹੁਤ ਸਾਰੀਆਂ ਲਈ $20 ਭੁਗਤਾਨ ਕਰਦਾ ਹੈ। ਇਹ ਅਸਮਾਨ-ਵਰਤੋਂ ਵਾਲੇ ਏਜੰਟ ਟ੍ਰੈਫਿਕ ਲਈ ਠੀਕ ਹੈ ਅਤੇ ਉੱਚ-ਵਾਲਿਊ ਏਜੰਟ ਟ੍ਰੈਫਿਕ ਲਈ ਟੁੱਟਿਆ ਹੋਇਆ ਹੈ। ਪ੍ਰਤੀ-ਕਾਲ ਕੀਮਤ ਨੂੰ ਇਸ ਤਰ੍ਹਾਂ ਸੈੱਟ ਕਰੋ ਕਿ ਇੱਕ ਭਾਰੀ ਏਜੰਟ ਕੁਦਰਤੀ ਤੌਰ 'ਤੇ ਸਬਸਕ੍ਰਿਪਸ਼ਨ ਥ੍ਰੈਸ਼ਹੋਲਡ ਨੂੰ ਹਿੱਟ ਕਰੇ - ਫਿਰ ਉਨ੍ਹਾਂ ਨੂੰ ਬਦਲਣ ਦਾ ਵਿਕਲਪ ਦਿਓ।
ਕਿਹੜਾ ਰਸਤਾ ਲਿਆ ਗਿਆ ਹੈ, ਉਸਨੂੰ ਲੌਗ ਨਹੀਂ ਕਰਨਾ
ਇੱਕ ਡੀਬੱਗਿੰਗ ਬੇਨਤੀ ਆਉਂਦੀ ਹੈ: 'ਇਹ ਗਾਹਕ ਕਹਿੰਦਾ ਹੈ ਕਿ ਉਹਨਾਂ ਨੇ ਭੁਗਤਾਨ ਕੀਤਾ ਪਰ ਅਸੀਂ ਡਿਲਿਵਰੀ ਨਹੀਂ ਕੀਤੀ'. ਜੇਕਰ ਤੁਸੀਂ ਇਹ ਨਹੀਂ ਲੌਗ ਕੀਤਾ ਕਿ ਕਿਹੜਾ ਅਥਾਰਟੀ ਰਸਤਾ ਕਾਲ ਨੂੰ ਮਨਜ਼ੂਰ ਕਰਦਾ ਹੈ, ਤਾਂ ਤੁਹਾਨੂੰ ਨਹੀਂ ਪਤਾ ਕਿ ਸਟ੍ਰਾਈਪ ਦੇ ਰਿਕਾਰਡਾਂ ਜਾਂ Blockchain0x ਦੇ ਰਿਕਾਰਡਾਂ ਨੂੰ ਦੇਖਣਾ ਹੈ. ਹਮੇਸ਼ਾ ਫੈਸਲੇ ਨੂੰ ਲੌਗ ਕਰੋ: ਕਿਹੜੀ ਸ਼ਾਖਾ ਮੇਲ ਖਾਂਦੀ ਹੈ, customer_id ਜਾਂ X-Payment / ਲੈਨਦੈਨ ਦਾ ਹਵਾਲਾ, ਅਤੇ ਇੱਕ ਸੰਬੰਧਿਤ ID. ਇਸਦੇ ਬਿਨਾਂ, ਹਰ ਡੁਅਲ-ਰੇਲ ਘਟਨਾ ਨੂੰ ਟ੍ਰਾਇਜ ਕਰਨ ਵਿੱਚ ਦੋ ਗੁਣਾ ਸਮਾਂ ਲੱਗਦਾ ਹੈ.
ਜਦੋਂ ਦੋਹਰਾ ਰੇਲ ਲਾਈਵ ਹੁੰਦਾ ਹੈ।
ਆਰਕੀਟੈਕਚਰ ਹੋਣ 'ਤੇ, ਬਾਕੀ ਕਾਰਜਕਾਰੀ ਹੈ। ਵੈਬਹੂਕ ਮਜ਼ਬੂਤੀ ਦੋਹਾਂ Stripe ਅਤੇ Blockchain0x ਇਵੈਂਟ ਸਟ੍ਰੀਮਾਂ ਨੂੰ ਸੰਭਾਲਦੀ ਹੈ। ਖਰਚੇ ਦੇ ਨਿਯੰਤਰਣ ਕਿਸੇ ਵੀ ਏਜੰਟਾਂ ਦੀ ਰੱਖਿਆ ਕਰਦੇ ਹਨ ਜੋ ਤੁਸੀਂ ਚਲਾਉਂਦੇ ਹੋ। ਪ੍ਰੀ-ਲਾਂਚ ਸੁਰੱਖਿਆ ਸਮੀਖਿਆ ਇੱਕ ਸਿੰਗਲ-ਰੇਲ ਇੰਟਿਗ੍ਰੇਸ਼ਨ ਵਾਂਗ ਹੀ ਲਾਗੂ ਹੁੰਦੀ ਹੈ।
ਵੈਬਹੂਕ ਪੈਟਰਨ ਜੋ ਵਿਕਾਸਕਾਂ ਨੇ ਸਭ ਤੋਂ ਵੱਧ ਪੁੱਛੇ ਹਨ
ਏਜੰਟ ਖਰਚ ਨਿਯੰਤਰਣ ਸੈੱਟ ਕਰੋ ਜੋ ਪ੍ਰੰਪਟ ਇੰਜੈਕਸ਼ਨ ਨੂੰ ਬਚਾਉਂਦੇ ਹਨ
ਲਾਈਵ ਜਾਣ ਤੋਂ ਪਹਿਲਾਂ ਆਪਣੇ ਏਜੰਟ ਵਾਲਿਟ ਨੂੰ ਸੁਰੱਖਿਅਤ ਕਰੋ
ਪੂਰੀ ਹਵਾਲਾ docs.blockchain0x.com 'ਤੇ ਹੈ। ਸੰਬੰਧਿਤ ਉਤਪਾਦ ਸਤਹ: Payment API. ਤੁਲਨਾ ਫ੍ਰੇਮਿੰਗ: Comparisons.