ಏಜೆಂಟ್-ಚಾಲಿತ API ಪ್ರವೇಶಕ್ಕಾಗಿ ಸ್ಟ್ರೈಪ್ ನಿಂದ Blockchain0x ಗೆ ಸ್ಥಳಾಂತರಿಸಿ.
Stripe ಅನ್ನು ಬದಲಾಯಿಸಬೇಡಿ; ಇದನ್ನು ಹತ್ತಿರವೇ ಓಡಿಸಿ. ಪ್ರತಿ ರಕ್ಷಿತ ಎಂಡ್ಪಾಯಿಂಟ್ನ್ನು ಒಬ್ಬೇ ಗೇಟ್ ಮುಂಭಾಗದಲ್ಲಿದೆ, ಎರಡು ಪ್ರಮಾಣೀಕರಣ ವಿಧಾನಗಳೊಂದಿಗೆ: ಸಕ್ರಿಯ Stripe ಚಂದಾದಾರಿಕೆ (ಮಾನವರಿಗೆ), ಇಲ್ಲದಿದ್ದರೆ x402 ಸ್ವೀಕರಿಸುವ ಅಡಾಪ್ಟರ್ (ಏಜೆಂಟ್ಗಳಿಗೆ), ಇದು 402 ಸವಾಲು ನೀಡುತ್ತದೆ ಮತ್ತು ಪುನರಾವೃತ್ತದಲ್ಲಿ X-Payment ಹೆಡರ್ ಅನ್ನು ದೃಢೀಕರಿಸುತ್ತದೆ. ಹ್ಯಾಂಡ್ಲರ್ ಲಾಜಿಕ್ ಬದಲಾಯಿಸುವುದಿಲ್ಲ.
ನೀವು ಪ್ರಾರಂಭಿಸುವ ಮೊದಲು.
- ಕನಿಷ್ಠ ಒಂದು ಸಕ್ರಿಯ ಉತ್ಪನ್ನ/ಬೆಲೆಯೊಂದಿಗೆ ಕಾರ್ಯನಿರ್ವಹಣೆಯ Stripe ಏಕೀಕರಣ (ಚಂದಾ ಅಥವಾ ಒಮ್ಮೆ).
- ಒಂದು Blockchain0x ಏಜೆಂಟ್ ಪ್ರೊಫೈಲ್ ಮತ್ತು API ಕೀ ( add-payments-to-agent ಅನ್ನು ನೋಡಿ).
- ನೀವು ಪ್ರಸ್ತುತ ಪ್ರವೇಶವನ್ನು ಗೇಟು ಮಾಡಲು Stripe ಅನ್ನು ಕರೆ ಮಾಡುವ ನಿಮ್ಮ ವೆಬ್ ಫ್ರೇಮ್ವರ್ಕ್ನಲ್ಲಿ ಒಬ್ಬ auth/middleware ಹಂತ.
- ಒಂದು ವೈಶಿಷ್ಟ್ಯ-ಧ್ವಜ ಯಂತ್ರವಿಜ್ಞಾನ (ಪರಿಸರ ವ್ಯತ್ಯಾಸ, LaunchDarkly, ಸರಳ ಬೂಲಿಯನ್ - ಪುನಃ ನಿಯೋಜನೆಯಿಲ್ಲದೆ ವರ್ತನೆಗಳನ್ನು ಸ್ವಿಚ್ ಮಾಡಲು ನಿಮಗೆ ಅವಕಾಶ ನೀಡುವ ಯಾವುದೇ ವಿಷಯ).
- x402 ಮಾದರಿಯ ಅರ್ಥ - ಕೆಳಗಿನ ಡೆಕೋರೆಟರ್ ಇದನ್ನು ಕಾರ್ಯಗತಗೊಳಿಸುತ್ತದೆ.
dual-auth gate ಅನ್ನು ಬರೆಯಿರಿ.
gate ಒಂದೇ glue piece ಆಗಿದೆ. ಇದು ಮೊದಲು active Stripe subscription ಇದೆಯೇ ಎಂದು ಪರಿಶೀಲಿಸುತ್ತದೆ (human path); ಇಲ್ಲದಿದ್ದರೆ, ಅದು request ಅನ್ನು x402 receive-side adapter ಗೆ (agent path) hand off ಮಾಡುತ್ತದೆ, ಅದು 402 challenge ಅನ್ನು issue ಮಾಡುತ್ತದೆ ಮತ್ತು agent retry ಮಾಡಿದಾಗ X-Payment header ಅನ್ನು verify ಮಾಡುತ್ತದೆ. Node example createX402Middleware ಅನ್ನು ಬಳಸುತ್ತದೆ; Python service ಅದೇ wire ಅನ್ನು ಕೈಯಾರೆ ಮಾತಾಡುತ್ತದೆ.
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 ನಲ್ಲಿ rollout ಮಾಡಿ, ನಂತರ enabled mode.
ಎಲ್ಲರಿಗೂ ಎರಡೂ ಮಾರ್ಗಗಳನ್ನು ಒಂದೇ ಬಾರಿ ಆನ್ ಮಾಡಬೇಡಿ. ಸುರಕ್ಷಿತ rollout pattern ನಾಲ್ಕು ಹಂತಗಳು - 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.ದ್ವಿ-ರೇಲ್ ಅನ್ನು ನೋವುಗೊಳಿಸುವ ನಾಲ್ಕು ತಪ್ಪುಗಳು.
ಅದರಲ್ಲಿನ ಬದಲಿಗೆ ಸ್ಟ್ರೈಪ್ ಅನ್ನು ಬದಲಾಯಿಸಲು ಪ್ರಯತ್ನಿಸುತ್ತಿದೆ
ಸ್ಟ್ರೈಪ್ ಒಮ್ಮೆ ಮಾತ್ರ ಮಾನವ ಚೆಕ್ಔಟ್ಗಳಿಗೆ ಮತ್ತು ಮಾನವ ಚಂದಾದಾರಿಕೆಗಳಿಗೆ ಸರಿಯಾಗಿದೆ. ಏಜೆಂಟ್ ಟ್ರಾಫಿಕ್ ಅನ್ನು ಸ್ಟ್ರೈಪ್ ಮೂಲಕ ಒತ್ತಿಸಲು (ಪ್ರತಿ ಕರೆ ಬಿಲ್ಗಳು, ಡೈನಾಮಿಕ್ ಬೆಲೆ) ಕಾರ್ಡ್-ನೆಟ್ವರ್ಕ್ ಕನಿಷ್ಠ ಮತ್ತು ಶುಲ್ಕ ರಚನೆಗಳ ವಿರುದ್ಧ ಮುರಿಯುತ್ತದೆ. ಯಶಸ್ವಿ ಮಾದರಿ ವೃದ್ಧಿಯಾಗಿದೆ: ಸ್ಟ್ರೈಪ್ ಅನ್ನು ಏನನ್ನು ಉತ್ತಮವಾಗಿ ಮಾಡಲು ಬಿಡಿ (ಮಾನವರು ಕಾರ್ಡ್ಗಳಿಂದ ಪಾವತಿಸುತ್ತಾರೆ) ಮತ್ತು ಸ್ಟ್ರೈಪ್ ಎಂದಿಗೂ ವಿನ್ಯಾಸಗೊಳಿಸಲಾಗದ ಟ್ರಾಫಿಕ್ಗಾಗಿ x402 / ಏಜೆಂಟ್ ಪಾವತಿಗಳನ್ನು ಸೇರಿಸಿ. ಒಂದನ್ನು ಅಥವಾ ಇನ್ನೊಂದನ್ನು ಆಯ್ಕೆ ಮಾಡಬೇಡಿ.
402 ಬದಲು ಏಜೆಂಟ್ಗಳಿಗೆ 401 ಹಿಂತಿರುಗಿಸುತ್ತಿದೆ
ಬಹಳಷ್ಟು ಅಸ್ತಿತ್ವದಲ್ಲಿರುವ ಎಂಡ್ಪಾಯಿಂಟ್ಗಳು ಸ್ಟ್ರೈಪ್ ಸೆಷನ್ ಇಲ್ಲದಾಗ 401 ಅನುಮತಿಸದಂತೆ ಹಿಂತಿರುಗಿಸುತ್ತವೆ. ಏಜೆಂಟ್ಗಳಿಗೆ 401 ಅನ್ನು ಏನು ಮಾಡಬೇಕು ಎಂಬುದರ ಬಗ್ಗೆ ತಿಳಿದಿಲ್ಲ - ಅವರು 'ಮುಂದುವರಿಸಲು ಪಾವತಿಸಿ' ಸಂಕೇತವಾಗಿ 402 ಪಾವತಿ ಅಗತ್ಯವಿದೆ ಎಂದು ಮಾತ್ರ ಅರ್ಥಮಾಡಿಕೊಳ್ಳುತ್ತಾರೆ. ಗೇಟ್ ವಿಭಜಿಸಲು ಅಗತ್ಯವಿದೆ: 'ಈ ಕರೆ ಮಾಡುವವರು ಅನುಮತಿಸದವರು ಮತ್ತು ಪಾವತಿಸಲು ಸಾಧ್ಯವಿಲ್ಲ' (ಸತ್ಯ 401, 401 ಅನ್ನು ಹಿಂತಿರುಗಿಸಿ) ವಿರುದ್ಧ 'ಈ ಕರೆ ಮಾಡುವವರು ಪ್ರಮಾಣೀಕೃತವಲ್ಲ ಆದರೆ ಪಾವತಿಸಬಹುದು' (x402 402 ಸವಾಲುವನ್ನು ಹಿಂತಿರುಗಿಸಿ).
ಏಜೆಂಟ್ಗಳನ್ನು Stripe ಬೆಲೆಯನ್ನು ಬಿಟ್ಟು ಹೋಗಲು ಬಿಡುವುದು
ನಿಮ್ಮ Stripe ಚಂದಾ $20/ತಿಂಗಳಿಗೆ ಅಸীম ಕರೆಗಳಿಗೆ ಮತ್ತು ನಿಮ್ಮ x402 ಉಲ್ಲೇಖವು $0.01/ಕರೆ ಇದ್ದರೆ, ಏಕಕಾಲದಲ್ಲಿ $0.01 ಅನ್ನು ಪಾವತಿಸಲು ಏಕಕಾಲದಲ್ಲಿ $0.01 ಅನ್ನು ಪಾವತಿಸಲು ಸಾಧ್ಯವಾಗುತ್ತದೆ, ಅಲ್ಲಿ ಮಾನವನು $20 ಅನ್ನು ಬಹಳಷ್ಟು ಪಾವತಿಸುತ್ತಾನೆ. ಇದು ಅಪರೂಪದ ಬಳಕೆದಾರ ಏಜೆಂಟ್ ಟ್ರಾಫಿಕ್ಗಾಗಿ ಉತ್ತಮವಾಗಿದೆ ಮತ್ತು ಹೆಚ್ಚಿನ ಪ್ರಮಾಣದ ಏಜೆಂಟ್ ಟ್ರಾಫಿಕ್ಗಾಗಿ ಮುರಿಯುತ್ತದೆ. ಭಾರಿ ಏಜೆಂಟ್ ಸ್ವಾಭಾವಿಕವಾಗಿ ಚಂದಾ ಮಿತಿಯನ್ನು ತಲುಪುವಂತೆ ಕರೆ ಪ್ರತಿ ಬೆಲೆಯನ್ನು ಹೊಂದಿಸಿ - ನಂತರ ಅವರಿಗೆ ಬದಲಾಯಿಸಲು ಆಯ್ಕೆಯನ್ನು ನೀಡಿರಿ.
ಯಾವ ಮಾರ್ಗವನ್ನು ತೆಗೆದುಕೊಂಡಿದ್ದೇವೆ ಎಂಬುದನ್ನು ಲಾಗ್ ಮಾಡುತ್ತಿಲ್ಲ
ಒಂದು ಡಿಬಗ್ ವಿನಂತಿ ಬರುತ್ತದೆ: 'ಈ ಗ್ರಾಹಕ ಅವರು ಪಾವತಿಸಿದ್ದಾರೆ ಆದರೆ ನಾವು ತಲುಪಿಸುತ್ತಿಲ್ಲ' ಎಂದು ಹೇಳುತ್ತಾನೆ. ನೀವು ಯಾವ ಪ್ರಮಾಣೀಕರಣ ಮಾರ್ಗವು ಕರೆವನ್ನು ಅನುಮೋದಿತಗೊಳಿಸಿದೆ ಎಂದು ಲಾಗ್ ಮಾಡದಿದ್ದರೆ, ನೀವು Stripe ನ ದಾಖಲೆಗಳನ್ನು ಅಥವಾ Blockchain0x ನ ದಾಖಲೆಗಳನ್ನು ನೋಡಬೇಕೆಂದು ತಿಳಿಯುವುದಿಲ್ಲ. ನಿರ್ಧಾರವನ್ನು ಸದಾ ಲಾಗ್ ಮಾಡಿ: ಯಾವ ಶಾಖೆ ಹೊಂದಿತ್ತಾದರೂ, customer_id ಅಥವಾ X-Payment / ವ್ಯವಹಾರ ಉಲ್ಲೇಖ, ಮತ್ತು ಸಂಬಂಧ ID. ಇದಿಲ್ಲದೆ, ಪ್ರತಿಯೊಂದು ಡ್ಯುಯಲ್-ರೇಲ್ ಘಟನೆಗಳನ್ನು ತ್ರಿಯಾಜ್ ಮಾಡಲು ಎರಡು ಪಟ್ಟು ಹೆಚ್ಚು ಸಮಯ ತೆಗೆದುಕೊಳ್ಳುತ್ತದೆ.
ಒಂದು ಬಾರಿ ಡ್ಯುಯಲ್-ರೇಲ್ ಲೈವ್ ಆಗುತ್ತದೆ.
ವಾಸ್ತುಶಾಸ್ತ್ರವನ್ನು ಹೊಂದಿರುವುದರಿಂದ, ಉಳಿದವು ಕಾರ್ಯಾಚರಣಾತ್ಮಕವಾಗಿದೆ. ವೆಬ್ಹುಕ್ ಶ್ರೇಷ್ಟತೆ Stripe ಮತ್ತು Blockchain0x ಘಟನೆ ಹರಿವನ್ನು ನಿರ್ವಹಿಸುತ್ತದೆ. ಖರ್ಚು ನಿಯಂತ್ರಣಗಳು ನೀವು ನಿರ್ವಹಿಸುತ್ತಿರುವ ಯಾವುದೇ ಏಜೆಂಟ್ಗಳನ್ನು ರಕ್ಷಿಸುತ್ತವೆ. ಪ್ರೀ-ಲಾಂಚ್ ಭದ್ರತಾ ವಿಮರ್ಶೆ ಒಬ್ಬ ರೈಲು ಏಕೀಕರಣದಂತೆ ಅನ್ವಯಿಸುತ್ತದೆ.
ಅಭಿವೃದ್ಧಿಕಾರರು ಕೇಳುವ ವೆಬ್ಹುಕ್ ಮಾದರಿಗಳು
ಪ್ರಾಂಪ್ಟ್ ಇಂಜೆಕ್ಷನ್ ಅನ್ನು ಸಹನೆ ಮಾಡುವ ಏಜೆಂಟ್ ಖರ್ಚು ನಿಯಂತ್ರಣಗಳನ್ನು ಹೊಂದಿಸಿ
ಜೀವಂತವಾಗುವ ಮೊದಲು ನಿಮ್ಮ ಏಜೆಂಟ್ ವಾಲೆಟ್ ಅನ್ನು ಸುರಕ್ಷಿತಗೊಳಿಸಿ
docs.blockchain0x.com ನಲ್ಲಿ ಸಂಪೂರ್ಣ ಉಲ್ಲೇಖ. ಸಂಬಂಧಿತ ಉತ್ಪನ್ನ ಮೇಲ್ಮಟ್ಟ: ಪಾವತಿ API. ಹೋಲಿಸುವ ಚೌಕಟ್ಟು: ಹೋಲಿಸುತ್ತವೆ.