@@ -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
0 commit comments