-
Notifications
You must be signed in to change notification settings - Fork 1.7k
antom-payment-agent sample code #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wangzunjiao
wants to merge
5
commits into
google:main
Choose a base branch
from
wangzunjiao:antom-payment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+187
−1
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48594a3
antom-payment-agent sample code
wangzunjiao a56ea5b
Merge branch 'main' into antom-payment
wangzunjiao d5a9154
Update README add antom-mcp descriptions and sample agent responses
abfb142
Modify code comments
826df1e
Merge branch 'main' into antom-payment
Keith514 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Modify this file and rename it to ".env" or Copy as .env file and fill your values below | ||
GATEWAY_URL= | ||
CLIENT_ID= | ||
MERCHANT_PRIVATE_KEY= | ||
ALIPAY_PUBLIC_KEY= | ||
PAYMENT_REDIRECT_URL= | ||
PAYMENT_NOTIFY_URL= | ||
|
||
|
||
GOOGLE_GENAI_USE_VERTEXAI= | ||
GOOGLE_API_KEY= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Antom Payment Agent | ||
|
||
That integrates Ant International's Antom payment APIs, enabling AI assistants to handle payment and refund operations seamlessly. | ||
|
||
## Overview | ||
|
||
The Antom Payment Agent wraps Ant International's Antom payment APIs into standardized MCP tools, allowing AI assistants to securely process payment-related operations during conversations. With this server, you can create payment sessions, query transaction status, handle refunds, and more directly through AI interactions. | ||
|
||
## Features | ||
|
||
### 💳 Payment Operations | ||
- **Create Payment Session** (`create_payment_session`): Generate payment sessions for client-side SDK integration | ||
- **Query Payment Details** (`query_payment_detail`): Retrieve transaction status and information for submitted payment requests | ||
- **Cancel Payment** (`cancel_payment`): Cancel payments when results are not returned within expected timeframes | ||
|
||
### 💰 Refund Operations | ||
- **Create Refund** (`create_refund`): Initiate full or partial refunds against successful payments | ||
- **Query Refund Details** (`query_refund_detail`): Check refund status for previously submitted refund requests | ||
|
||
|
||
## Setup and Installation | ||
|
||
|
||
1. **Prerequisites** | ||
|
||
Before using the Antom Payment Agent, ensure you have: | ||
|
||
- **Python 3.11 or higher** | ||
- **uv** (recommended package manager) or **pip** | ||
- **Valid Antom Merchant Account** with: | ||
- Merchant Client ID (CLIENT_ID) | ||
- Merchant RSA Private Key (MERCHANT_PRIVATE_KEY) | ||
- Alipay RSA Public Key (ALIPAY_PUBLIC_KEY) | ||
- Payment Redirect Return URL (PAYMENT_REDIRECT_URL) | ||
- Payment Notification Callback URL (PAYMENT_NOTIFY_URL) | ||
|
||
|
||
2. **Installation** | ||
|
||
|
||
```bash | ||
# Clone this repository. | ||
git clone https://github.com/google/adk-samples.git | ||
cd adk-samples/python/agents/antom-payment | ||
# Install the package and dependencies. | ||
pip install poetry | ||
poetry install | ||
|
||
or | ||
uv venv | ||
uv sync | ||
|
||
``` | ||
|
||
3. **Configuration** | ||
|
||
You may set the following environment variables in your shell, or in a `python/agents/antom-payment/antom-payemnt-agent/.env` file instead. | ||
* Set up Google Cloud credentials. | ||
|
||
GOOGLE_GENAI_USE_VERTEXAI | ||
GOOGLE_API_KEY | ||
|
||
|
||
* your Antom config. | ||
|
||
|
||
GATEWAY_URL | ||
CLIENT_ID | ||
MERCHANT_PRIVATE_KEY | ||
ALIPAY_PUBLIC_KEY | ||
PAYMENT_REDIRECT_URL | ||
PAYMENT_NOTIFY_URL | ||
|
||
## Running the Agent | ||
|
||
|
||
**Using `adk`** | ||
|
||
|
||
ADK provides convenient ways to bring up agents locally and interact with them. | ||
You may talk to the agent using: | ||
|
||
```bash | ||
poetry run adk web | ||
or | ||
uv run adk web | ||
``` | ||
|
||
|
||
**Try the following prompts:** | ||
|
||
|
||
After running the agent, try the following example prompt | ||
|
||
``` | ||
[user]: Create a payment link for an order called "Cream Puff" for $100 and think of a sentence describing Cream Puff. | ||
polong-lin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
from google.adk.agents import Agent | ||
from google.adk.tools import MCPToolset | ||
from google.adk.tools.mcp_tool import StdioConnectionParams | ||
from mcp import StdioServerParameters | ||
|
||
root_agent = Agent( | ||
name="antom_payment_agent", | ||
model="gemini-2.0-flash", | ||
description=( | ||
"Agent creates payment links for merchants, queries payment result details。" | ||
), | ||
instruction=( | ||
"You are an Antom payment agent who can help users create payment links and query payment result details." | ||
"Regarding RequestId, you generate it randomly" | ||
"And you can describe the description of the user creating the order in one sentence" | ||
"when refund get the order details and paymentId based on the paymentRequest ID used when creating " | ||
"the payment method by the payment agent. " | ||
"If the merchant specifies a refund amount, a full refund will be made in the order currency by default." | ||
), | ||
tools=[ | ||
MCPToolset( | ||
connection_params=StdioConnectionParams( | ||
server_params=StdioServerParameters( | ||
command='uvx', | ||
args=[ | ||
"ant-intl-antom-mcp" | ||
], | ||
# Pass the API key as an environment variable to the npx process | ||
# This is how the MCP server for Google Maps expects the key. | ||
polong-lin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
env={ | ||
"GATEWAY_URL": os.getenv("GATEWAY_URL"), | ||
"CLIENT_ID": os.getenv("CLIENT_ID"), | ||
"MERCHANT_PRIVATE_KEY": os.getenv("MERCHANT_PRIVATE_KEY"), | ||
"ALIPAY_PUBLIC_KEY": os.getenv("ALIPAY_PUBLIC_KEY"), | ||
"PAYMENT_REDIRECT_URL": os.getenv("PAYMENT_REDIRECT_URL"), | ||
"PAYMENT_NOTIFY_URL": os.getenv("PAYMENT_NOTIFY_URL"), | ||
} | ||
), | ||
), | ||
) | ||
], | ||
) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[project] | ||
name = "antom-payment" | ||
version = "0.1.0" | ||
description = "That integrates Ant International's Antom payment APIs, enabling AI assistants to handle payment and refund operations seamlessly." | ||
authors = [ | ||
{ name = "Steven", email = "[email protected]" }, | ||
{ name = "Zunjiao Wang", email = "[email protected]" } | ||
] | ||
license = "Apache License 2.0" | ||
readme = "README.md" | ||
requires-python = ">=3.11" | ||
dependencies = [ | ||
"google-adk>=1.11.0", | ||
"mcp>=1.13.0", | ||
] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.