1+ import os
2+ from typing import Dict , List , Optional , Union , Literal
3+ from paymanai import Paymanai
4+
5+ # Initialize Payman client
6+ PAYMAN_API_SECRET = os .getenv ("PAYMAN_API_SECRET" )
7+ PAYMAN_ENVIRONMENT = os .getenv ("PAYMAN_ENVIRONMENT" )
8+
9+ client = Paymanai (
10+ x_payman_api_secret = PAYMAN_API_SECRET ,
11+ environment = PAYMAN_ENVIRONMENT
12+ )
13+
14+ def send_payment (
15+ amount_decimal : float ,
16+ payment_destination_id : Optional [str ] = None ,
17+ payment_destination : Optional [Dict ] = None ,
18+ customer_id : Optional [str ] = None ,
19+ customer_email : Optional [str ] = None ,
20+ customer_name : Optional [str ] = None ,
21+ memo : Optional [str ] = None
22+ ) -> Dict :
23+ """
24+ Send a payment using Payman.
25+
26+ Args:
27+ amount_decimal: Amount to send in decimal format
28+ payment_destination_id: ID of existing payment destination
29+ payment_destination: Dictionary containing payment destination details
30+ customer_id: Optional customer ID
31+ customer_email: Optional customer email
32+ customer_name: Optional customer name
33+ memo: Optional payment memo
34+
35+ Returns:
36+ Dictionary containing payment details
37+ """
38+ try :
39+ return client .payments .send_payment (
40+ amount_decimal = amount_decimal ,
41+ payment_destination_id = payment_destination_id ,
42+ payment_destination = payment_destination ,
43+ customer_id = customer_id ,
44+ customer_email = customer_email ,
45+ customer_name = customer_name ,
46+ memo = memo
47+ )
48+ except Exception as e :
49+ return {"error" : f"Failed to send payment: { str (e )} " }
50+
51+ def search_available_payees (
52+ name : Optional [str ] = None ,
53+ contact_email : Optional [str ] = None ,
54+ type : Optional [str ] = None
55+ ) -> List [Dict ]:
56+ """
57+ Search for available payment destinations/payees.
58+
59+ Args:
60+ name: Optional name filter
61+ contact_email: Optional email filter
62+ type: Optional payment type filter
63+
64+ Returns:
65+ List of matching payment destinations
66+ """
67+ try :
68+ return client .payments .search_payees (
69+ name = name ,
70+ contact_email = contact_email ,
71+ type = type
72+ )
73+ except Exception as e :
74+ return [{"error" : f"Failed to search payees: { str (e )} " }]
75+
76+ def add_payee (
77+ type : Literal ["CRYPTO_ADDRESS" ] | Literal ["US_ACH" ],
78+ name : Optional [str ] = None ,
79+ contact_details : Optional [Dict ] = None ,
80+ account_holder_name : Optional [str ] = None ,
81+ account_number : Optional [str ] = None ,
82+ account_type : Optional [str ] = None ,
83+ routing_number : Optional [str ] = None ,
84+ address : Optional [str ] = None ,
85+ currency : Optional [str ] = None ,
86+ tags : Optional [List [str ]] = None
87+ ) -> Dict :
88+ """
89+ Add a new payee/payment destination.
90+
91+ Args:
92+ type: Type of payment destination ("CRYPTO_ADDRESS" or "US_ACH")
93+ name: Optional name for the payment destination
94+ contact_details: Optional dictionary containing contact information
95+ account_holder_name: Required for US_ACH
96+ account_number: Required for US_ACH
97+ account_type: Required for US_ACH
98+ routing_number: Required for US_ACH
99+ address: Required for CRYPTO_ADDRESS
100+ currency: Optional currency specification
101+ tags: Optional list of tags
102+
103+ Returns:
104+ Dictionary containing the created payee details
105+ """
106+ try :
107+ return client .payments .create_payee (
108+ type = type ,
109+ name = name ,
110+ contact_details = contact_details ,
111+ account_holder_name = account_holder_name ,
112+ account_number = account_number ,
113+ account_type = account_type ,
114+ routing_number = routing_number ,
115+ address = address ,
116+ currency = currency ,
117+ tags = tags
118+ )
119+ except Exception as e :
120+ return {"error" : f"Failed to add payee: { str (e )} " }
121+
122+ def ask_for_money (
123+ amount_decimal : float ,
124+ customer_id : str ,
125+ customer_email : Optional [str ] = None ,
126+ customer_name : Optional [str ] = None ,
127+ memo : Optional [str ] = None
128+ ) -> Dict :
129+ """
130+ Generate a checkout link to request money from a customer.
131+
132+ Args:
133+ amount_decimal: Amount to request in decimal format
134+ customer_id: Customer's ID
135+ customer_email: Optional customer email
136+ customer_name: Optional customer name
137+ memo: Optional memo for the request
138+
139+ Returns:
140+ Dictionary containing the checkout URL
141+ """
142+ try :
143+ response = client .payments .initiate_customer_deposit (
144+ amount_decimal = amount_decimal ,
145+ customer_id = customer_id ,
146+ customer_email = customer_email ,
147+ customer_name = customer_name ,
148+ memo = memo
149+ )
150+ return {"checkout_url" : response .checkout_url }
151+ except Exception as e :
152+ return {"error" : f"Failed to generate payment request: { str (e )} " }
153+
154+ def get_balance (
155+ customer_id : Optional [str ] = None ,
156+ currency : str = "USD"
157+ ) -> Dict :
158+ """
159+ Get balance information.
160+
161+ Args:
162+ customer_id: Optional customer ID (if None, returns agent balance)
163+ currency: Currency to check balance for
164+
165+ Returns:
166+ Dictionary containing balance information
167+ """
168+ try :
169+ if customer_id and customer_id .lower () != "none" :
170+ return client .balances .get_customer_balance (
171+ customer_id = customer_id , # Use keyword arguments
172+ currency = currency
173+ )
174+ return client .balances .get_spendable_balance (
175+ currency = currency
176+ )
177+ except Exception as e :
178+ return {"error" : f"Failed to get balance: { str (e )} " }
0 commit comments