Skip to content

Commit c718eb0

Browse files
committed
feat: some updates
1 parent 3479b5d commit c718eb0

3 files changed

Lines changed: 94 additions & 1 deletion

File tree

frontend/content/docs/api-guide.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export default function CheckoutButton({ amount, cartId }) {
216216
```
217217
</FrameworkTab>
218218
<FrameworkTab label="Vue 3 (Composition API)">
219-
```vue
219+
```html
220220
<script setup>
221221
import { ref } from 'vue';
222222

frontend/content/docs/x402-agentic-payments.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Requirements for `X402_PAYER_SECRET` wallet:
7474

7575
## Production `payOnStellar` sample
7676

77+
<FrameworkTabs>
78+
<FrameworkTab label="Express (Node.js) / Next.js">
7779
`lib/payOnStellar.js`
7880

7981
```js
@@ -122,6 +124,56 @@ export async function payOnStellar({ amount, recipient, memo, assetIssuer }) {
122124
return result.hash;
123125
}
124126
```
127+
</FrameworkTab>
128+
<FrameworkTab label="Python (Django)">
129+
`payment_helpers.py`
130+
131+
```python
132+
import os
133+
from stellar_sdk import Server, Keypair, Network, TransactionBuilder, Asset
134+
135+
def pay_on_stellar(amount, recipient, memo, asset_issuer):
136+
secret = os.getenv("X402_PAYER_SECRET")
137+
if not secret:
138+
raise Exception("X402_PAYER_SECRET is missing")
139+
140+
if not amount or not recipient or not memo or not asset_issuer:
141+
raise Exception("Missing x402 challenge payment fields")
142+
143+
if len(memo.encode("utf-8")) > 28:
144+
raise Exception("x402 memo exceeds 28 bytes")
145+
146+
horizon_url = os.getenv("STELLAR_HORIZON_URL", "https://horizon-testnet.stellar.org")
147+
network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE if os.getenv("STELLAR_NETWORK") == "public" else Network.TESTNET_NETWORK_PASSPHRASE
148+
149+
server = Server(horizon_url)
150+
source_keypair = Keypair.from_secret(secret)
151+
source_account = server.load_account(source_keypair.public_key)
152+
base_fee = server.fetch_base_fee()
153+
154+
tx = TransactionBuilder(
155+
source_account,
156+
network_passphrase=network_passphrase,
157+
base_fee=base_fee
158+
)
159+
160+
tx.append_payment_op(
161+
destination=recipient,
162+
asset=Asset("USDC", asset_issuer),
163+
amount=str(amount)
164+
)
165+
166+
tx.add_text_memo(memo)
167+
tx.set_timeout(30)
168+
169+
transaction = tx.build()
170+
transaction.sign(source_keypair)
171+
172+
response = server.submit_transaction(transaction)
173+
return response.get("hash")
174+
```
175+
</FrameworkTab>
176+
</FrameworkTabs>
125177

126178
---
127179

frontend/test-mdx.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { serialize } = require("next-mdx-remote/serialize");
2+
const fs = require("fs");
3+
4+
async function check() {
5+
const remarkGfm = (await import("remark-gfm")).default;
6+
const rehypePrismPlus = (await import("rehype-prism-plus")).default;
7+
8+
const raw = fs.readFileSync("./content/docs/api-guide.mdx", "utf8");
9+
10+
function escapeNonCodeBraces(content) {
11+
const lines = content.split("\n");
12+
let inFence = false;
13+
return lines.map((line) => {
14+
const trimmed = line.trimStart();
15+
if (trimmed.startsWith("```") || trimmed.startsWith("~~~")) {
16+
inFence = !inFence;
17+
return line;
18+
}
19+
if (inFence) return line;
20+
return line.replace(/\{/g, "&#123;").replace(/\}/g, "&#125;");
21+
}).join("\n");
22+
}
23+
24+
const escaped = escapeNonCodeBraces(raw);
25+
26+
try {
27+
await serialize(escaped, {
28+
mdxOptions: {
29+
remarkPlugins: [remarkGfm],
30+
rehypePlugins: [
31+
[rehypePrismPlus, { defaultLanguage: "bash", showLineNumbers: false }],
32+
],
33+
},
34+
});
35+
console.log("SUCCESS");
36+
} catch(e) {
37+
console.error("MDX ERROR:", e);
38+
}
39+
}
40+
41+
check();

0 commit comments

Comments
 (0)