| 
									
										
										
										
											2024-01-24 20:14:02 +08:00
										 |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import requests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OperationService: | 
					
						
							| 
									
										
										
										
											2024-08-26 13:43:57 +08:00
										 |  |  |     base_url = os.environ.get("BILLING_API_URL", "BILLING_API_URL") | 
					
						
							|  |  |  |     secret_key = os.environ.get("BILLING_API_SECRET_KEY", "BILLING_API_SECRET_KEY") | 
					
						
							| 
									
										
										
										
											2024-01-24 20:14:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def _send_request(cls, method, endpoint, json=None, params=None): | 
					
						
							| 
									
										
										
										
											2024-08-26 13:43:57 +08:00
										 |  |  |         headers = {"Content-Type": "application/json", "Billing-Api-Secret-Key": cls.secret_key} | 
					
						
							| 
									
										
										
										
											2024-01-24 20:14:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         url = f"{cls.base_url}{endpoint}" | 
					
						
							|  |  |  |         response = requests.request(method, url, json=json, params=params, headers=headers) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return response.json() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2024-01-29 17:31:45 +08:00
										 |  |  |     def record_utm(cls, tenant_id: str, utm_info: dict): | 
					
						
							| 
									
										
										
										
											2024-01-24 20:14:02 +08:00
										 |  |  |         params = { | 
					
						
							| 
									
										
										
										
											2024-08-26 13:43:57 +08:00
										 |  |  |             "tenant_id": tenant_id, | 
					
						
							|  |  |  |             "utm_source": utm_info.get("utm_source", ""), | 
					
						
							|  |  |  |             "utm_medium": utm_info.get("utm_medium", ""), | 
					
						
							|  |  |  |             "utm_campaign": utm_info.get("utm_campaign", ""), | 
					
						
							|  |  |  |             "utm_content": utm_info.get("utm_content", ""), | 
					
						
							|  |  |  |             "utm_term": utm_info.get("utm_term", ""), | 
					
						
							| 
									
										
										
										
											2024-01-24 20:14:02 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-08-26 13:43:57 +08:00
										 |  |  |         return cls._send_request("POST", "/tenant_utms", params=params) |