In Agent Purchase Integration SDK, Supports All Popular Payment Stripe,Paypal,Alipay,WeChat,A2ZAgent Credit Payment
Project description
Agent A2Z Pay SDK
GitHub | Website AI Agent A2Z Pay | Reviews
AgentA2Z Pay SDK can help you integrate various payment methods (Stripe,Paypal,Alipay,WeChat) into your agent workflow and you can define when and where to charge money or create (AI Agent A2Z/DeepNLP API Credit) in the workflow.
Payment in AI Agent Workflow Example:
- Render an AIGC Image thumbnail to user and charge $1 dollars to render the 4K version per each run.
- Charge 'buy me a coffee' checkout at the end of a Finance/Med/Literature Deep Research before output the final report.
- Ask for Tips of a few CNY by Scanning QR code to continue fixing bugs in the AI Coding scenario.
- E-Commerce AI shopping to allow users to confirm the final payment to complete the transaction.
AgentA2ZPayment Checkout Integration
Checkout Card and Playground Result
Payment Options
| Platform | URL |
|---|---|
| Credit Card | Supported Credit Card using the Stripe Python Integration, including the checkout, webhook |
| Stripe | Supported, For Stripe Sandbox/Live PK, SK, Webhook Secret definition, see Stripe Doc |
| PayPal | Supported, For Client ID, Secret and Webhook ID, See Doc Paypal Doc |
| AgentA2Z Pay | WIP, Payment using API credit by AI AGENT A2Z Agent Platform / DeepNLP OneKey MCP & Agent API credit, OneKey Router Website and Doc OneKey Router API Benifits |
| Alipay | WIP, See Alipay Developer Doc |
| WeChat Pay | WIP, See WeChat Pay Developer Doc |
Supported Environment
| Platform | URL |
|---|---|
| Python | Pypi |
| NodeJs | NodeJS |
Brief Introduction of Different Payment Process
Stripe: Requires two steps: Create Payment Intent return a client_secret, Start Payment in the Client Side and then finish payment, Post Web Hook on
PayPal: Requires two steps: Create Order (server-side, returns approval_link) and Capture Order (server-side, after user approval/return).
Agent A2Z Payment: Requires one step of unified credit deduction A2Z Payment on aiagenta2z.com/deepnlp.org right after payment confirmation
Alipay/WeChat Pay: Requires one step: Unified Order/Create Payment (server-side, returns QR Code URL). Payment is completed via webhook after the user scans the code.
Tutorial
Let's begin with a workflow that charge user per tokens consumed, Example will charge $1. If user pays successfully, the agent loop will continue and return more things, otherwise it will await till timeout and return a checkout fail card.
import agent_a2z_payment
import uuid
from agent_a2z_payment.core import get_payment_sdk, PaymentWaitingMode, Environment
from agent_a2z_payment.core import _get_paypal_access_token
environment = Environment.SANDBOX.value
payment_agent = get_payment_sdk(env=environment)
### Define server endpoint, e.g., using FastAPI: @app.post("/api/chat")
async def chat(messages: list = Body(...)
, kwargs: dict = Body(...)):
# 0. Process input and initialize
print (f"DEBUG: Input messages: {messages} kwargs: {kwargs}")
# 1. LLM/Agent decides the cost of the task (e.g., 0.5 dollars for a report)
### Replace with actual logic to determine the required payment amount and currency.
### e.g. output = payment_agent.calculate_payment(messages)
amount = 1.00 # Example amount
currency = "USD"
print (f"Payment Agent calculated required amount: {amount} {currency}")
# 2. Create an order and prepare for asynchronous waiting
order = payment_agent.create_order(amount, currency)
order_id = order.get("order_id", str(uuid.uuid4()))
# 3. Create payment intent and get the checkout card HTML/JS
## payment_method: all,stripe,paypal,agenta2z,alipay,wechat,etc
checkout_result = payment_agent.checkout(payment_method="all", order_id=order_id, amount=amount, currency=currency)
checkout_html = checkout_result.get("checkout_html", "")
checkout_js = checkout_result.get("checkout_js", "")
### code to format the HTML/JS for streaming back to the front-end
# message_id = get_new_message_id()
## Yield back the checkout_html and checkout_js
## Omitted
# 4. Generator function to wait for payment and stream the final response
generator = payment_stream_generator(
order_id, message_id, chunk_list, payment_agent.orders
)
return StreamingResponse(generator, media_type="text/event-stream")
@app.post("/stripe/webhook")
async def stripe_webhook(request: Request):
### STRIPE WEBHOOK IMPLEMENTATION
### - Verify the signature (Stripe-Signature header).
### - Handle event types (e.g., 'checkout.session.completed', 'payment_intent.succeeded').
@app.post("/paypal/webhook")
async def paypal_webhook(request: Request):
### PAYPAL WEBHOOK IMPLEMENTATION
### - Verify the authenticity of the webhook sender.
### - Handle the relevant payment completion event.
### - Signal the waiting agent workflow as done in the Stripe webhook.
Remember to put necessary Environment Keys
STRIPE_API_KEY_PK_TEST=pk_test_xxxx
STRIPE_API_KEY_SK_TEST=sk_test_xxxx
STRIPE_API_KEY_PK_LIVE=pk_xxxx
STRIPE_API_KEY_SK_LIVE=sk_xxxx
STRIPE_WEBHOOK_SECRET=xxxx
PAYPAL_CLIENT_ID_TEST=xxxx
PAYPAL_SECRET_TEST=xxxx
PAYPAL_CLIENT_ID_LIVE=xxxx
PAYPAL_SECRET_LIVE=xxxx
PAYPAL_WEBHOOK_ID=xxxx
AGENT_A2Z_API_KEY_TEST=a2zt_xxxxxxxx
AGENT_A2Z_API_KEY_LIVE=a2zl_xxxxxxxx
Run your app workflow, you can see the fully integrated App as in the playground.
git clone https://github.com/aiagenta2z/agent_a2z_payment
cd ./agent_a2z_payment/app/payment_agent_app
## Start Server at 7000 port
uvicorn app:app --port 7000
## Visit http://127.0.0.1:7000/
## To Expose Your Local Server to Public URL for Web hook Testing
ngrok http 7000
# copy and pase the url to each payment site
# Example: https://zincky-kenton-cloudily-xxxxx.ngrok-free.dev -> http://localhost:7000
## Stripe Webhook
https://zincky-kenton-cloudily-xxxxx.ngrok-free.dev/stripe/webhook
Related
AI Agent Marketplace Registry
Open AI Agent Marketplace
MCP Marketplace
OneKey Router AI Agent & MCP Ranking
OneKey Agent MCP Router
OneKey AGent MCP Router Doc
AI Agent Dataset
Gemini Nano Banana Agent
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_a2z_payment-0.0.1.tar.gz.
File metadata
- Download URL: agent_a2z_payment-0.0.1.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c83e654e0eba6d251cc82ab701813594659794a15b8ce6d79a2f402f41f07c42
|
|
| MD5 |
65e77236826c8cd192d4d7b096fcb467
|
|
| BLAKE2b-256 |
e264bb31ce94c1c711f6c3d2b61416e58d41e7fd2e2bcfd0a16cdfb9c3ee32b8
|
File details
Details for the file agent_a2z_payment-0.0.1-py3-none-any.whl.
File metadata
- Download URL: agent_a2z_payment-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47fbdad4f1a67a01982ae2afd1d9d8d2286953f4774f9b05725894f7d1ec4abc
|
|
| MD5 |
25c153b9356a6076e924d46fe234d2df
|
|
| BLAKE2b-256 |
43ef15c47dd601869cf44657e7cd80f63523e8806a0ff5db0a423c5706316ad0
|